Completed
Push — 16.1 ( dce808...4651d6 )
by Nathan
68:40 queued 52:57
created
api/src/Etemplate/Widget/HtmlArea.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -38,16 +38,16 @@  discard block
 block discarded – undo
38 38
 		$form_name = self::form_name($cname, $this->id);
39 39
 
40 40
 		$config = Api\Html\CkEditorConfig::get_ckeditor_config_array($this->attrs['mode'], $this->attrs['height'],
41
-			$this->attrs['expand_toolbar'],$this->attrs['base_href']
41
+			$this->attrs['expand_toolbar'], $this->attrs['base_href']
42 42
 		);
43 43
 		// User preferences
44 44
 		$font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font'];
45 45
 		$font_size = Api\Html\CkEditorConfig::font_size_from_prefs();
46 46
 		$font_span = '<span style="width: 100%; display: inline; '.
47
-			($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').
47
+			($font ? 'font-family:'.$font.'; ' : '').($font_size ? 'font-size:'.$font_size.'; ' : '').
48 48
 			'">&#8203;</span>';
49 49
 		if (empty($font) && empty($font_size)) $font_span = '';
50
-		if($font_span)
50
+		if ($font_span)
51 51
 		{
52 52
 			$config['preference_style'] = $font_span;
53 53
 		}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 * @param array &$validated=array() validated content
66 66
 	 * @return boolean true if no validation error, false otherwise
67 67
 	 */
68
-	public function validate($cname, array $expand, array $content, &$validated=array())
68
+	public function validate($cname, array $expand, array $content, &$validated = array())
69 69
 	{
70 70
 		$form_name = self::form_name($cname, $this->id, $expand);
71 71
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 			{
78 78
 				$value = Api\Html\HtmLawed::purify($value, $this->attrs['validation_rules']);
79 79
 			}
80
-			$valid =& self::get_array($validated, $form_name, true);
80
+			$valid = & self::get_array($validated, $form_name, true);
81 81
 			if (true) $valid = $value;
82 82
 		}
83 83
 	}
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
43 43
 	 * @param array $content
44 44
 	 * @param array &$validated=array() validated content
45
-	 * @return boolean true if no validation error, false otherwise
45
+	 * @return boolean|null true if no validation error, false otherwise
46 46
 	 */
47 47
 	public function validate($cname, array $expand, array $content, &$validated=array())
48 48
 	{
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,7 +46,10 @@  discard block
 block discarded – undo
46 46
 		$font_span = '<span style="width: 100%; display: inline; '.
47 47
 			($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').
48 48
 			'">&#8203;</span>';
49
-		if (empty($font) && empty($font_size)) $font_span = '';
49
+		if (empty($font) && empty($font_size))
50
+		{
51
+			$font_span = '';
52
+		}
50 53
 		if($font_span)
51 54
 		{
52 55
 			$config['preference_style'] = $font_span;
@@ -78,7 +81,10 @@  discard block
 block discarded – undo
78 81
 				$value = Api\Html\HtmLawed::purify($value, $this->attrs['validation_rules']);
79 82
 			}
80 83
 			$valid =& self::get_array($validated, $form_name, true);
81
-			if (true) $valid = $value;
84
+			if (true)
85
+			{
86
+				$valid = $value;
87
+			}
82 88
 		}
83 89
 	}
