@@ -23,7 +23,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
165 | 165 | |
166 | 166 | $sql = array(); |
167 | 167 | |
168 | - return $this->_init($sql,$options); |
|
168 | + return $this->_init($sql, $options); |
|
169 | 169 | } |
170 | 170 | } |
@@ -25,7 +25,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -28,7 +28,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -25,7 +25,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -40,7 +40,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -25,7 +25,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
802 | 802 | */ |
803 | 803 | function cleansep($value) |
804 | 804 | { |
805 | - return str_replace(array(',',';'),'/',$value); |
|
805 | + return str_replace(array(',', ';'), '/', $value); |
|
806 | 806 | }; |
@@ -24,7 +24,7 @@ discard block |
||
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 |
||
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(); |
@@ -25,7 +25,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -67,37 +67,37 @@ discard block |
||
67 | 67 | global $conf, $langs, $mysoc; |
68 | 68 | |
69 | 69 | // Load translation files required by the page |
70 | - $langs->loadLangs(array("main","companies")); |
|
70 | + $langs->loadLangs(array("main", "companies")); |
|
71 | 71 | |
72 | 72 | $this->db = $db; |
73 | 73 | $this->name = "ODT templates"; |
74 | 74 | $this->description = $langs->trans("DocumentModelOdt"); |
75 | - $this->scandir = 'PROPALE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
75 | + $this->scandir = 'PROPALE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
76 | 76 | |
77 | 77 | // Dimension page pour format A4 |
78 | 78 | $this->type = 'odt'; |
79 | 79 | $this->page_largeur = 0; |
80 | 80 | $this->page_hauteur = 0; |
81 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
82 | - $this->marge_gauche=0; |
|
83 | - $this->marge_droite=0; |
|
84 | - $this->marge_haute=0; |
|
85 | - $this->marge_basse=0; |
|
86 | - |
|
87 | - $this->option_logo = 1; // Affiche logo |
|
88 | - $this->option_tva = 0; // Gere option tva PROPALE_TVAOPTION |
|
89 | - $this->option_modereg = 0; // Affiche mode reglement |
|
90 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
91 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
92 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
93 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
94 | - $this->option_credit_note = 0; // Support credit notes |
|
95 | - $this->option_freetext = 1; // Support add of a personalised text |
|
96 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
81 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
82 | + $this->marge_gauche = 0; |
|
83 | + $this->marge_droite = 0; |
|
84 | + $this->marge_haute = 0; |
|
85 | + $this->marge_basse = 0; |
|
86 | + |
|
87 | + $this->option_logo = 1; // Affiche logo |
|
88 | + $this->option_tva = 0; // Gere option tva PROPALE_TVAOPTION |
|
89 | + $this->option_modereg = 0; // Affiche mode reglement |
|
90 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
91 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
92 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
93 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
94 | + $this->option_credit_note = 0; // Support credit notes |
|
95 | + $this->option_freetext = 1; // Support add of a personalised text |
|
96 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
97 | 97 | |
98 | 98 | // Recupere emetteur |
99 | - $this->emetteur=$mysoc; |
|
100 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
99 | + $this->emetteur = $mysoc; |
|
100 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | |
@@ -109,114 +109,114 @@ discard block |
||
109 | 109 | */ |
110 | 110 | function info($langs) |
111 | 111 | { |
112 | - global $conf,$langs; |
|
112 | + global $conf, $langs; |
|
113 | 113 | |
114 | 114 | // Load translation files required by the page |
115 | - $langs->loadLangs(array("errors","companies")); |
|
115 | + $langs->loadLangs(array("errors", "companies")); |
|
116 | 116 | |
117 | 117 | $form = new Form($this->db); |
118 | 118 | |
119 | 119 | $texte = $this->description.".<br>\n"; |
120 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
121 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
122 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
123 | - $texte.= '<input type="hidden" name="param1" value="PROPALE_ADDON_PDF_ODT_PATH">'; |
|
120 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
121 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
122 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
123 | + $texte .= '<input type="hidden" name="param1" value="PROPALE_ADDON_PDF_ODT_PATH">'; |
|
124 | 124 | if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) |
125 | 125 | { |
126 | - $texte.= '<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">'; |
|
127 | - $texte.= '<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">'; |
|
128 | - $texte.= '<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">'; |
|
126 | + $texte .= '<input type="hidden" name="param2" value="PROPALE_ADDON_PDF_ODT_DEFAULT">'; |
|
127 | + $texte .= '<input type="hidden" name="param3" value="PROPALE_ADDON_PDF_ODT_TOBILL">'; |
|
128 | + $texte .= '<input type="hidden" name="param4" value="PROPALE_ADDON_PDF_ODT_CLOSED">'; |
|
129 | 129 | } |
130 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
130 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
131 | 131 | |
132 | 132 | // List of directories area |
133 | - $texte.= '<tr><td>'; |
|
134 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
135 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PROPALE_ADDON_PDF_ODT_PATH))); |
|
136 | - $listoffiles=array(); |
|
137 | - foreach($listofdir as $key=>$tmpdir) |
|
133 | + $texte .= '<tr><td>'; |
|
134 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
135 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->PROPALE_ADDON_PDF_ODT_PATH))); |
|
136 | + $listoffiles = array(); |
|
137 | + foreach ($listofdir as $key=>$tmpdir) |
|
138 | 138 | { |
139 | - $tmpdir=trim($tmpdir); |
|
140 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
141 | - if (! $tmpdir) { |
|
139 | + $tmpdir = trim($tmpdir); |
|
140 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
141 | + if (!$tmpdir) { |
|
142 | 142 | unset($listofdir[$key]); continue; |
143 | 143 | } |
144 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
144 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
145 | 145 | else |
146 | 146 | { |
147 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
148 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
147 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
148 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
149 | 149 | } |
150 | 150 | } |
151 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
151 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
152 | 152 | // Add list of substitution keys |
153 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
154 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
155 | - |
|
156 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
157 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
158 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
159 | - $texte.=$conf->global->PROPALE_ADDON_PDF_ODT_PATH; |
|
160 | - $texte.= '</textarea>'; |
|
161 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
162 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
163 | - $texte.= '<br></div></div>'; |
|
153 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
154 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
155 | + |
|
156 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
157 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
158 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
159 | + $texte .= $conf->global->PROPALE_ADDON_PDF_ODT_PATH; |
|
160 | + $texte .= '</textarea>'; |
|
161 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
162 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
163 | + $texte .= '<br></div></div>'; |
|
164 | 164 | |
165 | 165 | // Scan directories |
166 | - $nbofiles=count($listoffiles); |
|
167 | - if (! empty($conf->global->PROPALE_ADDON_PDF_ODT_PATH)) |
|
166 | + $nbofiles = count($listoffiles); |
|
167 | + if (!empty($conf->global->PROPALE_ADDON_PDF_ODT_PATH)) |
|
168 | 168 | { |
169 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
169 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'; |
|
170 | 170 | //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
171 | - $texte.=count($listoffiles); |
|
171 | + $texte .= count($listoffiles); |
|
172 | 172 | //$texte.=$nbofiles?'</a>':''; |
173 | - $texte.='</b>'; |
|
173 | + $texte .= '</b>'; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | if ($nbofiles) |
177 | 177 | { |
178 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
179 | - foreach($listoffiles as $file) |
|
178 | + $texte .= '<div id="div_'.get_class($this).'" class="hidden">'; |
|
179 | + foreach ($listoffiles as $file) |
|
180 | 180 | { |
181 | - $texte.=$file['name'].'<br>'; |
|
181 | + $texte .= $file['name'].'<br>'; |
|
182 | 182 | } |
183 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
183 | + $texte .= '<div id="div_'.get_class($this).'">'; |
|
184 | 184 | |
185 | 185 | if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0) |
186 | 186 | { |
187 | 187 | // Model for creation |
188 | - $liste=ModelePDFPropales::liste_modeles($this->db); |
|
189 | - $texte.= '<table width="50%;">'; |
|
190 | - $texte.= '<tr>'; |
|
191 | - $texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalCreate").'</td>'; |
|
192 | - $texte.= '<td colspan="">'; |
|
193 | - $texte.= $form->selectarray('value2',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT); |
|
194 | - $texte.= "</td></tr>"; |
|
195 | - |
|
196 | - $texte.= '<tr>'; |
|
197 | - $texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalToBill").'</td>'; |
|
198 | - $texte.= '<td colspan="">'; |
|
199 | - $texte.= $form->selectarray('value3',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL); |
|
200 | - $texte.= "</td></tr>"; |
|
201 | - $texte.= '<tr>'; |
|
202 | - |
|
203 | - $texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalClosed").'</td>'; |
|
204 | - $texte.= '<td colspan="">'; |
|
205 | - $texte.= $form->selectarray('value4',$liste,$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED); |
|
206 | - $texte.= "</td></tr>"; |
|
207 | - $texte.= '</table>'; |
|
188 | + $liste = ModelePDFPropales::liste_modeles($this->db); |
|
189 | + $texte .= '<table width="50%;">'; |
|
190 | + $texte .= '<tr>'; |
|
191 | + $texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalCreate").'</td>'; |
|
192 | + $texte .= '<td colspan="">'; |
|
193 | + $texte .= $form->selectarray('value2', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT); |
|
194 | + $texte .= "</td></tr>"; |
|
195 | + |
|
196 | + $texte .= '<tr>'; |
|
197 | + $texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalToBill").'</td>'; |
|
198 | + $texte .= '<td colspan="">'; |
|
199 | + $texte .= $form->selectarray('value3', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL); |
|
200 | + $texte .= "</td></tr>"; |
|
201 | + $texte .= '<tr>'; |
|
202 | + |
|
203 | + $texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalClosed").'</td>'; |
|
204 | + $texte .= '<td colspan="">'; |
|
205 | + $texte .= $form->selectarray('value4', $liste, $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED); |
|
206 | + $texte .= "</td></tr>"; |
|
207 | + $texte .= '</table>'; |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | - $texte.= '</td>'; |
|
211 | + $texte .= '</td>'; |
|
212 | 212 | |
213 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
214 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
215 | - $texte.= '</td>'; |
|
216 | - $texte.= '</tr>'; |
|
213 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
214 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
215 | + $texte .= '</td>'; |
|
216 | + $texte .= '</tr>'; |
|
217 | 217 | |
218 | - $texte.= '</table>'; |
|
219 | - $texte.= '</form>'; |
|
218 | + $texte .= '</table>'; |
|
219 | + $texte .= '</form>'; |
|
220 | 220 | |
221 | 221 | return $texte; |
222 | 222 | } |
@@ -233,10 +233,10 @@ discard block |
||
233 | 233 | * @param int $hideref Do not show ref |
234 | 234 | * @return int 1 if OK, <=0 if KO |
235 | 235 | */ |
236 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
236 | + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
237 | 237 | { |
238 | 238 | // phpcs:enable |
239 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
239 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
240 | 240 | |
241 | 241 | if (empty($srctemplatepath)) |
242 | 242 | { |
@@ -245,17 +245,17 @@ discard block |
||
245 | 245 | } |
246 | 246 | |
247 | 247 | // Add odtgeneration hook |
248 | - if (! is_object($hookmanager)) |
|
248 | + if (!is_object($hookmanager)) |
|
249 | 249 | { |
250 | 250 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
251 | - $hookmanager=new HookManager($this->db); |
|
251 | + $hookmanager = new HookManager($this->db); |
|
252 | 252 | } |
253 | 253 | $hookmanager->initHooks(array('odtgeneration')); |
254 | 254 | global $action; |
255 | 255 | |
256 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
257 | - $sav_charset_output=$outputlangs->charset_output; |
|
258 | - $outputlangs->charset_output='UTF-8'; |
|
256 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
257 | + $sav_charset_output = $outputlangs->charset_output; |
|
258 | + $outputlangs->charset_output = 'UTF-8'; |
|
259 | 259 | |
260 | 260 | // Load translation files required by the page |
261 | 261 | $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); |
@@ -263,28 +263,28 @@ discard block |
||
263 | 263 | if ($conf->propal->multidir_output[$conf->entity]) |
264 | 264 | { |
265 | 265 | // If $object is id instead of object |
266 | - if (! is_object($object)) |
|
266 | + if (!is_object($object)) |
|
267 | 267 | { |
268 | 268 | $id = $object; |
269 | 269 | $object = new Propal($this->db); |
270 | - $result=$object->fetch($id); |
|
270 | + $result = $object->fetch($id); |
|
271 | 271 | if ($result < 0) |
272 | 272 | { |
273 | - dol_print_error($this->db,$object->error); |
|
273 | + dol_print_error($this->db, $object->error); |
|
274 | 274 | return -1; |
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | 278 | $dir = $conf->propal->multidir_output[$object->entity]; |
279 | 279 | $objectref = dol_sanitizeFileName($object->ref); |
280 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
281 | - $file = $dir . "/" . $objectref . ".odt"; |
|
280 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
281 | + $file = $dir."/".$objectref.".odt"; |
|
282 | 282 | |
283 | - if (! file_exists($dir)) |
|
283 | + if (!file_exists($dir)) |
|
284 | 284 | { |
285 | 285 | if (dol_mkdir($dir) < 0) |
286 | 286 | { |
287 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
287 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
288 | 288 | return -1; |
289 | 289 | } |
290 | 290 | } |
@@ -292,26 +292,26 @@ discard block |
||
292 | 292 | if (file_exists($dir)) |
293 | 293 | { |
294 | 294 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
295 | - $newfile=basename($srctemplatepath); |
|
296 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
297 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
298 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
295 | + $newfile = basename($srctemplatepath); |
|
296 | + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); |
|
297 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
298 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
299 | 299 | |
300 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
300 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
301 | 301 | |
302 | 302 | // Get extension (ods or odt) |
303 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
304 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
303 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
304 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
305 | 305 | { |
306 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
307 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
308 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
306 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
307 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
308 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
309 | 309 | } |
310 | 310 | else |
311 | 311 | { |
312 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
312 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
313 | 313 | } |
314 | - $file=$dir.'/'.$filename; |
|
314 | + $file = $dir.'/'.$filename; |
|
315 | 315 | //print "newdir=".$dir; |
316 | 316 | //print "newfile=".$newfile; |
317 | 317 | //print "file=".$file; |
@@ -321,20 +321,20 @@ discard block |
||
321 | 321 | |
322 | 322 | |
323 | 323 | // If CUSTOMER contact defined on proposal, we use it |
324 | - $usecontact=false; |
|
325 | - $arrayidcontact=$object->getIdContact('external','CUSTOMER'); |
|
324 | + $usecontact = false; |
|
325 | + $arrayidcontact = $object->getIdContact('external', 'CUSTOMER'); |
|
326 | 326 | if (count($arrayidcontact) > 0) |
327 | 327 | { |
328 | - $usecontact=true; |
|
329 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
328 | + $usecontact = true; |
|
329 | + $result = $object->fetch_contact($arrayidcontact[0]); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // Recipient name |
333 | - $contactobject=null; |
|
334 | - if (! empty($usecontact)) |
|
333 | + $contactobject = null; |
|
334 | + if (!empty($usecontact)) |
|
335 | 335 | { |
336 | 336 | // On peut utiliser le nom de la societe du contact |
337 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
337 | + if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
338 | 338 | else { |
339 | 339 | $socobject = $object->thirdparty; |
340 | 340 | // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use |
@@ -343,10 +343,10 @@ discard block |
||
343 | 343 | } |
344 | 344 | else |
345 | 345 | { |
346 | - $socobject=$object->thirdparty; |
|
346 | + $socobject = $object->thirdparty; |
|
347 | 347 | } |
348 | 348 | // Make substitution |
349 | - $substitutionarray=array( |
|
349 | + $substitutionarray = array( |
|
350 | 350 | '__FROM_NAME__' => $this->emetteur->name, |
351 | 351 | '__FROM_EMAIL__' => $this->emetteur->email, |
352 | 352 | '__TOTAL_TTC__' => $object->total_ttc, |
@@ -355,15 +355,15 @@ discard block |
||
355 | 355 | ); |
356 | 356 | complete_substitutions_array($substitutionarray, $langs, $object); |
357 | 357 | // Call the ODTSubstitution hook |
358 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
359 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
358 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray); |
|
359 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
360 | 360 | |
361 | 361 | // Line of free text |
362 | - $newfreetext=''; |
|
363 | - $paramfreetext='PROPOSAL_FREE_TEXT'; |
|
364 | - if (! empty($conf->global->$paramfreetext)) |
|
362 | + $newfreetext = ''; |
|
363 | + $paramfreetext = 'PROPOSAL_FREE_TEXT'; |
|
364 | + if (!empty($conf->global->$paramfreetext)) |
|
365 | 365 | { |
366 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
366 | + $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | // Open and load template |
@@ -373,15 +373,15 @@ discard block |
||
373 | 373 | $srctemplatepath, |
374 | 374 | array( |
375 | 375 | 'PATH_TO_TMP' => $conf->propal->multidir_temp[$object->entity], |
376 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
376 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
377 | 377 | 'DELIMITER_LEFT' => '{', |
378 | 378 | 'DELIMITER_RIGHT' => '}' |
379 | 379 | ) |
380 | 380 | ); |
381 | 381 | } |
382 | - catch(Exception $e) |
|
382 | + catch (Exception $e) |
|
383 | 383 | { |
384 | - $this->error=$e->getMessage(); |
|
384 | + $this->error = $e->getMessage(); |
|
385 | 385 | dol_syslog($e->getMessage(), LOG_INFO); |
386 | 386 | return -1; |
387 | 387 | } |
@@ -404,27 +404,27 @@ discard block |
||
404 | 404 | |
405 | 405 | // Define substitution array |
406 | 406 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
407 | - $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
408 | - $array_objet=$this->get_substitutionarray_object($object,$outputlangs); |
|
409 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
410 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
411 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
412 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
407 | + $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
408 | + $array_objet = $this->get_substitutionarray_object($object, $outputlangs); |
|
409 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
410 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
411 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
412 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
413 | 413 | // retrieve contact information for use in object as contact_xxx tags |
414 | 414 | $array_thirdparty_contact = array(); |
415 | - if ($usecontact && is_object($contactobject)) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
415 | + if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); |
|
416 | 416 | |
417 | - $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact); |
|
417 | + $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact); |
|
418 | 418 | complete_substitutions_array($tmparray, $outputlangs, $object); |
419 | 419 | |
420 | 420 | // Call the ODTSubstitution hook |
421 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
422 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
421 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
422 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
423 | 423 | |
424 | - foreach($tmparray as $key=>$value) |
|
424 | + foreach ($tmparray as $key=>$value) |
|
425 | 425 | { |
426 | 426 | try { |
427 | - if (preg_match('/logo$/',$key)) // Image |
|
427 | + if (preg_match('/logo$/', $key)) // Image |
|
428 | 428 | { |
429 | 429 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
430 | 430 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
435 | 435 | } |
436 | 436 | } |
437 | - catch(OdfException $e) |
|
437 | + catch (OdfException $e) |
|
438 | 438 | { |
439 | 439 | dol_syslog($e->getMessage(), LOG_INFO); |
440 | 440 | } |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | try { |
447 | 447 | $listlines = $odfHandler->setSegment('lines'); |
448 | 448 | } |
449 | - catch(OdfException $e) |
|
449 | + catch (OdfException $e) |
|
450 | 450 | { |
451 | 451 | // We may arrive here if tags for lines not present into template |
452 | 452 | $foundtagforlines = 0; |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | { |
457 | 457 | foreach ($object->lines as $line) |
458 | 458 | { |
459 | - $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); |
|
459 | + $tmparray = $this->get_substitutionarray_lines($line, $outputlangs); |
|
460 | 460 | complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); |
461 | 461 | // Call the ODTSubstitutionLine hook |
462 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); |
|
463 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
464 | - foreach($tmparray as $key => $val) |
|
462 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); |
|
463 | + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
464 | + foreach ($tmparray as $key => $val) |
|
465 | 465 | { |
466 | 466 | try |
467 | 467 | { |
468 | 468 | $listlines->setVars($key, $val, true, 'UTF-8'); |
469 | 469 | } |
470 | - catch(OdfException $e) |
|
470 | + catch (OdfException $e) |
|
471 | 471 | { |
472 | 472 | dol_syslog($e->getMessage(), LOG_INFO); |
473 | 473 | } |
474 | - catch(SegmentException $e) |
|
474 | + catch (SegmentException $e) |
|
475 | 475 | { |
476 | 476 | dol_syslog($e->getMessage(), LOG_INFO); |
477 | 477 | } |
@@ -481,16 +481,16 @@ discard block |
||
481 | 481 | $odfHandler->mergeSegment($listlines); |
482 | 482 | } |
483 | 483 | } |
484 | - catch(OdfException $e) |
|
484 | + catch (OdfException $e) |
|
485 | 485 | { |
486 | - $this->error=$e->getMessage(); |
|
486 | + $this->error = $e->getMessage(); |
|
487 | 487 | dol_syslog($this->error, LOG_WARNING); |
488 | 488 | return -1; |
489 | 489 | } |
490 | 490 | |
491 | 491 | // Replace labels translated |
492 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
493 | - foreach($tmparray as $key=>$value) |
|
492 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
493 | + foreach ($tmparray as $key=>$value) |
|
494 | 494 | { |
495 | 495 | try { |
496 | 496 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
@@ -502,15 +502,15 @@ discard block |
||
502 | 502 | } |
503 | 503 | |
504 | 504 | // Call the beforeODTSave hook |
505 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
506 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
505 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
506 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
507 | 507 | |
508 | 508 | // Write new file |
509 | 509 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
510 | 510 | try { |
511 | 511 | $odfHandler->exportAsAttachedPDF($file); |
512 | 512 | } catch (Exception $e) { |
513 | - $this->error=$e->getMessage(); |
|
513 | + $this->error = $e->getMessage(); |
|
514 | 514 | dol_syslog($e->getMessage(), LOG_INFO); |
515 | 515 | return -1; |
516 | 516 | } |
@@ -519,26 +519,26 @@ discard block |
||
519 | 519 | try { |
520 | 520 | $odfHandler->saveToDisk($file); |
521 | 521 | } catch (Exception $e) { |
522 | - $this->error=$e->getMessage(); |
|
522 | + $this->error = $e->getMessage(); |
|
523 | 523 | dol_syslog($e->getMessage(), LOG_INFO); |
524 | 524 | return -1; |
525 | 525 | } |
526 | 526 | } |
527 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
528 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
527 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
528 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
529 | 529 | |
530 | - if (! empty($conf->global->MAIN_UMASK)) |
|
530 | + if (!empty($conf->global->MAIN_UMASK)) |
|
531 | 531 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
532 | 532 | |
533 | - $odfHandler=null; // Destroy object |
|
533 | + $odfHandler = null; // Destroy object |
|
534 | 534 | |
535 | 535 | $this->result = array('fullpath'=>$file); |
536 | 536 | |
537 | - return 1; // Success |
|
537 | + return 1; // Success |
|
538 | 538 | } |
539 | 539 | else |
540 | 540 | { |
541 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
541 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
542 | 542 | return -1; |
543 | 543 | } |
544 | 544 | } |