Passed
Push — master ( 65bdac...4e88da )
by Alxarafe
32:38
created
dolibarr/htdocs/core/modules/modCron.class.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -33,24 +33,24 @@  discard block
 block discarded – undo
33 33
 {
34 34
 
35 35
     /**
36
-	 *   Constructor. Define names, constants, directories, boxes, permissions
37
-	 *
38
-	 *   @param      DoliDB		$db      Database handler
36
+     *   Constructor. Define names, constants, directories, boxes, permissions
37
+     *
38
+     *   @param      DoliDB		$db      Database handler
39 39
      */
40 40
     function __construct($db)
41 41
     {
42
-    	global $langs, $conf;
42
+        global $langs, $conf;
43 43
 
44 44
         $this->db = $db;
45 45
         $this->numero = 2300;
46 46
 
47
-		// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
48
-		// It is used to group modules in module setup page
47
+        // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
48
+        // It is used to group modules in module setup page
49 49
         $this->family = "base";
50 50
         // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
51 51
         $this->name = preg_replace('/^mod/i', '', get_class($this));
52 52
         $this->description = "Enable the Dolibarr cron service";
53
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
53
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
54 54
         $this->version = 'dolibarr';
55 55
         // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
56 56
         $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
@@ -64,26 +64,26 @@  discard block
 block discarded – undo
64 64
         //-------------
65 65
         $this->config_page_url = array("cron.php@cron");
66 66
 
67
-		// Dependancies
68
-		//-------------
69
-		$this->hidden = !empty($conf->global->MODULE_CRON_DISABLED); // A condition to disable module
70
-		$this->depends = array(); // List of modules id that must be enabled if this module is enabled
71
-		$this->requiredby = array(); // List of modules id to disable if this one is disabled
72
-		$this->conflictwith = array(); // List of modules id this module is in conflict with
73
-		$this->langfiles = array("cron");
74
-
75
-		// Constants
76
-		//-----------
77
-		$this->const = array(
78
-				0=>array(
79
-					'CRON_KEY',
80
-					'chaine',
81
-					'',
82
-					'CRON KEY',
83
-					0,
84
-					'main',
85
-					0
86
-				),);
67
+        // Dependancies
68
+        //-------------
69
+        $this->hidden = !empty($conf->global->MODULE_CRON_DISABLED); // A condition to disable module
70
+        $this->depends = array(); // List of modules id that must be enabled if this module is enabled
71
+        $this->requiredby = array(); // List of modules id to disable if this one is disabled
72
+        $this->conflictwith = array(); // List of modules id this module is in conflict with
73
+        $this->langfiles = array("cron");
74
+
75
+        // Constants
76
+        //-----------
77
+        $this->const = array(
78
+                0=>array(
79
+                    'CRON_KEY',
80
+                    'chaine',
81
+                    '',
82
+                    'CRON KEY',
83
+                    0,
84
+                    'main',
85
+                    0
86
+                ),);
87 87
 
88 88
         // New pages on tabs
89 89
         // -----------------
@@ -93,54 +93,54 @@  discard block
 block discarded – undo
93 93
         //------
94 94
         $this->boxes = array();
95 95
 
96
-		// Cronjobs
97
-		$this->cronjobs = array(
98
-			0=>array('entity'=>0, 'label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>50, 'status'=>1, 'test'=>true),
99
-			1=>array('entity'=>0, 'label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>90, 'status'=>0, 'test'=>in_array($db->type, array('mysql', 'mysqli'))),
100
-			// 1=>array('entity'=>0, 'label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
101
-		);
96
+        // Cronjobs
97
+        $this->cronjobs = array(
98
+            0=>array('entity'=>0, 'label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>50, 'status'=>1, 'test'=>true),
99
+            1=>array('entity'=>0, 'label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>90, 'status'=>0, 'test'=>in_array($db->type, array('mysql', 'mysqli'))),
100
+            // 1=>array('entity'=>0, 'label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
101
+        );
102 102
 
103 103
         // Permissions
104
-		$this->rights = array(); // Permission array used by this module
105
-		$this->rights_class = 'cron';
106
-		$r = 0;
107
-
108
-		$this->rights[$r][0] = 23001;
109
-		$this->rights[$r][1] = 'Read cron jobs';
110
-		$this->rights[$r][3] = 0;
111
-		$this->rights[$r][4] = 'read';
112
-		$r++;
113
-
114
-		$this->rights[$r][0] = 23002;
115
-		$this->rights[$r][1] = 'Create cron Jobs';
116
-		$this->rights[$r][3] = 0;
117
-		$this->rights[$r][4] = 'create';
118
-		$r++;
119
-
120
-		$this->rights[$r][0] = 23003;
121
-		$this->rights[$r][1] = 'Delete cron Jobs';
122
-		$this->rights[$r][3] = 0;
123
-		$this->rights[$r][4] = 'delete';
124
-		$r++;
125
-
126
-		$this->rights[$r][0] = 23004;
127
-		$this->rights[$r][1] = 'Execute cron Jobs';
128
-		$this->rights[$r][3] = 0;
129
-		$this->rights[$r][4] = 'execute';
130
-		$r++;
104
+        $this->rights = array(); // Permission array used by this module
105
+        $this->rights_class = 'cron';
106
+        $r = 0;
107
+
108
+        $this->rights[$r][0] = 23001;
109
+        $this->rights[$r][1] = 'Read cron jobs';
110
+        $this->rights[$r][3] = 0;
111
+        $this->rights[$r][4] = 'read';
112
+        $r++;
113
+
114
+        $this->rights[$r][0] = 23002;
115
+        $this->rights[$r][1] = 'Create cron Jobs';
116
+        $this->rights[$r][3] = 0;
117
+        $this->rights[$r][4] = 'create';
118
+        $r++;
119
+
120
+        $this->rights[$r][0] = 23003;
121
+        $this->rights[$r][1] = 'Delete cron Jobs';
122
+        $this->rights[$r][3] = 0;
123
+        $this->rights[$r][4] = 'delete';
124
+        $r++;
125
+
126
+        $this->rights[$r][0] = 23004;
127
+        $this->rights[$r][1] = 'Execute cron Jobs';
128
+        $this->rights[$r][3] = 0;
129
+        $this->rights[$r][4] = 'execute';
130
+        $r++;
131 131
 
132 132
         // Main menu entries
133 133
         $r = 0;
134 134
         $this->menu[$r] = array('fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
135
-						        'type'=>'left', // This is a Left menu entry
136
-						        'titre'=>'CronList',
137
-						        'url'=>'/cron/list.php?status=-2&leftmenu=admintools',
138
-						        'langs'=>'cron', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
139
-						        'position'=>200,
140
-						        'enabled'=>'$conf->cron->enabled && preg_match(\'/^(admintools|all)/\', $leftmenu)', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
141
-						        'perms'=>'$user->rights->cron->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
142
-						        'target'=>'',
143
-						        'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
135
+                                'type'=>'left', // This is a Left menu entry
136
+                                'titre'=>'CronList',
137
+                                'url'=>'/cron/list.php?status=-2&leftmenu=admintools',
138
+                                'langs'=>'cron', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
139
+                                'position'=>200,
140
+                                'enabled'=>'$conf->cron->enabled && preg_match(\'/^(admintools|all)/\', $leftmenu)', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
141
+                                'perms'=>'$user->rights->cron->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
142
+                                'target'=>'',
143
+                                'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
144 144
         $r++;
145 145
     }
146 146
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modLoan.class.php 2 patches
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -32,139 +32,139 @@
 block discarded – undo
32 32
 class modLoan extends DolibarrModules
33 33
 {
34 34
 
35
-	/**
36
-	 *   Constructor. Define names, constants, directories, boxes, permissions
37
-	 *
38
-	 *   @param      DoliDB		$db      Database handler
39
-	 */
40
-	function __construct($db)
41
-	{
42
-		global $conf;
43
-
44
-		$this->db = $db;
45
-		$this->numero = 520;
46
-
47
-		$this->family = "financial";
48
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
49
-		$this->name = preg_replace('/^mod/i','',get_class($this));
50
-		// Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
51
-		$this->description = "Loans management";
52
-
53
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
54
-		$this->version = 'dolibarr';
55
-
56
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
57
-		$this->picto='bill';
58
-
59
-		// Data directories to create when module is enabled
60
-		$this->dirs = array("/loan/temp");
61
-
62
-		// Config pages
63
-		$this->config_page_url = array('loan.php');
64
-
65
-		// Dependencies
66
-		$this->hidden = false;			// A condition to hide module
67
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
68
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
69
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
70
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
71
-		$this->langfiles = array("loan");
72
-
73
-		// Constants
74
-		$this->const = array();
75
-		$this->const[0] = array(
76
-				"LOAN_ACCOUNTING_ACCOUNT_CAPITAL",
77
-				"chaine",
78
-				"164"
79
-		);
80
-		$this->const[1] = array(
81
-				"LOAN_ACCOUNTING_ACCOUNT_INTEREST",
82
-				"chaine",
83
-				"6611"
84
-		);
85
-		$this->const[1] = array(
86
-				"LOAN_ACCOUNTING_ACCOUNT_INSURANCE",
87
-				"chaine",
88
-				"6162"
89
-		);
90
-
91
-		// Boxes
92
-		$this->boxes = array();
93
-
94
-		// Permissions
95
-		$this->rights = array();
96
-		$this->rights_class = 'loan';
97
-		$r=0;
98
-
99
-		$r++;
100
-		$this->rights[$r][0] = 520;
101
-		$this->rights[$r][1] = 'Read loans';
102
-		$this->rights[$r][2] = 'r';
103
-		$this->rights[$r][3] = 0;
104
-		$this->rights[$r][4] = 'read';
105
-		$this->rights[$r][5] = '';
106
-
107
-		$r++;
108
-		$this->rights[$r][0] = 522;
109
-		$this->rights[$r][1] = 'Create/modify loans';
110
-		$this->rights[$r][2] = 'w';
111
-		$this->rights[$r][3] = 0;
112
-		$this->rights[$r][4] = 'write';
113
-		$this->rights[$r][5] = '';
114
-
115
-		$r++;
116
-		$this->rights[$r][0] = 524;
117
-		$this->rights[$r][1] = 'Delete loans';
118
-		$this->rights[$r][2] = 'd';
119
-		$this->rights[$r][3] = 0;
120
-		$this->rights[$r][4] = 'delete';
121
-		$this->rights[$r][5] = '';
122
-
123
-		$r++;
124
-		$this->rights[$r][0] = 525;
125
-		$this->rights[$r][1] = 'Access loan calculator';
126
-		$this->rights[$r][2] = 'r';
127
-		$this->rights[$r][3] = 0;
128
-		$this->rights[$r][4] = 'calc';
129
-		$this->rights[$r][5] = '';
130
-
131
-		$r++;
132
-		$this->rights[$r][0] = 527;
133
-		$this->rights[$r][1] = 'Export loans';
134
-		$this->rights[$r][2] = 'r';
135
-		$this->rights[$r][3] = 0;
136
-		$this->rights[$r][4] = 'export';
137
-		$this->rights[$r][5] = '';
138
-
139
-
140
-		// Menus
141
-		//-------
142
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
143
-
144
-
145
-		// Exports
146
-		//--------
147
-		$r=0;
148
-	}
149
-
150
-
151
-	/**
152
-	 *		Function called when module is enabled.
153
-	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
154
-	 *		It also creates data directories
155
-	 *
35
+    /**
36
+     *   Constructor. Define names, constants, directories, boxes, permissions
37
+     *
38
+     *   @param      DoliDB		$db      Database handler
39
+     */
40
+    function __construct($db)
41
+    {
42
+        global $conf;
43
+
44
+        $this->db = $db;
45
+        $this->numero = 520;
46
+
47
+        $this->family = "financial";
48
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
49
+        $this->name = preg_replace('/^mod/i','',get_class($this));
50
+        // Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
51
+        $this->description = "Loans management";
52
+
53
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
54
+        $this->version = 'dolibarr';
55
+
56
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
57
+        $this->picto='bill';
58
+
59
+        // Data directories to create when module is enabled
60
+        $this->dirs = array("/loan/temp");
61
+
62
+        // Config pages
63
+        $this->config_page_url = array('loan.php');
64
+
65
+        // Dependencies
66
+        $this->hidden = false;			// A condition to hide module
67
+        $this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
68
+        $this->requiredby = array();	// List of module ids to disable if this one is disabled
69
+        $this->conflictwith = array();	// List of module class names as string this module is in conflict with
70
+        $this->phpmin = array(5,4);		// Minimum version of PHP required by module
71
+        $this->langfiles = array("loan");
72
+
73
+        // Constants
74
+        $this->const = array();
75
+        $this->const[0] = array(
76
+                "LOAN_ACCOUNTING_ACCOUNT_CAPITAL",
77
+                "chaine",
78
+                "164"
79
+        );
80
+        $this->const[1] = array(
81
+                "LOAN_ACCOUNTING_ACCOUNT_INTEREST",
82
+                "chaine",
83
+                "6611"
84
+        );
85
+        $this->const[1] = array(
86
+                "LOAN_ACCOUNTING_ACCOUNT_INSURANCE",
87
+                "chaine",
88
+                "6162"
89
+        );
90
+
91
+        // Boxes
92
+        $this->boxes = array();
93
+
94
+        // Permissions
95
+        $this->rights = array();
96
+        $this->rights_class = 'loan';
97
+        $r=0;
98
+
99
+        $r++;
100
+        $this->rights[$r][0] = 520;
101
+        $this->rights[$r][1] = 'Read loans';
102
+        $this->rights[$r][2] = 'r';
103
+        $this->rights[$r][3] = 0;
104
+        $this->rights[$r][4] = 'read';
105
+        $this->rights[$r][5] = '';
106
+
107
+        $r++;
108
+        $this->rights[$r][0] = 522;
109
+        $this->rights[$r][1] = 'Create/modify loans';
110
+        $this->rights[$r][2] = 'w';
111
+        $this->rights[$r][3] = 0;
112
+        $this->rights[$r][4] = 'write';
113
+        $this->rights[$r][5] = '';
114
+
115
+        $r++;
116
+        $this->rights[$r][0] = 524;
117
+        $this->rights[$r][1] = 'Delete loans';
118
+        $this->rights[$r][2] = 'd';
119
+        $this->rights[$r][3] = 0;
120
+        $this->rights[$r][4] = 'delete';
121
+        $this->rights[$r][5] = '';
122
+
123
+        $r++;
124
+        $this->rights[$r][0] = 525;
125
+        $this->rights[$r][1] = 'Access loan calculator';
126
+        $this->rights[$r][2] = 'r';
127
+        $this->rights[$r][3] = 0;
128
+        $this->rights[$r][4] = 'calc';
129
+        $this->rights[$r][5] = '';
130
+
131
+        $r++;
132
+        $this->rights[$r][0] = 527;
133
+        $this->rights[$r][1] = 'Export loans';
134
+        $this->rights[$r][2] = 'r';
135
+        $this->rights[$r][3] = 0;
136
+        $this->rights[$r][4] = 'export';
137
+        $this->rights[$r][5] = '';
138
+
139
+
140
+        // Menus
141
+        //-------
142
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
143
+
144
+
145
+        // Exports
146
+        //--------
147
+        $r=0;
148
+    }
149
+
150
+
151
+    /**
152
+     *		Function called when module is enabled.
153
+     *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
154
+     *		It also creates data directories
155
+     *
156 156
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
157
-	 *      @return     int             	1 if OK, 0 if KO
158
-	 */
159
-	function init($options='')
160
-	{
161
-		global $conf;
157
+     *      @return     int             	1 if OK, 0 if KO
158
+     */
159
+    function init($options='')
160
+    {
161
+        global $conf;
162 162
 
163
-		// Clean before activation
164
-		$this->remove($options);
163
+        // Clean before activation
164
+        $this->remove($options);
165 165
 
166
-		$sql = array();
166
+        $sql = array();
167 167
 
168
-		return $this->_init($sql,$options);
169
-	}
168
+        return $this->_init($sql,$options);
169
+    }
170 170
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  *      \ingroup    loan
24 24
  *      \brief      File to activate module loan
25 25
  */
26
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
26
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
27 27
 
28 28
 
29 29
 /**
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
 		$this->family = "financial";
48 48
 		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
49
-		$this->name = preg_replace('/^mod/i','',get_class($this));
49
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
50 50
 		// Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
51 51
 		$this->description = "Loans management";
52 52
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		$this->version = 'dolibarr';
55 55
 
56 56
 		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
57
-		$this->picto='bill';
57
+		$this->picto = 'bill';
58 58
 
59 59
 		// Data directories to create when module is enabled
60 60
 		$this->dirs = array("/loan/temp");
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 		$this->config_page_url = array('loan.php');
64 64
 
65 65
 		// Dependencies
66
-		$this->hidden = false;			// A condition to hide module
67
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
68
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
69
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
70
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module
66
+		$this->hidden = false; // A condition to hide module
67
+		$this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
68
+		$this->requiredby = array(); // List of module ids to disable if this one is disabled
69
+		$this->conflictwith = array(); // List of module class names as string this module is in conflict with
70
+		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
71 71
 		$this->langfiles = array("loan");
72 72
 
73 73
 		// Constants
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		// Permissions
95 95
 		$this->rights = array();
96 96
 		$this->rights_class = 'loan';
97
-		$r=0;
97
+		$r = 0;
98 98
 
99 99
 		$r++;
100 100
 		$this->rights[$r][0] = 520;
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
 
140 140
 		// Menus
141 141
 		//-------
142
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
142
+		$this->menu = 1; // This module add menu entries. They are coded into menu manager.
143 143
 
144 144
 
145 145
 		// Exports
146 146
 		//--------
147
-		$r=0;
147
+		$r = 0;
148 148
 	}
149 149
 
150 150
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      *      @param      string	$options    Options when enabling module ('', 'noboxes')
157 157
 	 *      @return     int             	1 if OK, 0 if KO
158 158
 	 */
159
-	function init($options='')
159
+	function init($options = '')
160 160
 	{
161 161
 		global $conf;
162 162
 
@@ -165,6 +165,6 @@  discard block
 block discarded – undo
165 165
 
166 166
 		$sql = array();
167 167
 
168
-		return $this->_init($sql,$options);
168
+		return $this->_init($sql, $options);
169 169
 	}
170 170
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modOauth.class.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -68,10 +68,10 @@
 block discarded – undo
68 68
 
69 69
         // Dependencies
70 70
         $this->hidden = false;			// A condition to hide module
71
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
72
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
73
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
74
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module                    // Minimum version of PHP required by module
71
+        $this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
72
+        $this->requiredby = array();	// List of module ids to disable if this one is disabled
73
+        $this->conflictwith = array();	// List of module class names as string this module is in conflict with
74
+        $this->phpmin = array(5,4);		// Minimum version of PHP required by module                    // Minimum version of PHP required by module
75 75
         $this->need_dolibarr_version = array(3,7,-2);   // Minimum version of Dolibarr required by module
76 76
         $this->conflictwith = array();
77 77
         $this->langfiles = array("oauth");
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *  \ingroup    oauth
26 26
  *  \brief      File of class to describe and activate module Oauth
27 27
  */
28
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
28
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 29
 
30 30
 
31 31
 
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
      */
43 43
     function __construct($db)
44 44
     {
45
-        $this->db = $db ;
45
+        $this->db = $db;
46 46
         $this->numero = 66000;
47 47
         // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
48 48
         // It is used to group modules in module setup page
49 49
         $this->family = "interface";
50 50
         $this->module_position = '31';
51 51
         // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52
-        $this->name = preg_replace('/^mod/i','',get_class($this));
52
+        $this->name = preg_replace('/^mod/i', '', get_class($this));
53 53
         // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
54 54
         $this->description = "Enable OAuth authentication";
55 55
         // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
         $this->config_page_url = array("oauth.php");
68 68
 
69 69
         // Dependencies
70
-        $this->hidden = false;			// A condition to hide module
71
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
72
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
73
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
74
-		$this->phpmin = array(5,4);		// Minimum version of PHP required by module                    // Minimum version of PHP required by module
75
-        $this->need_dolibarr_version = array(3,7,-2);   // Minimum version of Dolibarr required by module
70
+        $this->hidden = false; // A condition to hide module
71
+		$this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
72
+		$this->requiredby = array(); // List of module ids to disable if this one is disabled
73
+		$this->conflictwith = array(); // List of module class names as string this module is in conflict with
74
+		$this->phpmin = array(5, 4); // Minimum version of PHP required by module                    // Minimum version of PHP required by module
75
+        $this->need_dolibarr_version = array(3, 7, -2); // Minimum version of Dolibarr required by module
76 76
         $this->conflictwith = array();
77 77
         $this->langfiles = array("oauth");
78 78
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
         $this->rights = array();
87 87
         $this->rights_class = 'oauth';
88 88
 
89
-        $r=0;
89
+        $r = 0;
90 90
         // $this->rights[$r][0]     Id permission (unique tous modules confondus)
91 91
         // $this->rights[$r][1]     Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
92 92
         // $this->rights[$r][2]     Non utilise
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
         $this->rights[$r][4] = 'read';*/
103 103
 
104 104
         // Main menu entries
105
-        $this->menus = array();         // List of menus to add
106
-        $r=0;
105
+        $this->menus = array(); // List of menus to add
106
+        $r = 0;
107 107
 
108 108
         // This is to declare the Top Menu entry:
109 109
         //$this->menu[$r]=array(  'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools',               // Put 0 if this is a top menu
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      *      @param      string  $options    Options when enabling module ('', 'noboxes')
131 131
      *      @return     int                 1 if OK, 0 if KO
132 132
      */
133
-    function init($options='')
133
+    function init($options = '')
134 134
     {
135 135
         global $conf;
136 136
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modHoliday.class.php 2 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -36,225 +36,225 @@
 block discarded – undo
36 36
  */
37 37
 class modHoliday extends DolibarrModules
38 38
 {
39
-	/**
40
-	 *  Constructor. Define names, constants, directories, boxes, permissions
41
-	 *
42
-	 *  @param	DoliDB	$db		Database handler
43
-	 */
44
-	function __construct($db)
45
-	{
46
-		$this->db = $db;
47
-
48
-		// Id for module (must be unique).
49
-		// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
50
-		$this->numero = 20000;
51
-		// Key text used to identify module (for permissions, menus, etc...)
52
-		$this->rights_class = 'holiday';
53
-
54
-		// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
55
-		// It is used to group modules in module setup page
56
-		$this->family = "hr";
57
-		$this->module_position = '30';
58
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
59
-		$this->name = preg_replace('/^mod/i','',get_class($this));
60
-		// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
61
-		$this->description = "Leave requests";
62
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
63
-		$this->version = 'dolibarr';
64
-		// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
65
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
66
-		// Name of image file used for this module.
67
-		// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
68
-		// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
69
-		$this->picto='holiday';
70
-
71
-		// Data directories to create when module is enabled.
72
-		// Example: this->dirs = array("/mymodule/temp");
73
-		$this->dirs = array("/holiday/temp");
74
-		$r=0;
75
-
76
-		// Config pages
77
-		$this->config_page_url = array("holiday.php");
78
-
79
-
80
-		// Config pages. Put here list of php page names stored in admmin directory used to setup module.
81
-		// $this->config_page_url = array("holiday.php?leftmenu=setup@holiday");
82
-
83
-		// Dependencies
84
-		$this->hidden = false;			// A condition to hide module
85
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
86
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
87
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
88
-		$this->phpmin = array(5,4);					// Minimum version of PHP required by module
89
-		$this->need_dolibarr_version = array(3,0);	// Minimum version of Dolibarr required by module
90
-		$this->langfiles = array("holiday");
91
-
92
-		// Constants
93
-		// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
94
-		//                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
95
-		//                             2=>array('MAIN_MODULE_MYMODULE_NEEDSMARTY','chaine',1,'Constant to say module need smarty',0)
96
-		$this->const = array();			// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
97
-		$r=0;
98
-
99
-		$this->const[$r][0] = "HOLIDAY_ADDON";
100
-		$this->const[$r][1] = "chaine";
101
-		$this->const[$r][2] = "mod_holiday_madonna";
102
-		$this->const[$r][3] = 'Nom du gestionnaire de numerotation des congés';
103
-		$this->const[$r][4] = 0;
104
-		$r++;
105
-
106
-		$this->const[$r][0] = "HOLIDAY_ADDON_PDF";
107
-		$this->const[$r][1] = "chaine";
108
-		$this->const[$r][2] = "celebrate";
109
-		$this->const[$r][3] = 'Name of PDF model of holiday';
110
-		$this->const[$r][4] = 0;
111
-		$r++;
112
-
113
-		$this->const[$r][0] = "HOLIDAY_ADDON_PDF_ODT_PATH";
114
-		$this->const[$r][1] = "chaine";
115
-		$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/holiday";
116
-		$this->const[$r][3] = "";
117
-		$this->const[$r][4] = 0;
118
-		$r++;
119
-
120
-		// Array to add new pages in new tabs
121
-		//$this->tabs[] = array('data'=>'user:+paidholidays:CPTitreMenu:holiday:$user->rights->holiday->read:/holiday/list.php?mainmenu=hrm&id=__ID__');	// We avoid to get one tab for each module. RH data are already in RH tab.
122
-		$this->tabs[] = array();  					// To add a new tab identified by code tabname1
123
-
124
-		// Boxes
125
-		$this->boxes = array();			// List of boxes
126
-		$r=0;
127
-
128
-		// Add here list of php file(s) stored in includes/boxes that contains class to show a box.
129
-		// Example:
130
-		//$this->boxes[$r][1] = "myboxa.php";
131
-		//$r++;
132
-		//$this->boxes[$r][1] = "myboxb.php";
133
-		//$r++;
134
-
135
-
136
-		// Permissions
137
-		$this->rights = array();		// Permission array used by this module
138
-		$r=0;
139
-
140
-		$this->rights[$r][0] = 20001; 				// Permission id (must not be already used)
141
-		$this->rights[$r][1] = 'Read your own leave requests';	// Permission label
142
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
143
-		$this->rights[$r][4] = 'read';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
144
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
145
-		$r++;
146
-
147
-		$this->rights[$r][0] = 20002; 				// Permission id (must not be already used)
148
-		$this->rights[$r][1] = 'Create/modify your own leave requests';	// Permission label
149
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
150
-		$this->rights[$r][4] = 'write';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
151
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
152
-		$r++;
153
-
154
-		$this->rights[$r][0] = 20003; 				// Permission id (must not be already used)
155
-		$this->rights[$r][1] = 'Delete leave requests';	// Permission label
156
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
157
-		$this->rights[$r][4] = 'delete';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
158
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
159
-		$r++;
160
-
161
-		$this->rights[$r][0] = 20007;
162
-		$this->rights[$r][1] = 'Approve leave requests';
163
-		$this->rights[$r][2] = 'w';
164
-		$this->rights[$r][3] = 0;
165
-		$this->rights[$r][4] = 'approve';
166
-		$r++;
167
-
168
-		$this->rights[$r][0] = 20004; 				// Permission id (must not be already used)
169
-		$this->rights[$r][1] = 'Read leave requests for everybody';	// Permission label
170
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
171
-		$this->rights[$r][4] = 'read_all';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
172
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
173
-		$r++;
174
-
175
-		$this->rights[$r][0] = 20005; 				// Permission id (must not be already used)
176
-		$this->rights[$r][1] = 'Create/modify leave requests for everybody';	// Permission label
177
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
178
-		$this->rights[$r][4] = 'write_all';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
179
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
180
-		$r++;
181
-
182
-		$this->rights[$r][0] = 20006; 				// Permission id (must not be already used)
183
-		$this->rights[$r][1] = 'Setup leave requests of users (setup and update balance)';	// Permission label
184
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
185
-		$this->rights[$r][4] = 'define_holiday';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
186
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
187
-		$r++;
188
-
189
-
190
-		// Menus
191
-		//-------
192
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
193
-
194
-
195
-		// Exports
196
-		$r=0;
197
-
198
-		$r++;
199
-		$this->export_code[$r]='leaverequest_'.$r;
200
-		$this->export_label[$r]='ListeCP';
201
-		$this->export_icon[$r]='holiday';
202
-		$this->export_permission[$r]=array(array("holiday","read_all"));
203
-		$this->export_fields_array[$r]=array(
204
-			'd.rowid'=>"LeaveId",'d.fk_type'=>'TypeOfLeaveId','t.code'=>'TypeOfLeaveCode','t.label'=>'TypeOfLeaveLabel','d.fk_user'=>'UserID',
205
-			'u.lastname'=>'Lastname','u.firstname'=>'Firstname','u.login'=>"Login",'d.date_debut'=>'DateStart','d.date_fin'=>'DateEnd','d.halfday'=>'HalfDay',
206
-			'd.date_valid'=>'DateApprove','d.fk_validator'=>"UserForApprovalID",'ua.lastname'=>"UserForApprovalLastname",'ua.firstname'=>"UserForApprovalFirstname",
207
-			'ua.login'=>"UserForApprovalLogin",'d.description'=>'Description','d.statut'=>'Status'
208
-		);
209
-		$this->export_entities_array[$r]=array(
210
-			'u.lastname'=>'user','u.firstname'=>'user','u.login'=>'user','ua.lastname'=>'user','ua.firstname'=>'user','ua.login'=>'user'
211
-		);
212
-		$this->export_alias_array[$r]=array('d.rowid'=>"idholiday");
213
-		$this->export_dependencies_array[$r]=array(); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
214
-
215
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
216
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'holiday as d';
217
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_holiday_types as t ON t.rowid = d.fk_type';
218
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua ON ua.rowid = d.fk_validator,';
219
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'user as u';
220
-		$this->export_sql_end[$r] .=' WHERE d.fk_user = u.rowid';
221
-		$this->export_sql_end[$r] .=' AND d.entity IN ('.getEntity('holiday').')';
222
-
223
-		// Example:
224
-		// $this->export_code[$r]=$this->rights_class.'_'.$r;
225
-		// $this->export_label[$r]='CustomersInvoicesAndInvoiceLines';	// Translation key (used only if key ExportDataset_xxx_z not found)
226
-		// $this->export_permission[$r]=array(array("facture","facture","export"));
227
-		// $this->export_fields_array[$r]=array(
228
-		//	's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
229
-		//	's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
230
-		//	's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
231
-		//	'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
232
-		//	'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
233
-		//	'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
234
-		//	'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
235
-		//);
236
-		// $this->export_entities_array[$r]=array(
237
-		//	's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
238
-		//	's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
239
-		//	'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",
240
-		//	'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
241
-		//	'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
242
-		//	'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
243
-		//);
244
-		// $this->export_alias_array[$r]=array(
245
-		//	's.rowid'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.zip'=>'soc_zip','s.town'=>'soc_town','s.fk_pays'=>'soc_pays','s.phone'=>'soc_tel',
246
-		//	's.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','s.code_compta'=>'soc_customer_accountancy',
247
-		//	's.code_compta_fournisseur'=>'soc_supplier_accountancy','f.rowid'=>"invoiceid",'f.ref'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",
248
-		//	'f.total'=>"totalht",'f.total_ttc'=>"totalttc",'f.tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'fd.rowid'=>'lineid',
249
-		//	'fd.description'=>"linedescription",'fd.price'=>"lineprice",'fd.total_ht'=>"linetotalht",'fd.total_tva'=>"linetotaltva",'fd.total_ttc'=>"linetotalttc",
250
-		//	'fd.tva_tx'=>"linevatrate",'fd.qty'=>"lineqty",'fd.date_start'=>"linedatestart",'fd.date_end'=>"linedateend",'fd.fk_product'=>'productid',
251
-		//	'p.ref'=>'productref'
252
-		//);
253
-		// $this->export_sql_start[$r]='SELECT DISTINCT ';
254
-		// $this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
255
-		// $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
256
-		// $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
257
-		// $r++;
258
-	}
39
+    /**
40
+     *  Constructor. Define names, constants, directories, boxes, permissions
41
+     *
42
+     *  @param	DoliDB	$db		Database handler
43
+     */
44
+    function __construct($db)
45
+    {
46
+        $this->db = $db;
47
+
48
+        // Id for module (must be unique).
49
+        // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
50
+        $this->numero = 20000;
51
+        // Key text used to identify module (for permissions, menus, etc...)
52
+        $this->rights_class = 'holiday';
53
+
54
+        // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
55
+        // It is used to group modules in module setup page
56
+        $this->family = "hr";
57
+        $this->module_position = '30';
58
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
59
+        $this->name = preg_replace('/^mod/i','',get_class($this));
60
+        // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
61
+        $this->description = "Leave requests";
62
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
63
+        $this->version = 'dolibarr';
64
+        // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
65
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
66
+        // Name of image file used for this module.
67
+        // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
68
+        // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
69
+        $this->picto='holiday';
70
+
71
+        // Data directories to create when module is enabled.
72
+        // Example: this->dirs = array("/mymodule/temp");
73
+        $this->dirs = array("/holiday/temp");
74
+        $r=0;
75
+
76
+        // Config pages
77
+        $this->config_page_url = array("holiday.php");
78
+
79
+
80
+        // Config pages. Put here list of php page names stored in admmin directory used to setup module.
81
+        // $this->config_page_url = array("holiday.php?leftmenu=setup@holiday");
82
+
83
+        // Dependencies
84
+        $this->hidden = false;			// A condition to hide module
85
+        $this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
86
+        $this->requiredby = array();	// List of module ids to disable if this one is disabled
87
+        $this->conflictwith = array();	// List of module class names as string this module is in conflict with
88
+        $this->phpmin = array(5,4);					// Minimum version of PHP required by module
89
+        $this->need_dolibarr_version = array(3,0);	// Minimum version of Dolibarr required by module
90
+        $this->langfiles = array("holiday");
91
+
92
+        // Constants
93
+        // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
94
+        //                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
95
+        //                             2=>array('MAIN_MODULE_MYMODULE_NEEDSMARTY','chaine',1,'Constant to say module need smarty',0)
96
+        $this->const = array();			// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
97
+        $r=0;
98
+
99
+        $this->const[$r][0] = "HOLIDAY_ADDON";
100
+        $this->const[$r][1] = "chaine";
101
+        $this->const[$r][2] = "mod_holiday_madonna";
102
+        $this->const[$r][3] = 'Nom du gestionnaire de numerotation des congés';
103
+        $this->const[$r][4] = 0;
104
+        $r++;
105
+
106
+        $this->const[$r][0] = "HOLIDAY_ADDON_PDF";
107
+        $this->const[$r][1] = "chaine";
108
+        $this->const[$r][2] = "celebrate";
109
+        $this->const[$r][3] = 'Name of PDF model of holiday';
110
+        $this->const[$r][4] = 0;
111
+        $r++;
112
+
113
+        $this->const[$r][0] = "HOLIDAY_ADDON_PDF_ODT_PATH";
114
+        $this->const[$r][1] = "chaine";
115
+        $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/holiday";
116
+        $this->const[$r][3] = "";
117
+        $this->const[$r][4] = 0;
118
+        $r++;
119
+
120
+        // Array to add new pages in new tabs
121
+        //$this->tabs[] = array('data'=>'user:+paidholidays:CPTitreMenu:holiday:$user->rights->holiday->read:/holiday/list.php?mainmenu=hrm&id=__ID__');	// We avoid to get one tab for each module. RH data are already in RH tab.
122
+        $this->tabs[] = array();  					// To add a new tab identified by code tabname1
123
+
124
+        // Boxes
125
+        $this->boxes = array();			// List of boxes
126
+        $r=0;
127
+
128
+        // Add here list of php file(s) stored in includes/boxes that contains class to show a box.
129
+        // Example:
130
+        //$this->boxes[$r][1] = "myboxa.php";
131
+        //$r++;
132
+        //$this->boxes[$r][1] = "myboxb.php";
133
+        //$r++;
134
+
135
+
136
+        // Permissions
137
+        $this->rights = array();		// Permission array used by this module
138
+        $r=0;
139
+
140
+        $this->rights[$r][0] = 20001; 				// Permission id (must not be already used)
141
+        $this->rights[$r][1] = 'Read your own leave requests';	// Permission label
142
+        $this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
143
+        $this->rights[$r][4] = 'read';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
144
+        $this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
145
+        $r++;
146
+
147
+        $this->rights[$r][0] = 20002; 				// Permission id (must not be already used)
148
+        $this->rights[$r][1] = 'Create/modify your own leave requests';	// Permission label
149
+        $this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
150
+        $this->rights[$r][4] = 'write';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
151
+        $this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
152
+        $r++;
153
+
154
+        $this->rights[$r][0] = 20003; 				// Permission id (must not be already used)
155
+        $this->rights[$r][1] = 'Delete leave requests';	// Permission label
156
+        $this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
157
+        $this->rights[$r][4] = 'delete';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
158
+        $this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
159
+        $r++;
160
+
161
+        $this->rights[$r][0] = 20007;
162
+        $this->rights[$r][1] = 'Approve leave requests';
163
+        $this->rights[$r][2] = 'w';
164
+        $this->rights[$r][3] = 0;
165
+        $this->rights[$r][4] = 'approve';
166
+        $r++;
167
+
168
+        $this->rights[$r][0] = 20004; 				// Permission id (must not be already used)
169
+        $this->rights[$r][1] = 'Read leave requests for everybody';	// Permission label
170
+        $this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
171
+        $this->rights[$r][4] = 'read_all';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
172
+        $this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
173
+        $r++;
174
+
175
+        $this->rights[$r][0] = 20005; 				// Permission id (must not be already used)
176
+        $this->rights[$r][1] = 'Create/modify leave requests for everybody';	// Permission label
177
+        $this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
178
+        $this->rights[$r][4] = 'write_all';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
179
+        $this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
180
+        $r++;
181
+
182
+        $this->rights[$r][0] = 20006; 				// Permission id (must not be already used)
183
+        $this->rights[$r][1] = 'Setup leave requests of users (setup and update balance)';	// Permission label
184
+        $this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
185
+        $this->rights[$r][4] = 'define_holiday';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
186
+        $this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
187
+        $r++;
188
+
189
+
190
+        // Menus
191
+        //-------
192
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
193
+
194
+
195
+        // Exports
196
+        $r=0;
197
+
198
+        $r++;
199
+        $this->export_code[$r]='leaverequest_'.$r;
200
+        $this->export_label[$r]='ListeCP';
201
+        $this->export_icon[$r]='holiday';
202
+        $this->export_permission[$r]=array(array("holiday","read_all"));
203
+        $this->export_fields_array[$r]=array(
204
+            'd.rowid'=>"LeaveId",'d.fk_type'=>'TypeOfLeaveId','t.code'=>'TypeOfLeaveCode','t.label'=>'TypeOfLeaveLabel','d.fk_user'=>'UserID',
205
+            'u.lastname'=>'Lastname','u.firstname'=>'Firstname','u.login'=>"Login",'d.date_debut'=>'DateStart','d.date_fin'=>'DateEnd','d.halfday'=>'HalfDay',
206
+            'd.date_valid'=>'DateApprove','d.fk_validator'=>"UserForApprovalID",'ua.lastname'=>"UserForApprovalLastname",'ua.firstname'=>"UserForApprovalFirstname",
207
+            'ua.login'=>"UserForApprovalLogin",'d.description'=>'Description','d.statut'=>'Status'
208
+        );
209
+        $this->export_entities_array[$r]=array(
210
+            'u.lastname'=>'user','u.firstname'=>'user','u.login'=>'user','ua.lastname'=>'user','ua.firstname'=>'user','ua.login'=>'user'
211
+        );
212
+        $this->export_alias_array[$r]=array('d.rowid'=>"idholiday");
213
+        $this->export_dependencies_array[$r]=array(); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
214
+
215
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
216
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'holiday as d';
217
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_holiday_types as t ON t.rowid = d.fk_type';
218
+        $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua ON ua.rowid = d.fk_validator,';
219
+        $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'user as u';
220
+        $this->export_sql_end[$r] .=' WHERE d.fk_user = u.rowid';
221
+        $this->export_sql_end[$r] .=' AND d.entity IN ('.getEntity('holiday').')';
222
+
223
+        // Example:
224
+        // $this->export_code[$r]=$this->rights_class.'_'.$r;
225
+        // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines';	// Translation key (used only if key ExportDataset_xxx_z not found)
226
+        // $this->export_permission[$r]=array(array("facture","facture","export"));
227
+        // $this->export_fields_array[$r]=array(
228
+        //	's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
229
+        //	's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
230
+        //	's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
231
+        //	'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
232
+        //	'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
233
+        //	'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
234
+        //	'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
235
+        //);
236
+        // $this->export_entities_array[$r]=array(
237
+        //	's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
238
+        //	's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
239
+        //	'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",
240
+        //	'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
241
+        //	'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
242
+        //	'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
243
+        //);
244
+        // $this->export_alias_array[$r]=array(
245
+        //	's.rowid'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.zip'=>'soc_zip','s.town'=>'soc_town','s.fk_pays'=>'soc_pays','s.phone'=>'soc_tel',
246
+        //	's.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','s.code_compta'=>'soc_customer_accountancy',
247
+        //	's.code_compta_fournisseur'=>'soc_supplier_accountancy','f.rowid'=>"invoiceid",'f.ref'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",
248
+        //	'f.total'=>"totalht",'f.total_ttc'=>"totalttc",'f.tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'fd.rowid'=>'lineid',
249
+        //	'fd.description'=>"linedescription",'fd.price'=>"lineprice",'fd.total_ht'=>"linetotalht",'fd.total_tva'=>"linetotaltva",'fd.total_ttc'=>"linetotalttc",
250
+        //	'fd.tva_tx'=>"linevatrate",'fd.qty'=>"lineqty",'fd.date_start'=>"linedatestart",'fd.date_end'=>"linedateend",'fd.fk_product'=>'productid',
251
+        //	'p.ref'=>'productref'
252
+        //);
253
+        // $this->export_sql_start[$r]='SELECT DISTINCT ';
254
+        // $this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
255
+        // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
256
+        // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
257
+        // $r++;
258
+    }
259 259
 }
260 260
 
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  *    \ingroup    holiday
29 29
  *    \brief      Description and activation file for module holiday
30 30
  */
31
-include_once DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php";
31
+include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
32 32
 
33 33
 
34 34
 /**
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		$this->family = "hr";
57 57
 		$this->module_position = '30';
58 58
 		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
59
-		$this->name = preg_replace('/^mod/i','',get_class($this));
59
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
60 60
 		// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
61 61
 		$this->description = "Leave requests";
62 62
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 		// Name of image file used for this module.
67 67
 		// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
68 68
 		// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
69
-		$this->picto='holiday';
69
+		$this->picto = 'holiday';
70 70
 
71 71
 		// Data directories to create when module is enabled.
72 72
 		// Example: this->dirs = array("/mymodule/temp");
73 73
 		$this->dirs = array("/holiday/temp");
74
-		$r=0;
74
+		$r = 0;
75 75
 
76 76
 		// Config pages
77 77
 		$this->config_page_url = array("holiday.php");
@@ -81,20 +81,20 @@  discard block
 block discarded – undo
81 81
 		// $this->config_page_url = array("holiday.php?leftmenu=setup@holiday");
82 82
 
83 83
 		// Dependencies
84
-		$this->hidden = false;			// A condition to hide module
85
-		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
86
-		$this->requiredby = array();	// List of module ids to disable if this one is disabled
87
-		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
88
-		$this->phpmin = array(5,4);					// Minimum version of PHP required by module
89
-		$this->need_dolibarr_version = array(3,0);	// Minimum version of Dolibarr required by module
84
+		$this->hidden = false; // A condition to hide module
85
+		$this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
86
+		$this->requiredby = array(); // List of module ids to disable if this one is disabled
87
+		$this->conflictwith = array(); // List of module class names as string this module is in conflict with
88
+		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
89
+		$this->need_dolibarr_version = array(3, 0); // Minimum version of Dolibarr required by module
90 90
 		$this->langfiles = array("holiday");
91 91
 
92 92
 		// Constants
93 93
 		// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
94 94
 		//                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
95 95
 		//                             2=>array('MAIN_MODULE_MYMODULE_NEEDSMARTY','chaine',1,'Constant to say module need smarty',0)
96
-		$this->const = array();			// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
97
-		$r=0;
96
+		$this->const = array(); // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
97
+		$r = 0;
98 98
 
99 99
 		$this->const[$r][0] = "HOLIDAY_ADDON";
100 100
 		$this->const[$r][1] = "chaine";
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
 
120 120
 		// Array to add new pages in new tabs
121 121
 		//$this->tabs[] = array('data'=>'user:+paidholidays:CPTitreMenu:holiday:$user->rights->holiday->read:/holiday/list.php?mainmenu=hrm&id=__ID__');	// We avoid to get one tab for each module. RH data are already in RH tab.
122
-		$this->tabs[] = array();  					// To add a new tab identified by code tabname1
122
+		$this->tabs[] = array(); // To add a new tab identified by code tabname1
123 123
 
124 124
 		// Boxes
125
-		$this->boxes = array();			// List of boxes
126
-		$r=0;
125
+		$this->boxes = array(); // List of boxes
126
+		$r = 0;
127 127
 
128 128
 		// Add here list of php file(s) stored in includes/boxes that contains class to show a box.
129 129
 		// Example:
@@ -134,28 +134,28 @@  discard block
 block discarded – undo
134 134
 
135 135
 
136 136
 		// Permissions
137
-		$this->rights = array();		// Permission array used by this module
138
-		$r=0;
139
-
140
-		$this->rights[$r][0] = 20001; 				// Permission id (must not be already used)
141
-		$this->rights[$r][1] = 'Read your own leave requests';	// Permission label
142
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
143
-		$this->rights[$r][4] = 'read';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
144
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
137
+		$this->rights = array(); // Permission array used by this module
138
+		$r = 0;
139
+
140
+		$this->rights[$r][0] = 20001; // Permission id (must not be already used)
141
+		$this->rights[$r][1] = 'Read your own leave requests'; // Permission label
142
+		$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
143
+		$this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
144
+		$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
145 145
 		$r++;
146 146
 
147
-		$this->rights[$r][0] = 20002; 				// Permission id (must not be already used)
148
-		$this->rights[$r][1] = 'Create/modify your own leave requests';	// Permission label
149
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
150
-		$this->rights[$r][4] = 'write';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
151
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
147
+		$this->rights[$r][0] = 20002; // Permission id (must not be already used)
148
+		$this->rights[$r][1] = 'Create/modify your own leave requests'; // Permission label
149
+		$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
150
+		$this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
151
+		$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
152 152
 		$r++;
153 153
 
154
-		$this->rights[$r][0] = 20003; 				// Permission id (must not be already used)
155
-		$this->rights[$r][1] = 'Delete leave requests';	// Permission label
156
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
157
-		$this->rights[$r][4] = 'delete';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
158
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
154
+		$this->rights[$r][0] = 20003; // Permission id (must not be already used)
155
+		$this->rights[$r][1] = 'Delete leave requests'; // Permission label
156
+		$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
157
+		$this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
158
+		$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
159 159
 		$r++;
160 160
 
161 161
 		$this->rights[$r][0] = 20007;
@@ -165,60 +165,60 @@  discard block
 block discarded – undo
165 165
 		$this->rights[$r][4] = 'approve';
166 166
 		$r++;
167 167
 
168
-		$this->rights[$r][0] = 20004; 				// Permission id (must not be already used)
169
-		$this->rights[$r][1] = 'Read leave requests for everybody';	// Permission label
170
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
171
-		$this->rights[$r][4] = 'read_all';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
172
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
168
+		$this->rights[$r][0] = 20004; // Permission id (must not be already used)
169
+		$this->rights[$r][1] = 'Read leave requests for everybody'; // Permission label
170
+		$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
171
+		$this->rights[$r][4] = 'read_all'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
172
+		$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
173 173
 		$r++;
174 174
 
175
-		$this->rights[$r][0] = 20005; 				// Permission id (must not be already used)
176
-		$this->rights[$r][1] = 'Create/modify leave requests for everybody';	// Permission label
177
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
178
-		$this->rights[$r][4] = 'write_all';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
179
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
175
+		$this->rights[$r][0] = 20005; // Permission id (must not be already used)
176
+		$this->rights[$r][1] = 'Create/modify leave requests for everybody'; // Permission label
177
+		$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
178
+		$this->rights[$r][4] = 'write_all'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
179
+		$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
180 180
 		$r++;
181 181
 
182
-		$this->rights[$r][0] = 20006; 				// Permission id (must not be already used)
183
-		$this->rights[$r][1] = 'Setup leave requests of users (setup and update balance)';	// Permission label
184
-		$this->rights[$r][3] = 0; 					// Permission by default for new user (0/1)
185
-		$this->rights[$r][4] = 'define_holiday';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
186
-		$this->rights[$r][5] = '';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
182
+		$this->rights[$r][0] = 20006; // Permission id (must not be already used)
183
+		$this->rights[$r][1] = 'Setup leave requests of users (setup and update balance)'; // Permission label
184
+		$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
185
+		$this->rights[$r][4] = 'define_holiday'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
186
+		$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
187 187
 		$r++;
188 188
 
189 189
 
190 190
 		// Menus
191 191
 		//-------
192
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
192
+		$this->menu = 1; // This module add menu entries. They are coded into menu manager.
193 193
 
194 194
 
195 195
 		// Exports
196
-		$r=0;
196
+		$r = 0;
197 197
 
198 198
 		$r++;
199
-		$this->export_code[$r]='leaverequest_'.$r;
200
-		$this->export_label[$r]='ListeCP';
201
-		$this->export_icon[$r]='holiday';
202
-		$this->export_permission[$r]=array(array("holiday","read_all"));
203
-		$this->export_fields_array[$r]=array(
204
-			'd.rowid'=>"LeaveId",'d.fk_type'=>'TypeOfLeaveId','t.code'=>'TypeOfLeaveCode','t.label'=>'TypeOfLeaveLabel','d.fk_user'=>'UserID',
205
-			'u.lastname'=>'Lastname','u.firstname'=>'Firstname','u.login'=>"Login",'d.date_debut'=>'DateStart','d.date_fin'=>'DateEnd','d.halfday'=>'HalfDay',
206
-			'd.date_valid'=>'DateApprove','d.fk_validator'=>"UserForApprovalID",'ua.lastname'=>"UserForApprovalLastname",'ua.firstname'=>"UserForApprovalFirstname",
207
-			'ua.login'=>"UserForApprovalLogin",'d.description'=>'Description','d.statut'=>'Status'
199
+		$this->export_code[$r] = 'leaverequest_'.$r;
200
+		$this->export_label[$r] = 'ListeCP';
201
+		$this->export_icon[$r] = 'holiday';
202
+		$this->export_permission[$r] = array(array("holiday", "read_all"));
203
+		$this->export_fields_array[$r] = array(
204
+			'd.rowid'=>"LeaveId", 'd.fk_type'=>'TypeOfLeaveId', 't.code'=>'TypeOfLeaveCode', 't.label'=>'TypeOfLeaveLabel', 'd.fk_user'=>'UserID',
205
+			'u.lastname'=>'Lastname', 'u.firstname'=>'Firstname', 'u.login'=>"Login", 'd.date_debut'=>'DateStart', 'd.date_fin'=>'DateEnd', 'd.halfday'=>'HalfDay',
206
+			'd.date_valid'=>'DateApprove', 'd.fk_validator'=>"UserForApprovalID", 'ua.lastname'=>"UserForApprovalLastname", 'ua.firstname'=>"UserForApprovalFirstname",
207
+			'ua.login'=>"UserForApprovalLogin", 'd.description'=>'Description', 'd.statut'=>'Status'
208 208
 		);
209
-		$this->export_entities_array[$r]=array(
210
-			'u.lastname'=>'user','u.firstname'=>'user','u.login'=>'user','ua.lastname'=>'user','ua.firstname'=>'user','ua.login'=>'user'
209
+		$this->export_entities_array[$r] = array(
210
+			'u.lastname'=>'user', 'u.firstname'=>'user', 'u.login'=>'user', 'ua.lastname'=>'user', 'ua.firstname'=>'user', 'ua.login'=>'user'
211 211
 		);
212
-		$this->export_alias_array[$r]=array('d.rowid'=>"idholiday");
213
-		$this->export_dependencies_array[$r]=array(); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
214
-
215
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
216
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'holiday as d';
217
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_holiday_types as t ON t.rowid = d.fk_type';
218
-		$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua ON ua.rowid = d.fk_validator,';
219
-		$this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'user as u';
220
-		$this->export_sql_end[$r] .=' WHERE d.fk_user = u.rowid';
221
-		$this->export_sql_end[$r] .=' AND d.entity IN ('.getEntity('holiday').')';
212
+		$this->export_alias_array[$r] = array('d.rowid'=>"idholiday");
213
+		$this->export_dependencies_array[$r] = array(); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
214
+
215
+		$this->export_sql_start[$r] = 'SELECT DISTINCT ';
216
+		$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'holiday as d';
217
+		$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_holiday_types as t ON t.rowid = d.fk_type';
218
+		$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua ON ua.rowid = d.fk_validator,';
219
+		$this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'user as u';
220
+		$this->export_sql_end[$r] .= ' WHERE d.fk_user = u.rowid';
221
+		$this->export_sql_end[$r] .= ' AND d.entity IN ('.getEntity('holiday').')';
222 222
 
223 223
 		// Example:
224 224
 		// $this->export_code[$r]=$this->rights_class.'_'.$r;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/import/import_xlsx.modules.php 3 patches
Indentation   +546 added lines, -546 removed lines patch added patch discarded remove patch
@@ -41,76 +41,76 @@  discard block
 block discarded – undo
41 41
     public $datatoimport;
42 42
 
43 43
     /**
44
-	 * @var string Error code (or message)
45
-	 */
46
-	public $error='';
44
+     * @var string Error code (or message)
45
+     */
46
+    public $error='';
47 47
 
48
-	/**
49
-	 * @var string[] Error codes (or messages)
50
-	 */
51
-	public $errors = array();
48
+    /**
49
+     * @var string[] Error codes (or messages)
50
+     */
51
+    public $errors = array();
52 52
 
53 53
     /**
54
-	 * @var int ID
55
-	 */
56
-	public $id;
54
+     * @var int ID
55
+     */
56
+    public $id;
57 57
 
58
-	/**
58
+    /**
59 59
      * @var string label
60 60
      */
61 61
     public $label;
62 62
 
63
-	public $extension;    // Extension of files imported by driver
63
+    public $extension;    // Extension of files imported by driver
64 64
 
65
-	/**
65
+    /**
66 66
      * Dolibarr version of driver
67 67
      * @public string
68 68
      */
69
-	public $version = 'dolibarr';
69
+    public $version = 'dolibarr';
70 70
 
71
-	public $label_lib;    // Label of external lib used by driver
71
+    public $label_lib;    // Label of external lib used by driver
72 72
 
73
-	public $version_lib;  // Version of external lib used by driver
73
+    public $version_lib;  // Version of external lib used by driver
74 74
 
75
-	public $separator;
75
+    public $separator;
76 76
 
77 77
     public $file;      // Path of file
78 78
 
79
-	public $handle;    // Handle fichier
80
-
81
-	public $cacheconvert=array();      // Array to cache list of value found after a convertion
79
+    public $handle;    // Handle fichier
82 80
 
83
-	public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
81
+    public $cacheconvert=array();      // Array to cache list of value found after a convertion
84 82
 
85
-	public $workbook; // temporary import file
83
+    public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
86 84
 
87
-	public $record; // current record
85
+    public $workbook; // temporary import file
88 86
 
89
-	public $headers;
87
+    public $record; // current record
90 88
 
89
+    public $headers;
91 90
 
92
-	/**
93
-	 *	Constructor
94
-	 *
95
-	 *	@param	DoliDB		$db				Database handler
96
-	 *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
97
-	 */
98
-	function __construct($db,$datatoimport)
99
-	{
100
-		global $conf,$langs;
101
-		$this->db = $db;
102 91
 
103
-		// this is used as an extension from the example file code, so we have to put xlsx here !!!
104
-		$this->id='xlsx';                // Same value as xxx in file name export_xxx.modules.php
105
-		$this->label='Excel 2007';             // Label of driver
106
-		$this->desc=$langs->trans("Excel2007FormatDesc");
107
-		$this->extension='xlsx';         // Extension for generated file by this driver
108
-		$this->picto='mime/xls';		// Picto (This is not used by the example file code as Mime type, too bad ...)
109
-		$this->version='1.0';         // Driver version
110
-
111
-		// If driver use an external library, put its name here
92
+    /**
93
+     *	Constructor
94
+     *
95
+     *	@param	DoliDB		$db				Database handler
96
+     *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
97
+     */
98
+    function __construct($db,$datatoimport)
99
+    {
100
+        global $conf,$langs;
101
+        $this->db = $db;
102
+
103
+        // this is used as an extension from the example file code, so we have to put xlsx here !!!
104
+        $this->id='xlsx';                // Same value as xxx in file name export_xxx.modules.php
105
+        $this->label='Excel 2007';             // Label of driver
106
+        $this->desc=$langs->trans("Excel2007FormatDesc");
107
+        $this->extension='xlsx';         // Extension for generated file by this driver
108
+        $this->picto='mime/xls';		// Picto (This is not used by the example file code as Mime type, too bad ...)
109
+        $this->version='1.0';         // Driver version
110
+
111
+        // If driver use an external library, put its name here
112 112
         require_once PHPEXCEL_PATH.'PHPExcel.php';
113
-		require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php';
113
+        require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php';
114 114
         if (! class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive
115 115
         {
116 116
                 $langs->load("errors");
@@ -120,20 +120,20 @@  discard block
 block discarded – undo
120 120
         $this->label_lib='PhpExcel';
121 121
         $this->version_lib='1.8.0';
122 122
 
123
-		$this->datatoimport=$datatoimport;
124
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
125
-	}
123
+        $this->datatoimport=$datatoimport;
124
+        if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
125
+    }
126 126
 
127 127
 
128 128
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
129
-	/**
130
-	 * 	Output header of an example file for this format
131
-	 *
132
-	 * 	@param	Translate	$outputlangs		Output language
133
-	 *  @return	string
134
-	 */
135
-	function write_header_example($outputlangs)
136
-	{
129
+    /**
130
+     * 	Output header of an example file for this format
131
+     *
132
+     * 	@param	Translate	$outputlangs		Output language
133
+     *  @return	string
134
+     */
135
+    function write_header_example($outputlangs)
136
+    {
137 137
         // phpcs:enable
138 138
         global $user,$conf,$langs;
139 139
         // create a temporary object, the final output will be generated in footer
@@ -159,291 +159,291 @@  discard block
 block discarded – undo
159 159
     }
160 160
 
161 161
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
162
-	/**
163
-	 * 	Output title line of an example file for this format
164
-	 *
165
-	 * 	@param	Translate	$outputlangs		Output language
166
-	 *  @param	array		$headerlinefields	Array of fields name
167
-	 * 	@return	string
168
-	 */
169
-	function write_title_example($outputlangs,$headerlinefields)
170
-	{
162
+    /**
163
+     * 	Output title line of an example file for this format
164
+     *
165
+     * 	@param	Translate	$outputlangs		Output language
166
+     *  @param	array		$headerlinefields	Array of fields name
167
+     * 	@return	string
168
+     */
169
+    function write_title_example($outputlangs,$headerlinefields)
170
+    {
171 171
         // phpcs:enable
172
-		global $conf;
173
-		$this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true);
174
-		$this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
175
-
176
-		$col = 0;
177
-		foreach($headerlinefields as $field) {
178
-			$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, 1, $outputlangs->transnoentities($field));
179
-			// set autowidth
180
-			//$this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($col + 1))->setAutoSize(true);
181
-			$col++;
182
-		}
172
+        global $conf;
173
+        $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true);
174
+        $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
175
+
176
+        $col = 0;
177
+        foreach($headerlinefields as $field) {
178
+            $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, 1, $outputlangs->transnoentities($field));
179
+            // set autowidth
180
+            //$this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($col + 1))->setAutoSize(true);
181
+            $col++;
182
+        }
183 183
 
184
-		return ''; // final output will be generated in footer
185
-	}
184
+        return ''; // final output will be generated in footer
185
+    }
186 186
 
187 187
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
188
-	/**
189
-	 * 	Output record of an example file for this format
190
-	 *
191
-	 * 	@param	Translate	$outputlangs		Output language
192
-	 * 	@param	array		$contentlinevalues	Array of lines
193
-	 * 	@return	string
194
-	 */
195
-	function write_record_example($outputlangs,$contentlinevalues)
196
-	{
188
+    /**
189
+     * 	Output record of an example file for this format
190
+     *
191
+     * 	@param	Translate	$outputlangs		Output language
192
+     * 	@param	array		$contentlinevalues	Array of lines
193
+     * 	@return	string
194
+     */
195
+    function write_record_example($outputlangs,$contentlinevalues)
196
+    {
197 197
         // phpcs:enable
198
-		$col = 0;
199
-		$row = 2;
200
-		foreach($contentlinevalues as $cell) {
201
-			$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, $row, $cell);
202
-			$col++;
203
-		}
198
+        $col = 0;
199
+        $row = 2;
200
+        foreach($contentlinevalues as $cell) {
201
+            $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, $row, $cell);
202
+            $col++;
203
+        }
204 204
 
205
-		return ''; // final output will be generated in footer
206
-	}
205
+        return ''; // final output will be generated in footer
206
+    }
207 207
 
208 208
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
209
-	/**
210
-	 * 	Output footer of an example file for this format
211
-	 *
212
-	 * 	@param	Translate	$outputlangs		Output language
213
-	 *  @return	string
214
-	 */
215
-	function write_footer_example($outputlangs)
216
-	{
209
+    /**
210
+     * 	Output footer of an example file for this format
211
+     *
212
+     * 	@param	Translate	$outputlangs		Output language
213
+     *  @return	string
214
+     */
215
+    function write_footer_example($outputlangs)
216
+    {
217 217
         // phpcs:enable
218
-		// return the file content as a string
219
-		$tempfile = tempnam(sys_get_temp_dir(), 'dol');
220
-		$objWriter = new PHPExcel_Writer_Excel2007($this->workbook);
221
-		$objWriter->save($tempfile);
222
-		$this->workbook->disconnectWorksheets();
223
-		unset($this->workbook);
224
-
225
-		$content = file_get_contents($tempfile);
226
-		unlink($tempfile);
227
-		return $content;
228
-	}
218
+        // return the file content as a string
219
+        $tempfile = tempnam(sys_get_temp_dir(), 'dol');
220
+        $objWriter = new PHPExcel_Writer_Excel2007($this->workbook);
221
+        $objWriter->save($tempfile);
222
+        $this->workbook->disconnectWorksheets();
223
+        unset($this->workbook);
224
+
225
+        $content = file_get_contents($tempfile);
226
+        unlink($tempfile);
227
+        return $content;
228
+    }
229 229
 
230 230
 
231 231
 
232 232
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
233
-	/**
234
-	 *	Open input file
235
-	 *
236
-	 *	@param	string	$file		Path of filename
237
-	 *	@return	int					<0 if KO, >=0 if OK
238
-	 */
239
-	function import_open_file($file)
240
-	{
233
+    /**
234
+     *	Open input file
235
+     *
236
+     *	@param	string	$file		Path of filename
237
+     *	@return	int					<0 if KO, >=0 if OK
238
+     */
239
+    function import_open_file($file)
240
+    {
241 241
         // phpcs:enable
242
-		global $langs;
243
-		$ret=1;
242
+        global $langs;
243
+        $ret=1;
244 244
 
245
-		dol_syslog(get_class($this)."::open_file file=".$file);
245
+        dol_syslog(get_class($this)."::open_file file=".$file);
246 246
 
247
-		$reader = new PHPExcel_Reader_Excel2007();
248
-		$this->workbook = $reader->load($file);
249
-		$this->record = 1;
250
-		$this->file = $file;
247
+        $reader = new PHPExcel_Reader_Excel2007();
248
+        $this->workbook = $reader->load($file);
249
+        $this->record = 1;
250
+        $this->file = $file;
251 251
 
252
-		return $ret;
253
-	}
252
+        return $ret;
253
+    }
254 254
 
255 255
 
256 256
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
257
-	/**
258
-	 * 	Return nb of records. File must be closed.
259
-	 *
260
-	 *	@param	string	$file		Path of filename
261
-	 * 	@return		int		<0 if KO, >=0 if OK
262
-	 */
263
-	function import_get_nb_of_lines($file)
264
-	{
257
+    /**
258
+     * 	Return nb of records. File must be closed.
259
+     *
260
+     *	@param	string	$file		Path of filename
261
+     * 	@return		int		<0 if KO, >=0 if OK
262
+     */
263
+    function import_get_nb_of_lines($file)
264
+    {
265 265
         // phpcs:enable
266
-		$reader = new PHPExcel_Reader_Excel2007();
267
-		$this->workbook = $reader->load($file);
266
+        $reader = new PHPExcel_Reader_Excel2007();
267
+        $this->workbook = $reader->load($file);
268 268
 
269
-		$rowcount = $this->workbook->getActiveSheet()->getHighestDataRow();
269
+        $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow();
270 270
 
271
-		$this->workbook->disconnectWorksheets();
272
-		unset($this->workbook);
271
+        $this->workbook->disconnectWorksheets();
272
+        unset($this->workbook);
273 273
 
274
-		return $rowcount;
275
-	}
274
+        return $rowcount;
275
+    }
276 276
 
277 277
 
278 278
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
279
-	/**
280
-	 * 	Input header line from file
281
-	 *
282
-	 * 	@return		int		<0 if KO, >=0 if OK
283
-	 */
284
-	function import_read_header()
285
-	{
279
+    /**
280
+     * 	Input header line from file
281
+     *
282
+     * 	@return		int		<0 if KO, >=0 if OK
283
+     */
284
+    function import_read_header()
285
+    {
286 286
         // phpcs:enable
287
-		// This is not called by the import code !!!
288
-		$this->headers = array();
289
-		$colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn());
290
-		for($col=0;$col<$colcount;$col++) {
291
-			$this->headers[$col] = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, 1)->getValue();
292
-		}
293
-		return 0;
294
-	}
287
+        // This is not called by the import code !!!
288
+        $this->headers = array();
289
+        $colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn());
290
+        for($col=0;$col<$colcount;$col++) {
291
+            $this->headers[$col] = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, 1)->getValue();
292
+        }
293
+        return 0;
294
+    }
295 295
 
296 296
 
297 297
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
298
-	/**
299
-	 * 	Return array of next record in input file.
300
-	 *
301
-	 * 	@return		Array		Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=not empty string)
302
-	 */
303
-	function import_read_record()
304
-	{
298
+    /**
299
+     * 	Return array of next record in input file.
300
+     *
301
+     * 	@return		Array		Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=not empty string)
302
+     */
303
+    function import_read_record()
304
+    {
305 305
         // phpcs:enable
306
-		global $conf;
307
-
308
-		$rowcount = $this->workbook->getActiveSheet()->getHighestDataRow();
309
-		if($this->record > $rowcount)
310
-			return false;
311
-		$array = array();
312
-		$colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn(0));
313
-		for($col=0;$col<$colcount;$col++) {
314
-			$val = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $this->record)->getValue();
315
-			$array[$col]['val'] = $val;
316
-			$array[$col]['type'] = (dol_strlen($val)?1:-1); // If empty we consider it null
317
-		}
318
-		$this->record++;
319
-		return $array;
320
-	}
306
+        global $conf;
307
+
308
+        $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow();
309
+        if($this->record > $rowcount)
310
+            return false;
311
+        $array = array();
312
+        $colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn(0));
313
+        for($col=0;$col<$colcount;$col++) {
314
+            $val = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $this->record)->getValue();
315
+            $array[$col]['val'] = $val;
316
+            $array[$col]['type'] = (dol_strlen($val)?1:-1); // If empty we consider it null
317
+        }
318
+        $this->record++;
319
+        return $array;
320
+    }
321 321
 