84 90
 }
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/ItemPicker.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function __construct($xml = '')
33 33
 	{
34
-		if($xml) {
34
+		if ($xml) {
35 35
 			parent::__construct($xml);
36 36
 		}
37 37
 	}
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 * Find items that match the given parameters
41 41
 	 * using the egw_link class
42 42
 	 */
43
-	public static function ajax_item_search($app, $type, $pattern, $options=array())
43
+	public static function ajax_item_search($app, $type, $pattern, $options = array())
44 44
 	{
45 45
 		$options['type'] = $type ? $type : $options['type'];
46 46
 		$items = Api\Link::query($app, $pattern, $options);
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,8 @@
 block discarded – undo
31 31
 	 */
32 32
 	public function __construct($xml = '')
33 33
 	{
34
-		if($xml) {
34
+		if($xml)
35
+		{
35 36
 			parent::__construct($xml);
36 37
 		}
37 38
 	}
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/HistoryLog.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	 * while it uses select-account for owner in historylog (containing all users).
34 34
 	 *
35 35
 	 * @param string $cname
36
-	*/
36
+	 */
37 37
 	public function beforeSendToClient($cname)
38 38
 	{
39 39
 		$form_name = self::form_name($cname, $this->id);
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,19 +38,19 @@  discard block
 block discarded – undo
38 38
 	{
39 39
 		$form_name = self::form_name($cname, $this->id);
40 40
 
41
-		if(is_array(self::$request->content[$form_name]['status-widgets']))
41
+		if (is_array(self::$request->content[$form_name]['status-widgets']))
42 42
 		{
43
-			foreach(self::$request->content[$form_name]['status-widgets'] as $key => $type)
43
+			foreach (self::$request->content[$form_name]['status-widgets'] as $key => $type)
44 44
 			{
45
-				if(!is_array($type))
45
+				if (!is_array($type))
46 46
 				{
47
-					list($basetype) = explode('-',$type);
47
+					list($basetype) = explode('-', $type);
48 48
 					$widget = @self::factory($basetype, '<?xml version="1.0"?><'.$type.' type="'.$type.'"/>', $key);
49 49
 					$widget->id = $key;
50 50
 					$widget->attrs['type'] = $type;
51 51
 					$widget->type = $type;
52 52
 
53
-					if(method_exists($widget, 'beforeSendToClient'))
53
+					if (method_exists($widget, 'beforeSendToClient'))
54 54
 					{
55 55
 						// need to use $form_name as $cname see comment in header
56 56
 						$widget->beforeSendToClient($form_name, array());
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 				else
60 60
 				{
61 61
 					// need to use self::form_name($form_name, $key) as index into sel_options see comment in header
62
-					$options =& self::get_array(self::$request->sel_options, self::form_name($form_name, $key), true);
62
+					$options = & self::get_array(self::$request->sel_options, self::form_name($form_name, $key), true);
63 63
 					if (!is_array($options)) $options = array();
64 64
 					$options += $type;
65 65
 				}
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 	 * @param array &$validated=array() validated content
83 83
 	 * @return boolean true if no validation error, false otherwise
84 84
 	 */
85
-	public function validate($cname, array $expand, array $content, &$validated=array())
85
+	public function validate($cname, array $expand, array $content, &$validated = array())
86 86
 	{
87 87
 		$form_name = self::form_name($cname, $this->id, $expand);
88 88
 		$value = self::get_array($content, $form_name);
89
-		$valid =& self::get_array($validated, $form_name, true);
89
+		$valid = & self::get_array($validated, $form_name, true);
90 90
 		if (true) $valid = $value;
91 91
 		return true;
92 92
 	}
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -60,7 +60,10 @@  discard block
 block discarded – undo
60 60
 				{
61 61
 					// need to use self::form_name($form_name, $key) as index into sel_options see comment in header
62 62
 					$options =& self::get_array(self::$request->sel_options, self::form_name($form_name, $key), true);
63
-					if (!is_array($options)) $options = array();
63
+					if (!is_array($options))
64
+					{
65
+						$options = array();
66
+					}
64 67
 					$options += $type;
65 68
 				}
66 69
 
@@ -87,7 +90,10 @@  discard block
 block discarded – undo
87 90
 		$form_name = self::form_name($cname, $this->id, $expand);
88 91
 		$value = self::get_array($content, $form_name);
89 92
 		$valid =& self::get_array($validated, $form_name, true);
90
-		if (true) $valid = $value;
93
+		if (true)
94
+		{
95
+			$valid = $value;
96
+		}
91 97
 		return true;
92 98
 	}
93 99
 }
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/Toolbar.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,14 +29,14 @@
 block discarded – undo
29 29
 	 * @param array &$validated=array() validated content
30 30
 	 * @return boolean true if no validation error, false otherwise
31 31
 	 */
32
-	public function validate($cname, array $expand, array $content, &$validated=array())
32
+	public function validate($cname, array $expand, array $content, &$validated = array())
33 33
 	{
34 34
 		$form_name = self::form_name($cname, $this->id, $expand);
35 35
 
36 36
 		if (!$this->is_readonly($cname, $form_name))
37 37
 		{
38 38
 			$value = self::get_array($content, $form_name);
39
-			$valid =& self::get_array($validated, $form_name, true);
39
+			$valid = & self::get_array($validated, $form_name, true);
40 40
 			if (true) $valid = $value;
41 41
 		}
42 42
 	}
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
43 43
 	 * @param array $content
44 44
 	 * @param array &$validated=array() validated content
45
-	 * @return boolean true if no validation error, false otherwise
45
+	 * @return boolean|null true if no validation error, false otherwise
46 46
 	 */
47 47
 	public function validate($cname, array $expand, array $content, &$validated=array())
48 48
 	{
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,10 @@
 block discarded – undo
37 37
 		{
38 38
 			$value = self::get_array($content, $form_name);
39 39
 			$valid =& self::get_array($validated, $form_name, true);
40
-			if (true) $valid = $value;
40
+			if (true)
41
+			{
42
+				$valid = $value;
43
+			}
41 44
 		}
42 45
 	}
43 46
 }
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/Image.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,21 +29,21 @@
 block discarded – undo
29 29
 	 * @param string $cname
30 30
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
31 31
 	 */
32
-	public function beforeSendToClient($cname, array $expand=null)
32
+	public function beforeSendToClient($cname, array $expand = null)
33 33
 	{
34 34
 		$form_name = self::form_name($cname, $this->id, $expand);
35
-		$value =& self::get_array(self::$request->content, $form_name);
35
+		$value = & self::get_array(self::$request->content, $form_name);
36 36
 
37 37
 		$image = $value != '' ? $value : $this->attrs['src'];
38 38
 
39
-		if (is_string($image)) list($app,$img) = explode('/',$image,2);
40
-		if (!$app || !$img || !is_dir(EGW_SERVER_ROOT.'/'.$app) || strpos($img,'/')!==false)
39
+		if (is_string($image)) list($app, $img) = explode('/', $image, 2);
40
+		if (!$app || !$img || !is_dir(EGW_SERVER_ROOT.'/'.$app) || strpos($img, '/') !== false)
41 41
 		{
42 42
 			$img = $image;
43
-			list($app) = explode('.',$form_name);
43
+			list($app) = explode('.', $form_name);
44 44
 		}
45 45
 		$src = Api\Image::find($app, $img);
46
-		if(!$this->id)
46
+		if (!$this->id)
47 47
 		{
48 48
 //			self::setElementAttribute($this->attrs['src'], 'id', $this->attrs['src']);
49 49
 		}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,10 @@
 block discarded – undo
36 36
 
37 37
 		$image = $value != '' ? $value : $this->attrs['src'];
38 38
 
39
-		if (is_string($image)) list($app,$img) = explode('/',$image,2);
39
+		if (is_string($image))
40
+		{
41
+			list($app,$img) = explode('/',$image,2);
42
+		}
40 43
 		if (!$app || !$img || !is_dir(EGW_SERVER_ROOT.'/'.$app) || strpos($img,'/')!==false)
41 44
 		{
42 45
 			$img = $image;
Please login to merge, or discard this patch.
api/src/Etemplate/WidgetBrowser.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
 	{
33 33
 		$GLOBALS['egw_info']['flags']['currentapp'] = 'etemplate';
34 34
 		$GLOBALS['egw_info']['flags']['app_header'] = 'et2 Widgets';
35
-                //'js_link_registry'      => True,
35
+				//'js_link_registry'      => True,
36 36
 
37 37
 		// Widget browser code
38 38
 		Api\Framework::includeJS('/api/js/etemplate/widget_browser.js');
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
 
47 47
 		Api\Framework::includeCSS('/api/templates/default/etemplate2.css');
48 48
 
49
-		Api\Framework::includeCSS('api','widget_browser',false);
49
+		Api\Framework::includeCSS('api', 'widget_browser', false);
50 50
 
51 51
 		// load translations
52 52
 		Api\Translation::add_app('etemplate');
Please login to merge, or discard this patch.
api/src/MimeMagic.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		{
47 47
 			return $mime;
48 48
 		}
49
-		return lang('%1 file',strtoupper($ext)).' ('.$mime.')';
49
+		return lang('%1 file', strtoupper($ext)).' ('.$mime.')';
50 50
 	}
51 51
 
52 52
 	/**
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	{
64 64
 		if (empty($_ext))
65 65
 		{
66
-			return 'text/plain';//assume no extension is a text file
66
+			return 'text/plain'; //assume no extension is a text file
67 67
 		}
68 68
 		$ext = strtolower($_ext);
69 69
 		if (!array_key_exists($ext, self::$mime_extension_map))
@@ -188,24 +188,24 @@  discard block
 block discarded – undo
188 188
 	 */
189 189
 	public static function analyze_data($data)
190 190
 	{
191
-		if(!is_writeable(@$GLOBALS['egw_info']['server']['temp_dir']))
191
+		if (!is_writeable(@$GLOBALS['egw_info']['server']['temp_dir']))
192 192
 		{
193 193
 			//nothing we can do but bail out
194 194
 			return false;
195 195
 		}
196 196
 
197 197
 		mt_srand(time());
198
-		$filename = $GLOBALS['egw_info']['server']['temp_dir'] . '/'
199
-			. md5( time() + mt_rand() ) . '.tmp';
198
+		$filename = $GLOBALS['egw_info']['server']['temp_dir'].'/'
199
+			. md5(time() + mt_rand()).'.tmp';
200 200
 
201 201
 		$fp = @fopen($filename, 'ab');
202
-		if(!$fp || !$data)
202
+		if (!$fp || !$data)
203 203
 		{
204 204
 			//houston we have a problem - bail out
205 205
 			return false;
206 206
 		}
207 207
 
208
-		if(!fwrite($fp, $data))
208
+		if (!fwrite($fp, $data))
209 209
 		{
210 210
 			//bail out again
211 211
 			return false;
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 
216 216
 		$mime = self::analyze_file($filename);
217 217
 
218
-		unlink($filename);//remove the temp file
218
+		unlink($filename); //remove the temp file
219 219
 
220 220
 		return $mime;
221 221
 	}
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	 * @var array of extenstion to mime mappings
234 234
 	 */
235 235
 	static $mime_extension_map = array(
236
-		'txt'				=> 'text/plain',	// should be first, so text/plain maps back to .txt
236
+		'txt'				=> 'text/plain', // should be first, so text/plain maps back to .txt
237 237
 		'3dml'              => 'text/vnd.in3d.3dml',
238 238
 		'3ds'               => 'image/x-3ds',
239 239
 		'3g2'               => 'video/3gpp2',
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -106,7 +106,10 @@
 block discarded – undo
106 106
 	public static function mime2ext($_type)
107 107
 	{
108 108
 		$type = strtolower($_type);
109
-		if (isset(self::$mime_alias_map[$type])) $type = self::$mime_alias_map[$type];
109
+		if (isset(self::$mime_alias_map[$type]))
110
+		{
111
+			$type = self::$mime_alias_map[$type];
112
+		}
110 113
 		$key = array_search($type, self::$mime_extension_map);
111 114
 		if (empty($type) || $key === false)
112 115
 		{
Please login to merge, or discard this patch.
api/src/Exception.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
 class Exception extends \Exception
30 30
 {
31 31
 	// nothing fancy yet
32
-	function __construct($msg=null,$code=100,\Exception $previous=null)
32
+	function __construct($msg = null, $code = 100, \Exception $previous = null)
33 33
 	{
34 34
 		return parent::__construct($msg, $code, $previous);
35 35
 	}
Please login to merge, or discard this patch.
api/src/Accounts/Ads.php 4 patches
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -807,11 +807,11 @@  discard block
 block discarded – undo
807 807
 	}
808 808
 
809 809
 	/**
810
-	* Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000
811
-	*
812
-	* @param long $unixTime
813
-	* @return long windowsTime
814
-	*/
810
+	 * Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000
811
+	 *
812
+	 * @param long $unixTime
813
+	 * @return long windowsTime
814
+	 */
815 815
 	public static function convertUnixTimeToWindowsTime($unixTime)
816 816
 	{
817 817
 		return ($unixTime + 11644477200) * 10000000;
@@ -1263,10 +1263,10 @@  discard block
 block discarded – undo
1263 1263
 	}
1264 1264
 
1265 1265
 	/**
1266
-    * Convert 8bit characters e.g. accented characters to UTF8 encoded characters
1267
-    *
1268
-    * Extended to use mbstring to convert from arbitrary charset to utf-8
1269
-	*/
1266
+	 * Convert 8bit characters e.g. accented characters to UTF8 encoded characters
1267
+	 *
1268
+	 * Extended to use mbstring to convert from arbitrary charset to utf-8
1269
+	 */
1270 1270
 	protected function encode8Bit(&$item, $key)
1271 1271
 	{
1272 1272
 		if ($this->charset != 'utf-8' && $key != 'password')
@@ -1294,29 +1294,29 @@  discard block
 block discarded – undo
1294 1294
 		return $this->userClass;
1295 1295
 	}
1296 1296
 
1297
-    /**
1298
-    * Get the group class interface
1299
-    *
1300
-    * @return adLDAPGroups
1301
-    */
1302
-    public function group() {
1303
-        if (!$this->groupClass) {
1304
-            $this->groupClass = new adLDAPGroups($this);
1305
-        }
1306
-        return $this->groupClass;
1307
-    }
1308
-
1309
-    /**
1310
-    * Get the utils class interface
1311
-    *
1312
-    * @return adLDAPUtils
1313
-    */
1314
-    public function utilities() {
1315
-        if (!$this->utilClass) {
1316
-            $this->utilClass = new adLDAPUtils($this);
1317
-        }
1318
-        return $this->utilClass;
1319
-    }
1297
+	/**
1298
+	 * Get the group class interface
1299
+	 *
1300
+	 * @return adLDAPGroups
1301
+	 */
1302
+	public function group() {
1303
+		if (!$this->groupClass) {
1304
+			$this->groupClass = new adLDAPGroups($this);
1305
+		}
1306
+		return $this->groupClass;
1307
+	}
1308
+
1309
+	/**
1310
+	 * Get the utils class interface
1311
+	 *
1312
+	 * @return adLDAPUtils
1313
+	 */
1314
+	public function utilities() {
1315
+		if (!$this->utilClass) {
1316
+			$this->utilClass = new adLDAPUtils($this);
1317
+		}
1318
+		return $this->utilClass;
1319
+	}
1320 1320
 }
1321 1321
 
1322 1322
 /**
@@ -1405,45 +1405,45 @@  discard block
 block discarded – undo
1405 1405
 		return true;
1406 1406
 	}
1407 1407
 
1408
-    /**
1409
-    * Encode a password for transmission over LDAP
1410
-    *
1411
-    * Extended to use mbstring to convert from arbitrary charset to UTF-16LE
1412
-    *
1413
-    * @param string $password The password to encode
1414
-    * @return string
1415
-    */
1416
-    public function encodePassword($password)
1417
-    {
1418
-        $password="\"".$password."\"";
1419
-        if (function_exists('mb_convert_encoding'))
1420
-        {
1421
-            return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422
-        }
1423
-        $encoded="";
1424
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1425
-        return $encoded;
1426
-    }
1427
-
1428
-    /**
1429
-     * Set a password
1430
-     *
1431
-     * Requires "Reset password" priviledges from bind user!
1432
-     *
1408
+	/**
1409
+	 * Encode a password for transmission over LDAP
1410
+	 *
1411
+	 * Extended to use mbstring to convert from arbitrary charset to UTF-16LE
1412
+	 *
1413
+	 * @param string $password The password to encode
1414
+	 * @return string
1415
+	 */
1416
+	public function encodePassword($password)
1417
+	{
1418
+		$password="\"".$password."\"";
1419
+		if (function_exists('mb_convert_encoding'))
1420
+		{
1421
+			return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422
+		}
1423
+		$encoded="";
1424
+		for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1425
+		return $encoded;
1426
+	}
1427
+
1428
+	/**
1429
+	 * Set a password
1430
+	 *
1431
+	 * Requires "Reset password" priviledges from bind user!
1432
+	 *
1433 1433
 	 * We can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2!
1434 1434
 	 *
1435
-     * @param string $dn
1436
-     * @param string $password
1437
-     * @return boolean
1438
-     */
1439
-    public function setPassword($dn, $password)
1440
-    {
1441
-    	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1442
-    		'unicodePwd' => $this->encodePassword($password),
1443
-    	));
1444
-    	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1445
-    	return $result;
1446
-    }
1435
+	 * @param string $dn
1436
+	 * @param string $password
1437
+	 * @return boolean
1438
+	 */
1439
+	public function setPassword($dn, $password)
1440
+	{
1441
+		$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1442
+			'unicodePwd' => $this->encodePassword($password),
1443
+		));
1444
+		if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1445
+		return $result;
1446
+	}
1447 1447
 
1448 1448
 	/**
1449 1449
 	 * Check if we can to a real password change, not just a password reset
@@ -1457,30 +1457,30 @@  discard block
 block discarded – undo
1457 1457
 		return function_exists('ldap_modify_batch');
1458 1458
 	}
1459 1459
 
1460
-    /**
1461
-    * Set the password of a user - This must be performed over SSL
1462
-    *
1463
-    * @param string $username The username to modify
1464
-    * @param string $password The new password
1465
-    * @param bool $isGUID Is the username passed a GUID or a samAccountName
1466
-	* @param string $old_password old password for password change, if supported
1467
-    * @return bool
1468
-    */
1469
-    public function password($username, $password, $isGUID = false, $old_password=null)
1470
-    {
1471
-        if ($username === NULL) { return false; }
1472
-        if ($password === NULL) { return false; }
1473
-        if (!$this->adldap->getLdapBind()) { return false; }
1474
-        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1475
-            throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1476
-        }
1477
-
1478
-        $userDn = $this->dn($username, $isGUID);
1479
-        if ($userDn === false) {
1480
-            return false;
1481
-        }
1482
-
1483
-        $add=array();
1460
+	/**
1461
+	 * Set the password of a user - This must be performed over SSL
1462
+	 *
1463
+	 * @param string $username The username to modify
1464
+	 * @param string $password The new password
1465
+	 * @param bool $isGUID Is the username passed a GUID or a samAccountName
1466
+	 * @param string $old_password old password for password change, if supported
1467
+	 * @return bool
1468
+	 */
1469
+	public function password($username, $password, $isGUID = false, $old_password=null)
1470
+	{
1471
+		if ($username === NULL) { return false; }
1472
+		if ($password === NULL) { return false; }
1473
+		if (!$this->adldap->getLdapBind()) { return false; }
1474
+		if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1475
+			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1476
+		}
1477
+
1478
+		$userDn = $this->dn($username, $isGUID);
1479
+		if ($userDn === false) {
1480
+			return false;
1481
+		}
1482
+
1483
+		$add=array();
1484 1484
 
1485 1485
 		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1486 1486
 			$add["unicodePwd"][0] = $this->encodePassword($password);
@@ -1502,76 +1502,76 @@  discard block
 block discarded – undo
1502 1502
 			);
1503 1503
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1504 1504
 		}
1505
-        if ($result === false){
1506
-            $err = ldap_errno($this->adldap->getLdapConnection());
1507
-            if ($err) {
1508
-                $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
-                if($err == 53) {
1510
-                    $msg .= ' Your password might not match the password policy.';
1511
-                }
1512
-                throw new adLDAPException($msg);
1513
-            }
1514
-            else {
1515
-                return false;
1516
-            }
1517
-        }
1518
-
1519
-        return true;
1520
-    }
1521
-
1522
-    /**
1523
-    * Modify a user
1524
-    *
1525
-    * @param string $username The username to query
1526
-    * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527
-    * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
-    * @return bool
1529
-    */
1530
-    public function modify($username, $attributes, $isGUID = false)
1531
-    {
1532
-        if ($username === NULL) { return "Missing compulsory field [username]"; }
1533
-        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1534
-            throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1535
-        }
1536
-
1537
-        // Find the dn of the user
1538
-        $userDn = $this->dn($username, $isGUID);
1539
-        if ($userDn === false) {
1540
-            return false;
1541
-        }
1542
-
1543
-        // Translate the update to the LDAP schema
1544
-        $mod = $this->adldap->adldap_schema($attributes);
1545
-
1546
-        // Check to see if this is an enabled status update
1547
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1548
-            return false;
1549
-        }
1550
-
1551
-        // Set the account control attribute (only if specified)
1552
-        if (array_key_exists("enabled", $attributes)){
1553
-            if ($attributes["enabled"]){
1554
-                $controlOptions = array("NORMAL_ACCOUNT");
1555
-            }
1556
-            else {
1557
-                $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1558
-            }
1559
-            $mod["userAccountControl"][0] = $this->accountControl($controlOptions);
1560
-        }
1505
+		if ($result === false){
1506
+			$err = ldap_errno($this->adldap->getLdapConnection());
1507
+			if ($err) {
1508
+				$msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
+				if($err == 53) {
1510
+					$msg .= ' Your password might not match the password policy.';
1511
+				}
1512
+				throw new adLDAPException($msg);
1513
+			}
1514
+			else {
1515
+				return false;
1516
+			}
1517
+		}
1518
+
1519
+		return true;
1520
+	}
1521
+
1522
+	/**
1523
+	 * Modify a user
1524
+	 *
1525
+	 * @param string $username The username to query
1526
+	 * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527
+	 * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
+	 * @return bool
1529
+	 */
1530
+	public function modify($username, $attributes, $isGUID = false)
1531
+	{
1532
+		if ($username === NULL) { return "Missing compulsory field [username]"; }
1533
+		if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1534
+			throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1535
+		}
1536
+
1537
+		// Find the dn of the user
1538
+		$userDn = $this->dn($username, $isGUID);
1539
+		if ($userDn === false) {
1540
+			return false;
1541
+		}
1542
+
1543
+		// Translate the update to the LDAP schema
1544
+		$mod = $this->adldap->adldap_schema($attributes);
1545
+
1546
+		// Check to see if this is an enabled status update
1547
+		if (!$mod && !array_key_exists("enabled", $attributes)){
1548
+			return false;
1549
+		}
1550
+
1551
+		// Set the account control attribute (only if specified)
1552
+		if (array_key_exists("enabled", $attributes)){
1553
+			if ($attributes["enabled"]){
1554
+				$controlOptions = array("NORMAL_ACCOUNT");
1555
+			}
1556
+			else {
1557
+				$controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1558
+			}
1559
+			$mod["userAccountControl"][0] = $this->accountControl($controlOptions);
1560
+		}
1561 1561
 		// we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2
1562 1562
 		unset($mod['unicodePwd']);
1563 1563
 
1564 1564
 		if ($mod)
1565 1565
 		{
1566
-	        // Do the update
1567
-	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1568
-	        if ($result == false) {
1566
+			// Do the update
1567
+			$result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1568
+			if ($result == false) {
1569 1569
 				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1570 1570
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1571
-	        	return false;
1572
-	        }
1571
+				return false;
1572
+			}
1573 1573
 		}
1574
-        if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1574
+		if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1575 1575
 		{
1576 1576
 			return false;
1577 1577
 		}
@@ -1636,23 +1636,23 @@  discard block
 block discarded – undo
1636 1636
 		return $this->adldap->encode8bit($item, $key);
1637 1637
 	}
1638 1638
 
1639
-    /**
1640
-    * Escape strings for the use in LDAP filters
1641
-    *
1642
-    * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT
1643
-    * Ported from Perl's Net::LDAP::Util escape_filter_value
1644
-    *
1645
-    * @param string $str The string the parse
1646
-    * @author Port by Andreas Gohr <[email protected]>
1647
-    * @return string
1648
-    */
1649
-    public function ldapSlashes($str){
1650
-        return preg_replace_callback(
1651
-      		'/([\x00-\x1F\*\(\)\\\\])/',
1652
-        	function ($matches) {
1653
-            	return "\\".join("", unpack("H2", $matches[1]));
1654
-        	},
1655
-        	$str
1656
-    	);
1657
-    }
1639
+	/**
1640
+	 * Escape strings for the use in LDAP filters
1641
+	 *
1642
+	 * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT
1643
+	 * Ported from Perl's Net::LDAP::Util escape_filter_value
1644
+	 *
1645
+	 * @param string $str The string the parse
1646
+	 * @author Port by Andreas Gohr <[email protected]>
1647
+	 * @return string
1648
+	 */
1649
+	public function ldapSlashes($str){
1650
+		return preg_replace_callback(
1651
+	  		'/([\x00-\x1F\*\(\)\\\\])/',
1652
+			function ($matches) {
1653
+				return "\\".join("", unpack("H2", $matches[1]));
1654
+			},
1655
+			$str
1656
+		);
1657
+	}
1658 1658
 }
