@@ -29,273 +29,273 @@ |
||
29 | 29 | */ |
30 | 30 | abstract class DoliDB implements Database |
31 | 31 | { |
32 | - /** @var resource Database handler */ |
|
33 | - public $db; |
|
34 | - /** @var string Database type */ |
|
35 | - public $type; |
|
36 | - /** @var string Charset used to force charset when creating database */ |
|
37 | - public $forcecharset='utf8'; |
|
38 | - /** @var string Collate used to force collate when creating database */ |
|
39 | - public $forcecollate='utf8_unicode_ci'; |
|
40 | - /** @var resource Resultset of last query */ |
|
41 | - private $_results; |
|
42 | - /** @var bool true if connected, else false */ |
|
43 | - public $connected; |
|
44 | - /** @var bool true if database selected, else false */ |
|
45 | - public $database_selected; |
|
46 | - /** @var string Selected database name */ |
|
47 | - public $database_name; |
|
48 | - /** @var string Database username */ |
|
49 | - public $database_user; |
|
50 | - /** @var string Database host */ |
|
51 | - public $database_host; |
|
52 | - /** @var int Database port */ |
|
53 | - public $database_port; |
|
54 | - /** @var int >=1 if a transaction is opened, 0 otherwise */ |
|
55 | - public $transaction_opened; |
|
56 | - /** @var string Last successful query */ |
|
57 | - public $lastquery; |
|
58 | - /** @var string Last failed query */ |
|
59 | - public $lastqueryerror; |
|
60 | - /** @var string Last error message */ |
|
61 | - public $lasterror; |
|
62 | - /** @var string Last error number. For example: 'DB_ERROR_RECORD_ALREADY_EXISTS', '12345', ... */ |
|
63 | - public $lasterrno; |
|
32 | + /** @var resource Database handler */ |
|
33 | + public $db; |
|
34 | + /** @var string Database type */ |
|
35 | + public $type; |
|
36 | + /** @var string Charset used to force charset when creating database */ |
|
37 | + public $forcecharset='utf8'; |
|
38 | + /** @var string Collate used to force collate when creating database */ |
|
39 | + public $forcecollate='utf8_unicode_ci'; |
|
40 | + /** @var resource Resultset of last query */ |
|
41 | + private $_results; |
|
42 | + /** @var bool true if connected, else false */ |
|
43 | + public $connected; |
|
44 | + /** @var bool true if database selected, else false */ |
|
45 | + public $database_selected; |
|
46 | + /** @var string Selected database name */ |
|
47 | + public $database_name; |
|
48 | + /** @var string Database username */ |
|
49 | + public $database_user; |
|
50 | + /** @var string Database host */ |
|
51 | + public $database_host; |
|
52 | + /** @var int Database port */ |
|
53 | + public $database_port; |
|
54 | + /** @var int >=1 if a transaction is opened, 0 otherwise */ |
|
55 | + public $transaction_opened; |
|
56 | + /** @var string Last successful query */ |
|
57 | + public $lastquery; |
|
58 | + /** @var string Last failed query */ |
|
59 | + public $lastqueryerror; |
|
60 | + /** @var string Last error message */ |
|
61 | + public $lasterror; |
|
62 | + /** @var string Last error number. For example: 'DB_ERROR_RECORD_ALREADY_EXISTS', '12345', ... */ |
|
63 | + public $lasterrno; |
|
64 | 64 | |
65 | - /** @var bool Status */ |
|
66 | - public $ok; |
|
67 | - /** @var string */ |
|
68 | - public $error; |
|
65 | + /** @var bool Status */ |
|
66 | + public $ok; |
|
67 | + /** @var string */ |
|
68 | + public $error; |
|
69 | 69 | |
70 | - /** |
|
71 | - * Format a SQL IF |
|
72 | - * |
|
73 | - * @param string $test Test string (example: 'cd.statut=0', 'field IS NULL') |
|
74 | - * @param string $resok resultat si test egal |
|
75 | - * @param string $resko resultat si test non egal |
|
76 | - * @return string SQL string |
|
77 | - */ |
|
78 | - function ifsql($test,$resok,$resko) |
|
79 | - { |
|
80 | - return 'IF('.$test.','.$resok.','.$resko.')'; |
|
81 | - } |
|
70 | + /** |
|
71 | + * Format a SQL IF |
|
72 | + * |
|
73 | + * @param string $test Test string (example: 'cd.statut=0', 'field IS NULL') |
|
74 | + * @param string $resok resultat si test egal |
|
75 | + * @param string $resko resultat si test non egal |
|
76 | + * @return string SQL string |
|
77 | + */ |
|
78 | + function ifsql($test,$resok,$resko) |
|
79 | + { |
|
80 | + return 'IF('.$test.','.$resok.','.$resko.')'; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. |
|
85 | - * Function to use to build INSERT, UPDATE or WHERE predica |
|
86 | - * |
|
87 | - * @param int $param Date TMS to convert |
|
88 | - * @return string Date in a string YYYY-MM-DD HH:MM:SS |
|
89 | - */ |
|
90 | - function idate($param) |
|
91 | - { |
|
92 | - // TODO GMT $param should be gmt, so we should add tzouptut to 'gmt' |
|
93 | - return dol_print_date($param,"%Y-%m-%d %H:%M:%S"); |
|
94 | - } |
|
83 | + /** |
|
84 | + * Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. |
|
85 | + * Function to use to build INSERT, UPDATE or WHERE predica |
|
86 | + * |
|
87 | + * @param int $param Date TMS to convert |
|
88 | + * @return string Date in a string YYYY-MM-DD HH:MM:SS |
|
89 | + */ |
|
90 | + function idate($param) |
|
91 | + { |
|
92 | + // TODO GMT $param should be gmt, so we should add tzouptut to 'gmt' |
|
93 | + return dol_print_date($param,"%Y-%m-%d %H:%M:%S"); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Return last error code |
|
98 | - * |
|
99 | - * @return string lasterrno |
|
100 | - */ |
|
101 | - function lasterrno() |
|
102 | - { |
|
103 | - return $this->lasterrno; |
|
104 | - } |
|
96 | + /** |
|
97 | + * Return last error code |
|
98 | + * |
|
99 | + * @return string lasterrno |
|
100 | + */ |
|
101 | + function lasterrno() |
|
102 | + { |
|
103 | + return $this->lasterrno; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Start transaction |
|
108 | - * |
|
109 | - * @return int 1 if transaction successfuly opened or already opened, 0 if error |
|
110 | - */ |
|
111 | - function begin() |
|
112 | - { |
|
113 | - if (! $this->transaction_opened) |
|
114 | - { |
|
115 | - $ret=$this->query("BEGIN"); |
|
116 | - if ($ret) |
|
117 | - { |
|
118 | - $this->transaction_opened++; |
|
119 | - dol_syslog("BEGIN Transaction",LOG_DEBUG); |
|
120 | - dol_syslog('',0,1); |
|
121 | - } |
|
122 | - return $ret; |
|
123 | - } |
|
124 | - else |
|
125 | - { |
|
126 | - $this->transaction_opened++; |
|
127 | - dol_syslog('',0,1); |
|
128 | - return 1; |
|
129 | - } |
|
130 | - } |
|
106 | + /** |
|
107 | + * Start transaction |
|
108 | + * |
|
109 | + * @return int 1 if transaction successfuly opened or already opened, 0 if error |
|
110 | + */ |
|
111 | + function begin() |
|
112 | + { |
|
113 | + if (! $this->transaction_opened) |
|
114 | + { |
|
115 | + $ret=$this->query("BEGIN"); |
|
116 | + if ($ret) |
|
117 | + { |
|
118 | + $this->transaction_opened++; |
|
119 | + dol_syslog("BEGIN Transaction",LOG_DEBUG); |
|
120 | + dol_syslog('',0,1); |
|
121 | + } |
|
122 | + return $ret; |
|
123 | + } |
|
124 | + else |
|
125 | + { |
|
126 | + $this->transaction_opened++; |
|
127 | + dol_syslog('',0,1); |
|
128 | + return 1; |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Validate a database transaction |
|
134 | - * |
|
135 | - * @param string $log Add more log to default log line |
|
136 | - * @return int 1 if validation is OK or transaction level no started, 0 if ERROR |
|
137 | - */ |
|
138 | - function commit($log='') |
|
139 | - { |
|
140 | - dol_syslog('',0,-1); |
|
141 | - if ($this->transaction_opened<=1) |
|
142 | - { |
|
143 | - $ret=$this->query("COMMIT"); |
|
144 | - if ($ret) |
|
145 | - { |
|
146 | - $this->transaction_opened=0; |
|
147 | - dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
148 | - return 1; |
|
149 | - } |
|
150 | - else |
|
151 | - { |
|
152 | - return 0; |
|
153 | - } |
|
154 | - } |
|
155 | - else |
|
156 | - { |
|
157 | - $this->transaction_opened--; |
|
158 | - return 1; |
|
159 | - } |
|
160 | - } |
|
132 | + /** |
|
133 | + * Validate a database transaction |
|
134 | + * |
|
135 | + * @param string $log Add more log to default log line |
|
136 | + * @return int 1 if validation is OK or transaction level no started, 0 if ERROR |
|
137 | + */ |
|
138 | + function commit($log='') |
|
139 | + { |
|
140 | + dol_syslog('',0,-1); |
|
141 | + if ($this->transaction_opened<=1) |
|
142 | + { |
|
143 | + $ret=$this->query("COMMIT"); |
|
144 | + if ($ret) |
|
145 | + { |
|
146 | + $this->transaction_opened=0; |
|
147 | + dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
148 | + return 1; |
|
149 | + } |
|
150 | + else |
|
151 | + { |
|
152 | + return 0; |
|
153 | + } |
|
154 | + } |
|
155 | + else |
|
156 | + { |
|
157 | + $this->transaction_opened--; |
|
158 | + return 1; |
|
159 | + } |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Annulation d'une transaction et retour aux anciennes valeurs |
|
164 | - * |
|
165 | - * @param string $log Add more log to default log line |
|
166 | - * @return resource|int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur |
|
167 | - */ |
|
168 | - function rollback($log='') |
|
169 | - { |
|
170 | - dol_syslog('',0,-1); |
|
171 | - if ($this->transaction_opened<=1) |
|
172 | - { |
|
173 | - $ret=$this->query("ROLLBACK"); |
|
174 | - $this->transaction_opened=0; |
|
175 | - dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
176 | - return $ret; |
|
177 | - } |
|
178 | - else |
|
179 | - { |
|
180 | - $this->transaction_opened--; |
|
181 | - return 1; |
|
182 | - } |
|
183 | - } |
|
162 | + /** |
|
163 | + * Annulation d'une transaction et retour aux anciennes valeurs |
|
164 | + * |
|
165 | + * @param string $log Add more log to default log line |
|
166 | + * @return resource|int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur |
|
167 | + */ |
|
168 | + function rollback($log='') |
|
169 | + { |
|
170 | + dol_syslog('',0,-1); |
|
171 | + if ($this->transaction_opened<=1) |
|
172 | + { |
|
173 | + $ret=$this->query("ROLLBACK"); |
|
174 | + $this->transaction_opened=0; |
|
175 | + dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
176 | + return $ret; |
|
177 | + } |
|
178 | + else |
|
179 | + { |
|
180 | + $this->transaction_opened--; |
|
181 | + return 1; |
|
182 | + } |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Define limits and offset of request |
|
187 | - * |
|
188 | - * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) |
|
189 | - * @param int $offset Numero of line from where starting fetch |
|
190 | - * @return string String with SQL syntax to add a limit and offset |
|
191 | - */ |
|
192 | - function plimit($limit=0,$offset=0) |
|
193 | - { |
|
194 | - global $conf; |
|
195 | - if (empty($limit)) return ""; |
|
196 | - if ($limit < 0) $limit=$conf->liste_limit; |
|
197 | - if ($offset > 0) return " LIMIT $offset,$limit "; |
|
198 | - else return " LIMIT $limit "; |
|
199 | - } |
|
185 | + /** |
|
186 | + * Define limits and offset of request |
|
187 | + * |
|
188 | + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) |
|
189 | + * @param int $offset Numero of line from where starting fetch |
|
190 | + * @return string String with SQL syntax to add a limit and offset |
|
191 | + */ |
|
192 | + function plimit($limit=0,$offset=0) |
|
193 | + { |
|
194 | + global $conf; |
|
195 | + if (empty($limit)) return ""; |
|
196 | + if ($limit < 0) $limit=$conf->liste_limit; |
|
197 | + if ($offset > 0) return " LIMIT $offset,$limit "; |
|
198 | + else return " LIMIT $limit "; |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * Return version of database server into an array |
|
203 | - * |
|
204 | - * @return array Version array |
|
205 | - */ |
|
206 | - function getVersionArray() |
|
207 | - { |
|
208 | - return preg_split("/[\.,-]/",$this->getVersion()); |
|
209 | - } |
|
201 | + /** |
|
202 | + * Return version of database server into an array |
|
203 | + * |
|
204 | + * @return array Version array |
|
205 | + */ |
|
206 | + function getVersionArray() |
|
207 | + { |
|
208 | + return preg_split("/[\.,-]/",$this->getVersion()); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Return last request executed with query() |
|
213 | - * |
|
214 | - * @return string Last query |
|
215 | - */ |
|
216 | - function lastquery() |
|
217 | - { |
|
218 | - return $this->lastquery; |
|
219 | - } |
|
211 | + /** |
|
212 | + * Return last request executed with query() |
|
213 | + * |
|
214 | + * @return string Last query |
|
215 | + */ |
|
216 | + function lastquery() |
|
217 | + { |
|
218 | + return $this->lastquery; |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * Define sort criteria of request |
|
223 | - * |
|
224 | - * @param string $sortfield List of sort fields, separated by comma. Example: 't1.fielda,t2.fieldb' |
|
225 | - * @param string $sortorder Sort order, separated by comma. Example: 'ASC,DESC'; |
|
226 | - * @return string String to provide syntax of a sort sql string |
|
227 | - */ |
|
228 | - function order($sortfield=null,$sortorder=null) |
|
229 | - { |
|
230 | - if (! empty($sortfield)) |
|
231 | - { |
|
232 | - $return=''; |
|
233 | - $fields=explode(',',$sortfield); |
|
234 | - $orders=explode(',',$sortorder); |
|
235 | - $i=0; |
|
236 | - foreach($fields as $val) |
|
237 | - { |
|
238 | - if (! $return) $return.=' ORDER BY '; |
|
239 | - else $return.=', '; |
|
221 | + /** |
|
222 | + * Define sort criteria of request |
|
223 | + * |
|
224 | + * @param string $sortfield List of sort fields, separated by comma. Example: 't1.fielda,t2.fieldb' |
|
225 | + * @param string $sortorder Sort order, separated by comma. Example: 'ASC,DESC'; |
|
226 | + * @return string String to provide syntax of a sort sql string |
|
227 | + */ |
|
228 | + function order($sortfield=null,$sortorder=null) |
|
229 | + { |
|
230 | + if (! empty($sortfield)) |
|
231 | + { |
|
232 | + $return=''; |
|
233 | + $fields=explode(',',$sortfield); |
|
234 | + $orders=explode(',',$sortorder); |
|
235 | + $i=0; |
|
236 | + foreach($fields as $val) |
|
237 | + { |
|
238 | + if (! $return) $return.=' ORDER BY '; |
|
239 | + else $return.=', '; |
|
240 | 240 | |
241 | - $return.=preg_replace('/[^0-9a-z_\.]/i','',$val); |
|
241 | + $return.=preg_replace('/[^0-9a-z_\.]/i','',$val); |
|
242 | 242 | |
243 | - $tmpsortorder = trim($orders[$i]); |
|
243 | + $tmpsortorder = trim($orders[$i]); |
|
244 | 244 | |
245 | - // Only ASC and DESC values are valid SQL |
|
246 | - if (strtoupper($tmpsortorder) === 'ASC') { |
|
247 | - $return .= ' ASC'; |
|
248 | - } elseif (strtoupper($tmpsortorder) === 'DESC') { |
|
249 | - $return .= ' DESC'; |
|
250 | - } |
|
245 | + // Only ASC and DESC values are valid SQL |
|
246 | + if (strtoupper($tmpsortorder) === 'ASC') { |
|
247 | + $return .= ' ASC'; |
|
248 | + } elseif (strtoupper($tmpsortorder) === 'DESC') { |
|
249 | + $return .= ' DESC'; |
|
250 | + } |
|
251 | 251 | |
252 | - $i++; |
|
253 | - } |
|
254 | - return $return; |
|
255 | - } |
|
256 | - else |
|
257 | - { |
|
258 | - return ''; |
|
259 | - } |
|
260 | - } |
|
252 | + $i++; |
|
253 | + } |
|
254 | + return $return; |
|
255 | + } |
|
256 | + else |
|
257 | + { |
|
258 | + return ''; |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * Return last error label |
|
264 | - * |
|
265 | - * @return string Last error |
|
266 | - */ |
|
267 | - function lasterror() |
|
268 | - { |
|
269 | - return $this->lasterror; |
|
270 | - } |
|
262 | + /** |
|
263 | + * Return last error label |
|
264 | + * |
|
265 | + * @return string Last error |
|
266 | + */ |
|
267 | + function lasterror() |
|
268 | + { |
|
269 | + return $this->lasterror; |
|
270 | + } |
|
271 | 271 | |
272 | - /** |
|
273 | - * Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) |
|
274 | - * 19700101020000 -> 3600 with TZ+1 and gmt=0 |
|
275 | - * 19700101020000 -> 7200 whaterver is TZ if gmt=1 |
|
276 | - * |
|
277 | - * @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) |
|
278 | - * @param bool $gm 1=Input informations are GMT values, otherwise local to server TZ |
|
279 | - * @return int|string Date TMS or '' |
|
280 | - */ |
|
281 | - function jdate($string, $gm=false) |
|
282 | - { |
|
283 | - // TODO GMT must set param gm to true by default |
|
284 | - if ($string==0 || $string=="0000-00-00 00:00:00") return ''; |
|
285 | - $string=preg_replace('/([^0-9])/i','',$string); |
|
286 | - $tmp=$string.'000000'; |
|
287 | - $date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm); |
|
288 | - return $date; |
|
289 | - } |
|
272 | + /** |
|
273 | + * Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) |
|
274 | + * 19700101020000 -> 3600 with TZ+1 and gmt=0 |
|
275 | + * 19700101020000 -> 7200 whaterver is TZ if gmt=1 |
|
276 | + * |
|
277 | + * @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) |
|
278 | + * @param bool $gm 1=Input informations are GMT values, otherwise local to server TZ |
|
279 | + * @return int|string Date TMS or '' |
|
280 | + */ |
|
281 | + function jdate($string, $gm=false) |
|
282 | + { |
|
283 | + // TODO GMT must set param gm to true by default |
|
284 | + if ($string==0 || $string=="0000-00-00 00:00:00") return ''; |
|
285 | + $string=preg_replace('/([^0-9])/i','',$string); |
|
286 | + $tmp=$string.'000000'; |
|
287 | + $date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm); |
|
288 | + return $date; |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Return last query in error |
|
293 | - * |
|
294 | - * @return string lastqueryerror |
|
295 | - */ |
|
296 | - function lastqueryerror() |
|
297 | - { |
|
298 | - return $this->lastqueryerror; |
|
299 | - } |
|
291 | + /** |
|
292 | + * Return last query in error |
|
293 | + * |
|
294 | + * @return string lastqueryerror |
|
295 | + */ |
|
296 | + function lastqueryerror() |
|
297 | + { |
|
298 | + return $this->lastqueryerror; |
|
299 | + } |
|
300 | 300 | } |
301 | 301 |
@@ -120,8 +120,7 @@ discard block |
||
120 | 120 | dol_syslog('',0,1); |
121 | 121 | } |
122 | 122 | return $ret; |
123 | - } |
|
124 | - else |
|
123 | + } else |
|
125 | 124 | { |
126 | 125 | $this->transaction_opened++; |
127 | 126 | dol_syslog('',0,1); |
@@ -146,13 +145,11 @@ discard block |
||
146 | 145 | $this->transaction_opened=0; |
147 | 146 | dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); |
148 | 147 | return 1; |
149 | - } |
|
150 | - else |
|
148 | + } else |
|
151 | 149 | { |
152 | 150 | return 0; |
153 | 151 | } |
154 | - } |
|
155 | - else |
|
152 | + } else |
|
156 | 153 | { |
157 | 154 | $this->transaction_opened--; |
158 | 155 | return 1; |
@@ -174,8 +171,7 @@ discard block |
||
174 | 171 | $this->transaction_opened=0; |
175 | 172 | dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); |
176 | 173 | return $ret; |
177 | - } |
|
178 | - else |
|
174 | + } else |
|
179 | 175 | { |
180 | 176 | $this->transaction_opened--; |
181 | 177 | return 1; |
@@ -192,10 +188,17 @@ discard block |
||
192 | 188 | function plimit($limit=0,$offset=0) |
193 | 189 | { |
194 | 190 | global $conf; |
195 | - if (empty($limit)) return ""; |
|
196 | - if ($limit < 0) $limit=$conf->liste_limit; |
|
197 | - if ($offset > 0) return " LIMIT $offset,$limit "; |
|
198 | - else return " LIMIT $limit "; |
|
191 | + if (empty($limit)) { |
|
192 | + return ""; |
|
193 | + } |
|
194 | + if ($limit < 0) { |
|
195 | + $limit=$conf->liste_limit; |
|
196 | + } |
|
197 | + if ($offset > 0) { |
|
198 | + return " LIMIT $offset,$limit "; |
|
199 | + } else { |
|
200 | + return " LIMIT $limit "; |
|
201 | + } |
|
199 | 202 | } |
200 | 203 | |
201 | 204 | /** |
@@ -235,8 +238,11 @@ discard block |
||
235 | 238 | $i=0; |
236 | 239 | foreach($fields as $val) |
237 | 240 | { |
238 | - if (! $return) $return.=' ORDER BY '; |
|
239 | - else $return.=', '; |
|
241 | + if (! $return) { |
|
242 | + $return.=' ORDER BY '; |
|
243 | + } else { |
|
244 | + $return.=', '; |
|
245 | + } |
|
240 | 246 | |
241 | 247 | $return.=preg_replace('/[^0-9a-z_\.]/i','',$val); |
242 | 248 | |
@@ -252,8 +258,7 @@ discard block |
||
252 | 258 | $i++; |
253 | 259 | } |
254 | 260 | return $return; |
255 | - } |
|
256 | - else |
|
261 | + } else |
|
257 | 262 | { |
258 | 263 | return ''; |
259 | 264 | } |
@@ -281,7 +286,9 @@ discard block |
||
281 | 286 | function jdate($string, $gm=false) |
282 | 287 | { |
283 | 288 | // TODO GMT must set param gm to true by default |
284 | - if ($string==0 || $string=="0000-00-00 00:00:00") return ''; |
|
289 | + if ($string==0 || $string=="0000-00-00 00:00:00") { |
|
290 | + return ''; |
|
291 | + } |
|
285 | 292 | $string=preg_replace('/([^0-9])/i','',$string); |
286 | 293 | $tmp=$string.'000000'; |
287 | 294 | $date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * \brief Class file to manage Dolibarr database access |
27 | 27 | */ |
28 | 28 | |
29 | -require_once DOL_BASE_PATH . '/core/db/Database.interface.php'; |
|
29 | +require_once DOL_BASE_PATH.'/core/db/Database.interface.php'; |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Class to manage Dolibarr database access |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | /** @var string Database type */ |
39 | 39 | public $type; |
40 | 40 | /** @var string Charset used to force charset when creating database */ |
41 | - public $forcecharset='utf8'; |
|
41 | + public $forcecharset = 'utf8'; |
|
42 | 42 | /** @var string Collate used to force collate when creating database */ |
43 | - public $forcecollate='utf8_unicode_ci'; |
|
43 | + public $forcecollate = 'utf8_unicode_ci'; |
|
44 | 44 | /** @var resource Resultset of last query */ |
45 | 45 | private $_results; |
46 | 46 | /** @var bool true if connected, else false */ |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param string $resko resultat si test non egal |
80 | 80 | * @return string SQL string |
81 | 81 | */ |
82 | - function ifsql($test,$resok,$resko) |
|
82 | + function ifsql($test, $resok, $resko) |
|
83 | 83 | { |
84 | 84 | return 'IF('.$test.','.$resok.','.$resko.')'; |
85 | 85 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | function idate($param) |
95 | 95 | { |
96 | 96 | // TODO GMT $param should be gmt, so we should add tzouptut to 'gmt' |
97 | - return dol_print_date($param,"%Y-%m-%d %H:%M:%S"); |
|
97 | + return dol_print_date($param, "%Y-%m-%d %H:%M:%S"); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -114,21 +114,21 @@ discard block |
||
114 | 114 | */ |
115 | 115 | function begin() |
116 | 116 | { |
117 | - if (! $this->transaction_opened) |
|
117 | + if (!$this->transaction_opened) |
|
118 | 118 | { |
119 | - $ret=$this->query("BEGIN"); |
|
119 | + $ret = $this->query("BEGIN"); |
|
120 | 120 | if ($ret) |
121 | 121 | { |
122 | 122 | $this->transaction_opened++; |
123 | - dol_syslog("BEGIN Transaction",LOG_DEBUG); |
|
124 | - dol_syslog('',0,1); |
|
123 | + dol_syslog("BEGIN Transaction", LOG_DEBUG); |
|
124 | + dol_syslog('', 0, 1); |
|
125 | 125 | } |
126 | 126 | return $ret; |
127 | 127 | } |
128 | 128 | else |
129 | 129 | { |
130 | 130 | $this->transaction_opened++; |
131 | - dol_syslog('',0,1); |
|
131 | + dol_syslog('', 0, 1); |
|
132 | 132 | return 1; |
133 | 133 | } |
134 | 134 | } |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | * @param string $log Add more log to default log line |
140 | 140 | * @return int 1 if validation is OK or transaction level no started, 0 if ERROR |
141 | 141 | */ |
142 | - function commit($log='') |
|
142 | + function commit($log = '') |
|
143 | 143 | { |
144 | - dol_syslog('',0,-1); |
|
145 | - if ($this->transaction_opened<=1) |
|
144 | + dol_syslog('', 0, -1); |
|
145 | + if ($this->transaction_opened <= 1) |
|
146 | 146 | { |
147 | - $ret=$this->query("COMMIT"); |
|
147 | + $ret = $this->query("COMMIT"); |
|
148 | 148 | if ($ret) |
149 | 149 | { |
150 | - $this->transaction_opened=0; |
|
151 | - dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
150 | + $this->transaction_opened = 0; |
|
151 | + dol_syslog("COMMIT Transaction".($log ? ' '.$log : ''), LOG_DEBUG); |
|
152 | 152 | return 1; |
153 | 153 | } |
154 | 154 | else |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | * @param string $log Add more log to default log line |
170 | 170 | * @return resource|int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur |
171 | 171 | */ |
172 | - function rollback($log='') |
|
172 | + function rollback($log = '') |
|
173 | 173 | { |
174 | - dol_syslog('',0,-1); |
|
175 | - if ($this->transaction_opened<=1) |
|
174 | + dol_syslog('', 0, -1); |
|
175 | + if ($this->transaction_opened <= 1) |
|
176 | 176 | { |
177 | - $ret=$this->query("ROLLBACK"); |
|
178 | - $this->transaction_opened=0; |
|
179 | - dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
177 | + $ret = $this->query("ROLLBACK"); |
|
178 | + $this->transaction_opened = 0; |
|
179 | + dol_syslog("ROLLBACK Transaction".($log ? ' '.$log : ''), LOG_DEBUG); |
|
180 | 180 | return $ret; |
181 | 181 | } |
182 | 182 | else |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | * @param int $offset Numero of line from where starting fetch |
194 | 194 | * @return string String with SQL syntax to add a limit and offset |
195 | 195 | */ |
196 | - function plimit($limit=0,$offset=0) |
|
196 | + function plimit($limit = 0, $offset = 0) |
|
197 | 197 | { |
198 | 198 | global $conf; |
199 | 199 | if (empty($limit)) return ""; |
200 | - if ($limit < 0) $limit=$conf->liste_limit; |
|
200 | + if ($limit < 0) $limit = $conf->liste_limit; |
|
201 | 201 | if ($offset > 0) return " LIMIT $offset,$limit "; |
202 | 202 | else return " LIMIT $limit "; |
203 | 203 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | function getVersionArray() |
211 | 211 | { |
212 | - return preg_split("/[\.,-]/",$this->getVersion()); |
|
212 | + return preg_split("/[\.,-]/", $this->getVersion()); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -229,20 +229,20 @@ discard block |
||
229 | 229 | * @param string $sortorder Sort order, separated by comma. Example: 'ASC,DESC'; |
230 | 230 | * @return string String to provide syntax of a sort sql string |
231 | 231 | */ |
232 | - function order($sortfield=null,$sortorder=null) |
|
232 | + function order($sortfield = null, $sortorder = null) |
|
233 | 233 | { |
234 | - if (! empty($sortfield)) |
|
234 | + if (!empty($sortfield)) |
|
235 | 235 | { |
236 | - $return=''; |
|
237 | - $fields=explode(',',$sortfield); |
|
238 | - $orders=explode(',',$sortorder); |
|
239 | - $i=0; |
|
240 | - foreach($fields as $val) |
|
236 | + $return = ''; |
|
237 | + $fields = explode(',', $sortfield); |
|
238 | + $orders = explode(',', $sortorder); |
|
239 | + $i = 0; |
|
240 | + foreach ($fields as $val) |
|
241 | 241 | { |
242 | - if (! $return) $return.=' ORDER BY '; |
|
243 | - else $return.=', '; |
|
242 | + if (!$return) $return .= ' ORDER BY '; |
|
243 | + else $return .= ', '; |
|
244 | 244 | |
245 | - $return.=preg_replace('/[^0-9a-z_\.]/i','',$val); |
|
245 | + $return .= preg_replace('/[^0-9a-z_\.]/i', '', $val); |
|
246 | 246 | |
247 | 247 | $tmpsortorder = trim($orders[$i]); |
248 | 248 | |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | * @param bool $gm 1=Input informations are GMT values, otherwise local to server TZ |
283 | 283 | * @return int|string Date TMS or '' |
284 | 284 | */ |
285 | - function jdate($string, $gm=false) |
|
285 | + function jdate($string, $gm = false) |
|
286 | 286 | { |
287 | 287 | // TODO GMT must set param gm to true by default |
288 | - if ($string==0 || $string=="0000-00-00 00:00:00") return ''; |
|
289 | - $string=preg_replace('/([^0-9])/i','',$string); |
|
290 | - $tmp=$string.'000000'; |
|
291 | - $date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm); |
|
288 | + if ($string == 0 || $string == "0000-00-00 00:00:00") return ''; |
|
289 | + $string = preg_replace('/([^0-9])/i', '', $string); |
|
290 | + $tmp = $string.'000000'; |
|
291 | + $date = dol_mktime(substr($tmp, 8, 2), substr($tmp, 10, 2), substr($tmp, 12, 2), substr($tmp, 4, 2), substr($tmp, 6, 2), substr($tmp, 0, 4), $gm); |
|
292 | 292 | return $date; |
293 | 293 | } |
294 | 294 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | } |
41 | 41 | else |
42 | 42 | { |
43 | - // Reload to get all modified line records and be ready for hooks |
|
43 | + // Reload to get all modified line records and be ready for hooks |
|
44 | 44 | $ret = $object->fetch($id); |
45 | 45 | $ret = $object->fetch_thirdparty(); |
46 | 46 | /*if (empty($object->id) || ! $object->id > 0) |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | }*/ |
51 | 51 | |
52 | 52 | // Save last template used to generate document |
53 | - if (GETPOST('model','alpha')) |
|
54 | - { |
|
55 | - $object->setDocModel($user, GETPOST('model','alpha')); |
|
56 | - } |
|
53 | + if (GETPOST('model','alpha')) |
|
54 | + { |
|
55 | + $object->setDocModel($user, GETPOST('model','alpha')); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | // Special case to force bank account |
59 | 59 | //if (property_exists($object, 'fk_bank')) |
@@ -91,17 +91,17 @@ discard block |
||
91 | 91 | } |
92 | 92 | else |
93 | 93 | { |
94 | - if (empty($donotredirect)) // This is set when include is done by bulk action "Bill Orders" |
|
95 | - { |
|
96 | - setEventMessages($langs->trans("FileGenerated"), null); |
|
94 | + if (empty($donotredirect)) // This is set when include is done by bulk action "Bill Orders" |
|
95 | + { |
|
96 | + setEventMessages($langs->trans("FileGenerated"), null); |
|
97 | 97 | |
98 | - $urltoredirect = $_SERVER['REQUEST_URI']; |
|
99 | - $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); |
|
100 | - $urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop |
|
98 | + $urltoredirect = $_SERVER['REQUEST_URI']; |
|
99 | + $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); |
|
100 | + $urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop |
|
101 | 101 | |
102 | - header('Location: '.$urltoredirect.'#builddoc'); |
|
103 | - exit; |
|
104 | - } |
|
102 | + header('Location: '.$urltoredirect.'#builddoc'); |
|
103 | + exit; |
|
104 | + } |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | } |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | if ($action == 'builddoc' && $permissioncreate) |
35 | 35 | { |
36 | 36 | |
37 | - if (is_numeric(GETPOST('model','alpha'))) |
|
37 | + if (is_numeric(GETPOST('model', 'alpha'))) |
|
38 | 38 | { |
39 | - $error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model")); |
|
39 | + $error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model")); |
|
40 | 40 | } |
41 | 41 | else |
42 | 42 | { |
@@ -50,44 +50,44 @@ discard block |
||
50 | 50 | }*/ |
51 | 51 | |
52 | 52 | // Save last template used to generate document |
53 | - if (GETPOST('model','alpha')) |
|
53 | + if (GETPOST('model', 'alpha')) |
|
54 | 54 | { |
55 | - $object->setDocModel($user, GETPOST('model','alpha')); |
|
55 | + $object->setDocModel($user, GETPOST('model', 'alpha')); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Special case to force bank account |
59 | 59 | //if (property_exists($object, 'fk_bank')) |
60 | 60 | //{ |
61 | - if (GETPOST('fk_bank','int')) { // this field may come from an external module |
|
62 | - $object->fk_bank = GETPOST('fk_bank','int'); |
|
63 | - } else if (! empty($object->fk_account)) { |
|
61 | + if (GETPOST('fk_bank', 'int')) { // this field may come from an external module |
|
62 | + $object->fk_bank = GETPOST('fk_bank', 'int'); |
|
63 | + } else if (!empty($object->fk_account)) { |
|
64 | 64 | $object->fk_bank = $object->fk_account; |
65 | 65 | } |
66 | 66 | //} |
67 | 67 | |
68 | 68 | $outputlangs = $langs; |
69 | - $newlang=''; |
|
69 | + $newlang = ''; |
|
70 | 70 | |
71 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
72 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang=$object->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
73 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang=$object->default_lang; // for thirdparty |
|
74 | - if (! empty($newlang)) |
|
71 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); |
|
72 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang = $object->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
73 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang = $object->default_lang; // for thirdparty |
|
74 | + if (!empty($newlang)) |
|
75 | 75 | { |
76 | - $outputlangs = new Translate("",$conf); |
|
76 | + $outputlangs = new Translate("", $conf); |
|
77 | 77 | $outputlangs->setDefaultLang($newlang); |
78 | 78 | } |
79 | 79 | |
80 | 80 | // To be sure vars is defined |
81 | - if (empty($hidedetails)) $hidedetails=0; |
|
82 | - if (empty($hidedesc)) $hidedesc=0; |
|
83 | - if (empty($hideref)) $hideref=0; |
|
84 | - if (empty($moreparams)) $moreparams=null; |
|
81 | + if (empty($hidedetails)) $hidedetails = 0; |
|
82 | + if (empty($hidedesc)) $hidedesc = 0; |
|
83 | + if (empty($hideref)) $hideref = 0; |
|
84 | + if (empty($moreparams)) $moreparams = null; |
|
85 | 85 | |
86 | - $result= $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
86 | + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
87 | 87 | if ($result <= 0) |
88 | 88 | { |
89 | 89 | setEventMessages($object->error, $object->errors, 'errors'); |
90 | - $action=''; |
|
90 | + $action = ''; |
|
91 | 91 | } |
92 | 92 | else |
93 | 93 | { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | $urltoredirect = $_SERVER['REQUEST_URI']; |
99 | 99 | $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); |
100 | - $urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop |
|
100 | + $urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop |
|
101 | 101 | |
102 | 102 | header('Location: '.$urltoredirect.'#builddoc'); |
103 | 103 | exit; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | { |
112 | 112 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
113 | 113 | |
114 | - if (empty($object->id) || ! $object->id > 0) |
|
114 | + if (empty($object->id) || !$object->id > 0) |
|
115 | 115 | { |
116 | 116 | // Reload to get all modified line records and be ready for hooks |
117 | 117 | $ret = $object->fetch($id); |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | $langs->load("other"); |
122 | - $filetodelete=GETPOST('file','alpha'); |
|
123 | - $file = $upload_dir . '/' . $filetodelete; |
|
124 | - $ret=dol_delete_file($file,0,0,0,$object); |
|
122 | + $filetodelete = GETPOST('file', 'alpha'); |
|
123 | + $file = $upload_dir.'/'.$filetodelete; |
|
124 | + $ret = dol_delete_file($file, 0, 0, 0, $object); |
|
125 | 125 | if ($ret) setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs'); |
126 | 126 | else setEventMessages($langs->trans("ErrorFailToDeleteFile", $filetodelete), null, 'errors'); |
127 | 127 |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | if (is_numeric(GETPOST('model','alpha'))) |
38 | 38 | { |
39 | 39 | $error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model")); |
40 | - } |
|
41 | - else |
|
40 | + } else |
|
42 | 41 | { |
43 | 42 | // Reload to get all modified line records and be ready for hooks |
44 | 43 | $ret = $object->fetch($id); |
@@ -68,9 +67,17 @@ discard block |
||
68 | 67 | $outputlangs = $langs; |
69 | 68 | $newlang=''; |
70 | 69 | |
71 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
72 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang=$object->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
73 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang=$object->default_lang; // for thirdparty |
|
70 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) { |
|
71 | + $newlang=GETPOST('lang_id','aZ09'); |
|
72 | + } |
|
73 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) { |
|
74 | + $newlang=$object->thirdparty->default_lang; |
|
75 | + } |
|
76 | + // for proposal, order, invoice, ... |
|
77 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) { |
|
78 | + $newlang=$object->default_lang; |
|
79 | + } |
|
80 | + // for thirdparty |
|
74 | 81 | if (! empty($newlang)) |
75 | 82 | { |
76 | 83 | $outputlangs = new Translate("",$conf); |
@@ -78,22 +85,31 @@ discard block |
||
78 | 85 | } |
79 | 86 | |
80 | 87 | // To be sure vars is defined |
81 | - if (empty($hidedetails)) $hidedetails=0; |
|
82 | - if (empty($hidedesc)) $hidedesc=0; |
|
83 | - if (empty($hideref)) $hideref=0; |
|
84 | - if (empty($moreparams)) $moreparams=null; |
|
88 | + if (empty($hidedetails)) { |
|
89 | + $hidedetails=0; |
|
90 | + } |
|
91 | + if (empty($hidedesc)) { |
|
92 | + $hidedesc=0; |
|
93 | + } |
|
94 | + if (empty($hideref)) { |
|
95 | + $hideref=0; |
|
96 | + } |
|
97 | + if (empty($moreparams)) { |
|
98 | + $moreparams=null; |
|
99 | + } |
|
85 | 100 | |
86 | 101 | $result= $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); |
87 | 102 | if ($result <= 0) |
88 | 103 | { |
89 | 104 | setEventMessages($object->error, $object->errors, 'errors'); |
90 | 105 | $action=''; |
91 | - } |
|
92 | - else |
|
106 | + } else |
|
93 | 107 | { |
94 | - if (empty($donotredirect)) // This is set when include is done by bulk action "Bill Orders" |
|
108 | + if (empty($donotredirect)) { |
|
109 | + // This is set when include is done by bulk action "Bill Orders" |
|
95 | 110 | { |
96 | 111 | setEventMessages($langs->trans("FileGenerated"), null); |
112 | + } |
|
97 | 113 | |
98 | 114 | $urltoredirect = $_SERVER['REQUEST_URI']; |
99 | 115 | $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); |
@@ -122,8 +138,11 @@ discard block |
||
122 | 138 | $filetodelete=GETPOST('file','alpha'); |
123 | 139 | $file = $upload_dir . '/' . $filetodelete; |
124 | 140 | $ret=dol_delete_file($file,0,0,0,$object); |
125 | - if ($ret) setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs'); |
|
126 | - else setEventMessages($langs->trans("ErrorFailToDeleteFile", $filetodelete), null, 'errors'); |
|
141 | + if ($ret) { |
|
142 | + setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs'); |
|
143 | + } else { |
|
144 | + setEventMessages($langs->trans("ErrorFailToDeleteFile", $filetodelete), null, 'errors'); |
|
145 | + } |
|
127 | 146 | |
128 | 147 | // Make a redirect to avoid to keep the remove_file into the url that create side effects |
129 | 148 | $urltoredirect = $_SERVER['REQUEST_URI']; |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | else |
79 | 79 | { |
80 | 80 | $usedbyinclude = 1; // Used into next include |
81 | - $showtitlebefore = GETPOST('showtitlebefore','int'); |
|
82 | - include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; |
|
81 | + $showtitlebefore = GETPOST('showtitlebefore','int'); |
|
82 | + include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; |
|
83 | 83 | |
84 | 84 | $accesskeyalreadyassigned=array(); |
85 | 85 | foreach($arrayresult as $key => $val) |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | $reshook=$hookmanager->executeHooks('printSearchForm',$parameters); // Note that $action and $object may have been modified by some hooks |
104 | 104 | if (empty($reshook)) |
105 | 105 | { |
106 | - $searchform.=$hookmanager->resPrint; |
|
106 | + $searchform.=$hookmanager->resPrint; |
|
107 | 107 | } |
108 | 108 | else $searchform=$hookmanager->resPrint; |
109 | 109 |
@@ -27,32 +27,32 @@ discard block |
||
27 | 27 | //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language |
28 | 28 | //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
29 | 29 | //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations |
30 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); |
|
31 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); |
|
30 | +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); |
|
31 | +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); |
|
32 | 32 | //if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language |
33 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); |
|
33 | +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); |
|
34 | 34 | //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); |
35 | 35 | |
36 | 36 | require_once '../main.inc.php'; |
37 | 37 | |
38 | -if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php |
|
38 | +if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php |
|
39 | 39 | |
40 | 40 | $langs->load("main"); |
41 | 41 | |
42 | -$right=($langs->trans("DIRECTION")=='rtl'?'left':'right'); |
|
43 | -$left=($langs->trans("DIRECTION")=='rtl'?'right':'left'); |
|
42 | +$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right'); |
|
43 | +$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left'); |
|
44 | 44 | |
45 | 45 | |
46 | 46 | /* |
47 | 47 | * View |
48 | 48 | */ |
49 | 49 | |
50 | -$title=$langs->trans("Search"); |
|
50 | +$title = $langs->trans("Search"); |
|
51 | 51 | |
52 | 52 | // URL http://mydolibarr/core/search_page?dol_use_jmobile=1 can be used for tests |
53 | -$head='<!-- Quick access -->'."\n"; |
|
54 | -$arrayofjs=array(); |
|
55 | -$arrayofcss=array(); |
|
53 | +$head = '<!-- Quick access -->'."\n"; |
|
54 | +$arrayofjs = array(); |
|
55 | +$arrayofcss = array(); |
|
56 | 56 | top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss); |
57 | 57 | |
58 | 58 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | print '<div>'; |
62 | 62 | //print '<br>'; |
63 | 63 | |
64 | -$nbofsearch=0; |
|
64 | +$nbofsearch = 0; |
|
65 | 65 | |
66 | 66 | // Instantiate hooks of thirdparty module |
67 | 67 | $hookmanager->initHooks(array('searchform')); |
@@ -71,41 +71,41 @@ discard block |
||
71 | 71 | |
72 | 72 | if ($conf->use_javascript_ajax && 1 == 2) // select2 is ko with jmobile |
73 | 73 | { |
74 | - if (! is_object($form)) $form=new Form($db); |
|
75 | - $selected=-1; |
|
76 | - $searchform.='<br><br>'.$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth300', 1, $langs->trans("Search"), 0); |
|
74 | + if (!is_object($form)) $form = new Form($db); |
|
75 | + $selected = -1; |
|
76 | + $searchform .= '<br><br>'.$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth300', 1, $langs->trans("Search"), 0); |
|
77 | 77 | } |
78 | 78 | else |
79 | 79 | { |
80 | 80 | $usedbyinclude = 1; // Used into next include |
81 | - $showtitlebefore = GETPOST('showtitlebefore','int'); |
|
81 | + $showtitlebefore = GETPOST('showtitlebefore', 'int'); |
|
82 | 82 | include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; |
83 | 83 | |
84 | - $accesskeyalreadyassigned=array(); |
|
85 | - foreach($arrayresult as $key => $val) |
|
84 | + $accesskeyalreadyassigned = array(); |
|
85 | + foreach ($arrayresult as $key => $val) |
|
86 | 86 | { |
87 | - $tmp=explode('?', $val['url']); |
|
88 | - $urlaction=$tmp[0]; |
|
89 | - $keysearch='search_all'; |
|
87 | + $tmp = explode('?', $val['url']); |
|
88 | + $urlaction = $tmp[0]; |
|
89 | + $keysearch = 'search_all'; |
|
90 | 90 | |
91 | - $accesskey=''; |
|
92 | - if (! $accesskeyalreadyassigned[$val['label'][0]]) |
|
91 | + $accesskey = ''; |
|
92 | + if (!$accesskeyalreadyassigned[$val['label'][0]]) |
|
93 | 93 | { |
94 | - $accesskey=$val['label'][0]; |
|
95 | - $accesskeyalreadyassigned[$accesskey]=$accesskey; |
|
94 | + $accesskey = $val['label'][0]; |
|
95 | + $accesskeyalreadyassigned[$accesskey] = $accesskey; |
|
96 | 96 | } |
97 | - $searchform.=printSearchForm($urlaction, $urlaction, $val['label'], 'minwidth200', $keysearch, $accesskey, $key, img_picto('',$val['img'],'', 0, 1), $showtitlebefore); |
|
97 | + $searchform .= printSearchForm($urlaction, $urlaction, $val['label'], 'minwidth200', $keysearch, $accesskey, $key, img_picto('', $val['img'], '', 0, 1), $showtitlebefore); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | 101 | // Execute hook printSearchForm |
102 | -$parameters=array('searchform'=>$searchform); |
|
103 | -$reshook=$hookmanager->executeHooks('printSearchForm',$parameters); // Note that $action and $object may have been modified by some hooks |
|
102 | +$parameters = array('searchform'=>$searchform); |
|
103 | +$reshook = $hookmanager->executeHooks('printSearchForm', $parameters); // Note that $action and $object may have been modified by some hooks |
|
104 | 104 | if (empty($reshook)) |
105 | 105 | { |
106 | - $searchform.=$hookmanager->resPrint; |
|
106 | + $searchform .= $hookmanager->resPrint; |
|
107 | 107 | } |
108 | -else $searchform=$hookmanager->resPrint; |
|
108 | +else $searchform = $hookmanager->resPrint; |
|
109 | 109 | |
110 | 110 | |
111 | 111 | print "\n"; |
@@ -27,15 +27,24 @@ discard block |
||
27 | 27 | //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language |
28 | 28 | //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
29 | 29 | //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations |
30 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); |
|
31 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); |
|
30 | +if (! defined('NOCSRFCHECK')) { |
|
31 | + define('NOCSRFCHECK',1); |
|
32 | +} |
|
33 | +if (! defined('NOTOKENRENEWAL')) { |
|
34 | + define('NOTOKENRENEWAL',1); |
|
35 | +} |
|
32 | 36 | //if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language |
33 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); |
|
37 | +if (! defined('NOREQUIREMENU')) { |
|
38 | + define('NOREQUIREMENU',1); |
|
39 | +} |
|
34 | 40 | //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); |
35 | 41 | |
36 | 42 | require_once '../main.inc.php'; |
37 | 43 | |
38 | -if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php |
|
44 | +if (GETPOST('lang', 'aZ09')) { |
|
45 | + $langs->setDefaultLang(GETPOST('lang', 'aZ09')); |
|
46 | +} |
|
47 | +// If language was forced on URL by the main.inc.php |
|
39 | 48 | |
40 | 49 | $langs->load("main"); |
41 | 50 | |
@@ -69,13 +78,14 @@ discard block |
||
69 | 78 | // Define $searchform |
70 | 79 | $searchform = ''; |
71 | 80 | |
72 | -if ($conf->use_javascript_ajax && 1 == 2) // select2 is ko with jmobile |
|
81 | +if ($conf->use_javascript_ajax && 1 == 2) { |
|
82 | + // select2 is ko with jmobile |
|
73 | 83 | { |
74 | 84 | if (! is_object($form)) $form=new Form($db); |
85 | +} |
|
75 | 86 | $selected=-1; |
76 | 87 | $searchform.='<br><br>'.$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth300', 1, $langs->trans("Search"), 0); |
77 | -} |
|
78 | -else |
|
88 | +} else |
|
79 | 89 | { |
80 | 90 | $usedbyinclude = 1; // Used into next include |
81 | 91 | $showtitlebefore = GETPOST('showtitlebefore','int'); |
@@ -104,8 +114,9 @@ discard block |
||
104 | 114 | if (empty($reshook)) |
105 | 115 | { |
106 | 116 | $searchform.=$hookmanager->resPrint; |
117 | +} else { |
|
118 | + $searchform=$hookmanager->resPrint; |
|
107 | 119 | } |
108 | -else $searchform=$hookmanager->resPrint; |
|
109 | 120 | |
110 | 121 | |
111 | 122 | print "\n"; |
@@ -40,23 +40,23 @@ discard block |
||
40 | 40 | // Add attribute |
41 | 41 | if ($action == 'add') |
42 | 42 | { |
43 | - if ($_POST["button"] != $langs->trans("Cancel")) |
|
44 | - { |
|
45 | - // Check values |
|
46 | - if (! $type) |
|
47 | - { |
|
48 | - $error++; |
|
49 | - $langs->load("errors"); |
|
50 | - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")); |
|
51 | - $action = 'create'; |
|
52 | - } |
|
53 | - if ($type=='varchar' && $extrasize <= 0) |
|
54 | - { |
|
55 | - $error++; |
|
56 | - $langs->load("errors"); |
|
57 | - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size")); |
|
58 | - $action = 'edit'; |
|
59 | - } |
|
43 | + if ($_POST["button"] != $langs->trans("Cancel")) |
|
44 | + { |
|
45 | + // Check values |
|
46 | + if (! $type) |
|
47 | + { |
|
48 | + $error++; |
|
49 | + $langs->load("errors"); |
|
50 | + $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")); |
|
51 | + $action = 'create'; |
|
52 | + } |
|
53 | + if ($type=='varchar' && $extrasize <= 0) |
|
54 | + { |
|
55 | + $error++; |
|
56 | + $langs->load("errors"); |
|
57 | + $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size")); |
|
58 | + $action = 'edit'; |
|
59 | + } |
|
60 | 60 | if ($type=='varchar' && $extrasize > $maxsizestring) |
61 | 61 | { |
62 | 62 | $error++; |
@@ -73,168 +73,168 @@ discard block |
||
73 | 73 | } |
74 | 74 | if ($type=='select' && !$param) |
75 | 75 | { |
76 | - $error++; |
|
77 | - $langs->load("errors"); |
|
78 | - $mesg[]=$langs->trans("ErrorNoValueForSelectType"); |
|
79 | - $action = 'create'; |
|
76 | + $error++; |
|
77 | + $langs->load("errors"); |
|
78 | + $mesg[]=$langs->trans("ErrorNoValueForSelectType"); |
|
79 | + $action = 'create'; |
|
80 | 80 | } |
81 | 81 | if ($type=='sellist' && !$param) |
82 | 82 | { |
83 | - $error++; |
|
84 | - $langs->load("errors"); |
|
85 | - $mesg[]=$langs->trans("ErrorNoValueForSelectListType"); |
|
86 | - $action = 'create'; |
|
83 | + $error++; |
|
84 | + $langs->load("errors"); |
|
85 | + $mesg[]=$langs->trans("ErrorNoValueForSelectListType"); |
|
86 | + $action = 'create'; |
|
87 | 87 | } |
88 | 88 | if ($type=='checkbox' && !$param) |
89 | 89 | { |
90 | - $error++; |
|
91 | - $langs->load("errors"); |
|
92 | - $mesg[]=$langs->trans("ErrorNoValueForCheckBoxType"); |
|
93 | - $action = 'create'; |
|
90 | + $error++; |
|
91 | + $langs->load("errors"); |
|
92 | + $mesg[]=$langs->trans("ErrorNoValueForCheckBoxType"); |
|
93 | + $action = 'create'; |
|
94 | 94 | } |
95 | 95 | if ($type=='link' && !$param) |
96 | 96 | { |
97 | - $error++; |
|
98 | - $langs->load("errors"); |
|
99 | - $mesg[]=$langs->trans("ErrorNoValueForLinkType"); |
|
100 | - $action = 'create'; |
|
97 | + $error++; |
|
98 | + $langs->load("errors"); |
|
99 | + $mesg[]=$langs->trans("ErrorNoValueForLinkType"); |
|
100 | + $action = 'create'; |
|
101 | 101 | } |
102 | 102 | if ($type=='radio' && !$param) |
103 | 103 | { |
104 | - $error++; |
|
105 | - $langs->load("errors"); |
|
106 | - $mesg[]=$langs->trans("ErrorNoValueForRadioType"); |
|
107 | - $action = 'create'; |
|
104 | + $error++; |
|
105 | + $langs->load("errors"); |
|
106 | + $mesg[]=$langs->trans("ErrorNoValueForRadioType"); |
|
107 | + $action = 'create'; |
|
108 | 108 | } |
109 | 109 | if ((($type=='radio') || ($type=='checkbox')) && $param) |
110 | 110 | { |
111 | - // Construct array for parameter (value of select list) |
|
112 | - $parameters = $param; |
|
113 | - $parameters_array = explode("\r\n",$parameters); |
|
114 | - foreach($parameters_array as $param_ligne) |
|
115 | - { |
|
116 | - if (!empty($param_ligne)) { |
|
117 | - if (preg_match_all('/,/',$param_ligne,$matches)) |
|
118 | - { |
|
119 | - if (count($matches[0])>1) { |
|
120 | - $error++; |
|
121 | - $langs->load("errors"); |
|
122 | - $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
123 | - $action = 'create'; |
|
124 | - } |
|
125 | - } |
|
126 | - else |
|
127 | - { |
|
128 | - $error++; |
|
129 | - $langs->load("errors"); |
|
130 | - $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
131 | - $action = 'create'; |
|
132 | - } |
|
133 | - } |
|
134 | - } |
|
111 | + // Construct array for parameter (value of select list) |
|
112 | + $parameters = $param; |
|
113 | + $parameters_array = explode("\r\n",$parameters); |
|
114 | + foreach($parameters_array as $param_ligne) |
|
115 | + { |
|
116 | + if (!empty($param_ligne)) { |
|
117 | + if (preg_match_all('/,/',$param_ligne,$matches)) |
|
118 | + { |
|
119 | + if (count($matches[0])>1) { |
|
120 | + $error++; |
|
121 | + $langs->load("errors"); |
|
122 | + $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
123 | + $action = 'create'; |
|
124 | + } |
|
125 | + } |
|
126 | + else |
|
127 | + { |
|
128 | + $error++; |
|
129 | + $langs->load("errors"); |
|
130 | + $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
131 | + $action = 'create'; |
|
132 | + } |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | |
137 | - if (! $error) |
|
138 | - { |
|
139 | - // attrname must be alphabetical and lower case only |
|
140 | - if (isset($_POST["attrname"]) && preg_match("/^[a-z0-9-_]+$/",$_POST['attrname']) && !is_numeric($_POST["attrname"])) |
|
141 | - { |
|
142 | - // Construct array for parameter (value of select list) |
|
143 | - $default_value = GETPOST('default_value','alpha'); |
|
144 | - $parameters = $param; |
|
145 | - $parameters_array = explode("\r\n",$parameters); |
|
146 | - //In sellist we have only one line and it can have come to do SQL expression |
|
147 | - if ($type=='sellist') { |
|
148 | - foreach($parameters_array as $param_ligne) |
|
149 | - { |
|
150 | - $params['options'] = array($parameters=>null); |
|
151 | - } |
|
152 | - } |
|
153 | - else |
|
154 | - { |
|
155 | - //Esle it's separated key/value and coma list |
|
156 | - foreach($parameters_array as $param_ligne) |
|
157 | - { |
|
158 | - list($key,$value) = explode(',',$param_ligne); |
|
159 | - $params['options'][$key] = $value; |
|
160 | - } |
|
161 | - } |
|
137 | + if (! $error) |
|
138 | + { |
|
139 | + // attrname must be alphabetical and lower case only |
|
140 | + if (isset($_POST["attrname"]) && preg_match("/^[a-z0-9-_]+$/",$_POST['attrname']) && !is_numeric($_POST["attrname"])) |
|
141 | + { |
|
142 | + // Construct array for parameter (value of select list) |
|
143 | + $default_value = GETPOST('default_value','alpha'); |
|
144 | + $parameters = $param; |
|
145 | + $parameters_array = explode("\r\n",$parameters); |
|
146 | + //In sellist we have only one line and it can have come to do SQL expression |
|
147 | + if ($type=='sellist') { |
|
148 | + foreach($parameters_array as $param_ligne) |
|
149 | + { |
|
150 | + $params['options'] = array($parameters=>null); |
|
151 | + } |
|
152 | + } |
|
153 | + else |
|
154 | + { |
|
155 | + //Esle it's separated key/value and coma list |
|
156 | + foreach($parameters_array as $param_ligne) |
|
157 | + { |
|
158 | + list($key,$value) = explode(',',$param_ligne); |
|
159 | + $params['options'][$key] = $value; |
|
160 | + } |
|
161 | + } |
|
162 | 162 | |
163 | - // Visibility: -1=not visible by default in list, 1=visible, 0=hidden |
|
164 | - $visibility = GETPOST('list', 'alpha'); |
|
165 | - if ($type == 'separate') $visibility=3; |
|
163 | + // Visibility: -1=not visible by default in list, 1=visible, 0=hidden |
|
164 | + $visibility = GETPOST('list', 'alpha'); |
|
165 | + if ($type == 'separate') $visibility=3; |
|
166 | 166 | |
167 | 167 | $result=$extrafields->addExtraField( |
168 | - GETPOST('attrname', 'alpha'), |
|
169 | - GETPOST('label', 'alpha'), |
|
170 | - $type, |
|
171 | - GETPOST('pos', 'int'), |
|
172 | - $extrasize, |
|
173 | - $elementtype, |
|
174 | - (GETPOST('unique', 'alpha')?1:0), |
|
175 | - (GETPOST('required', 'alpha')?1:0), |
|
176 | - $default_value, |
|
177 | - $params, |
|
178 | - (GETPOST('alwayseditable', 'alpha')?1:0), |
|
179 | - (GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''), |
|
180 | - $visibility, |
|
181 | - GETPOST('help','alpha'), |
|
168 | + GETPOST('attrname', 'alpha'), |
|
169 | + GETPOST('label', 'alpha'), |
|
170 | + $type, |
|
171 | + GETPOST('pos', 'int'), |
|
172 | + $extrasize, |
|
173 | + $elementtype, |
|
174 | + (GETPOST('unique', 'alpha')?1:0), |
|
175 | + (GETPOST('required', 'alpha')?1:0), |
|
176 | + $default_value, |
|
177 | + $params, |
|
178 | + (GETPOST('alwayseditable', 'alpha')?1:0), |
|
179 | + (GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''), |
|
180 | + $visibility, |
|
181 | + GETPOST('help','alpha'), |
|
182 | 182 | GETPOST('computed_value','alpha'), |
183 | - (GETPOST('entitycurrentorall', 'alpha')?0:''), |
|
183 | + (GETPOST('entitycurrentorall', 'alpha')?0:''), |
|
184 | 184 | GETPOST('langfile', 'alpha'), |
185 | 185 | 1, |
186 | 186 | (GETPOST('totalizable', 'alpha')?1:0) |
187 | 187 | ); |
188 | - if ($result > 0) |
|
189 | - { |
|
190 | - setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); |
|
191 | - header("Location: ".$_SERVER["PHP_SELF"]); |
|
192 | - exit; |
|
193 | - } |
|
194 | - else |
|
195 | - { |
|
188 | + if ($result > 0) |
|
189 | + { |
|
190 | + setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); |
|
191 | + header("Location: ".$_SERVER["PHP_SELF"]); |
|
192 | + exit; |
|
193 | + } |
|
194 | + else |
|
195 | + { |
|
196 | 196 | $error++; |
197 | - $mesg=$extrafields->error; |
|
197 | + $mesg=$extrafields->error; |
|
198 | 198 | setEventMessages($mesg, null, 'errors'); |
199 | - } |
|
200 | - } |
|
201 | - else |
|
202 | - { |
|
199 | + } |
|
200 | + } |
|
201 | + else |
|
202 | + { |
|
203 | 203 | $error++; |
204 | - $langs->load("errors"); |
|
205 | - $mesg=$langs->trans("ErrorFieldCanNotContainSpecialNorUpperCharacters",$langs->transnoentities("AttributeCode")); |
|
206 | - setEventMessages($mesg, null, 'errors'); |
|
207 | - $action = 'create'; |
|
208 | - } |
|
209 | - } |
|
210 | - else |
|
211 | - { |
|
212 | - setEventMessages($mesg, null, 'errors'); |
|
213 | - } |
|
214 | - } |
|
204 | + $langs->load("errors"); |
|
205 | + $mesg=$langs->trans("ErrorFieldCanNotContainSpecialNorUpperCharacters",$langs->transnoentities("AttributeCode")); |
|
206 | + setEventMessages($mesg, null, 'errors'); |
|
207 | + $action = 'create'; |
|
208 | + } |
|
209 | + } |
|
210 | + else |
|
211 | + { |
|
212 | + setEventMessages($mesg, null, 'errors'); |
|
213 | + } |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | // Rename field |
218 | 218 | if ($action == 'update') |
219 | 219 | { |
220 | - if ($_POST["button"] != $langs->trans("Cancel")) |
|
221 | - { |
|
220 | + if ($_POST["button"] != $langs->trans("Cancel")) |
|
221 | + { |
|
222 | 222 | // Check values |
223 | - if (! $type) |
|
224 | - { |
|
225 | - $error++; |
|
226 | - $langs->load("errors"); |
|
227 | - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")); |
|
228 | - $action = 'edit'; |
|
229 | - } |
|
230 | - if ($type=='varchar' && $extrasize <= 0) |
|
231 | - { |
|
232 | - $error++; |
|
233 | - $langs->load("errors"); |
|
234 | - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size")); |
|
235 | - $action = 'edit'; |
|
236 | - } |
|
237 | - if ($type=='varchar' && $extrasize > $maxsizestring) |
|
223 | + if (! $type) |
|
224 | + { |
|
225 | + $error++; |
|
226 | + $langs->load("errors"); |
|
227 | + $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")); |
|
228 | + $action = 'edit'; |
|
229 | + } |
|
230 | + if ($type=='varchar' && $extrasize <= 0) |
|
231 | + { |
|
232 | + $error++; |
|
233 | + $langs->load("errors"); |
|
234 | + $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size")); |
|
235 | + $action = 'edit'; |
|
236 | + } |
|
237 | + if ($type=='varchar' && $extrasize > $maxsizestring) |
|
238 | 238 | { |
239 | 239 | $error++; |
240 | 240 | $langs->load("errors"); |
@@ -250,143 +250,143 @@ discard block |
||
250 | 250 | } |
251 | 251 | if ($type=='select' && !$param) |
252 | 252 | { |
253 | - $error++; |
|
254 | - $langs->load("errors"); |
|
255 | - $mesg[]=$langs->trans("ErrorNoValueForSelectType"); |
|
256 | - $action = 'edit'; |
|
253 | + $error++; |
|
254 | + $langs->load("errors"); |
|
255 | + $mesg[]=$langs->trans("ErrorNoValueForSelectType"); |
|
256 | + $action = 'edit'; |
|
257 | 257 | } |
258 | 258 | if ($type=='sellist' && !$param) |
259 | 259 | { |
260 | - $error++; |
|
261 | - $langs->load("errors"); |
|
262 | - $mesg[]=$langs->trans("ErrorNoValueForSelectListType"); |
|
263 | - $action = 'edit'; |
|
260 | + $error++; |
|
261 | + $langs->load("errors"); |
|
262 | + $mesg[]=$langs->trans("ErrorNoValueForSelectListType"); |
|
263 | + $action = 'edit'; |
|
264 | 264 | } |
265 | 265 | if ($type=='checkbox' && !$param) |
266 | 266 | { |
267 | - $error++; |
|
268 | - $langs->load("errors"); |
|
269 | - $mesg[]=$langs->trans("ErrorNoValueForCheckBoxType"); |
|
270 | - $action = 'edit'; |
|
267 | + $error++; |
|
268 | + $langs->load("errors"); |
|
269 | + $mesg[]=$langs->trans("ErrorNoValueForCheckBoxType"); |
|
270 | + $action = 'edit'; |
|
271 | 271 | } |
272 | 272 | if ($type=='radio' && !$param) |
273 | 273 | { |
274 | - $error++; |
|
275 | - $langs->load("errors"); |
|
276 | - $mesg[]=$langs->trans("ErrorNoValueForRadioType"); |
|
277 | - $action = 'edit'; |
|
274 | + $error++; |
|
275 | + $langs->load("errors"); |
|
276 | + $mesg[]=$langs->trans("ErrorNoValueForRadioType"); |
|
277 | + $action = 'edit'; |
|
278 | 278 | } |
279 | 279 | if ((($type=='radio') || ($type=='checkbox')) && $param) |
280 | 280 | { |
281 | - // Construct array for parameter (value of select list) |
|
282 | - $parameters = $param; |
|
283 | - $parameters_array = explode("\r\n",$parameters); |
|
284 | - foreach($parameters_array as $param_ligne) |
|
285 | - { |
|
286 | - if (!empty($param_ligne)) { |
|
287 | - if (preg_match_all('/,/',$param_ligne,$matches)) |
|
288 | - { |
|
289 | - if (count($matches[0])>1) { |
|
290 | - $error++; |
|
291 | - $langs->load("errors"); |
|
292 | - $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
293 | - $action = 'edit'; |
|
294 | - } |
|
295 | - } |
|
296 | - else |
|
297 | - { |
|
298 | - $error++; |
|
299 | - $langs->load("errors"); |
|
300 | - $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
301 | - $action = 'edit'; |
|
302 | - } |
|
303 | - } |
|
304 | - } |
|
281 | + // Construct array for parameter (value of select list) |
|
282 | + $parameters = $param; |
|
283 | + $parameters_array = explode("\r\n",$parameters); |
|
284 | + foreach($parameters_array as $param_ligne) |
|
285 | + { |
|
286 | + if (!empty($param_ligne)) { |
|
287 | + if (preg_match_all('/,/',$param_ligne,$matches)) |
|
288 | + { |
|
289 | + if (count($matches[0])>1) { |
|
290 | + $error++; |
|
291 | + $langs->load("errors"); |
|
292 | + $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
293 | + $action = 'edit'; |
|
294 | + } |
|
295 | + } |
|
296 | + else |
|
297 | + { |
|
298 | + $error++; |
|
299 | + $langs->load("errors"); |
|
300 | + $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
301 | + $action = 'edit'; |
|
302 | + } |
|
303 | + } |
|
304 | + } |
|
305 | 305 | } |
306 | 306 | |
307 | - if (! $error) |
|
308 | - { |
|
307 | + if (! $error) |
|
308 | + { |
|
309 | 309 | if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) |
310 | - { |
|
311 | - $pos = GETPOST('pos','int'); |
|
312 | - // Construct array for parameter (value of select list) |
|
313 | - $parameters = $param; |
|
314 | - $parameters_array = explode("\r\n",$parameters); |
|
315 | - //In sellist we have only one line and it can have come to do SQL expression |
|
316 | - if ($type=='sellist') { |
|
317 | - foreach($parameters_array as $param_ligne) |
|
318 | - { |
|
319 | - $params['options'] = array($parameters=>null); |
|
320 | - } |
|
321 | - } |
|
322 | - else |
|
323 | - { |
|
324 | - //Esle it's separated key/value and coma list |
|
325 | - foreach($parameters_array as $param_ligne) |
|
326 | - { |
|
327 | - list($key,$value) = explode(',',$param_ligne); |
|
328 | - $params['options'][$key] = $value; |
|
329 | - } |
|
330 | - } |
|
310 | + { |
|
311 | + $pos = GETPOST('pos','int'); |
|
312 | + // Construct array for parameter (value of select list) |
|
313 | + $parameters = $param; |
|
314 | + $parameters_array = explode("\r\n",$parameters); |
|
315 | + //In sellist we have only one line and it can have come to do SQL expression |
|
316 | + if ($type=='sellist') { |
|
317 | + foreach($parameters_array as $param_ligne) |
|
318 | + { |
|
319 | + $params['options'] = array($parameters=>null); |
|
320 | + } |
|
321 | + } |
|
322 | + else |
|
323 | + { |
|
324 | + //Esle it's separated key/value and coma list |
|
325 | + foreach($parameters_array as $param_ligne) |
|
326 | + { |
|
327 | + list($key,$value) = explode(',',$param_ligne); |
|
328 | + $params['options'][$key] = $value; |
|
329 | + } |
|
330 | + } |
|
331 | 331 | |
332 | - // Visibility: -1=not visible by default in list, 1=visible, 0=hidden |
|
333 | - $visibility = GETPOST('list', 'alpha'); |
|
334 | - if ($type == 'separate') $visibility=3; |
|
332 | + // Visibility: -1=not visible by default in list, 1=visible, 0=hidden |
|
333 | + $visibility = GETPOST('list', 'alpha'); |
|
334 | + if ($type == 'separate') $visibility=3; |
|
335 | 335 | |
336 | 336 | $result=$extrafields->update( |
337 | - GETPOST('attrname', 'alpha'), |
|
338 | - GETPOST('label', 'alpha'), |
|
339 | - $type, |
|
340 | - $extrasize, |
|
341 | - $elementtype, |
|
342 | - (GETPOST('unique', 'alpha')?1:0), |
|
343 | - (GETPOST('required', 'alpha')?1:0), |
|
344 | - $pos, |
|
345 | - $params, |
|
346 | - (GETPOST('alwayseditable', 'alpha')?1:0), |
|
347 | - (GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''), |
|
348 | - $visibility, |
|
349 | - GETPOST('help','alpha'), |
|
350 | - GETPOST('default_value','alpha'), |
|
351 | - GETPOST('computed_value','alpha'), |
|
352 | - (GETPOST('entitycurrentorall', 'alpha')?0:''), |
|
337 | + GETPOST('attrname', 'alpha'), |
|
338 | + GETPOST('label', 'alpha'), |
|
339 | + $type, |
|
340 | + $extrasize, |
|
341 | + $elementtype, |
|
342 | + (GETPOST('unique', 'alpha')?1:0), |
|
343 | + (GETPOST('required', 'alpha')?1:0), |
|
344 | + $pos, |
|
345 | + $params, |
|
346 | + (GETPOST('alwayseditable', 'alpha')?1:0), |
|
347 | + (GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''), |
|
348 | + $visibility, |
|
349 | + GETPOST('help','alpha'), |
|
350 | + GETPOST('default_value','alpha'), |
|
351 | + GETPOST('computed_value','alpha'), |
|
352 | + (GETPOST('entitycurrentorall', 'alpha')?0:''), |
|
353 | 353 | GETPOST('langfile'), |
354 | 354 | 1, |
355 | 355 | (GETPOST('totalizable', 'alpha')?1:0) |
356 | - ); |
|
357 | - if ($result > 0) |
|
358 | - { |
|
359 | - setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); |
|
360 | - header("Location: ".$_SERVER["PHP_SELF"]); |
|
361 | - exit; |
|
362 | - } |
|
363 | - else |
|
364 | - { |
|
356 | + ); |
|
357 | + if ($result > 0) |
|
358 | + { |
|
359 | + setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); |
|
360 | + header("Location: ".$_SERVER["PHP_SELF"]); |
|
361 | + exit; |
|
362 | + } |
|
363 | + else |
|
364 | + { |
|
365 | 365 | $error++; |
366 | - $mesg=$extrafields->error; |
|
367 | - setEventMessages($mesg, null, 'errors'); |
|
368 | - } |
|
369 | - } |
|
370 | - else |
|
371 | - { |
|
372 | - $error++; |
|
373 | - $langs->load("errors"); |
|
374 | - $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); |
|
375 | - setEventMessages($mesg, null, 'errors'); |
|
376 | - } |
|
377 | - } |
|
378 | - else |
|
379 | - { |
|
380 | - setEventMessages($mesg, null, 'errors'); |
|
381 | - } |
|
382 | - } |
|
366 | + $mesg=$extrafields->error; |
|
367 | + setEventMessages($mesg, null, 'errors'); |
|
368 | + } |
|
369 | + } |
|
370 | + else |
|
371 | + { |
|
372 | + $error++; |
|
373 | + $langs->load("errors"); |
|
374 | + $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); |
|
375 | + setEventMessages($mesg, null, 'errors'); |
|
376 | + } |
|
377 | + } |
|
378 | + else |
|
379 | + { |
|
380 | + setEventMessages($mesg, null, 'errors'); |
|
381 | + } |
|
382 | + } |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | // Delete attribute |
386 | 386 | if ($action == 'delete') |
387 | 387 | { |
388 | - if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"])) |
|
389 | - { |
|
388 | + if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"])) |
|
389 | + { |
|
390 | 390 | $result=$extrafields->delete($_GET["attrname"],$elementtype); |
391 | 391 | if ($result >= 0) |
392 | 392 | { |
@@ -394,12 +394,12 @@ discard block |
||
394 | 394 | exit; |
395 | 395 | } |
396 | 396 | else $mesg=$extrafields->error; |
397 | - } |
|
398 | - else |
|
399 | - { |
|
400 | - $error++; |
|
401 | - $langs->load("errors"); |
|
402 | - $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); |
|
403 | - } |
|
397 | + } |
|
398 | + else |
|
399 | + { |
|
400 | + $error++; |
|
401 | + $langs->load("errors"); |
|
402 | + $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); |
|
403 | + } |
|
404 | 404 | } |
405 | 405 |
@@ -23,18 +23,18 @@ discard block |
||
23 | 23 | * \brief Code for actions on extrafields admin pages |
24 | 24 | */ |
25 | 25 | |
26 | -$maxsizestring=255; |
|
27 | -$maxsizeint=10; |
|
28 | -$mesg=array(); |
|
26 | +$maxsizestring = 255; |
|
27 | +$maxsizeint = 10; |
|
28 | +$mesg = array(); |
|
29 | 29 | |
30 | -$extrasize=GETPOST('size','int'); |
|
31 | -$type=GETPOST('type','alpha'); |
|
32 | -$param=GETPOST('param','alpha'); |
|
30 | +$extrasize = GETPOST('size', 'int'); |
|
31 | +$type = GETPOST('type', 'alpha'); |
|
32 | +$param = GETPOST('param', 'alpha'); |
|
33 | 33 | |
34 | -if ($type=='double' && strpos($extrasize,',')===false) $extrasize='24,8'; |
|
35 | -if ($type=='date') $extrasize=''; |
|
36 | -if ($type=='datetime') $extrasize=''; |
|
37 | -if ($type=='select') $extrasize=''; |
|
34 | +if ($type == 'double' && strpos($extrasize, ',') === false) $extrasize = '24,8'; |
|
35 | +if ($type == 'date') $extrasize = ''; |
|
36 | +if ($type == 'datetime') $extrasize = ''; |
|
37 | +if ($type == 'select') $extrasize = ''; |
|
38 | 38 | |
39 | 39 | |
40 | 40 | // Add attribute |
@@ -43,83 +43,83 @@ discard block |
||
43 | 43 | if ($_POST["button"] != $langs->trans("Cancel")) |
44 | 44 | { |
45 | 45 | // Check values |
46 | - if (! $type) |
|
46 | + if (!$type) |
|
47 | 47 | { |
48 | 48 | $error++; |
49 | 49 | $langs->load("errors"); |
50 | - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")); |
|
50 | + $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")); |
|
51 | 51 | $action = 'create'; |
52 | 52 | } |
53 | - if ($type=='varchar' && $extrasize <= 0) |
|
53 | + if ($type == 'varchar' && $extrasize <= 0) |
|
54 | 54 | { |
55 | 55 | $error++; |
56 | 56 | $langs->load("errors"); |
57 | - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size")); |
|
57 | + $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); |
|
58 | 58 | $action = 'edit'; |
59 | 59 | } |
60 | - if ($type=='varchar' && $extrasize > $maxsizestring) |
|
60 | + if ($type == 'varchar' && $extrasize > $maxsizestring) |
|
61 | 61 | { |
62 | 62 | $error++; |
63 | 63 | $langs->load("errors"); |
64 | - $mesg[]=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring); |
|
64 | + $mesg[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring); |
|
65 | 65 | $action = 'create'; |
66 | 66 | } |
67 | - if ($type=='int' && $extrasize > $maxsizeint) |
|
67 | + if ($type == 'int' && $extrasize > $maxsizeint) |
|
68 | 68 | { |
69 | 69 | $error++; |
70 | 70 | $langs->load("errors"); |
71 | - $mesg[]=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint); |
|
71 | + $mesg[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint); |
|
72 | 72 | $action = 'create'; |
73 | 73 | } |
74 | - if ($type=='select' && !$param) |
|
74 | + if ($type == 'select' && !$param) |
|
75 | 75 | { |
76 | 76 | $error++; |
77 | 77 | $langs->load("errors"); |
78 | - $mesg[]=$langs->trans("ErrorNoValueForSelectType"); |
|
78 | + $mesg[] = $langs->trans("ErrorNoValueForSelectType"); |
|
79 | 79 | $action = 'create'; |
80 | 80 | } |
81 | - if ($type=='sellist' && !$param) |
|
81 | + if ($type == 'sellist' && !$param) |
|
82 | 82 | { |
83 | 83 | $error++; |
84 | 84 | $langs->load("errors"); |
85 | - $mesg[]=$langs->trans("ErrorNoValueForSelectListType"); |
|
85 | + $mesg[] = $langs->trans("ErrorNoValueForSelectListType"); |
|
86 | 86 | $action = 'create'; |
87 | 87 | } |
88 | - if ($type=='checkbox' && !$param) |
|
88 | + if ($type == 'checkbox' && !$param) |
|
89 | 89 | { |
90 | 90 | $error++; |
91 | 91 | $langs->load("errors"); |
92 | - $mesg[]=$langs->trans("ErrorNoValueForCheckBoxType"); |
|
92 | + $mesg[] = $langs->trans("ErrorNoValueForCheckBoxType"); |
|
93 | 93 | $action = 'create'; |
94 | 94 | } |
95 | - if ($type=='link' && !$param) |
|
95 | + if ($type == 'link' && !$param) |
|
96 | 96 | { |
97 | 97 | $error++; |
98 | 98 | $langs->load("errors"); |
99 | - $mesg[]=$langs->trans("ErrorNoValueForLinkType"); |
|
99 | + $mesg[] = $langs->trans("ErrorNoValueForLinkType"); |
|
100 | 100 | $action = 'create'; |
101 | 101 | } |
102 | - if ($type=='radio' && !$param) |
|
102 | + if ($type == 'radio' && !$param) |
|
103 | 103 | { |
104 | 104 | $error++; |
105 | 105 | $langs->load("errors"); |
106 | - $mesg[]=$langs->trans("ErrorNoValueForRadioType"); |
|
106 | + $mesg[] = $langs->trans("ErrorNoValueForRadioType"); |
|
107 | 107 | $action = 'create'; |
108 | 108 | } |
109 | - if ((($type=='radio') || ($type=='checkbox')) && $param) |
|
109 | + if ((($type == 'radio') || ($type == 'checkbox')) && $param) |
|
110 | 110 | { |
111 | 111 | // Construct array for parameter (value of select list) |
112 | 112 | $parameters = $param; |
113 | - $parameters_array = explode("\r\n",$parameters); |
|
114 | - foreach($parameters_array as $param_ligne) |
|
113 | + $parameters_array = explode("\r\n", $parameters); |
|
114 | + foreach ($parameters_array as $param_ligne) |
|
115 | 115 | { |
116 | 116 | if (!empty($param_ligne)) { |
117 | - if (preg_match_all('/,/',$param_ligne,$matches)) |
|
117 | + if (preg_match_all('/,/', $param_ligne, $matches)) |
|
118 | 118 | { |
119 | - if (count($matches[0])>1) { |
|
119 | + if (count($matches[0]) > 1) { |
|
120 | 120 | $error++; |
121 | 121 | $langs->load("errors"); |
122 | - $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
122 | + $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); |
|
123 | 123 | $action = 'create'; |
124 | 124 | } |
125 | 125 | } |
@@ -127,25 +127,25 @@ discard block |
||
127 | 127 | { |
128 | 128 | $error++; |
129 | 129 | $langs->load("errors"); |
130 | - $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
130 | + $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); |
|
131 | 131 | $action = 'create'; |
132 | 132 | } |
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | - if (! $error) |
|
137 | + if (!$error) |
|
138 | 138 | { |
139 | 139 | // attrname must be alphabetical and lower case only |
140 | - if (isset($_POST["attrname"]) && preg_match("/^[a-z0-9-_]+$/",$_POST['attrname']) && !is_numeric($_POST["attrname"])) |
|
140 | + if (isset($_POST["attrname"]) && preg_match("/^[a-z0-9-_]+$/", $_POST['attrname']) && !is_numeric($_POST["attrname"])) |
|
141 | 141 | { |
142 | 142 | // Construct array for parameter (value of select list) |
143 | - $default_value = GETPOST('default_value','alpha'); |
|
143 | + $default_value = GETPOST('default_value', 'alpha'); |
|
144 | 144 | $parameters = $param; |
145 | - $parameters_array = explode("\r\n",$parameters); |
|
145 | + $parameters_array = explode("\r\n", $parameters); |
|
146 | 146 | //In sellist we have only one line and it can have come to do SQL expression |
147 | - if ($type=='sellist') { |
|
148 | - foreach($parameters_array as $param_ligne) |
|
147 | + if ($type == 'sellist') { |
|
148 | + foreach ($parameters_array as $param_ligne) |
|
149 | 149 | { |
150 | 150 | $params['options'] = array($parameters=>null); |
151 | 151 | } |
@@ -153,37 +153,37 @@ discard block |
||
153 | 153 | else |
154 | 154 | { |
155 | 155 | //Esle it's separated key/value and coma list |
156 | - foreach($parameters_array as $param_ligne) |
|
156 | + foreach ($parameters_array as $param_ligne) |
|
157 | 157 | { |
158 | - list($key,$value) = explode(',',$param_ligne); |
|
158 | + list($key, $value) = explode(',', $param_ligne); |
|
159 | 159 | $params['options'][$key] = $value; |
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Visibility: -1=not visible by default in list, 1=visible, 0=hidden |
164 | 164 | $visibility = GETPOST('list', 'alpha'); |
165 | - if ($type == 'separate') $visibility=3; |
|
165 | + if ($type == 'separate') $visibility = 3; |
|
166 | 166 | |
167 | - $result=$extrafields->addExtraField( |
|
167 | + $result = $extrafields->addExtraField( |
|
168 | 168 | GETPOST('attrname', 'alpha'), |
169 | 169 | GETPOST('label', 'alpha'), |
170 | 170 | $type, |
171 | 171 | GETPOST('pos', 'int'), |
172 | 172 | $extrasize, |
173 | 173 | $elementtype, |
174 | - (GETPOST('unique', 'alpha')?1:0), |
|
175 | - (GETPOST('required', 'alpha')?1:0), |
|
174 | + (GETPOST('unique', 'alpha') ? 1 : 0), |
|
175 | + (GETPOST('required', 'alpha') ? 1 : 0), |
|
176 | 176 | $default_value, |
177 | 177 | $params, |
178 | - (GETPOST('alwayseditable', 'alpha')?1:0), |
|
179 | - (GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''), |
|
178 | + (GETPOST('alwayseditable', 'alpha') ? 1 : 0), |
|
179 | + (GETPOST('perms', 'alpha') ?GETPOST('perms', 'alpha') : ''), |
|
180 | 180 | $visibility, |
181 | - GETPOST('help','alpha'), |
|
182 | - GETPOST('computed_value','alpha'), |
|
183 | - (GETPOST('entitycurrentorall', 'alpha')?0:''), |
|
181 | + GETPOST('help', 'alpha'), |
|
182 | + GETPOST('computed_value', 'alpha'), |
|
183 | + (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''), |
|
184 | 184 | GETPOST('langfile', 'alpha'), |
185 | 185 | 1, |
186 | - (GETPOST('totalizable', 'alpha')?1:0) |
|
186 | + (GETPOST('totalizable', 'alpha') ? 1 : 0) |
|
187 | 187 | ); |
188 | 188 | if ($result > 0) |
189 | 189 | { |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | else |
195 | 195 | { |
196 | 196 | $error++; |
197 | - $mesg=$extrafields->error; |
|
197 | + $mesg = $extrafields->error; |
|
198 | 198 | setEventMessages($mesg, null, 'errors'); |
199 | 199 | } |
200 | 200 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | $error++; |
204 | 204 | $langs->load("errors"); |
205 | - $mesg=$langs->trans("ErrorFieldCanNotContainSpecialNorUpperCharacters",$langs->transnoentities("AttributeCode")); |
|
205 | + $mesg = $langs->trans("ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities("AttributeCode")); |
|
206 | 206 | setEventMessages($mesg, null, 'errors'); |
207 | 207 | $action = 'create'; |
208 | 208 | } |
@@ -220,76 +220,76 @@ discard block |
||
220 | 220 | if ($_POST["button"] != $langs->trans("Cancel")) |
221 | 221 | { |
222 | 222 | // Check values |
223 | - if (! $type) |
|
223 | + if (!$type) |
|
224 | 224 | { |
225 | 225 | $error++; |
226 | 226 | $langs->load("errors"); |
227 | - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")); |
|
227 | + $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")); |
|
228 | 228 | $action = 'edit'; |
229 | 229 | } |
230 | - if ($type=='varchar' && $extrasize <= 0) |
|
230 | + if ($type == 'varchar' && $extrasize <= 0) |
|
231 | 231 | { |
232 | 232 | $error++; |
233 | 233 | $langs->load("errors"); |
234 | - $mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size")); |
|
234 | + $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); |
|
235 | 235 | $action = 'edit'; |
236 | 236 | } |
237 | - if ($type=='varchar' && $extrasize > $maxsizestring) |
|
237 | + if ($type == 'varchar' && $extrasize > $maxsizestring) |
|
238 | 238 | { |
239 | 239 | $error++; |
240 | 240 | $langs->load("errors"); |
241 | - $mesg[]=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring); |
|
241 | + $mesg[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring); |
|
242 | 242 | $action = 'edit'; |
243 | 243 | } |
244 | - if ($type=='int' && $extrasize > $maxsizeint) |
|
244 | + if ($type == 'int' && $extrasize > $maxsizeint) |
|
245 | 245 | { |
246 | 246 | $error++; |
247 | 247 | $langs->load("errors"); |
248 | - $mesg[]=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint); |
|
248 | + $mesg[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint); |
|
249 | 249 | $action = 'edit'; |
250 | 250 | } |
251 | - if ($type=='select' && !$param) |
|
251 | + if ($type == 'select' && !$param) |
|
252 | 252 | { |
253 | 253 | $error++; |
254 | 254 | $langs->load("errors"); |
255 | - $mesg[]=$langs->trans("ErrorNoValueForSelectType"); |
|
255 | + $mesg[] = $langs->trans("ErrorNoValueForSelectType"); |
|
256 | 256 | $action = 'edit'; |
257 | 257 | } |
258 | - if ($type=='sellist' && !$param) |
|
258 | + if ($type == 'sellist' && !$param) |
|
259 | 259 | { |
260 | 260 | $error++; |
261 | 261 | $langs->load("errors"); |
262 | - $mesg[]=$langs->trans("ErrorNoValueForSelectListType"); |
|
262 | + $mesg[] = $langs->trans("ErrorNoValueForSelectListType"); |
|
263 | 263 | $action = 'edit'; |
264 | 264 | } |
265 | - if ($type=='checkbox' && !$param) |
|
265 | + if ($type == 'checkbox' && !$param) |
|
266 | 266 | { |
267 | 267 | $error++; |
268 | 268 | $langs->load("errors"); |
269 | - $mesg[]=$langs->trans("ErrorNoValueForCheckBoxType"); |
|
269 | + $mesg[] = $langs->trans("ErrorNoValueForCheckBoxType"); |
|
270 | 270 | $action = 'edit'; |
271 | 271 | } |
272 | - if ($type=='radio' && !$param) |
|
272 | + if ($type == 'radio' && !$param) |
|
273 | 273 | { |
274 | 274 | $error++; |
275 | 275 | $langs->load("errors"); |
276 | - $mesg[]=$langs->trans("ErrorNoValueForRadioType"); |
|
276 | + $mesg[] = $langs->trans("ErrorNoValueForRadioType"); |
|
277 | 277 | $action = 'edit'; |
278 | 278 | } |
279 | - if ((($type=='radio') || ($type=='checkbox')) && $param) |
|
279 | + if ((($type == 'radio') || ($type == 'checkbox')) && $param) |
|
280 | 280 | { |
281 | 281 | // Construct array for parameter (value of select list) |
282 | 282 | $parameters = $param; |
283 | - $parameters_array = explode("\r\n",$parameters); |
|
284 | - foreach($parameters_array as $param_ligne) |
|
283 | + $parameters_array = explode("\r\n", $parameters); |
|
284 | + foreach ($parameters_array as $param_ligne) |
|
285 | 285 | { |
286 | 286 | if (!empty($param_ligne)) { |
287 | - if (preg_match_all('/,/',$param_ligne,$matches)) |
|
287 | + if (preg_match_all('/,/', $param_ligne, $matches)) |
|
288 | 288 | { |
289 | - if (count($matches[0])>1) { |
|
289 | + if (count($matches[0]) > 1) { |
|
290 | 290 | $error++; |
291 | 291 | $langs->load("errors"); |
292 | - $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
292 | + $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); |
|
293 | 293 | $action = 'edit'; |
294 | 294 | } |
295 | 295 | } |
@@ -297,24 +297,24 @@ discard block |
||
297 | 297 | { |
298 | 298 | $error++; |
299 | 299 | $langs->load("errors"); |
300 | - $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
|
300 | + $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); |
|
301 | 301 | $action = 'edit'; |
302 | 302 | } |
303 | 303 | } |
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - if (! $error) |
|
307 | + if (!$error) |
|
308 | 308 | { |
309 | - if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) |
|
309 | + if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $_POST['attrname'])) |
|
310 | 310 | { |
311 | - $pos = GETPOST('pos','int'); |
|
311 | + $pos = GETPOST('pos', 'int'); |
|
312 | 312 | // Construct array for parameter (value of select list) |
313 | 313 | $parameters = $param; |
314 | - $parameters_array = explode("\r\n",$parameters); |
|
314 | + $parameters_array = explode("\r\n", $parameters); |
|
315 | 315 | //In sellist we have only one line and it can have come to do SQL expression |
316 | - if ($type=='sellist') { |
|
317 | - foreach($parameters_array as $param_ligne) |
|
316 | + if ($type == 'sellist') { |
|
317 | + foreach ($parameters_array as $param_ligne) |
|
318 | 318 | { |
319 | 319 | $params['options'] = array($parameters=>null); |
320 | 320 | } |
@@ -322,37 +322,37 @@ discard block |
||
322 | 322 | else |
323 | 323 | { |
324 | 324 | //Esle it's separated key/value and coma list |
325 | - foreach($parameters_array as $param_ligne) |
|
325 | + foreach ($parameters_array as $param_ligne) |
|
326 | 326 | { |
327 | - list($key,$value) = explode(',',$param_ligne); |
|
327 | + list($key, $value) = explode(',', $param_ligne); |
|
328 | 328 | $params['options'][$key] = $value; |
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
332 | 332 | // Visibility: -1=not visible by default in list, 1=visible, 0=hidden |
333 | 333 | $visibility = GETPOST('list', 'alpha'); |
334 | - if ($type == 'separate') $visibility=3; |
|
334 | + if ($type == 'separate') $visibility = 3; |
|
335 | 335 | |
336 | - $result=$extrafields->update( |
|
336 | + $result = $extrafields->update( |
|
337 | 337 | GETPOST('attrname', 'alpha'), |
338 | 338 | GETPOST('label', 'alpha'), |
339 | 339 | $type, |
340 | 340 | $extrasize, |
341 | 341 | $elementtype, |
342 | - (GETPOST('unique', 'alpha')?1:0), |
|
343 | - (GETPOST('required', 'alpha')?1:0), |
|
342 | + (GETPOST('unique', 'alpha') ? 1 : 0), |
|
343 | + (GETPOST('required', 'alpha') ? 1 : 0), |
|
344 | 344 | $pos, |
345 | 345 | $params, |
346 | - (GETPOST('alwayseditable', 'alpha')?1:0), |
|
347 | - (GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''), |
|
346 | + (GETPOST('alwayseditable', 'alpha') ? 1 : 0), |
|
347 | + (GETPOST('perms', 'alpha') ?GETPOST('perms', 'alpha') : ''), |
|
348 | 348 | $visibility, |
349 | - GETPOST('help','alpha'), |
|
350 | - GETPOST('default_value','alpha'), |
|
351 | - GETPOST('computed_value','alpha'), |
|
352 | - (GETPOST('entitycurrentorall', 'alpha')?0:''), |
|
349 | + GETPOST('help', 'alpha'), |
|
350 | + GETPOST('default_value', 'alpha'), |
|
351 | + GETPOST('computed_value', 'alpha'), |
|
352 | + (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''), |
|
353 | 353 | GETPOST('langfile'), |
354 | 354 | 1, |
355 | - (GETPOST('totalizable', 'alpha')?1:0) |
|
355 | + (GETPOST('totalizable', 'alpha') ? 1 : 0) |
|
356 | 356 | ); |
357 | 357 | if ($result > 0) |
358 | 358 | { |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | else |
364 | 364 | { |
365 | 365 | $error++; |
366 | - $mesg=$extrafields->error; |
|
366 | + $mesg = $extrafields->error; |
|
367 | 367 | setEventMessages($mesg, null, 'errors'); |
368 | 368 | } |
369 | 369 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | { |
372 | 372 | $error++; |
373 | 373 | $langs->load("errors"); |
374 | - $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); |
|
374 | + $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode")); |
|
375 | 375 | setEventMessages($mesg, null, 'errors'); |
376 | 376 | } |
377 | 377 | } |
@@ -385,21 +385,21 @@ discard block |
||
385 | 385 | // Delete attribute |
386 | 386 | if ($action == 'delete') |
387 | 387 | { |
388 | - if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"])) |
|
388 | + if (isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $_GET["attrname"])) |
|
389 | 389 | { |
390 | - $result=$extrafields->delete($_GET["attrname"],$elementtype); |
|
390 | + $result = $extrafields->delete($_GET["attrname"], $elementtype); |
|
391 | 391 | if ($result >= 0) |
392 | 392 | { |
393 | 393 | header("Location: ".$_SERVER["PHP_SELF"]); |
394 | 394 | exit; |
395 | 395 | } |
396 | - else $mesg=$extrafields->error; |
|
396 | + else $mesg = $extrafields->error; |
|
397 | 397 | } |
398 | 398 | else |
399 | 399 | { |
400 | 400 | $error++; |
401 | 401 | $langs->load("errors"); |
402 | - $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); |
|
402 | + $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode")); |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 |
@@ -31,10 +31,18 @@ discard block |
||
31 | 31 | $type=GETPOST('type','alpha'); |
32 | 32 | $param=GETPOST('param','alpha'); |
33 | 33 | |
34 | -if ($type=='double' && strpos($extrasize,',')===false) $extrasize='24,8'; |
|
35 | -if ($type=='date') $extrasize=''; |
|
36 | -if ($type=='datetime') $extrasize=''; |
|
37 | -if ($type=='select') $extrasize=''; |
|
34 | +if ($type=='double' && strpos($extrasize,',')===false) { |
|
35 | + $extrasize='24,8'; |
|
36 | +} |
|
37 | +if ($type=='date') { |
|
38 | + $extrasize=''; |
|
39 | +} |
|
40 | +if ($type=='datetime') { |
|
41 | + $extrasize=''; |
|
42 | +} |
|
43 | +if ($type=='select') { |
|
44 | + $extrasize=''; |
|
45 | +} |
|
38 | 46 | |
39 | 47 | |
40 | 48 | // Add attribute |
@@ -122,8 +130,7 @@ discard block |
||
122 | 130 | $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
123 | 131 | $action = 'create'; |
124 | 132 | } |
125 | - } |
|
126 | - else |
|
133 | + } else |
|
127 | 134 | { |
128 | 135 | $error++; |
129 | 136 | $langs->load("errors"); |
@@ -149,8 +156,7 @@ discard block |
||
149 | 156 | { |
150 | 157 | $params['options'] = array($parameters=>null); |
151 | 158 | } |
152 | - } |
|
153 | - else |
|
159 | + } else |
|
154 | 160 | { |
155 | 161 | //Esle it's separated key/value and coma list |
156 | 162 | foreach($parameters_array as $param_ligne) |
@@ -162,7 +168,9 @@ discard block |
||
162 | 168 | |
163 | 169 | // Visibility: -1=not visible by default in list, 1=visible, 0=hidden |
164 | 170 | $visibility = GETPOST('list', 'alpha'); |
165 | - if ($type == 'separate') $visibility=3; |
|
171 | + if ($type == 'separate') { |
|
172 | + $visibility=3; |
|
173 | + } |
|
166 | 174 | |
167 | 175 | $result=$extrafields->addExtraField( |
168 | 176 | GETPOST('attrname', 'alpha'), |
@@ -190,15 +198,13 @@ discard block |
||
190 | 198 | setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); |
191 | 199 | header("Location: ".$_SERVER["PHP_SELF"]); |
192 | 200 | exit; |
193 | - } |
|
194 | - else |
|
201 | + } else |
|
195 | 202 | { |
196 | 203 | $error++; |
197 | 204 | $mesg=$extrafields->error; |
198 | 205 | setEventMessages($mesg, null, 'errors'); |
199 | 206 | } |
200 | - } |
|
201 | - else |
|
207 | + } else |
|
202 | 208 | { |
203 | 209 | $error++; |
204 | 210 | $langs->load("errors"); |
@@ -206,8 +212,7 @@ discard block |
||
206 | 212 | setEventMessages($mesg, null, 'errors'); |
207 | 213 | $action = 'create'; |
208 | 214 | } |
209 | - } |
|
210 | - else |
|
215 | + } else |
|
211 | 216 | { |
212 | 217 | setEventMessages($mesg, null, 'errors'); |
213 | 218 | } |
@@ -292,8 +297,7 @@ discard block |
||
292 | 297 | $mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne); |
293 | 298 | $action = 'edit'; |
294 | 299 | } |
295 | - } |
|
296 | - else |
|
300 | + } else |
|
297 | 301 | { |
298 | 302 | $error++; |
299 | 303 | $langs->load("errors"); |
@@ -318,8 +322,7 @@ discard block |
||
318 | 322 | { |
319 | 323 | $params['options'] = array($parameters=>null); |
320 | 324 | } |
321 | - } |
|
322 | - else |
|
325 | + } else |
|
323 | 326 | { |
324 | 327 | //Esle it's separated key/value and coma list |
325 | 328 | foreach($parameters_array as $param_ligne) |
@@ -331,7 +334,9 @@ discard block |
||
331 | 334 | |
332 | 335 | // Visibility: -1=not visible by default in list, 1=visible, 0=hidden |
333 | 336 | $visibility = GETPOST('list', 'alpha'); |
334 | - if ($type == 'separate') $visibility=3; |
|
337 | + if ($type == 'separate') { |
|
338 | + $visibility=3; |
|
339 | + } |
|
335 | 340 | |
336 | 341 | $result=$extrafields->update( |
337 | 342 | GETPOST('attrname', 'alpha'), |
@@ -359,23 +364,20 @@ discard block |
||
359 | 364 | setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); |
360 | 365 | header("Location: ".$_SERVER["PHP_SELF"]); |
361 | 366 | exit; |
362 | - } |
|
363 | - else |
|
367 | + } else |
|
364 | 368 | { |
365 | 369 | $error++; |
366 | 370 | $mesg=$extrafields->error; |
367 | 371 | setEventMessages($mesg, null, 'errors'); |
368 | 372 | } |
369 | - } |
|
370 | - else |
|
373 | + } else |
|
371 | 374 | { |
372 | 375 | $error++; |
373 | 376 | $langs->load("errors"); |
374 | 377 | $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); |
375 | 378 | setEventMessages($mesg, null, 'errors'); |
376 | 379 | } |
377 | - } |
|
378 | - else |
|
380 | + } else |
|
379 | 381 | { |
380 | 382 | setEventMessages($mesg, null, 'errors'); |
381 | 383 | } |
@@ -392,10 +394,10 @@ discard block |
||
392 | 394 | { |
393 | 395 | header("Location: ".$_SERVER["PHP_SELF"]); |
394 | 396 | exit; |
397 | + } else { |
|
398 | + $mesg=$extrafields->error; |
|
395 | 399 | } |
396 | - else $mesg=$extrafields->error; |
|
397 | - } |
|
398 | - else |
|
400 | + } else |
|
399 | 401 | { |
400 | 402 | $error++; |
401 | 403 | $langs->load("errors"); |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) |
35 | 35 | * @return string Login if OK, '' if KO |
36 | 36 | */ |
37 | -function check_user_password_openid($usertotest,$passwordtotest,$entitytotest) |
|
37 | +function check_user_password_openid($usertotest, $passwordtotest, $entitytotest) |
|
38 | 38 | { |
39 | - global $_POST,$db,$conf,$langs; |
|
39 | + global $_POST, $db, $conf, $langs; |
|
40 | 40 | |
41 | 41 | dol_syslog("functions_openid::check_user_password_openid usertotest=".$usertotest); |
42 | 42 | |
43 | - $login=''; |
|
43 | + $login = ''; |
|
44 | 44 | |
45 | 45 | // Get identity from user and redirect browser to OpenID Server |
46 | 46 | if (isset($_POST['username'])) |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | $openid = new SimpleOpenID(); |
49 | 49 | $openid->SetIdentity($_POST['username']); |
50 | 50 | $protocol = ($conf->file->main_force_https ? 'https://' : 'http://'); |
51 | - $openid->SetTrustRoot($protocol . $_SERVER["HTTP_HOST"]); |
|
52 | - $openid->SetRequiredFields(array('email','fullname')); |
|
51 | + $openid->SetTrustRoot($protocol.$_SERVER["HTTP_HOST"]); |
|
52 | + $openid->SetRequiredFields(array('email', 'fullname')); |
|
53 | 53 | $_SESSION['dol_entity'] = $_POST["entity"]; |
54 | 54 | //$openid->SetOptionalFields(array('dob','gender','postcode','country','language','timezone')); |
55 | 55 | if ($openid->sendDiscoveryRequestToGetXRDS()) |
56 | 56 | { |
57 | - $openid->SetApprovedURL($protocol . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"]); // Send Response from OpenID server to this script |
|
58 | - $openid->Redirect(); // This will redirect user to OpenID Server |
|
57 | + $openid->SetApprovedURL($protocol.$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]); // Send Response from OpenID server to this script |
|
58 | + $openid->Redirect(); // This will redirect user to OpenID Server |
|
59 | 59 | } |
60 | 60 | else |
61 | 61 | { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | // Perform HTTP Request to OpenID server to validate key |
68 | - elseif($_GET['openid_mode'] == 'id_res') |
|
68 | + elseif ($_GET['openid_mode'] == 'id_res') |
|
69 | 69 | { |
70 | 70 | $openid = new SimpleOpenID(); |
71 | 71 | $openid->SetIdentity($_GET['openid_identity']); |
@@ -74,23 +74,23 @@ discard block |
||
74 | 74 | { |
75 | 75 | // OK HERE KEY IS VALID |
76 | 76 | |
77 | - $sql ="SELECT login"; |
|
78 | - $sql.=" FROM ".MAIN_DB_PREFIX."user"; |
|
79 | - $sql.=" WHERE openid = '".$db->escape($_GET['openid_identity'])."'"; |
|
80 | - $sql.=" AND entity IN (0," . ($_SESSION["dol_entity"] ? $_SESSION["dol_entity"] : 1) . ")"; |
|
77 | + $sql = "SELECT login"; |
|
78 | + $sql .= " FROM ".MAIN_DB_PREFIX."user"; |
|
79 | + $sql .= " WHERE openid = '".$db->escape($_GET['openid_identity'])."'"; |
|
80 | + $sql .= " AND entity IN (0,".($_SESSION["dol_entity"] ? $_SESSION["dol_entity"] : 1).")"; |
|
81 | 81 | |
82 | 82 | dol_syslog("functions_openid::check_user_password_openid", LOG_DEBUG); |
83 | - $resql=$db->query($sql); |
|
83 | + $resql = $db->query($sql); |
|
84 | 84 | if ($resql) |
85 | 85 | { |
86 | - $obj=$db->fetch_object($resql); |
|
86 | + $obj = $db->fetch_object($resql); |
|
87 | 87 | if ($obj) |
88 | 88 | { |
89 | - $login=$obj->login; |
|
89 | + $login = $obj->login; |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | - else if($openid->IsError() === true) |
|
93 | + else if ($openid->IsError() === true) |
|
94 | 94 | { |
95 | 95 | // ON THE WAY, WE GOT SOME ERROR |
96 | 96 | $error = $openid->GetError(); |
@@ -56,8 +56,7 @@ discard block |
||
56 | 56 | { |
57 | 57 | $openid->SetApprovedURL($protocol . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"]); // Send Response from OpenID server to this script |
58 | 58 | $openid->Redirect(); // This will redirect user to OpenID Server |
59 | - } |
|
60 | - else |
|
59 | + } else |
|
61 | 60 | { |
62 | 61 | $error = $openid->GetError(); |
63 | 62 | return false; |
@@ -89,21 +88,18 @@ discard block |
||
89 | 88 | $login=$obj->login; |
90 | 89 | } |
91 | 90 | } |
92 | - } |
|
93 | - else if($openid->IsError() === true) |
|
91 | + } else if($openid->IsError() === true) |
|
94 | 92 | { |
95 | 93 | // ON THE WAY, WE GOT SOME ERROR |
96 | 94 | $error = $openid->GetError(); |
97 | 95 | return false; |
98 | - } |
|
99 | - else |
|
96 | + } else |
|
100 | 97 | { |
101 | 98 | // Signature Verification Failed |
102 | 99 | //echo "INVALID AUTHORIZATION"; |
103 | 100 | return false; |
104 | 101 | } |
105 | - } |
|
106 | - else if ($_GET['openid_mode'] == 'cancel') |
|
102 | + } else if ($_GET['openid_mode'] == 'cancel') |
|
107 | 103 | { |
108 | 104 | // User Canceled your Request |
109 | 105 | //echo "USER CANCELED REQUEST"; |
@@ -34,16 +34,16 @@ |
||
34 | 34 | */ |
35 | 35 | function check_user_password_forceuser($usertotest,$passwordtotest,$entitytotest) |
36 | 36 | { |
37 | - // Variable dolibarr_auto_user must be defined in conf.php file |
|
38 | - global $dolibarr_auto_user; |
|
37 | + // Variable dolibarr_auto_user must be defined in conf.php file |
|
38 | + global $dolibarr_auto_user; |
|
39 | 39 | |
40 | - dol_syslog("functions_forceuser::check_user_password_forceuser"); |
|
40 | + dol_syslog("functions_forceuser::check_user_password_forceuser"); |
|
41 | 41 | |
42 | - $login=$dolibarr_auto_user; |
|
43 | - if (empty($login)) $login='auto'; |
|
42 | + $login=$dolibarr_auto_user; |
|
43 | + if (empty($login)) $login='auto'; |
|
44 | 44 | |
45 | - if ($_SESSION["dol_loginmesg"]) $login=''; |
|
45 | + if ($_SESSION["dol_loginmesg"]) $login=''; |
|
46 | 46 | |
47 | - dol_syslog("functions_forceuser::check_user_password_forceuser ok. forced user = ".$login); |
|
48 | - return $login; |
|
47 | + dol_syslog("functions_forceuser::check_user_password_forceuser ok. forced user = ".$login); |
|
48 | + return $login; |
|
49 | 49 | } |
@@ -32,17 +32,17 @@ |
||
32 | 32 | * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) |
33 | 33 | * @return string Login if OK, '' if KO |
34 | 34 | */ |
35 | -function check_user_password_forceuser($usertotest,$passwordtotest,$entitytotest) |
|
35 | +function check_user_password_forceuser($usertotest, $passwordtotest, $entitytotest) |
|
36 | 36 | { |
37 | 37 | // Variable dolibarr_auto_user must be defined in conf.php file |
38 | 38 | global $dolibarr_auto_user; |
39 | 39 | |
40 | 40 | dol_syslog("functions_forceuser::check_user_password_forceuser"); |
41 | 41 | |
42 | - $login=$dolibarr_auto_user; |
|
43 | - if (empty($login)) $login='auto'; |
|
42 | + $login = $dolibarr_auto_user; |
|
43 | + if (empty($login)) $login = 'auto'; |
|
44 | 44 | |
45 | - if ($_SESSION["dol_loginmesg"]) $login=''; |
|
45 | + if ($_SESSION["dol_loginmesg"]) $login = ''; |
|
46 | 46 | |
47 | 47 | dol_syslog("functions_forceuser::check_user_password_forceuser ok. forced user = ".$login); |
48 | 48 | return $login; |
@@ -40,9 +40,13 @@ |
||
40 | 40 | dol_syslog("functions_forceuser::check_user_password_forceuser"); |
41 | 41 | |
42 | 42 | $login=$dolibarr_auto_user; |
43 | - if (empty($login)) $login='auto'; |
|
43 | + if (empty($login)) { |
|
44 | + $login='auto'; |
|
45 | + } |
|
44 | 46 | |
45 | - if ($_SESSION["dol_loginmesg"]) $login=''; |
|
47 | + if ($_SESSION["dol_loginmesg"]) { |
|
48 | + $login=''; |
|
49 | + } |
|
46 | 50 | |
47 | 51 | dol_syslog("functions_forceuser::check_user_password_forceuser ok. forced user = ".$login); |
48 | 52 | return $login; |
@@ -35,124 +35,124 @@ |
||
35 | 35 | */ |
36 | 36 | function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest=1) |
37 | 37 | { |
38 | - global $db,$conf,$langs; |
|
39 | - |
|
40 | - // Force master entity in transversal mode |
|
41 | - $entity=$entitytotest; |
|
42 | - if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; |
|
43 | - |
|
44 | - $login=''; |
|
45 | - |
|
46 | - if (! empty($usertotest)) |
|
47 | - { |
|
48 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest." passwordtotest=".preg_replace('/./','*',$passwordtotest)." entitytotest=".$entitytotest); |
|
49 | - |
|
50 | - // If test username/password asked, we define $test=false if ko and $login var to login if ok, set also $_SESSION["dol_loginmesg"] if ko |
|
51 | - $table = MAIN_DB_PREFIX."user"; |
|
52 | - $usernamecol1 = 'login'; |
|
53 | - $usernamecol2 = 'email'; |
|
54 | - $entitycol = 'entity'; |
|
55 | - |
|
56 | - $sql ='SELECT rowid, login, entity, pass, pass_crypted'; |
|
57 | - $sql.=' FROM '.$table; |
|
58 | - $sql.=' WHERE ('.$usernamecol1." = '".$db->escape($usertotest)."'"; |
|
59 | - if (preg_match('/@/',$usertotest)) $sql.=' OR '.$usernamecol2." = '".$db->escape($usertotest)."'"; |
|
60 | - $sql.=') AND '.$entitycol." IN (0," . ($entity ? $entity : 1) . ")"; |
|
61 | - $sql.=' AND statut = 1'; |
|
62 | - // Required to first found the user into entity, then the superadmin. |
|
63 | - // For the case (TODO and that we must avoid) a user has renamed its login with same value than a user in entity 0. |
|
64 | - $sql.=' ORDER BY entity DESC'; |
|
65 | - |
|
66 | - $resql=$db->query($sql); |
|
67 | - if ($resql) |
|
68 | - { |
|
69 | - $obj=$db->fetch_object($resql); |
|
70 | - if ($obj) |
|
71 | - { |
|
72 | - $passclear=$obj->pass; |
|
73 | - $passcrypted=$obj->pass_crypted; |
|
74 | - $passtyped=$passwordtotest; |
|
75 | - |
|
76 | - $passok=false; |
|
77 | - |
|
78 | - // Check crypted password |
|
79 | - $cryptType=''; |
|
80 | - if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) $cryptType=$conf->global->DATABASE_PWD_ENCRYPTED; |
|
81 | - |
|
82 | - // By default, we used MD5 |
|
83 | - if (! in_array($cryptType,array('md5'))) $cryptType='md5'; |
|
84 | - // Check crypted password according to crypt algorithm |
|
85 | - if ($cryptType == 'md5') |
|
86 | - { |
|
87 | - if (dol_verifyHash($passtyped, $passcrypted)) |
|
88 | - { |
|
89 | - $passok=true; |
|
90 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - ".$cryptType." of pass is ok"); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - // For compatibility with old versions |
|
95 | - if (! $passok) |
|
96 | - { |
|
97 | - if ((! $passcrypted || $passtyped) |
|
98 | - && ($passclear && ($passtyped == $passclear))) |
|
99 | - { |
|
100 | - $passok=true; |
|
101 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - found pass in database"); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - // Password ok ? |
|
106 | - if ($passok) |
|
107 | - { |
|
108 | - $login=$obj->login; |
|
109 | - } |
|
110 | - else |
|
111 | - { |
|
112 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko bad password for '".$usertotest."'"); |
|
113 | - sleep(2); // Anti brut force protection |
|
114 | - |
|
115 | - // Load translation files required by the page |
|
38 | + global $db,$conf,$langs; |
|
39 | + |
|
40 | + // Force master entity in transversal mode |
|
41 | + $entity=$entitytotest; |
|
42 | + if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; |
|
43 | + |
|
44 | + $login=''; |
|
45 | + |
|
46 | + if (! empty($usertotest)) |
|
47 | + { |
|
48 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest." passwordtotest=".preg_replace('/./','*',$passwordtotest)." entitytotest=".$entitytotest); |
|
49 | + |
|
50 | + // If test username/password asked, we define $test=false if ko and $login var to login if ok, set also $_SESSION["dol_loginmesg"] if ko |
|
51 | + $table = MAIN_DB_PREFIX."user"; |
|
52 | + $usernamecol1 = 'login'; |
|
53 | + $usernamecol2 = 'email'; |
|
54 | + $entitycol = 'entity'; |
|
55 | + |
|
56 | + $sql ='SELECT rowid, login, entity, pass, pass_crypted'; |
|
57 | + $sql.=' FROM '.$table; |
|
58 | + $sql.=' WHERE ('.$usernamecol1." = '".$db->escape($usertotest)."'"; |
|
59 | + if (preg_match('/@/',$usertotest)) $sql.=' OR '.$usernamecol2." = '".$db->escape($usertotest)."'"; |
|
60 | + $sql.=') AND '.$entitycol." IN (0," . ($entity ? $entity : 1) . ")"; |
|
61 | + $sql.=' AND statut = 1'; |
|
62 | + // Required to first found the user into entity, then the superadmin. |
|
63 | + // For the case (TODO and that we must avoid) a user has renamed its login with same value than a user in entity 0. |
|
64 | + $sql.=' ORDER BY entity DESC'; |
|
65 | + |
|
66 | + $resql=$db->query($sql); |
|
67 | + if ($resql) |
|
68 | + { |
|
69 | + $obj=$db->fetch_object($resql); |
|
70 | + if ($obj) |
|
71 | + { |
|
72 | + $passclear=$obj->pass; |
|
73 | + $passcrypted=$obj->pass_crypted; |
|
74 | + $passtyped=$passwordtotest; |
|
75 | + |
|
76 | + $passok=false; |
|
77 | + |
|
78 | + // Check crypted password |
|
79 | + $cryptType=''; |
|
80 | + if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) $cryptType=$conf->global->DATABASE_PWD_ENCRYPTED; |
|
81 | + |
|
82 | + // By default, we used MD5 |
|
83 | + if (! in_array($cryptType,array('md5'))) $cryptType='md5'; |
|
84 | + // Check crypted password according to crypt algorithm |
|
85 | + if ($cryptType == 'md5') |
|
86 | + { |
|
87 | + if (dol_verifyHash($passtyped, $passcrypted)) |
|
88 | + { |
|
89 | + $passok=true; |
|
90 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - ".$cryptType." of pass is ok"); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + // For compatibility with old versions |
|
95 | + if (! $passok) |
|
96 | + { |
|
97 | + if ((! $passcrypted || $passtyped) |
|
98 | + && ($passclear && ($passtyped == $passclear))) |
|
99 | + { |
|
100 | + $passok=true; |
|
101 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - found pass in database"); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + // Password ok ? |
|
106 | + if ($passok) |
|
107 | + { |
|
108 | + $login=$obj->login; |
|
109 | + } |
|
110 | + else |
|
111 | + { |
|
112 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko bad password for '".$usertotest."'"); |
|
113 | + sleep(2); // Anti brut force protection |
|
114 | + |
|
115 | + // Load translation files required by the page |
|
116 | 116 | $langs->loadLangs(array('main', 'errors')); |
117 | 117 | |
118 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
119 | - } |
|
120 | - |
|
121 | - // We must check entity |
|
122 | - if ($passok && ! empty($conf->multicompany->enabled)) // We must check entity |
|
123 | - { |
|
124 | - global $mc; |
|
125 | - |
|
126 | - if (! isset($mc)) $conf->multicompany->enabled = false; // Global not available, disable $conf->multicompany->enabled for safety |
|
127 | - else |
|
128 | - { |
|
129 | - $ret = $mc->checkRight($obj->rowid, $entitytotest); |
|
130 | - if ($ret < 0) |
|
131 | - { |
|
132 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko entity '" . $entitytotest . "' not allowed for user '" . $obj->rowid . "'"); |
|
133 | - $login = ''; // force authentication failure |
|
134 | - } |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - else |
|
139 | - { |
|
140 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko user not found for '".$usertotest."'"); |
|
141 | - sleep(1); |
|
142 | - |
|
143 | - // Load translation files required by the page |
|
118 | + $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
119 | + } |
|
120 | + |
|
121 | + // We must check entity |
|
122 | + if ($passok && ! empty($conf->multicompany->enabled)) // We must check entity |
|
123 | + { |
|
124 | + global $mc; |
|
125 | + |
|
126 | + if (! isset($mc)) $conf->multicompany->enabled = false; // Global not available, disable $conf->multicompany->enabled for safety |
|
127 | + else |
|
128 | + { |
|
129 | + $ret = $mc->checkRight($obj->rowid, $entitytotest); |
|
130 | + if ($ret < 0) |
|
131 | + { |
|
132 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko entity '" . $entitytotest . "' not allowed for user '" . $obj->rowid . "'"); |
|
133 | + $login = ''; // force authentication failure |
|
134 | + } |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + else |
|
139 | + { |
|
140 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko user not found for '".$usertotest."'"); |
|
141 | + sleep(1); |
|
142 | + |
|
143 | + // Load translation files required by the page |
|
144 | 144 | $langs->loadLangs(array('main', 'errors')); |
145 | 145 | |
146 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
147 | - } |
|
148 | - } |
|
149 | - else |
|
150 | - { |
|
151 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko db error for '".$usertotest."' error=".$db->lasterror()); |
|
152 | - sleep(1); |
|
153 | - $_SESSION["dol_loginmesg"]=$db->lasterror(); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - return $login; |
|
146 | + $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
147 | + } |
|
148 | + } |
|
149 | + else |
|
150 | + { |
|
151 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko db error for '".$usertotest."' error=".$db->lasterror()); |
|
152 | + sleep(1); |
|
153 | + $_SESSION["dol_loginmesg"]=$db->lasterror(); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + return $login; |
|
158 | 158 | } |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) |
34 | 34 | * @return string Login if OK, '' if KO |
35 | 35 | */ |
36 | -function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest=1) |
|
36 | +function check_user_password_dolibarr($usertotest, $passwordtotest, $entitytotest = 1) |
|
37 | 37 | { |
38 | - global $db,$conf,$langs; |
|
38 | + global $db, $conf, $langs; |
|
39 | 39 | |
40 | 40 | // Force master entity in transversal mode |
41 | - $entity=$entitytotest; |
|
42 | - if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; |
|
41 | + $entity = $entitytotest; |
|
42 | + if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity = 1; |
|
43 | 43 | |
44 | - $login=''; |
|
44 | + $login = ''; |
|
45 | 45 | |
46 | - if (! empty($usertotest)) |
|
46 | + if (!empty($usertotest)) |
|
47 | 47 | { |
48 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest." passwordtotest=".preg_replace('/./','*',$passwordtotest)." entitytotest=".$entitytotest); |
|
48 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest." passwordtotest=".preg_replace('/./', '*', $passwordtotest)." entitytotest=".$entitytotest); |
|
49 | 49 | |
50 | 50 | // If test username/password asked, we define $test=false if ko and $login var to login if ok, set also $_SESSION["dol_loginmesg"] if ko |
51 | 51 | $table = MAIN_DB_PREFIX."user"; |
@@ -53,51 +53,51 @@ discard block |
||
53 | 53 | $usernamecol2 = 'email'; |
54 | 54 | $entitycol = 'entity'; |
55 | 55 | |
56 | - $sql ='SELECT rowid, login, entity, pass, pass_crypted'; |
|
57 | - $sql.=' FROM '.$table; |
|
58 | - $sql.=' WHERE ('.$usernamecol1." = '".$db->escape($usertotest)."'"; |
|
59 | - if (preg_match('/@/',$usertotest)) $sql.=' OR '.$usernamecol2." = '".$db->escape($usertotest)."'"; |
|
60 | - $sql.=') AND '.$entitycol." IN (0," . ($entity ? $entity : 1) . ")"; |
|
61 | - $sql.=' AND statut = 1'; |
|
56 | + $sql = 'SELECT rowid, login, entity, pass, pass_crypted'; |
|
57 | + $sql .= ' FROM '.$table; |
|
58 | + $sql .= ' WHERE ('.$usernamecol1." = '".$db->escape($usertotest)."'"; |
|
59 | + if (preg_match('/@/', $usertotest)) $sql .= ' OR '.$usernamecol2." = '".$db->escape($usertotest)."'"; |
|
60 | + $sql .= ') AND '.$entitycol." IN (0,".($entity ? $entity : 1).")"; |
|
61 | + $sql .= ' AND statut = 1'; |
|
62 | 62 | // Required to first found the user into entity, then the superadmin. |
63 | 63 | // For the case (TODO and that we must avoid) a user has renamed its login with same value than a user in entity 0. |
64 | - $sql.=' ORDER BY entity DESC'; |
|
64 | + $sql .= ' ORDER BY entity DESC'; |
|
65 | 65 | |
66 | - $resql=$db->query($sql); |
|
66 | + $resql = $db->query($sql); |
|
67 | 67 | if ($resql) |
68 | 68 | { |
69 | - $obj=$db->fetch_object($resql); |
|
69 | + $obj = $db->fetch_object($resql); |
|
70 | 70 | if ($obj) |
71 | 71 | { |
72 | - $passclear=$obj->pass; |
|
73 | - $passcrypted=$obj->pass_crypted; |
|
74 | - $passtyped=$passwordtotest; |
|
72 | + $passclear = $obj->pass; |
|
73 | + $passcrypted = $obj->pass_crypted; |
|
74 | + $passtyped = $passwordtotest; |
|
75 | 75 | |
76 | - $passok=false; |
|
76 | + $passok = false; |
|
77 | 77 | |
78 | 78 | // Check crypted password |
79 | - $cryptType=''; |
|
80 | - if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) $cryptType=$conf->global->DATABASE_PWD_ENCRYPTED; |
|
79 | + $cryptType = ''; |
|
80 | + if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) $cryptType = $conf->global->DATABASE_PWD_ENCRYPTED; |
|
81 | 81 | |
82 | 82 | // By default, we used MD5 |
83 | - if (! in_array($cryptType,array('md5'))) $cryptType='md5'; |
|
83 | + if (!in_array($cryptType, array('md5'))) $cryptType = 'md5'; |
|
84 | 84 | // Check crypted password according to crypt algorithm |
85 | 85 | if ($cryptType == 'md5') |
86 | 86 | { |
87 | 87 | if (dol_verifyHash($passtyped, $passcrypted)) |
88 | 88 | { |
89 | - $passok=true; |
|
89 | + $passok = true; |
|
90 | 90 | dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - ".$cryptType." of pass is ok"); |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | // For compatibility with old versions |
95 | - if (! $passok) |
|
95 | + if (!$passok) |
|
96 | 96 | { |
97 | - if ((! $passcrypted || $passtyped) |
|
97 | + if ((!$passcrypted || $passtyped) |
|
98 | 98 | && ($passclear && ($passtyped == $passclear))) |
99 | 99 | { |
100 | - $passok=true; |
|
100 | + $passok = true; |
|
101 | 101 | dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - found pass in database"); |
102 | 102 | } |
103 | 103 | } |
@@ -105,31 +105,31 @@ discard block |
||
105 | 105 | // Password ok ? |
106 | 106 | if ($passok) |
107 | 107 | { |
108 | - $login=$obj->login; |
|
108 | + $login = $obj->login; |
|
109 | 109 | } |
110 | 110 | else |
111 | 111 | { |
112 | 112 | dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko bad password for '".$usertotest."'"); |
113 | - sleep(2); // Anti brut force protection |
|
113 | + sleep(2); // Anti brut force protection |
|
114 | 114 | |
115 | 115 | // Load translation files required by the page |
116 | 116 | $langs->loadLangs(array('main', 'errors')); |
117 | 117 | |
118 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
118 | + $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword"); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | // We must check entity |
122 | - if ($passok && ! empty($conf->multicompany->enabled)) // We must check entity |
|
122 | + if ($passok && !empty($conf->multicompany->enabled)) // We must check entity |
|
123 | 123 | { |
124 | 124 | global $mc; |
125 | 125 | |
126 | - if (! isset($mc)) $conf->multicompany->enabled = false; // Global not available, disable $conf->multicompany->enabled for safety |
|
126 | + if (!isset($mc)) $conf->multicompany->enabled = false; // Global not available, disable $conf->multicompany->enabled for safety |
|
127 | 127 | else |
128 | 128 | { |
129 | 129 | $ret = $mc->checkRight($obj->rowid, $entitytotest); |
130 | 130 | if ($ret < 0) |
131 | 131 | { |
132 | - dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko entity '" . $entitytotest . "' not allowed for user '" . $obj->rowid . "'"); |
|
132 | + dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko entity '".$entitytotest."' not allowed for user '".$obj->rowid."'"); |
|
133 | 133 | $login = ''; // force authentication failure |
134 | 134 | } |
135 | 135 | } |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | // Load translation files required by the page |
144 | 144 | $langs->loadLangs(array('main', 'errors')); |
145 | 145 | |
146 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
146 | + $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword"); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | else |
150 | 150 | { |
151 | 151 | dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko db error for '".$usertotest."' error=".$db->lasterror()); |
152 | 152 | sleep(1); |
153 | - $_SESSION["dol_loginmesg"]=$db->lasterror(); |
|
153 | + $_SESSION["dol_loginmesg"] = $db->lasterror(); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 |
@@ -39,7 +39,9 @@ discard block |
||
39 | 39 | |
40 | 40 | // Force master entity in transversal mode |
41 | 41 | $entity=$entitytotest; |
42 | - if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; |
|
42 | + if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
43 | + $entity=1; |
|
44 | + } |
|
43 | 45 | |
44 | 46 | $login=''; |
45 | 47 | |
@@ -56,7 +58,9 @@ discard block |
||
56 | 58 | $sql ='SELECT rowid, login, entity, pass, pass_crypted'; |
57 | 59 | $sql.=' FROM '.$table; |
58 | 60 | $sql.=' WHERE ('.$usernamecol1." = '".$db->escape($usertotest)."'"; |
59 | - if (preg_match('/@/',$usertotest)) $sql.=' OR '.$usernamecol2." = '".$db->escape($usertotest)."'"; |
|
61 | + if (preg_match('/@/',$usertotest)) { |
|
62 | + $sql.=' OR '.$usernamecol2." = '".$db->escape($usertotest)."'"; |
|
63 | + } |
|
60 | 64 | $sql.=') AND '.$entitycol." IN (0," . ($entity ? $entity : 1) . ")"; |
61 | 65 | $sql.=' AND statut = 1'; |
62 | 66 | // Required to first found the user into entity, then the superadmin. |
@@ -77,10 +81,14 @@ discard block |
||
77 | 81 | |
78 | 82 | // Check crypted password |
79 | 83 | $cryptType=''; |
80 | - if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) $cryptType=$conf->global->DATABASE_PWD_ENCRYPTED; |
|
84 | + if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) { |
|
85 | + $cryptType=$conf->global->DATABASE_PWD_ENCRYPTED; |
|
86 | + } |
|
81 | 87 | |
82 | 88 | // By default, we used MD5 |
83 | - if (! in_array($cryptType,array('md5'))) $cryptType='md5'; |
|
89 | + if (! in_array($cryptType,array('md5'))) { |
|
90 | + $cryptType='md5'; |
|
91 | + } |
|
84 | 92 | // Check crypted password according to crypt algorithm |
85 | 93 | if ($cryptType == 'md5') |
86 | 94 | { |
@@ -106,8 +114,7 @@ discard block |
||
106 | 114 | if ($passok) |
107 | 115 | { |
108 | 116 | $login=$obj->login; |
109 | - } |
|
110 | - else |
|
117 | + } else |
|
111 | 118 | { |
112 | 119 | dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko bad password for '".$usertotest."'"); |
113 | 120 | sleep(2); // Anti brut force protection |
@@ -119,11 +126,16 @@ discard block |
||
119 | 126 | } |
120 | 127 | |
121 | 128 | // We must check entity |
122 | - if ($passok && ! empty($conf->multicompany->enabled)) // We must check entity |
|
129 | + if ($passok && ! empty($conf->multicompany->enabled)) { |
|
130 | + // We must check entity |
|
123 | 131 | { |
124 | 132 | global $mc; |
133 | + } |
|
125 | 134 | |
126 | - if (! isset($mc)) $conf->multicompany->enabled = false; // Global not available, disable $conf->multicompany->enabled for safety |
|
135 | + if (! isset($mc)) { |
|
136 | + $conf->multicompany->enabled = false; |
|
137 | + } |
|
138 | + // Global not available, disable $conf->multicompany->enabled for safety |
|
127 | 139 | else |
128 | 140 | { |
129 | 141 | $ret = $mc->checkRight($obj->rowid, $entitytotest); |
@@ -134,8 +146,7 @@ discard block |
||
134 | 146 | } |
135 | 147 | } |
136 | 148 | } |
137 | - } |
|
138 | - else |
|
149 | + } else |
|
139 | 150 | { |
140 | 151 | dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko user not found for '".$usertotest."'"); |
141 | 152 | sleep(1); |
@@ -145,8 +156,7 @@ discard block |
||
145 | 156 | |
146 | 157 | $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
147 | 158 | } |
148 | - } |
|
149 | - else |
|
159 | + } else |
|
150 | 160 | { |
151 | 161 | dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ko db error for '".$usertotest."' error=".$db->lasterror()); |
152 | 162 | sleep(1); |
@@ -33,13 +33,13 @@ |
||
33 | 33 | */ |
34 | 34 | function check_user_password_http($usertotest,$passwordtotest,$entitytotest) |
35 | 35 | { |
36 | - dol_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=".(empty($_SERVER["REMOTE_USER"])?'':$_SERVER["REMOTE_USER"])); |
|
36 | + dol_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=".(empty($_SERVER["REMOTE_USER"])?'':$_SERVER["REMOTE_USER"])); |
|
37 | 37 | |
38 | - $login=''; |
|
39 | - if (! empty($_SERVER["REMOTE_USER"])) |
|
40 | - { |
|
41 | - $login=$_SERVER["REMOTE_USER"]; |
|
42 | - } |
|
38 | + $login=''; |
|
39 | + if (! empty($_SERVER["REMOTE_USER"])) |
|
40 | + { |
|
41 | + $login=$_SERVER["REMOTE_USER"]; |
|
42 | + } |
|
43 | 43 | |
44 | - return $login; |
|
44 | + return $login; |
|
45 | 45 | } |
@@ -31,14 +31,14 @@ |
||
31 | 31 | * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) |
32 | 32 | * @return string Login if OK, '' if KO |
33 | 33 | */ |
34 | -function check_user_password_http($usertotest,$passwordtotest,$entitytotest) |
|
34 | +function check_user_password_http($usertotest, $passwordtotest, $entitytotest) |
|
35 | 35 | { |
36 | - dol_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=".(empty($_SERVER["REMOTE_USER"])?'':$_SERVER["REMOTE_USER"])); |
|
36 | + dol_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=".(empty($_SERVER["REMOTE_USER"]) ? '' : $_SERVER["REMOTE_USER"])); |
|
37 | 37 | |
38 | - $login=''; |
|
39 | - if (! empty($_SERVER["REMOTE_USER"])) |
|
38 | + $login = ''; |
|
39 | + if (!empty($_SERVER["REMOTE_USER"])) |
|
40 | 40 | { |
41 | - $login=$_SERVER["REMOTE_USER"]; |
|
41 | + $login = $_SERVER["REMOTE_USER"]; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | return $login; |
@@ -34,190 +34,190 @@ discard block |
||
34 | 34 | */ |
35 | 35 | function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest) |
36 | 36 | { |
37 | - global $db,$conf,$langs; |
|
38 | - global $_POST; |
|
39 | - global $dolibarr_main_auth_ldap_host,$dolibarr_main_auth_ldap_port; |
|
40 | - global $dolibarr_main_auth_ldap_version,$dolibarr_main_auth_ldap_servertype; |
|
41 | - global $dolibarr_main_auth_ldap_login_attribute,$dolibarr_main_auth_ldap_dn; |
|
42 | - global $dolibarr_main_auth_ldap_admin_login,$dolibarr_main_auth_ldap_admin_pass; |
|
43 | - global $dolibarr_main_auth_ldap_filter; |
|
44 | - global $dolibarr_main_auth_ldap_debug; |
|
45 | - |
|
46 | - // Force master entity in transversal mode |
|
47 | - $entity=$entitytotest; |
|
48 | - if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; |
|
49 | - |
|
50 | - $login=''; |
|
51 | - $resultFetchUser=''; |
|
52 | - |
|
53 | - if (! function_exists("ldap_connect")) |
|
54 | - { |
|
55 | - dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP. LDAP functions are disabled on this PHP"); |
|
56 | - sleep(1); |
|
57 | - |
|
58 | - // Load translation files required by the page |
|
37 | + global $db,$conf,$langs; |
|
38 | + global $_POST; |
|
39 | + global $dolibarr_main_auth_ldap_host,$dolibarr_main_auth_ldap_port; |
|
40 | + global $dolibarr_main_auth_ldap_version,$dolibarr_main_auth_ldap_servertype; |
|
41 | + global $dolibarr_main_auth_ldap_login_attribute,$dolibarr_main_auth_ldap_dn; |
|
42 | + global $dolibarr_main_auth_ldap_admin_login,$dolibarr_main_auth_ldap_admin_pass; |
|
43 | + global $dolibarr_main_auth_ldap_filter; |
|
44 | + global $dolibarr_main_auth_ldap_debug; |
|
45 | + |
|
46 | + // Force master entity in transversal mode |
|
47 | + $entity=$entitytotest; |
|
48 | + if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; |
|
49 | + |
|
50 | + $login=''; |
|
51 | + $resultFetchUser=''; |
|
52 | + |
|
53 | + if (! function_exists("ldap_connect")) |
|
54 | + { |
|
55 | + dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP. LDAP functions are disabled on this PHP"); |
|
56 | + sleep(1); |
|
57 | + |
|
58 | + // Load translation files required by the page |
|
59 | 59 | $langs->loadLangs(array('main', 'other')); |
60 | 60 | |
61 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorLDAPFunctionsAreDisabledOnThisPHP").' '.$langs->trans("TryAnotherConnectionMode"); |
|
62 | - return; |
|
63 | - } |
|
64 | - |
|
65 | - if ($usertotest) |
|
66 | - { |
|
67 | - dol_syslog("functions_ldap::check_user_password_ldap usertotest=".$usertotest." passwordtotest=".preg_replace('/./','*',$passwordtotest)." entitytotest=".$entitytotest); |
|
68 | - |
|
69 | - // If test username/password asked, we define $test=false and $login var if ok, set $_SESSION["dol_loginmesg"] if ko |
|
70 | - $ldaphost=$dolibarr_main_auth_ldap_host; |
|
71 | - $ldapport=$dolibarr_main_auth_ldap_port; |
|
72 | - $ldapversion=$dolibarr_main_auth_ldap_version; |
|
73 | - $ldapservertype=(empty($dolibarr_main_auth_ldap_servertype) ? 'openldap' : $dolibarr_main_auth_ldap_servertype); |
|
74 | - |
|
75 | - $ldapuserattr=$dolibarr_main_auth_ldap_login_attribute; |
|
76 | - $ldapdn=$dolibarr_main_auth_ldap_dn; |
|
77 | - $ldapadminlogin=$dolibarr_main_auth_ldap_admin_login; |
|
78 | - $ldapadminpass=$dolibarr_main_auth_ldap_admin_pass; |
|
79 | - $ldapdebug=(empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug=="false" ? false : true); |
|
80 | - |
|
81 | - if ($ldapdebug) print "DEBUG: Logging LDAP steps<br>\n"; |
|
82 | - |
|
83 | - require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; |
|
84 | - $ldap=new Ldap(); |
|
85 | - $ldap->server=explode(',',$ldaphost); |
|
86 | - $ldap->serverPort=$ldapport; |
|
87 | - $ldap->ldapProtocolVersion=$ldapversion; |
|
88 | - $ldap->serverType=$ldapservertype; |
|
89 | - $ldap->searchUser=$ldapadminlogin; |
|
90 | - $ldap->searchPassword=$ldapadminpass; |
|
91 | - |
|
92 | - if ($ldapdebug) |
|
93 | - { |
|
94 | - dol_syslog("functions_ldap::check_user_password_ldap Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType); |
|
95 | - dol_syslog("functions_ldap::check_user_password_ldap uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword); |
|
96 | - print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."<br>\n"; |
|
97 | - print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."<br>\n"; |
|
98 | - } |
|
99 | - |
|
100 | - $resultFetchLdapUser=0; |
|
101 | - |
|
102 | - // Define $userSearchFilter |
|
103 | - $userSearchFilter = ""; |
|
104 | - if (empty($dolibarr_main_auth_ldap_filter)) { |
|
105 | - $userSearchFilter = "(" . $ldapuserattr . "=" . $usertotest . ")"; |
|
106 | - } else { |
|
107 | - $userSearchFilter = str_replace('%1%', $usertotest, $dolibarr_main_auth_ldap_filter); |
|
108 | - } |
|
109 | - |
|
110 | - // If admin login provided |
|
111 | - // Code to get user in LDAP from an admin connection (may differ from user connection, done later) |
|
112 | - if ($ldapadminlogin) |
|
113 | - { |
|
114 | - $result=$ldap->connect_bind(); |
|
115 | - if ($result > 0) |
|
116 | - { |
|
117 | - $resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter); |
|
118 | - //dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser); |
|
119 | - if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) // If ok but password need to be reset |
|
120 | - { |
|
121 | - dol_syslog('functions_ldap::check_user_password_ldap '.$usertotest.' must change password next logon'); |
|
122 | - if ($ldapdebug) print "DEBUG: User ".$usertotest." must change password<br>\n"; |
|
123 | - $ldap->close(); |
|
124 | - sleep(1); |
|
125 | - $langs->load('ldap'); |
|
126 | - $_SESSION["dol_loginmesg"]=$langs->trans("YouMustChangePassNextLogon",$usertotest,$ldap->domainFQDN); |
|
127 | - return ''; |
|
128 | - } |
|
129 | - } |
|
130 | - else |
|
131 | - { |
|
132 | - if ($ldapdebug) print "DEBUG: ".$ldap->error."<br>\n"; |
|
133 | - } |
|
134 | - $ldap->close(); |
|
135 | - } |
|
136 | - |
|
137 | - // Forge LDAP user and password to test with them |
|
138 | - // If LDAP need a dn with login like "uid=jbloggs,ou=People,dc=foo,dc=com", default dn may work even if previous code with |
|
139 | - // admin login no exectued. |
|
140 | - $ldap->searchUser=$ldapuserattr."=".$usertotest.",".$ldapdn; // Default dn (will work if LDAP accept a dn with login value inside) |
|
141 | - // But if LDAP need a dn with name like "cn=Jhon Bloggs,ou=People,dc=foo,dc=com", previous part must have been executed to have |
|
142 | - // dn detected into ldapUserDN. |
|
143 | - if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN; |
|
144 | - $ldap->searchPassword=$passwordtotest; |
|
145 | - |
|
146 | - // Test with this->seachUser and this->searchPassword |
|
147 | - //print $resultFetchLdapUser."-".$ldap->ldapUserDN."-".$ldap->searchUser.'-'.$ldap->searchPassword;exit; |
|
148 | - $result=$ldap->connect_bind(); |
|
149 | - if ($result > 0) |
|
150 | - { |
|
151 | - if ($result == 2) // Connection is ok for user/pass into LDAP |
|
152 | - { |
|
153 | - dol_syslog("functions_ldap::check_user_password_ldap Authentification ok"); |
|
154 | - $login=$usertotest; |
|
155 | - |
|
156 | - // ldap2dolibarr synchronisation |
|
157 | - if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') // ldap2dolibarr synchronisation |
|
158 | - { |
|
159 | - dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr"); |
|
160 | - |
|
161 | - // On charge les attributs du user ldap |
|
162 | - if ($ldapdebug) print "DEBUG: login ldap = ".$login."<br>\n"; |
|
163 | - $resultFetchLdapUser = $ldap->fetch($login,$userSearchFilter); |
|
164 | - |
|
165 | - if ($ldapdebug) print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n"; |
|
166 | - if ($ldapdebug) print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n"; |
|
167 | - if ($ldapdebug) print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n"; |
|
168 | - |
|
169 | - // On recherche le user dolibarr en fonction de son SID ldap |
|
170 | - $sid = $ldap->getObjectSid($login); |
|
171 | - if ($ldapdebug) print "DEBUG: sid = ".$sid."<br>\n"; |
|
172 | - |
|
173 | - $usertmp=new User($db); |
|
174 | - $resultFetchUser=$usertmp->fetch('',$login,$sid); |
|
175 | - if ($resultFetchUser > 0) |
|
176 | - { |
|
177 | - dol_syslog("functions_ldap::check_user_password_ldap Sync user found user id=".$usertmp->id); |
|
178 | - // On verifie si le login a change et on met a jour les attributs dolibarr |
|
179 | - |
|
180 | - if ($usertmp->login != $ldap->login && $ldap->login) |
|
181 | - { |
|
182 | - $usertmp->login = $ldap->login; |
|
183 | - $usertmp->update($usertmp); |
|
184 | - // TODO Que faire si update echoue car on update avec un login deja existant. |
|
185 | - } |
|
186 | - |
|
187 | - //$resultUpdate = $usertmp->update_ldap2dolibarr($ldap); |
|
188 | - } |
|
189 | - unset($usertmp); |
|
190 | - } |
|
191 | - |
|
192 | - if (! empty($conf->multicompany->enabled)) // We must check entity (even if sync is not active) |
|
193 | - { |
|
194 | - global $mc; |
|
195 | - |
|
196 | - $usertmp=new User($db); |
|
197 | - $usertmp->fetch('',$login); |
|
198 | - $ret=$mc->checkRight($usertmp->id, $entitytotest); |
|
199 | - if ($ret < 0) |
|
200 | - { |
|
201 | - dol_syslog("functions_ldap::check_user_password_ldap Authentification ko entity '".$entitytotest."' not allowed for user '".$usertmp->id."'"); |
|
202 | - $login=''; // force authentication failure |
|
203 | - } |
|
204 | - unset($usertmp); |
|
205 | - } |
|
206 | - } |
|
207 | - if ($result == 1) |
|
208 | - { |
|
209 | - dol_syslog("functions_ldap::check_user_password_ldap Authentification ko bad user/password for '".$usertotest."'"); |
|
210 | - sleep(1); |
|
211 | - |
|
212 | - // Load translation files required by the page |
|
61 | + $_SESSION["dol_loginmesg"]=$langs->trans("ErrorLDAPFunctionsAreDisabledOnThisPHP").' '.$langs->trans("TryAnotherConnectionMode"); |
|
62 | + return; |
|
63 | + } |
|
64 | + |
|
65 | + if ($usertotest) |
|
66 | + { |
|
67 | + dol_syslog("functions_ldap::check_user_password_ldap usertotest=".$usertotest." passwordtotest=".preg_replace('/./','*',$passwordtotest)." entitytotest=".$entitytotest); |
|
68 | + |
|
69 | + // If test username/password asked, we define $test=false and $login var if ok, set $_SESSION["dol_loginmesg"] if ko |
|
70 | + $ldaphost=$dolibarr_main_auth_ldap_host; |
|
71 | + $ldapport=$dolibarr_main_auth_ldap_port; |
|
72 | + $ldapversion=$dolibarr_main_auth_ldap_version; |
|
73 | + $ldapservertype=(empty($dolibarr_main_auth_ldap_servertype) ? 'openldap' : $dolibarr_main_auth_ldap_servertype); |
|
74 | + |
|
75 | + $ldapuserattr=$dolibarr_main_auth_ldap_login_attribute; |
|
76 | + $ldapdn=$dolibarr_main_auth_ldap_dn; |
|
77 | + $ldapadminlogin=$dolibarr_main_auth_ldap_admin_login; |
|
78 | + $ldapadminpass=$dolibarr_main_auth_ldap_admin_pass; |
|
79 | + $ldapdebug=(empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug=="false" ? false : true); |
|
80 | + |
|
81 | + if ($ldapdebug) print "DEBUG: Logging LDAP steps<br>\n"; |
|
82 | + |
|
83 | + require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; |
|
84 | + $ldap=new Ldap(); |
|
85 | + $ldap->server=explode(',',$ldaphost); |
|
86 | + $ldap->serverPort=$ldapport; |
|
87 | + $ldap->ldapProtocolVersion=$ldapversion; |
|
88 | + $ldap->serverType=$ldapservertype; |
|
89 | + $ldap->searchUser=$ldapadminlogin; |
|
90 | + $ldap->searchPassword=$ldapadminpass; |
|
91 | + |
|
92 | + if ($ldapdebug) |
|
93 | + { |
|
94 | + dol_syslog("functions_ldap::check_user_password_ldap Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType); |
|
95 | + dol_syslog("functions_ldap::check_user_password_ldap uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword); |
|
96 | + print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."<br>\n"; |
|
97 | + print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."<br>\n"; |
|
98 | + } |
|
99 | + |
|
100 | + $resultFetchLdapUser=0; |
|
101 | + |
|
102 | + // Define $userSearchFilter |
|
103 | + $userSearchFilter = ""; |
|
104 | + if (empty($dolibarr_main_auth_ldap_filter)) { |
|
105 | + $userSearchFilter = "(" . $ldapuserattr . "=" . $usertotest . ")"; |
|
106 | + } else { |
|
107 | + $userSearchFilter = str_replace('%1%', $usertotest, $dolibarr_main_auth_ldap_filter); |
|
108 | + } |
|
109 | + |
|
110 | + // If admin login provided |
|
111 | + // Code to get user in LDAP from an admin connection (may differ from user connection, done later) |
|
112 | + if ($ldapadminlogin) |
|
113 | + { |
|
114 | + $result=$ldap->connect_bind(); |
|
115 | + if ($result > 0) |
|
116 | + { |
|
117 | + $resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter); |
|
118 | + //dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser); |
|
119 | + if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) // If ok but password need to be reset |
|
120 | + { |
|
121 | + dol_syslog('functions_ldap::check_user_password_ldap '.$usertotest.' must change password next logon'); |
|
122 | + if ($ldapdebug) print "DEBUG: User ".$usertotest." must change password<br>\n"; |
|
123 | + $ldap->close(); |
|
124 | + sleep(1); |
|
125 | + $langs->load('ldap'); |
|
126 | + $_SESSION["dol_loginmesg"]=$langs->trans("YouMustChangePassNextLogon",$usertotest,$ldap->domainFQDN); |
|
127 | + return ''; |
|
128 | + } |
|
129 | + } |
|
130 | + else |
|
131 | + { |
|
132 | + if ($ldapdebug) print "DEBUG: ".$ldap->error."<br>\n"; |
|
133 | + } |
|
134 | + $ldap->close(); |
|
135 | + } |
|
136 | + |
|
137 | + // Forge LDAP user and password to test with them |
|
138 | + // If LDAP need a dn with login like "uid=jbloggs,ou=People,dc=foo,dc=com", default dn may work even if previous code with |
|
139 | + // admin login no exectued. |
|
140 | + $ldap->searchUser=$ldapuserattr."=".$usertotest.",".$ldapdn; // Default dn (will work if LDAP accept a dn with login value inside) |
|
141 | + // But if LDAP need a dn with name like "cn=Jhon Bloggs,ou=People,dc=foo,dc=com", previous part must have been executed to have |
|
142 | + // dn detected into ldapUserDN. |
|
143 | + if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN; |
|
144 | + $ldap->searchPassword=$passwordtotest; |
|
145 | + |
|
146 | + // Test with this->seachUser and this->searchPassword |
|
147 | + //print $resultFetchLdapUser."-".$ldap->ldapUserDN."-".$ldap->searchUser.'-'.$ldap->searchPassword;exit; |
|
148 | + $result=$ldap->connect_bind(); |
|
149 | + if ($result > 0) |
|
150 | + { |
|
151 | + if ($result == 2) // Connection is ok for user/pass into LDAP |
|
152 | + { |
|
153 | + dol_syslog("functions_ldap::check_user_password_ldap Authentification ok"); |
|
154 | + $login=$usertotest; |
|
155 | + |
|
156 | + // ldap2dolibarr synchronisation |
|
157 | + if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') // ldap2dolibarr synchronisation |
|
158 | + { |
|
159 | + dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr"); |
|
160 | + |
|
161 | + // On charge les attributs du user ldap |
|
162 | + if ($ldapdebug) print "DEBUG: login ldap = ".$login."<br>\n"; |
|
163 | + $resultFetchLdapUser = $ldap->fetch($login,$userSearchFilter); |
|
164 | + |
|
165 | + if ($ldapdebug) print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n"; |
|
166 | + if ($ldapdebug) print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n"; |
|
167 | + if ($ldapdebug) print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n"; |
|
168 | + |
|
169 | + // On recherche le user dolibarr en fonction de son SID ldap |
|
170 | + $sid = $ldap->getObjectSid($login); |
|
171 | + if ($ldapdebug) print "DEBUG: sid = ".$sid."<br>\n"; |
|
172 | + |
|
173 | + $usertmp=new User($db); |
|
174 | + $resultFetchUser=$usertmp->fetch('',$login,$sid); |
|
175 | + if ($resultFetchUser > 0) |
|
176 | + { |
|
177 | + dol_syslog("functions_ldap::check_user_password_ldap Sync user found user id=".$usertmp->id); |
|
178 | + // On verifie si le login a change et on met a jour les attributs dolibarr |
|
179 | + |
|
180 | + if ($usertmp->login != $ldap->login && $ldap->login) |
|
181 | + { |
|
182 | + $usertmp->login = $ldap->login; |
|
183 | + $usertmp->update($usertmp); |
|
184 | + // TODO Que faire si update echoue car on update avec un login deja existant. |
|
185 | + } |
|
186 | + |
|
187 | + //$resultUpdate = $usertmp->update_ldap2dolibarr($ldap); |
|
188 | + } |
|
189 | + unset($usertmp); |
|
190 | + } |
|
191 | + |
|
192 | + if (! empty($conf->multicompany->enabled)) // We must check entity (even if sync is not active) |
|
193 | + { |
|
194 | + global $mc; |
|
195 | + |
|
196 | + $usertmp=new User($db); |
|
197 | + $usertmp->fetch('',$login); |
|
198 | + $ret=$mc->checkRight($usertmp->id, $entitytotest); |
|
199 | + if ($ret < 0) |
|
200 | + { |
|
201 | + dol_syslog("functions_ldap::check_user_password_ldap Authentification ko entity '".$entitytotest."' not allowed for user '".$usertmp->id."'"); |
|
202 | + $login=''; // force authentication failure |
|
203 | + } |
|
204 | + unset($usertmp); |
|
205 | + } |
|
206 | + } |
|
207 | + if ($result == 1) |
|
208 | + { |
|
209 | + dol_syslog("functions_ldap::check_user_password_ldap Authentification ko bad user/password for '".$usertotest."'"); |
|
210 | + sleep(1); |
|
211 | + |
|
212 | + // Load translation files required by the page |
|
213 | 213 | $langs->loadLangs(array('main', 'other')); |
214 | 214 | |
215 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
216 | - } |
|
217 | - } |
|
218 | - else |
|
219 | - { |
|
220 | - /* Login failed. Return false, together with the error code and text from |
|
215 | + $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
216 | + } |
|
217 | + } |
|
218 | + else |
|
219 | + { |
|
220 | + /* Login failed. Return false, together with the error code and text from |
|
221 | 221 | ** the LDAP server. The common error codes and reasons are listed below : |
222 | 222 | ** (for iPlanet, other servers may differ) |
223 | 223 | ** 19 - Account locked out (too many invalid login attempts) |
@@ -225,24 +225,24 @@ discard block |
||
225 | 225 | ** 49 - Wrong password |
226 | 226 | ** 53 - Account inactive (manually locked out by administrator) |
227 | 227 | */ |
228 | - dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP for '".$usertotest."'"); |
|
229 | - if (is_resource($ldap->connection)) // If connection ok but bind ko |
|
230 | - { |
|
231 | - $ldap->ldapErrorCode = ldap_errno($ldap->connection); |
|
232 | - $ldap->ldapErrorText = ldap_error($ldap->connection); |
|
233 | - dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorCode." ".$ldap->ldapErrorText); |
|
234 | - } |
|
235 | - sleep(2); // Anti brut force protection |
|
236 | - |
|
237 | - // Load translation files required by the page |
|
228 | + dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP for '".$usertotest."'"); |
|
229 | + if (is_resource($ldap->connection)) // If connection ok but bind ko |
|
230 | + { |
|
231 | + $ldap->ldapErrorCode = ldap_errno($ldap->connection); |
|
232 | + $ldap->ldapErrorText = ldap_error($ldap->connection); |
|
233 | + dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorCode." ".$ldap->ldapErrorText); |
|
234 | + } |
|
235 | + sleep(2); // Anti brut force protection |
|
236 | + |
|
237 | + // Load translation files required by the page |
|
238 | 238 | $langs->loadLangs(array('main', 'other', 'errors')); |
239 | 239 | ; |
240 | - $_SESSION["dol_loginmesg"]=($ldap->error?$ldap->error:$langs->trans("ErrorBadLoginPassword")); |
|
241 | - } |
|
240 | + $_SESSION["dol_loginmesg"]=($ldap->error?$ldap->error:$langs->trans("ErrorBadLoginPassword")); |
|
241 | + } |
|
242 | 242 | |
243 | - $ldap->close(); |
|
244 | - } |
|
243 | + $ldap->close(); |
|
244 | + } |
|
245 | 245 | |
246 | - return $login; |
|
246 | + return $login; |
|
247 | 247 | } |
248 | 248 |
@@ -32,25 +32,25 @@ discard block |
||
32 | 32 | * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) |
33 | 33 | * @return string Login if OK, '' if KO |
34 | 34 | */ |
35 | -function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest) |
|
35 | +function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest) |
|
36 | 36 | { |
37 | - global $db,$conf,$langs; |
|
37 | + global $db, $conf, $langs; |
|
38 | 38 | global $_POST; |
39 | - global $dolibarr_main_auth_ldap_host,$dolibarr_main_auth_ldap_port; |
|
40 | - global $dolibarr_main_auth_ldap_version,$dolibarr_main_auth_ldap_servertype; |
|
41 | - global $dolibarr_main_auth_ldap_login_attribute,$dolibarr_main_auth_ldap_dn; |
|
42 | - global $dolibarr_main_auth_ldap_admin_login,$dolibarr_main_auth_ldap_admin_pass; |
|
39 | + global $dolibarr_main_auth_ldap_host, $dolibarr_main_auth_ldap_port; |
|
40 | + global $dolibarr_main_auth_ldap_version, $dolibarr_main_auth_ldap_servertype; |
|
41 | + global $dolibarr_main_auth_ldap_login_attribute, $dolibarr_main_auth_ldap_dn; |
|
42 | + global $dolibarr_main_auth_ldap_admin_login, $dolibarr_main_auth_ldap_admin_pass; |
|
43 | 43 | global $dolibarr_main_auth_ldap_filter; |
44 | 44 | global $dolibarr_main_auth_ldap_debug; |
45 | 45 | |
46 | 46 | // Force master entity in transversal mode |
47 | - $entity=$entitytotest; |
|
48 | - if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; |
|
47 | + $entity = $entitytotest; |
|
48 | + if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity = 1; |
|
49 | 49 | |
50 | - $login=''; |
|
51 | - $resultFetchUser=''; |
|
50 | + $login = ''; |
|
51 | + $resultFetchUser = ''; |
|
52 | 52 | |
53 | - if (! function_exists("ldap_connect")) |
|
53 | + if (!function_exists("ldap_connect")) |
|
54 | 54 | { |
55 | 55 | dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP. LDAP functions are disabled on this PHP"); |
56 | 56 | sleep(1); |
@@ -58,51 +58,51 @@ discard block |
||
58 | 58 | // Load translation files required by the page |
59 | 59 | $langs->loadLangs(array('main', 'other')); |
60 | 60 | |
61 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorLDAPFunctionsAreDisabledOnThisPHP").' '.$langs->trans("TryAnotherConnectionMode"); |
|
61 | + $_SESSION["dol_loginmesg"] = $langs->trans("ErrorLDAPFunctionsAreDisabledOnThisPHP").' '.$langs->trans("TryAnotherConnectionMode"); |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | 65 | if ($usertotest) |
66 | 66 | { |
67 | - dol_syslog("functions_ldap::check_user_password_ldap usertotest=".$usertotest." passwordtotest=".preg_replace('/./','*',$passwordtotest)." entitytotest=".$entitytotest); |
|
67 | + dol_syslog("functions_ldap::check_user_password_ldap usertotest=".$usertotest." passwordtotest=".preg_replace('/./', '*', $passwordtotest)." entitytotest=".$entitytotest); |
|
68 | 68 | |
69 | 69 | // If test username/password asked, we define $test=false and $login var if ok, set $_SESSION["dol_loginmesg"] if ko |
70 | - $ldaphost=$dolibarr_main_auth_ldap_host; |
|
71 | - $ldapport=$dolibarr_main_auth_ldap_port; |
|
72 | - $ldapversion=$dolibarr_main_auth_ldap_version; |
|
73 | - $ldapservertype=(empty($dolibarr_main_auth_ldap_servertype) ? 'openldap' : $dolibarr_main_auth_ldap_servertype); |
|
70 | + $ldaphost = $dolibarr_main_auth_ldap_host; |
|
71 | + $ldapport = $dolibarr_main_auth_ldap_port; |
|
72 | + $ldapversion = $dolibarr_main_auth_ldap_version; |
|
73 | + $ldapservertype = (empty($dolibarr_main_auth_ldap_servertype) ? 'openldap' : $dolibarr_main_auth_ldap_servertype); |
|
74 | 74 | |
75 | - $ldapuserattr=$dolibarr_main_auth_ldap_login_attribute; |
|
76 | - $ldapdn=$dolibarr_main_auth_ldap_dn; |
|
77 | - $ldapadminlogin=$dolibarr_main_auth_ldap_admin_login; |
|
78 | - $ldapadminpass=$dolibarr_main_auth_ldap_admin_pass; |
|
79 | - $ldapdebug=(empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug=="false" ? false : true); |
|
75 | + $ldapuserattr = $dolibarr_main_auth_ldap_login_attribute; |
|
76 | + $ldapdn = $dolibarr_main_auth_ldap_dn; |
|
77 | + $ldapadminlogin = $dolibarr_main_auth_ldap_admin_login; |
|
78 | + $ldapadminpass = $dolibarr_main_auth_ldap_admin_pass; |
|
79 | + $ldapdebug = (empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug == "false" ? false : true); |
|
80 | 80 | |
81 | 81 | if ($ldapdebug) print "DEBUG: Logging LDAP steps<br>\n"; |
82 | 82 | |
83 | 83 | require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; |
84 | - $ldap=new Ldap(); |
|
85 | - $ldap->server=explode(',',$ldaphost); |
|
86 | - $ldap->serverPort=$ldapport; |
|
87 | - $ldap->ldapProtocolVersion=$ldapversion; |
|
88 | - $ldap->serverType=$ldapservertype; |
|
89 | - $ldap->searchUser=$ldapadminlogin; |
|
90 | - $ldap->searchPassword=$ldapadminpass; |
|
84 | + $ldap = new Ldap(); |
|
85 | + $ldap->server = explode(',', $ldaphost); |
|
86 | + $ldap->serverPort = $ldapport; |
|
87 | + $ldap->ldapProtocolVersion = $ldapversion; |
|
88 | + $ldap->serverType = $ldapservertype; |
|
89 | + $ldap->searchUser = $ldapadminlogin; |
|
90 | + $ldap->searchPassword = $ldapadminpass; |
|
91 | 91 | |
92 | 92 | if ($ldapdebug) |
93 | 93 | { |
94 | - dol_syslog("functions_ldap::check_user_password_ldap Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType); |
|
94 | + dol_syslog("functions_ldap::check_user_password_ldap Server:".join(',', $ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType); |
|
95 | 95 | dol_syslog("functions_ldap::check_user_password_ldap uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword); |
96 | - print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."<br>\n"; |
|
96 | + print "DEBUG: Server:".join(',', $ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."<br>\n"; |
|
97 | 97 | print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."<br>\n"; |
98 | 98 | } |
99 | 99 | |
100 | - $resultFetchLdapUser=0; |
|
100 | + $resultFetchLdapUser = 0; |
|
101 | 101 | |
102 | 102 | // Define $userSearchFilter |
103 | 103 | $userSearchFilter = ""; |
104 | 104 | if (empty($dolibarr_main_auth_ldap_filter)) { |
105 | - $userSearchFilter = "(" . $ldapuserattr . "=" . $usertotest . ")"; |
|
105 | + $userSearchFilter = "(".$ldapuserattr."=".$usertotest.")"; |
|
106 | 106 | } else { |
107 | 107 | $userSearchFilter = str_replace('%1%', $usertotest, $dolibarr_main_auth_ldap_filter); |
108 | 108 | } |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | // Code to get user in LDAP from an admin connection (may differ from user connection, done later) |
112 | 112 | if ($ldapadminlogin) |
113 | 113 | { |
114 | - $result=$ldap->connect_bind(); |
|
114 | + $result = $ldap->connect_bind(); |
|
115 | 115 | if ($result > 0) |
116 | 116 | { |
117 | - $resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter); |
|
117 | + $resultFetchLdapUser = $ldap->fetch($usertotest, $userSearchFilter); |
|
118 | 118 | //dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser); |
119 | 119 | if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) // If ok but password need to be reset |
120 | 120 | { |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $ldap->close(); |
124 | 124 | sleep(1); |
125 | 125 | $langs->load('ldap'); |
126 | - $_SESSION["dol_loginmesg"]=$langs->trans("YouMustChangePassNextLogon",$usertotest,$ldap->domainFQDN); |
|
126 | + $_SESSION["dol_loginmesg"] = $langs->trans("YouMustChangePassNextLogon", $usertotest, $ldap->domainFQDN); |
|
127 | 127 | return ''; |
128 | 128 | } |
129 | 129 | } |
@@ -137,41 +137,41 @@ discard block |
||
137 | 137 | // Forge LDAP user and password to test with them |
138 | 138 | // If LDAP need a dn with login like "uid=jbloggs,ou=People,dc=foo,dc=com", default dn may work even if previous code with |
139 | 139 | // admin login no exectued. |
140 | - $ldap->searchUser=$ldapuserattr."=".$usertotest.",".$ldapdn; // Default dn (will work if LDAP accept a dn with login value inside) |
|
140 | + $ldap->searchUser = $ldapuserattr."=".$usertotest.",".$ldapdn; // Default dn (will work if LDAP accept a dn with login value inside) |
|
141 | 141 | // But if LDAP need a dn with name like "cn=Jhon Bloggs,ou=People,dc=foo,dc=com", previous part must have been executed to have |
142 | 142 | // dn detected into ldapUserDN. |
143 | 143 | if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN; |
144 | - $ldap->searchPassword=$passwordtotest; |
|
144 | + $ldap->searchPassword = $passwordtotest; |
|
145 | 145 | |
146 | 146 | // Test with this->seachUser and this->searchPassword |
147 | 147 | //print $resultFetchLdapUser."-".$ldap->ldapUserDN."-".$ldap->searchUser.'-'.$ldap->searchPassword;exit; |
148 | - $result=$ldap->connect_bind(); |
|
148 | + $result = $ldap->connect_bind(); |
|
149 | 149 | if ($result > 0) |
150 | 150 | { |
151 | 151 | if ($result == 2) // Connection is ok for user/pass into LDAP |
152 | 152 | { |
153 | 153 | dol_syslog("functions_ldap::check_user_password_ldap Authentification ok"); |
154 | - $login=$usertotest; |
|
154 | + $login = $usertotest; |
|
155 | 155 | |
156 | 156 | // ldap2dolibarr synchronisation |
157 | - if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') // ldap2dolibarr synchronisation |
|
157 | + if ($login && !empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') // ldap2dolibarr synchronisation |
|
158 | 158 | { |
159 | 159 | dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr"); |
160 | 160 | |
161 | 161 | // On charge les attributs du user ldap |
162 | 162 | if ($ldapdebug) print "DEBUG: login ldap = ".$login."<br>\n"; |
163 | - $resultFetchLdapUser = $ldap->fetch($login,$userSearchFilter); |
|
163 | + $resultFetchLdapUser = $ldap->fetch($login, $userSearchFilter); |
|
164 | 164 | |
165 | - if ($ldapdebug) print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n"; |
|
166 | - if ($ldapdebug) print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n"; |
|
167 | - if ($ldapdebug) print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n"; |
|
165 | + if ($ldapdebug) print "DEBUG: UACF = ".join(',', $ldap->uacf)."<br>\n"; |
|
166 | + if ($ldapdebug) print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset, 'day')."<br>\n"; |
|
167 | + if ($ldapdebug) print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime, 'day')."<br>\n"; |
|
168 | 168 | |
169 | 169 | // On recherche le user dolibarr en fonction de son SID ldap |
170 | 170 | $sid = $ldap->getObjectSid($login); |
171 | 171 | if ($ldapdebug) print "DEBUG: sid = ".$sid."<br>\n"; |
172 | 172 | |
173 | - $usertmp=new User($db); |
|
174 | - $resultFetchUser=$usertmp->fetch('',$login,$sid); |
|
173 | + $usertmp = new User($db); |
|
174 | + $resultFetchUser = $usertmp->fetch('', $login, $sid); |
|
175 | 175 | if ($resultFetchUser > 0) |
176 | 176 | { |
177 | 177 | dol_syslog("functions_ldap::check_user_password_ldap Sync user found user id=".$usertmp->id); |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | unset($usertmp); |
190 | 190 | } |
191 | 191 | |
192 | - if (! empty($conf->multicompany->enabled)) // We must check entity (even if sync is not active) |
|
192 | + if (!empty($conf->multicompany->enabled)) // We must check entity (even if sync is not active) |
|
193 | 193 | { |
194 | 194 | global $mc; |
195 | 195 | |
196 | - $usertmp=new User($db); |
|
197 | - $usertmp->fetch('',$login); |
|
198 | - $ret=$mc->checkRight($usertmp->id, $entitytotest); |
|
196 | + $usertmp = new User($db); |
|
197 | + $usertmp->fetch('', $login); |
|
198 | + $ret = $mc->checkRight($usertmp->id, $entitytotest); |
|
199 | 199 | if ($ret < 0) |
200 | 200 | { |
201 | 201 | dol_syslog("functions_ldap::check_user_password_ldap Authentification ko entity '".$entitytotest."' not allowed for user '".$usertmp->id."'"); |
202 | - $login=''; // force authentication failure |
|
202 | + $login = ''; // force authentication failure |
|
203 | 203 | } |
204 | 204 | unset($usertmp); |
205 | 205 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | // Load translation files required by the page |
213 | 213 | $langs->loadLangs(array('main', 'other')); |
214 | 214 | |
215 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
|
215 | + $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword"); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | else |
@@ -232,12 +232,12 @@ discard block |
||
232 | 232 | $ldap->ldapErrorText = ldap_error($ldap->connection); |
233 | 233 | dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorCode." ".$ldap->ldapErrorText); |
234 | 234 | } |
235 | - sleep(2); // Anti brut force protection |
|
235 | + sleep(2); // Anti brut force protection |
|
236 | 236 | |
237 | 237 | // Load translation files required by the page |
238 | 238 | $langs->loadLangs(array('main', 'other', 'errors')); |
239 | 239 | ; |
240 | - $_SESSION["dol_loginmesg"]=($ldap->error?$ldap->error:$langs->trans("ErrorBadLoginPassword")); |
|
240 | + $_SESSION["dol_loginmesg"] = ($ldap->error ? $ldap->error : $langs->trans("ErrorBadLoginPassword")); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | $ldap->close(); |
@@ -45,7 +45,9 @@ discard block |
||
45 | 45 | |
46 | 46 | // Force master entity in transversal mode |
47 | 47 | $entity=$entitytotest; |
48 | - if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; |
|
48 | + if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
49 | + $entity=1; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | $login=''; |
51 | 53 | $resultFetchUser=''; |
@@ -78,7 +80,9 @@ discard block |
||
78 | 80 | $ldapadminpass=$dolibarr_main_auth_ldap_admin_pass; |
79 | 81 | $ldapdebug=(empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug=="false" ? false : true); |
80 | 82 | |
81 | - if ($ldapdebug) print "DEBUG: Logging LDAP steps<br>\n"; |
|
83 | + if ($ldapdebug) { |
|
84 | + print "DEBUG: Logging LDAP steps<br>\n"; |
|
85 | + } |
|
82 | 86 | |
83 | 87 | require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; |
84 | 88 | $ldap=new Ldap(); |
@@ -116,20 +120,25 @@ discard block |
||
116 | 120 | { |
117 | 121 | $resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter); |
118 | 122 | //dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser); |
119 | - if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) // If ok but password need to be reset |
|
123 | + if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) { |
|
124 | + // If ok but password need to be reset |
|
120 | 125 | { |
121 | 126 | dol_syslog('functions_ldap::check_user_password_ldap '.$usertotest.' must change password next logon'); |
122 | - if ($ldapdebug) print "DEBUG: User ".$usertotest." must change password<br>\n"; |
|
127 | + } |
|
128 | + if ($ldapdebug) { |
|
129 | + print "DEBUG: User ".$usertotest." must change password<br>\n"; |
|
130 | + } |
|
123 | 131 | $ldap->close(); |
124 | 132 | sleep(1); |
125 | 133 | $langs->load('ldap'); |
126 | 134 | $_SESSION["dol_loginmesg"]=$langs->trans("YouMustChangePassNextLogon",$usertotest,$ldap->domainFQDN); |
127 | 135 | return ''; |
128 | 136 | } |
129 | - } |
|
130 | - else |
|
137 | + } else |
|
131 | 138 | { |
132 | - if ($ldapdebug) print "DEBUG: ".$ldap->error."<br>\n"; |
|
139 | + if ($ldapdebug) { |
|
140 | + print "DEBUG: ".$ldap->error."<br>\n"; |
|
141 | + } |
|
133 | 142 | } |
134 | 143 | $ldap->close(); |
135 | 144 | } |
@@ -140,7 +149,9 @@ discard block |
||
140 | 149 | $ldap->searchUser=$ldapuserattr."=".$usertotest.",".$ldapdn; // Default dn (will work if LDAP accept a dn with login value inside) |
141 | 150 | // But if LDAP need a dn with name like "cn=Jhon Bloggs,ou=People,dc=foo,dc=com", previous part must have been executed to have |
142 | 151 | // dn detected into ldapUserDN. |
143 | - if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN; |
|
152 | + if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) { |
|
153 | + $ldap->searchUser = $ldap->ldapUserDN; |
|
154 | + } |
|
144 | 155 | $ldap->searchPassword=$passwordtotest; |
145 | 156 | |
146 | 157 | // Test with this->seachUser and this->searchPassword |
@@ -148,27 +159,41 @@ discard block |
||
148 | 159 | $result=$ldap->connect_bind(); |
149 | 160 | if ($result > 0) |
150 | 161 | { |
151 | - if ($result == 2) // Connection is ok for user/pass into LDAP |
|
162 | + if ($result == 2) { |
|
163 | + // Connection is ok for user/pass into LDAP |
|
152 | 164 | { |
153 | 165 | dol_syslog("functions_ldap::check_user_password_ldap Authentification ok"); |
166 | + } |
|
154 | 167 | $login=$usertotest; |
155 | 168 | |
156 | 169 | // ldap2dolibarr synchronisation |
157 | - if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') // ldap2dolibarr synchronisation |
|
170 | + if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') { |
|
171 | + // ldap2dolibarr synchronisation |
|
158 | 172 | { |
159 | 173 | dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr"); |
174 | + } |
|
160 | 175 | |
161 | 176 | // On charge les attributs du user ldap |
162 | - if ($ldapdebug) print "DEBUG: login ldap = ".$login."<br>\n"; |
|
177 | + if ($ldapdebug) { |
|
178 | + print "DEBUG: login ldap = ".$login."<br>\n"; |
|
179 | + } |
|
163 | 180 | $resultFetchLdapUser = $ldap->fetch($login,$userSearchFilter); |
164 | 181 | |
165 | - if ($ldapdebug) print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n"; |
|
166 | - if ($ldapdebug) print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n"; |
|
167 | - if ($ldapdebug) print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n"; |
|
182 | + if ($ldapdebug) { |
|
183 | + print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n"; |
|
184 | + } |
|
185 | + if ($ldapdebug) { |
|
186 | + print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n"; |
|
187 | + } |
|
188 | + if ($ldapdebug) { |
|
189 | + print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n"; |
|
190 | + } |
|
168 | 191 | |
169 | 192 | // On recherche le user dolibarr en fonction de son SID ldap |
170 | 193 | $sid = $ldap->getObjectSid($login); |
171 | - if ($ldapdebug) print "DEBUG: sid = ".$sid."<br>\n"; |
|
194 | + if ($ldapdebug) { |
|
195 | + print "DEBUG: sid = ".$sid."<br>\n"; |
|
196 | + } |
|
172 | 197 | |
173 | 198 | $usertmp=new User($db); |
174 | 199 | $resultFetchUser=$usertmp->fetch('',$login,$sid); |
@@ -189,9 +214,11 @@ discard block |
||
189 | 214 | unset($usertmp); |
190 | 215 | } |
191 | 216 | |
192 | - if (! empty($conf->multicompany->enabled)) // We must check entity (even if sync is not active) |
|
217 | + if (! empty($conf->multicompany->enabled)) { |
|
218 | + // We must check entity (even if sync is not active) |
|
193 | 219 | { |
194 | 220 | global $mc; |
221 | + } |
|
195 | 222 | |
196 | 223 | $usertmp=new User($db); |
197 | 224 | $usertmp->fetch('',$login); |
@@ -214,8 +241,7 @@ discard block |
||
214 | 241 | |
215 | 242 | $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword"); |
216 | 243 | } |
217 | - } |
|
218 | - else |
|
244 | + } else |
|
219 | 245 | { |
220 | 246 | /* Login failed. Return false, together with the error code and text from |
221 | 247 | ** the LDAP server. The common error codes and reasons are listed below : |
@@ -226,9 +252,11 @@ discard block |
||
226 | 252 | ** 53 - Account inactive (manually locked out by administrator) |
227 | 253 | */ |
228 | 254 | dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP for '".$usertotest."'"); |
229 | - if (is_resource($ldap->connection)) // If connection ok but bind ko |
|
255 | + if (is_resource($ldap->connection)) { |
|
256 | + // If connection ok but bind ko |
|
230 | 257 | { |
231 | 258 | $ldap->ldapErrorCode = ldap_errno($ldap->connection); |
259 | + } |
|
232 | 260 | $ldap->ldapErrorText = ldap_error($ldap->connection); |
233 | 261 | dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorCode." ".$ldap->ldapErrorText); |
234 | 262 | } |