322 322
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
323
-	/**
324
-	 * 	Close file handle
325
-	 *
326
-	 *  @return	integer
327
-	 */
328
-	function import_close_file()
329
-	{
323
+    /**
324
+     * 	Close file handle
325
+     *
326
+     *  @return	integer
327
+     */
328
+    function import_close_file()
329
+    {
330 330
         // phpcs:enable
331
-		$this->workbook->disconnectWorksheets();
332
-		unset($this->workbook);
333
-	}
331
+        $this->workbook->disconnectWorksheets();
332
+        unset($this->workbook);
333
+    }
334 334
 
335 335
 
336 336
     // What is this doing here ? it is common to all imports, is should be in the parent class
337 337
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
338
-	/**
339
-	 * Insert a record into database
340
-	 *
341
-	 * @param	array	$arrayrecord					Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
342
-	 * @param	array	$array_match_file_to_database	Array of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]...
343
-	 * @param 	Object	$objimport						Object import (contains objimport->array_import_tables, objimport->array_import_fields, objimport->array_import_convertvalue, ...)
344
-	 * @param	int		$maxfields						Max number of fields to use
345
-	 * @param	string	$importid						Import key
346
-	 * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
347
-	 * @return	int										<0 if KO, >0 if OK
348
-	 */
349
-	function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
350
-	{
338
+    /**
339
+     * Insert a record into database
340
+     *
341
+     * @param	array	$arrayrecord					Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
342
+     * @param	array	$array_match_file_to_database	Array of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]...
343
+     * @param 	Object	$objimport						Object import (contains objimport->array_import_tables, objimport->array_import_fields, objimport->array_import_convertvalue, ...)
344
+     * @param	int		$maxfields						Max number of fields to use
345
+     * @param	string	$importid						Import key
346
+     * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
347
+     * @return	int										<0 if KO, >0 if OK
348
+     */
349
+    function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
350
+    {
351 351
         // phpcs:enable
352
-		global $langs,$conf,$user;
352
+        global $langs,$conf,$user;
353 353
         global $thirdparty_static;    	// Specific to thirdparty import
354
-		global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
355
-
356
-		$error=0;
357
-		$warning=0;
358
-		$this->errors=array();
359
-		$this->warnings=array();
360
-
361
-		//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
362
-
363
-		//var_dump($array_match_file_to_database);
364
-		//var_dump($arrayrecord);
365
-		$array_match_database_to_file=array_flip($array_match_file_to_database);
366
-		$sort_array_match_file_to_database=$array_match_file_to_database;
367
-		ksort($sort_array_match_file_to_database);
368
-
369
-		//var_dump($sort_array_match_file_to_database);
370
-
371
-		if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
372
-		{
373
-			//print 'W';
374
-			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
375
-			$this->warnings[$warning]['type']='EMPTY';
376
-			$warning++;
377
-		}
378
-		else
379
-		{
380
-			$last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
381
-			$updatedone = false;
382
-			$insertdone = false;
383
-			// For each table to insert, me make a separate insert
384
-			foreach($objimport->array_import_tables[0] as $alias => $tablename)
385
-			{
386
-				// Build sql request
387
-				$sql='';
388
-				$listfields=array();
389
-				$listvalues=array();
390
-				$i=0;
391
-				$errorforthistable=0;
392
-
393
-				// Define $tablewithentity_cache[$tablename] if not already defined
394
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
395
-				{
396
-					dol_syslog("Check if table ".$tablename." has an entity field");
397
-					$resql=$this->db->DDLDescTable($tablename,'entity');
398
-					if ($resql)
399
-					{
400
-						$obj=$this->db->fetch_object($resql);
401
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
402
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
403
-					}
404
-					else dol_print_error($this->db);
405
-				}
406
-				else
407
-				{
408
-					//dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
409
-				}
410
-
411
-
412
-				// Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
413
-				foreach($sort_array_match_file_to_database as $key => $val)
414
-				{
415
-				    $fieldalias=preg_replace('/\..*$/i','',$val);
416
-				    $fieldname=preg_replace('/^.*\./i','',$val);
417
-
418
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
419
-
420
-					if ($key <= $maxfields)
421
-					{
422
-						// Set $newval with value to insert and set $listvalues with sql request part for insert
423
-						$newval='';
424
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
425
-
426
-						// Make some tests on $newval
427
-
428
-						// Is it a required field ?
429
-						if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
430
-						{
431
-							$this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
432
-							$this->errors[$error]['type']='NOTNULL';
433
-							$errorforthistable++;
434
-							$error++;
435
-						}
436
-						// Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
437
-						else
438
-						{
439
-						    // We convert field if required
440
-						    if (! empty($objimport->array_import_convertvalue[0][$val]))
441
-						    {
354
+        global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
355
+
356
+        $error=0;
357
+        $warning=0;
358
+        $this->errors=array();
359
+        $this->warnings=array();
360
+
361
+        //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
362
+
363
+        //var_dump($array_match_file_to_database);
364
+        //var_dump($arrayrecord);
365
+        $array_match_database_to_file=array_flip($array_match_file_to_database);
366
+        $sort_array_match_file_to_database=$array_match_file_to_database;
367
+        ksort($sort_array_match_file_to_database);
368
+
369
+        //var_dump($sort_array_match_file_to_database);
370
+
371
+        if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
372
+        {
373
+            //print 'W';
374
+            $this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
375
+            $this->warnings[$warning]['type']='EMPTY';
376
+            $warning++;
377
+        }
378
+        else
379
+        {
380
+            $last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
381
+            $updatedone = false;
382
+            $insertdone = false;
383
+            // For each table to insert, me make a separate insert
384
+            foreach($objimport->array_import_tables[0] as $alias => $tablename)
385
+            {
386
+                // Build sql request
387
+                $sql='';
388
+                $listfields=array();
389
+                $listvalues=array();
390
+                $i=0;
391
+                $errorforthistable=0;
392
+
393
+                // Define $tablewithentity_cache[$tablename] if not already defined
394
+                if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
395
+                {
396
+                    dol_syslog("Check if table ".$tablename." has an entity field");
397
+                    $resql=$this->db->DDLDescTable($tablename,'entity');
398
+                    if ($resql)
399
+                    {
400
+                        $obj=$this->db->fetch_object($resql);
401
+                        if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
402
+                        else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
403
+                    }
404
+                    else dol_print_error($this->db);
405
+                }
406
+                else
407
+                {
408
+                    //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
409
+                }
410
+
411
+
412
+                // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
413
+                foreach($sort_array_match_file_to_database as $key => $val)
414
+                {
415
+                    $fieldalias=preg_replace('/\..*$/i','',$val);
416
+                    $fieldname=preg_replace('/^.*\./i','',$val);
417
+
418
+                    if ($alias != $fieldalias) continue;    // Not a field of current table
419
+
420
+                    if ($key <= $maxfields)
421
+                    {
422
+                        // Set $newval with value to insert and set $listvalues with sql request part for insert
423
+                        $newval='';
424
+                        if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
425
+
426
+                        // Make some tests on $newval
427
+
428
+                        // Is it a required field ?
429
+                        if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
430
+                        {
431
+                            $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
432
+                            $this->errors[$error]['type']='NOTNULL';
433
+                            $errorforthistable++;
434
+                            $error++;
435
+                        }
436
+                        // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
437
+                        else
438
+                        {
439
+                            // We convert field if required
440
+                            if (! empty($objimport->array_import_convertvalue[0][$val]))
441
+                            {
442 442
                                 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
443 443
                                 if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid'
444
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
445
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
446
-                                	)
444
+                                    || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
445
+                                    || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
446
+                                    )
447 447
                                 {
448 448
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
449 449
                                     $isidorref='id';
@@ -458,10 +458,10 @@  discard block
 block discarded – undo
458 458
                                         $method=$objimport->array_import_convertvalue[0][$val]['method'];
459 459
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
460 460
                                         {
461
-                                        	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
461
+                                            $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
462 462
                                         }
463 463
                                         else
464
-										{
464
+                                        {
465 465
                                             $resultload = dol_include_once($file);
466 466
                                             if (empty($resultload))
467 467
                                             {
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
                                             // If not found, try the fetch from label
475 475
                                             if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
476 476
                                             {
477
-												call_user_func_array(array($classinstance, $method),array('', '', $newval));
477
+                                                call_user_func_array(array($classinstance, $method),array('', '', $newval));
478 478
                                             }
479 479
                                             $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
480 480
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
@@ -561,257 +561,257 @@  discard block
 block discarded – undo
561 561
                                 }
562 562
 
563 563
                                 //print 'Val to use as insert is '.$newval.'<br>';
564
-						    }
565
-
566
-						    // Test regexp
567
-							if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
568
-							{
569
-								// If test is "Must exist in a field@table"
570
-								if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
571
-								{
572
-									$field=$reg[1];
573
-									$table=$reg[2];
574
-
575
-									// Load content of field@table into cache array
576
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
577
-									{
578
-										$sql="SELECT ".$field." as aliasfield FROM ".$table;
579
-										$resql=$this->db->query($sql);
580
-										if ($resql)
581
-										{
582
-											$num=$this->db->num_rows($resql);
583
-											$i=0;
584
-											while ($i < $num)
585
-											{
586
-												$obj=$this->db->fetch_object($resql);
587
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
588
-												$i++;
589
-											}
590
-										}
591
-										else
592
-										{
593
-											dol_print_error($this->db);
594
-										}
595
-									}
596
-
597
-									// Now we check cache is not empty (should not) and key is into cache
598
-									if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
599
-									{
600
-										$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
601
-										$this->errors[$error]['type']='FOREIGNKEY';
602
-									    $errorforthistable++;
603
-										$error++;
604
-									}
605
-								}
606
-								// If test is just a static regex
607
-								else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
608
-								{
609
-								    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
610
-									$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
611
-									$this->errors[$error]['type']='REGEX';
612
-									$errorforthistable++;
613
-									$error++;
614
-								}
615
-							}
616
-
617
-							// Other tests
618
-							// ...
619
-						}
620
-
621
-						// Define $listfields and $listvalues to build SQL request
622
-						$listfields[] = $fieldname;
623
-
624
-						// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
625
-						if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0)		 $listvalues[] = ($newval=='0'?$newval:"null");
626
-						elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0)	 $listvalues[] = "''";
627
-						else															 $listvalues[] = "'".$this->db->escape($newval)."'";
628
-					}
629
-					$i++;
630
-				}
631
-
632
-				// We add hidden fields (but only if there is at least one field to add into table)
633
-				if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
634
-				{
635
-    				// Loop on each hidden fields to add them into listfields/listvalues
636
-				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
637
-    				{
638
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
639
-    				    if ($val == 'user->id')
640
-    				    {
641
-    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
642
-    				        $listvalues[] = $user->id;
643
-    				    }
644
-    				    elseif (preg_match('/^lastrowid-/',$val))
645
-    				    {
646
-    				        $tmp=explode('-',$val);
647
-    				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
648
-							$keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
649
-    				        $listfields[] = $keyfield;
564
+                            }
565
+
566
+                            // Test regexp
567
+                            if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
568
+                            {
569
+                                // If test is "Must exist in a field@table"
570
+                                if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
571
+                                {
572
+                                    $field=$reg[1];
573
+                                    $table=$reg[2];
574
+
575
+                                    // Load content of field@table into cache array
576
+                                    if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
577
+                                    {
578
+                                        $sql="SELECT ".$field." as aliasfield FROM ".$table;
579
+                                        $resql=$this->db->query($sql);
580
+                                        if ($resql)
581
+                                        {
582
+                                            $num=$this->db->num_rows($resql);
583
+                                            $i=0;
584
+                                            while ($i < $num)
585
+                                            {
586
+                                                $obj=$this->db->fetch_object($resql);
587
+                                                if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
588
+                                                $i++;
589
+                                            }
590
+                                        }
591
+                                        else
592
+                                        {
593
+                                            dol_print_error($this->db);
594
+                                        }
595
+                                    }
596
+
597
+                                    // Now we check cache is not empty (should not) and key is into cache
598
+                                    if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
599
+                                    {
600
+                                        $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
601
+                                        $this->errors[$error]['type']='FOREIGNKEY';
602
+                                        $errorforthistable++;
603
+                                        $error++;
604
+                                    }
605
+                                }
606
+                                // If test is just a static regex
607
+                                else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
608
+                                {
609
+                                    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
610
+                                    $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
611
+                                    $this->errors[$error]['type']='REGEX';
612
+                                    $errorforthistable++;
613
+                                    $error++;
614
+                                }
615
+                            }
616
+
617
+                            // Other tests
618
+                            // ...
619
+                        }
620
+
621
+                        // Define $listfields and $listvalues to build SQL request
622
+                        $listfields[] = $fieldname;
623
+
624
+                        // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
625
+                        if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0)		 $listvalues[] = ($newval=='0'?$newval:"null");
626
+                        elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0)	 $listvalues[] = "''";
627
+                        else															 $listvalues[] = "'".$this->db->escape($newval)."'";
628
+                    }
629
+                    $i++;
630
+                }
631
+
632
+                // We add hidden fields (but only if there is at least one field to add into table)
633
+                if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
634
+                {
635
+                    // Loop on each hidden fields to add them into listfields/listvalues
636
+                    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
637
+                    {
638
+                        if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
639
+                        if ($val == 'user->id')
640
+                        {
641
+                            $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
642
+                            $listvalues[] = $user->id;
643
+                        }
644
+                        elseif (preg_match('/^lastrowid-/',$val))
645
+                        {
646
+                            $tmp=explode('-',$val);
647
+                            $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
648
+                            $keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
649
+                            $listfields[] = $keyfield;
650 650
                             $listvalues[] = $lastinsertid;
651
-    				        //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
652
-    				    }
653
-    				}
654
-				}
655
-				//print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
656
-
657
-				// If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
658
-				// so we can try to make the insert or update now.
659
-				if (! $errorforthistable)
660
-				{
661
-					//print "$alias/$tablename/$listfields/$listvalues<br>";
662
-					if (!empty($listfields))
663
-					{
664
-						$updatedone = false;
665
-						$insertdone = false;
666
-						if (!empty($updatekeys)) {
667
-							// We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
668
-
669
-							if (empty($lastinsertid)) {	// No insert done yet for a parent table
670
-								$sqlSelect = 'SELECT rowid FROM '.$tablename;
671
-
672
-								$data = array_combine($listfields, $listvalues);
673
-								$where = array();
674
-								$filters = array();
675
-								foreach ($updatekeys as $key) {
676
-									$col = $objimport->array_import_updatekeys[0][$key];
677
-									$key=preg_replace('/^.*\./i','',$key);
678
-									$where[] = $key.' = '.$data[$key];
679
-									$filters[] = $col.' = '.$data[$key];
680
-								}
681
-								$sqlSelect.= ' WHERE '.implode(' AND ', $where);
682
-
683
-								$resql=$this->db->query($sqlSelect);
684
-								if($resql) {
685
-									$res = $this->db->fetch_object($resql);
686
-									if($resql->num_rows == 1) {
687
-										$lastinsertid = $res->rowid;
688
-										$last_insert_id_array[$tablename] = $lastinsertid;
689
-									} else if($resql->num_rows > 1) {
690
-										$this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
691
-										$this->errors[$error]['type']='SQL';
692
-										$error++;
693
-									} else {
694
-										// No record found with filters, insert will be tried below
695
-									}
696
-								}
697
-								else
698
-								{
699
-									//print 'E';
700
-									$this->errors[$error]['lib']=$this->db->lasterror();
701
-									$this->errors[$error]['type']='SQL';
702
-									$error++;
703
-								}
704
-							} else {
705
-								// We have a last INSERT ID. Check if we have a row referencing this foreign key.
706
-								// This is required when updating table with some extrafields. When inserting a record in parent table, we can make
707
-								// a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
708
-								// may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
709
-								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
710
-								$sqlSelect = 'SELECT rowid FROM '.$tablename;
711
-
712
-								if(empty($keyfield)) $keyfield = 'rowid';
713
-								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
714
-
715
-								$resql=$this->db->query($sqlSelect);
716
-								if($resql) {
717
-									$res = $this->db->fetch_object($resql);
718
-									if($resql->num_rows == 1) {
719
-										// We have a row referencing this last foreign key, continue with UPDATE.
720
-									} else {
721
-										// No record found referencing this last foreign key,
722
-										// force $lastinsertid to 0 so we INSERT below.
723
-										$lastinsertid = 0;
724
-									}
725
-								}
726
-								else
727
-								{
728
-									//print 'E';
729
-									$this->errors[$error]['lib']=$this->db->lasterror();
730
-									$this->errors[$error]['type']='SQL';
731
-									$error++;
732
-								}
733
-							}
734
-
735
-							if (!empty($lastinsertid)) {
736
-								// Build SQL UPDATE request
737
-								$sqlstart = 'UPDATE '.$tablename;
738
-
739
-								$data = array_combine($listfields, $listvalues);
740
-								$set = array();
741
-								foreach ($data as $key => $val) {
742
-									$set[] = $key.' = '.$val;
743
-								}
744
-								$sqlstart.= ' SET '.implode(', ', $set);
745
-
746
-								if(empty($keyfield)) $keyfield = 'rowid';
747
-								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
748
-
749
-								$sql = $sqlstart.$sqlend;
750
-
751
-								// Run update request
752
-								$resql=$this->db->query($sql);
753
-								if($resql) {
754
-									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
755
-									$updatedone = true;
756
-								}
757
-								else
758
-								{
759
-									//print 'E';
760
-									$this->errors[$error]['lib']=$this->db->lasterror();
761
-									$this->errors[$error]['type']='SQL';
762
-									$error++;
763
-								}
764
-							}
765
-						}
766
-
767
-						// Update not done, we do insert
768
-						if (!$error && !$updatedone) {
769
-							// Build SQL INSERT request
770
-							$sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
771
-							$sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
772
-							if (! empty($tablewithentity_cache[$tablename])) {
773
-								$sqlstart.= ', entity';
774
-								$sqlend.= ', '.$conf->entity;
775
-							}
776
-							if (! empty($objimport->array_import_tables_creator[0][$alias])) {
777
-								$sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
778
-								$sqlend.=', '.$user->id;
779
-							}
780
-							$sql = $sqlstart.$sqlend.')';
781
-							dol_syslog("import_xlsx.modules", LOG_DEBUG);
782
-
783
-							// Run insert request
784
-							if ($sql)
785
-							{
786
-								$resql=$this->db->query($sql);
787
-								if ($resql)
788
-								{
789
-								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
790
-								    $insertdone = true;
791
-								}
792
-								else
793
-								{
794
-									//print 'E';
795
-									$this->errors[$error]['lib']=$this->db->lasterror();
796
-									$this->errors[$error]['type']='SQL';
797
-									$error++;
798
-								}
799
-							}
800
-						}
801
-					}
802
-					/*else
651
+                            //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
652
+                        }
653
+                    }
654
+                }
655
+                //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
656
+
657
+                // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
658
+                // so we can try to make the insert or update now.
659
+                if (! $errorforthistable)
660
+                {
661
+                    //print "$alias/$tablename/$listfields/$listvalues<br>";
662
+                    if (!empty($listfields))
663
+                    {
664
+                        $updatedone = false;
665
+                        $insertdone = false;
666
+                        if (!empty($updatekeys)) {
667
+                            // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
668
+
669
+                            if (empty($lastinsertid)) {	// No insert done yet for a parent table
670
+                                $sqlSelect = 'SELECT rowid FROM '.$tablename;
671
+
672
+                                $data = array_combine($listfields, $listvalues);
673
+                                $where = array();
674
+                                $filters = array();
675
+                                foreach ($updatekeys as $key) {
676
+                                    $col = $objimport->array_import_updatekeys[0][$key];
677
+                                    $key=preg_replace('/^.*\./i','',$key);
678
+                                    $where[] = $key.' = '.$data[$key];
679
+                                    $filters[] = $col.' = '.$data[$key];
680
+                                }
681
+                                $sqlSelect.= ' WHERE '.implode(' AND ', $where);
682
+
683
+                                $resql=$this->db->query($sqlSelect);
684
+                                if($resql) {
685
+                                    $res = $this->db->fetch_object($resql);
686
+                                    if($resql->num_rows == 1) {
687
+                                        $lastinsertid = $res->rowid;
688
+                                        $last_insert_id_array[$tablename] = $lastinsertid;
689
+                                    } else if($resql->num_rows > 1) {
690
+                                        $this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
691
+                                        $this->errors[$error]['type']='SQL';
692
+                                        $error++;
693
+                                    } else {
694
+                                        // No record found with filters, insert will be tried below
695
+                                    }
696
+                                }
697
+                                else
698
+                                {
699
+                                    //print 'E';
700
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
701
+                                    $this->errors[$error]['type']='SQL';
702
+                                    $error++;
703
+                                }
704
+                            } else {
705
+                                // We have a last INSERT ID. Check if we have a row referencing this foreign key.
706
+                                // This is required when updating table with some extrafields. When inserting a record in parent table, we can make
707
+                                // a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
708
+                                // may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
709
+                                // Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
710
+                                $sqlSelect = 'SELECT rowid FROM '.$tablename;
711
+
712
+                                if(empty($keyfield)) $keyfield = 'rowid';
713
+                                $sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
714
+
715
+                                $resql=$this->db->query($sqlSelect);
716
+                                if($resql) {
717
+                                    $res = $this->db->fetch_object($resql);
718
+                                    if($resql->num_rows == 1) {
719
+                                        // We have a row referencing this last foreign key, continue with UPDATE.
720
+                                    } else {
721
+                                        // No record found referencing this last foreign key,
722
+                                        // force $lastinsertid to 0 so we INSERT below.
723
+                                        $lastinsertid = 0;
724
+                                    }
725
+                                }
726
+                                else
727
+                                {
728
+                                    //print 'E';
729
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
730
+                                    $this->errors[$error]['type']='SQL';
731
+                                    $error++;
732
+                                }
733
+                            }
734
+
735
+                            if (!empty($lastinsertid)) {
736
+                                // Build SQL UPDATE request
737
+                                $sqlstart = 'UPDATE '.$tablename;
738
+
739
+                                $data = array_combine($listfields, $listvalues);
740
+                                $set = array();
741
+                                foreach ($data as $key => $val) {
742
+                                    $set[] = $key.' = '.$val;
743
+                                }
744
+                                $sqlstart.= ' SET '.implode(', ', $set);
745
+
746
+                                if(empty($keyfield)) $keyfield = 'rowid';
747
+                                $sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
748
+
749
+                                $sql = $sqlstart.$sqlend;
750
+
751
+                                // Run update request
752
+                                $resql=$this->db->query($sql);
753
+                                if($resql) {
754
+                                    // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
755
+                                    $updatedone = true;
756
+                                }
757
+                                else
758
+                                {
759
+                                    //print 'E';
760
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
761
+                                    $this->errors[$error]['type']='SQL';
762
+                                    $error++;
763
+                                }
764
+                            }
765
+                        }
766
+
767
+                        // Update not done, we do insert
768
+                        if (!$error && !$updatedone) {
769
+                            // Build SQL INSERT request
770
+                            $sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
771
+                            $sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
772
+                            if (! empty($tablewithentity_cache[$tablename])) {
773
+                                $sqlstart.= ', entity';
774
+                                $sqlend.= ', '.$conf->entity;
775
+                            }
776
+                            if (! empty($objimport->array_import_tables_creator[0][$alias])) {
777
+                                $sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
778
+                                $sqlend.=', '.$user->id;
779
+                            }
780
+                            $sql = $sqlstart.$sqlend.')';
781
+                            dol_syslog("import_xlsx.modules", LOG_DEBUG);
782
+
783
+                            // Run insert request
784
+                            if ($sql)
785
+                            {
786
+                                $resql=$this->db->query($sql);
787
+                                if ($resql)
788
+                                {
789
+                                    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
790
+                                    $insertdone = true;
791
+                                }
792
+                                else
793
+                                {
794
+                                    //print 'E';
795
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
796
+                                    $this->errors[$error]['type']='SQL';
797
+                                    $error++;
798
+                                }
799
+                            }
800
+                        }
801
+                    }
802
+                    /*else
803 803
 					{
804 804
 						dol_print_error('','ErrorFieldListEmptyFor '.$alias."/".$tablename);
805 805
 					}*/
806
-				}
806
+                }
807 807
 
808
-			    if ($error) break;
809
-			}
808
+                if ($error) break;
809
+            }
810 810
 
811
-			if($updatedone) $this->nbupdate++;
812
-			if($insertdone) $this->nbinsert++;
813
-		}
811
+            if($updatedone) $this->nbupdate++;
812
+            if($insertdone) $this->nbinsert++;
813
+        }
814 814
 
815
-		return 1;
816
-	}
815
+        return 1;
816
+    }
817 817
 }
