Passed
Push — master ( 8f7a8e...7e4a07 )
by Alxarafe
20:11
created
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.
dolibarr/htdocs/core/actions_fetchobject.inc.php 3 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -30,25 +30,25 @@
 block discarded – undo
30 30
 
31 31
 if (($id > 0 || (! empty($ref) && ! in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0))
32 32
 {
33
-	if (($id > 0 && is_numeric($id)) || ! empty($ref))	// To discard case when id is list of ids like '1,2,3...'
34
-	{
35
-	    $ret = $object->fetch($id, $ref);
36
-	    if ($ret > 0)
37
-	    {
38
-	        $object->fetch_thirdparty();
39
-	        $id = $object->id;
40
-	    }
41
-	    else
42
-	    {
43
-	    	if (empty($object->error) && ! count($object->errors))
44
-	    	{
45
-	    		if ($ret < 0)	// if $ret == 0, it means not found.
46
-	    		{
47
-	    			setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors');
48
-	    		}
49
-	    	}
50
-	        else setEventMessages($object->error, $object->errors, 'errors');
51
-	        $action='';
52
-	    }
53
-	}
33
+    if (($id > 0 && is_numeric($id)) || ! empty($ref))	// To discard case when id is list of ids like '1,2,3...'
34
+    {
35
+        $ret = $object->fetch($id, $ref);
36
+        if ($ret > 0)
37
+        {
38
+            $object->fetch_thirdparty();
39
+            $id = $object->id;
40
+        }
41
+        else
42
+        {
43
+            if (empty($object->error) && ! count($object->errors))
44
+            {
45
+                if ($ret < 0)	// if $ret == 0, it means not found.
46
+                {
47
+                    setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors');
48
+                }
49
+            }
50
+            else setEventMessages($object->error, $object->errors, 'errors');
51
+            $action='';
52
+        }
53
+    }
54 54
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 // $cancel must be defined
29 29
 // $id or $ref must be defined (object is loaded in this file with fetch)
30 30
 
31
-if (($id > 0 || (! empty($ref) && ! in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0))
31
+if (($id > 0 || (!empty($ref) && !in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0))
32 32
 {
33
-	if (($id > 0 && is_numeric($id)) || ! empty($ref))	// To discard case when id is list of ids like '1,2,3...'
33
+	if (($id > 0 && is_numeric($id)) || !empty($ref))	// To discard case when id is list of ids like '1,2,3...'
34 34
 	{
35 35
 	    $ret = $object->fetch($id, $ref);
36 36
 	    if ($ret > 0)
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	    }
41 41
 	    else
42 42
 	    {
43
-	    	if (empty($object->error) && ! count($object->errors))
43
+	    	if (empty($object->error) && !count($object->errors))
44 44
 	    	{
45 45
 	    		if ($ret < 0)	// if $ret == 0, it means not found.
46 46
 	    		{
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	    		}
49 49
 	    	}
50 50
 	        else setEventMessages($object->error, $object->errors, 'errors');
51
-	        $action='';
51
+	        $action = '';
52 52
 	    }
53 53
 	}
54 54
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -6 removed lines patch added patch discarded remove patch
@@ -30,24 +30,28 @@
 block discarded – undo
30 30
 
31 31
 if (($id > 0 || (! empty($ref) && ! in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0))
32 32
 {
33
-	if (($id > 0 && is_numeric($id)) || ! empty($ref))	// To discard case when id is list of ids like '1,2,3...'
33
+	if (($id > 0 && is_numeric($id)) || ! empty($ref)) {
34
+	    // To discard case when id is list of ids like '1,2,3...'
34 35
 	{
35 36
 	    $ret = $object->fetch($id, $ref);
37
+	}
36 38
 	    if ($ret > 0)
37 39
 	    {
38 40
 	        $object->fetch_thirdparty();
39 41
 	        $id = $object->id;
40
-	    }
41
-	    else
42
+	    } else
42 43
 	    {
43 44
 	    	if (empty($object->error) && ! count($object->errors))
44 45
 	    	{
45
-	    		if ($ret < 0)	// if $ret == 0, it means not found.
46
+	    		if ($ret < 0) {
47
+	    		    // if $ret == 0, it means not found.
46 48
 	    		{
47 49
 	    			setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors');
48 50
 	    		}
49
-	    	}
50
-	        else setEventMessages($object->error, $object->errors, 'errors');
51
+	    		}
52
+	    	} else {
53
+	            setEventMessages($object->error, $object->errors, 'errors');
54
+	        }
51 55
 	        $action='';
52 56
 	    }
53 57
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/selectobject.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -62,16 +62,16 @@
 block discarded – undo
62 62
 $classpath=$InfoFieldList[1];
63 63
 if (! empty($classpath))
64 64
 {
65
-	dol_include_once($classpath);
66
-	if ($classname && class_exists($classname))
67
-	{
68
-		$objecttmp = new $classname($db);
69
-	}
65
+    dol_include_once($classpath);
66
+    if ($classname && class_exists($classname))
67
+    {
68
+        $objecttmp = new $classname($db);
69
+    }
70 70
 }
71 71
 if (! is_object($objecttmp))
72 72
 {
73
-	dol_syslog('Error bad param objectdesc', LOG_WARNING);
74
-	print 'Error bad param objectdesc';
73
+    dol_syslog('Error bad param objectdesc', LOG_WARNING);
74
+    print 'Error bad param objectdesc';
75 75
 }
76 76
 
77 77
 // When used from jQuery, the search term is added as GET param "term".
Please login to merge, or discard this patch.
Braces   +25 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,12 +20,25 @@  discard block
 block discarded – undo
20 20
  *       \brief      File to return Ajax response on a selection list request
21 21
  */
22 22
 
23
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
24
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
25
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');
26
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
27
-if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
28
-if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');
23
+if (! defined('NOTOKENRENEWAL')) {
24
+    define('NOTOKENRENEWAL',1);
25
+}
26
+// Disables token renewal
27
+if (! defined('NOREQUIREMENU')) {
28
+    define('NOREQUIREMENU','1');
29
+}
30
+if (! defined('NOREQUIREHTML')) {
31
+    define('NOREQUIREHTML','1');
32
+}
33
+if (! defined('NOREQUIREAJAX')) {
34
+    define('NOREQUIREAJAX','1');
35
+}
36
+if (! defined('NOREQUIRESOC')) {
37
+    define('NOREQUIRESOC','1');
38
+}
39
+if (! defined('NOCSRFCHECK')) {
40
+    define('NOCSRFCHECK','1');
41
+}
29 42
 
30 43
 
31 44
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
@@ -57,7 +70,9 @@  discard block
 block discarded – undo
57 70
 
58 71
 top_httphead();
59 72
 
60
-if (empty($htmlname)) return;
73
+if (empty($htmlname)) {
74
+    return;
75
+}
61 76
 
62 77
 
63 78
 $InfoFieldList = explode(":", $objectdesc);
@@ -86,4 +101,6 @@  discard block
 block discarded – undo
86 101
 
87 102
 $db->close();
88 103
 
89
-if ($outjson) print json_encode($arrayresult);
104
+if ($outjson) {
105
+    print json_encode($arrayresult);
106
+}
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -20,24 +20,24 @@  discard block
 block discarded – undo
20 20
  *       \brief      File to return Ajax response on a selection list request
21 21
  */
22 22
 
23
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
24
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
25
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');
26
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
27
-if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
28
-if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');
23
+if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal
24
+if (!defined('NOREQUIREMENU'))  define('NOREQUIREMENU', '1');
25
+if (!defined('NOREQUIREHTML'))  define('NOREQUIREHTML', '1');
26
+if (!defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX', '1');
27
+if (!defined('NOREQUIRESOC'))   define('NOREQUIRESOC', '1');
28
+if (!defined('NOCSRFCHECK'))    define('NOCSRFCHECK', '1');
29 29
 
30 30
 
31 31
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
32 32
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
33
-require DOL_BASE_PATH . '/main.inc.php';
33
+require DOL_BASE_PATH.'/main.inc.php';
34 34
 
35
-$objectdesc=GETPOST('objectdesc', 'alpha');
36
-$htmlname=GETPOST('htmlname', 'aZ09');
37
-$sqlfilter=GETPOST('sqlfilter', 'alpha');
38
-$outjson=(GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
39
-$action=GETPOST('action', 'alpha');
40
-$id=GETPOST('id', 'int');
35
+$objectdesc = GETPOST('objectdesc', 'alpha');
36
+$htmlname = GETPOST('htmlname', 'aZ09');
37
+$sqlfilter = GETPOST('sqlfilter', 'alpha');
38
+$outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
39
+$action = GETPOST('action', 'alpha');
40
+$id = GETPOST('id', 'int');
41 41
 
42 42
 
43 43
 /*
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
 $InfoFieldList = explode(":", $objectdesc);
64
-$classname=$InfoFieldList[0];
65
-$classpath=$InfoFieldList[1];
66
-if (! empty($classpath))
64
+$classname = $InfoFieldList[0];
65
+$classpath = $InfoFieldList[1];
66
+if (!empty($classpath))
67 67
 {
68 68
 	dol_include_once($classpath);
69 69
 	if ($classname && class_exists($classname))
@@ -71,18 +71,18 @@  discard block
 block discarded – undo
71 71
 		$objecttmp = new $classname($db);
72 72
 	}
73 73
 }
74
-if (! is_object($objecttmp))
74
+if (!is_object($objecttmp))
75 75
 {
76 76
 	dol_syslog('Error bad param objectdesc', LOG_WARNING);
77 77
 	print 'Error bad param objectdesc';
78 78
 }
79 79
 
80 80
 // When used from jQuery, the search term is added as GET param "term".
81
-$searchkey=(($id && GETPOST($id, 'alpha'))?GETPOST($id, 'alpha'):(($htmlname && GETPOST($htmlname, 'alpha'))?GETPOST($htmlname, 'alpha'):''));
81
+$searchkey = (($id && GETPOST($id, 'alpha')) ?GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ?GETPOST($htmlname, 'alpha') : ''));
82 82
 
83 83
 // TODO Add a security test to avoid to get content of all tables
84 84
 
85
-$arrayresult=$form->selectForFormsList($objecttmp, $htmlname, '', 0, $searchkey, '', '', '', 0, 1);
85
+$arrayresult = $form->selectForFormsList($objecttmp, $htmlname, '', 0, $searchkey, '', '', '', 0, 1);
86 86
 
87 87
 $db->close();
88 88
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/ajax/loadinplace.php 3 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -44,72 +44,72 @@
 block discarded – undo
44 44
 // Load original field value
45 45
 if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($fk_element))
46 46
 {
47
-	$ext_element	= GETPOST('ext_element','alpha');
48
-	$field			= substr($field, 8); // remove prefix val_
49
-	$type			= GETPOST('type','alpha');
50
-	$loadmethod		= (GETPOST('loadmethod','alpha') ? GETPOST('loadmethod','alpha') : 'getValueFrom');
47
+    $ext_element	= GETPOST('ext_element','alpha');
48
+    $field			= substr($field, 8); // remove prefix val_
49
+    $type			= GETPOST('type','alpha');
50
+    $loadmethod		= (GETPOST('loadmethod','alpha') ? GETPOST('loadmethod','alpha') : 'getValueFrom');
51 51
 
52
-	if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
53
-	{
54
-		$element = $regs[1];
55
-		$subelement = $regs[2];
56
-	}
52
+    if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
53
+    {
54
+        $element = $regs[1];
55
+        $subelement = $regs[2];
56
+    }
57 57
 
58
-	if ($element == 'propal') $element = 'propale';
59
-	else if ($element == 'fichinter') $element = 'ficheinter';
60
-	else if ($element == 'product') $element = 'produit';
61
-	else if ($element == 'member') $element = 'adherent';
62
-	else if ($element == 'order_supplier') {
63
-		$element = 'fournisseur';
64
-		$subelement = 'commande';
65
-	}
66
-	else if ($element == 'invoice_supplier') {
67
-		$element = 'fournisseur';
68
-		$subelement = 'facture';
69
-	}
58
+    if ($element == 'propal') $element = 'propale';
59
+    else if ($element == 'fichinter') $element = 'ficheinter';
60
+    else if ($element == 'product') $element = 'produit';
61
+    else if ($element == 'member') $element = 'adherent';
62
+    else if ($element == 'order_supplier') {
63
+        $element = 'fournisseur';
64
+        $subelement = 'commande';
65
+    }
66
+    else if ($element == 'invoice_supplier') {
67
+        $element = 'fournisseur';
68
+        $subelement = 'facture';
69
+    }
70 70
 
71
-	if ($user->rights->$element->lire || $user->rights->$element->read
72
-	|| (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read))
73
-	|| ($element == 'payment' && $user->rights->facture->lire)
74
-	|| ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire))
75
-	{
76
-		if ($type == 'select')
77
-		{
78
-			$methodname	= 'load_cache_'.$loadmethod;
79
-			$cachename = 'cache_'.GETPOST('loadmethod','alpha');
71
+    if ($user->rights->$element->lire || $user->rights->$element->read
72
+    || (isset($subelement) && ($user->rights->$element->$subelement->lire || $user->rights->$element->$subelement->read))
73
+    || ($element == 'payment' && $user->rights->facture->lire)
74
+    || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->lire))
75
+    {
76
+        if ($type == 'select')
77
+        {
78
+            $methodname	= 'load_cache_'.$loadmethod;
79
+            $cachename = 'cache_'.GETPOST('loadmethod','alpha');
80 80
 
81
-			$form = new Form($db);
82
-			if (method_exists($form, $methodname))
83
-			{
84
-				$ret = $form->$methodname();
85
-				if ($ret > 0) echo json_encode($form->$cachename);
86
-			}
87
-			else if (! empty($ext_element))
88
-			{
89
-				$module = $subelement = $ext_element;
90
-				if (preg_match('/^([^_]+)_([^_]+)/i',$ext_element,$regs))
91
-				{
92
-					$module = $regs[1];
93
-					$subelement = $regs[2];
94
-				}
81
+            $form = new Form($db);
82
+            if (method_exists($form, $methodname))
83
+            {
84
+                $ret = $form->$methodname();
85
+                if ($ret > 0) echo json_encode($form->$cachename);
86
+            }
87
+            else if (! empty($ext_element))
88
+            {
89
+                $module = $subelement = $ext_element;
90
+                if (preg_match('/^([^_]+)_([^_]+)/i',$ext_element,$regs))
91
+                {
92
+                    $module = $regs[1];
93
+                    $subelement = $regs[2];
94
+                }
95 95
 
96
-				dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
97
-				$classname = 'Actions'.ucfirst($subelement);
98
-				$object = new $classname($db);
99
-				$ret = $object->$methodname($fk_element);
100
-				if ($ret > 0) echo json_encode($object->$cachename);
101
-			}
102
-		}
103
-		else
104
-		{
105
-			$object = new GenericObject($db);
106
-			$value=$object->$loadmethod($table_element, $fk_element, $field);
107
-			echo $value;
108
-		}
109
-	}
110
-	else
111
-	{
112
-		echo $langs->transnoentities('NotEnoughPermissions');
113
-	}
96
+                dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php');
97
+                $classname = 'Actions'.ucfirst($subelement);
98
+                $object = new $classname($db);
99
+                $ret = $object->$methodname($fk_element);
100
+                if ($ret > 0) echo json_encode($object->$cachename);
101
+            }
102
+        }
103
+        else
104
+        {
105
+            $object = new GenericObject($db);
106
+            $value=$object->$loadmethod($table_element, $fk_element, $field);
107
+            echo $value;
108
+        }
109
+    }
110
+    else
111
+    {
112
+        echo $langs->transnoentities('NotEnoughPermissions');
113
+    }
114 114
 }
115 115
 
Please login to merge, or discard this patch.
Braces   +32 added lines, -19 removed lines patch added patch discarded remove patch
@@ -20,10 +20,19 @@  discard block
 block discarded – undo
20 20
  *       \brief      File to load field value
21 21
  */
22 22
 
23
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
24
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
25
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
26
-if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
23
+if (! defined('NOTOKENRENEWAL')) {
24
+    define('NOTOKENRENEWAL','1');
25
+}
26
+// Disables token renewal
27
+if (! defined('NOREQUIREMENU')) {
28
+    define('NOREQUIREMENU','1');
29
+}
30
+if (! defined('NOREQUIREAJAX')) {
31
+    define('NOREQUIREAJAX','1');
32
+}
33
+if (! defined('NOREQUIRESOC')) {
34
+    define('NOREQUIRESOC','1');
35
+}
27 36
 
28 37
 
29 38
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
@@ -58,15 +67,18 @@  discard block
 block discarded – undo
58 67
 		$subelement = $regs[2];
59 68
 	}
60 69
 
61
-	if ($element == 'propal') $element = 'propale';
62
-	else if ($element == 'fichinter') $element = 'ficheinter';
63
-	else if ($element == 'product') $element = 'produit';
64
-	else if ($element == 'member') $element = 'adherent';
65
-	else if ($element == 'order_supplier') {
70
+	if ($element == 'propal') {
71
+	    $element = 'propale';
72
+	} else if ($element == 'fichinter') {
73
+	    $element = 'ficheinter';
74
+	} else if ($element == 'product') {
75
+	    $element = 'produit';
76
+	} else if ($element == 'member') {
77
+	    $element = 'adherent';
78
+	} else if ($element == 'order_supplier') {
66 79
 		$element = 'fournisseur';
67 80
 		$subelement = 'commande';
68
-	}
69
-	else if ($element == 'invoice_supplier') {
81
+	} else if ($element == 'invoice_supplier') {
70 82
 		$element = 'fournisseur';
71 83
 		$subelement = 'facture';
72 84
 	}
@@ -85,9 +97,10 @@  discard block
 block discarded – undo
85 97
 			if (method_exists($form, $methodname))
86 98
 			{
87 99
 				$ret = $form->$methodname();
88
-				if ($ret > 0) echo json_encode($form->$cachename);
89
-			}
90
-			else if (! empty($ext_element))
100
+				if ($ret > 0) {
101
+				    echo json_encode($form->$cachename);
102
+				}
103
+			} else if (! empty($ext_element))
91 104
 			{
92 105
 				$module = $subelement = $ext_element;
93 106
 				if (preg_match('/^([^_]+)_([^_]+)/i',$ext_element,$regs))
@@ -100,17 +113,17 @@  discard block
 block discarded – undo
100 113
 				$classname = 'Actions'.ucfirst($subelement);
101 114
 				$object = new $classname($db);
102 115
 				$ret = $object->$methodname($fk_element);
103
-				if ($ret > 0) echo json_encode($object->$cachename);
116
+				if ($ret > 0) {
117
+				    echo json_encode($object->$cachename);
118
+				}
104 119
 			}
105
-		}
106
-		else
120
+		} else
107 121
 		{
108 122
 			$object = new GenericObject($db);
109 123
 			$value=$object->$loadmethod($table_element, $fk_element, $field);
110 124
 			echo $value;
111 125
 		}
112
-	}
113
-	else
126
+	} else
114 127
 	{
115 128
 		echo $langs->transnoentities('NotEnoughPermissions');
116 129
 	}
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -20,21 +20,21 @@  discard block
 block discarded – undo
20 20
  *       \brief      File to load field value
21 21
  */
22 22
 
23
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
24
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
25
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
26
-if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
23
+if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal
24
+if (!defined('NOREQUIREMENU'))  define('NOREQUIREMENU', '1');
25
+if (!defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX', '1');
26
+if (!defined('NOREQUIRESOC'))   define('NOREQUIRESOC', '1');
27 27
 
28 28
 
29 29
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
30 30
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
31
-require DOL_BASE_PATH . '/main.inc.php';
31
+require DOL_BASE_PATH.'/main.inc.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
33 33
 
34
-$field			= GETPOST('field','alpha');
35
-$element		= GETPOST('element','alpha');
36
-$table_element	= GETPOST('table_element','alpha');
37
-$fk_element		= GETPOST('fk_element','alpha');
34
+$field = GETPOST('field', 'alpha');
35
+$element = GETPOST('element', 'alpha');
36
+$table_element = GETPOST('table_element', 'alpha');
37
+$fk_element = GETPOST('fk_element', 'alpha');
38 38
 
39 39
 /*
40 40
  * View
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
46 46
 
47 47
 // Load original field value
48
-if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($fk_element))
48
+if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_element))
49 49
 {
50
-	$ext_element	= GETPOST('ext_element','alpha');
51
-	$field			= substr($field, 8); // remove prefix val_
52
-	$type			= GETPOST('type','alpha');
53
-	$loadmethod		= (GETPOST('loadmethod','alpha') ? GETPOST('loadmethod','alpha') : 'getValueFrom');
50
+	$ext_element	= GETPOST('ext_element', 'alpha');
51
+	$field = substr($field, 8); // remove prefix val_
52
+	$type = GETPOST('type', 'alpha');
53
+	$loadmethod		= (GETPOST('loadmethod', 'alpha') ? GETPOST('loadmethod', 'alpha') : 'getValueFrom');
54 54
 
55
-	if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
55
+	if ($element != 'order_supplier' && $element != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i', $element, $regs))
56 56
 	{
57 57
 		$element = $regs[1];
58 58
 		$subelement = $regs[2];
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	{
79 79
 		if ($type == 'select')
80 80
 		{
81
-			$methodname	= 'load_cache_'.$loadmethod;
82
-			$cachename = 'cache_'.GETPOST('loadmethod','alpha');
81
+			$methodname = 'load_cache_'.$loadmethod;
82
+			$cachename = 'cache_'.GETPOST('loadmethod', 'alpha');
83 83
 
84 84
 			$form = new Form($db);
85 85
 			if (method_exists($form, $methodname))
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
 				$ret = $form->$methodname();
88 88
 				if ($ret > 0) echo json_encode($form->$cachename);
89 89
 			}
90
-			else if (! empty($ext_element))
90
+			else if (!empty($ext_element))
91 91
 			{
92 92
 				$module = $subelement = $ext_element;
93
-				if (preg_match('/^([^_]+)_([^_]+)/i',$ext_element,$regs))
93
+				if (preg_match('/^([^_]+)_([^_]+)/i', $ext_element, $regs))
94 94
 				{
95 95
 					$module = $regs[1];
96 96
 					$subelement = $regs[2];
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 		else
107 107
 		{
108 108
 			$object = new GenericObject($db);
109
-			$value=$object->$loadmethod($table_element, $fk_element, $field);
109
+			$value = $object->$loadmethod($table_element, $fk_element, $field);
110 110
 			echo $value;
111 111
 		}
112 112
 	}
Please login to merge, or discard this patch.