Please login to merge, or discard this patch.
Braces   +234 added lines, -78 removed lines patch added patch discarded remove patch
@@ -136,12 +136,21 @@  discard block
 block discarded – undo
136 136
 	public static function get_adldap(array &$config=null)
137 137
 	{
138 138
 		static $adldap = array();
139
-		if (!$config) $config =& $GLOBALS['egw_info']['server'];
139
+		if (!$config)
140
+		{
141
+			$config =& $GLOBALS['egw_info']['server'];
142
+		}
140 143
 
141 144
 		if (!isset($adldap[$config['ads_domain']]))
142 145
 		{
143
-			if (empty($config['ads_host'])) throw new Api\Exception("Required ADS host name(s) missing!");
144
-			if (empty($config['ads_domain'])) throw new Api\Exception("Required ADS domain missing!");
146
+			if (empty($config['ads_host']))
147
+			{
148
+				throw new Api\Exception("Required ADS host name(s) missing!");
149
+			}
150
+			if (empty($config['ads_domain']))
151
+			{
152
+				throw new Api\Exception("Required ADS domain missing!");
153
+			}
145 154
 
146 155
 			$base_dn_parts = array();
147 156
 			foreach(explode('.', $config['ads_domain']) as $dc)
@@ -160,7 +169,10 @@  discard block
 block discarded – undo
160 169
 				'charset' => Api\Translation::charset(),
161 170
 			);
162 171
 			$adldap[$config['ads_domain']] = new adLDAP($options);
163
-			if (self::$debug) error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
172
+			if (self::$debug)
173
+			{
174
+				error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
175
+			}
164 176
 		}
165 177
 		//else error_log(__METHOD__."() returning cached adLDAP ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
166 178
 		return $adldap[$config['ads_domain']];
@@ -241,7 +253,10 @@  discard block
 block discarded – undo
241 253
 			throw new Api\Exception\WrongUserinput("Wrong or not configured ADS context '$context' (baseDN='$base')!");
242 254
 		}
243 255
 		$container = $matches[1];
244
-		if (self::$debug) error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container));
256
+		if (self::$debug)
257
+		{
258
+			error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container));
259
+		}
245 260
 		return $container;
246 261
 	}
247 262
 
@@ -334,10 +349,16 @@  discard block
 block discarded – undo
334 349
 	 */
335 350
 	public function read($account_id)
336 351
 	{
337
-		if (!(int)$account_id) return false;
352
+		if (!(int)$account_id)
353
+		{
354
+			return false;
355
+		}
338 356
 
339 357
 		$ret = $account_id < 0 ? $this->_read_group($account_id) : $this->_read_user($account_id);
340
-		if (self::$debug) error_log(__METHOD__."($account_id) returning ".array2string($ret));
358
+		if (self::$debug)
359
+		{
360
+			error_log(__METHOD__."($account_id) returning ".array2string($ret));
361
+		}
341 362
 		return $ret;
342 363
 	}
343 364
 
@@ -370,7 +391,10 @@  discard block
 block discarded – undo
370 391
 		}
371 392
 		$ret = $is_group ? $this->_save_group($data, $old) : $this->_save_user($data, $old);
372 393
 
373
-		if (self::$debug) error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret));
394
+		if (self::$debug)
395
+		{
396
+			error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret));
397
+		}
374 398
 		return $ret;
375 399
 	}
376 400
 
@@ -400,7 +424,10 @@  discard block
 block discarded – undo
400 424
 		{
401 425
 			$ret = $this->adldap->user()->delete($account_lid);
402 426
 		}
403
-		if (self::$debug) error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret));
427
+		if (self::$debug)
428
+		{
429
+			error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret));
430
+		}
404 431
 		return $ret;
405 432
 	}
406 433
 
@@ -562,11 +589,17 @@  discard block
 block discarded – undo
562 589
 	protected static function _when2ts($_when)
563 590
 	{
564 591
 		static $utc=null;
565
-		if (!isset($utc)) $utc = new \DateTimeZone('UTC');
592
+		if (!isset($utc))
593
+		{
594
+			$utc = new \DateTimeZone('UTC');
595
+		}
566 596
 
567 597
 		list($when) = explode('.', $_when);	// remove .0Z not understood by createFromFormat
568 598
 		$datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc);