Please login to merge, or discard this patch.
Spacing   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *		\brief      File to load import files with Excel format
26 26
  */
27 27
 
28
-require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php';
28
+require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
29 29
 
30 30
 
31 31
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     /**
44 44
 	 * @var string Error code (or message)
45 45
 	 */
46
-	public $error='';
46
+	public $error = '';
47 47
 
48 48
 	/**
49 49
 	 * @var string[] Error codes (or messages)
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public $label;
62 62
 
63
-	public $extension;    // Extension of files imported by driver
63
+	public $extension; // Extension of files imported by driver
64 64
 
65 65
 	/**
66 66
      * Dolibarr version of driver
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
      */
69 69
 	public $version = 'dolibarr';
70 70
 
71
-	public $label_lib;    // Label of external lib used by driver
71
+	public $label_lib; // Label of external lib used by driver
72 72
 
73
-	public $version_lib;  // Version of external lib used by driver
73
+	public $version_lib; // Version of external lib used by driver
74 74
 
75 75
 	public $separator;
76 76
 
77
-    public $file;      // Path of file
77
+    public $file; // Path of file
78 78
 
79
-	public $handle;    // Handle fichier
79
+	public $handle; // Handle fichier
80 80
 
81
-	public $cacheconvert=array();      // Array to cache list of value found after a convertion
81
+	public $cacheconvert = array(); // Array to cache list of value found after a convertion
82 82
 
83
-	public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
83
+	public $cachefieldtable = array(); // Array to cache list of value found into fields@tables
84 84
 
85 85
 	public $workbook; // temporary import file
86 86
 
@@ -95,33 +95,33 @@  discard block
 block discarded – undo
95 95
 	 *	@param	DoliDB		$db				Database handler
96 96
 	 *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
97 97
 	 */
