Passed
Push — master ( db7d4f...be8d41 )
by Alxarafe
21:50
created
dolibarr/htdocs/core/actions_extrafields.inc.php 3 patches
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -40,23 +40,23 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -23,18 +23,18 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +31 added lines, -29 removed lines patch added patch discarded remove patch
@@ -31,10 +31,18 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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");
Please login to merge, or discard this patch.
dolibarr/htdocs/core/login/functions_openid.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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();
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -56,8 +56,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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";
Please login to merge, or discard this patch.
dolibarr/htdocs/core/login/functions_forceuser.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,16 +34,16 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,17 +32,17 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,9 +40,13 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/login/functions_dolibarr.php 3 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -35,124 +35,124 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +22 added lines, -12 removed lines patch added patch discarded remove patch
@@ -39,7 +39,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/login/functions_http.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,13 +33,13 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -31,14 +31,14 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/login/functions_ldap.php 3 patches
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -34,190 +34,190 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -32,25 +32,25 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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();
Please login to merge, or discard this patch.
Braces   +47 added lines, -19 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 			}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/login/functions_empty.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@
 block discarded – undo
33 33
  */
34 34
 function check_user_password_empty($usertotest,$passwordtotest,$entitytotest)
35 35
 {
36
-	global $langs;
36
+    global $langs;
37 37
 
38
-	dol_syslog("functions_empty::check_user_password_empty usertotest=".$usertotest);
38
+    dol_syslog("functions_empty::check_user_password_empty usertotest=".$usertotest);
39 39
 
40
-	$login='';
41
-	$_SESSION["dol_loginmesg"]=$langs->trans("FailedToLogin");
40
+    $login='';
41
+    $_SESSION["dol_loginmesg"]=$langs->trans("FailedToLogin");
42 42
 
43
-	return $login;
43
+    return $login;
44 44
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,14 +31,14 @@
 block discarded – undo
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_empty($usertotest,$passwordtotest,$entitytotest)
34
+function check_user_password_empty($usertotest, $passwordtotest, $entitytotest)
35 35
 {
36 36
 	global $langs;
37 37
 
38 38
 	dol_syslog("functions_empty::check_user_password_empty usertotest=".$usertotest);
39 39
 
40
-	$login='';
41
-	$_SESSION["dol_loginmesg"]=$langs->trans("FailedToLogin");
40
+	$login = '';
41
+	$_SESSION["dol_loginmesg"] = $langs->trans("FailedToLogin");
42 42
 
43 43
 	return $login;
44 44
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/actions_changeselectedfields.inc.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,16 +30,16 @@
 block discarded – undo
30 30
 // Save selection
31 31
 if (GETPOST('formfilteraction') == 'listafterchangingselectedfields')
32 32
 {
33
-    $tabparam=array();
33
+    $tabparam = array();
34 34
 
35
-    $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
35
+    $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
36 36
 
37
-    if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
38
-    else $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
37
+    if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage] = GETPOST("selectedfields");
38
+    else $tabparam["MAIN_SELECTEDFIELDS_".$varpage] = '';
39 39
 
40 40
     include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41 41
 
42
-    $result=dol_set_user_param($db, $conf, $user, $tabparam);
42
+    $result = dol_set_user_param($db, $conf, $user, $tabparam);
43 43
 
44 44
     //$action='list';
45 45
     //var_dump($tabparam);exit;
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,8 +34,11 @@
 block discarded – undo
34 34
 
35 35
     $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
36 36
 
37
-    if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
38
-    else $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
37
+    if (GETPOST("selectedfields")) {
38
+        $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
39
+    } else {
40
+        $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
41
+    }
39 42
 
40 43
     include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41 44
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/actions_dellink.inc.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
 // Delete link
41 41
 if ($action == 'dellink' && ! empty($permissiondellink) && ! GETPOST('cancel','alpha') && $dellinkid > 0)
42 42
 {
43
-	$result=$object->deleteObjectLinked(0, '', 0, '', $dellinkid);
44
-	if ($result < 0) setEventMessages($object->error,$object->errors,'errors');
43
+    $result=$object->deleteObjectLinked(0, '', 0, '', $dellinkid);
44
+    if ($result < 0) setEventMessages($object->error,$object->errors,'errors');
45 45
 }
46 46
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,21 +26,21 @@
 block discarded – undo
26 26
 // $object must be defined
27 27
 // $permissiondellink must be defined
28 28
 
29
-$dellinkid = GETPOST('dellinkid','int');
30
-$addlinkid = GETPOST('idtolinkto','int');
29
+$dellinkid = GETPOST('dellinkid', 'int');
30
+$addlinkid = GETPOST('idtolinkto', 'int');
31 31
 
32 32
 // Link invoice to order
33
-if ($action == 'addlink' && ! empty($permissiondellink) && ! GETPOST('cancel','alpha') && $id > 0 && $addlinkid > 0)
33
+if ($action == 'addlink' && !empty($permissiondellink) && !GETPOST('cancel', 'alpha') && $id > 0 && $addlinkid > 0)
34 34
 {
35 35
     $object->fetch($id);
36 36
     $object->fetch_thirdparty();
37
-    $result = $object->add_object_linked(GETPOST('addlink','alpha'), $addlinkid);
37
+    $result = $object->add_object_linked(GETPOST('addlink', 'alpha'), $addlinkid);
38 38
 }
39 39
 
40 40
 // Delete link
41
-if ($action == 'dellink' && ! empty($permissiondellink) && ! GETPOST('cancel','alpha') && $dellinkid > 0)
41
+if ($action == 'dellink' && !empty($permissiondellink) && !GETPOST('cancel', 'alpha') && $dellinkid > 0)
42 42
 {
43
-	$result=$object->deleteObjectLinked(0, '', 0, '', $dellinkid);
44
-	if ($result < 0) setEventMessages($object->error,$object->errors,'errors');
43
+	$result = $object->deleteObjectLinked(0, '', 0, '', $dellinkid);
44
+	if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
45 45
 }
46 46
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,6 +41,8 @@
 block discarded – undo
41 41
 if ($action == 'dellink' && ! empty($permissiondellink) && ! GETPOST('cancel','alpha') && $dellinkid > 0)
42 42
 {
43 43
 	$result=$object->deleteObjectLinked(0, '', 0, '', $dellinkid);
44
-	if ($result < 0) setEventMessages($object->error,$object->errors,'errors');
45
-}
44
+	if ($result < 0) {
45
+	    setEventMessages($object->error,$object->errors,'errors');
46
+	}
47
+	}
46 48
 
Please login to merge, or discard this patch.