569
-		if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone);
599
+		if (Api\DateTime::$server_timezone)
600
+		{
601
+			$datetime->setTimezone(Api\DateTime::$server_timezone);
602
+		}
570 603
 
571 604
 		return $datetime->getTimestamp();
572 605
 	}
@@ -583,12 +616,15 @@  discard block
 block discarded – undo
583 616
 	{
584 617
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
585 618
 
586
-		if (!$old)	// new entry
619
+		if (!$old)
620
+		{
621
+			// new entry
587 622
 		{
588 623
 			static $new2adldap = array(
589 624
 				'account_lid'       => 'group_name',
590 625
 				'account_description' => 'description',
591 626
 			);
627
+		}
592 628
 			$attributes = array();
593 629
 			foreach($new2adldap as $egw => $adldap)
594 630
 			{
@@ -668,7 +704,9 @@  discard block
 block discarded – undo
668 704
 			$data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname'];
669 705
 		}
670 706
 
671
-		if (($new_entry = !$old))	// new entry
707
+		if (($new_entry = !$old))
708
+		{
709
+			// new entry
672 710
 		{
673 711
 			static $new2adldap = array(
674 712
 				'account_lid'       => 'username',
@@ -679,6 +717,7 @@  discard block
 block discarded – undo
679 717
 				'account_passwd'    => 'password',
680 718
 				'account_status'    => 'enabled',
681 719
 			);
720
+		}
682 721
 			$attributes = array();
683 722
 			foreach($new2adldap as $egw => $adldap)
684 723
 			{
@@ -687,7 +726,10 @@  discard block
 block discarded – undo
687 726
 				{
688 727
 					continue;	// do not try to set password, if no SSL or TLS, whole user creation will fail
689 728
 				}
690
-				if (isset($data[$egw])) $attributes[$adldap] = $data[$egw];
729
+				if (isset($data[$egw]))
730
+				{
731
+					$attributes[$adldap] = $data[$egw];
732
+				}
691 733
 			}
692 734
 			$attributes['enabled'] = !isset($data['account_status']) || $data['account_status'] === 'A';
693 735
 			$attributes['container'] = $this->_get_container();
@@ -773,7 +815,11 @@  discard block
 block discarded – undo
773 815
 							self::convertUnixTimeToWindowsTime($data[$egw]);
774 816
 						break;
775 817
 					case 'account_status':
776
-						if ($new_entry && empty($data['account_passwd'])) continue;	// cant active new account without passwd!
818
+						if ($new_entry && empty($data['account_passwd']))
819
+						{
820
+							continue;
821
+						}
822
+						// cant active new account without passwd!
777 823
 						$attributes[$adldap] = $data[$egw] == 'A';
778 824
 						break;
779 825
 					case 'account_lastpwd_change':
@@ -853,8 +899,14 @@  discard block
 block discarded – undo
853 899
 		}
854 900
 		// if it's a limited query, check if the unlimited query is cached
855 901
 		$start = $param['start'];
856
-		if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15;
857
-		if (!($offset = $param['offset'])) $offset = $maxmatchs;
902
+		if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']))
903
+		{
904
+			$maxmatchs = 15;
905
+		}
906
+		if (!($offset = $param['offset']))
907
+		{
908
+			$offset = $maxmatchs;
909
+		}
858 910
 		unset($param['start']);
859 911
 		unset($param['offset']);
860 912
 		$unl_serial = serialize($param);
@@ -1051,7 +1103,10 @@  discard block
 block discarded – undo
1051 1103
 			$attrs ? $attrs : self::$default_attributes);
1052 1104
 		if (!$sri)
1053 1105
 		{
1054
-			if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1106
+			if (self::$debug)
1107
+			{
1108
+				error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1109
+			}
1055 1110
 			$sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter,
1056 1111
 				$attrs ? $attrs : self::$default_attributes);
1057 1112
 		}
@@ -1060,7 +1115,10 @@  discard block
 block discarded – undo
1060 1115
 		{
1061 1116
 			foreach($allValues as $key => $data)
1062 1117
 			{
1063
-				if ($key === 'count') continue;
1118
+				if ($key === 'count')
1119
+				{
1120
+					continue;
1121
+				}
1064 1122
 
1065 1123
 				if ($account_type && !($account_type == 'u' && $data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT ||
1066 1124
 					$account_type == 'g' && $data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP))
@@ -1078,7 +1136,10 @@  discard block
 block discarded – undo
1078 1136
 					$attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8');
1079 1137
 			}
1080 1138
 		}
1081
-		else if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues));
1139
+		else if (self::$debug)
1140
+		{
1141
+			error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues));
1142
+		}
1082 1143
 
1083 1144
 		//error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returning ".array2string($accounts).' '.function_backtrace());
1084 1145
 		return $accounts;
@@ -1115,7 +1176,10 @@  discard block
 block discarded – undo
1115 1176
 				break;
1116 1177
 			}
1117 1178
 		}
1118
-		if (self::$debug) error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret));
1179
+		if (self::$debug)
1180
+		{
1181
+			error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret));
1182
+		}
1119 1183
 		return $ret;
1120 1184
 	}
1121 1185
 
@@ -1157,7 +1221,10 @@  discard block
 block discarded – undo
1157 1221
 	 */
1158 1222
 	function memberships($account_id)
1159 1223
 	{
1160
-		if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0) return false;
1224
+		if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0)
1225
+		{
1226
+			return false;
1227
+		}
1161 1228
 
1162 1229
 		return $data['memberships'];
1163 1230
 	}
@@ -1172,7 +1239,10 @@  discard block
 block discarded – undo
1172 1239
 	 */
1173 1240
 	function members($gid)
1174 1241
 	{
1175
-		if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0) return false;
1242
+		if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0)
1243
+		{
1244
+			return false;
1245
+		}
1176 1246
 
1177 1247
 		return $data['members'];
1178 1248
 	}
@@ -1186,7 +1256,10 @@  discard block
 block discarded – undo
1186 1256
 	 */
1187 1257
 	function set_memberships($groups,$account_id)
1188 1258
 	{
1189
-		if (!($account = $this->id2name($account_id))) return;
1259
+		if (!($account = $this->id2name($account_id)))
1260
+		{
1261
+			return;
1262
+		}
1190 1263
 		$current = array_keys($this->memberships($account_id));
1191 1264
 
1192 1265
 		$changed = 0;
@@ -1203,7 +1276,10 @@  discard block
 block discarded – undo
1203 1276
 				$changed += (int)$ok;
1204 1277
 			}
1205 1278
 		}
1206
-		if (self::$debug) error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed");
1279
+		if (self::$debug)
1280
+		{
1281
+			error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed");
1282
+		}
1207 1283
 		return $changed;
1208 1284
 	}
1209 1285
 
@@ -1216,7 +1292,10 @@  discard block
 block discarded – undo
1216 1292
 	 */
1217 1293
 	function set_members($users, $gid)
1218 1294
 	{
1219
-		if (!($group = $this->id2name($gid))) return;
1295
+		if (!($group = $this->id2name($gid)))
1296
+		{
1297
+			return;
1298
+		}
1220 1299
 		$current = array_keys($this->members($gid));
1221 1300
 
1222 1301
 		$changed = 0;
@@ -1233,7 +1312,10 @@  discard block
 block discarded – undo
1233 1312
 				$changed += (int)$ok;
1234 1313
 			}
1235 1314
 		}
1236
-		if (self::$debug) error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed");
1315
+		if (self::$debug)
1316
+		{
1317
+			error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed");
1318
+		}
1237 1319
 		return $changed;
1238 1320
 	}
1239 1321
 }
@@ -1287,8 +1369,10 @@  discard block
 block discarded – undo
1287 1369
 	 *
1288 1370
 	 * @return adLDAPUsers
1289 1371
 	 */