98
-	function __construct($db,$datatoimport)
98
+	function __construct($db, $datatoimport)
99 99
 	{
100
-		global $conf,$langs;
100
+		global $conf, $langs;
101 101
 		$this->db = $db;
102 102
 
103 103
 		// this is used as an extension from the example file code, so we have to put xlsx here !!!
104
-		$this->id='xlsx';                // Same value as xxx in file name export_xxx.modules.php
105
-		$this->label='Excel 2007';             // Label of driver
106
-		$this->desc=$langs->trans("Excel2007FormatDesc");
107
-		$this->extension='xlsx';         // Extension for generated file by this driver
108
-		$this->picto='mime/xls';		// Picto (This is not used by the example file code as Mime type, too bad ...)
109
-		$this->version='1.0';         // Driver version
104
+		$this->id = 'xlsx'; // Same value as xxx in file name export_xxx.modules.php
105
+		$this->label = 'Excel 2007'; // Label of driver
106
+		$this->desc = $langs->trans("Excel2007FormatDesc");
107
+		$this->extension = 'xlsx'; // Extension for generated file by this driver
108
+		$this->picto = 'mime/xls'; // Picto (This is not used by the example file code as Mime type, too bad ...)
109
+		$this->version = '1.0'; // Driver version
110 110
 
111 111
 		// If driver use an external library, put its name here
112 112
         require_once PHPEXCEL_PATH.'PHPExcel.php';
113 113
 		require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php';
114
-        if (! class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive
114
+        if (!class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive
115 115
         {
116 116
                 $langs->load("errors");
117
-                $this->error=$langs->trans('ErrorPHPNeedModule','zip');
117
+                $this->error = $langs->trans('ErrorPHPNeedModule', 'zip');
118 118
                 return -1;
119 119
         }
120
-        $this->label_lib='PhpExcel';
121
-        $this->version_lib='1.8.0';
120
+        $this->label_lib = 'PhpExcel';
121
+        $this->version_lib = '1.8.0';
122 122
 
123
-		$this->datatoimport=$datatoimport;
124
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
123
+		$this->datatoimport = $datatoimport;
124
+		if (preg_match('/^societe_/', $datatoimport)) $this->thirpartyobject = new Societe($this->db);
125 125
 	}
126 126
 
127 127
 
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
 	function write_header_example($outputlangs)
136 136
 	{
137 137
         // phpcs:enable
138
-        global $user,$conf,$langs;
138
+        global $user, $conf, $langs;
139 139
         // create a temporary object, the final output will be generated in footer
140 140
         if (!empty($conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR)) {
141 141
             $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
142
-            $cacheSettings = array (
142
+            $cacheSettings = array(
143 143
                 'dir' => $conf->global->MAIN_USE_FILECACHE_EXPORT_EXCEL_DIR
144 144
             );
145 145
             PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 *  @param	array		$headerlinefields	Array of fields name
167 167
 	 * 	@return	string
168 168
 	 */
169
-	function write_title_example($outputlangs,$headerlinefields)
169
+	function write_title_example($outputlangs, $headerlinefields)
170 170
 	{
171 171
         // phpcs:enable
172 172
 		global $conf;
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 		$this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
175 175
 
176 176
 		$col = 0;
177
-		foreach($headerlinefields as $field) {
177
+		foreach ($headerlinefields as $field) {
178 178
 			$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, 1, $outputlangs->transnoentities($field));
179 179
 			// set autowidth
180 180
 			//$this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($col + 1))->setAutoSize(true);
@@ -192,12 +192,12 @@  discard block
 block discarded – undo
192 192
 	 * 	@param	array		$contentlinevalues	Array of lines
193 193
 	 * 	@return	string
194 194
 	 */
195
-	function write_record_example($outputlangs,$contentlinevalues)
195
+	function write_record_example($outputlangs, $contentlinevalues)
196 196
 	{
197 197
         // phpcs:enable
198 198
 		$col = 0;
199 199
 		$row = 2;
200
-		foreach($contentlinevalues as $cell) {
200
+		foreach ($contentlinevalues as $cell) {
201 201
 			$this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, $row, $cell);
202 202
 			$col++;
203 203
 		}
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	{
241 241
         // phpcs:enable
242 242
 		global $langs;
243
-		$ret=1;
243
+		$ret = 1;
244 244
 
245 245
 		dol_syslog(get_class($this)."::open_file file=".$file);
246 246
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 		// This is not called by the import code !!!
288 288
 		$this->headers = array();
289 289
 		$colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn());
290
-		for($col=0;$col<$colcount;$col++) {
290
+		for ($col = 0; $col < $colcount; $col++) {
291 291
 			$this->headers[$col] = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, 1)->getValue();
292 292
 		}
293 293
 		return 0;
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
 		global $conf;
307 307
 
308 308
 		$rowcount = $this->workbook->getActiveSheet()->getHighestDataRow();
309
-		if($this->record > $rowcount)
309
+		if ($this->record > $rowcount)
310 310
 			return false;
311 311
 		$array = array();
312 312
 		$colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn(0));
313
-		for($col=0;$col<$colcount;$col++) {
313
+		for ($col = 0; $col < $colcount; $col++) {
314 314
 			$val = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $this->record)->getValue();
315 315
 			$array[$col]['val'] = $val;
316
-			$array[$col]['type'] = (dol_strlen($val)?1:-1); // If empty we consider it null
316
+			$array[$col]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it null
317 317
 		}
318 318
 		$this->record++;
319 319
 		return $array;
@@ -346,24 +346,24 @@  discard block
 block discarded – undo
346 346
 	 * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
347 347
 	 * @return	int										<0 if KO, >0 if OK
348 348
 	 */
349
-	function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
349
+	function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
350 350
 	{
351 351
         // phpcs:enable
352
-		global $langs,$conf,$user;
353
-        global $thirdparty_static;    	// Specific to thirdparty import
354
-		global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
352
+		global $langs, $conf, $user;
353
+        global $thirdparty_static; // Specific to thirdparty import
354
+		global $tablewithentity_cache; // Cache to avoid to call  desc at each rows on tables
355 355
 
356
-		$error=0;
357
-		$warning=0;
358
-		$this->errors=array();
359
-		$this->warnings=array();
356
+		$error = 0;
357
+		$warning = 0;
358
+		$this->errors = array();
359
+		$this->warnings = array();
360 360
 
361 361
 		//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
362 362
 
363 363
 		//var_dump($array_match_file_to_database);
364 364
 		//var_dump($arrayrecord);
365
-		$array_match_database_to_file=array_flip($array_match_file_to_database);
366
-		$sort_array_match_file_to_database=$array_match_file_to_database;
365
+		$array_match_database_to_file = array_flip($array_match_file_to_database);
366
+		$sort_array_match_file_to_database = $array_match_file_to_database;
367 367
 		ksort($sort_array_match_file_to_database);
368 368
 
369 369
 		//var_dump($sort_array_match_file_to_database);
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 		if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
372 372
 		{
373 373
 			//print 'W';
374
-			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
375
-			$this->warnings[$warning]['type']='EMPTY';
374
+			$this->warnings[$warning]['lib'] = $langs->trans('EmptyLine');
375
+			$this->warnings[$warning]['type'] = 'EMPTY';
376 376
 			$warning++;
377 377
 		}
378 378
 		else
@@ -381,25 +381,25 @@  discard block
 block discarded – undo
381 381
 			$updatedone = false;
382 382
 			$insertdone = false;
383 383
 			// For each table to insert, me make a separate insert
384
-			foreach($objimport->array_import_tables[0] as $alias => $tablename)
384
+			foreach ($objimport->array_import_tables[0] as $alias => $tablename)
385 385
 			{
386 386
 				// Build sql request
387
-				$sql='';
388
-				$listfields=array();
389
-				$listvalues=array();
390
-				$i=0;
391
-				$errorforthistable=0;
387
+				$sql = '';
388
+				$listfields = array();
389
+				$listvalues = array();
390
+				$i = 0;
391
+				$errorforthistable = 0;
392 392
 
393 393
 				// Define $tablewithentity_cache[$tablename] if not already defined
394
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
394
+				if (!isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
395 395
 				{
396 396
 					dol_syslog("Check if table ".$tablename." has an entity field");
397
-					$resql=$this->db->DDLDescTable($tablename,'entity');
397
+					$resql = $this->db->DDLDescTable($tablename, 'entity');
398 398
 					if ($resql)
399 399
 					{
400
-						$obj=$this->db->fetch_object($resql);
401
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
402
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
400
+						$obj = $this->db->fetch_object($resql);
401
+						if ($obj) $tablewithentity_cache[$tablename] = 1; // table contains entity field
402
+						else $tablewithentity_cache[$tablename] = 0; // table does not contains entity field
403 403
 					}
404 404
 					else dol_print_error($this->db);
405 405
 				}
@@ -410,26 +410,26 @@  discard block
 block discarded – undo
410 410
 
411 411
 
412 412
 				// Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
413
-				foreach($sort_array_match_file_to_database as $key => $val)
413
+				foreach ($sort_array_match_file_to_database as $key => $val)
414 414
 				{
415
-				    $fieldalias=preg_replace('/\..*$/i','',$val);
416
-				    $fieldname=preg_replace('/^.*\./i','',$val);
415
+				    $fieldalias = preg_replace('/\..*$/i', '', $val);
416
+				    $fieldname = preg_replace('/^.*\./i', '', $val);
417 417
 
418
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
418
+				    if ($alias != $fieldalias) continue; // Not a field of current table
419 419
 
420 420
 					if ($key <= $maxfields)
421 421
 					{
422 422
 						// Set $newval with value to insert and set $listvalues with sql request part for insert
423
-						$newval='';
424
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
423
+						$newval = '';
424
+						if ($arrayrecord[($key - 1)]['type'] > 0) $newval = $arrayrecord[($key - 1)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value
425 425
 
426 426
 						// Make some tests on $newval
427 427
 
428 428
 						// Is it a required field ?
429
-						if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
429
+						if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == ''))
430 430
 						{
431
-							$this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
432
-							$this->errors[$error]['type']='NOTNULL';
431
+							$this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', $key);
432
+							$this->errors[$error]['type'] = 'NOTNULL';
433 433
 							$errorforthistable++;
434 434
 							$error++;
435 435
 						}
@@ -437,28 +437,28 @@  discard block
 block discarded – undo
437 437
 						else
438 438
 						{
439 439
 						    // We convert field if required
440
-						    if (! empty($objimport->array_import_convertvalue[0][$val]))
440
+						    if (!empty($objimport->array_import_convertvalue[0][$val]))
441 441
 						    {
442 442
                                 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
443
-                                if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid'
444
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
445
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
443
+                                if ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeid'
444
+                                	|| $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromref'
445
+                                	|| $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel'
446 446
                                 	)
447 447
                                 {
448 448
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
449
-                                    $isidorref='id';
450
-                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref';
451
-                                    $newval=preg_replace('/^(id|ref):/i','',$newval);    // Remove id: or ref: that was used to force if field is id or ref
449
+                                    $isidorref = 'id';
450
+                                    if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) $isidorref = 'ref';
451
+                                    $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref
452 452
                                     //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n";
453 453
 
454 454
                                     if ($isidorref == 'ref')    // If value into input import file is a ref, we apply the function defined into descriptor
455 455
                                     {
456
-                                        $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']);
457
-                                        $class=$objimport->array_import_convertvalue[0][$val]['class'];
458
-                                        $method=$objimport->array_import_convertvalue[0][$val]['method'];
456
+                                        $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
457
+                                        $class = $objimport->array_import_convertvalue[0][$val]['class'];
458
+                                        $method = $objimport->array_import_convertvalue[0][$val]['method'];
459 459
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
460 460
                                         {
461
-                                        	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
461
+                                        	$newval = $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
462 462
                                         }
463 463
                                         else
464 464
 										{
@@ -468,94 +468,94 @@  discard block
 block discarded – undo
468 468
                                                 dol_print_error('', 'Error trying to call file='.$file.', class='.$class.', method='.$method);
469 469
                                                 break;
470 470
                                             }
471
-                                            $classinstance=new $class($this->db);
471
+                                            $classinstance = new $class($this->db);
472 472
                                             // Try the fetch from code or ref
473
-                                            call_user_func_array(array($classinstance, $method),array('', $newval));
473
+                                            call_user_func_array(array($classinstance, $method), array('', $newval));
474 474
                                             // If not found, try the fetch from label
475
-                                            if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
475
+                                            if (!($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel')
476 476
                                             {
477
-												call_user_func_array(array($classinstance, $method),array('', '', $newval));
477
+												call_user_func_array(array($classinstance, $method), array('', '', $newval));
478 478
                                             }
479
-                                            $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
479
+                                            $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] = $classinstance->id;
480 480
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
481 481
                                             if ($classinstance->id != '')	// id may be 0, it is a found value
482 482
                                             {
483
-                                                $newval=$classinstance->id;
483
+                                                $newval = $classinstance->id;
484 484
                                             }
485 485
                                             else
486 486
                                             {
487
-                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
488
-                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
489
-                                                else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
490
-                                                $this->errors[$error]['type']='FOREIGNKEY';
487
+                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', $key, $newval, 'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
488
+                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib'] = $langs->trans('ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
489
+                                                else $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
490
+                                                $this->errors[$error]['type'] = 'FOREIGNKEY';
491 491
                                                 $errorforthistable++;
492 492
                                                 $error++;
493 493
                                             }
494 494
                                         }
495 495
                                     }
496 496
                                 }
497
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
497
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'zeroifnull')
498 498
                                 {
499
-                                    if (empty($newval)) $newval='0';
499
+                                    if (empty($newval)) $newval = '0';
500 500
                                 }
501
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
501
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomercodeifauto')
502 502
                                 {
503 503
                                     if (strtolower($newval) == 'auto')
504 504
                                     {
505
-                                        $this->thirpartyobject->get_codeclient(0,0);
506
-                                        $newval=$this->thirpartyobject->code_client;
505
+                                        $this->thirpartyobject->get_codeclient(0, 0);
506
+                                        $newval = $this->thirpartyobject->code_client;
507 507
                                         //print 'code_client='.$newval;
508 508
                                     }
509
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
509
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
510 510
                                 }
511
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
511
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto')
512 512
                                 {
513 513
                                     if (strtolower($newval) == 'auto')
514 514
                                     {
515
-                                        $newval=$this->thirpartyobject->get_codefournisseur(0,1);
516
-                                        $newval=$this->thirpartyobject->code_fournisseur;
515
+                                        $newval = $this->thirpartyobject->get_codefournisseur(0, 1);
516
+                                        $newval = $this->thirpartyobject->code_fournisseur;
517 517
                                         //print 'code_fournisseur='.$newval;
518 518
                                     }
519
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
519
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
520 520
                                 }
521
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
521
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto')
522 522
                                 {
523 523
                                     if (strtolower($newval) == 'auto')
524 524
                                     {
525 525
                                         $this->thirpartyobject->get_codecompta('customer');
526
-                                        $newval=$this->thirpartyobject->code_compta;
526
+                                        $newval = $this->thirpartyobject->code_compta;
527 527
                                         //print 'code_compta='.$newval;
528 528
                                     }
529
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
529
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
530 530
                                 }
531
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
531
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto')
532 532
                                 {
533 533
                                     if (strtolower($newval) == 'auto')
534 534
                                     {
535 535
                                         $this->thirpartyobject->get_codecompta('supplier');
536
-                                        $newval=$this->thirpartyobject->code_compta_fournisseur;
537
-                                        if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
536
+                                        $newval = $this->thirpartyobject->code_compta_fournisseur;
537
+                                        if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
538 538
                                         //print 'code_compta_fournisseur='.$newval;
539 539
                                     }
540
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
540
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
541 541
                                 }
542
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
542
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto')
543 543
                                 {
544
-                                    $defaultref='';
544
+                                    $defaultref = '';
545 545
                                     // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function
546
-                                    $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
547
-                                    if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
546
+                                    $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
547
+                                    if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
548 548
                                     {
549
-                                        require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
549
+                                        require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
550 550
                                         $modTask = new $obj;
551
-                                        $defaultref = $modTask->getNextValue(null,null);
551
+                                        $defaultref = $modTask->getNextValue(null, null);
552 552
                                     }
553
-                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
554
-                                    $newval=$defaultref;
553
+                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = '';
554
+                                    $newval = $defaultref;
555 555
                                 }
556 556
 
557 557
 
558
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
558
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric')
559 559
                                 {
560 560
                                     $newval = price2num($newval);
561 561
                                 }
@@ -564,27 +564,27 @@  discard block
 block discarded – undo
564 564
 						    }
565 565
 
566 566
 						    // Test regexp
567
-							if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
567
+							if (!empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
568 568
 							{
569 569
 								// If test is "Must exist in a field@table"
570
-								if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
570
+								if (preg_match('/^(.*)@(.*)$/', $objimport->array_import_regex[0][$val], $reg))
571 571
 								{
572
-									$field=$reg[1];
573
-									$table=$reg[2];
572
+									$field = $reg[1];
573
+									$table = $reg[2];
574 574
 
575 575
 									// Load content of field@table into cache array
576
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
576
+									if (!is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
577 577
 									{
578
-										$sql="SELECT ".$field." as aliasfield FROM ".$table;
579
-										$resql=$this->db->query($sql);
578
+										$sql = "SELECT ".$field." as aliasfield FROM ".$table;
579
+										$resql = $this->db->query($sql);
580 580
 										if ($resql)
581 581
 										{
582
-											$num=$this->db->num_rows($resql);
583
-											$i=0;
582
+											$num = $this->db->num_rows($resql);
583
+											$i = 0;
584 584
 											while ($i < $num)
585 585
 											{
586
-												$obj=$this->db->fetch_object($resql);
587
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
586
+												$obj = $this->db->fetch_object($resql);
587
+												if ($obj) $this->cachefieldtable[$field.'@'.$table][] = $obj->aliasfield;
588 588
 												$i++;
589 589
 											}
590 590
 										}
@@ -595,20 +595,20 @@  discard block
 block discarded – undo
595 595
 									}
596 596
 
597 597
 									// Now we check cache is not empty (should not) and key is into cache
598
-									if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
598
+									if (!is_array($this->cachefieldtable[$field.'@'.$table]) || !in_array($newval, $this->cachefieldtable[$field.'@'.$table]))
599 599
 									{
600
-										$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
601
-										$this->errors[$error]['type']='FOREIGNKEY';
600
+										$this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $table);
601
+										$this->errors[$error]['type'] = 'FOREIGNKEY';
602 602
 									    $errorforthistable++;
603 603
 										$error++;
604 604
 									}
605 605
 								}
606 606
 								// If test is just a static regex
607
-								else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
607
+								else if (!preg_match('/'.$objimport->array_import_regex[0][$val].'/i', $newval))
608 608
 								{
609 609
 								    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
610
-									$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
611
-									$this->errors[$error]['type']='REGEX';
610
+									$this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
611
+									$this->errors[$error]['type'] = 'REGEX';
612 612
 									$errorforthistable++;
613 613
 									$error++;
614 614
 								}
@@ -622,8 +622,8 @@  discard block
 block discarded – undo
622 622
 						$listfields[] = $fieldname;
623 623
 
624 624
 						// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
625
-						if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0)		 $listvalues[] = ($newval=='0'?$newval:"null");
626
-						elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0)	 $listvalues[] = "''";
625
+						if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0)		 $listvalues[] = ($newval == '0' ? $newval : "null");
626
+						elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0)	 $listvalues[] = "''";
627 627
 						else															 $listvalues[] = "'".$this->db->escape($newval)."'";
628 628
 					}
629 629
 					$i++;
@@ -633,19 +633,19 @@  discard block
 block discarded – undo
633 633
 				if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
634 634
 				{
635 635
     				// Loop on each hidden fields to add them into listfields/listvalues
636
-				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
636
+				    foreach ($objimport->array_import_fieldshidden[0] as $key => $val)
637 637
     				{
638
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
638
+    				    if (!preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table
639 639
     				    if ($val == 'user->id')
640 640
     				    {
641
-    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
641
+    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./', '', $key);
642 642
     				        $listvalues[] = $user->id;
643 643
     				    }
644
-    				    elseif (preg_match('/^lastrowid-/',$val))
644
+    				    elseif (preg_match('/^lastrowid-/', $val))
645 645
     				    {
646
-    				        $tmp=explode('-',$val);
647
-    				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
648
-							$keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
646
+    				        $tmp = explode('-', $val);
647
+    				        $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
648
+							$keyfield = preg_replace('/^'.preg_quote($alias).'\./', '', $key);
649 649
     				        $listfields[] = $keyfield;
650 650
                             $listvalues[] = $lastinsertid;
651 651
     				        //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
 
657 657
 				// If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
658 658
 				// so we can try to make the insert or update now.
659
-				if (! $errorforthistable)
659
+				if (!$errorforthistable)
660 660
 				{
661 661
 					//print "$alias/$tablename/$listfields/$listvalues<br>";
662 662
 					if (!empty($listfields))
@@ -674,21 +674,21 @@  discard block
 block discarded – undo
674 674
 								$filters = array();
675 675
 								foreach ($updatekeys as $key) {
676 676
 									$col = $objimport->array_import_updatekeys[0][$key];
677
-									$key=preg_replace('/^.*\./i','',$key);
677
+									$key = preg_replace('/^.*\./i', '', $key);
678 678
 									$where[] = $key.' = '.$data[$key];
679 679
 									$filters[] = $col.' = '.$data[$key];
680 680
 								}
681
-								$sqlSelect.= ' WHERE '.implode(' AND ', $where);
681
+								$sqlSelect .= ' WHERE '.implode(' AND ', $where);
682 682
 
683
-								$resql=$this->db->query($sqlSelect);
684
-								if($resql) {
683
+								$resql = $this->db->query($sqlSelect);
684
+								if ($resql) {
685 685
 									$res = $this->db->fetch_object($resql);
686
-									if($resql->num_rows == 1) {
686
+									if ($resql->num_rows == 1) {
687 687
 										$lastinsertid = $res->rowid;
688 688
 										$last_insert_id_array[$tablename] = $lastinsertid;
689
-									} else if($resql->num_rows > 1) {
690
-										$this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
691
-										$this->errors[$error]['type']='SQL';
689
+									} else if ($resql->num_rows > 1) {
690
+										$this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
691
+										$this->errors[$error]['type'] = 'SQL';
692 692
 										$error++;
693 693
 									} else {
694 694
 										// No record found with filters, insert will be tried below
@@ -697,8 +697,8 @@  discard block
 block discarded – undo
697 697
 								else
698 698
 								{
699 699
 									//print 'E';
700
-									$this->errors[$error]['lib']=$this->db->lasterror();
701
-									$this->errors[$error]['type']='SQL';
700
+									$this->errors[$error]['lib'] = $this->db->lasterror();
701
+									$this->errors[$error]['type'] = 'SQL';
702 702
 									$error++;
703 703
 								}
704 704
 							} else {
@@ -709,13 +709,13 @@  discard block
 block discarded – undo
709 709
 								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
710 710
 								$sqlSelect = 'SELECT rowid FROM '.$tablename;
711 711
 
712
-								if(empty($keyfield)) $keyfield = 'rowid';
712
+								if (empty($keyfield)) $keyfield = 'rowid';
713 713
 								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
714 714
 
715
-								$resql=$this->db->query($sqlSelect);
716
-								if($resql) {
715
+								$resql = $this->db->query($sqlSelect);
716
+								if ($resql) {
717 717
 									$res = $this->db->fetch_object($resql);
718
-									if($resql->num_rows == 1) {
718
+									if ($resql->num_rows == 1) {
719 719
 										// We have a row referencing this last foreign key, continue with UPDATE.
720 720
 									} else {
721 721
 										// No record found referencing this last foreign key,
@@ -726,8 +726,8 @@  discard block
 block discarded – undo
726 726
 								else
727 727
 								{
728 728
 									//print 'E';
729
-									$this->errors[$error]['lib']=$this->db->lasterror();
730
-									$this->errors[$error]['type']='SQL';
729
+									$this->errors[$error]['lib'] = $this->db->lasterror();
730
+									$this->errors[$error]['type'] = 'SQL';
731 731
 									$error++;
732 732
 								}
733 733
 							}
@@ -741,24 +741,24 @@  discard block
 block discarded – undo
741 741
 								foreach ($data as $key => $val) {
742 742
 									$set[] = $key.' = '.$val;
743 743
 								}
744
-								$sqlstart.= ' SET '.implode(', ', $set);
744
+								$sqlstart .= ' SET '.implode(', ', $set);
745 745
 
746
-								if(empty($keyfield)) $keyfield = 'rowid';
746
+								if (empty($keyfield)) $keyfield = 'rowid';
747 747
 								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
748 748
 
749 749
 								$sql = $sqlstart.$sqlend;
750 750
 
751 751
 								// Run update request
752
-								$resql=$this->db->query($sql);
753
-								if($resql) {
752
+								$resql = $this->db->query($sql);
753
+								if ($resql) {
754 754
 									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
755 755
 									$updatedone = true;
756 756
 								}
757 757
 								else
758 758
 								{
759 759
 									//print 'E';
760
-									$this->errors[$error]['lib']=$this->db->lasterror();
761
-									$this->errors[$error]['type']='SQL';
760
+									$this->errors[$error]['lib'] = $this->db->lasterror();
761
+									$this->errors[$error]['type'] = 'SQL';
762 762
 									$error++;
763 763
 								}
764 764
 							}
@@ -769,13 +769,13 @@  discard block
 block discarded – undo
769 769
 							// Build SQL INSERT request
770 770
 							$sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
771 771
 							$sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
772
-							if (! empty($tablewithentity_cache[$tablename])) {
773
-								$sqlstart.= ', entity';
774
-								$sqlend.= ', '.$conf->entity;
772
+							if (!empty($tablewithentity_cache[$tablename])) {
773
+								$sqlstart .= ', entity';
774
+								$sqlend .= ', '.$conf->entity;
775 775
 							}
776
-							if (! empty($objimport->array_import_tables_creator[0][$alias])) {
777
-								$sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
778
-								$sqlend.=', '.$user->id;
776
+							if (!empty($objimport->array_import_tables_creator[0][$alias])) {
777
+								$sqlstart .= ', '.$objimport->array_import_tables_creator[0][$alias];
778
+								$sqlend .= ', '.$user->id;
779 779
 							}
780 780
 							$sql = $sqlstart.$sqlend.')';
781 781
 							dol_syslog("import_xlsx.modules", LOG_DEBUG);
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
 							// Run insert request
784 784
 							if ($sql)
785 785
 							{
786
-								$resql=$this->db->query($sql);
786
+								$resql = $this->db->query($sql);
787 787
 								if ($resql)
788 788
 								{
789 789
 								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
 								else
793 793
 								{
794 794
 									//print 'E';
795
-									$this->errors[$error]['lib']=$this->db->lasterror();
796
-									$this->errors[$error]['type']='SQL';
795
+									$this->errors[$error]['lib'] = $this->db->lasterror();
796
+									$this->errors[$error]['type'] = 'SQL';
797 797
 									$error++;
798 798
 								}
799 799
 							}
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
 			    if ($error) break;
809 809
 			}
810 810
 
811
-			if($updatedone) $this->nbupdate++;
812
-			if($insertdone) $this->nbinsert++;
811
+			if ($updatedone) $this->nbupdate++;
812
+			if ($insertdone) $this->nbinsert++;
813 813
 		}
814 814
 
815 815
 		return 1;
Please login to merge, or discard this patch.
Braces   +120 added lines, -69 removed lines patch added patch discarded remove patch
@@ -111,9 +111,11 @@  discard block
 block discarded – undo
111 111
 		// If driver use an external library, put its name here
112 112
         require_once PHPEXCEL_PATH.'PHPExcel.php';
113 113
 		require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php';
114
-        if (! class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive
114
+        if (! class_exists('ZipArchive')) {
115
+            // For Excel2007, PHPExcel need ZipArchive
115 116
         {
116 117
                 $langs->load("errors");
118
+        }
117 119
                 $this->error=$langs->trans('ErrorPHPNeedModule','zip');
118 120
                 return -1;
119 121
         }
@@ -121,7 +123,9 @@  discard block
 block discarded – undo
121 123
         $this->version_lib='1.8.0';
122 124
 
123 125
 		$this->datatoimport=$datatoimport;
124
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
126
+		if (preg_match('/^societe_/',$datatoimport)) {
127
+		    $this->thirpartyobject=new Societe($this->db);
128
+		}
125 129
 	}
126 130
 
127 131
 
@@ -306,8 +310,9 @@  discard block
 block discarded – undo
306 310
 		global $conf;
307 311
 
308 312
 		$rowcount = $this->workbook->getActiveSheet()->getHighestDataRow();
309
-		if($this->record > $rowcount)
310
-			return false;
313
+		if($this->record > $rowcount) {
314
+					return false;
315
+		}
311 316
 		$array = array();
312 317
 		$colcount = PHPExcel_Cell::columnIndexFromString($this->workbook->getActiveSheet()->getHighestDataColumn(0));
313 318
 		for($col=0;$col<$colcount;$col++) {
@@ -374,8 +379,7 @@  discard block
 block discarded – undo
374 379
 			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
375 380
 			$this->warnings[$warning]['type']='EMPTY';
376 381
 			$warning++;
377
-		}
378
-		else
382
+		} else
379 383
 		{
380 384
 			$last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
381 385
 			$updatedone = false;
@@ -391,19 +395,27 @@  discard block
 block discarded – undo
391 395
 				$errorforthistable=0;
392 396
 
393 397
 				// Define $tablewithentity_cache[$tablename] if not already defined
394
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
398
+				if (! isset($tablewithentity_cache[$tablename])) {
399
+				    // keep this test with "isset"
395 400
 				{
396 401
 					dol_syslog("Check if table ".$tablename." has an entity field");
402
+				}
397 403
 					$resql=$this->db->DDLDescTable($tablename,'entity');
398 404
 					if ($resql)
399 405
 					{
400 406
 						$obj=$this->db->fetch_object($resql);
401
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
402
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
407
+						if ($obj) {
408
+						    $tablewithentity_cache[$tablename]=1;
409
+						}
410
+						// table contains entity field
411
+						else {
412
+						    $tablewithentity_cache[$tablename]=0;
413
+						}
414
+						// table does not contains entity field
415
+					} else {
416
+					    dol_print_error($this->db);
403 417
 					}
404
-					else dol_print_error($this->db);
405
-				}
406
-				else
418
+				} else
407 419
 				{
408 420
 					//dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
409 421
 				}
@@ -415,13 +427,19 @@  discard block
 block discarded – undo
415 427
 				    $fieldalias=preg_replace('/\..*$/i','',$val);
416 428
 				    $fieldname=preg_replace('/^.*\./i','',$val);
417 429
 
418
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
430
+				    if ($alias != $fieldalias) {
431
+				        continue;
432
+				    }
433
+				    // Not a field of current table
419 434
 
420 435
 					if ($key <= $maxfields)
421 436
 					{
422 437
 						// Set $newval with value to insert and set $listvalues with sql request part for insert
423 438
 						$newval='';
424
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
439
+						if ($arrayrecord[($key-1)]['type'] > 0) {
440
+						    $newval=$arrayrecord[($key-1)]['val'];
441
+						}
442
+						// If type of field into input file is not empty string (so defined into input file), we get value
425 443
 
426 444
 						// Make some tests on $newval
427 445
 
@@ -447,20 +465,23 @@  discard block
 block discarded – undo
447 465
                                 {
448 466
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
449 467
                                     $isidorref='id';
450
-                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref';
468
+                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) {
469
+                                        $isidorref='ref';
470
+                                    }
451 471
                                     $newval=preg_replace('/^(id|ref):/i','',$newval);    // Remove id: or ref: that was used to force if field is id or ref
452 472
                                     //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n";
453 473
 
454
-                                    if ($isidorref == 'ref')    // If value into input import file is a ref, we apply the function defined into descriptor
474
+                                    if ($isidorref == 'ref') {
475
+                                        // If value into input import file is a ref, we apply the function defined into descriptor
455 476
                                     {
456 477
                                         $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']);
478
+                                    }
457 479
                                         $class=$objimport->array_import_convertvalue[0][$val]['class'];
458 480
                                         $method=$objimport->array_import_convertvalue[0][$val]['method'];
459 481
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
460 482
                                         {
461 483
                                         	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
462
-                                        }
463
-                                        else
484
+                                        } else
464 485
 										{
465 486
                                             $resultload = dol_include_once($file);
466 487
                                             if (empty($resultload))
@@ -478,27 +499,32 @@  discard block
 block discarded – undo
478 499
                                             }
479 500
                                             $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
480 501
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
481
-                                            if ($classinstance->id != '')	// id may be 0, it is a found value
502
+                                            if ($classinstance->id != '') {
503
+                                                // id may be 0, it is a found value
482 504
                                             {
483 505
                                                 $newval=$classinstance->id;
484 506
                                             }
485
-                                            else
507
+                                            } else
486 508
                                             {
487
-                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
488
-                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
489
-                                                else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
509
+                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
510
+                                                    $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
511
+                                                } else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) {
512
+                                                    $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
513
+                                                } else {
514
+                                                    $this->errors[$error]['lib']='ErrorFieldValueNotIn';
515
+                                                }
490 516
                                                 $this->errors[$error]['type']='FOREIGNKEY';
491 517
                                                 $errorforthistable++;
492 518
                                                 $error++;
493 519
                                             }
494 520
                                         }
495 521
                                     }
496
-                                }
497
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
522
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
498 523
                                 {
499
-                                    if (empty($newval)) $newval='0';
500
-                                }
501
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
524
+                                    if (empty($newval)) {
525
+                                        $newval='0';
526
+                                    }
527
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
502 528
                                 {
503 529
                                     if (strtolower($newval) == 'auto')
504 530
                                     {
@@ -506,9 +532,11 @@  discard block
 block discarded – undo
506 532
                                         $newval=$this->thirpartyobject->code_client;
507 533
                                         //print 'code_client='.$newval;
508 534
                                     }
509
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
510
-                                }
511
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
535
+                                    if (empty($newval)) {
536
+                                        $arrayrecord[($key-1)]['type']=-1;
537
+                                    }
538
+                                    // If we get empty value, we will use "null"
539
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
512 540
                                 {
513 541
                                     if (strtolower($newval) == 'auto')
514 542
                                     {
@@ -516,9 +544,11 @@  discard block
 block discarded – undo
516 544
                                         $newval=$this->thirpartyobject->code_fournisseur;
517 545
                                         //print 'code_fournisseur='.$newval;
518 546
                                     }
519
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
520
-                                }
521
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
547
+                                    if (empty($newval)) {
548
+                                        $arrayrecord[($key-1)]['type']=-1;
549
+                                    }
550
+                                    // If we get empty value, we will use "null"
551
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
522 552
                                 {
523 553
                                     if (strtolower($newval) == 'auto')
524 554
                                     {
@@ -526,20 +556,27 @@  discard block
 block discarded – undo
526 556
                                         $newval=$this->thirpartyobject->code_compta;
527 557
                                         //print 'code_compta='.$newval;
528 558
                                     }
529
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
530
-                                }
531
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
559
+                                    if (empty($newval)) {
560
+                                        $arrayrecord[($key-1)]['type']=-1;
561
+                                    }
562
+                                    // If we get empty value, we will use "null"
563
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
532 564
                                 {
533 565
                                     if (strtolower($newval) == 'auto')
534 566
                                     {
535 567
                                         $this->thirpartyobject->get_codecompta('supplier');
536 568
                                         $newval=$this->thirpartyobject->code_compta_fournisseur;
537
-                                        if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
569
+                                        if (empty($newval)) {
570
+                                            $arrayrecord[($key-1)]['type']=-1;
571
+                                        }
572
+                                        // If we get empty value, we will use "null"
538 573
                                         //print 'code_compta_fournisseur='.$newval;
539 574
                                     }
540
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
541
-                                }
542
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
575
+                                    if (empty($newval)) {
576
+                                        $arrayrecord[($key-1)]['type']=-1;
577
+                                    }
578
+                                    // If we get empty value, we will use "null"
579
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
543 580
                                 {
544 581
                                     $defaultref='';
545 582
                                     // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function
@@ -550,12 +587,11 @@  discard block
 block discarded – undo
550 587
                                         $modTask = new $obj;
551 588
                                         $defaultref = $modTask->getNextValue(null,null);
552 589
                                     }
553
-                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
590
+                                    if (is_numeric($defaultref) && $defaultref <= 0) {
591
+                                        $defaultref='';
592
+                                    }
554 593
                                     $newval=$defaultref;
555
-                                }
556
-
557
-
558
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
594
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
559 595
                                 {
560 596
                                     $newval = price2num($newval);
561 597
                                 }
@@ -573,9 +609,11 @@  discard block
 block discarded – undo
573 609
 									$table=$reg[2];
574 610
 
575 611
 									// Load content of field@table into cache array
576
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
612
+									if (! is_array($this->cachefieldtable[$field.'@'.$table])) {
613
+									    // If content of field@table not already loaded into cache
577 614
 									{
578 615
 										$sql="SELECT ".$field." as aliasfield FROM ".$table;
616
+									}
579 617
 										$resql=$this->db->query($sql);
580 618
 										if ($resql)
581 619
 										{
@@ -584,11 +622,12 @@  discard block
 block discarded – undo
584 622
 											while ($i < $num)
585 623
 											{
586 624
 												$obj=$this->db->fetch_object($resql);
587
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
625
+												if ($obj) {
626
+												    $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
627
+												}
588 628
 												$i++;
589 629
 											}
590
-										}
591
-										else
630
+										} else
592 631
 										{
593 632
 											dol_print_error($this->db);
594 633
 										}
@@ -622,9 +661,13 @@  discard block
 block discarded – undo
622 661
 						$listfields[] = $fieldname;
623 662
 
624 663
 						// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
625
-						if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0)		 $listvalues[] = ($newval=='0'?$newval:"null");
626
-						elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0)	 $listvalues[] = "''";
627
-						else															 $listvalues[] = "'".$this->db->escape($newval)."'";
664
+						if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) {
665
+						    $listvalues[] = ($newval=='0'?$newval:"null");
666
+						} elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) {
667
+						    $listvalues[] = "''";
668
+						} else {
669
+						    $listvalues[] = "'".$this->db->escape($newval)."'";
670
+						}
628 671
 					}
629 672
 					$i++;
630 673
 				}
@@ -635,13 +678,15 @@  discard block
 block discarded – undo
635 678
     				// Loop on each hidden fields to add them into listfields/listvalues
636 679
 				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
637 680
     				{
638
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
681
+    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) {
682
+    				        continue;
683
+    				    }
684
+    				    // Not a field of current table
639 685
     				    if ($val == 'user->id')
640 686
     				    {
641 687
     				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
642 688
     				        $listvalues[] = $user->id;
643
-    				    }
644
-    				    elseif (preg_match('/^lastrowid-/',$val))
689
+    				    } elseif (preg_match('/^lastrowid-/',$val))
645 690
     				    {
646 691
     				        $tmp=explode('-',$val);
647 692
     				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
@@ -693,8 +738,7 @@  discard block
 block discarded – undo
693 738
 									} else {
694 739
 										// No record found with filters, insert will be tried below
695 740
 									}
696
-								}
697
-								else
741
+								} else
698 742
 								{
699 743
 									//print 'E';
700 744
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -709,7 +753,9 @@  discard block
 block discarded – undo
709 753
 								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
710 754
 								$sqlSelect = 'SELECT rowid FROM '.$tablename;
711 755
 
712
-								if(empty($keyfield)) $keyfield = 'rowid';
756
+								if(empty($keyfield)) {
757
+								    $keyfield = 'rowid';
758
+								}
713 759
 								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
714 760
 
715 761
 								$resql=$this->db->query($sqlSelect);
@@ -722,8 +768,7 @@  discard block
 block discarded – undo
722 768
 										// force $lastinsertid to 0 so we INSERT below.
723 769
 										$lastinsertid = 0;
724 770
 									}
725
-								}
726
-								else
771
+								} else
727 772
 								{
728 773
 									//print 'E';
729 774
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -743,7 +788,9 @@  discard block
 block discarded – undo
743 788
 								}
744 789
 								$sqlstart.= ' SET '.implode(', ', $set);
745 790
 
746
-								if(empty($keyfield)) $keyfield = 'rowid';
791
+								if(empty($keyfield)) {
792
+								    $keyfield = 'rowid';
793
+								}
747 794
 								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
748 795
 
749 796
 								$sql = $sqlstart.$sqlend;
@@ -753,8 +800,7 @@  discard block
 block discarded – undo
753 800
 								if($resql) {
754 801
 									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
755 802
 									$updatedone = true;
756
-								}
757
-								else
803
+								} else
758 804
 								{
759 805
 									//print 'E';
760 806
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -788,8 +834,7 @@  discard block
 block discarded – undo
788 834
 								{
789 835
 								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
790 836
 								    $insertdone = true;
791
-								}
792
-								else
837
+								} else
793 838
 								{
794 839
 									//print 'E';
795 840
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -805,11 +850,17 @@  discard block
 block discarded – undo
805 850
 					}*/
806 851
 				}
807 852
 
808
-			    if ($error) break;
853
+			    if ($error) {
854
+			        break;
855
+			    }
809 856
 			}
810 857
 
811
-			if($updatedone) $this->nbupdate++;
812
-			if($insertdone) $this->nbinsert++;
858
+			if($updatedone) {
859
+			    $this->nbupdate++;
860
+			}
861
+			if($insertdone) {
862
+			    $this->nbinsert++;
863
+			}
813 864
 		}
814 865
 
815 866
 		return 1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/import/modules_import.php 2 patches
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -38,121 +38,121 @@  discard block
 block discarded – undo
38 38
     public $datatoimport;
39 39
 
40 40
     /**
41
-	 * @var string Error code (or message)
42
-	 */
43
-	public $error='';
41
+     * @var string Error code (or message)
42
+     */
43
+    public $error='';
44 44
 
45 45
     /**
46
-	 * @var int id of driver
47
-	 */
48
-	public $id;
46
+     * @var int id of driver
47
+     */
48
+    public $id;
49 49
 
50 50
     /**
51 51
      * @var string label
52 52
      */
53 53
     public $label;
54 54
 
55
-	public $extension;    // Extension of files imported by driver
55
+    public $extension;    // Extension of files imported by driver
56 56
 
57
-	/**
57
+    /**
58 58
      * Dolibarr version of driver
59 59
      * @public string
60 60
      */
61
-	public $version = 'dolibarr';
61
+    public $version = 'dolibarr';
62 62
 
63
-	public $label_lib;    // Label of external lib used by driver
63
+    public $label_lib;    // Label of external lib used by driver
64 64
 
65
-	public $version_lib;  // Version of external lib used by driver
65
+    public $version_lib;  // Version of external lib used by driver
66 66
 
67
-	// Array of all drivers
68
-	public $driverlabel=array();
67
+    // Array of all drivers
68
+    public $driverlabel=array();
69 69
 
70
-	public $driverdesc=array();
70
+    public $driverdesc=array();
71 71
 
72
-	public $driverversion=array();
72
+    public $driverversion=array();
73 73
 
74
-	public $liblabel=array();
74
+    public $liblabel=array();
75 75
 
76
-	public $libversion=array();
76
+    public $libversion=array();
77 77
 
78 78
 
79
-	/**
79
+    /**
80 80
      *  Constructor
81
-	 */
82
-	function __construct()
83
-	{
84
-	}
85
-
86
-
87
-	/**
88
-	 * getDriverId
89
-	 *
90
-	 * @return string		Id
91
-	 */
92
-	function getDriverId()
93
-	{
94
-	    return $this->id;
95
-	}
96
-
97
-	/**
98
-	 *	getDriverLabel
99
-	 *
100
-	 *	@return string	Label
101
-	 */
102
-	function getDriverLabel()
103
-	{
104
-	    return $this->label;
105
-	}
106
-
107
-	/**
108
-	 *	getDriverDesc
109
-	 *
110
-	 *	@return string	Description
111
-	 */
112
-	function getDriverDesc()
113
-	{
114
-	    return $this->desc;
115
-	}
116
-
117
-	/**
118
-	 * getDriverExtension
119
-	 *
120
-	 * @return string	Driver suffix
121
-	 */
122
-	function getDriverExtension()
123
-	{
124
-	    return $this->extension;
125
-	}
126
-
127
-	/**
128
-	 *	getDriverVersion
129
-	 *
130
-	 *	@return string	Driver version
131
-	 */
132
-	function getDriverVersion()
133
-	{
134
-	    return $this->version;
135
-	}
136
-
137
-	/**
138
-	 *	getDriverLabel
139
-	 *
140
-	 *	@return string	Label of external lib
141
-	 */
142
-	function getLibLabel()
143
-	{
144
-	    return $this->label_lib;
145
-	}
146
-
147
-	/**
148
-	 * getLibVersion
149
-	 *
150
-	 *	@return string	Version of external lib
151
-	 */
152
-	function getLibVersion()
153
-	{
154
-	    return $this->version_lib;
155
-	}
81
+     */
82
+    function __construct()
83
+    {
84
+    }
85
+
86
+
87
+    /**
88
+     * getDriverId
89
+     *
90
+     * @return string		Id
91
+     */
92
+    function getDriverId()
93
+    {
94
+        return $this->id;
95
+    }
96
+
97
+    /**
98
+     *	getDriverLabel
99
+     *
100
+     *	@return string	Label
101
+     */
102
+    function getDriverLabel()
103
+    {
104
+        return $this->label;
105
+    }
106
+
107
+    /**
108
+     *	getDriverDesc
109
+     *
110
+     *	@return string	Description
111
+     */
112
+    function getDriverDesc()
113
+    {
114
+        return $this->desc;
115
+    }
116
+
117
+    /**
118
+     * getDriverExtension
119
+     *
120
+     * @return string	Driver suffix
121
+     */
122
+    function getDriverExtension()
123
+    {
124
+        return $this->extension;
125
+    }
126
+
127
+    /**
128
+     *	getDriverVersion
129
+     *
130
+     *	@return string	Driver version
131
+     */
132
+    function getDriverVersion()
133
+    {
134
+        return $this->version;
135
+    }
136
+
137
+    /**
138
+     *	getDriverLabel
139
+     *
140
+     *	@return string	Label of external lib
141
+     */
142
+    function getLibLabel()
143
+    {
144
+        return $this->label_lib;
145
+    }
146
+
147
+    /**
148
+     * getLibVersion
149
+     *
150
+     *	@return string	Version of external lib
151
+     */
152
+    function getLibVersion()
153
+    {
154
+        return $this->version_lib;
155
+    }
156 156
 
157 157
 
158 158
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -162,114 +162,114 @@  discard block
 block discarded – undo
162 162
      *  @param	DoliDB	$db     			Database handler
163 163
      *  @param  integer	$maxfilenamelength  Max length of value to show
164 164
      *  @return	array						List of templates
165
-	 */
166
-	function liste_modeles($db,$maxfilenamelength=0)
167
-	{
165
+     */
166
+    function liste_modeles($db,$maxfilenamelength=0)
167
+    {
168 168
         // phpcs:enable
169
-		dol_syslog(get_class($this)."::liste_modeles");
169
+        dol_syslog(get_class($this)."::liste_modeles");
170 170
 
171
-		$dir=DOL_DOCUMENT_ROOT."/core/modules/import/";
172
-		$handle=opendir($dir);
171
+        $dir=DOL_DOCUMENT_ROOT."/core/modules/import/";
172
+        $handle=opendir($dir);
173 173
 
174
-		// Recherche des fichiers drivers imports disponibles
175
-		$i=0;
174
+        // Recherche des fichiers drivers imports disponibles
175
+        $i=0;
176 176
         if (is_resource($handle))
177 177
         {
178
-    		while (($file = readdir($handle))!==false)
179
-    		{
180
-    			if (preg_match("/^import_(.*)\.modules\.php/i",$file,$reg))
181
-    			{
182
-    				$moduleid=$reg[1];
183
-
184
-    				// Loading Class
185
-    				$file = $dir."/import_".$moduleid.".modules.php";
186
-    				$classname = "Import".ucfirst($moduleid);
187
-
188
-    				require_once $file;
189
-    				$module = new $classname($db,'');
190
-
191
-    				// Picto
192
-    				$this->picto[$module->id]=$module->picto;
193
-    				// Driver properties
194
-    				$this->driverlabel[$module->id]=$module->getDriverLabel('');
195
-    				$this->driverdesc[$module->id]=$module->getDriverDesc('');
196
-    				$this->driverversion[$module->id]=$module->getDriverVersion('');
197
-    				// If use an external lib
198
-    				$this->liblabel[$module->id]=$module->getLibLabel('');
199
-    				$this->libversion[$module->id]=$module->getLibVersion('');
200
-
201
-    				$i++;
202
-    			}
203
-    		}
178
+            while (($file = readdir($handle))!==false)
179
+            {
180
+                if (preg_match("/^import_(.*)\.modules\.php/i",$file,$reg))
181
+                {
182
+                    $moduleid=$reg[1];
183
+
184
+                    // Loading Class
185
+                    $file = $dir."/import_".$moduleid.".modules.php";
186
+                    $classname = "Import".ucfirst($moduleid);
187
+
188
+                    require_once $file;
189
+                    $module = new $classname($db,'');
190
+
191
+                    // Picto
192
+                    $this->picto[$module->id]=$module->picto;
193
+                    // Driver properties
194
+                    $this->driverlabel[$module->id]=$module->getDriverLabel('');
195
+                    $this->driverdesc[$module->id]=$module->getDriverDesc('');
196
+                    $this->driverversion[$module->id]=$module->getDriverVersion('');
197
+                    // If use an external lib
198
+                    $this->liblabel[$module->id]=$module->getLibLabel('');
199
+                    $this->libversion[$module->id]=$module->getLibVersion('');
200
+
201
+                    $i++;
202
+                }
203
+            }
204 204
         }
205 205
 
206
-		return array_keys($this->driverlabel);
207
-	}
208
-
209
-
210
-	/**
211
-	 *  Return picto of import driver
212
-	 *
213
-	 *	@param	string	$key	Key
214
-	 *	@return	string
215
-	 */
216
-	function getPictoForKey($key)
217
-	{
218
-		return $this->picto[$key];
219
-	}
220
-
221
-	/**
222
-	 *  Renvoi libelle d'un driver import
223
-	 *
224
-	 *	@param	string	$key	Key
225
-	 *	@return	string
226
-	 */
227
-	function getDriverLabelForKey($key)
228
-	{
229
-		return $this->driverlabel[$key];
230
-	}
231
-
232
-	/**
233
-	 *  Renvoi la description d'un driver import
234
-	 *
235
-	 *	@param	string	$key	Key
236
-	 *	@return	string
237
-	 */
238
-	function getDriverDescForKey($key)
239
-	{
240
-		return $this->driverdesc[$key];
241
-	}
242
-
243
-	/**
244
-	 *  Renvoi version d'un driver import
245
-	 *
246
-	 *	@param	string	$key	Key
247
-	 *	@return	string
248
-	 */
249
-	function getDriverVersionForKey($key)
250
-	{
251
-		return $this->driverversion[$key];
252
-	}
253
-
254
-	/**
255
-	 *  Renvoi libelle de librairie externe du driver
256
-	 *
257
-	 *	@param	string	$key	Key
258
-	 *	@return	string
259
-	 */
260
-	function getLibLabelForKey($key)
261
-	{
262
-		return $this->liblabel[$key];
263
-	}
264
-
265
-	/**
266
-	 *  Renvoi version de librairie externe du driver
267
-	 *
268
-	 *	@param	string	$key	Key
269
-	 *	@return	string
270
-	 */
271
-	function getLibVersionForKey($key)
272
-	{
273
-		return $this->libversion[$key];
274
-	}
206
+        return array_keys($this->driverlabel);
207
+    }
208
+
209
+
210
+    /**
211
+     *  Return picto of import driver
212
+     *
213
+     *	@param	string	$key	Key
214
+     *	@return	string
215
+     */
216
+    function getPictoForKey($key)
217
+    {
218
+        return $this->picto[$key];
219
+    }
220
+
221
+    /**
222
+     *  Renvoi libelle d'un driver import
223
+     *
224
+     *	@param	string	$key	Key
225
+     *	@return	string
226
+     */
227
+    function getDriverLabelForKey($key)
228
+    {
229
+        return $this->driverlabel[$key];
230
+    }
231
+
232
+    /**
233
+     *  Renvoi la description d'un driver import
234
+     *
235
+     *	@param	string	$key	Key
236
+     *	@return	string
237
+     */
238
+    function getDriverDescForKey($key)
239
+    {
240
+        return $this->driverdesc[$key];
241
+    }
242
+
243
+    /**
244
+     *  Renvoi version d'un driver import
245
+     *
246
+     *	@param	string	$key	Key
247
+     *	@return	string
248
+     */
249
+    function getDriverVersionForKey($key)
250
+    {
251
+        return $this->driverversion[$key];
252
+    }
253
+
254
+    /**
255
+     *  Renvoi libelle de librairie externe du driver
256
+     *
257
+     *	@param	string	$key	Key
258
+     *	@return	string
259
+     */
260
+    function getLibLabelForKey($key)
261
+    {
262
+        return $this->liblabel[$key];
263
+    }
264
+
265
+    /**
266
+     *  Renvoi version de librairie externe du driver
267
+     *
268
+     *	@param	string	$key	Key
269
+     *	@return	string
270
+     */
271
+    function getLibVersionForKey($key)
272
+    {
273
+        return $this->libversion[$key];
274
+    }
275 275
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     /**
41 41
 	 * @var string Error code (or message)
42 42
 	 */
43
-	public $error='';
43
+	public $error = '';
44 44
 
45 45
     /**
46 46
 	 * @var int id of driver
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public $label;
54 54
 
55
-	public $extension;    // Extension of files imported by driver
55
+	public $extension; // Extension of files imported by driver
56 56
 
57 57
 	/**
58 58
      * Dolibarr version of driver
@@ -60,20 +60,20 @@  discard block
 block discarded – undo
60 60
      */
61 61
 	public $version = 'dolibarr';
62 62
 
63
-	public $label_lib;    // Label of external lib used by driver
63
+	public $label_lib; // Label of external lib used by driver
64 64
 
65
-	public $version_lib;  // Version of external lib used by driver
65
+	public $version_lib; // Version of external lib used by driver
66 66
 
67 67
 	// Array of all drivers
68
-	public $driverlabel=array();
68
+	public $driverlabel = array();
69 69
 
70
-	public $driverdesc=array();
70
+	public $driverdesc = array();
71 71
 
72
-	public $driverversion=array();
72
+	public $driverversion = array();
73 73
 
74
-	public $liblabel=array();
74
+	public $liblabel = array();
75 75
 
76
-	public $libversion=array();
76
+	public $libversion = array();
77 77
 
78 78
 
79 79
 	/**
@@ -163,40 +163,40 @@  discard block
 block discarded – undo
163 163
      *  @param  integer	$maxfilenamelength  Max length of value to show
164 164
      *  @return	array						List of templates
165 165
 	 */