1290
-	public function user() {
1291
-		if (!$this->userClass) {
1372
+	public function user()
1373
+	{
1374
+		if (!$this->userClass)
1375
+		{
1292 1376
 			$this->userClass = new adLDAPUsers($this);
1293 1377
 		}
1294 1378
 		return $this->userClass;
@@ -1299,8 +1383,10 @@  discard block
 block discarded – undo
1299 1383
     *
1300 1384
     * @return adLDAPGroups
1301 1385
     */
1302
-    public function group() {
1303
-        if (!$this->groupClass) {
1386
+    public function group()
1387
+    {
1388
+        if (!$this->groupClass)
1389
+        {
1304 1390
             $this->groupClass = new adLDAPGroups($this);
1305 1391
         }
1306 1392
         return $this->groupClass;
@@ -1311,8 +1397,10 @@  discard block
 block discarded – undo
1311 1397
     *
1312 1398
     * @return adLDAPUtils
1313 1399
     */
1314
-    public function utilities() {
1315
-        if (!$this->utilClass) {
1400
+    public function utilities()
1401
+    {
1402
+        if (!$this->utilClass)
1403
+        {
1316 1404
             $this->utilClass = new adLDAPUtils($this);
1317 1405
         }
1318 1406
         return $this->utilClass;
@@ -1340,18 +1428,32 @@  discard block
 block discarded – undo
1340 1428
 	public function create($attributes)
1341 1429
 	{
1342 1430
 		// Check for compulsory fields
1343
-		if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; }
1344
-		if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; }
1345
-		if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; }
1346
-		if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; }
1347
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1348
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1349
-
1350
-		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){
1431
+		if (!array_key_exists("username", $attributes))
1432
+		{
1433
+return "Missing compulsory field [username]"; }
1434
+		if (!array_key_exists("firstname", $attributes))
1435
+		{
1436
+return "Missing compulsory field [firstname]"; }
1437
+		if (!array_key_exists("surname", $attributes))
1438
+		{
1439
+return "Missing compulsory field [surname]"; }
1440
+		if (!array_key_exists("email", $attributes))
1441
+		{
1442
+return "Missing compulsory field [email]"; }
1443
+		if (!array_key_exists("container", $attributes))
1444
+		{
1445
+return "Missing compulsory field [container]"; }
1446
+		if (empty($attributes["container"]))
1447
+		{
1448
+return "Container attribute must be an array or string."; }
1449
+
1450
+		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()))
1451
+		{
1351 1452
 			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1352 1453
 		}
1353 1454
 
1354
-		if (!array_key_exists("display_name", $attributes)) {
1455
+		if (!array_key_exists("display_name", $attributes))
1456
+		{
1355 1457
 			$attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"];
1356 1458
 		}
1357 1459
 
@@ -1373,7 +1475,8 @@  discard block
 block discarded – undo
1373 1475
 		$add["userAccountControl"][0] = $this->accountControl($control_options);
1374 1476
 
1375 1477
 		// Determine the container
1376
-		if (is_array($attributes['container'])) {
1478
+		if (is_array($attributes['container']))
1479
+		{
1377 1480
 			$attributes["container"] = array_reverse($attributes["container"]);
1378 1481
 			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1379 1482
 		}
@@ -1382,7 +1485,8 @@  discard block
 block discarded – undo
1382 1485
 
1383 1486
 		// Add the entry
1384 1487
 		$result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1385
-		if ($result != true) {
1488
+		if ($result != true)
1489
+		{
1386 1490
 			error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1387 1491
 			return false;
1388 1492
 		}
@@ -1390,7 +1494,10 @@  discard block
 block discarded – undo
1390 1494
 		// now password can be added to still disabled account
1391 1495
 		if (array_key_exists("password",$attributes))
1392 1496
 		{
1393
-			if (!$this->setPassword($dn, $attributes['password'])) return false;
1497
+			if (!$this->setPassword($dn, $attributes['password']))
1498
+			{
1499
+				return false;
1500
+			}
1394 1501
 
1395 1502
 			// now account can be enabled
1396 1503
 			if ($attributes["enabled"])
@@ -1398,7 +1505,10 @@  discard block
 block discarded – undo
1398 1505
 				$control_options = array("NORMAL_ACCOUNT");
1399 1506
 				$mod = array("userAccountControl" => $this->accountControl($control_options));
1400 1507
 				$result = ldap_modify($ds, $dn, $mod);
1401
-				if (!$result) error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1508
+				if (!$result)
1509
+				{
1510
+					error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1511
+				}
1402 1512
 			}
1403 1513
 		}
1404 1514
 
@@ -1421,7 +1531,9 @@  discard block
 block discarded – undo
1421 1531
             return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422 1532
         }
1423 1533
         $encoded="";
1424
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1534
+        for ($i=0; $i <strlen($password); $i++)
1535
+        {
1536
+$encoded.="{$password{$i}}\000"; }
1425 1537
         return $encoded;
1426 1538
     }
1427 1539
 
@@ -1441,7 +1553,10 @@  discard block
 block discarded – undo
1441 1553
     	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1442 1554
     		'unicodePwd' => $this->encodePassword($password),
1443 1555
     	));
1444
-    	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1556
+    	if (!$result)
1557
+    	{
1558
+    		error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1559
+    	}
1445 1560
     	return $result;
1446 1561
     }
1447 1562
 
@@ -1468,26 +1583,36 @@  discard block
 block discarded – undo
1468 1583
     */
1469 1584
     public function password($username, $password, $isGUID = false, $old_password=null)
1470 1585
     {
1471
-        if ($username === NULL) { return false; }
1472
-        if ($password === NULL) { return false; }
1473
-        if (!$this->adldap->getLdapBind()) { return false; }
1474
-        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1586
+        if ($username === NULL)
1587
+        {
1588
+return false; }
1589
+        if ($password === NULL)
1590
+        {
1591
+return false; }
1592
+        if (!$this->adldap->getLdapBind())
1593
+        {
1594
+return false; }
1595
+        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())
1596
+        {
1475 1597
             throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1476 1598
         }
1477 1599
 
1478 1600
         $userDn = $this->dn($username, $isGUID);
1479
-        if ($userDn === false) {
1601
+        if ($userDn === false)
1602
+        {
1480 1603
             return false;
1481 1604
         }
1482 1605
 
1483 1606
         $add=array();
1484 1607
 
1485
-		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1608
+		if (empty($old_password) || !function_exists('ldap_modify_batch'))
1609
+		{
1486 1610
 			$add["unicodePwd"][0] = $this->encodePassword($password);
1487 1611
 
1488 1612
 			$result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $add);
1489 1613
 		}
1490
-		else {
1614
+		else
1615
+		{
1491 1616
 			$mods = array(
1492 1617
 				array(
1493 1618
 					"attrib"  => "unicodePwd",
@@ -1502,16 +1627,20 @@  discard block
 block discarded – undo
1502 1627
 			);
1503 1628
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1504 1629
 		}
1505
-        if ($result === false){
1630
+        if ($result === false)
1631
+        {
1506 1632
             $err = ldap_errno($this->adldap->getLdapConnection());
1507
-            if ($err) {
1633
+            if ($err)
1634
+            {
1508 1635
                 $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
-                if($err == 53) {
1636
+                if($err == 53)
1637
+                {
1510 1638
                     $msg .= ' Your password might not match the password policy.';
1511 1639
                 }
1512 1640
                 throw new adLDAPException($msg);
1513 1641
             }
1514
-            else {
1642
+            else
1643
+            {
1515 1644
                 return false;
1516 1645
             }
1517 1646
         }
@@ -1529,14 +1658,18 @@  discard block
 block discarded – undo
1529 1658
     */
1530 1659
     public function modify($username, $attributes, $isGUID = false)
1531 1660
     {
1532
-        if ($username === NULL) { return "Missing compulsory field [username]"; }
1533
-        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1661
+        if ($username === NULL)
1662
+        {
1663
+return "Missing compulsory field [username]"; }
1664
+        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())
1665
+        {
1534 1666
             throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1535 1667
         }
1536 1668
 
1537 1669
         // Find the dn of the user
1538 1670
         $userDn = $this->dn($username, $isGUID);
1539
-        if ($userDn === false) {
1671
+        if ($userDn === false)
1672
+        {
1540 1673
             return false;
1541 1674
         }
1542 1675
 
@@ -1544,16 +1677,20 @@  discard block
 block discarded – undo
1544 1677
         $mod = $this->adldap->adldap_schema($attributes);
1545 1678
 
1546 1679
         // Check to see if this is an enabled status update
1547
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1680
+        if (!$mod && !array_key_exists("enabled", $attributes))
1681
+        {
1548 1682
             return false;
1549 1683
         }
1550 1684
 
1551 1685
         // Set the account control attribute (only if specified)
1552
-        if (array_key_exists("enabled", $attributes)){
1553
-            if ($attributes["enabled"]){
1686
+        if (array_key_exists("enabled", $attributes))
1687
+        {
1688
+            if ($attributes["enabled"])
1689
+            {
1554 1690
                 $controlOptions = array("NORMAL_ACCOUNT");
1555 1691
             }
1556
-            else {
1692
+            else
1693
+            {
1557 1694
                 $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1558 1695
             }
1559 1696
             $mod["userAccountControl"][0] = $this->accountControl($controlOptions);
@@ -1565,14 +1702,18 @@  discard block
 block discarded – undo
1565 1702
 		{
1566 1703
 	        // Do the update
1567 1704
 	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1568
-	        if ($result == false) {
1569
-				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1705
+	        if ($result == false)
1706
+	        {
1707
+				if (isset($mod['unicodePwd']))
1708
+				{
1709
+					$mod['unicodePwd'] = '***';
1710
+				}
1570 1711
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1571 1712
 	        	return false;
1572 1713
 	        }
1573 1714
 		}
1574 1715
         if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1575
-		{
1716
+        {
1576 1717
 			return false;
1577 1718
 		}
1578 1719
 		return true;
@@ -1594,10 +1735,18 @@  discard block
 block discarded – undo
1594 1735
 	 */
1595 1736
 	public function create($attributes)
1596 1737
 	{
1597
-		if (!is_array($attributes)){ return "Attributes must be an array"; }
1598
-		if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; }
1599
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1600
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1738
+		if (!is_array($attributes))
1739
+		{
1740
+return "Attributes must be an array"; }
1741
+		if (!array_key_exists("group_name", $attributes))
1742
+		{
1743
+return "Missing compulsory field [group_name]"; }
1744
+		if (!array_key_exists("container", $attributes))
1745
+		{
1746
+return "Missing compulsory field [container]"; }
1747
+		if (empty($attributes["container"]))
1748
+		{
1749
+return "Container attribute must be an array or string."; }
1601 1750
 
1602 1751
 		//$member_array = array();
1603 1752
 		//$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com";
@@ -1607,16 +1756,21 @@  discard block
 block discarded – undo
1607 1756
 		$add["cn"] = $attributes["group_name"];
1608 1757
 		$add["samaccountname"] = $attributes["group_name"];
1609 1758
 		$add["objectClass"] = "Group";
1610
-		if (!empty($attributes["description"])) $add["description"] = $attributes["description"];
1759
+		if (!empty($attributes["description"]))
1760
+		{
1761
+			$add["description"] = $attributes["description"];
1762
+		}
1611 1763
 		//$add["member"] = $member_array; UNTESTED
1612 1764
 
1613 1765
 		// Determine the container
1614
-		if (is_array($attributes['container'])) {
1766
+		if (is_array($attributes['container']))
1767
+		{
1615 1768
 			$attributes["container"] = array_reverse($attributes["container"]);
1616 1769
 			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1617 1770
 		}
1618 1771
 		$result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1619
-		if ($result != true) {
1772
+		if ($result != true)
1773
+		{
1620 1774
 			return false;
1621 1775
 		}
1622 1776
 		return true;
@@ -1646,10 +1800,12 @@  discard block
 block discarded – undo
1646 1800
     * @author Port by Andreas Gohr <[email protected]>
1647 1801
     * @return string
1648 1802
     */
1649
-    public function ldapSlashes($str){
1803
+    public function ldapSlashes($str)
1804
+    {
1650 1805
         return preg_replace_callback(
1651 1806
       		'/([\x00-\x1F\*\(\)\\\\])/',
1652
-        	function ($matches) {
1807
+        	function ($matches)
1808
+        	{
1653 1809
             	return "\\".join("", unpack("H2", $matches[1]));
1654 1810
         	},
1655 1811
         	$str
Please login to merge, or discard this patch.
Doc Comments   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	/**
130 130
 	 * Factory method and singelton to get adLDAP object for given configuration or default server config
131 131
 	 *
132
-	 * @param array $config=null values for keys 'ads_domain', 'ads_host' (required) and optional 'ads_admin_user', 'ads_admin_passwd', 'ads_connection'
132
+	 * @param array $config values for keys 'ads_domain', 'ads_host' (required) and optional 'ads_admin_user', 'ads_admin_passwd', 'ads_connection'
133 133
 	 * @return adLDAP
134 134
 	 * @throws adLDAPException
135 135
 	 */
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	 * Convert binary GUID to string
309 309
 	 *
310 310
 	 * @param string $objectguid
311
-	 * @return int
311
+	 * @return string
312 312
 	 */
313 313
 	public function objectguid2str($objectguid)
314 314
 	{
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * Convert a string GUID to hex string used in filter
320 320
 	 *
321 321
 	 * @param string $strGUID
322
-	 * @return int
322
+	 * @return string
323 323
 	 */
324 324
 	public function objectguid2hex($strGUID)
325 325
 	{
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	 * Delete one account, deletes also all acl-entries for that account
379 379
 	 *
380 380
 	 * @param int $account_id numeric account_id
381
-	 * @return boolean true on success, false otherwise
381
+	 * @return string|boolean true on success, false otherwise
382 382
 	 */
383 383
 	function delete($account_id)
384 384
 	{
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 	 *
1139 1139
 	 * @param int $_account_id
1140 1140
 	 * @param string $ip
1141
-	 * @return int lastlogin time
1141
+	 * @return boolean lastlogin time
1142 1142
 	 */
1143 1143
 	function update_lastlogin($_account_id, $ip)
1144 1144
 	{
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 	 * - activate user
1336 1336
 	 *
1337 1337
 	 * @param array $attributes The attributes to set to the user account
1338
-	 * @return bool
1338
+	 * @return string|boolean
1339 1339
 	 */
1340 1340
 	public function create($attributes)
1341 1341
 	{
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
     * @param string $username The username to query
1526 1526
     * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527 1527
     * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
-    * @return bool
1528
+    * @return string|boolean
1529 1529
     */
1530 1530
     public function modify($username, $attributes, $isGUID = false)
1531 1531
     {
@@ -1590,7 +1590,7 @@  discard block
 block discarded – undo
1590 1590
 	 * Extended to allow to specify $attribute["container"] as string, because array hardcodes "OU=", while Samba4 and win2008r2 uses "CN=Users"
1591 1591
 	 *
1592 1592
 	 * @param array $attributes Default attributes of the group
1593
-	 * @return bool
1593
+	 * @return string|boolean
1594 1594
 	 */
1595 1595
 	public function create($attributes)
1596 1596
 	{
Please login to merge, or discard this patch.
Spacing   +109 added lines, -114 removed lines patch added patch discarded remove patch
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	 * @return adLDAP
134 134
 	 * @throws adLDAPException
135 135
 	 */
136
-	public static function get_adldap(array &$config=null)
136
+	public static function get_adldap(array &$config = null)
137 137
 	{
138 138
 		static $adldap = array();
139
-		if (!$config) $config =& $GLOBALS['egw_info']['server'];
139
+		if (!$config) $config = & $GLOBALS['egw_info']['server'];
140 140
 
141 141
 		if (!isset($adldap[$config['ads_domain']]))
142 142
 		{
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			if (empty($config['ads_domain'])) throw new Api\Exception("Required ADS domain missing!");
145 145
 
146 146
 			$base_dn_parts = array();
147
-			foreach(explode('.', $config['ads_domain']) as $dc)
147
+			foreach (explode('.', $config['ads_domain']) as $dc)
148 148
 			{
149 149
 				$base_dn_parts[] = 'DC='.$dc;
150 150
 			}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @param int $account_id
173 173
 	 * @return string|NULL
174 174
 	 */
175
-	protected function get_sid($account_id=null)
175
+	protected function get_sid($account_id = null)
176 176
 	{
177 177
 		static $domain_sid = null;
178 178
 		if (!isset($domain_sid))
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
 	 * @param boolean $set_if_empty =false true set from DN of "Domain Users" group #
208 208
 	 * @return string
209 209
 	 */
210
-	public function ads_context($set_if_empty=false)
210
+	public function ads_context($set_if_empty = false)
211 211
 	{
212 212
 		if (empty($this->frontend->config[self::ADS_CONTEXT]))
213 213
 		{
214 214
 			if ($set_if_empty && ($dn = $this->id2name(-self::DOMAIN_USERS_GROUP, 'account_dn')))
215 215
 			{
216 216
 				$dn = preg_replace('/^CN=.*?,(CN|OU)=/i', '$1=', $dn);
217
-				Api\Config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT]=$dn, 'phpgwapi');
217
+				Api\Config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT] = $dn, 'phpgwapi');
218 218
 			}
219 219
 			else
220 220
 			{
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * @param boolean $reconnect =false true: reconnect even if already connected
252 252
 	 * @return resource
253 253
 	 */
254
-	public function ldap_connection($reconnect=false)
254
+	public function ldap_connection($reconnect = false)
255 255
 	{
256 256
 		if (($reconnect || !($ds = $this->adldap->getLdapConnection())) &&
257 257
 			// call connect, thought I dont know how it can be not connected ...
@@ -415,8 +415,7 @@  discard block
 block discarded – undo
415 415
 		$data = Api\Translation::convert($_data, 'utf-8');
416 416
 
417 417
 		// no need to calculate sid, if already calculated
418
-		$sid = is_string($data['objectsid']) ? $data['objectsid'] :
419
-			$this->adldap->utilities()->getTextSID($data['objectsid'][0]);
418
+		$sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]);
420 419
 		$account_id = -self::sid2account_id($sid);
421 420
 
422 421
 		$group = array(
@@ -453,7 +452,7 @@  discard block
 block discarded – undo
453 452
 	{
454 453
 		if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'g', self::$group_attributes)))
455 454
 		{
456
-			return false;	// group not found
455
+			return false; // group not found
457 456
 		}
458 457
 		$group = $this->_ldap2group(array_shift($data));
459 458
 
@@ -476,8 +475,7 @@  discard block
 block discarded – undo
476 475
 		$data = Api\Translation::convert($_data, 'utf-8');
477 476
 
478 477
 		// no need to calculate sid, if already calculated
479
-		$sid = is_string($data['objectsid']) ? $data['objectsid'] :
480
-			$this->adldap->utilities()->getTextSID($data['objectsid'][0]);
478
+		$sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]);
481 479
 		$account_id = self::sid2account_id($sid);
482 480
 
483 481
 		$user = array(
@@ -493,11 +491,9 @@  discard block
 block discarded – undo
493 491
 			'account_email'     => $data['mail'][0],
494 492
 			'account_fullname'  => $data['displayname'][0],
495 493
 			'account_phone'     => $data['telephonenumber'][0],
496
-			'account_status'    => $data['useraccountcontrol'][0] & 2 ? false : 'A',
497
-			'account_expires'   => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 :
498
-				$this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]),
499
-			'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 :
500
-				$this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])),
494
+			'account_status'    => $data['useraccountcontrol'][0]&2 ? false : 'A',
495
+			'account_expires'   => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]),
496
+			'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])),
501 497
 			'account_created' => !isset($data['whencreated'][0]) ? null :
502 498
 				self::_when2ts($data['whencreated'][0]),
503 499
 			'account_modified' => !isset($data['whenchanged'][0]) ? null :
@@ -508,7 +504,7 @@  discard block
 block discarded – undo
508 504
 		{
509 505
 			$user['account_status'] = false;
510 506
 		}
511
-		$user['person_id'] = $user['account_guid'];	// id of contact
507
+		$user['person_id'] = $user['account_guid']; // id of contact
512 508
 		//error_log(__METHOD__."(".array2string($data).") returning ".array2string($user));
513 509
 		return $user;
514 510
 	}
@@ -538,7 +534,7 @@  discard block
 block discarded – undo
538 534
 	{
539 535
 		if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'u', self::$user_attributes)))
540 536
 		{
541
-			return false;	// user not found
537
+			return false; // user not found
542 538
 		}
543 539
 		$user = $this->_ldap2user(array_shift($data));
544 540
 
@@ -561,10 +557,10 @@  discard block
 block discarded – undo
561 557
 	 */
562 558
 	protected static function _when2ts($_when)
563 559
 	{
564
-		static $utc=null;
560
+		static $utc = null;
565 561
 		if (!isset($utc)) $utc = new \DateTimeZone('UTC');
566 562
 
567
-		list($when) = explode('.', $_when);	// remove .0Z not understood by createFromFormat
563
+		list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat
568 564
 		$datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc);
569 565
 		if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone);
570 566
 
@@ -579,7 +575,7 @@  discard block
 block discarded – undo
579 575
 	 * @param array $old =null current data
580 576
 	 * @return int|false account_id or false on error
581 577
 	 */
582
-	protected function _save_group(array &$data, array $old=null)
578
+	protected function _save_group(array &$data, array $old = null)
583 579
 	{
584 580
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
585 581
 
@@ -590,7 +586,7 @@  discard block
 block discarded – undo
590 586
 				'account_description' => 'description',
591 587
 			);
592 588
 			$attributes = array();
593
-			foreach($new2adldap as $egw => $adldap)
589
+			foreach ($new2adldap as $egw => $adldap)
594 590
 			{
595 591
 				$attributes[$adldap] = (string)$data[$egw];
596 592
 			}
@@ -627,11 +623,11 @@  discard block
 block discarded – undo
627 623
 			'account_description' => 'description',
628 624
 		);
629 625
 		$ldap = array();
630
-		foreach($egw2adldap as $egw => $adldap)
626
+		foreach ($egw2adldap as $egw => $adldap)
631 627
 		{
632 628
 			if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw])
633 629
 			{
634
-				switch($egw)
630
+				switch ($egw)
635 631
 				{
636 632
 					case 'account_description':
637 633
 						$ldap[$adldap] = !empty($data[$egw]) ? $data[$egw] : array();
@@ -644,7 +640,7 @@  discard block
 block discarded – undo
644 640
 			}
645 641
 		}
646 642
 		// attributes not (yet) suppored by adldap
647
-		if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap)))
643
+		if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap)))
648 644
 		{
649 645
 			error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret));
650 646
 			return false;
@@ -660,7 +656,7 @@  discard block
 block discarded – undo
660 656
 	 * @param array $old =null current data
661 657
 	 * @return int|false account_id or false on error
662 658
 	 */
663
-	protected function _save_user(array &$data, array $old=null)
659
+	protected function _save_user(array &$data, array $old = null)
664 660
 	{
665 661
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
666 662
 		if (!isset($data['account_fullname']) && !empty($data['account_firstname']) && !empty($data['account_lastname']))
@@ -680,12 +676,12 @@  discard block
 block discarded – undo
680 676
 				'account_status'    => 'enabled',
681 677
 			);
682 678
 			$attributes = array();
683
-			foreach($new2adldap as $egw => $adldap)
679
+			foreach ($new2adldap as $egw => $adldap)
684 680
 			{
685 681
 				if ($egw == 'account_passwd' && (empty($data[$egw]) ||
686 682
 					!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()))
687 683
 				{
688
-					continue;	// do not try to set password, if no SSL or TLS, whole user creation will fail
684
+					continue; // do not try to set password, if no SSL or TLS, whole user creation will fail
689 685
 				}
690 686
 				if (isset($data[$egw])) $attributes[$adldap] = $data[$egw];
691 687
 			}
@@ -722,7 +718,7 @@  discard block
 block discarded – undo
722 718
 			'account_firstname' => 'firstname',
723 719
 			'account_lastname'  => 'surname',
724 720
 			'account_email'     => 'email',
725
-			'account_fullname'  => 'display_name',	// handeled currently in rename above, as not supported by adLDAP
721
+			'account_fullname'  => 'display_name', // handeled currently in rename above, as not supported by adLDAP
726 722
 			'account_passwd'    => 'password',
727 723
 			'account_status'    => 'enabled',
728 724
 			'account_primary_group' => 'primarygroupid',
@@ -735,7 +731,7 @@  discard block
 block discarded – undo
735 731
 		// for a new entry set certain values (eg. profilePath) to in setup configured value
736 732
 		if ($new_entry)
737 733
 		{
738
-			foreach($this->frontend->config as $name => $value)
734
+			foreach ($this->frontend->config as $name => $value)
739 735
 			{
740 736
 				if (substr($name, 0, 8) == 'ads_new_')
741 737
 				{
@@ -743,22 +739,22 @@  discard block
 block discarded – undo
743 739
 				}
744 740
 			}
745 741
 		}
746
-		foreach($egw2adldap as $egw => $adldap)
742
+		foreach ($egw2adldap as $egw => $adldap)
747 743
 		{
748 744
 			if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw])
749 745
 			{
750
-				switch($egw)
746
+				switch ($egw)
751 747
 				{
752 748
 					case 'account_passwd':
753 749
 						if (!empty($data[$egw]) && ($this->adldap->getUseSSL() || $this->adldap->getUseTLS()))
754 750
 						{
755
-							$attributes[$adldap] = $data[$egw];	// only try to set password, if no SSL or TLS
751
+							$attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS
756 752
 						}
757 753
 						break;
758 754
 					case 'account_primary_group':
759 755
 						// setting a primary group seems to fail, if user is no member of that group
760 756
 						if (isset($old['memberships'][$data[$egw]]) ||
761
-							$this->adldap->group()->addUser($group=$this->id2name($data[$egw]), $data['account_id']))
757
+							$this->adldap->group()->addUser($group = $this->id2name($data[$egw]), $data['account_id']))
762 758
 						{
763 759
 							$old['memberships'][$data[$egw]] = $group;
764 760
 							$ldap[$adldap] = abs($data[$egw]);
@@ -769,11 +765,10 @@  discard block
 block discarded – undo
769 765
 						$ldap['userPrincipalName'] = $data[$egw].'@'.$this->frontend->config['ads_domain'];
770 766
 						break;
771 767
 					case 'account_expires':
772
-						$attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER :
773
-							self::convertUnixTimeToWindowsTime($data[$egw]);
768
+						$attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : self::convertUnixTimeToWindowsTime($data[$egw]);
774 769
 						break;
775 770
 					case 'account_status':
776
-						if ($new_entry && empty($data['account_passwd'])) continue;	// cant active new account without passwd!
771
+						if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd!
777 772
 						$attributes[$adldap] = $data[$egw] == 'A';
778 773
 						break;
779 774
 					case 'account_lastpwd_change':
@@ -795,7 +790,7 @@  discard block
 block discarded – undo
795 790
 		}
796 791
 		//elseif ($attributes) error_log(__METHOD__."(".array2string($data).") adldap->user()->modify('$data[account_lid]', ".array2string($attributes).') returned '.array2string($ret).' '.function_backtrace());
797 792
 		// attributes not (yet) suppored by adldap
798
-		if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap)))
793
+		if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap)))
799 794
 		{
800 795
 			error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret).' ('.ldap_error($ds).') '.function_backtrace());