166
-	function liste_modeles($db,$maxfilenamelength=0)
166
+	function liste_modeles($db, $maxfilenamelength = 0)
167 167
 	{
168 168
         // phpcs:enable
169 169
 		dol_syslog(get_class($this)."::liste_modeles");
170 170
 
171
-		$dir=DOL_DOCUMENT_ROOT."/core/modules/import/";
172
-		$handle=opendir($dir);
171
+		$dir = DOL_DOCUMENT_ROOT."/core/modules/import/";
172
+		$handle = opendir($dir);
173 173
 
174 174
 		// Recherche des fichiers drivers imports disponibles
175
-		$i=0;
175
+		$i = 0;
176 176
         if (is_resource($handle))
177 177
         {
178
-    		while (($file = readdir($handle))!==false)
178
+    		while (($file = readdir($handle)) !== false)
179 179
     		{
180
-    			if (preg_match("/^import_(.*)\.modules\.php/i",$file,$reg))
180
+    			if (preg_match("/^import_(.*)\.modules\.php/i", $file, $reg))
181 181
     			{
182
-    				$moduleid=$reg[1];
182
+    				$moduleid = $reg[1];
183 183
 
184 184
     				// Loading Class
185 185
     				$file = $dir."/import_".$moduleid.".modules.php";
186 186
     				$classname = "Import".ucfirst($moduleid);
187 187
 
188 188
     				require_once $file;
189
-    				$module = new $classname($db,'');
189
+    				$module = new $classname($db, '');
190 190
 
191 191
     				// Picto
192
-    				$this->picto[$module->id]=$module->picto;
192
+    				$this->picto[$module->id] = $module->picto;
193 193
     				// Driver properties
194
-    				$this->driverlabel[$module->id]=$module->getDriverLabel('');
195
-    				$this->driverdesc[$module->id]=$module->getDriverDesc('');
196
-    				$this->driverversion[$module->id]=$module->getDriverVersion('');
194
+    				$this->driverlabel[$module->id] = $module->getDriverLabel('');
195
+    				$this->driverdesc[$module->id] = $module->getDriverDesc('');
196
+    				$this->driverversion[$module->id] = $module->getDriverVersion('');
197 197
     				// If use an external lib
198
-    				$this->liblabel[$module->id]=$module->getLibLabel('');
199
-    				$this->libversion[$module->id]=$module->getLibVersion('');
198
+    				$this->liblabel[$module->id] = $module->getLibLabel('');
199
+    				$this->libversion[$module->id] = $module->getLibVersion('');
200 200
 
201 201
     				$i++;
202 202
     			}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/import/import_csv.modules.php 3 patches
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -40,383 +40,383 @@  discard block
 block discarded – undo
40 40
 
41 41
     public $datatoimport;
42 42
 
43
-	/**
44
-	 * @var string Error code (or message)
45
-	 */
46
-	public $error='';
43
+    /**
44
+     * @var string Error code (or message)
45
+     */
46
+    public $error='';
47 47
 
48
-	/**
49
-	 * @var string[] Error codes (or messages)
50
-	 */
51
-	public $errors = array();
48
+    /**
49
+     * @var string[] Error codes (or messages)
50
+     */
51
+    public $errors = array();
52 52
 
53 53
     /**
54
-	 * @var int ID
55
-	 */
56
-	public $id;
54
+     * @var int ID
55
+     */
56
+    public $id;
57 57
 
58
-	/**
58
+    /**
59 59
      * @var string label
60 60
      */
61 61
     public $label;
62 62
 
63
-	public $extension;    // Extension of files imported by driver
63
+    public $extension;    // Extension of files imported by driver
64 64
 
65
-	/**
65
+    /**
66 66
      * Dolibarr version of driver
67 67
      * @public string
68 68
      */
69
-	public $version = 'dolibarr';
69
+    public $version = 'dolibarr';
70 70
 
71
-	public $label_lib;    // Label of external lib used by driver
71
+    public $label_lib;    // Label of external lib used by driver
72 72
 
73
-	public $version_lib;  // Version of external lib used by driver
73
+    public $version_lib;  // Version of external lib used by driver
74 74
 
75
-	public $separator;
75
+    public $separator;
76 76
 
77
-	public $file;      // Path of file
77
+    public $file;      // Path of file
78 78
 
79
-	public $handle;    // Handle fichier
79
+    public $handle;    // Handle fichier
80 80
 
81
-	public $cacheconvert=array();      // Array to cache list of value found after a convertion
81
+    public $cacheconvert=array();      // Array to cache list of value found after a convertion
82 82
 
83
-	public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
83
+    public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
84 84
 
85
-	public $nbinsert = 0; // # of insert done during the import
85
+    public $nbinsert = 0; // # of insert done during the import
86 86
 
87
-	public $nbupdate = 0; // # of update done during the import
87
+    public $nbupdate = 0; // # of update done during the import
88 88
 
89 89
 
90
-	/**
91
-	 *	Constructor
92
-	 *
93
-	 *	@param	DoliDB		$db				Database handler
94
-	 *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
95
-	 */
96
-	function __construct($db,$datatoimport)
97
-	{
98
-		global $conf, $langs;
99
-		$this->db = $db;
100
-
101
-		$this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102
-		$this->enclosure='"';
103
-		$this->escape='"';
104
-
105
-		$this->id='csv';                // Same value then xxx in file name export_xxx.modules.php
106
-		$this->label='Csv';             // Label of driver
107
-		$this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape);
108
-		$this->extension='csv';         // Extension for generated file by this driver
109
-		$this->picto='mime/other';		// Picto
110
-		$this->version='1.34';         // Driver version
111
-
112
-		// If driver use an external library, put its name here
113
-		$this->label_lib='Dolibarr';
114
-		$this->version_lib=DOL_VERSION;
115
-
116
-		$this->datatoimport=$datatoimport;
117
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
118
-	}
90
+    /**
91
+     *	Constructor
92
+     *
93
+     *	@param	DoliDB		$db				Database handler
94
+     *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
95
+     */
96
+    function __construct($db,$datatoimport)
97
+    {
98
+        global $conf, $langs;
99
+        $this->db = $db;
100
+
101
+        $this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102
+        $this->enclosure='"';
103
+        $this->escape='"';
104
+
105
+        $this->id='csv';                // Same value then xxx in file name export_xxx.modules.php
106
+        $this->label='Csv';             // Label of driver
107
+        $this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape);
108
+        $this->extension='csv';         // Extension for generated file by this driver
109
+        $this->picto='mime/other';		// Picto
110
+        $this->version='1.34';         // Driver version
111
+
112
+        // If driver use an external library, put its name here
113
+        $this->label_lib='Dolibarr';
114
+        $this->version_lib=DOL_VERSION;
115
+
116
+        $this->datatoimport=$datatoimport;
117
+        if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
118
+    }
119 119
 
120 120
 
121 121
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
122
-	/**
123
-	 * 	Output header of an example file for this format
124
-	 *
125
-	 * 	@param	Translate	$outputlangs		Output language
126
-	 *  @return	string
127
-	 */
128
-	function write_header_example($outputlangs)
129
-	{
122
+    /**
123
+     * 	Output header of an example file for this format
124
+     *
125
+     * 	@param	Translate	$outputlangs		Output language
126
+     *  @return	string
127
+     */
128
+    function write_header_example($outputlangs)
129
+    {
130 130
         // phpcs:enable
131
-		return '';
132
-	}
131
+        return '';
132
+    }
133 133
 
134 134
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
135
-	/**
136
-	 * 	Output title line of an example file for this format
137
-	 *
138
-	 * 	@param	Translate	$outputlangs		Output language
139
-	 *  @param	array		$headerlinefields	Array of fields name
140
-	 * 	@return	string
141
-	 */
142
-	function write_title_example($outputlangs,$headerlinefields)
143
-	{
135
+    /**
136
+     * 	Output title line of an example file for this format
137
+     *
138
+     * 	@param	Translate	$outputlangs		Output language
139
+     *  @param	array		$headerlinefields	Array of fields name
140
+     * 	@return	string
141
+     */
142
+    function write_title_example($outputlangs,$headerlinefields)
143
+    {
144 144
         // phpcs:enable
145
-		$s=join($this->separator,array_map('cleansep',$headerlinefields));
146
-		return $s."\n";
147
-	}
145
+        $s=join($this->separator,array_map('cleansep',$headerlinefields));
146
+        return $s."\n";
147
+    }
148 148
 
149 149
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
150
-	/**
151
-	 * 	Output record of an example file for this format
152
-	 *
153
-	 * 	@param	Translate	$outputlangs		Output language
154
-	 * 	@param	array		$contentlinevalues	Array of lines
155
-	 * 	@return	string
156
-	 */
157
-	function write_record_example($outputlangs,$contentlinevalues)
158
-	{
150
+    /**
151
+     * 	Output record of an example file for this format
152
+     *
153
+     * 	@param	Translate	$outputlangs		Output language
154
+     * 	@param	array		$contentlinevalues	Array of lines
155
+     * 	@return	string
156
+     */
157
+    function write_record_example($outputlangs,$contentlinevalues)
158
+    {
159 159
         // phpcs:enable
160
-		$s=join($this->separator,array_map('cleansep',$contentlinevalues));
161
-		return $s."\n";
162
-	}
160
+        $s=join($this->separator,array_map('cleansep',$contentlinevalues));
161
+        return $s."\n";
162
+    }
163 163
 
164 164
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
165
-	/**
166
-	 * 	Output footer of an example file for this format
167
-	 *
168
-	 * 	@param	Translate	$outputlangs		Output language
169
-	 *  @return	string
170
-	 */
171
-	function write_footer_example($outputlangs)
172
-	{
165
+    /**
166
+     * 	Output footer of an example file for this format
167
+     *
168
+     * 	@param	Translate	$outputlangs		Output language
169
+     *  @return	string
170
+     */
171
+    function write_footer_example($outputlangs)
172
+    {
173 173
         // phpcs:enable
174
-		return '';
175
-	}
174
+        return '';
175
+    }
176 176
 
177 177
 
178 178
 
179 179
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
180
-	/**
181
-	 *	Open input file
182
-	 *
183
-	 *	@param	string	$file		Path of filename
184
-	 *	@return	int					<0 if KO, >=0 if OK
185
-	 */
186
-	function import_open_file($file)
187
-	{
180
+    /**
181
+     *	Open input file
182
+     *
183
+     *	@param	string	$file		Path of filename
184
+     *	@return	int					<0 if KO, >=0 if OK
185
+     */
186
+    function import_open_file($file)
187
+    {
188 188
         // phpcs:enable
189
-		global $langs;
190
-		$ret=1;
191
-
192
-		dol_syslog(get_class($this)."::open_file file=".$file);
193
-
194
-		ini_set('auto_detect_line_endings',1);	// For MAC compatibility
195
-
196
-		$this->handle = fopen(dol_osencode($file), "r");
197
-		if (! $this->handle)
198
-		{
199
-			$langs->load("errors");
200
-			$this->error=$langs->trans("ErrorFailToOpenFile",$file);
201
-			$ret=-1;
202
-		}
203
-		else
204
-		{
205
-			$this->file=$file;
206
-		}
207
-
208
-		return $ret;
209
-	}
189
+        global $langs;
190
+        $ret=1;
191
+
192
+        dol_syslog(get_class($this)."::open_file file=".$file);
193
+
194
+        ini_set('auto_detect_line_endings',1);	// For MAC compatibility
195
+
196
+        $this->handle = fopen(dol_osencode($file), "r");
197
+        if (! $this->handle)
198
+        {
199
+            $langs->load("errors");
200
+            $this->error=$langs->trans("ErrorFailToOpenFile",$file);
201
+            $ret=-1;
202
+        }
203
+        else
204
+        {
205
+            $this->file=$file;
206
+        }
207
+
208
+        return $ret;
209
+    }
210 210
 
211 211
 
212 212
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
213
-	/**
214
-	 * 	Return nb of records. File must be closed.
215
-	 *
216
-	 *	@param	string	$file		Path of filename
217
-	 * 	@return		int		<0 if KO, >=0 if OK
218
-	 */
219
-	function import_get_nb_of_lines($file)
220
-	{
213
+    /**
214
+     * 	Return nb of records. File must be closed.
215
+     *
216
+     *	@param	string	$file		Path of filename
217
+     * 	@return		int		<0 if KO, >=0 if OK
218
+     */
219
+    function import_get_nb_of_lines($file)
220
+    {
221 221
         // phpcs:enable
222
-       return dol_count_nb_of_line($file);
222
+        return dol_count_nb_of_line($file);
223 223
     }
224 224
 
225 225
 
226 226
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
227
-	/**
228
-	 * 	Input header line from file
229
-	 *
230
-	 * 	@return		int		<0 if KO, >=0 if OK
231
-	 */
232
-	function import_read_header()
233
-	{
227
+    /**
228
+     * 	Input header line from file
229
+     *
230
+     * 	@return		int		<0 if KO, >=0 if OK
231
+     */
232
+    function import_read_header()
233
+    {
234 234
         // phpcs:enable
235
-		return 0;
236
-	}
235
+        return 0;
236
+    }
237 237
 
238 238
 
239 239
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
240
-	/**
241
-	 * 	Return array of next record in input file.
242
-	 *
243
-	 * 	@return		Array		Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=not empty string)
244
-	 */
245
-	function import_read_record()
246
-	{
240
+    /**
241
+     * 	Return array of next record in input file.
242
+     *
243
+     * 	@return		Array		Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=not empty string)
244
+     */
245
+    function import_read_record()
246
+    {
247 247
         // phpcs:enable
248
-		global $conf;
249
-
250
-		$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
251
-
252
-		// End of file
253
-		if ($arrayres === false) return false;
254
-
255
-		//var_dump($this->handle);
256
-		//var_dump($arrayres);exit;
257
-		$newarrayres=array();
258
-		if ($arrayres && is_array($arrayres))
259
-		{
260
-			foreach($arrayres as $key => $val)
261
-			{
262
-				if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
263
-				{
264
-					if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
265
-					{
266
-						$newarrayres[$key]['val']=$val;
267
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
268
-					}
269
-					else
270
-					{
271
-						$newarrayres[$key]['val']=utf8_encode($val);
272
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
273
-					}
274
-				}
275
-				else	// Autodetect format (UTF8 or ISO)
276
-				{
277
-					if (utf8_check($val))
278
-					{
279
-						$newarrayres[$key]['val']=$val;
280
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
281
-					}
282
-					else
283
-					{
284
-						$newarrayres[$key]['val']=utf8_encode($val);
285
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
286
-					}
287
-				}
288
-			}
289
-
290
-			$this->col=count($newarrayres);
291
-		}
292
-
293
-		return $newarrayres;
294
-	}
248
+        global $conf;
249
+
250
+        $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
251
+
252
+        // End of file
253
+        if ($arrayres === false) return false;
254
+
255
+        //var_dump($this->handle);
256
+        //var_dump($arrayres);exit;
257
+        $newarrayres=array();
258
+        if ($arrayres && is_array($arrayres))
259
+        {
260
+            foreach($arrayres as $key => $val)
261
+            {
262
+                if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
263
+                {
264
+                    if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
265
+                    {
266
+                        $newarrayres[$key]['val']=$val;
267
+                        $newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
268
+                    }
269
+                    else
270
+                    {
271
+                        $newarrayres[$key]['val']=utf8_encode($val);
272
+                        $newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
273
+                    }
274
+                }
275
+                else	// Autodetect format (UTF8 or ISO)
276
+                {
277
+                    if (utf8_check($val))
278
+                    {
279
+                        $newarrayres[$key]['val']=$val;
280
+                        $newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
281
+                    }
282
+                    else
283
+                    {
284
+                        $newarrayres[$key]['val']=utf8_encode($val);
285
+                        $newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
286
+                    }
287
+                }
288
+            }
289
+
290
+            $this->col=count($newarrayres);
291
+        }
292
+
293
+        return $newarrayres;
294
+    }
295 295
 
296 296
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
297
-	/**
298
-	 * 	Close file handle
299
-	 *
300
-	 *  @return	integer
301
-	 */
302
-	function import_close_file()
303
-	{
297
+    /**
298
+     * 	Close file handle
299
+     *
300
+     *  @return	integer
301
+     */
302
+    function import_close_file()
303
+    {
304 304
         // phpcs:enable
305
-		fclose($this->handle);
306
-		return 0;
307
-	}
305
+        fclose($this->handle);
306
+        return 0;
307
+    }
308 308
 
309 309
 
310 310
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
311
-	/**
312
-	 * Insert a record into database
313
-	 *
314
-	 * @param	array	$arrayrecord					Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
315
-	 * @param	array	$array_match_file_to_database	Array of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]...
316
-	 * @param 	Object	$objimport						Object import (contains objimport->array_import_tables, objimport->array_import_fields, objimport->array_import_convertvalue, ...)
317
-	 * @param	int		$maxfields						Max number of fields to use
318
-	 * @param	string	$importid						Import key
319
-	 * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
320
-	 * @return	int										<0 if KO, >0 if OK
321
-	 */
322
-	function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
323
-	{
311
+    /**
312
+     * Insert a record into database
313
+     *
314
+     * @param	array	$arrayrecord					Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
315
+     * @param	array	$array_match_file_to_database	Array of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]...
316
+     * @param 	Object	$objimport						Object import (contains objimport->array_import_tables, objimport->array_import_fields, objimport->array_import_convertvalue, ...)
317
+     * @param	int		$maxfields						Max number of fields to use
318
+     * @param	string	$importid						Import key
319
+     * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
320
+     * @return	int										<0 if KO, >0 if OK
321
+     */
322
+    function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
323
+    {
324 324
         // phpcs:enable
325
-		global $langs,$conf,$user;
325
+        global $langs,$conf,$user;
326 326
         global $thirdparty_static;    	// Specific to thirdparty import
327
-		global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
328
-
329
-		$error=0;
330
-		$warning=0;
331
-		$this->errors=array();
332
-		$this->warnings=array();
333
-
334
-		//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
335
-
336
-		//var_dump($array_match_file_to_database);
337
-		//var_dump($arrayrecord);
338
-		$array_match_database_to_file=array_flip($array_match_file_to_database);
339
-		$sort_array_match_file_to_database=$array_match_file_to_database;
340
-		ksort($sort_array_match_file_to_database);
341
-
342
-		//var_dump($sort_array_match_file_to_database);
343
-
344
-		if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
345
-		{
346
-			//print 'W';
347
-			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
348
-			$this->warnings[$warning]['type']='EMPTY';
349
-			$warning++;
350
-		}
351
-		else
352
-		{
353
-			$last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
354
-			$updatedone = false;
355
-			$insertdone = false;
356
-			// For each table to insert, me make a separate insert
357
-			foreach($objimport->array_import_tables[0] as $alias => $tablename)
358
-			{
359
-				// Build sql request
360
-				$sql='';
361
-				$listfields=array();
362
-				$listvalues=array();
363
-				$i=0;
364
-				$errorforthistable=0;
365
-
366
-				// Define $tablewithentity_cache[$tablename] if not already defined
367
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
368
-				{
369
-					dol_syslog("Check if table ".$tablename." has an entity field");
370
-					$resql=$this->db->DDLDescTable($tablename,'entity');
371
-					if ($resql)
372
-					{
373
-						$obj=$this->db->fetch_object($resql);
374
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
375
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
376
-					}
377
-					else dol_print_error($this->db);
378
-				}
379
-				else
380
-				{
381
-					//dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
382
-				}
383
-
384
-
385
-				// Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
386
-				foreach($sort_array_match_file_to_database as $key => $val)
387
-				{
388
-				    $fieldalias=preg_replace('/\..*$/i','',$val);
389
-				    $fieldname=preg_replace('/^.*\./i','',$val);
390
-
391
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
392
-
393
-					if ($key <= $maxfields)
394
-					{
395
-						// Set $newval with value to insert and set $listvalues with sql request part for insert
396
-						$newval='';
397
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
398
-
399
-						// Make some tests on $newval
400
-
401
-						// Is it a required field ?
402
-						if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
403
-						{
404
-							$this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
405
-							$this->errors[$error]['type']='NOTNULL';
406
-							$errorforthistable++;
407
-							$error++;
408
-						}
409
-						// Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
410
-						else
411
-						{
412
-						    // We convert field if required
413
-						    if (! empty($objimport->array_import_convertvalue[0][$val]))
414
-						    {
327
+        global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
328
+
329
+        $error=0;
330
+        $warning=0;
331
+        $this->errors=array();
332
+        $this->warnings=array();
333
+
334
+        //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
335
+
336
+        //var_dump($array_match_file_to_database);
337
+        //var_dump($arrayrecord);
338
+        $array_match_database_to_file=array_flip($array_match_file_to_database);
339
+        $sort_array_match_file_to_database=$array_match_file_to_database;
340
+        ksort($sort_array_match_file_to_database);
341
+
342
+        //var_dump($sort_array_match_file_to_database);
343
+
344
+        if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
345
+        {
346
+            //print 'W';
347
+            $this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
348
+            $this->warnings[$warning]['type']='EMPTY';
349
+            $warning++;
350
+        }
351
+        else
352
+        {
353
+            $last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
354
+            $updatedone = false;
355
+            $insertdone = false;
356
+            // For each table to insert, me make a separate insert
357
+            foreach($objimport->array_import_tables[0] as $alias => $tablename)
358
+            {
359
+                // Build sql request
360
+                $sql='';
361
+                $listfields=array();
362
+                $listvalues=array();
363
+                $i=0;
364
+                $errorforthistable=0;
365
+
366
+                // Define $tablewithentity_cache[$tablename] if not already defined
367
+                if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
368
+                {
369
+                    dol_syslog("Check if table ".$tablename." has an entity field");
370
+                    $resql=$this->db->DDLDescTable($tablename,'entity');
371
+                    if ($resql)
372
+                    {
373
+                        $obj=$this->db->fetch_object($resql);
374
+                        if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
375
+                        else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
376
+                    }
377
+                    else dol_print_error($this->db);
378
+                }
379
+                else
380
+                {
381
+                    //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
382
+                }
383
+
384
+
385
+                // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
386
+                foreach($sort_array_match_file_to_database as $key => $val)
387
+                {
388
+                    $fieldalias=preg_replace('/\..*$/i','',$val);
389
+                    $fieldname=preg_replace('/^.*\./i','',$val);
390
+
391
+                    if ($alias != $fieldalias) continue;    // Not a field of current table
392
+
393
+                    if ($key <= $maxfields)
394
+                    {
395
+                        // Set $newval with value to insert and set $listvalues with sql request part for insert
396
+                        $newval='';
397
+                        if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
398
+
399
+                        // Make some tests on $newval
400
+
401
+                        // Is it a required field ?
402
+                        if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
403
+                        {
404
+                            $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
405
+                            $this->errors[$error]['type']='NOTNULL';
406
+                            $errorforthistable++;
407
+                            $error++;
408
+                        }
409
+                        // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory)
410
+                        else
411
+                        {
412
+                            // We convert field if required
413
+                            if (! empty($objimport->array_import_convertvalue[0][$val]))
414
+                            {
415 415
                                 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
416 416
                                 if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid'
417
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
418
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
419
-                                	)
417
+                                    || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
418
+                                    || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
419
+                                    )
420 420
                                 {
421 421
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
422 422
                                     $isidorref='id';
@@ -431,10 +431,10 @@  discard block
 block discarded – undo
431 431
                                         $method=$objimport->array_import_convertvalue[0][$val]['method'];
432 432
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
433 433
                                         {
434
-                                        	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
434
+                                            $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
435 435
                                         }
436 436
                                         else
437
-										{
437
+                                        {
438 438
                                             $resultload = dol_include_once($file);
439 439
                                             if (empty($resultload))
440 440
                                             {
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
                                             // If not found, try the fetch from label
448 448
                                             if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
449 449
                                             {
450
-												call_user_func_array(array($classinstance, $method),array('', '', $newval));
450
+                                                call_user_func_array(array($classinstance, $method),array('', '', $newval));
451 451
                                             }
452 452
                                             $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
453 453
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
@@ -534,264 +534,264 @@  discard block
 block discarded – undo
534 534
                                 }
535 535
 
536 536
                                 //print 'Val to use as insert is '.$newval.'<br>';
537
-						    }
538
-
539
-						    // Test regexp
540
-							if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
541
-							{
542
-								// If test is "Must exist in a field@table"
543
-								if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
544
-								{
545
-									$field=$reg[1];
546
-									$table=$reg[2];
547
-
548
-									// Load content of field@table into cache array
549
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
550
-									{
551
-										$sql="SELECT ".$field." as aliasfield FROM ".$table;
552
-										$resql=$this->db->query($sql);
553
-										if ($resql)
554
-										{
555
-											$num=$this->db->num_rows($resql);
556
-											$i=0;
557
-											while ($i < $num)
558
-											{
559
-												$obj=$this->db->fetch_object($resql);
560
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
561
-												$i++;
562
-											}
563
-										}
564
-										else
565
-										{
566
-											dol_print_error($this->db);
567
-										}
568
-									}
569
-
570
-									// Now we check cache is not empty (should not) and key is into cache
571
-									if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
572
-									{
573
-										$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
574
-										$this->errors[$error]['type']='FOREIGNKEY';
575
-									    $errorforthistable++;
576
-										$error++;
577
-									}
578
-								}
579
-								// If test is just a static regex
580
-								else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
581
-								{
582
-								    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
583
-									$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
584
-									$this->errors[$error]['type']='REGEX';
585
-									$errorforthistable++;
586
-									$error++;
587
-								}
588
-							}
589
-
590
-							// Other tests
591
-							// ...
592
-						}
593
-
594
-						// Define $listfields and $listvalues to build SQL request
595
-						$listfields[] = $fieldname;
596
-
597
-						// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
598
-						if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) {
537
+                            }
538
+
539
+                            // Test regexp
540
+                            if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
541
+                            {
542
+                                // If test is "Must exist in a field@table"
543
+                                if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
544
+                                {
545
+                                    $field=$reg[1];
546
+                                    $table=$reg[2];
547
+
548
+                                    // Load content of field@table into cache array
549
+                                    if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
550
+                                    {
551
+                                        $sql="SELECT ".$field." as aliasfield FROM ".$table;
552
+                                        $resql=$this->db->query($sql);
553
+                                        if ($resql)
554
+                                        {
555
+                                            $num=$this->db->num_rows($resql);
556
+                                            $i=0;
557
+                                            while ($i < $num)
558
+                                            {
559
+                                                $obj=$this->db->fetch_object($resql);
560
+                                                if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
561
+                                                $i++;
562
+                                            }
563
+                                        }
564
+                                        else
565
+                                        {
566
+                                            dol_print_error($this->db);
567
+                                        }
568
+                                    }
569
+
570
+                                    // Now we check cache is not empty (should not) and key is into cache
571
+                                    if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
572
+                                    {
573
+                                        $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
574
+                                        $this->errors[$error]['type']='FOREIGNKEY';
575
+                                        $errorforthistable++;
576
+                                        $error++;
577
+                                    }
578
+                                }
579
+                                // If test is just a static regex
580
+                                else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
581
+                                {
582
+                                    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
583
+                                    $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
584
+                                    $this->errors[$error]['type']='REGEX';
585
+                                    $errorforthistable++;
586
+                                    $error++;
587
+                                }
588
+                            }
589
+
590
+                            // Other tests
591
+                            // ...
592
+                        }
593
+
594
+                        // Define $listfields and $listvalues to build SQL request
595
+                        $listfields[] = $fieldname;
596
+
597
+                        // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
598
+                        if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) {
599 599
                             $listvalues[] = ($newval=='0'?$newval:"null");
600 600
                         } elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) {
601 601
                             $listvalues[] = "''";
602 602
                         } else {
603 603
                             $listvalues[] = "'".$this->db->escape($newval)."'";
604 604
                         }
605
-					}
606
-					$i++;
607
-				}
608
-
609
-				// We add hidden fields (but only if there is at least one field to add into table)
610
-				if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
611
-				{
612
-    				// Loop on each hidden fields to add them into listfields/listvalues
613
-				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
614
-    				{
615
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
616
-    				    if ($val == 'user->id')
617
-    				    {
618
-    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
619
-    				        $listvalues[] = $user->id;
620
-    				    }
621
-    				    elseif (preg_match('/^lastrowid-/',$val))
622
-    				    {
623
-    				        $tmp=explode('-',$val);
624
-    				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
625
-							$keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
626
-    				        $listfields[] = $keyfield;
605
+                    }
606
+                    $i++;
607
+                }
608
+
609
+                // We add hidden fields (but only if there is at least one field to add into table)
610
+                if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
611
+                {
612
+                    // Loop on each hidden fields to add them into listfields/listvalues
613
+                    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
614
+                    {
615
+                        if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
616
+                        if ($val == 'user->id')
617
+                        {
618
+                            $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
619
+                            $listvalues[] = $user->id;
620
+                        }
621
+                        elseif (preg_match('/^lastrowid-/',$val))
622
+                        {
623
+                            $tmp=explode('-',$val);
624
+                            $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
625
+                            $keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
626
+                            $listfields[] = $keyfield;
627 627
                             $listvalues[] = $lastinsertid;
628
-    				        //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
629
-    				    }
630
-    				}
631
-				}
632
-				//print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
633
-
634
-				// If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
635
-				// so we can try to make the insert or update now.
636
-				if (! $errorforthistable)
637
-				{
638
-					//print "$alias/$tablename/$listfields/$listvalues<br>";
639
-					if (!empty($listfields))
640
-					{
641
-						$updatedone = false;
642
-						$insertdone = false;
643
-
644
-						if (!empty($updatekeys)) {
645
-							// We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
646
-
647
-							if (empty($lastinsertid)) {	// No insert done yet for a parent table
648
-								$sqlSelect = 'SELECT rowid FROM '.$tablename;
649
-
650
-								$data = array_combine($listfields, $listvalues);
651
-								$where = array();
652
-								$filters = array();
653
-								foreach ($updatekeys as $key) {
654
-									$col = $objimport->array_import_updatekeys[0][$key];
655
-									$key=preg_replace('/^.*\./i','',$key);
656
-									$where[] = $key.' = '.$data[$key];
657
-									$filters[] = $col.' = '.$data[$key];
658
-								}
659
-								$sqlSelect.= ' WHERE '.implode(' AND ', $where);
660
-
661
-								$resql=$this->db->query($sqlSelect);
662
-								if($resql) {
663
-									$res = $this->db->fetch_object($resql);
664
-									if($resql->num_rows == 1) {
665
-										$lastinsertid = $res->rowid;
666
-										$last_insert_id_array[$tablename] = $lastinsertid;
667
-									} else if($resql->num_rows > 1) {
668
-										$this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
669
-										$this->errors[$error]['type']='SQL';
670
-										$error++;
671
-									} else {
672
-										// No record found with filters, insert will be tried below
673
-									}
674
-								}
675
-								else
676
-								{
677
-									//print 'E';
678
-									$this->errors[$error]['lib']=$this->db->lasterror();
679
-									$this->errors[$error]['type']='SQL';
680
-									$error++;
681
-								}
682
-							} else {
683
-								// We have a last INSERT ID (got by previous pass), so we check if we have a row referencing this foreign key.
684
-								// This is required when updating table with some extrafields. When inserting a record in parent table, we can make
685
-								// a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
686
-								// may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
687
-								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
688
-								$sqlSelect = 'SELECT rowid FROM '.$tablename;
689
-
690
-								if(empty($keyfield)) $keyfield = 'rowid';
691
-								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
692
-
693
-								$resql=$this->db->query($sqlSelect);
694
-								if($resql) {
695
-									$res = $this->db->fetch_object($resql);
696
-									if($resql->num_rows == 1) {
697
-										// We have a row referencing this last foreign key, continue with UPDATE.
698
-									} else {
699
-										// No record found referencing this last foreign key,
700
-										// force $lastinsertid to 0 so we INSERT below.
701
-										$lastinsertid = 0;
702
-									}
703
-								}
704
-								else
705
-								{
706
-									//print 'E';
707
-									$this->errors[$error]['lib']=$this->db->lasterror();
708
-									$this->errors[$error]['type']='SQL';
709
-									$error++;
710
-								}
711
-							}
712
-
713
-							if (!empty($lastinsertid)) {
714
-								// Build SQL UPDATE request
715
-								$sqlstart = 'UPDATE '.$tablename;
716
-
717
-								$data = array_combine($listfields, $listvalues);
718
-								$set = array();
719
-								foreach ($data as $key => $val) {
720
-									$set[] = $key.' = '.$val;
721
-								}
722
-								$sqlstart.= ' SET '.implode(', ', $set);
723
-
724
-								if(empty($keyfield)) $keyfield = 'rowid';
725
-								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
726
-
727
-								$sql = $sqlstart.$sqlend;
728
-
729
-								// Run update request
730
-								$resql=$this->db->query($sql);
731
-								if($resql) {
732
-									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
733
-									$updatedone = true;
734
-								}
735
-								else
736
-								{
737
-									//print 'E';
738
-									$this->errors[$error]['lib']=$this->db->lasterror();
739
-									$this->errors[$error]['type']='SQL';
740
-									$error++;
741
-								}
742
-							}
743
-						}
744
-
745
-						// Update not done, we do insert
746
-						if (!$error && !$updatedone) {
747
-							// Build SQL INSERT request
748
-							$sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
749
-							$sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
750
-							if (! empty($tablewithentity_cache[$tablename])) {
751
-								$sqlstart.= ', entity';
752
-								$sqlend.= ', '.$conf->entity;
753
-							}
754
-							if (! empty($objimport->array_import_tables_creator[0][$alias])) {
755
-								$sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
756
-								$sqlend.=', '.$user->id;
757
-							}
758
-							$sql = $sqlstart.$sqlend.')';
759
-							dol_syslog("import_csv.modules", LOG_DEBUG);
760
-
761
-							// Run insert request
762
-							if ($sql)
763
-							{
764
-								$resql=$this->db->query($sql);
765
-								if ($resql)
766
-								{
767
-								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
768
-								    $insertdone = true;
769
-								}
770
-								else
771
-								{
772
-									//print 'E';
773
-									$this->errors[$error]['lib']=$this->db->lasterror();
774
-									$this->errors[$error]['type']='SQL';
775
-									$error++;
776
-								}
777
-							}
778
-						}
779
-					}
780
-					/*else
628
+                            //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
629
+                        }
630
+                    }
631
+                }
632
+                //print 'listfields='.$listfields.'<br>listvalues='.$listvalues.'<br>';
633
+
634
+                // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
635
+                // so we can try to make the insert or update now.
636
+                if (! $errorforthistable)
637
+                {
638
+                    //print "$alias/$tablename/$listfields/$listvalues<br>";
639
+                    if (!empty($listfields))
640
+                    {
641
+                        $updatedone = false;
642
+                        $insertdone = false;
643
+
644
+                        if (!empty($updatekeys)) {
645
+                            // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields)
646
+
647
+                            if (empty($lastinsertid)) {	// No insert done yet for a parent table
648
+                                $sqlSelect = 'SELECT rowid FROM '.$tablename;
649
+
650
+                                $data = array_combine($listfields, $listvalues);
651
+                                $where = array();
652
+                                $filters = array();
653
+                                foreach ($updatekeys as $key) {
654
+                                    $col = $objimport->array_import_updatekeys[0][$key];
655
+                                    $key=preg_replace('/^.*\./i','',$key);
656
+                                    $where[] = $key.' = '.$data[$key];
657
+                                    $filters[] = $col.' = '.$data[$key];
658
+                                }
659
+                                $sqlSelect.= ' WHERE '.implode(' AND ', $where);
660
+
661
+                                $resql=$this->db->query($sqlSelect);
662
+                                if($resql) {
663
+                                    $res = $this->db->fetch_object($resql);
664
+                                    if($resql->num_rows == 1) {
665
+                                        $lastinsertid = $res->rowid;
666
+                                        $last_insert_id_array[$tablename] = $lastinsertid;
667
+                                    } else if($resql->num_rows > 1) {
668
+                                        $this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
669
+                                        $this->errors[$error]['type']='SQL';
670
+                                        $error++;
671
+                                    } else {
672
+                                        // No record found with filters, insert will be tried below
673
+                                    }
674
+                                }
675
+                                else
676
+                                {
677
+                                    //print 'E';
678
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
679
+                                    $this->errors[$error]['type']='SQL';
680
+                                    $error++;
681
+                                }
682
+                            } else {
683
+                                // We have a last INSERT ID (got by previous pass), so we check if we have a row referencing this foreign key.
684
+                                // This is required when updating table with some extrafields. When inserting a record in parent table, we can make
685
+                                // a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record
686
+                                // may already exists. So we rescan the extrafield table to know if record exists or not for the rowid.
687
+                                // Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
688
+                                $sqlSelect = 'SELECT rowid FROM '.$tablename;
689
+
690
+                                if(empty($keyfield)) $keyfield = 'rowid';
691
+                                $sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
692
+
693
+                                $resql=$this->db->query($sqlSelect);
694
+                                if($resql) {
695
+                                    $res = $this->db->fetch_object($resql);
696
+                                    if($resql->num_rows == 1) {
697
+                                        // We have a row referencing this last foreign key, continue with UPDATE.
698
+                                    } else {
699
+                                        // No record found referencing this last foreign key,
700
+                                        // force $lastinsertid to 0 so we INSERT below.
701
+                                        $lastinsertid = 0;
702
+                                    }
703
+                                }
704
+                                else
705
+                                {
706
+                                    //print 'E';
707
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
708
+                                    $this->errors[$error]['type']='SQL';
709
+                                    $error++;
710
+                                }
711
+                            }
712
+
713
+                            if (!empty($lastinsertid)) {
714
+                                // Build SQL UPDATE request
715
+                                $sqlstart = 'UPDATE '.$tablename;
716
+
717
+                                $data = array_combine($listfields, $listvalues);
718
+                                $set = array();
719
+                                foreach ($data as $key => $val) {
720
+                                    $set[] = $key.' = '.$val;
721
+                                }
722
+                                $sqlstart.= ' SET '.implode(', ', $set);
723
+
724
+                                if(empty($keyfield)) $keyfield = 'rowid';
725
+                                $sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
726
+
727
+                                $sql = $sqlstart.$sqlend;
728
+
729
+                                // Run update request
730
+                                $resql=$this->db->query($sql);
731
+                                if($resql) {
732
+                                    // No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
733
+                                    $updatedone = true;
734
+                                }
735
+                                else
736
+                                {
737
+                                    //print 'E';
738
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
739
+                                    $this->errors[$error]['type']='SQL';
740
+                                    $error++;
741
+                                }
742
+                            }
743
+                        }
744
+
745
+                        // Update not done, we do insert
746
+                        if (!$error && !$updatedone) {
747
+                            // Build SQL INSERT request
748
+                            $sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
749
+                            $sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
750
+                            if (! empty($tablewithentity_cache[$tablename])) {
751
+                                $sqlstart.= ', entity';
752
+                                $sqlend.= ', '.$conf->entity;
753
+                            }
754
+                            if (! empty($objimport->array_import_tables_creator[0][$alias])) {
755
+                                $sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
756
+                                $sqlend.=', '.$user->id;
757
+                            }
758
+                            $sql = $sqlstart.$sqlend.')';
759
+                            dol_syslog("import_csv.modules", LOG_DEBUG);
760
+
761
+                            // Run insert request
762
+                            if ($sql)
763
+                            {
764
+                                $resql=$this->db->query($sql);
765
+                                if ($resql)
766
+                                {
767
+                                    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
768
+                                    $insertdone = true;
769
+                                }
770
+                                else
771
+                                {
772
+                                    //print 'E';
773
+                                    $this->errors[$error]['lib']=$this->db->lasterror();
774
+                                    $this->errors[$error]['type']='SQL';
775
+                                    $error++;
776
+                                }
777
+                            }
778
+                        }
779
+                    }
780
+                    /*else
781 781
 					{
782 782
 						dol_print_error('','ErrorFieldListEmptyFor '.$alias."/".$tablename);
783 783
 					}*/
784
-				}
784
+                }
785 785
 
786
-			    if ($error) break;
787
-			}
786
+                if ($error) break;
787
+            }
788 788
 
789
-			if($updatedone) $this->nbupdate++;
790
-			if($insertdone) $this->nbinsert++;
791
-		}
789
+            if($updatedone) $this->nbupdate++;
790
+            if($insertdone) $this->nbinsert++;
791
+        }
792 792
 
793
-		return 1;
794
-	}
793
+        return 1;
794
+    }
795 795
 }
796 796
 
797 797
 /**
@@ -802,5 +802,5 @@  discard block
 block discarded – undo
802 802
  */
803 803
 function cleansep($value)
804 804
 {
805
-	return str_replace(array(',',';'),'/',$value);
805
+    return str_replace(array(',',';'),'/',$value);
806 806
 };
Please login to merge, or discard this patch.
Spacing   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *		\brief      File to load import files with CSV format
26 26
  */
27 27
 
28
-require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php';
28
+require_once DOL_DOCUMENT_ROOT.'/core/modules/import/modules_import.php';
29 29
 
30 30
 
31 31
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	/**
44 44
 	 * @var string Error code (or message)
45 45
 	 */
46
-	public $error='';
46
+	public $error = '';
47 47
 
48 48
 	/**
49 49
 	 * @var string[] Error codes (or messages)
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public $label;
62 62
 
63
-	public $extension;    // Extension of files imported by driver
63
+	public $extension; // Extension of files imported by driver
64 64
 
65 65
 	/**
66 66
      * Dolibarr version of driver
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
      */
69 69
 	public $version = 'dolibarr';
70 70
 
71
-	public $label_lib;    // Label of external lib used by driver
71
+	public $label_lib; // Label of external lib used by driver
72 72
 
73
-	public $version_lib;  // Version of external lib used by driver
73
+	public $version_lib; // Version of external lib used by driver
74 74
 
75 75
 	public $separator;
76 76
 
77
-	public $file;      // Path of file
77
+	public $file; // Path of file
78 78
 
79
-	public $handle;    // Handle fichier
79
+	public $handle; // Handle fichier
80 80
 
81
-	public $cacheconvert=array();      // Array to cache list of value found after a convertion
81
+	public $cacheconvert = array(); // Array to cache list of value found after a convertion
82 82
 
83
-	public $cachefieldtable=array();   // Array to cache list of value found into fields@tables
83
+	public $cachefieldtable = array(); // Array to cache list of value found into fields@tables
84 84
 
85 85
 	public $nbinsert = 0; // # of insert done during the import
86 86
 
@@ -93,28 +93,28 @@  discard block
 block discarded – undo
93 93
 	 *	@param	DoliDB		$db				Database handler
94 94
 	 *	@param	string		$datatoimport	String code describing import set (ex: 'societe_1')
95 95
 	 */
96
-	function __construct($db,$datatoimport)
96
+	function __construct($db, $datatoimport)
97 97
 	{
98 98
 		global $conf, $langs;
99 99
 		$this->db = $db;
100 100
 
101
-		$this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102
-		$this->enclosure='"';
103
-		$this->escape='"';
101
+		$this->separator = (GETPOST('separator') ?GETPOST('separator') : (empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE) ? ',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
102
+		$this->enclosure = '"';
103
+		$this->escape = '"';
104 104
 
105
-		$this->id='csv';                // Same value then xxx in file name export_xxx.modules.php
106
-		$this->label='Csv';             // Label of driver
107
-		$this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape);
108
-		$this->extension='csv';         // Extension for generated file by this driver
109
-		$this->picto='mime/other';		// Picto
110
-		$this->version='1.34';         // Driver version
105
+		$this->id = 'csv'; // Same value then xxx in file name export_xxx.modules.php
106
+		$this->label = 'Csv'; // Label of driver
107
+		$this->desc = $langs->trans("CSVFormatDesc", $this->separator, $this->enclosure, $this->escape);
108
+		$this->extension = 'csv'; // Extension for generated file by this driver
109
+		$this->picto = 'mime/other'; // Picto
110
+		$this->version = '1.34'; // Driver version
111 111
 
112 112
 		// If driver use an external library, put its name here
113
-		$this->label_lib='Dolibarr';
114
-		$this->version_lib=DOL_VERSION;
113
+		$this->label_lib = 'Dolibarr';
114
+		$this->version_lib = DOL_VERSION;
115 115
 
116
-		$this->datatoimport=$datatoimport;
117
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
116
+		$this->datatoimport = $datatoimport;
117
+		if (preg_match('/^societe_/', $datatoimport)) $this->thirpartyobject = new Societe($this->db);
118 118
 	}
119 119
 
120 120
 
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
 	 *  @param	array		$headerlinefields	Array of fields name
140 140
 	 * 	@return	string
141 141
 	 */
142
-	function write_title_example($outputlangs,$headerlinefields)
142
+	function write_title_example($outputlangs, $headerlinefields)
143 143
 	{
144 144
         // phpcs:enable
145
-		$s=join($this->separator,array_map('cleansep',$headerlinefields));
145
+		$s = join($this->separator, array_map('cleansep', $headerlinefields));
146 146
 		return $s."\n";
147 147
 	}
148 148
 
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 	 * 	@param	array		$contentlinevalues	Array of lines
155 155
 	 * 	@return	string
156 156
 	 */
157
-	function write_record_example($outputlangs,$contentlinevalues)
157
+	function write_record_example($outputlangs, $contentlinevalues)
158 158
 	{
159 159
         // phpcs:enable
160
-		$s=join($this->separator,array_map('cleansep',$contentlinevalues));
160
+		$s = join($this->separator, array_map('cleansep', $contentlinevalues));
161 161
 		return $s."\n";
162 162
 	}
163 163
 
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
 	{
188 188
         // phpcs:enable
189 189
 		global $langs;
190
-		$ret=1;
190
+		$ret = 1;
191 191
 
192 192
 		dol_syslog(get_class($this)."::open_file file=".$file);
193 193
 
194
-		ini_set('auto_detect_line_endings',1);	// For MAC compatibility
194
+		ini_set('auto_detect_line_endings', 1); // For MAC compatibility
195 195
 
196 196
 		$this->handle = fopen(dol_osencode($file), "r");
197
-		if (! $this->handle)
197
+		if (!$this->handle)
198 198
 		{
199 199
 			$langs->load("errors");
200
-			$this->error=$langs->trans("ErrorFailToOpenFile",$file);
201
-			$ret=-1;
200
+			$this->error = $langs->trans("ErrorFailToOpenFile", $file);
201
+			$ret = -1;
202 202
 		}
203 203
 		else
204 204
 		{
205
-			$this->file=$file;
205
+			$this->file = $file;
206 206
 		}
207 207
 
208 208
 		return $ret;
@@ -247,47 +247,47 @@  discard block
 block discarded – undo
247 247
         // phpcs:enable
248 248
 		global $conf;
249 249
 
250
-		$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
250
+		$arrayres = fgetcsv($this->handle, 100000, $this->separator, $this->enclosure, $this->escape);
251 251
 
252 252
 		// End of file
253 253
 		if ($arrayres === false) return false;
254 254
 
255 255
 		//var_dump($this->handle);
256 256
 		//var_dump($arrayres);exit;
257
-		$newarrayres=array();
257
+		$newarrayres = array();
258 258
 		if ($arrayres && is_array($arrayres))
259 259
 		{
260
-			foreach($arrayres as $key => $val)
260
+			foreach ($arrayres as $key => $val)
261 261
 			{
262
-				if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
262
+				if (!empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
263 263
 				{
264 264
 					if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
265 265
 					{
266
-						$newarrayres[$key]['val']=$val;
267
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
266
+						$newarrayres[$key]['val'] = $val;
267
+						$newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null
268 268
 					}
269 269
 					else
270 270
 					{
271
-						$newarrayres[$key]['val']=utf8_encode($val);
272
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
271
+						$newarrayres[$key]['val'] = utf8_encode($val);
272
+						$newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null
273 273
 					}
274 274
 				}
275 275
 				else	// Autodetect format (UTF8 or ISO)
276 276
 				{
277 277
 					if (utf8_check($val))
278 278
 					{
279
-						$newarrayres[$key]['val']=$val;
280
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
279
+						$newarrayres[$key]['val'] = $val;
280
+						$newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null
281 281
 					}
282 282
 					else
283 283
 					{
284
-						$newarrayres[$key]['val']=utf8_encode($val);
285
-						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
284
+						$newarrayres[$key]['val'] = utf8_encode($val);
285
+						$newarrayres[$key]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we considere it's null
286 286
 					}
287 287
 				}
288 288
 			}
289 289
 
290
-			$this->col=count($newarrayres);
290
+			$this->col = count($newarrayres);
291 291
 		}
292 292
 
293 293
 		return $newarrayres;
@@ -319,24 +319,24 @@  discard block
 block discarded – undo
319 319
 	 * @param	array	$updatekeys						Array of keys to use to try to do an update first before insert. This field are defined into the module descriptor.
320 320
 	 * @return	int										<0 if KO, >0 if OK
321 321
 	 */
322
-	function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid,$updatekeys)
322
+	function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
323 323
 	{
324 324
         // phpcs:enable
325
-		global $langs,$conf,$user;
326
-        global $thirdparty_static;    	// Specific to thirdparty import
327
-		global $tablewithentity_cache;	// Cache to avoid to call  desc at each rows on tables
325
+		global $langs, $conf, $user;
326
+        global $thirdparty_static; // Specific to thirdparty import
327
+		global $tablewithentity_cache; // Cache to avoid to call  desc at each rows on tables
328 328
 
329
-		$error=0;
330
-		$warning=0;
331
-		$this->errors=array();
332
-		$this->warnings=array();
329
+		$error = 0;
330
+		$warning = 0;
331
+		$this->errors = array();
332
+		$this->warnings = array();
333 333
 
334 334
 		//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
335 335
 
336 336
 		//var_dump($array_match_file_to_database);
337 337
 		//var_dump($arrayrecord);
338
-		$array_match_database_to_file=array_flip($array_match_file_to_database);
339
-		$sort_array_match_file_to_database=$array_match_file_to_database;
338
+		$array_match_database_to_file = array_flip($array_match_file_to_database);
339
+		$sort_array_match_file_to_database = $array_match_file_to_database;
340 340
 		ksort($sort_array_match_file_to_database);
341 341
 
342 342
 		//var_dump($sort_array_match_file_to_database);
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
 		if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
345 345
 		{
346 346
 			//print 'W';
347
-			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
348
-			$this->warnings[$warning]['type']='EMPTY';
347
+			$this->warnings[$warning]['lib'] = $langs->trans('EmptyLine');
348
+			$this->warnings[$warning]['type'] = 'EMPTY';
349 349
 			$warning++;
350 350
 		}
351 351
 		else
@@ -354,25 +354,25 @@  discard block
 block discarded – undo
354 354
 			$updatedone = false;
355 355
 			$insertdone = false;
356 356
 			// For each table to insert, me make a separate insert
357
-			foreach($objimport->array_import_tables[0] as $alias => $tablename)
357
+			foreach ($objimport->array_import_tables[0] as $alias => $tablename)
358 358
 			{
359 359
 				// Build sql request
360
-				$sql='';
361
-				$listfields=array();
362
-				$listvalues=array();
363
-				$i=0;
364
-				$errorforthistable=0;
360
+				$sql = '';
361
+				$listfields = array();
362
+				$listvalues = array();
363
+				$i = 0;
364
+				$errorforthistable = 0;
365 365
 
366 366
 				// Define $tablewithentity_cache[$tablename] if not already defined
367
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
367
+				if (!isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
368 368
 				{
369 369
 					dol_syslog("Check if table ".$tablename." has an entity field");
370
-					$resql=$this->db->DDLDescTable($tablename,'entity');
370
+					$resql = $this->db->DDLDescTable($tablename, 'entity');
371 371
 					if ($resql)
372 372
 					{
373
-						$obj=$this->db->fetch_object($resql);
374
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
375
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
373
+						$obj = $this->db->fetch_object($resql);
374
+						if ($obj) $tablewithentity_cache[$tablename] = 1; // table contains entity field
375
+						else $tablewithentity_cache[$tablename] = 0; // table does not contains entity field
376 376
 					}
377 377
 					else dol_print_error($this->db);
378 378
 				}
@@ -383,26 +383,26 @@  discard block
 block discarded – undo
383 383
 
384 384
 
385 385
 				// Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
386
-				foreach($sort_array_match_file_to_database as $key => $val)
386
+				foreach ($sort_array_match_file_to_database as $key => $val)
387 387
 				{
388
-				    $fieldalias=preg_replace('/\..*$/i','',$val);
389
-				    $fieldname=preg_replace('/^.*\./i','',$val);
388
+				    $fieldalias = preg_replace('/\..*$/i', '', $val);
389
+				    $fieldname = preg_replace('/^.*\./i', '', $val);
390 390
 
391
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
391
+				    if ($alias != $fieldalias) continue; // Not a field of current table
392 392
 
393 393
 					if ($key <= $maxfields)
394 394
 					{
395 395
 						// Set $newval with value to insert and set $listvalues with sql request part for insert
396
-						$newval='';
397
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
396
+						$newval = '';
397
+						if ($arrayrecord[($key - 1)]['type'] > 0) $newval = $arrayrecord[($key - 1)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value
398 398
 
399 399
 						// Make some tests on $newval
400 400
 
401 401
 						// Is it a required field ?
402
-						if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ((string) $newval==''))
402
+						if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == ''))
403 403
 						{
404
-							$this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
405
-							$this->errors[$error]['type']='NOTNULL';
404
+							$this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', $key);
405
+							$this->errors[$error]['type'] = 'NOTNULL';
406 406
 							$errorforthistable++;
407 407
 							$error++;
408 408
 						}
@@ -410,28 +410,28 @@  discard block
 block discarded – undo
410 410
 						else
411 411
 						{
412 412
 						    // We convert field if required
413
-						    if (! empty($objimport->array_import_convertvalue[0][$val]))
413
+						    if (!empty($objimport->array_import_convertvalue[0][$val]))
414 414
 						    {
415 415
                                 //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. ';
416
-                                if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid'
417
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref'
418
-                                	|| $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel'
416
+                                if ($objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeid'
417
+                                	|| $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromref'
418
+                                	|| $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel'
419 419
                                 	)
420 420
                                 {
421 421
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
422
-                                    $isidorref='id';
423
-                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref';
424
-                                    $newval=preg_replace('/^(id|ref):/i','',$newval);    // Remove id: or ref: that was used to force if field is id or ref
422
+                                    $isidorref = 'id';
423
+                                    if (!is_numeric($newval) && $newval != '' && !preg_match('/^id:/i', $newval)) $isidorref = 'ref';
424
+                                    $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref
425 425
                                     //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n";
426 426
 
427 427
                                     if ($isidorref == 'ref')    // If value into input import file is a ref, we apply the function defined into descriptor
428 428
                                     {
429
-                                        $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']);
430
-                                        $class=$objimport->array_import_convertvalue[0][$val]['class'];
431
-                                        $method=$objimport->array_import_convertvalue[0][$val]['method'];
429
+                                        $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']);
430
+                                        $class = $objimport->array_import_convertvalue[0][$val]['class'];
431
+                                        $method = $objimport->array_import_convertvalue[0][$val]['method'];
432 432
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
433 433
                                         {
434
-                                        	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
434
+                                        	$newval = $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
435 435
                                         }
436 436
                                         else
437 437
 										{
@@ -441,94 +441,94 @@  discard block
 block discarded – undo
441 441
                                                 dol_print_error('', 'Error trying to call file='.$file.', class='.$class.', method='.$method);
442 442
                                                 break;
443 443
                                             }
444
-                                            $classinstance=new $class($this->db);
444
+                                            $classinstance = new $class($this->db);
445 445
                                             // Try the fetch from code or ref
446
-                                            call_user_func_array(array($classinstance, $method),array('', $newval));
446
+                                            call_user_func_array(array($classinstance, $method), array('', $newval));
447 447
                                             // If not found, try the fetch from label
448
-                                            if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel')
448
+                                            if (!($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule'] == 'fetchidfromcodeorlabel')
449 449
                                             {
450
-												call_user_func_array(array($classinstance, $method),array('', '', $newval));
450
+												call_user_func_array(array($classinstance, $method), array('', '', $newval));
451 451
                                             }
452
-                                            $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
452
+                                            $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] = $classinstance->id;
453 453
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
454 454
                                             if ($classinstance->id != '')	// id may be 0, it is a found value
455 455
                                             {
456
-                                                $newval=$classinstance->id;
456
+                                                $newval = $classinstance->id;
457 457
                                             }
458 458
                                             else
459 459
                                             {
460
-                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
461
-                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
462
-                                                else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
463
-                                                $this->errors[$error]['type']='FOREIGNKEY';
460
+                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib'] = $langs->trans('ErrorFieldValueNotIn', $key, $newval, 'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
461
+                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib'] = $langs->trans('ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
462
+                                                else $this->errors[$error]['lib'] = 'ErrorFieldValueNotIn';
463
+                                                $this->errors[$error]['type'] = 'FOREIGNKEY';
464 464
                                                 $errorforthistable++;
465 465
                                                 $error++;
466 466
                                             }
467 467
                                         }
468 468
                                     }
469 469
                                 }
470
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
470
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'zeroifnull')
471 471
                                 {
472
-                                    if (empty($newval)) $newval='0';
472
+                                    if (empty($newval)) $newval = '0';
473 473
                                 }
474
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
474
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomercodeifauto')
475 475
                                 {
476 476
                                     if (strtolower($newval) == 'auto')
477 477
                                     {
478
-                                        $this->thirpartyobject->get_codeclient(0,0);
479
-                                        $newval=$this->thirpartyobject->code_client;
478
+                                        $this->thirpartyobject->get_codeclient(0, 0);
479
+                                        $newval = $this->thirpartyobject->code_client;
480 480
                                         //print 'code_client='.$newval;
481 481
                                     }
482
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
482
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
483 483
                                 }
484
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
484
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto')
485 485
                                 {
486 486
                                     if (strtolower($newval) == 'auto')
487 487
                                     {
488
-                                        $newval=$this->thirpartyobject->get_codefournisseur(0,1);
489
-                                        $newval=$this->thirpartyobject->code_fournisseur;
488
+                                        $newval = $this->thirpartyobject->get_codefournisseur(0, 1);
489
+                                        $newval = $this->thirpartyobject->code_fournisseur;
490 490
                                         //print 'code_fournisseur='.$newval;
491 491
                                     }
492
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
492
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
493 493
                                 }
494
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
494
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto')
495 495
                                 {
496 496
                                     if (strtolower($newval) == 'auto')
497 497
                                     {
498 498
                                         $this->thirpartyobject->get_codecompta('customer');
499
-                                        $newval=$this->thirpartyobject->code_compta;
499
+                                        $newval = $this->thirpartyobject->code_compta;
500 500
                                         //print 'code_compta='.$newval;
501 501
                                     }
502
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
502
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
503 503
                                 }
504
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
504
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto')
505 505
                                 {
506 506
                                     if (strtolower($newval) == 'auto')
507 507
                                     {
508 508
                                         $this->thirpartyobject->get_codecompta('supplier');
509
-                                        $newval=$this->thirpartyobject->code_compta_fournisseur;
510
-                                        if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
509
+                                        $newval = $this->thirpartyobject->code_compta_fournisseur;
510
+                                        if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
511 511
                                         //print 'code_compta_fournisseur='.$newval;
512 512
                                     }
513
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
513
+                                    if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
514 514
                                 }
515
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
515
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto')
516 516
                                 {
517
-                                    $defaultref='';
517
+                                    $defaultref = '';
518 518
                                     // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function
519
-                                    $obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
520
-                                    if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
519
+                                    $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
520
+                                    if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
521 521
                                     {
522
-                                        require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
522
+                                        require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
523 523
                                         $modTask = new $obj;
524
-                                        $defaultref = $modTask->getNextValue(null,null);
524
+                                        $defaultref = $modTask->getNextValue(null, null);
525 525
                                     }
526
-                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
527
-                                    $newval=$defaultref;
526
+                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = '';
527
+                                    $newval = $defaultref;
528 528
                                 }
529 529
 
530 530
 
531
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
531
+                                elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric')
532 532
                                 {
533 533
                                     $newval = price2num($newval);
534 534
                                 }
@@ -537,27 +537,27 @@  discard block
 block discarded – undo
537 537
 						    }
538 538
 
539 539
 						    // Test regexp
540
-							if (! empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
540
+							if (!empty($objimport->array_import_regex[0][$val]) && ($newval != ''))
541 541
 							{
542 542
 								// If test is "Must exist in a field@table"
543
-								if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg))
543
+								if (preg_match('/^(.*)@(.*)$/', $objimport->array_import_regex[0][$val], $reg))
544 544
 								{
545
-									$field=$reg[1];
546
-									$table=$reg[2];
545
+									$field = $reg[1];
546
+									$table = $reg[2];
547 547
 
548 548
 									// Load content of field@table into cache array
549
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
549
+									if (!is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
550 550
 									{
551
-										$sql="SELECT ".$field." as aliasfield FROM ".$table;
552
-										$resql=$this->db->query($sql);
551
+										$sql = "SELECT ".$field." as aliasfield FROM ".$table;
552
+										$resql = $this->db->query($sql);
553 553
 										if ($resql)
554 554
 										{
555
-											$num=$this->db->num_rows($resql);
556
-											$i=0;
555
+											$num = $this->db->num_rows($resql);
556
+											$i = 0;
557 557
 											while ($i < $num)
558 558
 											{
559
-												$obj=$this->db->fetch_object($resql);
560
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
559
+												$obj = $this->db->fetch_object($resql);
560
+												if ($obj) $this->cachefieldtable[$field.'@'.$table][] = $obj->aliasfield;
561 561
 												$i++;
562 562
 											}
563 563
 										}
@@ -568,20 +568,20 @@  discard block
 block discarded – undo
568 568
 									}
569 569
 
570 570
 									// Now we check cache is not empty (should not) and key is into cache
571
-									if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table]))
571
+									if (!is_array($this->cachefieldtable[$field.'@'.$table]) || !in_array($newval, $this->cachefieldtable[$field.'@'.$table]))
572 572
 									{
573
-										$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table);
574
-										$this->errors[$error]['type']='FOREIGNKEY';
573
+										$this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorFieldValueNotIn', $key, $newval, $field, $table);
574
+										$this->errors[$error]['type'] = 'FOREIGNKEY';
575 575
 									    $errorforthistable++;
576 576
 										$error++;
577 577
 									}
578 578
 								}
579 579
 								// If test is just a static regex
580
-								else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval))
580
+								else if (!preg_match('/'.$objimport->array_import_regex[0][$val].'/i', $newval))
581 581
 								{
582 582
 								    //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."<br>";
583
-									$this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
584
-									$this->errors[$error]['type']='REGEX';
583
+									$this->errors[$error]['lib'] = $langs->transnoentitiesnoconv('ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
584
+									$this->errors[$error]['type'] = 'REGEX';
585 585
 									$errorforthistable++;
586 586
 									$error++;
587 587
 								}
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 						$listfields[] = $fieldname;
596 596
 
597 597
 						// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
598
-						if (empty($newval) && $arrayrecord[($key-1)]['type'] < 0) {
599
-                            $listvalues[] = ($newval=='0'?$newval:"null");
600
-                        } elseif (empty($newval) && $arrayrecord[($key-1)]['type'] == 0) {
598
+						if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) {
599
+                            $listvalues[] = ($newval == '0' ? $newval : "null");
600
+                        } elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) {
601 601
                             $listvalues[] = "''";
602 602
                         } else {
603 603
                             $listvalues[] = "'".$this->db->escape($newval)."'";
@@ -610,19 +610,19 @@  discard block
 block discarded – undo
610 610
 				if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0]))
611 611
 				{
612 612
     				// Loop on each hidden fields to add them into listfields/listvalues
613
-				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
613
+				    foreach ($objimport->array_import_fieldshidden[0] as $key => $val)
614 614
     				{
615
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
615
+    				    if (!preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table
616 616
     				    if ($val == 'user->id')
617 617
     				    {
618
-    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
618
+    				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./', '', $key);
619 619
     				        $listvalues[] = $user->id;
620 620
     				    }
621
-    				    elseif (preg_match('/^lastrowid-/',$val))
621
+    				    elseif (preg_match('/^lastrowid-/', $val))
622 622
     				    {
623
-    				        $tmp=explode('-',$val);
624
-    				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
625
-							$keyfield = preg_replace('/^'.preg_quote($alias).'\./','',$key);
623
+    				        $tmp = explode('-', $val);
624
+    				        $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
625
+							$keyfield = preg_replace('/^'.preg_quote($alias).'\./', '', $key);
626 626
     				        $listfields[] = $keyfield;
627 627
                             $listvalues[] = $lastinsertid;
628 628
     				        //print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 
634 634
 				// If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined
635 635
 				// so we can try to make the insert or update now.
636
-				if (! $errorforthistable)
636
+				if (!$errorforthistable)
637 637
 				{
638 638
 					//print "$alias/$tablename/$listfields/$listvalues<br>";
639 639
 					if (!empty($listfields))
@@ -652,21 +652,21 @@  discard block
 block discarded – undo
652 652
 								$filters = array();
653 653
 								foreach ($updatekeys as $key) {
654 654
 									$col = $objimport->array_import_updatekeys[0][$key];
655
-									$key=preg_replace('/^.*\./i','',$key);
655
+									$key = preg_replace('/^.*\./i', '', $key);
656 656
 									$where[] = $key.' = '.$data[$key];
657 657
 									$filters[] = $col.' = '.$data[$key];
658 658
 								}
659
-								$sqlSelect.= ' WHERE '.implode(' AND ', $where);
659
+								$sqlSelect .= ' WHERE '.implode(' AND ', $where);
660 660
 
661
-								$resql=$this->db->query($sqlSelect);
662
-								if($resql) {
661
+								$resql = $this->db->query($sqlSelect);
662
+								if ($resql) {
663 663
 									$res = $this->db->fetch_object($resql);
664
-									if($resql->num_rows == 1) {
664
+									if ($resql->num_rows == 1) {
665 665
 										$lastinsertid = $res->rowid;
666 666
 										$last_insert_id_array[$tablename] = $lastinsertid;
667
-									} else if($resql->num_rows > 1) {
668
-										$this->errors[$error]['lib']=$langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
669
-										$this->errors[$error]['type']='SQL';
667
+									} else if ($resql->num_rows > 1) {
668
+										$this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode($filters, ', '));
669
+										$this->errors[$error]['type'] = 'SQL';
670 670
 										$error++;
671 671
 									} else {
672 672
 										// No record found with filters, insert will be tried below
@@ -675,8 +675,8 @@  discard block
 block discarded – undo
675 675
 								else
676 676
 								{
677 677
 									//print 'E';
678
-									$this->errors[$error]['lib']=$this->db->lasterror();
679
-									$this->errors[$error]['type']='SQL';
678
+									$this->errors[$error]['lib'] = $this->db->lasterror();
679
+									$this->errors[$error]['type'] = 'SQL';
680 680
 									$error++;
681 681
 								}
682 682
 							} else {
@@ -687,13 +687,13 @@  discard block
 block discarded – undo
687 687
 								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
688 688
 								$sqlSelect = 'SELECT rowid FROM '.$tablename;
689 689
 
690
-								if(empty($keyfield)) $keyfield = 'rowid';
690
+								if (empty($keyfield)) $keyfield = 'rowid';
691 691
 								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
692 692
 
693
-								$resql=$this->db->query($sqlSelect);
694
-								if($resql) {
693
+								$resql = $this->db->query($sqlSelect);
694
+								if ($resql) {
695 695
 									$res = $this->db->fetch_object($resql);
696
-									if($resql->num_rows == 1) {
696
+									if ($resql->num_rows == 1) {
697 697
 										// We have a row referencing this last foreign key, continue with UPDATE.
698 698
 									} else {
699 699
 										// No record found referencing this last foreign key,
@@ -704,8 +704,8 @@  discard block
 block discarded – undo
704 704
 								else
705 705
 								{
706 706
 									//print 'E';
707
-									$this->errors[$error]['lib']=$this->db->lasterror();
708
-									$this->errors[$error]['type']='SQL';
707
+									$this->errors[$error]['lib'] = $this->db->lasterror();
708
+									$this->errors[$error]['type'] = 'SQL';
709 709
 									$error++;
710 710
 								}
711 711
 							}
@@ -719,24 +719,24 @@  discard block
 block discarded – undo
719 719
 								foreach ($data as $key => $val) {
720 720
 									$set[] = $key.' = '.$val;
721 721
 								}
722
-								$sqlstart.= ' SET '.implode(', ', $set);
722
+								$sqlstart .= ' SET '.implode(', ', $set);
723 723
 
724
-								if(empty($keyfield)) $keyfield = 'rowid';
724
+								if (empty($keyfield)) $keyfield = 'rowid';
725 725
 								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
726 726
 
727 727
 								$sql = $sqlstart.$sqlend;
728 728
 
729 729
 								// Run update request
730
-								$resql=$this->db->query($sql);
731
-								if($resql) {
730
+								$resql = $this->db->query($sql);
731
+								if ($resql) {
732 732
 									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
733 733
 									$updatedone = true;
734 734
 								}
735 735
 								else
736 736
 								{
737 737
 									//print 'E';
738
-									$this->errors[$error]['lib']=$this->db->lasterror();
739
-									$this->errors[$error]['type']='SQL';
738
+									$this->errors[$error]['lib'] = $this->db->lasterror();
739
+									$this->errors[$error]['type'] = 'SQL';
740 740
 									$error++;
741 741
 								}
742 742
 							}
@@ -747,13 +747,13 @@  discard block
 block discarded – undo
747 747
 							// Build SQL INSERT request
748 748
 							$sqlstart = 'INSERT INTO '.$tablename.'('.implode(', ', $listfields).', import_key';
749 749
 							$sqlend = ') VALUES('.implode(', ', $listvalues).", '".$importid."'";
750
-							if (! empty($tablewithentity_cache[$tablename])) {
751
-								$sqlstart.= ', entity';
752
-								$sqlend.= ', '.$conf->entity;
750
+							if (!empty($tablewithentity_cache[$tablename])) {
751
+								$sqlstart .= ', entity';
752
+								$sqlend .= ', '.$conf->entity;
753 753
 							}
754
-							if (! empty($objimport->array_import_tables_creator[0][$alias])) {
755
-								$sqlstart.= ', '.$objimport->array_import_tables_creator[0][$alias];
756
-								$sqlend.=', '.$user->id;
754
+							if (!empty($objimport->array_import_tables_creator[0][$alias])) {
755
+								$sqlstart .= ', '.$objimport->array_import_tables_creator[0][$alias];
756
+								$sqlend .= ', '.$user->id;
757 757
 							}
758 758
 							$sql = $sqlstart.$sqlend.')';
759 759
 							dol_syslog("import_csv.modules", LOG_DEBUG);
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 							// Run insert request
762 762
 							if ($sql)
763 763
 							{
764
-								$resql=$this->db->query($sql);
764
+								$resql = $this->db->query($sql);
765 765
 								if ($resql)
766 766
 								{
767 767
 								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
@@ -770,8 +770,8 @@  discard block
 block discarded – undo
770 770
 								else
771 771
 								{
772 772
 									//print 'E';
773
-									$this->errors[$error]['lib']=$this->db->lasterror();
774
-									$this->errors[$error]['type']='SQL';
773
+									$this->errors[$error]['lib'] = $this->db->lasterror();
774
+									$this->errors[$error]['type'] = 'SQL';
775 775
 									$error++;
776 776
 								}
777 777
 							}
@@ -786,8 +786,8 @@  discard block
 block discarded – undo
786 786
 			    if ($error) break;
787 787
 			}
788 788
 
789
-			if($updatedone) $this->nbupdate++;
790
-			if($insertdone) $this->nbinsert++;
789
+			if ($updatedone) $this->nbupdate++;
790
+			if ($insertdone) $this->nbinsert++;
791 791
 		}
792 792
 
793 793
 		return 1;
@@ -802,5 +802,5 @@  discard block
 block discarded – undo
802 802
  */
803 803
 function cleansep($value)
804 804
 {
805
-	return str_replace(array(',',';'),'/',$value);
805
+	return str_replace(array(',', ';'), '/', $value);
806 806
 };
Please login to merge, or discard this patch.
Braces   +117 added lines, -73 removed lines patch added patch discarded remove patch
@@ -114,7 +114,9 @@  discard block
 block discarded – undo
114 114
 		$this->version_lib=DOL_VERSION;
115 115
 
116 116
 		$this->datatoimport=$datatoimport;
117
-		if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db);
117
+		if (preg_match('/^societe_/',$datatoimport)) {
118
+		    $this->thirpartyobject=new Societe($this->db);
119
+		}
118 120
 	}
119 121
 
120 122
 
@@ -199,8 +201,7 @@  discard block
 block discarded – undo
199 201
 			$langs->load("errors");
200 202
 			$this->error=$langs->trans("ErrorFailToOpenFile",$file);
201 203
 			$ret=-1;
202
-		}
203
-		else
204
+		} else
204 205
 		{
205 206
 			$this->file=$file;
206 207
 		}
@@ -250,7 +251,9 @@  discard block
 block discarded – undo
250 251
 		$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
251 252
 
252 253
 		// End of file
253
-		if ($arrayres === false) return false;
254
+		if ($arrayres === false) {
255
+		    return false;
256
+		}
254 257
 
255 258
 		//var_dump($this->handle);
256 259
 		//var_dump($arrayres);exit;
@@ -259,27 +262,26 @@  discard block
 block discarded – undo
259 262
 		{
260 263
 			foreach($arrayres as $key => $val)
261 264
 			{
262
-				if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET))	// Forced charset
265
+				if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) {
266
+				    // Forced charset
263 267
 				{
264 268
 					if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8')
265 269
 					{
266 270
 						$newarrayres[$key]['val']=$val;
271
+				}
267 272
 						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
268
-					}
269
-					else
273
+					} else
270 274
 					{
271 275
 						$newarrayres[$key]['val']=utf8_encode($val);
272 276
 						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
273 277
 					}
274
-				}
275
-				else	// Autodetect format (UTF8 or ISO)
278
+				} else	// Autodetect format (UTF8 or ISO)
276 279
 				{
277 280
 					if (utf8_check($val))
278 281
 					{
279 282
 						$newarrayres[$key]['val']=$val;
280 283
 						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
281
-					}
282
-					else
284
+					} else
283 285
 					{
284 286
 						$newarrayres[$key]['val']=utf8_encode($val);
285 287
 						$newarrayres[$key]['type']=(dol_strlen($val)?1:-1);	// If empty we considere it's null
@@ -347,8 +349,7 @@  discard block
 block discarded – undo
347 349
 			$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
348 350
 			$this->warnings[$warning]['type']='EMPTY';
349 351
 			$warning++;
350
-		}
351
-		else
352
+		} else
352 353
 		{
353 354
 			$last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
354 355
 			$updatedone = false;
@@ -364,19 +365,27 @@  discard block
 block discarded – undo
364 365
 				$errorforthistable=0;
365 366
 
366 367
 				// Define $tablewithentity_cache[$tablename] if not already defined
367
-				if (! isset($tablewithentity_cache[$tablename]))	// keep this test with "isset"
368
+				if (! isset($tablewithentity_cache[$tablename])) {
369
+				    // keep this test with "isset"
368 370
 				{
369 371
 					dol_syslog("Check if table ".$tablename." has an entity field");
372
+				}
370 373
 					$resql=$this->db->DDLDescTable($tablename,'entity');
371 374
 					if ($resql)
372 375
 					{
373 376
 						$obj=$this->db->fetch_object($resql);
374
-						if ($obj) $tablewithentity_cache[$tablename]=1;		// table contains entity field
375
-						else $tablewithentity_cache[$tablename]=0;			// table does not contains entity field
377
+						if ($obj) {
378
+						    $tablewithentity_cache[$tablename]=1;
379
+						}
380
+						// table contains entity field
381
+						else {
382
+						    $tablewithentity_cache[$tablename]=0;
383
+						}
384
+						// table does not contains entity field
385
+					} else {
386
+					    dol_print_error($this->db);
376 387
 					}
377
-					else dol_print_error($this->db);
378
-				}
379
-				else
388
+				} else
380 389
 				{
381 390
 					//dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
382 391
 				}
@@ -388,13 +397,19 @@  discard block
 block discarded – undo
388 397
 				    $fieldalias=preg_replace('/\..*$/i','',$val);
389 398
 				    $fieldname=preg_replace('/^.*\./i','',$val);
390 399
 
391
-				    if ($alias != $fieldalias) continue;    // Not a field of current table
400
+				    if ($alias != $fieldalias) {
401
+				        continue;
402
+				    }
403
+				    // Not a field of current table
392 404
 
393 405
 					if ($key <= $maxfields)
394 406
 					{
395 407
 						// Set $newval with value to insert and set $listvalues with sql request part for insert
396 408
 						$newval='';
397
-						if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val'];    // If type of field into input file is not empty string (so defined into input file), we get value
409
+						if ($arrayrecord[($key-1)]['type'] > 0) {
410
+						    $newval=$arrayrecord[($key-1)]['val'];
411
+						}
412
+						// If type of field into input file is not empty string (so defined into input file), we get value
398 413
 
399 414
 						// Make some tests on $newval
400 415
 
@@ -420,20 +435,23 @@  discard block
 block discarded – undo
420 435
                                 {
421 436
                                     // New val can be an id or ref. If it start with id: it is forced to id, if it start with ref: it is forced to ref. It not, we try to guess.
422 437
                                     $isidorref='id';
423
-                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) $isidorref='ref';
438
+                                    if (! is_numeric($newval) && $newval != '' && ! preg_match('/^id:/i',$newval)) {
439
+                                        $isidorref='ref';
440
+                                    }
424 441
                                     $newval=preg_replace('/^(id|ref):/i','',$newval);    // Remove id: or ref: that was used to force if field is id or ref
425 442
                                     //print 'Val is now '.$newval.' and is type '.$isidorref."<br>\n";
426 443
 
427
-                                    if ($isidorref == 'ref')    // If value into input import file is a ref, we apply the function defined into descriptor
444
+                                    if ($isidorref == 'ref') {
445
+                                        // If value into input import file is a ref, we apply the function defined into descriptor
428 446
                                     {
429 447
                                         $file=(empty($objimport->array_import_convertvalue[0][$val]['classfile'])?$objimport->array_import_convertvalue[0][$val]['file']:$objimport->array_import_convertvalue[0][$val]['classfile']);
448
+                                    }
430 449
                                         $class=$objimport->array_import_convertvalue[0][$val]['class'];
431 450
                                         $method=$objimport->array_import_convertvalue[0][$val]['method'];
432 451
                                         if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '')
433 452
                                         {
434 453
                                         	$newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval];
435
-                                        }
436
-                                        else
454
+                                        } else
437 455
 										{
438 456
                                             $resultload = dol_include_once($file);
439 457
                                             if (empty($resultload))
@@ -451,27 +469,32 @@  discard block
 block discarded – undo
451 469
                                             }
452 470
                                             $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id;
453 471
                                             //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. ';
454
-                                            if ($classinstance->id != '')	// id may be 0, it is a found value
472
+                                            if ($classinstance->id != '') {
473
+                                                // id may be 0, it is a found value
455 474
                                             {
456 475
                                                 $newval=$classinstance->id;
457 476
                                             }
458
-                                            else
477
+                                            } else
459 478
                                             {
460
-                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
461
-                                                else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
462
-                                                else $this->errors[$error]['lib']='ErrorFieldValueNotIn';
479
+                                                if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) {
480
+                                                    $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict']));
481
+                                                } else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) {
482
+                                                    $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element']));
483
+                                                } else {
484
+                                                    $this->errors[$error]['lib']='ErrorFieldValueNotIn';
485
+                                                }
463 486
                                                 $this->errors[$error]['type']='FOREIGNKEY';
464 487
                                                 $errorforthistable++;
465 488
                                                 $error++;
466 489
                                             }
467 490
                                         }
468 491
                                     }
469
-                                }
470
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
492
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull')
471 493
                                 {
472
-                                    if (empty($newval)) $newval='0';
473
-                                }
474
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
494
+                                    if (empty($newval)) {
495
+                                        $newval='0';
496
+                                    }
497
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifauto')
475 498
                                 {
476 499
                                     if (strtolower($newval) == 'auto')
477 500
                                     {
@@ -479,9 +502,11 @@  discard block
 block discarded – undo
479 502
                                         $newval=$this->thirpartyobject->code_client;
480 503
                                         //print 'code_client='.$newval;
481 504
                                     }
482
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
483
-                                }
484
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
505
+                                    if (empty($newval)) {
506
+                                        $arrayrecord[($key-1)]['type']=-1;
507
+                                    }
508
+                                    // If we get empty value, we will use "null"
509
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifauto')
485 510
                                 {
486 511
                                     if (strtolower($newval) == 'auto')
487 512
                                     {
@@ -489,9 +514,11 @@  discard block
 block discarded – undo
489 514
                                         $newval=$this->thirpartyobject->code_fournisseur;
490 515
                                         //print 'code_fournisseur='.$newval;
491 516
                                     }
492
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
493
-                                }
494
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
517
+                                    if (empty($newval)) {
518
+                                        $arrayrecord[($key-1)]['type']=-1;
519
+                                    }
520
+                                    // If we get empty value, we will use "null"
521
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifauto')
495 522
                                 {
496 523
                                     if (strtolower($newval) == 'auto')
497 524
                                     {
@@ -499,20 +526,27 @@  discard block
 block discarded – undo
499 526
                                         $newval=$this->thirpartyobject->code_compta;
500 527
                                         //print 'code_compta='.$newval;
501 528
                                     }
502
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
503
-                                }
504
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
529
+                                    if (empty($newval)) {
530
+                                        $arrayrecord[($key-1)]['type']=-1;
531
+                                    }
532
+                                    // If we get empty value, we will use "null"
533
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifauto')
505 534
                                 {
506 535
                                     if (strtolower($newval) == 'auto')
507 536
                                     {
508 537
                                         $this->thirpartyobject->get_codecompta('supplier');
509 538
                                         $newval=$this->thirpartyobject->code_compta_fournisseur;
510
-                                        if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
539
+                                        if (empty($newval)) {
540
+                                            $arrayrecord[($key-1)]['type']=-1;
541
+                                        }
542
+                                        // If we get empty value, we will use "null"
511 543
                                         //print 'code_compta_fournisseur='.$newval;
512 544
                                     }
513
-                                    if (empty($newval)) $arrayrecord[($key-1)]['type']=-1;	// If we get empty value, we will use "null"
514
-                                }
515
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
545
+                                    if (empty($newval)) {
546
+                                        $arrayrecord[($key-1)]['type']=-1;
547
+                                    }
548
+                                    // If we get empty value, we will use "null"
549
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getrefifauto')
516 550
                                 {
517 551
                                     $defaultref='';
518 552
                                     // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function
@@ -523,12 +557,11 @@  discard block
 block discarded – undo
523 557
                                         $modTask = new $obj;
524 558
                                         $defaultref = $modTask->getNextValue(null,null);
525 559
                                     }
526
-                                    if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
560
+                                    if (is_numeric($defaultref) && $defaultref <= 0) {
561
+                                        $defaultref='';
562
+                                    }
527 563
                                     $newval=$defaultref;
528
-                                }
529
-
530
-
531
-                                elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
564
+                                } elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='numeric')
532 565
                                 {
533 566
                                     $newval = price2num($newval);
534 567
                                 }
@@ -546,9 +579,11 @@  discard block
 block discarded – undo
546 579
 									$table=$reg[2];
547 580
 
548 581
 									// Load content of field@table into cache array
549
-									if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache
582
+									if (! is_array($this->cachefieldtable[$field.'@'.$table])) {
583
+									    // If content of field@table not already loaded into cache
550 584
 									{
551 585
 										$sql="SELECT ".$field." as aliasfield FROM ".$table;
586
+									}
552 587
 										$resql=$this->db->query($sql);
553 588
 										if ($resql)
554 589
 										{
@@ -557,11 +592,12 @@  discard block
 block discarded – undo
557 592
 											while ($i < $num)
558 593
 											{
559 594
 												$obj=$this->db->fetch_object($resql);
560
-												if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
595
+												if ($obj) {
596
+												    $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield;
597
+												}
561 598
 												$i++;
562 599
 											}
563
-										}
564
-										else
600
+										} else
565 601
 										{
566 602
 											dol_print_error($this->db);
567 603
 										}
@@ -612,13 +648,15 @@  discard block
 block discarded – undo
612 648
     				// Loop on each hidden fields to add them into listfields/listvalues
613 649
 				    foreach($objimport->array_import_fieldshidden[0] as $key => $val)
614 650
     				{
615
-    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue;    // Not a field of current table
651
+    				    if (! preg_match('/^'.preg_quote($alias).'\./', $key)) {
652
+    				        continue;
653
+    				    }
654
+    				    // Not a field of current table
616 655
     				    if ($val == 'user->id')
617 656
     				    {
618 657
     				        $listfields[] = preg_replace('/^'.preg_quote($alias).'\./','',$key);
619 658
     				        $listvalues[] = $user->id;
620
-    				    }
621
-    				    elseif (preg_match('/^lastrowid-/',$val))
659
+    				    } elseif (preg_match('/^lastrowid-/',$val))
622 660
     				    {
623 661
     				        $tmp=explode('-',$val);
624 662
     				        $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
@@ -671,8 +709,7 @@  discard block
 block discarded – undo
671 709
 									} else {
672 710
 										// No record found with filters, insert will be tried below
673 711
 									}
674
-								}
675
-								else
712
+								} else
676 713
 								{
677 714
 									//print 'E';
678 715
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -687,7 +724,9 @@  discard block
 block discarded – undo
687 724
 								// Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object'
688 725
 								$sqlSelect = 'SELECT rowid FROM '.$tablename;
689 726
 
690
-								if(empty($keyfield)) $keyfield = 'rowid';
727
+								if(empty($keyfield)) {
728
+								    $keyfield = 'rowid';
729
+								}
691 730
 								$sqlSelect .= ' WHERE '.$keyfield.' = '.$lastinsertid;
692 731
 
693 732
 								$resql=$this->db->query($sqlSelect);
@@ -700,8 +739,7 @@  discard block
 block discarded – undo
700 739
 										// force $lastinsertid to 0 so we INSERT below.
701 740
 										$lastinsertid = 0;
702 741
 									}
703
-								}
704
-								else
742
+								} else
705 743
 								{
706 744
 									//print 'E';
707 745
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -721,7 +759,9 @@  discard block
 block discarded – undo
721 759
 								}
722 760
 								$sqlstart.= ' SET '.implode(', ', $set);
723 761
 
724
-								if(empty($keyfield)) $keyfield = 'rowid';
762
+								if(empty($keyfield)) {
763
+								    $keyfield = 'rowid';
764
+								}
725 765
 								$sqlend = ' WHERE '.$keyfield.' = '.$lastinsertid;
726 766
 
727 767
 								$sql = $sqlstart.$sqlend;
@@ -731,8 +771,7 @@  discard block
 block discarded – undo
731 771
 								if($resql) {
732 772
 									// No error, update has been done. $this->db->db->affected_rows can be 0 if data hasn't changed
733 773
 									$updatedone = true;
734
-								}
735
-								else
774
+								} else
736 775
 								{
737 776
 									//print 'E';
738 777
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -766,8 +805,7 @@  discard block
 block discarded – undo
766 805
 								{
767 806
 								    $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that child tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
768 807
 								    $insertdone = true;
769
-								}
770
-								else
808
+								} else
771 809
 								{
772 810
 									//print 'E';
773 811
 									$this->errors[$error]['lib']=$this->db->lasterror();
@@ -783,11 +821,17 @@  discard block
 block discarded – undo
783 821
 					}*/
784 822
 				}
785 823
 
786
-			    if ($error) break;
824
+			    if ($error) {
825
+			        break;
826
+			    }
787 827
 			}
788 828
 
789
-			if($updatedone) $this->nbupdate++;
790
-			if($insertdone) $this->nbinsert++;
829
+			if($updatedone) {
830
+			    $this->nbupdate++;
831
+			}
832
+			if($insertdone) {
833
+			    $this->nbinsert++;
834
+			}
791 835
 		}
792 836
 
793 837
 		return 1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modClickToDial.class.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -33,44 +33,44 @@
 block discarded – undo
33 33
 class modClickToDial extends DolibarrModules