801 796
 			return false;
@@ -868,11 +863,11 @@  discard block
 block discarded – undo
868 863
 			$query = Api\Ldap::quote(strtolower($param['query']));
869 864
 
870 865
 			$accounts = array();
871
-			if($param['type'] !== 'groups')
866
+			if ($param['type'] !== 'groups')
872 867
 			{
873 868
 				if (!empty($query) && $query != '*')
874 869
 				{
875
-					switch($param['query_type'])
870
+					switch ($param['query_type'])
876 871
 					{
877 872
 						case 'all':
878 873
 						default:
@@ -903,14 +898,14 @@  discard block
 block discarded – undo
903 898
 					$membership_filter = '(|(memberOf='.$this->id2name((int)$param['type'], 'account_dn').')(PrimaryGroupId='.abs($param['type']).'))';
904 899
 					$filter = $filter ? "(&$membership_filter$filter)" : $membership_filter;
905 900
 				}
906
-				foreach($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data)
901
+				foreach ($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data)
907 902
 				{
908 903
 					$account = $this->_ldap2user($data);
909 904
 					if ($param['active'] && !$this->frontend->is_active($account))
910 905
 					{
911 906
 						continue;
912 907
 					}
913
-					$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$account['account_id']);
908
+					$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'], $account['account_firstname'], $account['account_lastname'], $account['account_id']);
914 909
 					$accounts[$account_id] = $account;
915 910
 				}
916 911
 			}
@@ -919,9 +914,9 @@  discard block
 block discarded – undo
919 914
 				$query = Api\Ldap::quote(strtolower($param['query']));
920 915
 
921 916
 				$filter = null;
922
-				if(!empty($query) && $query != '*')
917
+				if (!empty($query) && $query != '*')
923 918
 				{
924
-					switch($param['query_type'])
919
+					switch ($param['query_type'])
925 920
 					{
926 921
 						case 'all':
927 922
 						default:
@@ -935,23 +930,23 @@  discard block
 block discarded – undo
935 930
 					}
936 931
 					$filter = "(|(cn=$query)(description=$query))";
937 932
 				}
938
-				foreach($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data)
933
+				foreach ($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data)
939 934
 				{
940 935
 					$accounts[$account_id] = $this->_ldap2group($data);
941 936
 				}
942 937
 			}
943 938
 			// sort the array
944 939
 			$this->_callback_sort = strtoupper($param['sort']);
945
-			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']);
940
+			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']);
946 941
 			$sortedAccounts = $accounts;
947
-			uasort($sortedAccounts,array($this,'_sort_callback'));
942
+			uasort($sortedAccounts, array($this, '_sort_callback'));
948 943
 			$account_search[$unl_serial]['data'] = $sortedAccounts;
949 944
 
950 945
 			$account_search[$unl_serial]['total'] = $this->total = count($accounts);
951 946
 		}
952 947
 		// return only the wanted accounts
953 948
 		reset($sortedAccounts);