34 34
 {
35 35
 
36
-	/**
37
-	 *   Constructor. Define names, constants, directories, boxes, permissions
38
-	 *
39
-	 *   @param      DoliDB		$db      Database handler
40
-	 */
41
-	function __construct($db)
42
-	{
43
-		$this->db = $db;
44
-		$this->numero = 58;
36
+    /**
37
+     *   Constructor. Define names, constants, directories, boxes, permissions
38
+     *
39
+     *   @param      DoliDB		$db      Database handler
40
+     */
41
+    function __construct($db)
42
+    {
43
+        $this->db = $db;
44
+        $this->numero = 58;
45 45
 
46
-		$this->family = "interface";
47
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
48
-		$this->name = preg_replace('/^mod/i','',get_class($this));
49
-		$this->description = "Gestion du Click To Dial";
46
+        $this->family = "interface";
47
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
48
+        $this->name = preg_replace('/^mod/i','',get_class($this));
49
+        $this->description = "Gestion du Click To Dial";
50 50
 
51
-		$this->version = 'dolibarr';		// 'development' or 'experimental' or 'dolibarr' or version
51
+        $this->version = 'dolibarr';		// 'development' or 'experimental' or 'dolibarr' or version
52 52
 
53
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
54
-		$this->picto='phoning';
53
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
54
+        $this->picto='phoning';
55 55
 
56
-		// Data directories to create when module is enabled
57
-		$this->dirs = array();
56
+        // Data directories to create when module is enabled
57
+        $this->dirs = array();
58 58
 
59
-		// Dependencies
60
-		$this->depends = array();
61
-		$this->requiredby = array();
59
+        // Dependencies
60
+        $this->depends = array();
61
+        $this->requiredby = array();
62 62
 
63
-		// Config pages
64
-		$this->config_page_url = array("clicktodial.php");
63
+        // Config pages
64
+        $this->config_page_url = array("clicktodial.php");
65 65
 
66
-		// Constants
67
-		$this->const = array();
66
+        // Constants
67
+        $this->const = array();
68 68
 
69
-		// Boxes
70
-		$this->boxes = array();
69
+        // Boxes
70
+        $this->boxes = array();
71 71
 
72
-		// Permissions
73
-		$this->rights = array();
74
-		$this->rights_class = 'clicktodial';
75
-	}
72
+        // Permissions
73
+        $this->rights = array();
74
+        $this->rights_class = 'clicktodial';
75
+    }
76 76
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  *	\brief      Fichier de description et activation du module de click to Dial
25 25
  */
26 26
 
27
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
27
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
28 28
 
29 29
 
30 30
 /**
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
 
46 46
 		$this->family = "interface";
47 47
 		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
48
-		$this->name = preg_replace('/^mod/i','',get_class($this));
48
+		$this->name = preg_replace('/^mod/i', '', get_class($this));
49 49
 		$this->description = "Gestion du Click To Dial";
50 50
 
51
-		$this->version = 'dolibarr';		// 'development' or 'experimental' or 'dolibarr' or version
51
+		$this->version = 'dolibarr'; // 'development' or 'experimental' or 'dolibarr' or version
52 52
 
53 53
 		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
54
-		$this->picto='phoning';
54
+		$this->picto = 'phoning';
55 55
 
56 56
 		// Data directories to create when module is enabled
57 57
 		$this->dirs = array();
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modAccounting.class.php 2 patches
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -32,161 +32,161 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class modAccounting extends DolibarrModules
34 34
 {
35
-	/**
36
-	 *   Constructor. Define names, constants, directories, boxes, permissions
37
-	 *
38
-	 *   @param      DoliDB		$db      Database handler
39
-	 */
40
-	function __construct($db)
41
-	{
42
-		global $conf;
35
+    /**
36
+     *   Constructor. Define names, constants, directories, boxes, permissions
37
+     *
38
+     *   @param      DoliDB		$db      Database handler
39
+     */
40
+    function __construct($db)
41
+    {
42
+        global $conf;
43 43
 
44
-		$this->db = $db;
45
-		$this->numero = 50400;
44
+        $this->db = $db;
45
+        $this->numero = 50400;
46 46
 
47
-		$this->family = "financial";
48
-		$this->module_position = '61';
49
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
50
-		$this->name = preg_replace('/^mod/i', '', get_class($this));
51
-		$this->description = "Advanced accounting management";
47
+        $this->family = "financial";
48
+        $this->module_position = '61';
49
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
50
+        $this->name = preg_replace('/^mod/i', '', get_class($this));
51
+        $this->description = "Advanced accounting management";
52 52
 
53
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
54
-		$this->version = 'dolibarr';
53
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
54
+        $this->version = 'dolibarr';
55 55
 
56
-		$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
57
-		$this->picto = 'accounting';
56
+        $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
57
+        $this->picto = 'accounting';
58 58
 
59
-		// Data directories to create when module is enabled
60
-		$this->dirs = array('/accounting/temp');
59
+        // Data directories to create when module is enabled
60
+        $this->dirs = array('/accounting/temp');
61 61
 
62
-		// Config pages
63
-		$this->config_page_url = array();
62
+        // Config pages
63
+        $this->config_page_url = array();
64 64
 
65
-		// Dependencies
66
-		$this->depends = array("modFacture","modBanque","modTax"); // List of modules id that must be enabled if this module is enabled
67
-		$this->requiredby = array(); // List of modules id to disable if this one is disabled
68
-		$this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module
69
-		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
70
-		$this->need_dolibarr_version = array(3, 9); // Minimum version of Dolibarr required by module
71
-		$this->langfiles = array("accountancy","compta");
65
+        // Dependencies
66
+        $this->depends = array("modFacture","modBanque","modTax"); // List of modules id that must be enabled if this module is enabled
67
+        $this->requiredby = array(); // List of modules id to disable if this one is disabled
68
+        $this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module
69
+        $this->phpmin = array(5, 4); // Minimum version of PHP required by module
70
+        $this->need_dolibarr_version = array(3, 9); // Minimum version of Dolibarr required by module
71
+        $this->langfiles = array("accountancy","compta");
72 72
 
73
-		// Constants
74
-		// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
75
-		// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
76
-		//                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
77
-		// );
78
-		$this->const = array();
79
-		$this->const[1] = array(
80
-				"MAIN_COMPANY_CODE_ALWAYS_REQUIRED",
81
-				"chaine",
82
-				"1",
83
-				"With this constants on, third party code is always required whatever is numbering module behaviour", 0, 'current', 1
84
-		);
85
-		$this->const[2] = array(
86
-				"MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED",
87
-				"chaine",
88
-				"1",
89
-				"With this constants on, bank account number is always required", 0, 'current', 1
90
-		);
91
-		$this->const[3] = array(
92
-				"ACCOUNTING_ACCOUNT_SUSPENSE",
93
-				"chaine",
94
-				"471",
95
-				"", 0, 'current', 0
96
-		);
97
-		$this->const[4] = array(
98
-				"ACCOUNTING_ACCOUNT_TRANSFER_CASH",
99
-				"chaine",
100
-				"58",
101
-				"", 0, 'current', 0
102
-		);
103
-		$this->const[5] = array(
104
-				"CHARTOFACCOUNTS",
105
-				"chaine",
106
-				"2",
107
-				"", 0, 'current', 0
108
-		);
109
-		$this->const[6] = array(
110
-				"ACCOUNTING_EXPORT_MODELCSV",
111
-				"chaine",
112
-				"1",
113
-				"", 0, 'current', 0
114
-		);
115
-		$this->const[7] = array(
116
-				"ACCOUNTING_LENGTH_GACCOUNT",
117
-				"chaine",
118
-				"",
119
-				"", 0, 'current', 0
120
-		);
121
-		$this->const[8] = array(
122
-				"ACCOUNTING_LENGTH_AACCOUNT",
123
-				"chaine",
124
-				"",
125
-				"", 0, 'current', 0
126
-		);
127
-		$this->const[9] = array(
128
-				"ACCOUNTING_LIST_SORT_VENTILATION_TODO",
129
-				"yesno",
130
-				"1",
131
-				"", 0, 'current', 0
132
-		);
133
-		$this->const[10] = array(
134
-				"ACCOUNTING_LIST_SORT_VENTILATION_DONE",
135
-				"yesno",
136
-				"1",
137
-				"", 0, 'current', 0
138
-		);
139
-		$this->const[11] = array (
140
-				"ACCOUNTING_EXPORT_DATE",
141
-				"chaine",
142
-				"%d%m%Y",
143
-				"", 0, 'current', 0
144
-		);
145
-		$this->const[12] = array(
146
-				"ACCOUNTING_EXPORT_SEPARATORCSV",
147
-				"string",
148
-				",",
149
-				"", 0, 'current', 0
150
-		);
151
-		$this->const[13] = array(
152
-				"ACCOUNTING_EXPORT_FORMAT",
153
-				"chaine",
154
-				"csv",
155
-				"", 0, 'current', 0
156
-		);
73
+        // Constants
74
+        // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
75
+        // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
76
+        //                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
77
+        // );
78
+        $this->const = array();
79
+        $this->const[1] = array(
80
+                "MAIN_COMPANY_CODE_ALWAYS_REQUIRED",
81
+                "chaine",
82
+                "1",
83
+                "With this constants on, third party code is always required whatever is numbering module behaviour", 0, 'current', 1
84
+        );
85
+        $this->const[2] = array(
86
+                "MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED",
87
+                "chaine",
88
+                "1",
89
+                "With this constants on, bank account number is always required", 0, 'current', 1
90
+        );
91
+        $this->const[3] = array(
92
+                "ACCOUNTING_ACCOUNT_SUSPENSE",
93
+                "chaine",
94
+                "471",
95
+                "", 0, 'current', 0
96
+        );
97
+        $this->const[4] = array(
98
+                "ACCOUNTING_ACCOUNT_TRANSFER_CASH",
99
+                "chaine",
100
+                "58",
101
+                "", 0, 'current', 0
102
+        );
103
+        $this->const[5] = array(
104
+                "CHARTOFACCOUNTS",
105
+                "chaine",
106
+                "2",
107
+                "", 0, 'current', 0
108
+        );
109
+        $this->const[6] = array(
110
+                "ACCOUNTING_EXPORT_MODELCSV",
111
+                "chaine",
112
+                "1",
113
+                "", 0, 'current', 0
114
+        );
115
+        $this->const[7] = array(
116
+                "ACCOUNTING_LENGTH_GACCOUNT",
117
+                "chaine",
118
+                "",
119
+                "", 0, 'current', 0
120
+        );
121
+        $this->const[8] = array(
122
+                "ACCOUNTING_LENGTH_AACCOUNT",
123
+                "chaine",
124
+                "",
125
+                "", 0, 'current', 0
126
+        );
127
+        $this->const[9] = array(
128
+                "ACCOUNTING_LIST_SORT_VENTILATION_TODO",
129
+                "yesno",
130
+                "1",
131
+                "", 0, 'current', 0
132
+        );
133
+        $this->const[10] = array(
134
+                "ACCOUNTING_LIST_SORT_VENTILATION_DONE",
135
+                "yesno",
136
+                "1",
137
+                "", 0, 'current', 0
138
+        );
139
+        $this->const[11] = array (
140
+                "ACCOUNTING_EXPORT_DATE",
141
+                "chaine",
142
+                "%d%m%Y",
143
+                "", 0, 'current', 0
144
+        );
145
+        $this->const[12] = array(
146
+                "ACCOUNTING_EXPORT_SEPARATORCSV",
147
+                "string",
148
+                ",",
149
+                "", 0, 'current', 0
150
+        );
151
+        $this->const[13] = array(
152
+                "ACCOUNTING_EXPORT_FORMAT",
153
+                "chaine",
154
+                "csv",
155
+                "", 0, 'current', 0
156
+        );
157 157
 
158
-		// Tabs
159
-		$this->tabs = array();
158
+        // Tabs
159
+        $this->tabs = array();
160 160
 
161
-		// Css
162
-		$this->module_parts = array();
161
+        // Css
162
+        $this->module_parts = array();
163 163
 
164
-		// Boxes
165
-		$this->boxes = array();
164
+        // Boxes
165
+        $this->boxes = array();
166 166
 
167
-		// Permissions
168
-		$this->rights_class = 'accounting';
167
+        // Permissions
168
+        $this->rights_class = 'accounting';
169 169
 
170
-		$this->rights = array(); // Permission array used by this module
171
-		$r = 0;
170
+        $this->rights = array(); // Permission array used by this module
171
+        $r = 0;
172 172
 
173
-		$this->rights[$r][0] = 50440;
174
-		$this->rights[$r][1] = 'Manage chart of accounts, setup of accountancy';
175
-		$this->rights[$r][2] = 'r';
176
-		$this->rights[$r][3] = 0;
177
-		$this->rights[$r][4] = 'chartofaccount';
178
-		$this->rights[$r][5] = '';
179
-		$r++;
173
+        $this->rights[$r][0] = 50440;
174
+        $this->rights[$r][1] = 'Manage chart of accounts, setup of accountancy';
175
+        $this->rights[$r][2] = 'r';
176
+        $this->rights[$r][3] = 0;
177
+        $this->rights[$r][4] = 'chartofaccount';
178
+        $this->rights[$r][5] = '';
179
+        $r++;
180 180
 
181
-		$this->rights[$r][0] = 50401;
182
-		$this->rights[$r][1] = 'Bind products and invoices with accounting accounts';
183
-		$this->rights[$r][2] = 'r';
184
-		$this->rights[$r][3] = 0;
185
-		$this->rights[$r][4] = 'bind';
186
-		$this->rights[$r][5] = 'write';
187
-		$r++;
181
+        $this->rights[$r][0] = 50401;
182
+        $this->rights[$r][1] = 'Bind products and invoices with accounting accounts';
183
+        $this->rights[$r][2] = 'r';
184
+        $this->rights[$r][3] = 0;
185
+        $this->rights[$r][4] = 'bind';
186
+        $this->rights[$r][5] = 'write';
187
+        $r++;
188 188
 
189
-		/*
189
+        /*
190 190
 		$this->rights[$r][0] = 50402;
191 191
 		$this->rights[$r][1] = 'Make binding with products and invoices';
192 192
 		$this->rights[$r][2] = 'r';
@@ -196,96 +196,96 @@  discard block
 block discarded – undo
196 196
 		$r++;
197 197
         */
198 198
 
199
-		$this->rights[$r][0] = 50411;
200
-		$this->rights[$r][1] = 'Read operations in Ledger';
201
-		$this->rights[$r][2] = 'r';
202
-		$this->rights[$r][3] = 0;
203
-		$this->rights[$r][4] = 'mouvements';
204
-		$this->rights[$r][5] = 'lire';
205
-		$r++;
199
+        $this->rights[$r][0] = 50411;
200
+        $this->rights[$r][1] = 'Read operations in Ledger';
201
+        $this->rights[$r][2] = 'r';
202
+        $this->rights[$r][3] = 0;
203
+        $this->rights[$r][4] = 'mouvements';
204
+        $this->rights[$r][5] = 'lire';
205
+        $r++;
206 206
 
207
-		$this->rights[$r][0] = 50412;
208
-		$this->rights[$r][1] = 'Write/Edit operations in Ledger';
209
-		$this->rights[$r][2] = 'w';
210
-		$this->rights[$r][3] = 0;
211
-		$this->rights[$r][4] = 'mouvements';
212
-		$this->rights[$r][5] = 'creer';
213
-		$r++;
207
+        $this->rights[$r][0] = 50412;
208
+        $this->rights[$r][1] = 'Write/Edit operations in Ledger';
209
+        $this->rights[$r][2] = 'w';
210
+        $this->rights[$r][3] = 0;
211
+        $this->rights[$r][4] = 'mouvements';
212
+        $this->rights[$r][5] = 'creer';
213
+        $r++;
214 214
 
215
-		$this->rights[$r][0] = 50420;
216
-		$this->rights[$r][1] = 'Report and export reports (turnover, balance, journals, ledger)';
217
-		$this->rights[$r][2] = 'r';
218
-		$this->rights[$r][3] = 0;
219
-		$this->rights[$r][4] = 'comptarapport';
220
-		$this->rights[$r][5] = 'lire';
221
-		$r++;
215
+        $this->rights[$r][0] = 50420;
216
+        $this->rights[$r][1] = 'Report and export reports (turnover, balance, journals, ledger)';
217
+        $this->rights[$r][2] = 'r';
218
+        $this->rights[$r][3] = 0;
219
+        $this->rights[$r][4] = 'comptarapport';
220
+        $this->rights[$r][5] = 'lire';
221
+        $r++;
222 222
 
223
-		$this->rights[$r][0] = 50430;
224
-		$this->rights[$r][1] = 'Define and close a fiscal year';
225
-		$this->rights[$r][2] = 'r';
226
-		$this->rights[$r][3] = 0;
227
-		$this->rights[$r][4] = 'fiscalyear';
228
-		$this->rights[$r][5] = '';
229
-		$r++;
223
+        $this->rights[$r][0] = 50430;
224
+        $this->rights[$r][1] = 'Define and close a fiscal year';
225
+        $this->rights[$r][2] = 'r';
226
+        $this->rights[$r][3] = 0;
227
+        $this->rights[$r][4] = 'fiscalyear';
228
+        $this->rights[$r][5] = '';
229
+        $r++;
230 230
 
231 231
 
232
-		// Menus
233
-		//-------
234
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
232
+        // Menus
233
+        //-------
234
+        $this->menu = 1;        // This module add menu entries. They are coded into menu manager.
235 235
 
236
-		// Exports
237
-		//--------
238
-		$r=0;
236
+        // Exports
237
+        //--------
238
+        $r=0;
239 239
 
240
-		$r++;
241
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
242
-		$this->export_label[$r]='Chartofaccounts';
243
-		$this->export_icon[$r]='Accounting';
244
-		$this->export_permission[$r]=array(array("accounting","chartofaccount"));
245
-		$this->export_fields_array[$r]=array('ac.rowid'=>'ChartofaccountsId','ac.pcg_version'=>'Chartofaccounts','aa.rowid'=>'Id','aa.account_number'=>"AccountAccounting",'aa.label'=>"Label",'aa.account_parent'=>"Accountparent",'aa.pcg_type'=>"Pcgtype",'aa.pcg_subtype'=>'Pcgsubtype','aa.active'=>'Status');
246
-		$this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status');
247
-		$this->export_entities_array[$r]=array('ac.rowid'=>"Accounting",'ac.pcg_version'=>"Accounting",'aa.rowid'=>'Accounting','aa.account_number'=>"Accounting",'aa.label'=>"Accounting",'aa.accountparent'=>"Accounting",'aa.pcg_type'=>"Accounting",'aa.pcgsubtype'=>"Accounting",'aa_active'=>"Accounting");
240
+        $r++;
241
+        $this->export_code[$r]=$this->rights_class.'_'.$r;
242
+        $this->export_label[$r]='Chartofaccounts';
243
+        $this->export_icon[$r]='Accounting';
244
+        $this->export_permission[$r]=array(array("accounting","chartofaccount"));
245
+        $this->export_fields_array[$r]=array('ac.rowid'=>'ChartofaccountsId','ac.pcg_version'=>'Chartofaccounts','aa.rowid'=>'Id','aa.account_number'=>"AccountAccounting",'aa.label'=>"Label",'aa.account_parent'=>"Accountparent",'aa.pcg_type'=>"Pcgtype",'aa.pcg_subtype'=>'Pcgsubtype','aa.active'=>'Status');
246
+        $this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status');
247
+        $this->export_entities_array[$r]=array('ac.rowid'=>"Accounting",'ac.pcg_version'=>"Accounting",'aa.rowid'=>'Accounting','aa.account_number'=>"Accounting",'aa.label'=>"Accounting",'aa.accountparent'=>"Accounting",'aa.pcg_type'=>"Accounting",'aa.pcgsubtype'=>"Accounting",'aa_active'=>"Accounting");
248 248
 
249
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
250
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
251
-		$this->export_sql_end[$r] .=' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
249
+        $this->export_sql_start[$r]='SELECT DISTINCT ';
250
+        $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
251
+        $this->export_sql_end[$r] .=' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
252 252
 
253 253
 
254
-		// Imports
255
-		//--------
256
-		$r=0;
254
+        // Imports
255
+        //--------
256
+        $r=0;
257 257
 
258
-		// General ledger
259
-		$r++;
260
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
261
-		$this->import_label[$r]='ImportAccountingEntries';
262
-		$this->import_icon[$r]=$this->picto;
263
-		$this->import_entities_array[$r]=array();	// We define here only fields that use another icon that the one defined into import_icon
264
-		$this->import_tables_array[$r]=array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping');	// List of tables to insert into (insert done in same order)
265
-		$this->import_fields_array[$r]=array('b.doc_date'=>"Docdate",'b.code_journal'=>'Codejournal','b.numero_compte'=>'AccountAccountingShort','b.label_operation'=>'LabelOperation','b.debit'=>"Debit",'b.credit'=>"Credit",'b.date_creation'=>"DateCreation");
266
-		$this->import_fieldshidden_array[$r]=array('b.fk_user'=>'user->id');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
267
-		$this->import_convertvalue_array[$r]=array(
268
-				't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
269
-				't.ref'=>array('rule'=>'getrefifauto')
270
-		);
271
-		//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
272
-		$this->import_regex_array[$r]=array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
273
-		//$this->import_examplevalues_array[$r]=array('t.fk_projet'=>'MyProjectRef','t.ref'=>"auto or TK2010-1234",'t.label'=>"My task",'t.progress'=>"0 (not started) to 100 (finished)",'t.datec'=>'1972-10-10','t.note_private'=>"My private note",'t.note_public'=>"My public note");
258
+        // General ledger
259
+        $r++;
260
+        $this->import_code[$r]=$this->rights_class.'_'.$r;
261
+        $this->import_label[$r]='ImportAccountingEntries';
262
+        $this->import_icon[$r]=$this->picto;
263
+        $this->import_entities_array[$r]=array();	// We define here only fields that use another icon that the one defined into import_icon
264
+        $this->import_tables_array[$r]=array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping');	// List of tables to insert into (insert done in same order)
265
+        $this->import_fields_array[$r]=array('b.doc_date'=>"Docdate",'b.code_journal'=>'Codejournal','b.numero_compte'=>'AccountAccountingShort','b.label_operation'=>'LabelOperation','b.debit'=>"Debit",'b.credit'=>"Credit",'b.date_creation'=>"DateCreation");
266
+        $this->import_fieldshidden_array[$r]=array('b.fk_user'=>'user->id');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
267
+        $this->import_convertvalue_array[$r]=array(
268
+                't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
269
+                't.ref'=>array('rule'=>'getrefifauto')
270
+        );
271
+        //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
272
+        $this->import_regex_array[$r]=array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
273
+        //$this->import_examplevalues_array[$r]=array('t.fk_projet'=>'MyProjectRef','t.ref'=>"auto or TK2010-1234",'t.label'=>"My task",'t.progress'=>"0 (not started) to 100 (finished)",'t.datec'=>'1972-10-10','t.note_private'=>"My private note",'t.note_public'=>"My public note");
274 274
 
275
-		// Chart of accounts
276
-		$r++;
277
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
278
-		$this->import_label[$r]="Chartofaccounts"; // Translation key
279
-		$this->import_icon[$r]=$this->picto;
280
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
281
-		$this->import_tables_array[$r]=array('aa'=>MAIN_DB_PREFIX.'accounting_account');
282
-		$this->import_tables_creator_array[$r]=array('aa'=>'fk_user_author');    // Fields to store import user id
283
-		$this->import_fields_array[$r]=array('aa.fk_pcg_version'=>"Chartofaccounts*",'aa.account_number'=>"AccountAccounting*",'aa.label'=>"Label*",'aa.account_parent'=>"Accountparent","aa.fk_accounting_category"=>"AccountingCategory","aa.pcg_type"=>"Pcgtype*",'aa.pcg_subtype'=>'Pcgsubtype*','aa.active'=>'Status*','aa.datec'=>"DateCreation");
284
-		$this->import_regex_array[$r]=array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system','aa.account_number'=>'^\d{1,32}$','aa.label'=>'^.{1,255}$','aa.account_parent'=>'^\d{0,32}$','aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category','aa.pcg_type'=>'^.{1,20}$','aa.pcg_subtype'=>'^.{1,20}$','aa.active'=>'^0|1$','aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
285
-		$this->import_convertvalue_array[$r]=array(
286
-			'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/accountancy/class/accountancycategory.class.php','class'=>'AccountancyCategory','method'=>'fetch','dict'=>'DictionaryAccountancyCategory'),
287
-			'aa.account_parent'=>array('rule'=>'zeroifnull'),
288
-		);
289
-		$this->import_examplevalues_array[$r]=array('aa.fk_pcg_version'=>"PCG99-ABREGE",'aa.account_number'=>"707",'aa.label'=>"Product sales",'aa.account_parent'=>"1407","aa.fk_accounting_category"=>"","aa.pcg_type"=>"PROD",'aa.pcg_subtype'=>'PRODUCT','aa.active'=>'1','aa.datec'=>"2017-04-28");
290
-	}
275
+        // Chart of accounts
276
+        $r++;
277
+        $this->import_code[$r]=$this->rights_class.'_'.$r;
278
+        $this->import_label[$r]="Chartofaccounts"; // Translation key
279
+        $this->import_icon[$r]=$this->picto;
280
+        $this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
281
+        $this->import_tables_array[$r]=array('aa'=>MAIN_DB_PREFIX.'accounting_account');
282
+        $this->import_tables_creator_array[$r]=array('aa'=>'fk_user_author');    // Fields to store import user id
283
+        $this->import_fields_array[$r]=array('aa.fk_pcg_version'=>"Chartofaccounts*",'aa.account_number'=>"AccountAccounting*",'aa.label'=>"Label*",'aa.account_parent'=>"Accountparent","aa.fk_accounting_category"=>"AccountingCategory","aa.pcg_type"=>"Pcgtype*",'aa.pcg_subtype'=>'Pcgsubtype*','aa.active'=>'Status*','aa.datec'=>"DateCreation");
284
+        $this->import_regex_array[$r]=array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system','aa.account_number'=>'^\d{1,32}$','aa.label'=>'^.{1,255}$','aa.account_parent'=>'^\d{0,32}$','aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category','aa.pcg_type'=>'^.{1,20}$','aa.pcg_subtype'=>'^.{1,20}$','aa.active'=>'^0|1$','aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
285
+        $this->import_convertvalue_array[$r]=array(
286
+            'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/accountancy/class/accountancycategory.class.php','class'=>'AccountancyCategory','method'=>'fetch','dict'=>'DictionaryAccountancyCategory'),
287
+            'aa.account_parent'=>array('rule'=>'zeroifnull'),
288
+        );
289
+        $this->import_examplevalues_array[$r]=array('aa.fk_pcg_version'=>"PCG99-ABREGE",'aa.account_number'=>"707",'aa.label'=>"Product sales",'aa.account_parent'=>"1407","aa.fk_accounting_category"=>"","aa.pcg_type"=>"PROD",'aa.pcg_subtype'=>'PRODUCT','aa.active'=>'1','aa.datec'=>"2017-04-28");
290
+    }
291 291
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * \ingroup		Advanced accountancy
26 26
  * \brief		Module to activate Accounting Expert module
27 27
  */
28
-include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
28
+include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 29
 
30 30
 /**
31 31
  * Description and activation class for module accounting expert
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
54 54
 		$this->version = 'dolibarr';
55 55
 
56
-		$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
56
+		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
57 57
 		$this->picto = 'accounting';
58 58
 
59 59
 		// Data directories to create when module is enabled
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 		$this->config_page_url = array();
64 64
 
65 65
 		// Dependencies
66
-		$this->depends = array("modFacture","modBanque","modTax"); // List of modules id that must be enabled if this module is enabled
66
+		$this->depends = array("modFacture", "modBanque", "modTax"); // List of modules id that must be enabled if this module is enabled
67 67
 		$this->requiredby = array(); // List of modules id to disable if this one is disabled
68 68
 		$this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module
69 69
 		$this->phpmin = array(5, 4); // Minimum version of PHP required by module
70 70
 		$this->need_dolibarr_version = array(3, 9); // Minimum version of Dolibarr required by module
71
-		$this->langfiles = array("accountancy","compta");
71
+		$this->langfiles = array("accountancy", "compta");
72 72
 
73 73
 		// Constants
74 74
 		// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 				"1",
137 137
 				"", 0, 'current', 0
138 138
 		);
139
-		$this->const[11] = array (
139
+		$this->const[11] = array(
140 140
 				"ACCOUNTING_EXPORT_DATE",
141 141
 				"chaine",
142 142
 				"%d%m%Y",
@@ -231,61 +231,61 @@  discard block
 block discarded – undo
231 231
 
232 232
 		// Menus
233 233
 		//-------
234
-		$this->menu = 1;        // This module add menu entries. They are coded into menu manager.
234
+		$this->menu = 1; // This module add menu entries. They are coded into menu manager.
235 235
 
236 236
 		// Exports
237 237
 		//--------
238
-		$r=0;
238
+		$r = 0;
239 239
 
240 240
 		$r++;
241
-		$this->export_code[$r]=$this->rights_class.'_'.$r;
242
-		$this->export_label[$r]='Chartofaccounts';
243
-		$this->export_icon[$r]='Accounting';
244
-		$this->export_permission[$r]=array(array("accounting","chartofaccount"));
245
-		$this->export_fields_array[$r]=array('ac.rowid'=>'ChartofaccountsId','ac.pcg_version'=>'Chartofaccounts','aa.rowid'=>'Id','aa.account_number'=>"AccountAccounting",'aa.label'=>"Label",'aa.account_parent'=>"Accountparent",'aa.pcg_type'=>"Pcgtype",'aa.pcg_subtype'=>'Pcgsubtype','aa.active'=>'Status');
246
-		$this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status');
247
-		$this->export_entities_array[$r]=array('ac.rowid'=>"Accounting",'ac.pcg_version'=>"Accounting",'aa.rowid'=>'Accounting','aa.account_number'=>"Accounting",'aa.label'=>"Accounting",'aa.accountparent'=>"Accounting",'aa.pcg_type'=>"Accounting",'aa.pcgsubtype'=>"Accounting",'aa_active'=>"Accounting");
241
+		$this->export_code[$r] = $this->rights_class.'_'.$r;
242
+		$this->export_label[$r] = 'Chartofaccounts';
243
+		$this->export_icon[$r] = 'Accounting';
244
+		$this->export_permission[$r] = array(array("accounting", "chartofaccount"));
245
+		$this->export_fields_array[$r] = array('ac.rowid'=>'ChartofaccountsId', 'ac.pcg_version'=>'Chartofaccounts', 'aa.rowid'=>'Id', 'aa.account_number'=>"AccountAccounting", 'aa.label'=>"Label", 'aa.account_parent'=>"Accountparent", 'aa.pcg_type'=>"Pcgtype", 'aa.pcg_subtype'=>'Pcgsubtype', 'aa.active'=>'Status');
246
+		$this->export_TypeFields_array[$r] = array('ac.rowid'=>'List:accounting_system:pcg_version', 'aa.account_number'=>"Text", 'aa.label'=>"Text", 'aa.pcg_type'=>'Text', 'aa.pcg_subtype'=>'Text', 'aa.active'=>'Status');
247
+		$this->export_entities_array[$r] = array('ac.rowid'=>"Accounting", 'ac.pcg_version'=>"Accounting", 'aa.rowid'=>'Accounting', 'aa.account_number'=>"Accounting", 'aa.label'=>"Accounting", 'aa.accountparent'=>"Accounting", 'aa.pcg_type'=>"Accounting", 'aa.pcgsubtype'=>"Accounting", 'aa_active'=>"Accounting");
248 248
 
249
-		$this->export_sql_start[$r]='SELECT DISTINCT ';
250
-		$this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
251
-		$this->export_sql_end[$r] .=' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
249
+		$this->export_sql_start[$r] = 'SELECT DISTINCT ';
250
+		$this->export_sql_end[$r]  = ' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac';
251
+		$this->export_sql_end[$r] .= ' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').') ';
252 252
 
253 253
 
254 254
 		// Imports
255 255
 		//--------
256
-		$r=0;
256
+		$r = 0;
257 257
 
258 258
 		// General ledger
259 259
 		$r++;
260
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
261
-		$this->import_label[$r]='ImportAccountingEntries';
262
-		$this->import_icon[$r]=$this->picto;
263
-		$this->import_entities_array[$r]=array();	// We define here only fields that use another icon that the one defined into import_icon
264
-		$this->import_tables_array[$r]=array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping');	// List of tables to insert into (insert done in same order)
265
-		$this->import_fields_array[$r]=array('b.doc_date'=>"Docdate",'b.code_journal'=>'Codejournal','b.numero_compte'=>'AccountAccountingShort','b.label_operation'=>'LabelOperation','b.debit'=>"Debit",'b.credit'=>"Credit",'b.date_creation'=>"DateCreation");
266
-		$this->import_fieldshidden_array[$r]=array('b.fk_user'=>'user->id');    // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
267
-		$this->import_convertvalue_array[$r]=array(
268
-				't.fk_projet'=>array('rule'=>'fetchidfromref','classfile'=>'/projet/class/project.class.php','class'=>'Project','method'=>'fetch','element'=>'Project'),
260
+		$this->import_code[$r] = $this->rights_class.'_'.$r;
261
+		$this->import_label[$r] = 'ImportAccountingEntries';
262
+		$this->import_icon[$r] = $this->picto;
263
+		$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
264
+		$this->import_tables_array[$r] = array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping'); // List of tables to insert into (insert done in same order)
265
+		$this->import_fields_array[$r] = array('b.doc_date'=>"Docdate", 'b.code_journal'=>'Codejournal', 'b.numero_compte'=>'AccountAccountingShort', 'b.label_operation'=>'LabelOperation', 'b.debit'=>"Debit", 'b.credit'=>"Credit", 'b.date_creation'=>"DateCreation");
266
+		$this->import_fieldshidden_array[$r] = array('b.fk_user'=>'user->id'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
267
+		$this->import_convertvalue_array[$r] = array(
268
+				't.fk_projet'=>array('rule'=>'fetchidfromref', 'classfile'=>'/projet/class/project.class.php', 'class'=>'Project', 'method'=>'fetch', 'element'=>'Project'),
269 269
 				't.ref'=>array('rule'=>'getrefifauto')
270 270
 		);
271 271
 		//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
272
-		$this->import_regex_array[$r]=array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
272
+		$this->import_regex_array[$r] = array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
273 273
 		//$this->import_examplevalues_array[$r]=array('t.fk_projet'=>'MyProjectRef','t.ref'=>"auto or TK2010-1234",'t.label'=>"My task",'t.progress'=>"0 (not started) to 100 (finished)",'t.datec'=>'1972-10-10','t.note_private'=>"My private note",'t.note_public'=>"My public note");
274 274
 
275 275
 		// Chart of accounts
276 276
 		$r++;
277
-		$this->import_code[$r]=$this->rights_class.'_'.$r;
278
-		$this->import_label[$r]="Chartofaccounts"; // Translation key
279
-		$this->import_icon[$r]=$this->picto;
280
-		$this->import_entities_array[$r]=array();		// We define here only fields that use another icon that the one defined into import_icon
281
-		$this->import_tables_array[$r]=array('aa'=>MAIN_DB_PREFIX.'accounting_account');
282
-		$this->import_tables_creator_array[$r]=array('aa'=>'fk_user_author');    // Fields to store import user id
283
-		$this->import_fields_array[$r]=array('aa.fk_pcg_version'=>"Chartofaccounts*",'aa.account_number'=>"AccountAccounting*",'aa.label'=>"Label*",'aa.account_parent'=>"Accountparent","aa.fk_accounting_category"=>"AccountingCategory","aa.pcg_type"=>"Pcgtype*",'aa.pcg_subtype'=>'Pcgsubtype*','aa.active'=>'Status*','aa.datec'=>"DateCreation");
284
-		$this->import_regex_array[$r]=array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system','aa.account_number'=>'^\d{1,32}$','aa.label'=>'^.{1,255}$','aa.account_parent'=>'^\d{0,32}$','aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category','aa.pcg_type'=>'^.{1,20}$','aa.pcg_subtype'=>'^.{1,20}$','aa.active'=>'^0|1$','aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
285
-		$this->import_convertvalue_array[$r]=array(
286
-			'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/accountancy/class/accountancycategory.class.php','class'=>'AccountancyCategory','method'=>'fetch','dict'=>'DictionaryAccountancyCategory'),
277
+		$this->import_code[$r] = $this->rights_class.'_'.$r;
278
+		$this->import_label[$r] = "Chartofaccounts"; // Translation key
279
+		$this->import_icon[$r] = $this->picto;
280
+		$this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
281
+		$this->import_tables_array[$r] = array('aa'=>MAIN_DB_PREFIX.'accounting_account');
282
+		$this->import_tables_creator_array[$r] = array('aa'=>'fk_user_author'); // Fields to store import user id
283
+		$this->import_fields_array[$r] = array('aa.fk_pcg_version'=>"Chartofaccounts*", 'aa.account_number'=>"AccountAccounting*", 'aa.label'=>"Label*", 'aa.account_parent'=>"Accountparent", "aa.fk_accounting_category"=>"AccountingCategory", "aa.pcg_type"=>"Pcgtype*", 'aa.pcg_subtype'=>'Pcgsubtype*', 'aa.active'=>'Status*', 'aa.datec'=>"DateCreation");
284
+		$this->import_regex_array[$r] = array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system', 'aa.account_number'=>'^\d{1,32}$', 'aa.label'=>'^.{1,255}$', 'aa.account_parent'=>'^\d{0,32}$', 'aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category', 'aa.pcg_type'=>'^.{1,20}$', 'aa.pcg_subtype'=>'^.{1,20}$', 'aa.active'=>'^0|1$', 'aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
285
+		$this->import_convertvalue_array[$r] = array(
286
+			'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel', 'classfile'=>'/accountancy/class/accountancycategory.class.php', 'class'=>'AccountancyCategory', 'method'=>'fetch', 'dict'=>'DictionaryAccountancyCategory'),
287 287
 			'aa.account_parent'=>array('rule'=>'zeroifnull'),
288 288
 		);
289
-		$this->import_examplevalues_array[$r]=array('aa.fk_pcg_version'=>"PCG99-ABREGE",'aa.account_number'=>"707",'aa.label'=>"Product sales",'aa.account_parent'=>"1407","aa.fk_accounting_category"=>"","aa.pcg_type"=>"PROD",'aa.pcg_subtype'=>'PRODUCT','aa.active'=>'1','aa.datec'=>"2017-04-28");
289
+		$this->import_examplevalues_array[$r] = array('aa.fk_pcg_version'=>"PCG99-ABREGE", 'aa.account_number'=>"707", 'aa.label'=>"Product sales", 'aa.account_parent'=>"1407", "aa.fk_accounting_category"=>"", "aa.pcg_type"=>"PROD", 'aa.pcg_subtype'=>'PRODUCT', 'aa.active'=>'1', 'aa.datec'=>"2017-04-28");
290 290
 	}
291 291
 }
Please login to merge, or discard this patch.