954
-		if(is_numeric($start) && is_numeric($offset))
949
+		if (is_numeric($start) && is_numeric($offset))
955 950
 		{
956 951
 			$account_search[$serial]['data'] = array_slice($sortedAccounts, $start, $offset);
957 952
 			$account_search[$serial]['total'] = $this->total;
@@ -982,19 +977,19 @@  discard block
 block discarded – undo
982 977
 	 * @param array $b
983 978
 	 * @return int
984 979
 	 */
985
-	protected function _sort_callback($a,$b)
980
+	protected function _sort_callback($a, $b)
986 981
 	{
987
-		foreach($this->_callback_order as $col )
982
+		foreach ($this->_callback_order as $col)
988 983
 		{
989
-			if($this->_callback_sort != 'DESC')
984
+			if ($this->_callback_sort != 'DESC')
990 985
 			{
991
-				$cmp = strcasecmp( $a[$col], $b[$col] );
986
+				$cmp = strcasecmp($a[$col], $b[$col]);
992 987
 			}
993 988
 			else
994 989
 			{
995
-				$cmp = strcasecmp( $b[$col], $a[$col] );
990
+				$cmp = strcasecmp($b[$col], $a[$col]);
996 991
 			}
997
-			if ( $cmp != 0 )
992
+			if ($cmp != 0)
998 993
 			{
999 994
 				return $cmp;
1000 995
 			}
@@ -1013,9 +1008,9 @@  discard block
 block discarded – undo
1013 1008
 	 * @param array $accounts =array() array to add filtered accounts too, default empty array
1014 1009
 	 * @return array account_id => account_lid or values for $attrs pairs
1015 1010
 	 */
1016
-	protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array())
1011
+	protected function filter($attr_filter, $account_type = null, array $attrs = null, array $accounts = array())
1017 1012
 	{
1018
-		switch($account_type)
1013
+		switch ($account_type)
1019 1014
 		{
1020 1015
 			case 'u':
1021 1016
 				$type_filter = '(samaccounttype='.adLDAP::ADLDAP_NORMAL_ACCOUNT.')';
@@ -1040,25 +1035,25 @@  discard block
 block discarded – undo
1040 1035
 			}
1041 1036
 			else
1042 1037
 			{
1043
-				foreach($attr_filter as $attr => $value)
1038
+				foreach ($attr_filter as $attr => $value)
1044 1039
 				{
1045 1040
 					$filter .= '('.$attr.'='.$this->adldap->utilities()->ldapSlashes($value).')';
1046 1041
 				}
1047 1042
 			}
1048 1043
 			$filter .= $type_filter.')';
1049 1044
 		}
1050
-		$sri = ldap_search($ds=$this->ldap_connection(), $context=$this->ads_context(), $filter,
1045
+		$sri = ldap_search($ds = $this->ldap_connection(), $context = $this->ads_context(), $filter,
1051 1046
 			$attrs ? $attrs : self::$default_attributes);
1052 1047
 		if (!$sri)
1053 1048
 		{
1054 1049
 			if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1055
-			$sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter,
1050
+			$sri = ldap_search($ds = $this->ldap_connection(true), $context = $this->ads_context(), $filter,
1056 1051
 				$attrs ? $attrs : self::$default_attributes);
1057 1052
 		}
1058 1053
 
1059 1054
 		if ($sri && ($allValues = ldap_get_entries($ds, $sri)))
1060 1055
 		{
1061
-			foreach($allValues as $key => $data)
1056
+			foreach ($allValues as $key => $data)
1062 1057
 			{
1063 1058
 				if ($key === 'count') continue;
1064 1059
 
@@ -1072,7 +1067,7 @@  discard block
 block discarded – undo
1072 1067
 
1073 1068
 				if ($data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT && $rid < self::MIN_ACCOUNT_ID)
1074 1069
 				{
1075
-					continue;	// ignore system accounts incl. "Administrator"
1070
+					continue; // ignore system accounts incl. "Administrator"
1076 1071
 				}
1077 1072
 				$accounts[($data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP ? '-' : '').$rid] =
1078 1073
 					$attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8');
@@ -1096,7 +1091,7 @@  discard block
 block discarded – undo
1096 1091
 	 * @param string $account_type u = user, g = group, default null = try both
1097 1092
 	 * @return int|false numeric account_id or false on error ($name not found)
1098 1093
 	 */
1099
-	public function name2id($name, $which='account_lid', $account_type=null)
1094
+	public function name2id($name, $which = 'account_lid', $account_type = null)
1100 1095
 	{
1101 1096
 		static $to_ldap = array(
1102 1097
 			'account_lid'   => 'samaccountname',
@@ -1108,7 +1103,7 @@  discard block
 block discarded – undo
1108 1103
 		$ret = false;
1109 1104
 		if (isset($to_ldap[$which]))
1110 1105
 		{
1111
-			foreach($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
1106
+			foreach ($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
1112 1107
 			{
1113 1108
 				unset($account_lid);
1114 1109
 				$ret = $account_id;
@@ -1128,9 +1123,9 @@  discard block
 block discarded – undo
1128 1123
 	 * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
1129 1124
 	 * @return string/false converted value or false on error ($account_id not found)
1130 1125
 	 */
1131
-	public function id2name($account_id, $which='account_lid')
1126
+	public function id2name($account_id, $which = 'account_lid')
1132 1127
 	{
1133
-		return $this->frontend->id2name($account_id,$which);
1128
+		return $this->frontend->id2name($account_id, $which);
1134 1129
 	}
1135 1130
 
1136 1131
 	/**
@@ -1142,9 +1137,9 @@  discard block
 block discarded – undo
1142 1137
 	 */
1143 1138
 	function update_lastlogin($_account_id, $ip)
1144 1139
 	{
1145
-		unset($_account_id, $ip);	// not used, but required by function signature
1140
+		unset($_account_id, $ip); // not used, but required by function signature
1146 1141
 
1147
-		return false;	// not longer supported
1142
+		return false; // not longer supported
1148 1143
 	}
1149 1144
 
1150 1145
 	/**
@@ -1184,21 +1179,21 @@  discard block
 block discarded – undo
1184 1179
 	 * @param int $account_id uidnumber
1185 1180
 	 * @return int number of added or removed memberships
1186 1181
 	 */
1187
-	function set_memberships($groups,$account_id)
1182
+	function set_memberships($groups, $account_id)
1188 1183
 	{
1189 1184
 		if (!($account = $this->id2name($account_id))) return;
1190 1185
 		$current = array_keys($this->memberships($account_id));
1191 1186
 
1192 1187
 		$changed = 0;
1193
-		foreach(array(
1194
-			'add' => array_diff($groups, $current),		// add account to all groups he is currently not in
1195
-			'remove' => array_diff($current, $groups),	// remove account from all groups he is only currently in
1188
+		foreach (array(
1189
+			'add' => array_diff($groups, $current), // add account to all groups he is currently not in
1190
+			'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in
1196 1191
 		) as $op => $memberships)
1197 1192
 		{
1198 1193
 			$func = $op.($account_id > 0 ? 'User' : 'Group');
1199
-			foreach($memberships as $gid)
1194
+			foreach ($memberships as $gid)
1200 1195
 			{
1201
-				$ok = $this->adldap->group()->$func($group=$this->id2name($gid), $account);
1196
+				$ok = $this->adldap->group()->$func($group = $this->id2name($gid), $account);
1202 1197
 				//error_log(__METHOD__.'('.array2string($groups).", $account_id) $func('$group', '$account') returned ".array2string($ok));
1203 1198
 				$changed += (int)$ok;
1204 1199
 			}
@@ -1220,15 +1215,15 @@  discard block
 block discarded – undo
1220 1215
 		$current = array_keys($this->members($gid));
1221 1216
 
1222 1217
 		$changed = 0;
1223
-		foreach(array(
1224
-			'add' => array_diff($users, $current),	// add members currently not in
1225
-			'remove' => array_diff($current, $users),	// remove members only currently in
1218
+		foreach (array(
1219
+			'add' => array_diff($users, $current), // add members currently not in
1220
+			'remove' => array_diff($current, $users), // remove members only currently in
1226 1221
 		) as $op => $members)
1227 1222
 		{
1228
-			foreach($members as $account_id)
1223
+			foreach ($members as $account_id)
1229 1224
 			{
1230 1225
 				$func = $op.($account_id > 0 ? 'User' : 'Group');
1231
-				$ok = $this->adldap->group()->$func($group, $account=$this->id2name($account_id));
1226
+				$ok = $this->adldap->group()->$func($group, $account = $this->id2name($account_id));
1232 1227
 				//error_log(__METHOD__.'('.array2string($users).", $account_id) $func('$group', '$account') returned ".array2string($ok));
1233 1228
 				$changed += (int)$ok;
1234 1229
 			}
@@ -1253,7 +1248,7 @@  discard block
 block discarded – undo
1253 1248
 	 */
1254 1249
 	public $charset = 'iso-8859-1';
1255 1250
 
1256
-	function __construct(array $options=array())
1251
+	function __construct(array $options = array())
1257 1252
 	{
1258 1253
 		if (isset($options['charset']))
1259 1254
 		{
@@ -1340,19 +1335,19 @@  discard block
 block discarded – undo
1340 1335
 	public function create($attributes)
1341 1336
 	{
1342 1337
 		// Check for compulsory fields
1343
-		if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; }
1344
-		if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; }
1345
-		if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; }
1346
-		if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; }
1347
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1348
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1349
-
1350
-		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){
1338
+		if (!array_key_exists("username", $attributes)) { return "Missing compulsory field [username]"; }
1339
+		if (!array_key_exists("firstname", $attributes)) { return "Missing compulsory field [firstname]"; }
1340
+		if (!array_key_exists("surname", $attributes)) { return "Missing compulsory field [surname]"; }
1341
+		if (!array_key_exists("email", $attributes)) { return "Missing compulsory field [email]"; }
1342
+		if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; }
1343
+		if (empty($attributes["container"])) { return "Container attribute must be an array or string."; }
1344
+
1345
+		if (array_key_exists("password", $attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) {
1351 1346
 			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1352 1347
 		}
1353 1348
 
1354 1349
 		if (!array_key_exists("display_name", $attributes)) {
1355
-			$attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"];
1350
+			$attributes["display_name"] = $attributes["firstname"]." ".$attributes["surname"];
1356 1351
 		}
1357 1352
 
1358 1353
 		// Translate the schema
@@ -1375,20 +1370,20 @@  discard block
 block discarded – undo
1375 1370
 		// Determine the container
1376 1371
 		if (is_array($attributes['container'])) {
1377 1372
 			$attributes["container"] = array_reverse($attributes["container"]);
1378
-			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1373
+			$attributes["container"] = "OU=".implode(",OU=", $attributes["container"]);
1379 1374
 		}
1380 1375
 		// we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2
1381 1376
 		unset($add['unicodePwd']);
1382 1377
 
1383 1378
 		// Add the entry
1384
-		$result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1379
+		$result = ldap_add($ds = $this->adldap->getLdapConnection(), $dn = "CN=".$add["cn"][0].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add);
1385 1380
 		if ($result != true) {
1386 1381
 			error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1387 1382
 			return false;
1388 1383
 		}
1389 1384
 
1390 1385
 		// now password can be added to still disabled account
1391
-		if (array_key_exists("password",$attributes))
1386
+		if (array_key_exists("password", $attributes))
1392 1387
 		{
1393 1388
 			if (!$this->setPassword($dn, $attributes['password'])) return false;
1394 1389
 
@@ -1415,13 +1410,13 @@  discard block
 block discarded – undo
1415 1410
     */
1416 1411
     public function encodePassword($password)
1417 1412
     {
1418
-        $password="\"".$password."\"";
1413
+        $password = "\"".$password."\"";
1419 1414
         if (function_exists('mb_convert_encoding'))
1420 1415
         {
1421 1416
             return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422 1417
         }
1423
-        $encoded="";
1424
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1418
+        $encoded = "";
1419
+        for ($i = 0; $i < strlen($password); $i++) { $encoded .= "{$password{$i}}\000"; }
1425 1420
         return $encoded;
1426 1421
     }
1427 1422
 
@@ -1438,7 +1433,7 @@  discard block
 block discarded – undo
1438 1433
      */
1439 1434
     public function setPassword($dn, $password)
1440 1435
     {
1441
-    	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1436
+    	$result = ldap_mod_replace($ds = $this->adldap->getLdapConnection(), $dn, array(
1442 1437
     		'unicodePwd' => $this->encodePassword($password),
1443 1438
     	));
1444 1439
     	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
@@ -1466,7 +1461,7 @@  discard block
 block discarded – undo
1466 1461
 	* @param string $old_password old password for password change, if supported
1467 1462
     * @return bool
1468 1463
     */
1469
-    public function password($username, $password, $isGUID = false, $old_password=null)
1464
+    public function password($username, $password, $isGUID = false, $old_password = null)
1470 1465
     {
1471 1466
         if ($username === NULL) { return false; }
1472 1467
         if ($password === NULL) { return false; }
@@ -1480,7 +1475,7 @@  discard block
 block discarded – undo
1480 1475
             return false;
1481 1476
         }
1482 1477
 
1483
-        $add=array();
1478
+        $add = array();
1484 1479
 
1485 1480
 		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1486 1481
 			$add["unicodePwd"][0] = $this->encodePassword($password);
@@ -1502,11 +1497,11 @@  discard block
 block discarded – undo
1502 1497
 			);
1503 1498
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1504 1499
 		}
1505
-        if ($result === false){
1500
+        if ($result === false) {
1506 1501
             $err = ldap_errno($this->adldap->getLdapConnection());
1507 1502
             if ($err) {
1508
-                $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
-                if($err == 53) {
1503
+                $msg = 'Error '.$err.': '.ldap_err2str($err).'.';
1504
+                if ($err == 53) {
1510 1505
                     $msg .= ' Your password might not match the password policy.';
1511 1506
                 }
1512 1507
                 throw new adLDAPException($msg);
@@ -1544,13 +1539,13 @@  discard block
 block discarded – undo
1544 1539
         $mod = $this->adldap->adldap_schema($attributes);
1545 1540
 
1546 1541
         // Check to see if this is an enabled status update
1547
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1542
+        if (!$mod && !array_key_exists("enabled", $attributes)) {
1548 1543
             return false;
1549 1544
         }
1550 1545
 
1551 1546
         // Set the account control attribute (only if specified)
1552
-        if (array_key_exists("enabled", $attributes)){
1553
-            if ($attributes["enabled"]){
1547
+        if (array_key_exists("enabled", $attributes)) {
1548
+            if ($attributes["enabled"]) {
1554 1549
                 $controlOptions = array("NORMAL_ACCOUNT");
1555 1550
             }
1556 1551
             else {
@@ -1564,14 +1559,14 @@  discard block
 block discarded – undo
1564 1559
 		if ($mod)
1565 1560
 		{
1566 1561
 	        // Do the update
1567
-	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1562
+	        $result = @ldap_modify($ds = $this->adldap->getLdapConnection(), $userDn, $mod);
1568 1563
 	        if ($result == false) {
1569 1564
 				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1570 1565
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1571 1566
 	        	return false;
1572 1567
 	        }
1573 1568
 		}
1574
-        if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1569
+        if (array_key_exists("password", $attributes) && !$this->setPassword($userDn, $attributes['password']))
1575 1570
 		{
1576 1571
 			return false;
1577 1572
 		}
@@ -1594,10 +1589,10 @@  discard block
 block discarded – undo
1594 1589
 	 */
1595 1590
 	public function create($attributes)
1596 1591
 	{
1597
-		if (!is_array($attributes)){ return "Attributes must be an array"; }
1598
-		if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; }
1599
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1600
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1592
+		if (!is_array($attributes)) { return "Attributes must be an array"; }
1593
+		if (!array_key_exists("group_name", $attributes)) { return "Missing compulsory field [group_name]"; }
1594
+		if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; }
1595
+		if (empty($attributes["container"])) { return "Container attribute must be an array or string."; }
1601 1596
 
1602 1597
 		//$member_array = array();
1603 1598
 		//$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com";
@@ -1613,9 +1608,9 @@  discard block
 block discarded – undo
1613 1608
 		// Determine the container
1614 1609
 		if (is_array($attributes['container'])) {
1615 1610
 			$attributes["container"] = array_reverse($attributes["container"]);
1616
-			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1611
+			$attributes["container"] = "OU=".implode(",OU=", $attributes["container"]);
1617 1612
 		}
1618
-		$result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1613
+		$result = ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add);
1619 1614
 		if ($result != true) {
1620 1615
 			return false;
1621 1616
 		}
@@ -1646,10 +1641,10 @@  discard block
 block discarded – undo
1646 1641
     * @author Port by Andreas Gohr <[email protected]>
1647 1642
     * @return string
1648 1643
     */
1649
-    public function ldapSlashes($str){
1644
+    public function ldapSlashes($str) {
1650 1645
         return preg_replace_callback(
1651 1646
       		'/([\x00-\x1F\*\(\)\\\\])/',
1652
-        	function ($matches) {
1647
+        	function($matches) {
1653 1648
             	return "\\".join("", unpack("H2", $matches[1]));
1654 1649
         	},
1655 1650
         	$str
Please login to merge, or discard this patch.