Completed
Push — master ( aa44e9...fa84e5 )
by Ralf
90:14 queued 73:21
created
admin/inc/class.admin_statistics.inc.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -291,7 +291,7 @@
 block discarded – undo
291 291
 	 * Check if next submission is due, in which case we call submit and NOT return to the admin hook
292 292
 	 *
293 293
 	 * @param boolean $redirect should we redirect or return true
294
-	 * @return boolean true if statistic submission is due
294
+	 * @return boolean|null true if statistic submission is due
295 295
 	 */
296 296
 	public static function check($redirect=true)
297 297
 	{
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	const SUBMIT_URL = 'https://www.egroupware.org/usage-statistic';
31 31
 	const STATISTIC_URL = 'http://www.egroupware.org/usage-statistic';
32 32
 
33
-	const SUBMISION_RATE = 2592000;	// 30 days
33
+	const SUBMISION_RATE = 2592000; // 30 days
34 34
 
35 35
 	/**
36 36
 	 * Which methods of this class can be called as menuation
@@ -46,27 +46,27 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @param array $_content =null
48 48
 	 */
49
-	public function submit($_content=null)
49
+	public function submit($_content = null)
50 50
 	{
51 51
 		if (is_array($_content))
52 52
 		{
53 53
 			$config = new Api\Config(self::CONFIG_APP);
54 54
 			if ($_content['postpone'])
55 55
 			{
56
-				Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT,time()+$_content['postpone'],self::CONFIG_APP);
56
+				Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT, time() + $_content['postpone'], self::CONFIG_APP);
57 57
 				$what = 'postpone';
58 58
 			}
59
-			elseif(!$_content['cancel'])
59
+			elseif (!$_content['cancel'])
60 60
 			{
61
-				Api\Config::save_value(self::CONFIG_LAST_SUBMIT,time(),self::CONFIG_APP);
62
-				Api\Config::save_value(self::CONFIG_SUBMIT_ID,empty($_content['submit_id']) ? '***none***' : $_content['submit_id'],self::CONFIG_APP);
63
-				Api\Config::save_value(self::CONFIG_COUNTRY,empty($_content['country']) ? '***multinational***' : $_content['country'],self::CONFIG_APP);
64
-				Api\Config::save_value(self::CONFIG_USAGE_TYPE,$_content['usage_type'],self::CONFIG_APP);
65
-				Api\Config::save_value(self::CONFIG_INSTALL_TYPE,$_content['install_type'],self::CONFIG_APP);
66
-				Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT,null,self::CONFIG_APP);	// remove evtl. postpone time
61
+				Api\Config::save_value(self::CONFIG_LAST_SUBMIT, time(), self::CONFIG_APP);
62
+				Api\Config::save_value(self::CONFIG_SUBMIT_ID, empty($_content['submit_id']) ? '***none***' : $_content['submit_id'], self::CONFIG_APP);
63
+				Api\Config::save_value(self::CONFIG_COUNTRY, empty($_content['country']) ? '***multinational***' : $_content['country'], self::CONFIG_APP);
64
+				Api\Config::save_value(self::CONFIG_USAGE_TYPE, $_content['usage_type'], self::CONFIG_APP);
65
+				Api\Config::save_value(self::CONFIG_INSTALL_TYPE, $_content['install_type'], self::CONFIG_APP);
66
+				Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT, null, self::CONFIG_APP); // remove evtl. postpone time
67 67
 				$what = 'submitted';
68 68
 			}
69
-			Egw::redirect_link('/admin/index.php','ajax=true&statistics='.($what ? $what : 'canceled'),'admin');
69
+			Egw::redirect_link('/admin/index.php', 'ajax=true&statistics='.($what ? $what : 'canceled'), 'admin');
70 70
 		}
71 71
 		$sel_options['usage_type'] = array(
72 72
 			'commercial'   => lang('Commercial: all sorts of companies'),
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
 		$sel_options['postpone'] = array(
87 87
 			//10 => '10 secs',
88 88
 			3600 => lang('one hour'),
89
-			2*3600 => lang('two hours'),
90
-			24*3600 => lang('one day'),
91
-			2*24*3600 => lang('two days'),
92
-			7*24*3600 => lang('one week'),
93
-			14*24*3600 => lang('two weeks'),
94
-			30*24*3600 => lang('one month'),
95
-			60*24*3600 => lang('two months'),
89
+			2 * 3600 => lang('two hours'),
90
+			24 * 3600 => lang('one day'),
91
+			2 * 24 * 3600 => lang('two days'),
92
+			7 * 24 * 3600 => lang('one week'),
93
+			14 * 24 * 3600 => lang('two weeks'),
94
+			30 * 24 * 3600 => lang('one month'),
95
+			60 * 24 * 3600 => lang('two months'),
96 96
 		);
97 97
 		$config = Api\Config::read(self::CONFIG_APP);
98 98
 		//_debug_array($config);
99
-		$content = array_merge(self::gather_data(),array(
99
+		$content = array_merge(self::gather_data(), array(
100 100
 			'statistic_url' => self::STATISTIC_URL,
101
-			'submit_host' => parse_url(self::SUBMIT_URL,PHP_URL_HOST),
101
+			'submit_host' => parse_url(self::SUBMIT_URL, PHP_URL_HOST),
102 102
 			'submit_url'  => self::SUBMIT_URL,
103 103
 			'last_submitted' => $config[self::CONFIG_LAST_SUBMIT],
104 104
 		));
@@ -125,12 +125,12 @@  discard block
 block discarded – undo
125 125
 			$sel_options['install_type'] = array($content['install_type'] => $sel_options['install_type'][$content['install_type']]);
126 126
 		}
127 127
 		// else default to previous type
128
-		elseif($config[self::CONFIG_INSTALL_TYPE])
128
+		elseif ($config[self::CONFIG_INSTALL_TYPE])
129 129
 		{
130 130
 			$content['install_type'] = $config[self::CONFIG_INSTALL_TYPE];
131 131
 		}
132 132
 		// check if we are due for a new submission
133
-		if (!isset($config[self::CONFIG_LAST_SUBMIT]) || $config[self::CONFIG_LAST_SUBMIT ] <= time()-self::SUBMISION_RATE)
133
+		if (!isset($config[self::CONFIG_LAST_SUBMIT]) || $config[self::CONFIG_LAST_SUBMIT] <= time() - self::SUBMISION_RATE)
134 134
 		{
135 135
 			// clear etemplate_exec_id and replace form.action, before submitting the form
136 136
 			$content['onclick'] = "return app.admin.submit_statistic(this.form,'$content[submit_url]');";
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
 		{
140 140
 			$readonlys['submit'] = $readonlys['postpone'] = true;
141 141
 			$content['msg'] = lang('Your last submission was less then %1 days ago!',
142
-				ceil((time()-$config[self::CONFIG_LAST_SUBMIT])/24/3600));
142
+				ceil((time() - $config[self::CONFIG_LAST_SUBMIT]) / 24 / 3600));
143 143
 		}
144 144
 		$GLOBALS['egw_info']['flags']['app_header'] = lang('Submit statistic information');
145 145
 		$tmpl = new Etemplate('admin.statistics');
146
-		$tmpl->exec('admin.admin_statistics.submit',$content,$sel_options,$readonlys);
146
+		$tmpl->exec('admin.admin_statistics.submit', $content, $sel_options, $readonlys);
147 147
 	}
148 148
 
149 149
 	/**
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 			$data['version'] .= ' '.$GLOBALS['egw_info']['apps']['stylite']['version'].'EPL';
167 167
 		}
168 168
 		// sessions in the last 30 days
169
-		$data['sessions'] = $GLOBALS['egw']->db->query('SELECT COUNT(*) FROM egw_access_log WHERE li > '.(time()-30*24*3600))->fetchColumn();
169
+		$data['sessions'] = $GLOBALS['egw']->db->query('SELECT COUNT(*) FROM egw_access_log WHERE li > '.(time() - 30 * 24 * 3600))->fetchColumn();
170 170
 
171 171
 		// total accounts from accounts table or ldap
172 172
 		$GLOBALS['egw']->accounts->search(array(
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 		// @ required to get ride of warning, if files are outside of open_basedir
181 181
 		if (@file_exists($file = '/etc/SuSE-release') || @file_exists($file = '/etc/redhat-release') || @file_exists($file = '/etc/debian_version'))
182 182
 		{
183
-			$data['os'] .= ': '.str_replace(array("\n","\r"),'',implode(',',file($file)));
183
+			$data['os'] .= ': '.str_replace(array("\n", "\r"), '', implode(',', file($file)));
184 184
 		}
185
-		if(file_exists(EGW_INCLUDE_ROOT.'/.git'))
185
+		if (file_exists(EGW_INCLUDE_ROOT.'/.git'))
186 186
 		{
187 187
 			$data['install_type'] = 'git';
188 188
 		}
@@ -190,22 +190,22 @@  discard block
 block discarded – undo
190 190
 		{
191 191
 			$data['install_type'] = 'svn';
192 192
 		}
193
-		elseif(EGW_INCLUDE_ROOT == '/usr/share/egroupware' && PHP_OS == 'Linux' && is_link('/usr/share/egroupware/header.inc.php'))
193
+		elseif (EGW_INCLUDE_ROOT == '/usr/share/egroupware' && PHP_OS == 'Linux' && is_link('/usr/share/egroupware/header.inc.php'))
194 194
 		{
195 195
 			$data['install_type'] = 'package';
196 196
 		}
197
-		foreach(array_keys($GLOBALS['egw_info']['apps']) as $app)
197
+		foreach (array_keys($GLOBALS['egw_info']['apps']) as $app)
198 198
 		{
199
-			if (in_array($app,array(
200
-				'admin','phpgwapi','api','sambaadmin','developer_tools',
201
-				'home','preferences','etemplate','registration','manual',
199
+			if (in_array($app, array(
200
+				'admin', 'phpgwapi', 'api', 'sambaadmin', 'developer_tools',
201
+				'home', 'preferences', 'etemplate', 'registration', 'manual',
202 202
 			)))
203 203
 			{
204
-				continue;	// --> ignore to not submit too much
204
+				continue; // --> ignore to not submit too much
205 205
 			}
206 206
 			if (($users = self::gather_app_users($app)))	// ignore apps noone is allowed to run
207 207
 			{
208
-				$data['apps'][$app] = $app.':'.round(100.0*$users/$data['users']).'%';
208
+				$data['apps'][$app] = $app.':'.round(100.0 * $users / $data['users']).'%';
209 209
 				if (($entries = self::gather_app_entries($app)))
210 210
 				{
211 211
 					$data['apps'][$app] .= ':'.$entries;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			}
214 214
 		}
215 215
 		ksort($data['apps']);
216
-		$data['apps'] = implode("\n",$data['apps']);
216
+		$data['apps'] = implode("\n", $data['apps']);
217 217
 
218 218
 		return $data;
219 219
 	}
@@ -227,17 +227,17 @@  discard block
 block discarded – undo
227 227
 	static function gather_app_users($app)
228 228
 	{
229 229
 		$users = array();
230
-		if (($access = $GLOBALS['egw']->acl->get_ids_for_location('run',1,$app)))
230
+		if (($access = $GLOBALS['egw']->acl->get_ids_for_location('run', 1, $app)))
231 231
 		{
232
-			foreach($access as $uid)
232
+			foreach ($access as $uid)
233 233
 			{
234 234
 				if ($uid > 0)
235 235
 				{
236 236
 					$users[] = $uid;
237 237
 				}
238
-				elseif (($members = $GLOBALS['egw']->accounts->members($uid,true)))
238
+				elseif (($members = $GLOBALS['egw']->accounts->members($uid, true)))
239 239
 				{
240
-					$users = array_merge($users,$members);
240
+					$users = array_merge($users, $members);
241 241
 				}
242 242
 			}
243 243
 			$users = array_unique($users);
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 			'infolog'     => 'egw_infolog',
262 262
 			'filemanager' => 'egw_sqlfs',
263 263
 			'gallery'     => 'g2_Item',
264
-			'news_admin'  => 'egw_news WHERE news_submittedby > 0',	// exclude imported rss feeds
264
+			'news_admin'  => 'egw_news WHERE news_submittedby > 0', // exclude imported rss feeds
265 265
 			'polls'       => 'egw_polls',
266 266
 			'projectmanager' => 'egw_pm_projects',
267 267
 			'phpbrain'    => 'egw_kb_articles',
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 				$entries = (int)$GLOBALS['egw']->db->query('SELECT COUNT(*) FROM '.$table)->fetchColumn();
280 280
 				//echo "$app ($table): $entries<br />\n";
281 281
 			}
282
-			catch(Api\Db\Exception $e) {
282
+			catch (Api\Db\Exception $e) {
283 283
 				unset($e);
284 284
 				$entries = null;
285 285
 			}
@@ -293,19 +293,19 @@  discard block
 block discarded – undo
293 293
 	 * @param boolean $redirect should we redirect or return true
294 294
 	 * @return boolean true if statistic submission is due
295 295
 	 */
296
-	public static function check($redirect=true)
296
+	public static function check($redirect = true)
297 297
 	{
298 298
 		$config = Api\Config::read(self::CONFIG_APP);
299 299
 
300 300
 		if (isset($config[self::CONFIG_POSTPONE_SUBMIT]) && $config[self::CONFIG_POSTPONE_SUBMIT] > time() ||
301
-			isset($config[self::CONFIG_LAST_SUBMIT ]) && $config[self::CONFIG_LAST_SUBMIT ] > time()-self::SUBMISION_RATE)
301
+			isset($config[self::CONFIG_LAST_SUBMIT]) && $config[self::CONFIG_LAST_SUBMIT] > time() - self::SUBMISION_RATE)
302 302
 		{
303 303
 			return false;
304 304
 		}
305 305
 		if (!$redirect) return true;
306 306
 
307 307
 		//die('Due for new statistics submission: last_submit='.$config[self::CONFIG_LAST_SUBMIT ].', postpone='.$config[self::CONFIG_POSTPONE_SUBMIT].', '.function_backtrace());
308
-		Egw::redirect_link('/index.php',array(
308
+		Egw::redirect_link('/index.php', array(
309 309
 			'menuaction' => 'admin.admin_ui.index',
310 310
 			'ajax' => 'true',
311 311
 			'load' => 'admin.admin_statistics.submit',
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -203,9 +203,12 @@  discard block
 block discarded – undo
203 203
 			{
204 204
 				continue;	// --> ignore to not submit too much
205 205
 			}
206
-			if (($users = self::gather_app_users($app)))	// ignore apps noone is allowed to run
206
+			if (($users = self::gather_app_users($app)))
207
+			{
208
+				// ignore apps noone is allowed to run
207 209
 			{
208 210
 				$data['apps'][$app] = $app.':'.round(100.0*$users/$data['users']).'%';
211
+			}
209 212
 				if (($entries = self::gather_app_entries($app)))
210 213
 				{
211 214
 					$data['apps'][$app] .= ':'.$entries;
@@ -302,7 +305,10 @@  discard block
 block discarded – undo
302 305
 		{
303 306
 			return false;
304 307
 		}
305
-		if (!$redirect) return true;
308
+		if (!$redirect)
309
+		{
310
+			return true;
311
+		}
306 312
 
307 313
 		//die('Due for new statistics submission: last_submit='.$config[self::CONFIG_LAST_SUBMIT ].', postpone='.$config[self::CONFIG_POSTPONE_SUBMIT].', '.function_backtrace());
308 314
 		Egw::redirect_link('/index.php',array(
Please login to merge, or discard this patch.
admin/inc/class.admin_ui.inc.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -491,6 +491,10 @@
 block discarded – undo
491 491
 	protected static function call_hook()
492 492
 	{
493 493
 		self::$hook_data = array();
494
+
495
+		/**
496
+		 * @param string $appname
497
+		 */
494 498
 		function display_section($appname,$file,$file2=False)
495 499
 		{
496 500
 			admin_ui::$hook_data[$appname] = $file2 ? $file2 : $file;
Please login to merge, or discard this patch.
Spacing   +31 added lines, -35 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @param array $content
42 42
 	 */
43
-	public function index(array $content=null)
43
+	public function index(array $content = null)
44 44
 	{
45 45
 		if (admin_statistics::check(false))
46 46
 		{
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		//$content['msg'] = 'Hi Ralf ;-)';
66 66
 		$sel_options['tree'] = $this->tree_data();
67 67
 		$sel_options['filter'] = array('' => lang('All groups'));
68
-		foreach(self::$accounts->search(array(
68
+		foreach (self::$accounts->search(array(
69 69
 			'type' => 'groups',
70 70
 			'start' => false,
71 71
 			'order' => 'account_lid',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		}
97 97
 		else
98 98
 		{
99
-			$content['iframe'] = 'about:blank';	// we show accounts-list be default now
99
+			$content['iframe'] = 'about:blank'; // we show accounts-list be default now
100 100
 		}
101 101
 
102 102
 		$tpl->exec('admin.admin_ui.index', $content, $sel_options);
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 				'caption' => 'Show members',
118 118
 				'enableId' => '^/groups/-\\d+',
119 119
 				'default' => true,
120
-				'group' => $group=1,
120
+				'group' => $group = 1,
121 121
 			),
122 122
 			'add' => array(
123 123
 				'group' => $group,
124
-			)+$user_actions['add'],
124
+			) + $user_actions['add'],
125 125
 			'acl' => array(
126 126
 				'onExecute' => 'javaScript:app.admin.group',
127 127
 				'caption' => 'Access control',
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 				'group' => 2,
133 133
 			),
134 134
 		);
135
-		if (!$GLOBALS['egw']->acl->check('account_access',64,'admin'))	// no rights to set ACL-rights
135
+		if (!$GLOBALS['egw']->acl->check('account_access', 64, 'admin'))	// no rights to set ACL-rights
136 136
 		{
137 137
 			$actions['deny'] = array(
138 138
 				'caption'   => 'Deny access',
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
 				'group'     => 2,
144 144
 			);
145 145
 		}
146
-		$group = 5;	// allow to place actions in different groups by hook, this is the default
146
+		$group = 5; // allow to place actions in different groups by hook, this is the default
147 147
 		// supporting both old way using $GLOBALS['menuData'] and new just returning data in hook
148 148
 		$apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_group')));
149
-		foreach($apps as $app)
149
+		foreach ($apps as $app)
150 150
 		{
151 151
 			$GLOBALS['menuData'] = $data = array();
152 152
 			$data = Api\Hooks::single('edit_group', $app);
153 153
 			if (!is_array($data)) $data = $GLOBALS['menuData'];
154 154
 			//error_log(__METHOD__."() app $app returned ".array2string($data));
155
-			foreach($data as $item)
155
+			foreach ($data as $item)
156 156
 			{
157 157
 				// allow hook to return "real" actions, but still support legacy: description, url, extradata, options
158 158
 				if (empty($item['caption']))
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 					'default' => true,
204 204
 					'allowOnMultiple' => false,
205 205
 					'onExecute' => 'javaScript:app.admin.account',
206
-					'group' => $group=0,
206
+					'group' => $group = 0,
207 207
 				),
208 208
 				'add' => array(
209 209
 					'caption' => 'Add user',
@@ -214,25 +214,25 @@  discard block
 block discarded – undo
214 214
 			// generate urls for add/edit accounts via addressbook
215 215
 			$edit = Link::get_registry('addressbook', 'edit');
216 216
 			$edit['account_id'] = '$id';
217
-			foreach($edit as $name => $val)
217
+			foreach ($edit as $name => $val)
218 218
 			{
219 219
 				$actions['edit']['url'] .= ($actions['edit']['url'] ? '&' : '').$name.'='.$val;
220 220
 			}
221 221
 			unset($edit['account_id']);
222 222
 			$edit['owner'] = 0;
223
-			foreach($edit as $name => $val)
223
+			foreach ($edit as $name => $val)
224 224
 			{
225 225
 				$actions['add']['url'] .= ($actions['edit']['url'] ? '&' : '').$name.'='.$val;
226 226
 			}
227 227
 			++$group;
228 228
 			// supporting both old way using $GLOBALS['menuData'] and new just returning data in hook
229 229
 			$apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_user')));
230
-			foreach($apps as $app)
230
+			foreach ($apps as $app)
231 231
 			{
232 232
 				$GLOBALS['menuData'] = $data = array();
233 233
 				$data = Api\Hooks::single('edit_user', $app);
234 234
 				if (!is_array($data)) $data = $GLOBALS['menuData'];
235
-				foreach($data as $item)
235
+				foreach ($data as $item)
236 236
 				{
237 237
 					// allow hook to return "real" actions, but still support legacy: description, url, extradata, options
238 238
 					if (empty($item['caption']))
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @param array &$rows=null
282 282
 	 * @return int total number of rows available
283 283
 	 */
284
-	public static function get_users(array $query, array &$rows=null)
284
+	public static function get_users(array $query, array &$rows = null)
285 285
 	{
286 286
 		$params = array(
287 287
 			'type' => (int)$query['filter'] ? (int)$query['filter'] : 'accounts',
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 			$params['query'] = $query['searchletter'];
297 297
 			$params['query_type'] = 'start';
298 298
 		}
299
-		elseif($query['search'])
299
+		elseif ($query['search'])
300 300
 		{
301 301
 			$params['query'] = $query['search'];
302 302
 			$params['query_type'] = 'all';
@@ -305,13 +305,10 @@  discard block
 block discarded – undo
305 305
 		$rows = array_values(self::$accounts->search($params));
306 306
 		//error_log(__METHOD__."() accounts->search(".array2string($params).") total=".self::$accounts->total);
307 307
 
308
-		foreach($rows as &$row)
308
+		foreach ($rows as &$row)
309 309
 		{
310 310
 			$row['status'] = self::$accounts->is_expired($row) ?
311
-				lang('Expired').' '.Api\DateTime::to($row['account_expires'], true) :
312
-					(!self::$accounts->is_active($row) ? lang('Disabled') :
313
-						($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) :
314
-							lang('Enabled')));
311
+				lang('Expired').' '.Api\DateTime::to($row['account_expires'], true) : (!self::$accounts->is_active($row) ? lang('Disabled') : ($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) : lang('Enabled')));
315 312
 
316 313
 			if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive';
317 314
 		}
@@ -352,14 +349,14 @@  discard block
 block discarded – undo
352 349
 		if ($root == '/')
353 350
 		{
354 351
 			$hook_data = self::call_hook();
355
-			foreach($hook_data as $app => $app_data)
352
+			foreach ($hook_data as $app => $app_data)
356 353
 			{
357
-				if(!is_array($app_data))
354
+				if (!is_array($app_data))
358 355
 				{
359 356
 					// Application has no data
360 357
 					continue;
361 358
 				}
362
-				foreach($app_data as $text => $data)
359
+				foreach ($app_data as $text => $data)
363 360
 				{
364 361
 					if (!is_array($data))
365 362
 					{
@@ -390,18 +387,17 @@  discard block
 block discarded – undo
390 387
 						}
391 388
 					}
392 389
 					unset($data['icon']);
393
-					$parent =& $tree['item'];
390
+					$parent = & $tree['item'];
394 391
 					$parts = explode('/', $data['id']);
395
-					if ($data['id'][0] == '/') array_shift($parts);	// remove root
392
+					if ($data['id'][0] == '/') array_shift($parts); // remove root
396 393
 					array_pop($parts);
397 394
 					$path = '';
398
-					foreach($parts as $part)
395
+					foreach ($parts as $part)
399 396
 					{
400 397
 						$path .= ($path == '/' ? '' : '/').$part;
401 398
 						if (!isset($parent[$path]))
402 399
 						{
403
-							$icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') :
404
-								(($i=Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav')));
400
+							$icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') : (($i = Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav')));
405 401
 							$parent[$path] = array(
406 402
 								'id' => $path,
407 403
 								'text' => $part == 'apps' ? lang('Applications') : lang($part),
@@ -413,7 +409,7 @@  discard block
 block discarded – undo
413 409
 							);
414 410
 							if ($path == '/admin') $parent[$path]['open'] = true;
415 411
 						}
416
-						$parent =& $parent[$path]['item'];
412
+						$parent = & $parent[$path]['item'];
417 413
 					}
418 414
 					$data['text'] = lang($data['text']);
419 415
 					if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']);
@@ -425,7 +421,7 @@  discard block
 block discarded – undo
425 421
 		}
426 422
 		elseif ($root == '/groups')
427 423
 		{
428
-			foreach($GLOBALS['egw']->accounts->search(array(
424
+			foreach ($GLOBALS['egw']->accounts->search(array(
429 425
 				'type' => 'groups',
430 426
 				'order' => 'account_lid',
431 427
 				'sort' => 'ASC',
@@ -452,8 +448,8 @@  discard block
 block discarded – undo
452 448
 	private static function fix_userdata(array $data)
453 449
 	{
454 450
 		// store link as userdata, maybe we should store everything not directly understood by tree this way ...
455
-		foreach(array_diff_key($data, array_flip(array(
456
-			'id','text','tooltip','im0','im1','im2','item','child','select','open','call',
451
+		foreach (array_diff_key($data, array_flip(array(
452
+			'id', 'text', 'tooltip', 'im0', 'im1', 'im2', 'item', 'child', 'select', 'open', 'call',
457 453
 		))) as $name => $content)
458 454
 		{
459 455
 			$data['userdata'][] = array(
@@ -473,7 +469,7 @@  discard block
 block discarded – undo
473 469
 	private static function strip_item_keys(array &$items)
474 470
 	{
475 471
 		$items = array_values($items);
476
-		foreach($items as &$item)
472
+		foreach ($items as &$item)
477 473
 		{
478 474
 			if (is_array($item) && isset($item['item']))
479 475
 			{
@@ -491,7 +487,7 @@  discard block
 block discarded – undo
491 487
 	protected static function call_hook()
492 488
 	{
493 489
 		self::$hook_data = array();
494
-		function display_section($appname,$file,$file2=False)
490
+		function display_section($appname, $file, $file2 = False)
495 491
 		{
496 492
 			admin_ui::$hook_data[$appname] = $file2 ? $file2 : $file;
497 493
 			//error_log(__METHOD__."(".array2string(func_get_args()).")");
Please login to merge, or discard this patch.
Braces   +85 added lines, -21 removed lines patch added patch discarded remove patch
@@ -48,7 +48,10 @@  discard block
 block discarded – undo
48 48
 		}
49 49
 		$tpl = new Etemplate('admin.index');
50 50
 
51
-		if (!is_array($content)) $content = array();
51
+		if (!is_array($content))
52
+		{
53
+			$content = array();
54
+		}
52 55
 		$content['nm'] = array(
53 56
 			'get_rows' => 'admin_ui::get_users',
54 57
 			'no_cat' => true,
@@ -132,7 +135,9 @@  discard block
 block discarded – undo
132 135
 				'group' => 2,
133 136
 			),
134 137
 		);
135
-		if (!$GLOBALS['egw']->acl->check('account_access',64,'admin'))	// no rights to set ACL-rights
138
+		if (!$GLOBALS['egw']->acl->check('account_access',64,'admin'))
139
+		{
140
+			// no rights to set ACL-rights
136 141
 		{
137 142
 			$actions['deny'] = array(
138 143
 				'caption'   => 'Deny access',
@@ -143,6 +148,7 @@  discard block
 block discarded – undo
143 148
 				'group'     => 2,
144 149
 			);
145 150
 		}
151
+		}
146 152
 		$group = 5;	// allow to place actions in different groups by hook, this is the default
147 153
 		// supporting both old way using $GLOBALS['menuData'] and new just returning data in hook
148 154
 		$apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_group')));
@@ -150,7 +156,10 @@  discard block
 block discarded – undo
150 156
 		{
151 157
 			$GLOBALS['menuData'] = $data = array();
152 158
 			$data = Api\Hooks::single('edit_group', $app);
153
-			if (!is_array($data)) $data = $GLOBALS['menuData'];
159
+			if (!is_array($data))
160
+			{
161
+				$data = $GLOBALS['menuData'];
162
+			}
154 163
 			//error_log(__METHOD__."() app $app returned ".array2string($data));
155 164
 			foreach($data as $item)
156 165
 			{
@@ -170,15 +179,33 @@  discard block
 block discarded – undo
170 179
 					{
171 180
 						$item['popup'] = $matches[2].'x'.$matches[3];
172 181
 						$item['onExecute'] = 'javaScript:nm_action';
173
-						if (isset($matches[5])) $item['tooltip'] = $matches[5];
182
+						if (isset($matches[5]))
183
+						{
184
+							$item['tooltip'] = $matches[5];
185
+						}
174 186
 						unset($item['options']);
175 187
 					}
176 188
 				}
177
-				if (empty($item['icon'])) $item['icon'] = $app.'/navbar';
178
-				if (empty($item['group'])) $item['group'] = $group;
179
-				if (empty($item['onExecute'])) $item['onExecute'] = 'javaScript:app.admin.group';
180
-				if (!isset($item['allowOnMultiple'])) $item['allowOnMultiple'] = false;
181
-				if (!isset($item['enableId'])) $item['enableId'] = '^/groups/-\\d+';
189
+				if (empty($item['icon']))
190
+				{
191
+					$item['icon'] = $app.'/navbar';
192
+				}
193
+				if (empty($item['group']))
194
+				{
195
+					$item['group'] = $group;
196
+				}
197
+				if (empty($item['onExecute']))
198
+				{
199
+					$item['onExecute'] = 'javaScript:app.admin.group';
200
+				}
201
+				if (!isset($item['allowOnMultiple']))
202
+				{
203
+					$item['allowOnMultiple'] = false;
204
+				}
205
+				if (!isset($item['enableId']))
206
+				{
207
+					$item['enableId'] = '^/groups/-\\d+';
208
+				}
182 209
 
183 210
 				$actions[$item['id']] = $item;
184 211
 			}
@@ -231,7 +258,10 @@  discard block
 block discarded – undo
231 258
 			{
232 259
 				$GLOBALS['menuData'] = $data = array();
233 260
 				$data = Api\Hooks::single('edit_user', $app);
234
-				if (!is_array($data)) $data = $GLOBALS['menuData'];
261
+				if (!is_array($data))
262
+				{
263
+					$data = $GLOBALS['menuData'];
264
+				}
235 265
 				foreach($data as $item)
236 266
 				{
237 267
 					// allow hook to return "real" actions, but still support legacy: description, url, extradata, options
@@ -249,15 +279,30 @@  discard block
 block discarded – undo
249 279
 						if ($item['options'] && preg_match('/(egw_openWindowCentered2?|window.open)\([^)]+,(\d+),(\d+).*(title="([^"]+)")?/', $item['options'], $matches))
250 280
 						{
251 281
 							$item['popup'] = $matches[2].'x'.$matches[3];
252
-							if (isset($matches[5])) $item['tooltip'] = $matches[5];
282
+							if (isset($matches[5]))
283
+							{
284
+								$item['tooltip'] = $matches[5];
285
+							}
253 286
 							unset($item['options']);
254 287
 						}
255 288
 					}
256
-					if (empty($item['icon'])) $item['icon'] = $app.'/navbar';
257
-					if (empty($item['group'])) $item['group'] = $group;
258
-					if (empty($item['onExecute'])) $item['onExecute'] = $item['popup'] ?
289
+					if (empty($item['icon']))
290
+					{
291
+						$item['icon'] = $app.'/navbar';
292
+					}
293
+					if (empty($item['group']))
294
+					{
295
+						$item['group'] = $group;
296
+					}
297
+					if (empty($item['onExecute']))
298
+					{
299
+						$item['onExecute'] = $item['popup'] ?
259 300
 						'javaScript:nm_action' : 'javaScript:app.admin.iframe_location';
260
-					if (!isset($item['allowOnMultiple'])) $item['allowOnMultiple'] = false;
301
+					}
302
+					if (!isset($item['allowOnMultiple']))
303
+					{
304
+						$item['allowOnMultiple'] = false;
305
+					}
261 306
 
262 307
 					$actions[$item['id']] = $item;
263 308
 				}
@@ -313,7 +358,10 @@  discard block
 block discarded – undo
313 358
 						($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) :
314 359
 							lang('Enabled')));
315 360
 
316
-			if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive';
361
+			if (!self::$accounts->is_active($row))
362
+			{
363
+				$row['status_class'] = 'adminAccountInactive';
364
+			}
317 365
 		}
318 366
 
319 367
 		return self::$accounts->total;
@@ -367,7 +415,10 @@  discard block
 block discarded – undo
367 415
 							'link' => $data,
368 416
 						);
369 417
 					}
370
-					if (empty($data['text'])) $data['text'] = $text;
418
+					if (empty($data['text']))
419
+					{
420
+						$data['text'] = $text;
421
+					}
371 422
 					if (empty($data['id']))
372 423
 					{
373 424
 						$data['id'] = $root.($app == 'admin' ? 'admin' : 'apps/'.$app).'/';
@@ -392,7 +443,11 @@  discard block
 block discarded – undo
392 443
 					unset($data['icon']);
393 444
 					$parent =& $tree['item'];
394 445
 					$parts = explode('/', $data['id']);
395
-					if ($data['id'][0] == '/') array_shift($parts);	// remove root
446
+					if ($data['id'][0] == '/')
447
+					{
448
+						array_shift($parts);
449
+					}
450
+					// remove root
396 451
 					array_pop($parts);
397 452
 					$path = '';
398 453
 					foreach($parts as $part)
@@ -411,14 +466,23 @@  discard block
 block discarded – undo
411 466
 								'item' => array(),
412 467
 								'child' => 1,
413 468
 							);
414
-							if ($path == '/admin') $parent[$path]['open'] = true;
469
+							if ($path == '/admin')
470
+							{
471
+								$parent[$path]['open'] = true;
472
+							}
415 473
 						}
416 474
 						$parent =& $parent[$path]['item'];
417 475
 					}
418 476
 					$data['text'] = lang($data['text']);
419
-					if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']);
477
+					if (!empty($data['tooltip']))
478
+					{
479
+						$data['tooltip'] = lang($data['tooltip']);
480
+					}
420 481
 					// make sure keys are unique, as we overwrite tree entries otherwise
421
-					if (isset($parent[$data['id']])) $data['id'] .= md5($data['link']);
482
+					if (isset($parent[$data['id']]))
483
+					{
484
+						$data['id'] .= md5($data['link']);
485
+					}
422 486
 					$parent[$data['id']] = self::fix_userdata($data);
423 487
 				}
424 488
 			}
Please login to merge, or discard this patch.
admin/inc/class.customfields.inc.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -548,7 +548,7 @@
 block discarded – undo
548 548
 	 * Validate and create a new content type
549 549
 	 *
550 550
 	 * @param array $content
551
-	 * @return string|boolean New type ID, or false for error
551
+	 * @return false|string New type ID, or false for error
552 552
 	 */
553 553
 	function create_content_type(&$content)
554 554
 	{
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
 {
33 33
 
34 34
 	/**
35
-	* appname of app which want to add / edit its customfields
36
-	*
37
-	* @var string
38
-	*/
35
+	 * appname of app which want to add / edit its customfields
36
+	 *
37
+	 * @var string
38
+	 */
39 39
 	var $appname;
40 40
 
41 41
 	/**
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
 	protected $use_private = false;
45 45
 
46 46
 	/**
47
-	* userdefiened types e.g. type of infolog
48
-	*
49
-	* @var array
50
-	*/
47
+	 * userdefiened types e.g. type of infolog
48
+	 *
49
+	 * @var array
50
+	 */
51 51
 	var $types2 = array();
52 52
 	var $content_types,$fields;
53 53
 
@@ -507,8 +507,8 @@  discard block
 block discarded – undo
507 507
 	}
508 508
 
509 509
 	/**
510
-	* deletes custom field from customfield definitions
511
-	*/
510
+	 * deletes custom field from customfield definitions
511
+	 */
512 512
 	function delete_field(&$content)
513 513
 	{
514 514
 		unset($this->fields[key($content['fields']['delete'])]);
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
 	}
526 526
 
527 527
 	/**
528
-	* create a new custom field
529
-	*/
528
+	 * create a new custom field
529
+	 */
530 530
 	function create_field(&$content)
531 531
 	{
532 532
 		$new_name = trim($content['fields'][count($content['fields'])-1]['name']);
@@ -587,8 +587,8 @@  discard block
 block discarded – undo
587 587
 	}
588 588
 
589 589
 	/**
590
-	* save changes to repository
591
-	*/
590
+	 * save changes to repository
591
+	 */
592 592
 	function save_repository()
593 593
 	{
594 594
 		//echo '<p>uicustomfields::save_repository() \$this->fields=<pre style="text-aling: left;">'; print_r($this->fields); echo "</pre>\n";
@@ -601,25 +601,25 @@  discard block
 block discarded – undo
601 601
 	}
602 602
 
603 603
 	/**
604
-	* get customfields of using application
605
-	*
606
-	* @deprecated use Api\Storage\Customfields::get() direct, no need to instanciate this UI class
607
-	* @author Cornelius Weiss
608
-	* @param boolean $all_private_too =false should all the private fields be returned too
609
-	* @return array with customfields
610
-	*/
604
+	 * get customfields of using application
605
+	 *
606
+	 * @deprecated use Api\Storage\Customfields::get() direct, no need to instanciate this UI class
607
+	 * @author Cornelius Weiss
608
+	 * @param boolean $all_private_too =false should all the private fields be returned too
609
+	 * @return array with customfields
610
+	 */
611 611
 	function get_customfields($all_private_too=false)
612 612
 	{
613 613
 		return Api\Storage\Customfields::get($this->appname,$all_private_too);
614 614
 	}
615 615
 
616 616
 	/**
617
-	* get_content_types of using application
618
-	*
619
-	* @deprecated use Api\Config::get_content_types() direct, no need to instanciate this UI class
620
-	* @author Cornelius Weiss
621
-	* @return array with content-types
622
-	*/
617
+	 * get_content_types of using application
618
+	 *
619
+	 * @deprecated use Api\Config::get_content_types() direct, no need to instanciate this UI class
620
+	 * @author Cornelius Weiss
621
+	 * @return array with content-types
622
+	 */
623 623
 	function get_content_types()
624 624
 	{
625 625
 		return Api\Config::get_content_types($this->appname);
Please login to merge, or discard this patch.
Spacing   +79 added lines, -80 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	* @var array
50 50
 	*/
51 51
 	var $types2 = array();
52
-	var $content_types,$fields;
52
+	var $content_types, $fields;
53 53
 
54 54
 	/**
55 55
 	 * Currently selected content type (if used by app)
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @param string $appname
105 105
 	 */
106
-	function __construct($appname='')
106
+	function __construct($appname = '')
107 107
 	{
108 108
 		if (($this->appname = $appname))
109 109
 		{
110
-			$this->fields = Api\Storage\Customfields::get($this->appname,true);
110
+			$this->fields = Api\Storage\Customfields::get($this->appname, true);
111 111
 			$this->content_types = Api\Config::get_content_types($this->appname);
112 112
 		}
113
-		$this->so = new Api\Storage\Base('phpgwapi','egw_customfields',null,'',true);
113
+		$this->so = new Api\Storage\Base('phpgwapi', 'egw_customfields', null, '', true);
114 114
 	}
115 115
 
116 116
 	/**
@@ -120,43 +120,43 @@  discard block
 block discarded – undo
120 120
 	{
121 121
 		// determine appname
122 122
 		$this->appname = $this->appname ? $this->appname : ($_GET['appname'] ? $_GET['appname'] : ($content['appname'] ? $content['appname'] : false));
123
-		if(!$this->appname) die(lang('Error! No appname found'));
123
+		if (!$this->appname) die(lang('Error! No appname found'));
124 124
 
125 125
 		$this->use_private = !isset($_GET['use_private']) || (boolean)$_GET['use_private'] || $content['use_private'];
126 126
 
127 127
 		// Read fields, constructor doesn't always know appname
128
-		$this->fields = Api\Storage\Customfields::get($this->appname,true);
128
+		$this->fields = Api\Storage\Customfields::get($this->appname, true);
129 129
 
130 130
 		$this->tmpl = new Etemplate();
131 131
 		$this->tmpl->read('admin.customfields');
132 132
 
133 133
 		// do we manage content-types?
134 134
 		$test = new Etemplate();
135
-		if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true;
135
+		if ($test->read($this->appname.'.admin.types')) $this->manage_content_types = true;
136 136
 
137 137
 		// Handle incoming - types, options, etc.
138
-		if($this->manage_content_types)
138
+		if ($this->manage_content_types)
139 139
 		{
140
-			if(count($this->content_types) == 0)
140
+			if (count($this->content_types) == 0)
141 141
 			{
142 142
 				$this->content_types = Api\Config::get_content_types($this->appname);
143 143
 			}
144
-			if (count($this->content_types)==0)
144
+			if (count($this->content_types) == 0)
145 145
 			{
146 146
 				// if you define your default types of your app with the search_link hook, they are available here, if no types were found
147
-				$this->content_types = (array)Api\Link::get_registry($this->appname,'default_types');
147
+				$this->content_types = (array)Api\Link::get_registry($this->appname, 'default_types');
148 148
 			}
149 149
 			// Set this now, we need to know it for updates
150
-			$this->content_type = $content['content_types']['types'] ? $content['content_types']['types'] : (array_key_exists(0,$this->content_types) ? $this->content_types[0] : key($this->content_types));
150
+			$this->content_type = $content['content_types']['types'] ? $content['content_types']['types'] : (array_key_exists(0, $this->content_types) ? $this->content_types[0] : key($this->content_types));
151 151
 
152 152
 			// Common type changes - add, delete
153
-			if($content['content_types']['delete'])
153
+			if ($content['content_types']['delete'])
154 154
 			{
155 155
 				$this->delete_content_type($content);
156 156
 			}
157
-			elseif($content['content_types']['create'])
157
+			elseif ($content['content_types']['create'])
158 158
 			{
159
-				if(($new_type = $this->create_content_type($content)))
159
+				if (($new_type = $this->create_content_type($content)))
160 160
 				{
161 161
 					$content['content_types']['types'] = $this->content_type = $new_type;
162 162
 				}
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
 				unset($content['content_types']['name']);
165 165
 			}
166 166
 			// No common type change and type didn't change, try an update
167
-			elseif($this->content_type && is_array($content) && $this->content_type == $content['old_content_type'])
167
+			elseif ($this->content_type && is_array($content) && $this->content_type == $content['old_content_type'])
168 168
 			{
169 169
 				$this->update($content);
170 170
 			}
171 171
 		}
172 172
 
173 173
 		// Custom field deleted from nextmatch
174
-		if($content['nm']['action'] == 'delete')
174
+		if ($content['nm']['action'] == 'delete')
175 175
 		{
176
-			foreach($this->fields as $name => $data)
176
+			foreach ($this->fields as $name => $data)
177 177
 			{
178
-				if(in_array($data['id'],$content['nm']['selected']))
178
+				if (in_array($data['id'], $content['nm']['selected']))
179 179
 				{
180 180
 					unset($this->fields[$name]);
181 181
 				}
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 			$this->save_repository();
185 185
 		}
186 186
 
187
-		$content['nm']= Api\Cache::getSession('admin', 'customfield-index');
187
+		$content['nm'] = Api\Cache::getSession('admin', 'customfield-index');
188 188
 		if (!is_array($content['nm']))
189 189
 		{
190 190
 			// Initialize nextmatch
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
 				'no_filter'      => 'true',
195 195
 				'no_filter2'     => 'true',
196 196
 				'row_id'         => 'cf_id',
197
-				'order'          =>	'cf_order',// IO name of the column to sort
198
-				'sort'           =>	'ASC',// IO direction of the sort: 'ASC' or 'DESC'
197
+				'order'          =>	'cf_order', // IO name of the column to sort
198
+				'sort'           =>	'ASC', // IO direction of the sort: 'ASC' or 'DESC'
199 199
 				'actions'        => $this->get_actions()
200 200
 			);
201 201
 		}
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 		$content['nm']['use_private'] = $this->use_private;
204 204
 
205 205
 		// Set up sub-types
206
-		if($this->manage_content_types)
206
+		if ($this->manage_content_types)
207 207
 		{
208
-			foreach($this->content_types as $type => $entry)
208
+			foreach ($this->content_types as $type => $entry)
209 209
 			{
210
-				if(!is_array($entry))
210
+				if (!is_array($entry))
211 211
 				{
212 212
 					$this->content_types[$type] = array('name' => $entry);
213 213
 					$entry = $this->content_types[$type];
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 			}
217 217
 			$sel_options['types'] = $sel_options['cf_type2'] = $this->types2;
218 218
 
219
-			$content['type_template'] = $this->appname . '.admin.types';
219
+			$content['type_template'] = $this->appname.'.admin.types';
220 220
 			$content['content_types']['appname'] = $this->appname;
221 221
 
222 222
 			$content['content_type_options'] = $this->content_types[$this->content_type]['options'];
@@ -258,15 +258,15 @@  discard block
 block discarded – undo
258 258
 		static::app_index($content, $sel_options, $readonlys, $preserve);
259 259
 
260 260
 		// Make sure app css gets loaded, extending app might cause et2 to miss it
261
-		Framework::includeCSS('admin','app');
261
+		Framework::includeCSS('admin', 'app');
262 262
 
263 263
 		$GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$this->appname]['title'].' - '.lang('Custom fields');
264 264
 
265 265
 		// Some logic to make sure extending class (if there is one) gets called
266 266
 		// when etemplate2 comes back instead of parent class
267
-		$exec = get_class() == get_called_class() ? 'admin.customfields.index' : $this->appname . '.' . get_called_class() . '.index';
267
+		$exec = get_class() == get_called_class() ? 'admin.customfields.index' : $this->appname.'.'.get_called_class().'.index';
268 268
 
269
-		$this->tmpl->exec($exec,$content,$sel_options,$readonlys,$preserve);
269
+		$this->tmpl->exec($exec, $content, $sel_options, $readonlys, $preserve);
270 270
 	}
271 271
 
272 272
 	/**
@@ -281,28 +281,28 @@  discard block
 block discarded – undo
281 281
 
282 282
 		// determine appname
283 283
 		$this->appname = $this->appname ? $this->appname : ($_GET['appname'] ? $_GET['appname'] : ($content['cf_app'] ? $content['cf_app'] : false));
284
-		if(!$this->appname)
284
+		if (!$this->appname)
285 285
 		{
286
-			if($cf_id && $this->so)
286
+			if ($cf_id && $this->so)
287 287
 			{
288 288
 				$content = $this->so->read($cf_id);
289 289
 				$this->appname = $content['cf_app'];
290 290
 			}
291 291
 		}
292
-		if(!$this->appname)
292
+		if (!$this->appname)
293 293
 		{
294 294
 			die(lang('Error! No appname found'));
295 295
 		}
296 296
 		$this->use_private = !isset($_GET['use_private']) || (boolean)$_GET['use_private'] || $content['use_private'];
297 297
 
298 298
 		// Read fields, constructor doesn't always know appname
299
-		$this->fields = Api\Storage\Customfields::get($this->appname,true);
299
+		$this->fields = Api\Storage\Customfields::get($this->appname, true);
300 300
 
301 301
 		// Update based on info returned from template
302 302
 		if (is_array($content))
303 303
 		{
304 304
 			list($action) = @each($content['button']);
305
-			switch($action)
305
+			switch ($action)
306 306
 			{
307 307
 				case 'delete':
308 308
 					$this->so->delete($cf_id);
@@ -311,46 +311,46 @@  discard block
 block discarded – undo
311 311
 					break;
312 312
 				case 'save':
313 313
 				case 'apply':
314
-					if(!$cf_id && $this->fields[$content['cf_name']])
314
+					if (!$cf_id && $this->fields[$content['cf_name']])
315 315
 					{
316
-						Framework::message(lang("Field '%1' already exists !!!",$content['cf_name']),'error');
316
+						Framework::message(lang("Field '%1' already exists !!!", $content['cf_name']), 'error');
317 317
 						$content['cf_name'] = '';
318 318
 						break;
319 319
 					}
320
-					if(empty($content['cf_label']))
320
+					if (empty($content['cf_label']))
321 321
 					{
322 322
 						$content['cf_label'] = $content['cf_name'];
323 323
 					}
324 324
 					if (!empty($content['cf_values']))
325 325
 					{
326 326
 						$values = array();
327
-						if($content['cf_values'][0] === '@')
327
+						if ($content['cf_values'][0] === '@')
328 328
 						{
329
-							$values['@'] = substr($content['cf_values'], $content['cf_values'][1] === '=' ? 2:1);
329
+							$values['@'] = substr($content['cf_values'], $content['cf_values'][1] === '=' ? 2 : 1);
330 330
 						}
331 331
 						else
332 332
 						{
333
-							foreach(explode("\n",trim($content['cf_values'])) as $line)
333
+							foreach (explode("\n", trim($content['cf_values'])) as $line)
334 334
 							{
335
-								list($var_raw,$value) = explode('=',trim($line),2);
335
+								list($var_raw, $value) = explode('=', trim($line), 2);
336 336
 								$var = trim($var_raw);
337
-								$values[$var] = trim($value)==='' ? $var : $value;
337
+								$values[$var] = trim($value) === '' ? $var : $value;
338 338
 							}
339 339
 						}
340 340
 						$content['cf_values'] = $values;
341 341
 					}
342 342
 					$update_content = array();
343
-					foreach($content as $key => $value)
343
+					foreach ($content as $key => $value)
344 344
 					{
345
-						if(substr($key,0,3) == 'cf_')
345
+						if (substr($key, 0, 3) == 'cf_')
346 346
 						{
347
-							$update_content[substr($key,3)] = $value;
347
+							$update_content[substr($key, 3)] = $value;
348 348
 						}
349 349
 					}
350 350
 					Api\Storage\Customfields::update($update_content);
351
-					if(!$cf_id)
351
+					if (!$cf_id)
352 352
 					{
353
-						$this->fields = Api\Storage\Customfields::get($this->appname,true);
353
+						$this->fields = Api\Storage\Customfields::get($this->appname, true);
354 354
 						$cf_id = (int)$this->fields[$content['cf_name']]['id'];
355 355
 					}
356 356
 					Framework::refresh_opener('Saved', 'admin', $cf_id, 'edit');
@@ -371,30 +371,30 @@  discard block
 block discarded – undo
371 371
 
372 372
 		// do we manage content-types?
373 373
 		$test = new Etemplate();
374
-		if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true;
374
+		if ($test->read($this->appname.'.admin.types')) $this->manage_content_types = true;
375 375
 
376 376
 		$this->tmpl = new Etemplate();
377 377
 		$this->tmpl->read('admin.customfield_edit');
378 378
 
379
-		Api\Translation::add_app('infolog');	// til we move the translations
379
+		Api\Translation::add_app('infolog'); // til we move the translations
380 380
 
381 381
 		$GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$this->appname]['title'].' - '.lang('Custom fields');
382 382
 		$sel_options = array();
383 383
 		$readonlys = array();
384 384
 
385 385
 		//echo 'customfields=<pre style="text-align: left;">'; print_r($this->fields); echo "</pre>\n";
386
-		$content['cf_order'] = (count($this->fields)+1) * 10;
386
+		$content['cf_order'] = (count($this->fields) + 1) * 10;
387 387
 		$content['use_private'] = $this->use_private;
388 388
 
389
-		if($cf_id)
389
+		if ($cf_id)
390 390
 		{
391 391
 			$content = array_merge($content, $this->so->read($cf_id));
392 392
 			$this->appname = $content['cf_app'];
393
-			if($content['cf_private'])
393
+			if ($content['cf_private'])
394 394
 			{
395
-				$content['cf_private'] = explode(',',$content['cf_private']);
395
+				$content['cf_private'] = explode(',', $content['cf_private']);
396 396
 			}
397
-			if($content['cf_name'])
397
+			if ($content['cf_name'])
398 398
 			{
399 399
 				$readonlys['cf_name'] = true;
400 400
 			}
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 		if (is_array($content['cf_values']))
408 408
 		{
409 409
 			$values = '';
410
-			foreach($content['cf_values'] as $var => $value)
410
+			foreach ($content['cf_values'] as $var => $value)
411 411
 			{
412 412
 				$values .= (!empty($values) ? "\n" : '').$var.'='.$value;
413 413
 			}
@@ -415,18 +415,18 @@  discard block
 block discarded – undo
415 415
 		}
416 416
 
417 417
 		// Show sub-type row, and get types
418
-		if($this->manage_content_types)
418
+		if ($this->manage_content_types)
419 419
 		{
420
-			if(count($this->content_types) == 0)
420
+			if (count($this->content_types) == 0)
421 421
 			{
422 422
 				$this->content_types = Api\Config::get_content_types($this->appname);
423 423
 			}
424
-			if (count($this->content_types)==0)
424
+			if (count($this->content_types) == 0)
425 425
 			{
426 426
 				// if you define your default types of your app with the search_link hook, they are available here, if no types were found
427
-				$this->content_types = (array)egw_link::get_registry($this->appname,'default_types');
427
+				$this->content_types = (array)egw_link::get_registry($this->appname, 'default_types');
428 428
 			}
429
-			foreach($this->content_types as $type => $entry)
429
+			foreach ($this->content_types as $type => $entry)
430 430
 			{
431 431
 				$this->types2[$type] = is_array($entry) ? $entry['name'] : $entry;
432 432
 			}
@@ -438,19 +438,19 @@  discard block
 block discarded – undo
438 438
 		}
439 439
 
440 440
 		// Include type-specific value help
441
-		foreach(self::$type_option_help as $key => $value)
441
+		foreach (self::$type_option_help as $key => $value)
442 442
 		{
443 443
 			$content['options'][$key] = lang($value);
444 444
 		}
445 445
 		$content['statustext'] = $content['options'][$content['cf_type']];
446 446
 		$content['attributes'] = self::$type_attribute_flags;
447 447
 
448
-		$this->tmpl->exec('admin.customfields.edit',$content,$sel_options,$readonlys,array(
448
+		$this->tmpl->exec('admin.customfields.edit', $content, $sel_options, $readonlys, array(
449 449
 			'cf_id' => $cf_id,
450 450
 			'cf_app' => $this->appname,
451 451
 			'cf_name' => $content['cf_name'],
452 452
 			'use_private' => $this->use_private,
453
-		),2);
453
+		), 2);
454 454
 	}
455 455
 
456 456
 	/**
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 	 */
460 460
 	protected function app_index(&$content, &$sel_options, &$readonlys)
461 461
 	{
462
-		unset($content, $sel_options, $readonlys);	// not used, as this is a stub
462
+		unset($content, $sel_options, $readonlys); // not used, as this is a stub
463 463
 		// This is just a stub.
464 464
 	}
465 465
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 				'allowOnMultiple' => false,
480 480
 				'url' => 'menuaction=admin.customfields.edit&cf_id=$id&use_private='.$this->use_private,
481 481
 				'popup' => '500x380',
482
-				'group' => $group=1,
482
+				'group' => $group = 1,
483 483
 				'disableClass' => 'th',
484 484
 			),
485 485
 			'add' => array(
@@ -529,17 +529,16 @@  discard block
 block discarded – undo
529 529
 	*/
530 530
 	function create_field(&$content)
531 531
 	{
532
-		$new_name = trim($content['fields'][count($content['fields'])-1]['name']);
532
+		$new_name = trim($content['fields'][count($content['fields']) - 1]['name']);
533 533
 		if (empty($new_name) || isset($this->fields[$new_name]))
534 534
 		{
535 535
 			$content['error_msg'] .= empty($new_name) ?
536
-				lang('You have to enter a name, to create a new field!!!') :
537
-				lang("Field '%1' already exists !!!",$new_name);
536
+				lang('You have to enter a name, to create a new field!!!') : lang("Field '%1' already exists !!!", $new_name);
538 537
 		}
539 538
 		else
540 539
 		{
541
-			$this->fields[$new_name] = $content['fields'][count($content['fields'])-1];
542
-			if(!$this->fields[$new_name]['label']) $this->fields[$new_name]['label'] = $this->fields[$new_name]['name'];
540
+			$this->fields[$new_name] = $content['fields'][count($content['fields']) - 1];
541
+			if (!$this->fields[$new_name]['label']) $this->fields[$new_name]['label'] = $this->fields[$new_name]['name'];
543 542
 			$this->save_repository();
544 543
 		}
545 544
 	}
@@ -556,20 +555,20 @@  discard block
 block discarded – undo
556 555
 		$new_type = false;
557 556
 		if (empty($new_name))
558 557
 		{
559
-			$this->tmpl->set_validation_error('content_types[name]','You have to enter a name, to create a new type!!!');
558
+			$this->tmpl->set_validation_error('content_types[name]', 'You have to enter a name, to create a new type!!!');
560 559
 		}
561 560
 		else
562 561
 		{
563
-			foreach($this->content_types as $type)
562
+			foreach ($this->content_types as $type)
564 563
 			{
565
-				if($type['name'] == $new_name)
564
+				if ($type['name'] == $new_name)
566 565
 				{
567
-					$this->tmpl->set_validation_error('content_types[name]',lang("type '%1' already exists !!!",$new_name));
566
+					$this->tmpl->set_validation_error('content_types[name]', lang("type '%1' already exists !!!", $new_name));
568 567
 					return false;
569 568
 				}
570 569
 			}
571 570
 			// search free type character
572
-			for($i=97;$i<=122;$i++)
571
+			for ($i = 97; $i <= 122; $i++)
573 572
 			{
574 573
 				if (!$this->content_types[chr($i)] &&
575 574
 					// skip letter of deleted type for addressbook content-types, as it gives SQL error
@@ -594,7 +593,7 @@  discard block
 block discarded – undo
594 593
 		//echo '<p>uicustomfields::save_repository() \$this->fields=<pre style="text-aling: left;">'; print_r($this->fields); echo "</pre>\n";
595 594
 		$config = new Api\Config($this->appname);
596 595
 		$config->read_repository();
597
-		$config->value('types',$this->content_types);
596
+		$config->value('types', $this->content_types);
598 597
 		$config->save_repository();
599 598
 
600 599
 		Api\Storage\Customfields::save($this->appname, $this->fields);
@@ -608,9 +607,9 @@  discard block
 block discarded – undo
608 607
 	* @param boolean $all_private_too =false should all the private fields be returned too
609 608
 	* @return array with customfields
610 609
 	*/
611
-	function get_customfields($all_private_too=false)
610
+	function get_customfields($all_private_too = false)
612 611
 	{
613
-		return Api\Storage\Customfields::get($this->appname,$all_private_too);
612
+		return Api\Storage\Customfields::get($this->appname, $all_private_too);
614 613
 	}
615 614
 
616 615
 	/**
@@ -636,13 +635,13 @@  discard block
 block discarded – undo
636 635
 		$total = $this->so->get_rows($query, $rows, $readonlys);
637 636
 		unset($query['col_filter']['cf_app']);
638 637
 
639
-		foreach($rows as &$row)
638
+		foreach ($rows as &$row)
640 639
 		{
641 640
 			$row['cf_values'] = json_decode($row['cf_values'], true);
642 641
 			if (is_array($row['cf_values']))
643 642
 			{
644 643
 				$values = '';
645
-				foreach($row['cf_values'] as $var => $value)
644
+				foreach ($row['cf_values'] as $var => $value)
646 645
 				{
647 646
 					$values .= (!empty($values) ? "\n" : '').$var.'='.$value;
648 647
 				}
Please login to merge, or discard this patch.
Braces   +16 added lines, -4 removed lines patch added patch discarded remove patch
@@ -120,7 +120,10 @@  discard block
 block discarded – undo
120 120
 	{
121 121
 		// determine appname
122 122
 		$this->appname = $this->appname ? $this->appname : ($_GET['appname'] ? $_GET['appname'] : ($content['appname'] ? $content['appname'] : false));
123
-		if(!$this->appname) die(lang('Error! No appname found'));
123
+		if(!$this->appname)
124
+		{
125
+			die(lang('Error! No appname found'));
126
+		}
124 127
 
125 128
 		$this->use_private = !isset($_GET['use_private']) || (boolean)$_GET['use_private'] || $content['use_private'];
126 129
 
@@ -132,7 +135,10 @@  discard block
 block discarded – undo
132 135
 
133 136
 		// do we manage content-types?
134 137
 		$test = new Etemplate();
135
-		if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true;
138
+		if($test->read($this->appname.'.admin.types'))
139
+		{
140
+			$this->manage_content_types = true;
141
+		}
136 142
 
137 143
 		// Handle incoming - types, options, etc.
138 144
 		if($this->manage_content_types)
@@ -371,7 +377,10 @@  discard block
 block discarded – undo
371 377
 
372 378
 		// do we manage content-types?
373 379
 		$test = new Etemplate();
374
-		if($test->read($this->appname.'.admin.types')) $this->manage_content_types = true;
380
+		if($test->read($this->appname.'.admin.types'))
381
+		{
382
+			$this->manage_content_types = true;
383
+		}
375 384
 
376 385
 		$this->tmpl = new Etemplate();
377 386
 		$this->tmpl->read('admin.customfield_edit');
@@ -539,7 +548,10 @@  discard block
 block discarded – undo
539 548
 		else
540 549
 		{
541 550
 			$this->fields[$new_name] = $content['fields'][count($content['fields'])-1];
542
-			if(!$this->fields[$new_name]['label']) $this->fields[$new_name]['label'] = $this->fields[$new_name]['name'];
551
+			if(!$this->fields[$new_name]['label'])
552
+			{
553
+				$this->fields[$new_name]['label'] = $this->fields[$new_name]['name'];
554
+			}
543 555
 			$this->save_repository();
544 556
 		}
545 557
 	}
Please login to merge, or discard this patch.
api/src/Accounts.php 3 patches
Doc Comments   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 * All key of the returned array use the 'account_' prefix.
361 361
 	 * For backward compatibility some values are additionaly availible without the prefix, using them is depricated!
362 362
 	 *
363
-	 * @param int|string $id numeric account_id or string with account_lid (use of default value of 0 is depricated!!!)
363
+	 * @param integer $id numeric account_id or string with account_lid (use of default value of 0 is depricated!!!)
364 364
 	 * @param boolean $set_depricated_names =false set _additionaly_ the depricated keys without 'account_' prefix
365 365
 	 * @return array/boolean array with account data (keys: account_id, account_lid, ...) or false if account not found
366 366
 	 */
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	 * - 'account_firstname','account_lastname','account_email','account_fullname','account_phone'
401 401
 	 *
402 402
 	 * @param int|string $id
403
-	 * @return string|boolean json or false if not found
403
+	 * @return string json or false if not found
404 404
 	 */
405 405
 	function json($id)
406 406
 	{
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 	 * Not all existing accounts are visible because off account_selection preference: 'none' or 'groupmembers'
792 792
 	 *
793 793
 	 * @param int|string $account_id nummeric account_id or account_lid
794
-	 * @return boolean true = account is visible, false = account not visible, null = account does not exist
794
+	 * @return null|boolean true = account is visible, false = account not visible, null = account does not exist
795 795
 	 */
796 796
 	function visible($account_id)
797 797
 	{
@@ -986,7 +986,6 @@  discard block
 block discarded – undo
986 986
 	 *
987 987
 	 * @param string $account_lid
988 988
 	 * @param string $passwd
989
-	 * @param array $GLOBALS['auto_create_acct'] values for 'firstname', 'lastname', 'email' and 'primary_group'
990 989
 	 * @return int|boolean account_id or false on error
991 990
 	 */
992 991
 	function auto_add($account_lid, $passwd)
@@ -1106,7 +1105,7 @@  discard block
 block discarded – undo
1106 1105
 	 *
1107 1106
 	 * We use now an instance-wide read-cache storing account-data and members(hips).
1108 1107
 	 *
1109
-	 * @param int|array $account_ids user- or group-id(s) for which cache should be invalidated, default 0 = only search/name2id cache
1108
+	 * @param integer $account_ids user- or group-id(s) for which cache should be invalidated, default 0 = only search/name2id cache
1110 1109
 	 */
1111 1110
 	static function cache_invalidate($account_ids=0)
1112 1111
 	{
Please login to merge, or discard this patch.
Spacing   +101 added lines, -102 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 	 *
58 58
 	 * @var array
59 59
 	 */
60
-	var $depricated_names = array('firstname','lastname','fullname','email','type',
61
-		'status','expires','lastlogin','lastloginfrom','lastpasswd_change');
60
+	var $depricated_names = array('firstname', 'lastname', 'fullname', 'email', 'type',
61
+		'status', 'expires', 'lastlogin', 'lastloginfrom', 'lastpasswd_change');
62 62
 
63 63
 	/**
64 64
 	 * List of all config vars accounts depend on and therefore should be passed in when calling contructor with array syntax
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 	 * @var array
67 67
 	 */
68 68
 	static public $config_vars = array(
69
-		'account_repository', 'auth_type',	// auth_type if fallback if account_repository is not set
70
-		'install_id',	// instance-specific caching
71
-		'auto_create_expire', 'default_group_lid',	// auto-creation of accounts
72
-		'ldap_host','ldap_root_dn','ldap_root_pw','ldap_context','ldap_group_context','ldap_search_filter',	// ldap backend
73
-		'ads_domain', 'ads_host', 'ads_admin_user', 'ads_admin_passwd', 'ads_connection', 'ads_context',	// ads backend
69
+		'account_repository', 'auth_type', // auth_type if fallback if account_repository is not set
70
+		'install_id', // instance-specific caching
71
+		'auto_create_expire', 'default_group_lid', // auto-creation of accounts
72
+		'ldap_host', 'ldap_root_dn', 'ldap_root_pw', 'ldap_context', 'ldap_group_context', 'ldap_search_filter', // ldap backend
73
+		'ads_domain', 'ads_host', 'ads_admin_user', 'ads_admin_passwd', 'ads_connection', 'ads_context', // ads backend
74 74
 	);
75 75
 
76 76
 	/**
@@ -135,18 +135,18 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @param string|array $backend =null string with backend 'sql'|'ldap', or whole config array, default read from global egw_info
137 137
 	 */
138
-	public function __construct($backend=null)
138
+	public function __construct($backend = null)
139 139
 	{
140 140
 		if (is_array($backend))
141 141
 		{
142 142
 			$this->config = $backend;
143 143
 			$backend = null;
144
-			self::$_instance = $this;	// also set instance returned by singleton
145
-			self::$cache = array();		// and empty our internal (session) cache
144
+			self::$_instance = $this; // also set instance returned by singleton
145
+			self::$cache = array(); // and empty our internal (session) cache
146 146
 		}
147 147
 		else
148 148
 		{
149
-			$this->config =& $GLOBALS['egw_info']['server'];
149
+			$this->config = & $GLOBALS['egw_info']['server'];
150 150
 
151 151
 			if (!isset(self::$_instance)) self::$_instance = $this;
152 152
 		}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	function search($param)
196 196
 	{
197 197
 		//error_log(__METHOD__.'('.array2string($param).') '.function_backtrace());
198
-		if (!isset($param['active'])) $param['active'] = true;	// default is true = only return active accounts
198
+		if (!isset($param['active'])) $param['active'] = true; // default is true = only return active accounts
199 199
 
200 200
 		self::setup_cache();
201 201
 		$account_search = &self::$cache['account_search'];
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 		}
208 208
 		// no backend understands $param['app'], only sql understands type owngroups or groupmemember[+memberships]
209 209
 		// --> do an full search first and then filter and limit that search
210
-		elseif($param['app'] || $this->config['account_repository'] != 'sql' &&
211
-			in_array($param['type'], array('owngroups','groupmembers','groupmembers+memberships')))
210
+		elseif ($param['app'] || $this->config['account_repository'] != 'sql' &&
211
+			in_array($param['type'], array('owngroups', 'groupmembers', 'groupmembers+memberships')))
212 212
 		{
213 213
 			$app = $param['app'];
214 214
 			unset($param['app']);
@@ -220,15 +220,15 @@  discard block
 block discarded – undo
220 220
 
221 221
 			if ($param['type'] == 'owngroups')
222 222
 			{
223
-				$members = $this->memberships($GLOBALS['egw_info']['user']['account_id'],true);
223
+				$members = $this->memberships($GLOBALS['egw_info']['user']['account_id'], true);
224 224
 				$param['type'] = 'groups';
225 225
 			}
226
-			elseif(in_array($param['type'],array('groupmembers','groupmembers+memberships')))
226
+			elseif (in_array($param['type'], array('groupmembers', 'groupmembers+memberships')))
227 227
 			{
228 228
 				$members = array();
229
-				foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp)
229
+				foreach ((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp)
230 230
 				{
231
-					$members = array_unique(array_merge($members, (array)$this->members($grp,true,$param['active'])));
231
+					$members = array_unique(array_merge($members, (array)$this->members($grp, true, $param['active'])));
232 232
 					if ($param['type'] == 'groupmembers+memberships') $members[] = $grp;
233 233
 				}
234 234
 				$param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts';
@@ -241,20 +241,20 @@  discard block
 block discarded – undo
241 241
 			if ($app)
242 242
 			{
243 243
 				// we want the result merged, whatever it takes, as we only care for the ids
244
-				$valid = $this->split_accounts($app,!in_array($param['type'],array('accounts','groups')) ? 'merge' : $param['type'],$param['active']);
244
+				$valid = $this->split_accounts($app, !in_array($param['type'], array('accounts', 'groups')) ? 'merge' : $param['type'], $param['active']);
245 245
 			}
246 246
 			if (isset($members))
247 247
 			{
248 248
 				//error_log(__METHOD__.'() members='.array2string($members));
249 249
 				if (!$members) $members = array();
250
-				$valid = !$app ? $members : array_intersect($valid,$members);	// use the intersection
250
+				$valid = !$app ? $members : array_intersect($valid, $members); // use the intersection
251 251
 			}
252 252
 			//error_log(__METHOD__."() limiting result to app='$app' and/or group=$group valid-ids=".array2string($valid));
253 253
 			$n = 0;
254 254
 			$account_search[$serial]['data'] = array();
255 255
 			foreach ($full_search as $id => $data)
256 256
 			{
257
-				if (!in_array($id,$valid))
257
+				if (!in_array($id, $valid))
258 258
 				{
259 259
 					$this->total--;
260 260
 					continue;
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 			$account_search[$serial]['data'] = $this->backend->search($param);
275 275
 			if ($param['type'] !== 'accounts')
276 276
 			{
277
-				foreach($account_search[$serial]['data'] as &$account)
277
+				foreach ($account_search[$serial]['data'] as &$account)
278 278
 				{
279 279
 					// add default description for Admins and Default group
280 280
 					if ($account['account_type'] === 'g' && empty($account['account_description']))
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 		{
304 304
 			$options['filter'] = (array)$options['filter'];
305 305
 		}
306
-		switch($GLOBALS['egw_info']['user']['preferences']['common']['account_display'])
306
+		switch ($GLOBALS['egw_info']['user']['preferences']['common']['account_display'])
307 307
 		{
308 308
 			case 'firstname':
309 309
 			case 'firstall':
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 		}
320 320
 		$only_own = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] === 'groupmembers' &&
321 321
 			!isset($GLOBALS['egw_info']['user']['apps']['admin']);
322
-		switch($options['account_type'])
322
+		switch ($options['account_type'])
323 323
 		{
324 324
 			case 'accounts':
325 325
 				$type = $only_own ? 'groupmembers' : 'accounts';
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 				break;
341 341
 		}
342 342
 		$accounts = array();
343
-		foreach(self::getInstance()->search(array(
343
+		foreach (self::getInstance()->search(array(
344 344
 			'type' => $options['filter']['group'] < 0 ? $options['filter']['group'] : $type,
345 345
 			'query' => $pattern,
346 346
 			'query_type' => 'all',
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 		)) as $account)
349 349
 		{
350 350
 			$accounts[$account['account_id']] = self::format_username($account['account_lid'],
351
-				$account['account_firstname'],$account['account_lastname'],$account['account_id']);
351
+				$account['account_firstname'], $account['account_lastname'], $account['account_id']);
352 352
 		}
353 353
 		return $accounts;
354 354
 	}
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 	 * @param boolean $set_depricated_names =false set _additionaly_ the depricated keys without 'account_' prefix
365 365
 	 * @return array/boolean array with account data (keys: account_id, account_lid, ...) or false if account not found
366 366
 	 */
367
-	function read($id=0,$set_depricated_names=false)
367
+	function read($id = 0, $set_depricated_names = false)
368 368
 	{
369 369
 		if (!$id)	// deprecated use!!!
370 370
 		{
@@ -386,9 +386,9 @@  discard block
 block discarded – undo
386 386
 
387 387
 		if ($set_depricated_names && $data)
388 388
 		{
389
-			foreach($this->depricated_names as $name)
389
+			foreach ($this->depricated_names as $name)
390 390
 			{
391
-				$data[$name] =& $data['account_'.$name];
391
+				$data[$name] = & $data['account_'.$name];
392 392
 			}
393 393
 		}
394 394
 		return $data;
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
 	function json($id)
406 406
 	{
407 407
 		static $keys = array(
408
-			'account_id','account_lid','person_id','account_status',
409
-			'account_firstname','account_lastname','account_email','account_fullname','account_phone',
408
+			'account_id', 'account_lid', 'person_id', 'account_status',
409
+			'account_firstname', 'account_lastname', 'account_email', 'account_fullname', 'account_phone',
410 410
 		);
411 411
 		if (($account = $this->read($id)))
412 412
 		{
@@ -415,9 +415,9 @@  discard block
 block discarded – undo
415 415
 		// for current user, add the apps available to him
416 416
 		if ($id == $GLOBALS['egw_info']['user']['account_id'])
417 417
 		{
418
-			foreach((array)$GLOBALS['egw_info']['user']['apps'] as $app => $data)
418
+			foreach ((array)$GLOBALS['egw_info']['user']['apps'] as $app => $data)
419 419
 			{
420
-				unset($data['table_defs']);	// no need for that on the client
420
+				unset($data['table_defs']); // no need for that on the client
421 421
 				$account['apps'][$app] = $data;
422 422
 			}
423 423
 		}
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	 * @param $lastname ='' lastname
433 433
 	 * @param $accountid =0 id, to check if it's a user or group, otherwise the lid will be used
434 434
 	 */
435
-	static function format_username($lid = '', $firstname = '', $lastname = '', $accountid=0)
435
+	static function format_username($lid = '', $firstname = '', $lastname = '', $accountid = 0)
436 436
 	{
437 437
 		if (!$lid && !$firstname && !$lastname)
438 438
 		{
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 		if (empty($firstname)) $firstname = $lid;
446 446
 		if (empty($lastname) || $is_group)
447 447
 		{
448
-			$lastname  = $is_group ? lang('Group') : lang('User');
448
+			$lastname = $is_group ? lang('Group') : lang('User');
449 449
 		}
450 450
 		$display = $GLOBALS['egw_info']['user']['preferences']['common']['account_display'];
451 451
 
@@ -459,30 +459,30 @@  discard block
 block discarded – undo
459 459
 		}
460 460
 
461 461
 		$name = '';
462
-		switch($display)
462
+		switch ($display)
463 463
 		{
464 464
 			case 'firstname':
465
-				$name = $firstname . ' ' . $lastname;
465
+				$name = $firstname.' '.$lastname;
466 466
 				break;
467 467
 			case 'lastname':
468
-				$name = $lastname . $delimiter . $firstname;
468
+				$name = $lastname.$delimiter.$firstname;
469 469
 				break;
470 470
 			case 'username':
471 471
 				$name = $lid;
472 472
 				break;
473 473
 			case 'firstall':
474
-				$name = $firstname . ' ' . $lastname . ' ['.$lid.']';
474
+				$name = $firstname.' '.$lastname.' ['.$lid.']';
475 475
 				break;
476 476
 			case 'lastall':
477
-				$name = $lastname . $delimiter . $firstname . ' ['.$lid.']';
477
+				$name = $lastname.$delimiter.$firstname.' ['.$lid.']';
478 478
 				break;
479 479
 			case 'allfirst':
480
-				$name = '['.$lid.'] ' . $firstname . ' ' . $lastname;
480
+				$name = '['.$lid.'] '.$firstname.' '.$lastname;
481 481
 				break;
482 482
 			case 'all':
483 483
 				/* fall through */
484 484
 			default:
485
-				$name = '['.$lid.'] ' . $lastname . $delimiter . $firstname;
485
+				$name = '['.$lid.'] '.$lastname.$delimiter.$firstname;
486 486
 		}
487 487
 		return $name;
488 488
 	}
@@ -493,14 +493,14 @@  discard block
 block discarded – undo
493 493
 	 * @param string $account_id =null account id
494 494
 	 * @return string full name of user or "#$accountid" if user not found
495 495
 	 */
496
-	static function username($account_id=null)
496
+	static function username($account_id = null)
497 497
 	{
498 498
 		if ($account_id && !($account = self::cache_read((int)$account_id)))
499 499
 		{
500 500
 			return '#'.$account_id;
501 501
 		}
502 502
 		return self::format_username($account['account_lid'],
503
-			$account['account_firstname'] , $account['account_lastname'], $account_id);
503
+			$account['account_firstname'], $account['account_lastname'], $account_id);
504 504
 	}
505 505
 
506 506
 	/**
@@ -514,9 +514,9 @@  discard block
 block discarded – undo
514 514
 	 * @param string $domain =null domain-name or null to use eGW's default domain $GLOBALS['egw_info']['server']['mail_suffix]
515 515
 	 * @return string with email address
516 516
 	 */
517
-	static function email($first,$last,$account,$domain=null)
517
+	static function email($first, $last, $account, $domain = null)
518 518
 	{
519
-		foreach (array('first','last','account') as $name)
519
+		foreach (array('first', 'last', 'account') as $name)
520 520
 		{
521 521
 			$$name = Translation::to_ascii($$name);
522 522
 		}
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
 		}
538 538
 		if (!$domain) $domain = $GLOBALS['egw_info']['server']['mail_suffix'];
539 539
 
540
-		$email = str_replace(array('first','last','initial','account','dot','underscore','-'),
541
-			array($first,$last,substr($first,0,1),$account,$dot,$underscore,''),
540
+		$email = str_replace(array('first', 'last', 'initial', 'account', 'dot', 'underscore', '-'),
541
+			array($first, $last, substr($first, 0, 1), $account, $dot, $underscore, ''),
542 542
 			$GLOBALS['egw_info']['server']['email_address_format'] ? $GLOBALS['egw_info']['server']['email_address_format'] : 'first-dot-last').
543 543
 			($domain ? '@'.$domain : '');
544 544
 		//echo " = '$email'</p>\n";
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 	 */
553 553
 	protected static function add_default_group_description(array &$data)
554 554
 	{
555
-		switch($data['account_lid'])
555
+		switch ($data['account_lid'])
556 556
 		{
557 557
 			case 'Default':
558 558
 				$data['account_description'] = lang('EGroupware all users group, do NOT delete');
@@ -575,15 +575,15 @@  discard block
 block discarded – undo
575 575
 	 * @param boolean $check_depricated_names =false check _additionaly_ the depricated keys without 'account_' prefix
576 576
 	 * @return int|boolean the account_id or false on error
577 577
 	 */
578
-	function save(&$data,$check_depricated_names=false)
578
+	function save(&$data, $check_depricated_names = false)
579 579
 	{
580 580
 		if ($check_depricated_names)
581 581
 		{
582
-			foreach($this->depricated_names as $name)
582
+			foreach ($this->depricated_names as $name)
583 583
 			{
584 584
 				if (isset($data[$name]) && !isset($data['account_'.$name]))
585 585
 				{
586
-					$data['account_'.$name] =& $data[$name];
586
+					$data['account_'.$name] = & $data[$name];
587 587
 				}
588 588
 			}
589 589
 		}
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 		{
597 597
 			// if we are not on a pure LDAP system, we have to write the account-date via the contacts class now
598 598
 			if (($this->config['account_repository'] == 'sql' || $this->config['contact_repository'] == 'sql-ldap') &&
599
-				(!($old = $this->read($data['account_id'])) ||	// only for new account or changed contact-data
599
+				(!($old = $this->read($data['account_id'])) || // only for new account or changed contact-data
600 600
 				$old['account_firstname'] != $data['account_firstname'] ||
601 601
 				$old['account_lastname'] != $data['account_lastname'] ||
602 602
 				$old['account_email'] != $data['account_email']))
@@ -611,14 +611,14 @@  discard block
 block discarded – undo
611 611
 					'id'         => $data['person_id'],
612 612
 					'owner'      => 0,
613 613
 				);
614
-				$GLOBALS['egw']->contacts->save($contact,true);		// true = ignore addressbook acl
614
+				$GLOBALS['egw']->contacts->save($contact, true); // true = ignore addressbook acl
615 615
 			}
616 616
 			// save primary group if necessary
617
-			if ($data['account_primary_group'] && (!($memberships = $this->memberships($id,true)) ||
618
-				!in_array($data['account_primary_group'],$memberships)))
617
+			if ($data['account_primary_group'] && (!($memberships = $this->memberships($id, true)) ||
618
+				!in_array($data['account_primary_group'], $memberships)))
619 619
 			{
620 620
 				$memberships[] = $data['account_primary_group'];
621
-				$this->set_memberships($memberships, $id);	// invalidates cache for account_id and primary group
621
+				$this->set_memberships($memberships, $id); // invalidates cache for account_id and primary group
622 622
 			}
623 623
 		}
624 624
 		// as some backends set (group-)members in save, we need to invalidate their members too!
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
 	 * @param array $data =null array with account data, not specifying the account is depricated!!!
675 675
 	 * @return boolean true=expired (no more login possible), false otherwise
676 676
 	 */
677
-	function is_expired($data=null)
677
+	function is_expired($data = null)
678 678
 	{
679
-		if (is_null($data)) $data = $this->data;	// depricated use
679
+		if (is_null($data)) $data = $this->data; // depricated use
680 680
 
681 681
 		$expires = isset($data['account_expires']) ? $data['account_expires'] : $data['expires'];
682 682
 
@@ -710,10 +710,10 @@  discard block
 block discarded – undo
710 710
 	 * @param string $account_type =null u = user or g = group, or default null = try both
711 711
 	 * @return int|false numeric account_id or false on error ($name not found)
712 712
 	 */
713
-	function name2id($name,$which='account_lid',$account_type=null)
713
+	function name2id($name, $which = 'account_lid', $account_type = null)
714 714
 	{
715 715
 		// Don't bother searching for empty or non-scalar account_lid
716
-		if(empty($name) || !is_scalar($name))
716
+		if (empty($name) || !is_scalar($name))
717 717
 		{
718 718
 			return False;
719 719
 		}
@@ -721,12 +721,12 @@  discard block
 block discarded – undo
721 721
 		self::setup_cache();
722 722
 		$name_list = &self::$cache['name_list'];
723 723
 
724
-		if(@isset($name_list[$which][$name]) && $name_list[$which][$name])
724
+		if (@isset($name_list[$which][$name]) && $name_list[$which][$name])
725 725
 		{
726 726
 			return $name_list[$which][$name];
727 727
 		}
728 728
 
729
-		return $name_list[$which][$name] = $this->backend->name2id($name,$which,$account_type);
729
+		return $name_list[$which][$name] = $this->backend->name2id($name, $which, $account_type);
730 730
 	}
731 731
 
732 732
 	/**
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 	 * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
739 739
 	 * @return string|boolean converted value or false on error ($account_id not found)
740 740
 	 */
741
-	static function id2name($account_id, $which='account_lid')
741
+	static function id2name($account_id, $which = 'account_lid')
742 742
 	{
743 743
 		if (!is_numeric($account_id) && !($account_id = self::getInstance()->name2id($account_id)))
744 744
 		{
@@ -810,13 +810,13 @@  discard block
 block discarded – undo
810 810
 				$account_lid != $GLOBALS['egw_info']['user']['account_lid'] ||
811 811
 			// only allow group-members for account-selection is groupmembers
812 812
 			$GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
813
-				!array_intersect((array)$this->memberships($account_id,true),
814
-					(array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true))))
813
+				!array_intersect((array)$this->memberships($account_id, true),
814
+					(array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true))))
815 815
 		{
816 816
 			//error_log(__METHOD__."($account_id='$account_lid') returning FALSE");
817
-			return false;	// user is not allowed to see given account
817
+			return false; // user is not allowed to see given account
818 818
 		}
819
-		return true;	// user allowed to see given account
819
+		return true; // user allowed to see given account
820 820
 	}
821 821
 
822 822
 	/**
@@ -826,11 +826,11 @@  discard block
 block discarded – undo
826 826
 	 * @param boolean $just_id =false return just account_id's or account_id => account_lid pairs
827 827
 	 * @return array with account_id's ($just_id) or account_id => account_lid pairs (!$just_id)
828 828
 	 */
829
-	function memberships($account_id, $just_id=false)
829
+	function memberships($account_id, $just_id = false)
830 830
 	{
831 831
 		if (!is_int($account_id) && !is_numeric($account_id))
832 832
 		{
833
-			$account_id = $this->name2id($account_id,'account_lid','u');
833
+			$account_id = $this->name2id($account_id, 'account_lid', 'u');
834 834
 		}
835 835
 		if ($account_id && ($data = self::cache_read($account_id)))
836 836
 		{
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 	 * @param array $groups array with gidnumbers
847 847
 	 * @param int $account_id uidnumber
848 848
 	 */
849
-	function set_memberships($groups,$account_id)
849
+	function set_memberships($groups, $account_id)
850 850
 	{
851 851
 		if (!is_int($account_id) && !is_numeric($account_id))
852 852
 		{
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 	 * @param boolean $active =false true: return only active (not expired or deactived) members, false: return all accounts
875 875
 	 * @return array with account_id ($just_id) or account_id => account_lid pairs (!$just_id)
876 876
 	 */
877
-	function members($account_id, $just_id=false, $active=true)
877
+	function members($account_id, $just_id = false, $active = true)
878 878
 	{
879 879
 		if (!is_int($account_id) && !is_numeric($account_id))
880 880
 		{
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 	 * @param array $members array with uidnumber or uid's
896 896
 	 * @param int $gid gidnumber of group to set
897 897
 	 */
898
-	function set_members($members,$gid)
898
+	function set_members($members, $gid)
899 899
 	{
900 900
 		if (($old_members = $this->members($gid, true, false)) != $members)
901 901
 		{
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 	 * @param boolean $active =false true: return only active (not expired or deactived) members, false: return all accounts
920 920
 	 * @return array/boolean see $use, false on error (wront $use)
921 921
 	 */
922
-	function split_accounts($app_users,$use='both',$active=true)
922
+	function split_accounts($app_users, $use = 'both', $active = true)
923 923
 	{
924 924
 		if (!is_array($app_users))
925 925
 		{
@@ -930,21 +930,21 @@  discard block
 block discarded – undo
930 930
 			{
931 931
 				return $cache;
932 932
 			}
933
-			$app_users = $GLOBALS['egw']->acl->get_ids_for_location('run',1,$app_users);
933
+			$app_users = $GLOBALS['egw']->acl->get_ids_for_location('run', 1, $app_users);
934 934
 		}
935 935
 		$accounts = array(
936 936
 			'accounts' => array(),
937 937
 			'groups' => array(),
938 938
 		);
939
-		foreach($app_users as $id)
939
+		foreach ($app_users as $id)
940 940
 		{
941 941
 			$type = $this->get_type($id);
942
-			if($type == 'g')
942
+			if ($type == 'g')
943 943
 			{
944 944
 				$accounts['groups'][$id] = $id;
945 945
 				if ($use != 'groups')
946 946
 				{
947
-					foreach((array)$this->members($id, true, $active) as $id)
947
+					foreach ((array)$this->members($id, true, $active) as $id)
948 948
 					{
949 949
 						$accounts['accounts'][$id] = $id;
950 950
 					}
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 			$cache = $accounts;
966 966
 		}
967 967
 
968
-		switch($use)
968
+		switch ($use)
969 969
 		{
970 970
 			case 'both':
971 971
 				return $accounts;
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 			case 'accounts':
975 975
 				return $accounts['accounts'];
976 976
 			case 'merge':
977
-				return array_merge($accounts['accounts'],$accounts['groups']);
977
+				return array_merge($accounts['accounts'], $accounts['groups']);
978 978
 		}
979 979
 		return False;
980 980
 	}
@@ -992,21 +992,20 @@  discard block
 block discarded – undo
992 992
 	function auto_add($account_lid, $passwd)
993 993
 	{
994 994
 		$expires = !isset($this->config['auto_create_expire']) ||
995
-			$this->config['auto_create_expire'] == 'never' ? -1 :
996
-			time() + $this->config['auto_create_expire'] + 2;
995
+			$this->config['auto_create_expire'] == 'never' ? -1 : time() + $this->config['auto_create_expire'] + 2;
997 996
 
998 997
 		$memberships = array();
999 998
 		$default_group_id = null;
1000 999
 		// check if we have a comma or semicolon delimited list of groups --> add first as primary and rest as memberships
1001
-		foreach(preg_split('/[,;] */',$this->config['default_group_lid']) as $group_lid)
1000
+		foreach (preg_split('/[,;] */', $this->config['default_group_lid']) as $group_lid)
1002 1001
 		{
1003
-			if (($group_id = $this->name2id($group_lid,'account_lid','g')))
1002
+			if (($group_id = $this->name2id($group_lid, 'account_lid', 'g')))
1004 1003
 			{
1005 1004
 				if (!$default_group_id) $default_group_id = $group_id;
1006 1005
 				$memberships[] = $group_id;
1007 1006
 			}
1008 1007
 		}
1009
-		if (!$default_group_id && ($default_group_id = $this->name2id('Default','account_lid','g')))
1008
+		if (!$default_group_id && ($default_group_id = $this->name2id('Default', 'account_lid', 'g')))
1010 1009
 		{
1011 1010
 			$memberships[] = $default_group_id;
1012 1011
 		}
@@ -1043,25 +1042,25 @@  discard block
 block discarded – undo
1043 1042
 		// set memberships if given
1044 1043
 		if ($memberships)
1045 1044
 		{
1046
-			$this->set_memberships($memberships,$data['account_id']);
1045
+			$this->set_memberships($memberships, $data['account_id']);
1047 1046
 		}
1048 1047
 		// set the appropriate value for the can change password flag (assume users can, if the admin requires users to change their password)
1049 1048
 		$data['changepassword'] = (bool)$GLOBALS['egw_info']['server']['change_pwd_every_x_days'];
1050
-		if(!$data['changepassword'])
1049
+		if (!$data['changepassword'])
1051 1050
 		{
1052
-			$GLOBALS['egw']->acl->add_repository('preferences','nopasswordchange',$data['account_id'],1);
1051
+			$GLOBALS['egw']->acl->add_repository('preferences', 'nopasswordchange', $data['account_id'], 1);
1053 1052
 		}
1054 1053
 		else
1055 1054
 		{
1056
-			$GLOBALS['egw']->acl->delete_repository('preferences','nopasswordchange',$data['account_id']);
1055
+			$GLOBALS['egw']->acl->delete_repository('preferences', 'nopasswordchange', $data['account_id']);
1057 1056
 		}
1058 1057
 		// call hook to notify interested apps about the new account
1059 1058
 		$GLOBALS['hook_values'] = $data;
1060
-		Hooks::process($data+array(
1059
+		Hooks::process($data + array(
1061 1060
 			'location' => 'addaccount',
1062 1061
 			// at login-time only the hooks from the following apps will be called
1063
-			'order' => array('felamimail','fudforum'),
1064
-		),False,True);  // called for every app now, not only enabled ones
1062
+			'order' => array('felamimail', 'fudforum'),
1063
+		), False, True); // called for every app now, not only enabled ones
1065 1064
 		unset($data['changepassword']);
1066 1065
 
1067 1066
 		return $data['account_id'];
@@ -1108,14 +1107,14 @@  discard block
 block discarded – undo
1108 1107
 	 *
1109 1108
 	 * @param int|array $account_ids user- or group-id(s) for which cache should be invalidated, default 0 = only search/name2id cache
1110 1109
 	 */
1111
-	static function cache_invalidate($account_ids=0)
1110
+	static function cache_invalidate($account_ids = 0)
1112 1111
 	{
1113 1112
 		//error_log(__METHOD__.'('.array2string($account_ids).')');
1114 1113
 
1115 1114
 		// instance-wide cache
1116 1115
 		if ($account_ids)
1117 1116
 		{
1118
-			foreach((array)$account_ids as $account_id)
1117
+			foreach ((array)$account_ids as $account_id)
1119 1118
 			{
1120 1119
 				$instance = self::getInstance();
1121 1120
 
@@ -1127,11 +1126,11 @@  discard block
 block discarded – undo
1127 1126
 
1128 1127
 		// session-cache
1129 1128
 		if (self::$cache) self::$cache = array();
1130
-		Cache::unsetSession('accounts_cache','phpgwapi');
1129
+		Cache::unsetSession('accounts_cache', 'phpgwapi');
1131 1130
 
1132
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
1131
+		if (method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
1133 1132
 		{
1134
-			Egw::invalidate_session_cache();	// invalidates whole egw-enviroment if stored in the session
1133
+			Egw::invalidate_session_cache(); // invalidates whole egw-enviroment if stored in the session
1135 1134
 		}
1136 1135
 	}
1137 1136
 
@@ -1155,11 +1154,11 @@  discard block
 block discarded – undo
1155 1154
 	 * @return array
1156 1155
 	 * @throws Exception\WrongParameter if no integer was passed as $account_id
1157 1156
 	 */
1158
-	static function cache_read($account_id, $need_active=false)
1157
+	static function cache_read($account_id, $need_active = false)
1159 1158
 	{
1160 1159
 		if (!is_numeric($account_id)) throw new Exception\WrongParameter('Not an integer!');
1161 1160
 
1162
-		$account =& self::$request_cache[$account_id];
1161
+		$account = & self::$request_cache[$account_id];
1163 1162
 
1164 1163
 		if (!isset($account))	// not in request cache --> try instance cache
1165 1164
 		{
@@ -1190,7 +1189,7 @@  discard block
 block discarded – undo
1190 1189
 		{
1191 1190
 			$instance = self::getInstance();
1192 1191
 			$account['members-active'] = array();
1193
-			foreach((array)$account['members'] as $id => $lid)
1192
+			foreach ((array)$account['members'] as $id => $lid)
1194 1193
 			{
1195 1194
 				if ($instance->is_active($id)) $account['members-active'][$id] = $lid;
1196 1195
 			}
@@ -1216,11 +1215,11 @@  discard block
 block discarded – undo
1216 1215
 	 */
1217 1216
 	private static function setup_cache()
1218 1217
 	{
1219
-		if (is_array(self::$cache)) return;	// cache is already setup
1218
+		if (is_array(self::$cache)) return; // cache is already setup
1220 1219
 
1221 1220
 		if (self::$use_session_cache && is_object($GLOBALS['egw']->session))
1222 1221
 		{
1223
-			self::$cache =& Cache::getSession('accounts_cache','phpgwapi');
1222
+			self::$cache = & Cache::getSession('accounts_cache', 'phpgwapi');
1224 1223
 		}
1225 1224
 		//error_log(__METHOD__."() use_session_cache=".array2string(self::$use_session_cache).", is_array(self::\$cache)=".array2string(is_array(self::$cache)));
1226 1225
 
Please login to merge, or discard this patch.
Braces   +117 added lines, -29 removed lines patch added patch discarded remove patch
@@ -148,7 +148,10 @@  discard block
 block discarded – undo
148 148
 		{
149 149
 			$this->config =& $GLOBALS['egw_info']['server'];
150 150
 
151
-			if (!isset(self::$_instance)) self::$_instance = $this;
151
+			if (!isset(self::$_instance))
152
+			{
153
+				self::$_instance = $this;
154
+			}
152 155
 		}
153 156
 		if (is_null($backend))
154 157
 		{
@@ -195,7 +198,11 @@  discard block
 block discarded – undo
195 198
 	function search($param)
196 199
 	{
197 200
 		//error_log(__METHOD__.'('.array2string($param).') '.function_backtrace());
198
-		if (!isset($param['active'])) $param['active'] = true;	// default is true = only return active accounts
201
+		if (!isset($param['active']))
202
+		{
203
+			$param['active'] = true;
204
+		}
205
+		// default is true = only return active accounts
199 206
 
200 207
 		self::setup_cache();
201 208
 		$account_search = &self::$cache['account_search'];
@@ -229,7 +236,10 @@  discard block
 block discarded – undo
229 236
 				foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp)
230 237
 				{
231 238
 					$members = array_unique(array_merge($members, (array)$this->members($grp,true,$param['active'])));
232
-					if ($param['type'] == 'groupmembers+memberships') $members[] = $grp;
239
+					if ($param['type'] == 'groupmembers+memberships')
240
+					{
241
+						$members[] = $grp;
242
+					}
233 243
 				}
234 244
 				$param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts';
235 245
 			}
@@ -246,7 +256,10 @@  discard block
 block discarded – undo
246 256
 			if (isset($members))
247 257
 			{
248 258
 				//error_log(__METHOD__.'() members='.array2string($members));
249
-				if (!$members) $members = array();
259
+				if (!$members)
260
+				{
261
+					$members = array();
262
+				}
250 263
 				$valid = !$app ? $members : array_intersect($valid,$members);	// use the intersection
251 264
 			}
252 265
 			//error_log(__METHOD__."() limiting result to app='$app' and/or group=$group valid-ids=".array2string($valid));
@@ -366,15 +379,21 @@  discard block
 block discarded – undo
366 379
 	 */
367 380
 	function read($id=0,$set_depricated_names=false)
368 381
 	{
369
-		if (!$id)	// deprecated use!!!
382
+		if (!$id)
383
+		{
384
+			// deprecated use!!!
370 385
 		{
371 386
 			return $this->data ? $this->data : $this->read_repository();
372 387
 		}
388
+		}
373 389
 		if (!is_int($id) && !is_numeric($id))
374 390
 		{
375 391
 			$id = $this->name2id($id);
376 392
 		}
377
-		if (!$id) return false;
393
+		if (!$id)
394
+		{
395
+			return false;
396
+		}
378 397
 
379 398
 		$data = self::cache_read($id);
380 399
 
@@ -442,7 +461,10 @@  discard block
 block discarded – undo
442 461
 		}
443 462
 		$is_group = $GLOBALS['egw']->accounts->get_type($accountid ? $accountid : $lid) == 'g';
444 463
 
445
-		if (empty($firstname)) $firstname = $lid;
464
+		if (empty($firstname))
465
+		{
466
+			$firstname = $lid;
467
+		}
446 468
 		if (empty($lastname) || $is_group)
447 469
 		{
448 470
 			$lastname  = $is_group ? lang('Group') : lang('User');
@@ -521,9 +543,12 @@  discard block
 block discarded – undo
521 543
 			$$name = Translation::to_ascii($$name);
522 544
 		}
523 545
 		//echo " --> ('$first', '$last', '$account')";
524
-		if (!$first && !$last)	// fallback to the account-name, if real names contain only special chars
546
+		if (!$first && !$last)
547
+		{
548
+			// fallback to the account-name, if real names contain only special chars
525 549
 		{
526 550
 			$first = '';
551
+		}
527 552
 			$last = $account;
528 553
 		}
529 554
 		if (!$first || !$last)
@@ -535,7 +560,10 @@  discard block
 block discarded – undo
535 560
 			$dot = '.';
536 561
 			$underscore = '_';
537 562
 		}
538
-		if (!$domain) $domain = $GLOBALS['egw_info']['server']['mail_suffix'];
563
+		if (!$domain)
564
+		{
565
+			$domain = $GLOBALS['egw_info']['server']['mail_suffix'];
566
+		}
539 567
 
540 568
 		$email = str_replace(array('first','last','initial','account','dot','underscore','-'),
541 569
 			array($first,$last,substr($first,0,1),$account,$dot,$underscore,''),
@@ -601,7 +629,10 @@  discard block
 block discarded – undo
601 629
 				$old['account_lastname'] != $data['account_lastname'] ||
602 630
 				$old['account_email'] != $data['account_email']))
603 631
 			{
604
-				if (!$data['person_id']) $data['person_id'] = $old['person_id'];
632
+				if (!$data['person_id'])
633
+				{
634
+					$data['person_id'] = $old['person_id'];
635
+				}
605 636
 
606 637
 				$contact = array(
607 638
 					'n_given'    => $data['account_firstname'],
@@ -641,7 +672,10 @@  discard block
 block discarded – undo
641 672
 		{
642 673
 			$id = $this->name2id($id);
643 674
 		}
644
-		if (!$id) return false;
675
+		if (!$id)
676
+		{
677
+			return false;
678
+		}
645 679
 
646 680
 		if ($this->get_type($id) == 'u')
647 681
 		{
@@ -676,7 +710,11 @@  discard block
 block discarded – undo
676 710
 	 */
677 711
 	function is_expired($data=null)
678 712
 	{
679
-		if (is_null($data)) $data = $this->data;	// depricated use
713
+		if (is_null($data))
714
+		{
715
+			$data = $this->data;
716
+		}
717
+		// depricated use
680 718
 
681 719
 		$expires = isset($data['account_expires']) ? $data['account_expires'] : $data['expires'];
682 720
 
@@ -693,7 +731,10 @@  discard block
 block discarded – undo
693 731
 	 */
694 732
 	function is_active($data)
695 733
 	{
696
-		if (!is_array($data)) $data = $this->read($data);
734
+		if (!is_array($data))
735
+		{
736
+			$data = $this->read($data);
737
+		}
697 738
 
698 739
 		return $data && !(self::is_expired($data) || $data['account_status'] != 'A');
699 740
 	}
@@ -745,7 +786,10 @@  discard block
 block discarded – undo
745 786
 			return false;
746 787
 		}
747 788
 		try {
748
-			if (!($data = self::cache_read($account_id))) return false;
789
+			if (!($data = self::cache_read($account_id)))
790
+			{
791
+				return false;
792
+			}
749 793
 		}
750 794
 		catch (Exception $e) {
751 795
 			unset($e);
@@ -795,14 +839,23 @@  discard block
 block discarded – undo
795 839
 	 */
796 840
 	function visible($account_id)
797 841
 	{
798
-		if (!is_numeric($account_id))	// account_lid given
842
+		if (!is_numeric($account_id))
843
+		{
844
+			// account_lid given
799 845
 		{
800 846
 			$account_lid = $account_id;
801
-			if (!($account_id = $this->name2id($account_lid))) return null;
847
+		}
848
+			if (!($account_id = $this->name2id($account_lid)))
849
+			{
850
+				return null;
851
+			}
802 852
 		}
803 853
 		else
804 854
 		{
805
-			if (!($account_lid = $this->id2name($account_id))) return null;
855
+			if (!($account_lid = $this->id2name($account_id)))
856
+			{
857
+				return null;
858
+			}
806 859
 		}
807 860
 		if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) &&
808 861
 			// do NOT allow other user, if account-selection is none
@@ -856,7 +909,10 @@  discard block
 block discarded – undo
856 909
 		{
857 910
 			$this->backend->set_memberships($groups, $account_id);
858 911
 
859
-			if (!$old_memberships) $old_memberships = array();
912
+			if (!$old_memberships)
913
+			{
914
+				$old_memberships = array();
915
+			}
860 916
 			self::cache_invalidate(array_unique(array_merge(
861 917
 				array($account_id),
862 918
 				array_diff($old_memberships, $groups),
@@ -1002,7 +1058,10 @@  discard block
 block discarded – undo
1002 1058
 		{
1003 1059
 			if (($group_id = $this->name2id($group_lid,'account_lid','g')))
1004 1060
 			{
1005
-				if (!$default_group_id) $default_group_id = $group_id;
1061
+				if (!$default_group_id)
1062
+				{
1063
+					$default_group_id = $group_id;
1064
+				}
1006 1065
 				$memberships[] = $group_id;
1007 1066
 			}
1008 1067
 		}
@@ -1087,7 +1146,10 @@  discard block
 block discarded – undo
1087 1146
 	function change_account_lid_allowed()
1088 1147
 	{
1089 1148
 		$change_account_lid = constant(get_class($this->backend).'::CHANGE_ACCOUNT_LID');
1090
-		if (!isset($change_account_lid)) $change_account_lid = true;
1149
+		if (!isset($change_account_lid))
1150
+		{
1151
+			$change_account_lid = true;
1152
+		}
1091 1153
 		return $change_account_lid;
1092 1154
 	}
1093 1155
 
@@ -1126,12 +1188,19 @@  discard block
 block discarded – undo
1126 1188
 		}
1127 1189
 
1128 1190
 		// session-cache
1129
-		if (self::$cache) self::$cache = array();
1191
+		if (self::$cache)
1192
+		{
1193
+			self::$cache = array();
1194
+		}
1130 1195
 		Cache::unsetSession('accounts_cache','phpgwapi');
1131 1196
 
1132
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
1197
+		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))
1133 1198
 		{
1134
-			Egw::invalidate_session_cache();	// invalidates whole egw-enviroment if stored in the session
1199
+			// egw object in setup is limited
1200
+		{
1201
+			Egw::invalidate_session_cache();
1202
+		}
1203
+		// invalidates whole egw-enviroment if stored in the session
1135 1204
 		}
1136 1205
 	}
1137 1206
 
@@ -1157,27 +1226,39 @@  discard block
 block discarded – undo
1157 1226
 	 */
1158 1227
 	static function cache_read($account_id, $need_active=false)
1159 1228
 	{
1160
-		if (!is_numeric($account_id)) throw new Exception\WrongParameter('Not an integer!');
1229
+		if (!is_numeric($account_id))
1230
+		{
1231
+			throw new Exception\WrongParameter('Not an integer!');
1232
+		}
1161 1233
 
1162 1234
 		$account =& self::$request_cache[$account_id];
1163 1235
 
1164
-		if (!isset($account))	// not in request cache --> try instance cache
1236
+		if (!isset($account))
1237
+		{
1238
+			// not in request cache --> try instance cache
1165 1239
 		{
1166 1240
 			$instance = self::getInstance();
1241
+		}
1167 1242
 
1168 1243
 			$account = Cache::getCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id);
1169 1244
 
1170
-			if (!isset($account))	// not in instance cache --> read from backend
1245
+			if (!isset($account))
1246
+			{
1247
+				// not in instance cache --> read from backend
1171 1248
 			{
1172 1249
 				if (($account = $instance->backend->read($account_id)))
1173 1250
 				{
1174 1251
 					if ($instance->get_type($account_id) == 'u')
1175 1252
 					{
1176 1253
 						if (!isset($account['memberships'])) $account['memberships'] = $instance->backend->memberships($account_id);
1254
+			}
1177 1255
 					}
1178 1256
 					else
1179 1257
 					{
1180
-						if (!isset($account['members'])) $account['members'] = $instance->backend->members($account_id);
1258
+						if (!isset($account['members']))
1259
+						{
1260
+							$account['members'] = $instance->backend->members($account_id);
1261
+						}
1181 1262
 					}
1182 1263
 					Cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
1183 1264
 				}
@@ -1192,7 +1273,10 @@  discard block
 block discarded – undo
1192 1273
 			$account['members-active'] = array();
1193 1274
 			foreach((array)$account['members'] as $id => $lid)
1194 1275
 			{
1195
-				if ($instance->is_active($id)) $account['members-active'][$id] = $lid;
1276
+				if ($instance->is_active($id))
1277
+				{
1278
+					$account['members-active'][$id] = $lid;
1279
+				}
1196 1280
 			}
1197 1281
 			Cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT);
1198 1282
 		}
@@ -1216,7 +1300,11 @@  discard block
 block discarded – undo
1216 1300
 	 */
1217 1301
 	private static function setup_cache()
1218 1302
 	{
1219
-		if (is_array(self::$cache)) return;	// cache is already setup
1303
+		if (is_array(self::$cache))
1304
+		{
1305
+			return;
1306
+		}
1307
+		// cache is already setup
1220 1308
 
1221 1309
 		if (self::$use_session_cache && is_object($GLOBALS['egw']->session))
1222 1310
 		{
Please login to merge, or discard this patch.
api/src/Accounts/Ads.php 4 patches
Doc Comments   +5 added lines, -5 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
 	 */
@@ -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.
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.
Spacing   +113 added lines, -122 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(
@@ -430,10 +429,8 @@  discard block
 block discarded – undo
430 429
 			'account_lastname'  => lang('Group'),
431 430
 			'account_fullname'  => lang('Group').' '.$data['samaccountname'][0],
432 431
 			'account_email'     => $data['mail'][0],
433
-			'account_created'   => !isset($data['whencreated'][0]) ? null :
434
-				self::_when2ts($data['whencreated'][0]),
435
-			'account_modified'  => !isset($data['whenchanged'][0]) ? null :
436
-				self::_when2ts($data['whenchanged'][0]),
432
+			'account_created'   => !isset($data['whencreated'][0]) ? null : self::_when2ts($data['whencreated'][0]),
433
+			'account_modified'  => !isset($data['whenchanged'][0]) ? null : self::_when2ts($data['whenchanged'][0]),
437 434
 			'account_description' => $data['description'][0],
438 435
 			'mailAllowed'       => true,
439 436
 		);
@@ -453,7 +450,7 @@  discard block
 block discarded – undo
453 450
 	{
454 451
 		if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'g', self::$group_attributes)))
455 452
 		{
456
-			return false;	// group not found
453
+			return false; // group not found
457 454
 		}
458 455
 		$group = $this->_ldap2group(array_shift($data));
459 456
 
@@ -476,8 +473,7 @@  discard block
 block discarded – undo
476 473
 		$data = Api\Translation::convert($_data, 'utf-8');
477 474
 
478 475
 		// no need to calculate sid, if already calculated
479
-		$sid = is_string($data['objectsid']) ? $data['objectsid'] :
480
-			$this->adldap->utilities()->getTextSID($data['objectsid'][0]);
476
+		$sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]);
481 477
 		$account_id = self::sid2account_id($sid);
482 478
 
483 479
 		$user = array(
@@ -493,22 +489,18 @@  discard block
 block discarded – undo
493 489
 			'account_email'     => $data['mail'][0],
494 490
 			'account_fullname'  => $data['displayname'][0],
495 491
 			'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])),
501
-			'account_created' => !isset($data['whencreated'][0]) ? null :
502
-				self::_when2ts($data['whencreated'][0]),
503
-			'account_modified' => !isset($data['whenchanged'][0]) ? null :
504
-				self::_when2ts($data['whenchanged'][0]),
492
+			'account_status'    => $data['useraccountcontrol'][0]&2 ? false : 'A',
493
+			'account_expires'   => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]),
494
+			'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])),
495
+			'account_created' => !isset($data['whencreated'][0]) ? null : self::_when2ts($data['whencreated'][0]),
496
+			'account_modified' => !isset($data['whenchanged'][0]) ? null : self::_when2ts($data['whenchanged'][0]),
505 497
 		);
506 498
 		// expired accounts are NOT active
507 499
 		if ($user['account_expires'] !== -1 && $user['account_expires'] < time())
508 500
 		{
509 501
 			$user['account_status'] = false;
510 502
 		}
511
-		$user['person_id'] = $user['account_guid'];	// id of contact
503
+		$user['person_id'] = $user['account_guid']; // id of contact
512 504
 		//error_log(__METHOD__."(".array2string($data).") returning ".array2string($user));
513 505
 		return $user;
514 506
 	}
@@ -538,7 +530,7 @@  discard block
 block discarded – undo
538 530
 	{
539 531
 		if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'u', self::$user_attributes)))
540 532
 		{
541
-			return false;	// user not found
533
+			return false; // user not found
542 534
 		}
543 535
 		$user = $this->_ldap2user(array_shift($data));
544 536
 
@@ -561,10 +553,10 @@  discard block
 block discarded – undo
561 553
 	 */
562 554
 	protected static function _when2ts($_when)
563 555
 	{
564
-		static $utc=null;
556
+		static $utc = null;
565 557
 		if (!isset($utc)) $utc = new \DateTimeZone('UTC');
566 558
 
567
-		list($when) = explode('.', $_when);	// remove .0Z not understood by createFromFormat
559
+		list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat
568 560
 		$datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc);
569 561
 		if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone);
570 562
 
@@ -579,7 +571,7 @@  discard block
 block discarded – undo
579 571
 	 * @param array $old =null current data
580 572
 	 * @return int|false account_id or false on error
581 573
 	 */
582
-	protected function _save_group(array &$data, array $old=null)
574
+	protected function _save_group(array &$data, array $old = null)
583 575
 	{
584 576
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
585 577
 
@@ -590,7 +582,7 @@  discard block
 block discarded – undo
590 582
 				'account_description' => 'description',
591 583
 			);
592 584
 			$attributes = array();
593
-			foreach($new2adldap as $egw => $adldap)
585
+			foreach ($new2adldap as $egw => $adldap)
594 586
 			{
595 587
 				$attributes[$adldap] = (string)$data[$egw];
596 588
 			}
@@ -627,11 +619,11 @@  discard block
 block discarded – undo
627 619
 			'account_description' => 'description',
628 620
 		);
629 621
 		$ldap = array();
630
-		foreach($egw2adldap as $egw => $adldap)
622
+		foreach ($egw2adldap as $egw => $adldap)
631 623
 		{
632 624
 			if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw])
633 625
 			{
634
-				switch($egw)
626
+				switch ($egw)
635 627
 				{
636 628
 					case 'account_description':
637 629
 						$ldap[$adldap] = !empty($data[$egw]) ? $data[$egw] : array();
@@ -644,7 +636,7 @@  discard block
 block discarded – undo
644 636
 			}
645 637
 		}
646 638
 		// attributes not (yet) suppored by adldap
647
-		if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap)))
639
+		if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap)))
648 640
 		{
649 641
 			error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret));
650 642
 			return false;
@@ -660,7 +652,7 @@  discard block
 block discarded – undo
660 652
 	 * @param array $old =null current data
661 653
 	 * @return int|false account_id or false on error
662 654
 	 */
663
-	protected function _save_user(array &$data, array $old=null)
655
+	protected function _save_user(array &$data, array $old = null)
664 656
 	{
665 657
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
666 658
 		if (!isset($data['account_fullname']) && !empty($data['account_firstname']) && !empty($data['account_lastname']))
@@ -680,12 +672,12 @@  discard block
 block discarded – undo
680 672
 				'account_status'    => 'enabled',
681 673
 			);
682 674
 			$attributes = array();
683
-			foreach($new2adldap as $egw => $adldap)
675
+			foreach ($new2adldap as $egw => $adldap)
684 676
 			{
685 677
 				if ($egw == 'account_passwd' && (empty($data[$egw]) ||
686 678
 					!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()))
687 679
 				{
688
-					continue;	// do not try to set password, if no SSL or TLS, whole user creation will fail
680
+					continue; // do not try to set password, if no SSL or TLS, whole user creation will fail
689 681
 				}
690 682
 				if (isset($data[$egw])) $attributes[$adldap] = $data[$egw];
691 683
 			}
@@ -722,7 +714,7 @@  discard block
 block discarded – undo
722 714
 			'account_firstname' => 'firstname',
723 715
 			'account_lastname'  => 'surname',
724 716
 			'account_email'     => 'email',
725
-			'account_fullname'  => 'display_name',	// handeled currently in rename above, as not supported by adLDAP
717
+			'account_fullname'  => 'display_name', // handeled currently in rename above, as not supported by adLDAP
726 718
 			'account_passwd'    => 'password',
727 719
 			'account_status'    => 'enabled',
728 720
 			'account_primary_group' => 'primarygroupid',
@@ -735,7 +727,7 @@  discard block
 block discarded – undo
735 727
 		// for a new entry set certain values (eg. profilePath) to in setup configured value
736 728
 		if ($new_entry)
737 729
 		{
738
-			foreach($this->frontend->config as $name => $value)
730
+			foreach ($this->frontend->config as $name => $value)
739 731
 			{
740 732
 				if (substr($name, 0, 8) == 'ads_new_')
741 733
 				{
@@ -743,22 +735,22 @@  discard block
 block discarded – undo
743 735
 				}
744 736
 			}
745 737
 		}
746
-		foreach($egw2adldap as $egw => $adldap)
738
+		foreach ($egw2adldap as $egw => $adldap)
747 739
 		{
748 740
 			if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw])
749 741
 			{
750
-				switch($egw)
742
+				switch ($egw)
751 743
 				{
752 744
 					case 'account_passwd':
753 745
 						if (!empty($data[$egw]) && ($this->adldap->getUseSSL() || $this->adldap->getUseTLS()))
754 746
 						{
755
-							$attributes[$adldap] = $data[$egw];	// only try to set password, if no SSL or TLS
747
+							$attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS
756 748
 						}
757 749
 						break;
758 750
 					case 'account_primary_group':
759 751
 						// setting a primary group seems to fail, if user is no member of that group
760 752
 						if (isset($old['memberships'][$data[$egw]]) ||
761
-							$this->adldap->group()->addUser($group=$this->id2name($data[$egw]), $data['account_id']))
753
+							$this->adldap->group()->addUser($group = $this->id2name($data[$egw]), $data['account_id']))
762 754
 						{
763 755
 							$old['memberships'][$data[$egw]] = $group;
764 756
 							$ldap[$adldap] = abs($data[$egw]);
@@ -769,11 +761,10 @@  discard block
 block discarded – undo
769 761
 						$ldap['userPrincipalName'] = $data[$egw].'@'.$this->frontend->config['ads_domain'];
770 762
 						break;
771 763
 					case 'account_expires':
772
-						$attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER :
773
-							self::convertUnixTimeToWindowsTime($data[$egw]);
764
+						$attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : self::convertUnixTimeToWindowsTime($data[$egw]);
774 765
 						break;
775 766
 					case 'account_status':
776
-						if ($new_entry && empty($data['account_passwd'])) continue;	// cant active new account without passwd!
767
+						if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd!
777 768
 						$attributes[$adldap] = $data[$egw] == 'A';
778 769
 						break;
779 770
 					case 'account_lastpwd_change':
@@ -795,7 +786,7 @@  discard block
 block discarded – undo
795 786
 		}
796 787
 		//elseif ($attributes) error_log(__METHOD__."(".array2string($data).") adldap->user()->modify('$data[account_lid]', ".array2string($attributes).') returned '.array2string($ret).' '.function_backtrace());
797 788
 		// attributes not (yet) suppored by adldap
798
-		if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap)))
789
+		if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap)))
799 790
 		{
800 791
 			error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret).' ('.ldap_error($ds).') '.function_backtrace());
801 792
 			return false;
@@ -868,11 +859,11 @@  discard block
 block discarded – undo
868 859
 			$query = Api\Ldap::quote(strtolower($param['query']));
869 860
 
870 861
 			$accounts = array();
871
-			if($param['type'] !== 'groups')
862
+			if ($param['type'] !== 'groups')
872 863
 			{
873 864
 				if (!empty($query) && $query != '*')
874 865
 				{
875
-					switch($param['query_type'])
866
+					switch ($param['query_type'])
876 867
 					{
877 868
 						case 'all':
878 869
 						default:
@@ -903,14 +894,14 @@  discard block
 block discarded – undo
903 894
 					$membership_filter = '(|(memberOf='.$this->id2name((int)$param['type'], 'account_dn').')(PrimaryGroupId='.abs($param['type']).'))';
904 895
 					$filter = $filter ? "(&$membership_filter$filter)" : $membership_filter;
905 896
 				}
906
-				foreach($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data)
897
+				foreach ($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data)
907 898
 				{
908 899
 					$account = $this->_ldap2user($data);
909 900
 					if ($param['active'] && !$this->frontend->is_active($account))
910 901
 					{
911 902
 						continue;
912 903
 					}
913
-					$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$account['account_id']);
904
+					$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'], $account['account_firstname'], $account['account_lastname'], $account['account_id']);
914 905
 					$accounts[$account_id] = $account;
915 906
 				}
916 907
 			}
@@ -919,9 +910,9 @@  discard block
 block discarded – undo
919 910
 				$query = Api\Ldap::quote(strtolower($param['query']));
920 911
 
921 912
 				$filter = null;
922
-				if(!empty($query) && $query != '*')
913
+				if (!empty($query) && $query != '*')
923 914
 				{
924
-					switch($param['query_type'])
915
+					switch ($param['query_type'])
925 916
 					{
926 917
 						case 'all':
927 918
 						default:
@@ -935,23 +926,23 @@  discard block
 block discarded – undo
935 926
 					}
936 927
 					$filter = "(|(cn=$query)(description=$query))";
937 928
 				}
938
-				foreach($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data)
929
+				foreach ($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data)
939 930
 				{
940 931
 					$accounts[$account_id] = $this->_ldap2group($data);
941 932
 				}
942 933
 			}
943 934
 			// sort the array
944 935
 			$this->_callback_sort = strtoupper($param['sort']);
945
-			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']);
936
+			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']);
946 937
 			$sortedAccounts = $accounts;
947
-			uasort($sortedAccounts,array($this,'_sort_callback'));
938
+			uasort($sortedAccounts, array($this, '_sort_callback'));
948 939
 			$account_search[$unl_serial]['data'] = $sortedAccounts;
949 940
 
950 941
 			$account_search[$unl_serial]['total'] = $this->total = count($accounts);
951 942
 		}
952 943
 		// return only the wanted accounts
953 944
 		reset($sortedAccounts);
954
-		if(is_numeric($start) && is_numeric($offset))
945
+		if (is_numeric($start) && is_numeric($offset))
955 946
 		{
956 947
 			$account_search[$serial]['data'] = array_slice($sortedAccounts, $start, $offset);
957 948
 			$account_search[$serial]['total'] = $this->total;
@@ -982,19 +973,19 @@  discard block
 block discarded – undo
982 973
 	 * @param array $b
983 974
 	 * @return int
984 975
 	 */
985
-	protected function _sort_callback($a,$b)
976
+	protected function _sort_callback($a, $b)
986 977
 	{
987
-		foreach($this->_callback_order as $col )
978
+		foreach ($this->_callback_order as $col)
988 979
 		{
989
-			if($this->_callback_sort != 'DESC')
980
+			if ($this->_callback_sort != 'DESC')
990 981
 			{
991
-				$cmp = strcasecmp( $a[$col], $b[$col] );
982
+				$cmp = strcasecmp($a[$col], $b[$col]);
992 983
 			}
993 984
 			else
994 985
 			{
995
-				$cmp = strcasecmp( $b[$col], $a[$col] );
986
+				$cmp = strcasecmp($b[$col], $a[$col]);
996 987
 			}
997
-			if ( $cmp != 0 )
988
+			if ($cmp != 0)
998 989
 			{
999 990
 				return $cmp;
1000 991
 			}
@@ -1013,9 +1004,9 @@  discard block
 block discarded – undo
1013 1004
 	 * @param array $accounts =array() array to add filtered accounts too, default empty array
1014 1005
 	 * @return array account_id => account_lid or values for $attrs pairs
1015 1006
 	 */
1016
-	protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array())
1007
+	protected function filter($attr_filter, $account_type = null, array $attrs = null, array $accounts = array())
1017 1008
 	{
1018
-		switch($account_type)
1009
+		switch ($account_type)
1019 1010
 		{
1020 1011
 			case 'u':
1021 1012
 				$type_filter = '(samaccounttype='.adLDAP::ADLDAP_NORMAL_ACCOUNT.')';
@@ -1040,25 +1031,25 @@  discard block
 block discarded – undo
1040 1031
 			}
1041 1032
 			else
1042 1033
 			{
1043
-				foreach($attr_filter as $attr => $value)
1034
+				foreach ($attr_filter as $attr => $value)
1044 1035
 				{
1045 1036
 					$filter .= '('.$attr.'='.$this->adldap->utilities()->ldapSlashes($value).')';
1046 1037
 				}
1047 1038
 			}
1048 1039
 			$filter .= $type_filter.')';
1049 1040
 		}
1050
-		$sri = ldap_search($ds=$this->ldap_connection(), $context=$this->ads_context(), $filter,
1041
+		$sri = ldap_search($ds = $this->ldap_connection(), $context = $this->ads_context(), $filter,
1051 1042
 			$attrs ? $attrs : self::$default_attributes);
1052 1043
 		if (!$sri)
1053 1044
 		{
1054 1045
 			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,
1046
+			$sri = ldap_search($ds = $this->ldap_connection(true), $context = $this->ads_context(), $filter,
1056 1047
 				$attrs ? $attrs : self::$default_attributes);
1057 1048
 		}
1058 1049
 
1059 1050
 		if ($sri && ($allValues = ldap_get_entries($ds, $sri)))
1060 1051
 		{
1061
-			foreach($allValues as $key => $data)
1052
+			foreach ($allValues as $key => $data)
1062 1053
 			{
1063 1054
 				if ($key === 'count') continue;
1064 1055
 
@@ -1072,7 +1063,7 @@  discard block
 block discarded – undo
1072 1063
 
1073 1064
 				if ($data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT && $rid < self::MIN_ACCOUNT_ID)
1074 1065
 				{
1075
-					continue;	// ignore system accounts incl. "Administrator"
1066
+					continue; // ignore system accounts incl. "Administrator"
1076 1067
 				}
1077 1068
 				$accounts[($data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP ? '-' : '').$rid] =
1078 1069
 					$attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8');
@@ -1096,7 +1087,7 @@  discard block
 block discarded – undo
1096 1087
 	 * @param string $account_type u = user, g = group, default null = try both
1097 1088
 	 * @return int|false numeric account_id or false on error ($name not found)
1098 1089
 	 */
1099
-	public function name2id($name, $which='account_lid', $account_type=null)
1090
+	public function name2id($name, $which = 'account_lid', $account_type = null)
1100 1091
 	{
1101 1092
 		static $to_ldap = array(
1102 1093
 			'account_lid'   => 'samaccountname',
@@ -1108,7 +1099,7 @@  discard block
 block discarded – undo
1108 1099
 		$ret = false;
1109 1100
 		if (isset($to_ldap[$which]))
1110 1101
 		{
1111
-			foreach($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
1102
+			foreach ($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
1112 1103
 			{
1113 1104
 				unset($account_lid);
1114 1105
 				$ret = $account_id;
@@ -1128,9 +1119,9 @@  discard block
 block discarded – undo
1128 1119
 	 * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
1129 1120
 	 * @return string/false converted value or false on error ($account_id not found)
1130 1121
 	 */
1131
-	public function id2name($account_id, $which='account_lid')
1122
+	public function id2name($account_id, $which = 'account_lid')
1132 1123
 	{
1133
-		return $this->frontend->id2name($account_id,$which);
1124
+		return $this->frontend->id2name($account_id, $which);
1134 1125
 	}
1135 1126
 
1136 1127
 	/**
@@ -1142,9 +1133,9 @@  discard block
 block discarded – undo
1142 1133
 	 */
1143 1134
 	function update_lastlogin($_account_id, $ip)
1144 1135
 	{
1145
-		unset($_account_id, $ip);	// not used, but required by function signature
1136
+		unset($_account_id, $ip); // not used, but required by function signature
1146 1137
 
1147
-		return false;	// not longer supported
1138
+		return false; // not longer supported
1148 1139
 	}
1149 1140
 
1150 1141
 	/**
@@ -1184,21 +1175,21 @@  discard block
 block discarded – undo
1184 1175
 	 * @param int $account_id uidnumber
1185 1176
 	 * @return int number of added or removed memberships
1186 1177
 	 */
1187
-	function set_memberships($groups,$account_id)
1178
+	function set_memberships($groups, $account_id)
1188 1179
 	{
1189 1180
 		if (!($account = $this->id2name($account_id))) return;
1190 1181
 		$current = array_keys($this->memberships($account_id));
1191 1182
 
1192 1183
 		$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
1184
+		foreach (array(
1185
+			'add' => array_diff($groups, $current), // add account to all groups he is currently not in
1186
+			'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in
1196 1187
 		) as $op => $memberships)
1197 1188
 		{
1198 1189
 			$func = $op.($account_id > 0 ? 'User' : 'Group');
1199
-			foreach($memberships as $gid)
1190
+			foreach ($memberships as $gid)
1200 1191
 			{
1201
-				$ok = $this->adldap->group()->$func($group=$this->id2name($gid), $account);
1192
+				$ok = $this->adldap->group()->$func($group = $this->id2name($gid), $account);
1202 1193
 				//error_log(__METHOD__.'('.array2string($groups).", $account_id) $func('$group', '$account') returned ".array2string($ok));
1203 1194
 				$changed += (int)$ok;
1204 1195
 			}
@@ -1220,15 +1211,15 @@  discard block
 block discarded – undo
1220 1211
 		$current = array_keys($this->members($gid));
1221 1212
 
1222 1213
 		$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
1214
+		foreach (array(
1215
+			'add' => array_diff($users, $current), // add members currently not in
1216
+			'remove' => array_diff($current, $users), // remove members only currently in
1226 1217
 		) as $op => $members)
1227 1218
 		{
1228
-			foreach($members as $account_id)
1219
+			foreach ($members as $account_id)
1229 1220
 			{
1230 1221
 				$func = $op.($account_id > 0 ? 'User' : 'Group');
1231
-				$ok = $this->adldap->group()->$func($group, $account=$this->id2name($account_id));
1222
+				$ok = $this->adldap->group()->$func($group, $account = $this->id2name($account_id));
1232 1223
 				//error_log(__METHOD__.'('.array2string($users).", $account_id) $func('$group', '$account') returned ".array2string($ok));
1233 1224
 				$changed += (int)$ok;
1234 1225
 			}
@@ -1253,7 +1244,7 @@  discard block
 block discarded – undo
1253 1244
 	 */
1254 1245
 	public $charset = 'iso-8859-1';
1255 1246
 
1256
-	function __construct(array $options=array())
1247
+	function __construct(array $options = array())
1257 1248
 	{
1258 1249
 		if (isset($options['charset']))
1259 1250
 		{
@@ -1340,19 +1331,19 @@  discard block
 block discarded – undo
1340 1331
 	public function create($attributes)
1341 1332
 	{
1342 1333
 		// 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())){
1334
+		if (!array_key_exists("username", $attributes)) { return "Missing compulsory field [username]"; }
1335
+		if (!array_key_exists("firstname", $attributes)) { return "Missing compulsory field [firstname]"; }
1336
+		if (!array_key_exists("surname", $attributes)) { return "Missing compulsory field [surname]"; }
1337
+		if (!array_key_exists("email", $attributes)) { return "Missing compulsory field [email]"; }
1338
+		if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; }
1339
+		if (empty($attributes["container"])) { return "Container attribute must be an array or string."; }
1340
+
1341
+		if (array_key_exists("password", $attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) {
1351 1342
 			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1352 1343
 		}
1353 1344
 
1354 1345
 		if (!array_key_exists("display_name", $attributes)) {
1355
-			$attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"];
1346
+			$attributes["display_name"] = $attributes["firstname"]." ".$attributes["surname"];
1356 1347
 		}
1357 1348
 
1358 1349
 		// Translate the schema
@@ -1375,20 +1366,20 @@  discard block
 block discarded – undo
1375 1366
 		// Determine the container
1376 1367
 		if (is_array($attributes['container'])) {
1377 1368
 			$attributes["container"] = array_reverse($attributes["container"]);
1378
-			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1369
+			$attributes["container"] = "OU=".implode(",OU=", $attributes["container"]);
1379 1370
 		}
1380 1371
 		// we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2
1381 1372
 		unset($add['unicodePwd']);
1382 1373
 
1383 1374
 		// Add the entry
1384
-		$result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1375
+		$result = ldap_add($ds = $this->adldap->getLdapConnection(), $dn = "CN=".$add["cn"][0].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add);
1385 1376
 		if ($result != true) {
1386 1377
 			error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1387 1378
 			return false;
1388 1379
 		}
1389 1380
 
1390 1381
 		// now password can be added to still disabled account
1391
-		if (array_key_exists("password",$attributes))
1382
+		if (array_key_exists("password", $attributes))
1392 1383
 		{
1393 1384
 			if (!$this->setPassword($dn, $attributes['password'])) return false;
1394 1385
 
@@ -1415,13 +1406,13 @@  discard block
 block discarded – undo
1415 1406
     */
1416 1407
     public function encodePassword($password)
1417 1408
     {
1418
-        $password="\"".$password."\"";
1409
+        $password = "\"".$password."\"";
1419 1410
         if (function_exists('mb_convert_encoding'))
1420 1411
         {
1421 1412
             return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422 1413
         }
1423
-        $encoded="";
1424
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1414
+        $encoded = "";
1415
+        for ($i = 0; $i < strlen($password); $i++) { $encoded .= "{$password{$i}}\000"; }
1425 1416
         return $encoded;
1426 1417
     }
1427 1418
 
@@ -1438,7 +1429,7 @@  discard block
 block discarded – undo
1438 1429
      */
1439 1430
     public function setPassword($dn, $password)
1440 1431
     {
1441
-    	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1432
+    	$result = ldap_mod_replace($ds = $this->adldap->getLdapConnection(), $dn, array(
1442 1433
     		'unicodePwd' => $this->encodePassword($password),
1443 1434
     	));
1444 1435
     	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
@@ -1466,7 +1457,7 @@  discard block
 block discarded – undo
1466 1457
 	* @param string $old_password old password for password change, if supported
1467 1458
     * @return bool
1468 1459
     */
1469
-    public function password($username, $password, $isGUID = false, $old_password=null)
1460
+    public function password($username, $password, $isGUID = false, $old_password = null)
1470 1461
     {
1471 1462
         if ($username === NULL) { return false; }
1472 1463
         if ($password === NULL) { return false; }
@@ -1480,7 +1471,7 @@  discard block
 block discarded – undo
1480 1471
             return false;
1481 1472
         }
1482 1473
 
1483
-        $add=array();
1474
+        $add = array();
1484 1475
 
1485 1476
 		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1486 1477
 			$add["unicodePwd"][0] = $this->encodePassword($password);
@@ -1502,11 +1493,11 @@  discard block
 block discarded – undo
1502 1493
 			);
1503 1494
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1504 1495
 		}
1505
-        if ($result === false){
1496
+        if ($result === false) {
1506 1497
             $err = ldap_errno($this->adldap->getLdapConnection());
1507 1498
             if ($err) {
1508
-                $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
-                if($err == 53) {
1499
+                $msg = 'Error '.$err.': '.ldap_err2str($err).'.';
1500
+                if ($err == 53) {
1510 1501
                     $msg .= ' Your password might not match the password policy.';
1511 1502
                 }
1512 1503
                 throw new adLDAPException($msg);
@@ -1544,13 +1535,13 @@  discard block
 block discarded – undo
1544 1535
         $mod = $this->adldap->adldap_schema($attributes);
1545 1536
 
1546 1537
         // Check to see if this is an enabled status update
1547
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1538
+        if (!$mod && !array_key_exists("enabled", $attributes)) {
1548 1539
             return false;
1549 1540
         }
1550 1541
 
1551 1542
         // Set the account control attribute (only if specified)
1552
-        if (array_key_exists("enabled", $attributes)){
1553
-            if ($attributes["enabled"]){
1543
+        if (array_key_exists("enabled", $attributes)) {
1544
+            if ($attributes["enabled"]) {
1554 1545
                 $controlOptions = array("NORMAL_ACCOUNT");
1555 1546
             }
1556 1547
             else {
@@ -1564,14 +1555,14 @@  discard block
 block discarded – undo
1564 1555
 		if ($mod)
1565 1556
 		{
1566 1557
 	        // Do the update
1567
-	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1558
+	        $result = @ldap_modify($ds = $this->adldap->getLdapConnection(), $userDn, $mod);
1568 1559
 	        if ($result == false) {
1569 1560
 				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1570 1561
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1571 1562
 	        	return false;
1572 1563
 	        }
1573 1564
 		}
1574
-        if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1565
+        if (array_key_exists("password", $attributes) && !$this->setPassword($userDn, $attributes['password']))
1575 1566
 		{
1576 1567
 			return false;
1577 1568
 		}
@@ -1594,10 +1585,10 @@  discard block
 block discarded – undo
1594 1585
 	 */
1595 1586
 	public function create($attributes)
1596 1587
 	{
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."; }
1588
+		if (!is_array($attributes)) { return "Attributes must be an array"; }
1589
+		if (!array_key_exists("group_name", $attributes)) { return "Missing compulsory field [group_name]"; }
1590
+		if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; }
1591
+		if (empty($attributes["container"])) { return "Container attribute must be an array or string."; }
1601 1592
 
1602 1593
 		//$member_array = array();
1603 1594
 		//$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com";
@@ -1613,9 +1604,9 @@  discard block
 block discarded – undo
1613 1604
 		// Determine the container
1614 1605
 		if (is_array($attributes['container'])) {
1615 1606
 			$attributes["container"] = array_reverse($attributes["container"]);
1616
-			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1607
+			$attributes["container"] = "OU=".implode(",OU=", $attributes["container"]);
1617 1608
 		}
1618
-		$result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1609
+		$result = ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add);
1619 1610
 		if ($result != true) {
1620 1611
 			return false;
1621 1612
 		}
@@ -1646,10 +1637,10 @@  discard block
 block discarded – undo
1646 1637
     * @author Port by Andreas Gohr <[email protected]>
1647 1638
     * @return string
1648 1639
     */
1649
-    public function ldapSlashes($str){
1640
+    public function ldapSlashes($str) {
1650 1641
         return preg_replace_callback(
1651 1642
       		'/([\x00-\x1F\*\(\)\\\\])/',
1652
-        	function ($matches) {
1643
+        	function($matches) {
1653 1644
             	return "\\".join("", unpack("H2", $matches[1]));
1654 1645
         	},
1655 1646
         	$str
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.
api/src/Accounts/Ldap.php 5 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 * If no account_id is set in data the account is added and the new id is set in $data.
191 191
 	 *
192 192
 	 * @param array $data array with account-data
193
-	 * @return int|boolean the account_id or false on error
193
+	 * @return false|string the account_id or false on error
194 194
 	 */
195 195
 	function save(&$data)
196 196
 	{
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 	 *
996 996
 	 * @param int $_account_id
997 997
 	 * @param string $ip
998
-	 * @return int lastlogin time
998
+	 * @return boolean lastlogin time
999 999
 	 */
1000 1000
 	function update_lastlogin($_account_id, $ip)
1001 1001
 	{
@@ -1097,7 +1097,6 @@  discard block
 block discarded – undo
1097 1097
 	 * @param int $gid gidnumber of group to set
1098 1098
 	 * @param array $objectclass =null should we set the member and uniqueMember attributes (groupOf(Unique)Names|univentionGroup) (default detect it)
1099 1099
 	 * @param string $use_cn =null if set $cn is used instead $gid and the attributes are returned, not written to ldap
1100
-	 * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it)
1101 1100
 	 * @return boolean/array false on failure, array or true otherwise
1102 1101
 	 */
1103 1102
 	function set_members($members, $gid, array $objectclass=null, $use_cn=null)
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -962,7 +962,7 @@
 block discarded – undo
962 962
 			'account_fullname' => 'cn',
963 963
 		);
964 964
 		if (!isset($to_ldap[$which]) || $account_type === 'g') {
965
-		    return False;
965
+			return False;
966 966
 		}
967 967
 
968 968
 		$sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber'));
Please login to merge, or discard this patch.
Spacing   +138 added lines, -141 removed lines patch added patch discarded remove patch
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
 	 */
90 90
 	var $requiredObjectClasses = array(
91 91
 		'user' => array(
92
-			'top','person','organizationalperson','inetorgperson','posixaccount','shadowaccount'
92
+			'top', 'person', 'organizationalperson', 'inetorgperson', 'posixaccount', 'shadowaccount'
93 93
 		),
94 94
 		'user-if-supported' => array(	// these classes get added, if server supports them
95 95
 			'mozillaabpersonalpha', 'mozillaorgperson', 'evolutionperson',
96 96
 			'univentionperson', 'univentionmail', array('univentionobject', 'univentionObjectType' => 'users/user'),
97 97
 		),
98 98
 		'group' => array(
99
-			'top','posixgroup','groupofnames'
99
+			'top', 'posixgroup', 'groupofnames'
100 100
 		),
101 101
 		'group-if-supported' => array(	// these classes get added, if servers supports them
102 102
 			'univentiongroup', array('univentionobject', 'univentionObjectType' => 'groups/group'),
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	 */
116 116
 	var $group_mail_classes = array(
117 117
 		'dbmailforwardingaddress' => 'mailforwardingaddress',
118
-		'dbmailuser' => array('mailforwardingaddress','uid'),
119
-		'qmailuser' => array('mailforwardingaddress','uid'),
118
+		'dbmailuser' => array('mailforwardingaddress', 'uid'),
119
+		'qmailuser' => array('mailforwardingaddress', 'uid'),
120 120
 		'mailaccount' => 'mailalias',
121 121
 		'univentiongroup' => array(false, false, true),
122 122
 	);
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 		$this->use_session_cache = true;
159 159
 
160 160
 		$this->ldap = Api\Ldap::factory(false, $this->frontend->config['ldap_host'],
161
-			$this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']);
161
+			$this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']);
162 162
 		$this->ds = $this->ldap->ds;
163 163
 
164 164
 		$this->user_context  = $this->frontend->config['ldap_context'];
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	{
197 197
 		$is_group = $data['account_id'] < 0 || $data['account_type'] === 'g';
198 198
 
199
-		$data_utf8 = Api\Translation::convert($data,Api\Translation::charset(),'utf-8');
199
+		$data_utf8 = Api\Translation::convert($data, Api\Translation::charset(), 'utf-8');
200 200
 		$members = $data['account_members'];
201 201
 
202 202
 		if (!is_object($this->ldapServerInfo))
@@ -208,8 +208,7 @@  discard block
 block discarded – undo
208 208
 		if ($data_utf8['account_id'] && $data_utf8['account_lid'])
209 209
 		{
210 210
 			// read the entry first, to check if the dn (account_lid) has changed
211
-			$sri = $is_group ? ldap_search($this->ds,$this->group_context,'gidnumber='.abs($data['account_id'])) :
212
-				ldap_search($this->ds,$this->user_context,'uidnumber='.$data['account_id']);
211
+			$sri = $is_group ? ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($data['account_id'])) : ldap_search($this->ds, $this->user_context, 'uidnumber='.$data['account_id']);
213 212
 			$old = ldap_get_entries($this->ds, $sri);
214 213
 
215 214
 			if (!$old['count'])
@@ -221,9 +220,9 @@  discard block
 block discarded – undo
221 220
 				$old = Api\Ldap::result2array($old[0]);
222 221
 				$old['objectclass'] = array_map('strtolower', $old['objectclass']);
223 222
 				$key = false;
224
-				if ($is_group && ($key = array_search('namedobject',$old['objectclass'])) !== false ||
225
-					$is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'],0,3) != 'cn=') ||
226
-					!$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'],0,4) != 'uid='))
223
+				if ($is_group && ($key = array_search('namedobject', $old['objectclass'])) !== false ||
224
+					$is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 3) != 'cn=') ||
225
+					!$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 4) != 'uid='))
227 226
 				{
228 227
 					// query the memberships to set them again later
229 228
 					if (!$is_group)
@@ -252,7 +251,7 @@  discard block
 block discarded – undo
252 251
 			}
253 252
 		}
254 253
 		// check if we need to write the objectclass: new entry or required object classes are missing
255
-		if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'],$old['objectclass']))
254
+		if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'], $old['objectclass']))
256 255
 		{
257 256
 			// additional objectclasse might be already set in $to_write or $old
258 257
 			if (!is_array($to_write['objectclass']))
@@ -261,7 +260,7 @@  discard block
 block discarded – undo
261 260
 			}
262 261
 			if (!$old)	// for new accounts add additional addressbook object classes, if supported by server
263 262
 			{			// as setting them later might loose eg. password, if we are not allowed to read them
264
-				foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional)
263
+				foreach ($this->requiredObjectClasses[$is_group ? 'group-if-supported' : 'user-if-supported'] as $additional)
265 264
 				{
266 265
 					$add = array();
267 266
 					if (is_array($additional))
@@ -283,8 +282,7 @@  discard block
 block discarded – undo
283 282
 		{
284 283
 			if (!$data['account_lid']) return false;
285 284
 
286
-			$dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context :
287
-				'uid='.$data_utf8['account_lid'].','.$this->user_context;
285
+			$dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : 'uid='.$data_utf8['account_lid'].','.$this->user_context;
288 286
 		}
289 287
 		// now we merge the user or group data
290 288
 		if ($is_group)
@@ -293,23 +291,23 @@  discard block
 block discarded – undo
293 291
 			$data['account_type'] = 'g';
294 292
 
295 293
 			$objectclass = $old ? $old['objectclass'] : $to_write['objectclass'];
296
-			if ($members || !$old && array_intersect(array('groupofnames','groupofuniquenames','univentiongroup'), $objectclass))
294
+			if ($members || !$old && array_intersect(array('groupofnames', 'groupofuniquenames', 'univentiongroup'), $objectclass))
297 295
 			{
298 296
 				$to_write = array_merge($to_write, $this->set_members($members, $data['account_id'], $objectclass, $dn));
299 297
 			}
300 298
 			// check if we should set a mail address and forwards for each member
301
-			foreach($this->group_mail_classes as $objectclass => $forward)
299
+			foreach ($this->group_mail_classes as $objectclass => $forward)
302 300
 			{
303 301
 				$extra_attr = false;
304 302
 				$keep_objectclass = false;
305
-				if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward;
303
+				if (is_array($forward)) list($forward, $extra_attr, $keep_objectclass) = $forward;
306 304
 
307 305
 				if ($this->ldapServerInfo->supportsObjectClass($objectclass) &&
308
-					($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR]))
306
+					($old && in_array($objectclass, $old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR]))
309 307
 				{
310 308
 					if ($data_utf8['account_email'])	// setting an email
311 309
 					{
312
-						if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass']))
310
+						if (!in_array($objectclass, $old ? $old['objectclass'] : $to_write['objectclass']))
313 311
 						{
314 312
 							if ($old) $to_write['objectclass'] = $old['objectclass'];
315 313
 							$to_write['objectclass'][] = $objectclass;
@@ -323,19 +321,19 @@  discard block
 block discarded – undo
323 321
 							$to_write[$forward] = array();
324 322
 							foreach (array_keys($members) as $member)
325 323
 							{
326
-								if (($email = $this->id2name($member,'account_email')))
324
+								if (($email = $this->id2name($member, 'account_email')))
327 325
 								{
328 326
 									$to_write[$forward][] = $email;
329 327
 								}
330 328
 							}
331 329
 						}
332 330
 					}
333
-					elseif($old)	// remove the mail and forwards only for existing entries
331
+					elseif ($old)	// remove the mail and forwards only for existing entries
334 332
 					{
335 333
 						$to_write[static::MAIL_ATTR] = array();
336 334
 						if ($forward) $to_write[$forward] = array();
337 335
 						if ($extra_attr) $to_write[$extra_attr] = array();
338
-						if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass'])))
336
+						if (!$keep_objectclass && ($key = array_search($objectclass, $old['objectclass'])))
339 337
 						{
340 338
 							$to_write['objectclass'] = $old['objectclass'];
341 339
 							unset($to_write['objectclass'][$key]);
@@ -349,7 +347,7 @@  discard block
 block discarded – undo
349 347
 		}
350 348
 		else
351 349
 		{
352
-			$to_write = $this->_merge_user($to_write,$data_utf8,!$old);
350
+			$to_write = $this->_merge_user($to_write, $data_utf8, !$old);
353 351
 			// make sure multiple email-addresses in the mail attribute "survive"
354 352
 			if (isset($to_write[static::MAIL_ATTR]) && count($old[static::MAIL_ATTR]) > 1)
355 353
 			{
@@ -368,21 +366,21 @@  discard block
 block discarded – undo
368 366
 		}
369 367
 
370 368
 		// remove memberuid when adding a group
371
-		if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) {
369
+		if (!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) {
372 370
 			unset($to_write['memberuid']);
373 371
 		}
374 372
 		// modifying or adding the entry
375
-		if ($old && !@ldap_modify($this->ds,$dn,$to_write) ||
376
-			!$old && !@ldap_add($this->ds,$dn,$to_write))
373
+		if ($old && !@ldap_modify($this->ds, $dn, $to_write) ||
374
+			!$old && !@ldap_add($this->ds, $dn, $to_write))
377 375
 		{
378 376
 			$err = true;
379
-			if ($is_group && ($key = array_search('groupofnames',$to_write['objectclass'])) !== false)
377
+			if ($is_group && ($key = array_search('groupofnames', $to_write['objectclass'])) !== false)
380 378
 			{
381 379
 				// try again with removed groupOfNames stuff, as I cant detect if posixGroup is a structural object
382 380
 				unset($to_write['objectclass'][$key]);
383 381
 				$to_write['objectclass'] = array_values($to_write['objectclass']);
384 382
 				unset($to_write['member']);
385
-				$err = $old ? !ldap_modify($this->ds,$dn,$to_write) : !ldap_add($this->ds,$dn,$to_write);
383
+				$err = $old ? !ldap_modify($this->ds, $dn, $to_write) : !ldap_add($this->ds, $dn, $to_write);
386 384
 			}
387 385
 			if ($err)
388 386
 			{
@@ -392,7 +390,7 @@  discard block
 block discarded – undo
392 390
 		}
393 391
 		if ($memberships)
394 392
 		{
395
-			$this->set_memberships($memberships,$data['account_id']);
393
+			$this->set_memberships($memberships, $data['account_id']);
396 394
 		}
397 395
 		return $data['account_id'];
398 396
 	}
@@ -409,14 +407,14 @@  discard block
 block discarded – undo
409 407
 
410 408
 		if ($account_id < 0)
411 409
 		{
412
-			$sri = ldap_search($this->ds, $this->group_context, 'gidnumber=' . abs($account_id));
410
+			$sri = ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($account_id));
413 411
 		}
414 412
 		else
415 413
 		{
416 414
 			// remove the user's memberships
417
-			$this->set_memberships(array(),$account_id);
415
+			$this->set_memberships(array(), $account_id);
418 416
 
419
-			$sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id);
417
+			$sri = ldap_search($this->ds, $this->user_context, 'uidnumber='.$account_id);
420 418
 		}
421 419
 		if (!$sri) return false;
422 420
 
@@ -440,7 +438,7 @@  discard block
 block discarded – undo
440 438
 		{
441 439
 			$this->ldapServerInfo = $this->ldap->getLDAPServerInfo($this->frontend->config['ldap_host']);
442 440
 		}
443
-		foreach(array_keys($this->group_mail_classes) as $objectclass)
441
+		foreach (array_keys($this->group_mail_classes) as $objectclass)
444 442
 		{
445 443
 			if ($this->ldapServerInfo->supportsObjectClass($objectclass))
446 444
 			{
@@ -448,15 +446,15 @@  discard block
 block discarded – undo
448 446
 				break;
449 447
 			}
450 448
 		}
451
-		$sri = ldap_search($this->ds, $this->group_context,'(&(objectClass=posixGroup)(gidnumber=' . abs($account_id).'))',
449
+		$sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(gidnumber='.abs($account_id).'))',
452 450
 			array('dn', 'gidnumber', 'cn', 'objectclass', static::MAIL_ATTR, 'memberuid', 'description'));
453 451
 
454 452
 		$ldap_data = ldap_get_entries($this->ds, $sri);
455 453
 		if (!$ldap_data['count'])
456 454
 		{
457
-			return false;	// group not found
455
+			return false; // group not found
458 456
 		}
459
-		$data = Api\Translation::convert($ldap_data[0],'utf-8');
457
+		$data = Api\Translation::convert($ldap_data[0], 'utf-8');
460 458
 		unset($data['objectclass']['count']);
461 459
 
462 460
 		$group += array(
@@ -477,7 +475,7 @@  discard block
 block discarded – undo
477 475
 		{
478 476
 			unset($data['memberuid']['count']);
479 477
 
480
-			foreach($data['memberuid'] as $lid)
478
+			foreach ($data['memberuid'] as $lid)
481 479
 			{
482 480
 				if (($id = $this->name2id($lid, 'account_lid', 'u')))
483 481
 				{
@@ -498,16 +496,16 @@  discard block
 block discarded – undo
498 496
 	 */
499 497
 	protected function _read_user($account_id)
500 498
 	{
501
-		$sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber=' . (int)$account_id.'))',
502
-			array('dn','uidnumber','uid','gidnumber','givenname','sn','cn',static::MAIL_ATTR,'userpassword','telephonenumber',
503
-				'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp'));
499
+		$sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber='.(int)$account_id.'))',
500
+			array('dn', 'uidnumber', 'uid', 'gidnumber', 'givenname', 'sn', 'cn', static::MAIL_ATTR, 'userpassword', 'telephonenumber',
501
+				'shadowexpire', 'shadowlastchange', 'homedirectory', 'loginshell', 'createtimestamp', 'modifytimestamp'));
504 502
 
505 503
 		$ldap_data = ldap_get_entries($this->ds, $sri);
506 504
 		if (!$ldap_data['count'])
507 505
 		{
508
-			return false;	// user not found
506
+			return false; // user not found
509 507
 		}
510
-		$data = Api\Translation::convert($ldap_data[0],'utf-8');
508
+		$data = Api\Translation::convert($ldap_data[0], 'utf-8');
511 509
 
512 510
 		$utc_diff = date('Z');
513 511
 		$user = array(
@@ -527,13 +525,13 @@  discard block
 block discarded – undo
527 525
 			// - if it's set to 0, the account is disabled
528 526
 			// - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired
529 527
 			// shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60)
530
-			'account_status'    => isset($data['shadowexpire']) && $data['shadowexpire'][0]*24*3600+$utc_diff < time() ? false : 'A',
531
-			'account_expires'   => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC
532
-			'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0]*24*3600+($data['shadowlastchange'][0]!=0?$utc_diff:0) : null,
528
+			'account_status'    => isset($data['shadowexpire']) && $data['shadowexpire'][0] * 24 * 3600 + $utc_diff < time() ? false : 'A',
529
+			'account_expires'   => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC
530
+			'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0] * 24 * 3600 + ($data['shadowlastchange'][0] != 0 ? $utc_diff : 0) : null,
533 531
 			// lastlogin and lastlogin from are not availible via the shadowAccount object class
534 532
 			// 'account_lastlogin' => $data['phpgwaccountlastlogin'][0],
535 533
 			// 'account_lastloginfrom' => $data['phpgwaccountlastloginfrom'][0],
536
-			'person_id'         => $data['uid'][0],	// id of associated contact
534
+			'person_id'         => $data['uid'][0], // id of associated contact
537 535
 			'account_created' => isset($data['createtimestamp'][0]) ? self::accounts_ldap2ts($data['createtimestamp'][0]) : null,
538 536
 			'account_modified' => isset($data['modifytimestamp'][0]) ? self::accounts_ldap2ts($data['modifytimestamp'][0]) : null,
539 537
 		);
@@ -554,7 +552,7 @@  discard block
 block discarded – undo
554 552
 	 * @param array $data array with account-data in utf-8
555 553
 	 * @return array merged data
556 554
 	 */
557
-	protected function _merge_group($to_write,$data,$old=null)
555
+	protected function _merge_group($to_write, $data, $old = null)
558 556
 	{
559 557
 		$to_write['gidnumber'] = abs($data['account_id']);
560 558
 		$to_write['cn'] = $data['account_lid'];
@@ -574,7 +572,7 @@  discard block
 block discarded – undo
574 572
 	 * @param boolean $new_entry
575 573
 	 * @return array merged data
576 574
 	 */
577
-	protected function _merge_user($to_write,$data,$new_entry)
575
+	protected function _merge_user($to_write, $data, $new_entry)
578 576
 	{
579 577
 		$to_write['uidnumber'] = $data['account_id'];
580 578
 		$to_write['uid']       = $data['account_lid'];
@@ -583,12 +581,12 @@  discard block
 block discarded – undo
583 581
 		{
584 582
 			$to_write['givenname'] = $data['account_firstname'] ? $data['account_firstname'] : array();
585 583
 		}
586
-		$to_write['sn']        = $data['account_lastname'];
584
+		$to_write['sn'] = $data['account_lastname'];
587 585
 		if (!$new_entry || $data['account_email'])
588 586
 		{
589
-			$to_write[static::MAIL_ATTR]  = $data['account_email'] ? $data['account_email'] : array();
587
+			$to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array();
590 588
 		}
591
-		$to_write['cn']        = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname'];
589
+		$to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname'];
592 590
 
593 591
 		$utc_diff = date('Z');
594 592
 		if (isset($data['account_passwd']) && $data['account_passwd'])
@@ -597,47 +595,46 @@  discard block
 block discarded – undo
597 595
 			{
598 596
 				$data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']);
599 597
 			}
600
-			elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd']))	// if it's not already entcrypted, do so now
598
+			elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i', $data['account_passwd']))	// if it's not already entcrypted, do so now
601 599
 			{
602 600
 				$data['account_passwd'] = Api\Auth::encrypt_ldap($data['account_passwd']);
603 601
 			}
604 602
 			$to_write['userpassword'] = $data['account_passwd'];
605
-			$to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600));
603
+			$to_write['shadowlastchange'] = round((time() - $utc_diff) / (24 * 3600));
606 604
 		}
607 605
 		// both status and expires are encoded in the single shadowexpire value in LDAP
608 606
 		// - if it's unset an account is enabled AND does never expire
609 607
 		// - if it's set to 0, the account is disabled
610 608
 		// - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired
611 609
 		// shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60)
612
-		$shadowexpire = ($data['account_expires']-$utc_diff) / (24*3600);
610
+		$shadowexpire = ($data['account_expires'] - $utc_diff) / (24 * 3600);
613 611
 
614 612
 		$to_write['shadowexpire'] = !$data['account_status'] ?
615
-			($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) :
616
-			($data['account_expires'] != -1 ? round($shadowexpire) : array());	// array() = unset value
613
+			($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value
617 614
 
618 615
 		if ($new_entry && is_array($to_write['shadowexpire']) && !count($to_write['shadowexpire']))
619 616
 		{
620
-			unset($to_write['shadowexpire']);	// gives protocoll error otherwise
617
+			unset($to_write['shadowexpire']); // gives protocoll error otherwise
621 618
 		}
622 619
 		//error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#');
623
-		if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600));
624
-		if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0;
620
+		if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change'] - $utc_diff) / (24 * 3600));
621
+		if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change'] == 0) $to_write['shadowlastchange'] = 0;
625 622
 		// lastlogin and lastlogin from are not availible via the shadowAccount object class
626 623
 		// $to_write['phpgwaccountlastlogin'] = $data['lastlogin'];
627 624
 		// $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom'];
628 625
 
629 626
 		if ($this->frontend->config['ldap_extra_attributes'])
630 627
 		{
631
-			if (isset($data['homedirectory'])) $to_write['homedirectory']  = $data['homedirectory'];
628
+			if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory'];
632 629
 			if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array();
633 630
 		}
634 631
 		if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory']))
635 632
 		{
636
-			$to_write['homedirectory']  = '/dev/null';	// is a required attribute of posixAccount
633
+			$to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount
637 634
 		}
638 635
 		if ($new_entry && empty($to_write['loginshell']))
639 636
 		{
640
-			unset($to_write['loginshell']);	// setting array() for new entry gives "Protocol error", must not set it
637
+			unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it
641 638
 		}
642 639
 		return $to_write;
643 640
 	}
@@ -665,7 +662,7 @@  discard block
 block discarded – undo
665 662
 	function search($param)
666 663
 	{
667 664
 		//error_log(__METHOD__."(".array2string($param).")");
668
-		$account_search =& Api\Accounts::$cache['account_search'];
665
+		$account_search = & Api\Accounts::$cache['account_search'];
669 666
 
670 667
 		// check if the query is cached
671 668
 		$serial = serialize($param);
@@ -691,12 +688,12 @@  discard block
 block discarded – undo
691 688
 			$query = Api\Ldap::quote(strtolower($param['query']));
692 689
 
693 690
 			$accounts = array();
694
-			if($param['type'] != 'groups')
691
+			if ($param['type'] != 'groups')
695 692
 			{
696 693
 				$filter = "(&(objectclass=posixaccount)";
697 694
 				if (!empty($query) && $query != '*')
698 695
 				{
699
-					switch($param['query_type'])
696
+					switch ($param['query_type'])
700 697
 					{
701 698
 						case 'all':
702 699
 						default:
@@ -723,7 +720,7 @@  discard block
 block discarded – undo
723 720
 					}
724 721
 				}
725 722
 				// add account_filter to filter (user has to be '*', as we otherwise only search uid's)
726
-				$filter .= str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$this->account_filter);
723
+				$filter .= str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $this->account_filter);
727 724
 				$filter .= ')';
728 725
 
729 726
 				if ($param['type'] != 'both')
@@ -742,9 +739,9 @@  discard block
 block discarded – undo
742 739
 						'account_fullname'  => 'cn',
743 740
 						'account_primary_group' => 'gidnumber',
744 741
 					);
745
-					$orders = explode(',',$param['order']);
742
+					$orders = explode(',', $param['order']);
746 743
 					$order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid';
747
-					$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid', $order));
744
+					$sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', $order));
748 745
 					$fullSet = array();
749 746
 					foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry)
750 747
 					{
@@ -754,7 +751,7 @@  discard block
 block discarded – undo
754 751
 					if (is_numeric($param['type'])) // return only group-members
755 752
 					{
756 753
 						$relevantAccounts = array();
757
-						$sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid'));
754
+						$sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=".abs($param['type'])."))", array('memberuid'));
758 755
 						$group = ldap_get_entries($this->ds, $sri);
759 756
 						$fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array();
760 757
 					}
@@ -763,26 +760,26 @@  discard block
 block discarded – undo
763 760
 					$sortFn = $param['sort'] == 'DESC' ? 'arsort' : 'asort';
764 761
 					$sortFn($fullSet);
765 762
 					$relevantAccounts = is_numeric($start) ? array_slice(array_keys($fullSet), $start, $offset) : array_keys($fullSet);
766
-					$filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')';
767
-					$filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter);
763
+					$filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=', $relevantAccounts).'))'.$this->account_filter.')';
764
+					$filter = str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $filter);
768 765
 				}
769
-				$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn',static::MAIL_ATTR,'shadowExpire','createtimestamp','modifytimestamp','objectclass','gidNumber'));
766
+				$sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', 'uidNumber', 'givenname', 'sn', static::MAIL_ATTR, 'shadowExpire', 'createtimestamp', 'modifytimestamp', 'objectclass', 'gidNumber'));
770 767
 
771 768
 				$utc_diff = date('Z');
772
-				foreach(ldap_get_entries($this->ds, $sri) as $allVals)
769
+				foreach (ldap_get_entries($this->ds, $sri) as $allVals)
773 770
 				{
774
-					settype($allVals,'array');
771
+					settype($allVals, 'array');
775 772
 					$test = @$allVals['uid'][0];
776 773
 					if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0])
777 774
 					{
778 775
 						$account = Array(
779 776
 							'account_id'        => $allVals['uidnumber'][0],
780
-							'account_lid'       => Api\Translation::convert($allVals['uid'][0],'utf-8'),
777
+							'account_lid'       => Api\Translation::convert($allVals['uid'][0], 'utf-8'),
781 778
 							'account_type'      => 'u',
782
-							'account_firstname' => Api\Translation::convert($allVals['givenname'][0],'utf-8'),
783
-							'account_lastname'  => Api\Translation::convert($allVals['sn'][0],'utf-8'),
784
-							'account_status'    => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A',
785
-							'account_expires'   => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC
779
+							'account_firstname' => Api\Translation::convert($allVals['givenname'][0], 'utf-8'),
780
+							'account_lastname'  => Api\Translation::convert($allVals['sn'][0], 'utf-8'),
781
+							'account_status'    => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0] * 24 * 3600 - $utc_diff < time() ? false : 'A',
782
+							'account_expires'   => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC
786 783
 							'account_email'     => $allVals[static::MAIL_ATTR][0],
787 784
 							'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null,
788 785
 							'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null,
@@ -808,13 +805,13 @@  discard block
 block discarded – undo
808 805
 			}
809 806
 			if ($param['type'] == 'groups' || $param['type'] == 'both')
810 807
 			{
811
-				if(empty($query) || $query == '*')
808
+				if (empty($query) || $query == '*')
812 809
 				{
813 810
 					$filter = '(objectclass=posixgroup)';
814 811
 				}
815 812
 				else
816 813
 				{
817
-					switch($param['query_type'])
814
+					switch ($param['query_type'])
818 815
 					{
819 816
 						case 'all':
820 817
 						default:
@@ -828,21 +825,21 @@  discard block
 block discarded – undo
828 825
 					}
829 826
 					$filter = "(&(objectclass=posixgroup)(cn=$query))";
830 827
 				}
831
-				$sri = ldap_search($this->ds, $this->group_context, $filter,array('cn','gidNumber'));
832
-				foreach((array)ldap_get_entries($this->ds, $sri) as $allVals)
828
+				$sri = ldap_search($this->ds, $this->group_context, $filter, array('cn', 'gidNumber'));
829
+				foreach ((array)ldap_get_entries($this->ds, $sri) as $allVals)
833 830
 				{
834
-					settype($allVals,'array');
831
+					settype($allVals, 'array');
835 832
 					$test = $allVals['cn'][0];
836 833
 					if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0])
837 834
 					{
838 835
 						$accounts[(string)-$allVals['gidnumber'][0]] = Array(
839 836
 							'account_id'        => -$allVals['gidnumber'][0],
840
-							'account_lid'       => Api\Translation::convert($allVals['cn'][0],'utf-8'),
837
+							'account_lid'       => Api\Translation::convert($allVals['cn'][0], 'utf-8'),
841 838
 							'account_type'      => 'g',
842
-							'account_firstname' => Api\Translation::convert($allVals['cn'][0],'utf-8'),
839
+							'account_firstname' => Api\Translation::convert($allVals['cn'][0], 'utf-8'),
843 840
 							'account_lastname'  => lang('Group'),
844 841
 							'account_status'    => 'A',
845
-							'account_fullname'  => Api\Translation::convert($allVals['cn'][0],'utf-8'),
842
+							'account_fullname'  => Api\Translation::convert($allVals['cn'][0], 'utf-8'),
846 843
 						);
847 844
 						if (isset($totalcount)) ++$totalcount;
848 845
 					}
@@ -850,9 +847,9 @@  discard block
 block discarded – undo
850 847
 			}
851 848
 			// sort the array
852 849
 			$this->_callback_sort = strtoupper($param['sort']);
853
-			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']);
850
+			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']);
854 851
 			$sortedAccounts = $accounts;
855
-			uasort($sortedAccounts,array($this,'_sort_callback'));
852
+			uasort($sortedAccounts, array($this, '_sort_callback'));
856 853
 			$this->total = isset($totalcount) ? $totalcount : count($accounts);
857 854
 
858 855
 			// if totalcount is set, $sortedAccounts is NOT the full set, but already a limited set!
@@ -864,7 +861,7 @@  discard block
 block discarded – undo
864 861
 		}
865 862
 		// return only the wanted accounts
866 863
 		reset($sortedAccounts);
867
-		if(is_numeric($start) && is_numeric($offset))
864
+		if (is_numeric($start) && is_numeric($offset))
868 865
 		{
869 866
 			$account_search[$serial]['total'] = $this->total;
870 867
 			return $account_search[$serial]['data'] = isset($totalcount) ? $sortedAccounts : array_slice($sortedAccounts, $start, $offset);
@@ -892,19 +889,19 @@  discard block
 block discarded – undo
892 889
 	 * @param array $b
893 890
 	 * @return int
894 891
 	 */
895
-	function _sort_callback($a,$b)
892
+	function _sort_callback($a, $b)
896 893
 	{
897
-		foreach($this->_callback_order as $col )
894
+		foreach ($this->_callback_order as $col)
898 895
 		{
899
-			if($this->_callback_sort != 'DESC')
896
+			if ($this->_callback_sort != 'DESC')
900 897
 			{
901
-				$cmp = strcasecmp( $a[$col], $b[$col] );
898
+				$cmp = strcasecmp($a[$col], $b[$col]);
902 899
 			}
903 900
 			else
904 901
 			{
905
-				$cmp = strcasecmp( $b[$col], $a[$col] );
902
+				$cmp = strcasecmp($b[$col], $a[$col]);
906 903
 			}
907
-			if ( $cmp != 0 )
904
+			if ($cmp != 0)
908 905
 			{
909 906
 				return $cmp;
910 907
 			}
@@ -923,8 +920,8 @@  discard block
 block discarded – undo
923 920
 	{
924 921
 		if (!empty($date))
925 922
 		{
926
-			return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2),
927
-				substr($date,4,2),substr($date,6,2),substr($date,0,4));
923
+			return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2),
924
+				substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4));
928 925
 		}
929 926
 		return NULL;
930 927
 	}
@@ -941,14 +938,14 @@  discard block
 block discarded – undo
941 938
 	 * @param string $account_type u = user, g = group, default null = try both
942 939
 	 * @return int|false numeric account_id or false on error ($name not found)
943 940
 	 */
944
-	function name2id($_name,$which='account_lid',$account_type=null)
941
+	function name2id($_name, $which = 'account_lid', $account_type = null)
945 942
 	{
946
-		$name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8'));
943
+		$name = Api\Ldap::quote(Api\Translation::convert($_name, Api\Translation::charset(), 'utf-8'));
947 944
 
948 945
 		if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid
949 946
 		{
950 947
 
951
-			$sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber'));
948
+			$sri = ldap_search($this->ds, $this->group_context, '(&(cn='.$name.')(objectclass=posixgroup))', array('gidNumber'));
952 949
 			$allValues = ldap_get_entries($this->ds, $sri);
953 950
 
954 951
 			if (@$allValues[0]['gidnumber'][0])
@@ -965,7 +962,7 @@  discard block
 block discarded – undo
965 962
 		    return False;
966 963
 		}
967 964
 
968
-		$sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber'));
965
+		$sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'='.$name.')(objectclass=posixaccount))', array('uidNumber'));
969 966
 
970 967
 		$allValues = ldap_get_entries($this->ds, $sri);
971 968
 
@@ -985,9 +982,9 @@  discard block
 block discarded – undo
985 982
 	 * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
986 983
 	 * @return string/false converted value or false on error ($account_id not found)
987 984
 	 */
988
-	function id2name($account_id,$which='account_lid')
985
+	function id2name($account_id, $which = 'account_lid')
989 986
 	{
990
-		return $this->frontend->id2name($account_id,$which);
987
+		return $this->frontend->id2name($account_id, $which);
991 988
 	}
992 989
 
993 990
 	/**
@@ -1000,7 +997,7 @@  discard block
 block discarded – undo
1000 997
 	function update_lastlogin($_account_id, $ip)
1001 998
 	{
1002 999
 		unset($_account_id, $ip);
1003
-		return false;	// not longer supported
1000
+		return false; // not longer supported
1004 1001
 	}
1005 1002
 
1006 1003
 	/**
@@ -1011,11 +1008,11 @@  discard block
 block discarded – undo
1011 1008
 	 */
1012 1009
 	function memberships($account_id)
1013 1010
 	{
1014
-		if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false;
1011
+		if (!(int)$account_id || !($account_lid = $this->id2name($account_id))) return false;
1015 1012
 
1016
-		$sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber'));
1013
+		$sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))', array('cn', 'gidnumber'));
1017 1014
 		$memberships = array();
1018
-		foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data)
1015
+		foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $data)
1019 1016
 		{
1020 1017
 			if ($key === 'count') continue;
1021 1018
 
@@ -1035,13 +1032,13 @@  discard block
 block discarded – undo
1035 1032
 		if (!is_numeric($_gid))
1036 1033
 		{
1037 1034
 			// try to recover
1038
-			$_gid = $this->name2id($_gid,'account_lid','g');
1035
+			$_gid = $this->name2id($_gid, 'account_lid', 'g');
1039 1036
 			if (!is_numeric($_gid)) return false;
1040 1037
 		}
1041 1038
 
1042
-		$gid = abs($_gid);	// our gid is negative!
1039
+		$gid = abs($_gid); // our gid is negative!
1043 1040
 
1044
-		$sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=$gid))",array('memberuid'));
1041
+		$sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=$gid))", array('memberuid'));
1045 1042
 		$group = ldap_get_entries($this->ds, $sri);
1046 1043
 
1047 1044
 		$members = array();
@@ -1049,7 +1046,7 @@  discard block
 block discarded – undo
1049 1046
 		{
1050 1047
 			unset($group[0]['memberuid']['count']);
1051 1048
 
1052
-			foreach($group[0]['memberuid'] as $lid)
1049
+			foreach ($group[0]['memberuid'] as $lid)
1053 1050
 			{
1054 1051
 				if (($id = $this->name2id($lid, 'account_lid', 'u')))
1055 1052
 				{
@@ -1066,27 +1063,27 @@  discard block
 block discarded – undo
1066 1063
 	 * @param array $groups array with gidnumbers
1067 1064
 	 * @param int $account_id uidnumber
1068 1065
 	 */
1069
-	function set_memberships($groups,$account_id)
1066
+	function set_memberships($groups, $account_id)
1070 1067
 	{
1071 1068
 		// remove not longer existing memberships
1072 1069
 		if (($old_memberships = $this->memberships($account_id)))
1073 1070
 		{
1074 1071
 			$old_memberships = array_keys($old_memberships);
1075
-			foreach(array_diff($old_memberships,$groups) as $gid)
1072
+			foreach (array_diff($old_memberships, $groups) as $gid)
1076 1073
 			{
1077 1074
 				if (($members = $this->members($gid)))
1078 1075
 				{
1079 1076
 					unset($members[$account_id]);
1080
-					$this->set_members($members,$gid);
1077
+					$this->set_members($members, $gid);
1081 1078
 				}
1082 1079
 			}
1083 1080
 		}
1084 1081
 		// adding new memberships
1085
-		foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid)
1082
+		foreach ($old_memberships ? array_diff($groups, $old_memberships) : $groups as $gid)
1086 1083
 		{
1087 1084
 			$members = $this->members($gid);
1088 1085
 			$members[$account_id] = $this->id2name($account_id);
1089
-			$this->set_members($members,$gid);
1086
+			$this->set_members($members, $gid);
1090 1087
 		}
1091 1088
 	}
1092 1089
 
@@ -1100,15 +1097,15 @@  discard block
 block discarded – undo
1100 1097
 	 * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it)
1101 1098
 	 * @return boolean/array false on failure, array or true otherwise
1102 1099
 	 */
1103
-	function set_members($members, $gid, array $objectclass=null, $use_cn=null)
1100
+	function set_members($members, $gid, array $objectclass = null, $use_cn = null)
1104 1101
 	{
1105 1102
 		if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false;
1106 1103
 
1107 1104
 		// do that group is a groupOf(Unique)Names or univentionGroup?
1108
-		if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass');
1105
+		if (is_null($objectclass)) $objectclass = $this->id2name($gid, 'objectclass');
1109 1106
 
1110 1107
 		$to_write = array('memberuid' => array());
1111
-		foreach((array)$members as $key => $member)
1108
+		foreach ((array)$members as $key => $member)
1112 1109
 		{
1113 1110
 			$member_dn = $this->id2name($member, 'account_dn');
1114 1111
 			if (is_numeric($member)) $member = $this->id2name($member);
@@ -1120,7 +1117,7 @@  discard block
 block discarded – undo
1120 1117
 				{
1121 1118
 					$to_write['member'][] = $member_dn;
1122 1119
 				}
1123
-				if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass))
1120
+				if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass))
1124 1121
 				{
1125 1122
 					$to_write['uniquemember'][] = $member_dn;
1126 1123
 				}
@@ -1131,31 +1128,31 @@  discard block
 block discarded – undo
1131 1128
 		{
1132 1129
 			$to_write['member'][] = 'uid=dummy'.','.$this->user_context;
1133 1130
 		}
1134
-		if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass) && !$to_write['uniquemember'])
1131
+		if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass) && !$to_write['uniquemember'])
1135 1132
 		{
1136 1133
 			$to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context;
1137 1134
 		}
1138 1135
 		if ($use_cn) return $to_write;
1139 1136
 
1140 1137
 		// set the member email addresses as forwards
1141
-		if ($this->id2name($gid,'account_email') &&	($objectclass = $this->id2name($gid,'mailAllowed')))
1138
+		if ($this->id2name($gid, 'account_email') && ($objectclass = $this->id2name($gid, 'mailAllowed')))
1142 1139
 		{
1143 1140
 			$forward = $this->group_mail_classes[$objectclass];
1144
-			if (is_array($forward)) list($forward,$extra_attr) = $forward;
1141
+			if (is_array($forward)) list($forward, $extra_attr) = $forward;
1145 1142
 			if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid;
1146 1143
 
1147 1144
 			if ($forward)
1148 1145
 			{
1149 1146
 				$to_write[$forward] = array();
1150
-				foreach($members as $key => $member)
1147
+				foreach ($members as $key => $member)
1151 1148
 				{
1152
-					if (($email = $this->id2name($member,'account_email')))	$to_write[$forward][] = $email;
1149
+					if (($email = $this->id2name($member, 'account_email')))	$to_write[$forward][] = $email;
1153 1150
 				}
1154 1151
 			}
1155 1152
 		}
1156
-		if (!ldap_modify($this->ds,'cn='.Api\Ldap::quote($cn).','.$this->group_context,$to_write))
1153
+		if (!ldap_modify($this->ds, 'cn='.Api\Ldap::quote($cn).','.$this->group_context, $to_write))
1157 1154
 		{
1158
-			echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write,true)."))\n";
1155
+			echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write, true)."))\n";
1159 1156
 			return false;
1160 1157
 		}
1161 1158
 		return true;
@@ -1168,7 +1165,7 @@  discard block
 block discarded – undo
1168 1165
 	 * @param string $account_type ='u' (optional, default to 'u')
1169 1166
 	 * @return int|boolean integer account_id (negative for groups) or false if none is free anymore
1170 1167
 	 */
1171
-	protected function _get_nextid($account_type='u')
1168
+	protected function _get_nextid($account_type = 'u')
1172 1169
 	{
1173 1170
 		$min = $this->frontend->config['account_min_id'] ? $this->frontend->config['account_min_id'] : 0;
1174 1171
 		$max = $this->frontend->config['account_max_id'] ? $this->frontend->config['account_max_id'] : 0;
@@ -1190,15 +1187,15 @@  discard block
 block discarded – undo
1190 1187
 		/* Loop until we find a free id */
1191 1188
 		do
1192 1189
 		{
1193
-			$account_id = (int) self::next_id($type,$min,$max);
1190
+			$account_id = (int)self::next_id($type, $min, $max);
1194 1191
 		}
1195
-		while ($account_id && ($this->frontend->exists($sign * $account_id) ||	// check need to include the sign!
1192
+		while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign!
1196 1193
 			$this->frontend->exists(-1 * $sign * $account_id) ||
1197 1194
 			// if sambaadmin is installed, call it to check there's not yet a relative id (last part of SID) with that number
1198 1195
 			// to ease migration to AD or Samba4
1199 1196
 			$GLOBALS['egw_info']['apps']['sambaadmin'] && ExecMethod2('sambaadmin.sosambaadmin.sidExists', $account_id)));
1200 1197
 
1201
-		if	(!$account_id || $max && $account_id > $max)
1198
+		if (!$account_id || $max && $account_id > $max)
1202 1199
 		{
1203 1200
 			return False;
1204 1201
 		}
@@ -1213,14 +1210,14 @@  discard block
 block discarded – undo
1213 1210
 	 * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false
1214 1211
 	 * @return int|boolean the next id or false if $max given and exceeded
1215 1212
 	 */
1216
-	static function next_id($location,$min=0,$max=0)
1213
+	static function next_id($location, $min = 0, $max = 0)
1217 1214
 	{
1218 1215
 		if (!$location)
1219 1216
 		{
1220 1217
 			return -1;
1221 1218
 		}
1222 1219
 
1223
-		$id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location];
1220
+		$id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location];
1224 1221
 
1225 1222
 		if ($max && $id >= $max)
1226 1223
 		{
@@ -1228,10 +1225,10 @@  discard block
 block discarded – undo
1228 1225
 		}
1229 1226
 		++$id;
1230 1227
 
1231
-		if($id < $min) $id = $min;
1228
+		if ($id < $min) $id = $min;
1232 1229
 
1233 1230
 		Api\Config::save_value($key, $id, 'phpgwapi', true);
1234
-		$GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id;
1231
+		$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location] = $id;
1235 1232
 
1236 1233
 		return (int)$id;
1237 1234
 	}
@@ -1244,18 +1241,18 @@  discard block
 block discarded – undo
1244 1241
 	 * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false
1245 1242
 	 * @return int|boolean current id in the next_id table for a particular app/class or -1 for no app and false if $max is exceeded.
1246 1243
 	 */
1247
-	static function last_id($location,$min=0,$max=0)
1244
+	static function last_id($location, $min = 0, $max = 0)
1248 1245
 	{
1249 1246
 		if (!$location)
1250 1247
 		{
1251 1248
 			return -1;
1252 1249
 		}
1253 1250
 
1254
-		$id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location];
1251
+		$id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location];
1255 1252
 
1256 1253
 		if (!$id || $id < $min)
1257 1254
 		{
1258
-			return self::next_id($location,$min,$max);
1255
+			return self::next_id($location, $min, $max);
1259 1256
 		}
1260 1257
 		if ($max && $id > $max)
1261 1258
 		{
@@ -1270,6 +1267,6 @@  discard block
 block discarded – undo
1270 1267
 	function __wakeup()
1271 1268
 	{
1272 1269
 		$this->ds = Api\Ldap::factory(true, $this->frontend->config['ldap_host'],
1273
-			$this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']);
1270
+			$this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']);
1274 1271
 	}
1275 1272
 }
Please login to merge, or discard this patch.
Braces   +168 added lines, -43 removed lines patch added patch discarded remove patch
@@ -175,7 +175,10 @@  discard block
 block discarded – undo
175 175
 	 */
176 176
 	function read($account_id)
177 177
 	{
178
-		if (!(int)$account_id) return false;
178
+		if (!(int)$account_id)
179
+		{
180
+			return false;
181
+		}
179 182
 
180 183
 		if ($account_id < 0)
181 184
 		{
@@ -238,17 +241,23 @@  discard block
 block discarded – undo
238 241
 					$this->delete($data['account_id']);
239 242
 					unset($old['dn']);
240 243
 					// removing the namedObject object-class, if it's included
241
-					if ($key !== false) unset($old['objectclass'][$key]);
244
+					if ($key !== false)
245
+					{
246
+						unset($old['objectclass'][$key]);
247
+					}
242 248
 					$to_write = $old;
243 249
 					unset($old);
244 250
 				}
245 251
 			}
246 252
 		}
247
-		if (!$data['account_id'])	// new account
253
+		if (!$data['account_id'])
254
+		{
255
+			// new account
248 256
 		{
249 257
 			if (!($data['account_id'] = $data_utf8['account_id'] = $this->_get_nextid($is_group ? 'g' : 'u')))
250 258
 			{
251 259
 				return false;
260
+		}
252 261
 			}
253 262
 		}
254 263
 		// check if we need to write the objectclass: new entry or required object classes are missing
@@ -259,11 +268,14 @@  discard block
 block discarded – undo
259 268
 			{
260 269
 				$to_write['objectclass'] = $old ? $old['objectclass'] : array();
261 270
 			}
262
-			if (!$old)	// for new accounts add additional addressbook object classes, if supported by server
271
+			if (!$old)
272
+			{
273
+				// for new accounts add additional addressbook object classes, if supported by server
263 274
 			{			// as setting them later might loose eg. password, if we are not allowed to read them
264 275
 				foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional)
265 276
 				{
266 277
 					$add = array();
278
+			}
267 279
 					if (is_array($additional))
268 280
 					{
269 281
 						$add = $additional;
@@ -272,7 +284,10 @@  discard block
 block discarded – undo
272 284
 					if ($this->ldapServerInfo->supportsObjectClass($additional))
273 285
 					{
274 286
 						$to_write['objectclass'][] = $additional;
275
-						if ($add) $to_write += $add;
287
+						if ($add)
288
+						{
289
+							$to_write += $add;
290
+						}
276 291
 					}
277 292
 				}
278 293
 			}
@@ -281,7 +296,10 @@  discard block
 block discarded – undo
281 296
 		}
282 297
 		if (!($dn = $old['dn']))
283 298
 		{
284
-			if (!$data['account_lid']) return false;
299
+			if (!$data['account_lid'])
300
+			{
301
+				return false;
302
+			}
285 303
 
286 304
 			$dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context :
287 305
 				'uid='.$data_utf8['account_lid'].','.$this->user_context;
@@ -302,24 +320,36 @@  discard block
 block discarded – undo
302 320
 			{
303 321
 				$extra_attr = false;
304 322
 				$keep_objectclass = false;
305
-				if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward;
323
+				if (is_array($forward))
324
+				{
325
+					list($forward,$extra_attr,$keep_objectclass) = $forward;
326
+				}
306 327
 
307 328
 				if ($this->ldapServerInfo->supportsObjectClass($objectclass) &&
308 329
 					($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR]))
309 330
 				{
310
-					if ($data_utf8['account_email'])	// setting an email
331
+					if ($data_utf8['account_email'])
332
+					{
333
+						// setting an email
311 334
 					{
312 335
 						if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass']))
313 336
 						{
314 337
 							if ($old) $to_write['objectclass'] = $old['objectclass'];
338
+					}
315 339
 							$to_write['objectclass'][] = $objectclass;
316 340
 						}
317
-						if ($extra_attr) $to_write[$extra_attr] = $data_utf8['account_lid'];
341
+						if ($extra_attr)
342
+						{
343
+							$to_write[$extra_attr] = $data_utf8['account_lid'];
344
+						}
318 345
 						$to_write[static::MAIL_ATTR] = $data_utf8['account_email'];
319 346
 
320 347
 						if ($forward)
321 348
 						{
322
-							if (!$members) $members = $this->members($data['account_id']);
349
+							if (!$members)
350
+							{
351
+								$members = $this->members($data['account_id']);
352
+							}
323 353
 							$to_write[$forward] = array();
324 354
 							foreach (array_keys($members) as $member)
325 355
 							{
@@ -330,11 +360,20 @@  discard block
 block discarded – undo
330 360
 							}
331 361
 						}
332 362
 					}
333
-					elseif($old)	// remove the mail and forwards only for existing entries
363
+					elseif($old)
364
+					{
365
+						// remove the mail and forwards only for existing entries
334 366
 					{
335 367
 						$to_write[static::MAIL_ATTR] = array();
336
-						if ($forward) $to_write[$forward] = array();
337
-						if ($extra_attr) $to_write[$extra_attr] = array();
368
+					}
369
+						if ($forward)
370
+						{
371
+							$to_write[$forward] = array();
372
+						}
373
+						if ($extra_attr)
374
+						{
375
+							$to_write[$extra_attr] = array();
376
+						}
338 377
 						if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass'])))
339 378
 						{
340 379
 							$to_write['objectclass'] = $old['objectclass'];
@@ -368,7 +407,8 @@  discard block
 block discarded – undo
368 407
 		}
369 408
 
370 409
 		// remove memberuid when adding a group
371
-		if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) {
410
+		if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid']))
411
+		{
372 412
 			unset($to_write['memberuid']);
373 413
 		}
374 414
 		// modifying or adding the entry
@@ -405,7 +445,10 @@  discard block
 block discarded – undo
405 445
 	 */
406 446
 	function delete($account_id)
407 447
 	{
408
-		if (!(int)$account_id) return false;
448
+		if (!(int)$account_id)
449
+		{
450
+			return false;
451
+		}
409 452
 
410 453
 		if ($account_id < 0)
411 454
 		{
@@ -418,10 +461,16 @@  discard block
 block discarded – undo
418 461
 
419 462
 			$sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id);
420 463
 		}
421
-		if (!$sri) return false;
464
+		if (!$sri)
465
+		{
466
+			return false;
467
+		}
422 468
 
423 469
 		$allValues = ldap_get_entries($this->ds, $sri);
424
-		if (!$allValues['count']) return false;
470
+		if (!$allValues['count'])
471
+		{
472
+			return false;
473
+		}
425 474
 
426 475
 		return ldap_delete($this->ds, $allValues[0]['dn']);
427 476
 	}
@@ -593,14 +642,20 @@  discard block
 block discarded – undo
593 642
 		$utc_diff = date('Z');
594 643
 		if (isset($data['account_passwd']) && $data['account_passwd'])
595 644
 		{
596
-			if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd']))	// md5 --> ldap md5
645
+			if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd']))
646
+			{
647
+				// md5 --> ldap md5
597 648
 			{
598 649
 				$data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']);
599 650
 			}
600
-			elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd']))	// if it's not already entcrypted, do so now
651
+			}
652
+			elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd']))
653
+			{
654
+				// if it's not already entcrypted, do so now
601 655
 			{
602 656
 				$data['account_passwd'] = Api\Auth::encrypt_ldap($data['account_passwd']);
603 657
 			}
658
+			}
604 659
 			$to_write['userpassword'] = $data['account_passwd'];
605 660
 			$to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600));
606 661
 		}
@@ -620,16 +675,28 @@  discard block
 block discarded – undo
620 675
 			unset($to_write['shadowexpire']);	// gives protocoll error otherwise
621 676
 		}
622 677
 		//error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#');
623
-		if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600));
624
-		if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0;
678
+		if ($data['account_lastpwd_change'])
679
+		{
680
+			$to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600));
681
+		}
682
+		if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0)
683
+		{
684
+			$to_write['shadowlastchange'] = 0;
685
+		}
625 686
 		// lastlogin and lastlogin from are not availible via the shadowAccount object class
626 687
 		// $to_write['phpgwaccountlastlogin'] = $data['lastlogin'];
627 688
 		// $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom'];
628 689
 
629 690
 		if ($this->frontend->config['ldap_extra_attributes'])
630 691
 		{
631
-			if (isset($data['homedirectory'])) $to_write['homedirectory']  = $data['homedirectory'];
632
-			if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array();
692
+			if (isset($data['homedirectory']))
693
+			{
694
+				$to_write['homedirectory']  = $data['homedirectory'];
695
+			}
696
+			if (isset($data['loginshell']))
697
+			{
698
+				$to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array();
699
+			}
633 700
 		}
634 701
 		if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory']))
635 702
 		{
@@ -676,8 +743,14 @@  discard block
 block discarded – undo
676 743
 		}
677 744
 		// if it's a limited query, check if the unlimited query is cached
678 745
 		$start = $param['start'];
679
-		if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15;
680
-		if (!($offset = $param['offset'])) $offset = $maxmatchs;
746
+		if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']))
747
+		{
748
+			$maxmatchs = 15;
749
+		}
750
+		if (!($offset = $param['offset']))
751
+		{
752
+			$offset = $maxmatchs;
753
+		}
681 754
 		unset($param['start']);
682 755
 		unset($param['offset']);
683 756
 		$unl_serial = serialize($param);
@@ -748,12 +821,18 @@  discard block
 block discarded – undo
748 821
 					$fullSet = array();
749 822
 					foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry)
750 823
 					{
751
-						if ($key !== 'count') $fullSet[$entry['uid'][0]] = $entry[$order][0];
824
+						if ($key !== 'count')
825
+						{
826
+							$fullSet[$entry['uid'][0]] = $entry[$order][0];
827
+						}
752 828
 					}
753 829
 
754
-					if (is_numeric($param['type'])) // return only group-members
830
+					if (is_numeric($param['type']))
831
+					{
832
+						// return only group-members
755 833
 					{
756 834
 						$relevantAccounts = array();
835
+					}
757 836
 						$sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid'));
758 837
 						$group = ldap_get_entries($this->ds, $sri);
759 838
 						$fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array();
@@ -791,7 +870,10 @@  discard block
 block discarded – undo
791 870
 						//error_log(__METHOD__."() ldap=".array2string($allVals)." --> account=".array2string($account));
792 871
 						if ($param['active'] && !$this->frontend->is_active($account))
793 872
 						{
794
-							if (isset($totalcount)) --$totalcount;
873
+							if (isset($totalcount))
874
+							{
875
+								--$totalcount;
876
+							}
795 877
 							continue;
796 878
 						}
797 879
 						$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'],
@@ -844,7 +926,10 @@  discard block
 block discarded – undo
844 926
 							'account_status'    => 'A',
845 927
 							'account_fullname'  => Api\Translation::convert($allVals['cn'][0],'utf-8'),
846 928
 						);
847
-						if (isset($totalcount)) ++$totalcount;
929
+						if (isset($totalcount))
930
+						{
931
+							++$totalcount;
932
+						}
848 933
 					}
849 934
 				}
850 935
 			}
@@ -945,10 +1030,13 @@  discard block
 block discarded – undo
945 1030
 	{
946 1031
 		$name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8'));
947 1032
 
948
-		if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid
1033
+		if ($which == 'account_lid' && $account_type !== 'u')
1034
+		{
1035
+			// groups only support account_lid
949 1036
 		{
950 1037
 
951 1038
 			$sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber'));
1039
+		}
952 1040
 			$allValues = ldap_get_entries($this->ds, $sri);
953 1041
 
954 1042
 			if (@$allValues[0]['gidnumber'][0])
@@ -961,7 +1049,8 @@  discard block
 block discarded – undo
961 1049
 			'account_email' => static::MAIL_ATTR,
962 1050
 			'account_fullname' => 'cn',
963 1051
 		);
964
-		if (!isset($to_ldap[$which]) || $account_type === 'g') {
1052
+		if (!isset($to_ldap[$which]) || $account_type === 'g')
1053
+		{
965 1054
 		    return False;
966 1055
 		}
967 1056
 
@@ -1011,13 +1100,19 @@  discard block
 block discarded – undo
1011 1100
 	 */
1012 1101
 	function memberships($account_id)
1013 1102
 	{
1014
-		if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false;
1103
+		if (!(int) $account_id || !($account_lid = $this->id2name($account_id)))
1104
+		{
1105
+			return false;
1106
+		}
1015 1107
 
1016 1108
 		$sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber'));
1017 1109
 		$memberships = array();
1018 1110
 		foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data)
1019 1111
 		{
1020
-			if ($key === 'count') continue;
1112
+			if ($key === 'count')
1113
+			{
1114
+				continue;
1115
+			}
1021 1116
 
1022 1117
 			$memberships[(string) -$data['gidnumber'][0]] = $data['cn'][0];
1023 1118
 		}
@@ -1036,7 +1131,10 @@  discard block
 block discarded – undo
1036 1131
 		{
1037 1132
 			// try to recover
1038 1133
 			$_gid = $this->name2id($_gid,'account_lid','g');
1039
-			if (!is_numeric($_gid)) return false;
1134
+			if (!is_numeric($_gid))
1135
+			{
1136
+				return false;
1137
+			}
1040 1138
 		}
1041 1139
 
1042 1140
 		$gid = abs($_gid);	// our gid is negative!
@@ -1102,16 +1200,25 @@  discard block
 block discarded – undo
1102 1200
 	 */
1103 1201
 	function set_members($members, $gid, array $objectclass=null, $use_cn=null)
1104 1202
 	{
1105
-		if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false;
1203
+		if (!($cn = $use_cn) && !($cn = $this->id2name($gid)))
1204
+		{
1205
+			return false;
1206
+		}
1106 1207
 
1107 1208
 		// do that group is a groupOf(Unique)Names or univentionGroup?
1108
-		if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass');
1209
+		if (is_null($objectclass))
1210
+		{
1211
+			$objectclass = $this->id2name($gid,'objectclass');
1212
+		}
1109 1213
 
1110 1214
 		$to_write = array('memberuid' => array());
1111 1215
 		foreach((array)$members as $key => $member)
1112 1216
 		{
1113 1217
 			$member_dn = $this->id2name($member, 'account_dn');
1114
-			if (is_numeric($member)) $member = $this->id2name($member);
1218
+			if (is_numeric($member))
1219
+			{
1220
+				$member = $this->id2name($member);
1221
+			}
1115 1222
 
1116 1223
 			if ($member)
1117 1224
 			{
@@ -1135,21 +1242,33 @@  discard block
 block discarded – undo
1135 1242
 		{
1136 1243
 			$to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context;
1137 1244
 		}
1138
-		if ($use_cn) return $to_write;
1245
+		if ($use_cn)
1246
+		{
1247
+			return $to_write;
1248
+		}
1139 1249
 
1140 1250
 		// set the member email addresses as forwards
1141 1251
 		if ($this->id2name($gid,'account_email') &&	($objectclass = $this->id2name($gid,'mailAllowed')))
1142 1252
 		{
1143 1253
 			$forward = $this->group_mail_classes[$objectclass];
1144
-			if (is_array($forward)) list($forward,$extra_attr) = $forward;
1145
-			if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid;
1254
+			if (is_array($forward))
1255
+			{
1256
+				list($forward,$extra_attr) = $forward;
1257
+			}
1258
+			if ($extra_attr && ($uid = $this->id2name($gid)))
1259
+			{
1260
+				$to_write[$extra_attr] = $uid;
1261
+			}
1146 1262
 
1147 1263
 			if ($forward)
1148 1264
 			{
1149 1265
 				$to_write[$forward] = array();
1150 1266
 				foreach($members as $key => $member)
1151 1267
 				{
1152
-					if (($email = $this->id2name($member,'account_email')))	$to_write[$forward][] = $email;
1268
+					if (($email = $this->id2name($member,'account_email')))
1269
+					{
1270
+						$to_write[$forward][] = $email;
1271
+					}
1153 1272
 				}
1154 1273
 			}
1155 1274
 		}
@@ -1175,7 +1294,10 @@  discard block
 block discarded – undo
1175 1294
 
1176 1295
 		// prefer ids above 1000 (below reserved for system users under AD or Linux),
1177 1296
 		// if that's possible within what is configured, or nothing is configured
1178
-		if ($min < 1000 && (!$max || $max > 1000)) $min = 1000;
1297
+		if ($min < 1000 && (!$max || $max > 1000))
1298
+		{
1299
+			$min = 1000;
1300
+		}
1179 1301
 
1180 1302
 		if ($account_type == 'g')
1181 1303
 		{
@@ -1228,7 +1350,10 @@  discard block
 block discarded – undo
1228 1350
 		}
1229 1351
 		++$id;
1230 1352
 
1231
-		if($id < $min) $id = $min;
1353
+		if($id < $min)
1354
+		{
1355
+			$id = $min;
1356
+		}
1232 1357
 
1233 1358
 		Api\Config::save_value($key, $id, 'phpgwapi', true);
1234 1359
 		$GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id;
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 					$test = @$allVals['uid'][0];
776 776
 					if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0])
777 777
 					{
778
-						$account = Array(
778
+						$account = array(
779 779
 							'account_id'        => $allVals['uidnumber'][0],
780 780
 							'account_lid'       => Api\Translation::convert($allVals['uid'][0],'utf-8'),
781 781
 							'account_type'      => 'u',
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
 					$test = $allVals['cn'][0];
836 836
 					if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0])
837 837
 					{
838
-						$accounts[(string)-$allVals['gidnumber'][0]] = Array(
838
+						$accounts[(string)-$allVals['gidnumber'][0]] = array(
839 839
 							'account_id'        => -$allVals['gidnumber'][0],
840 840
 							'account_lid'       => Api\Translation::convert($allVals['cn'][0],'utf-8'),
841 841
 							'account_type'      => 'g',
Please login to merge, or discard this patch.
api/src/Accounts/Univention.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
 	 * If no account_id is set in data the account is added and the new id is set in $data.
48 48
 	 *
49 49
 	 * @param array $data array with account-data
50
-	 * @return int|boolean the account_id or false on error
50
+	 * @return false|string the account_id or false on error
51 51
 	 */
52 52
 	function save(&$data)
53 53
 	{
Please login to merge, or discard this patch.
Spacing   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 			if (!$data['account_id'] && $data['account_type'] !== 'g')
63 63
 			{
64 64
 				$params = array(
65
-					'users/user','create',
65
+					'users/user', 'create',
66 66
 					'--binddn', $config['ldap_root_dn'],
67 67
 					'--bindpwd', 5=>$config['ldap_root_pw'],
68 68
 					'--position', $config['ldap_context'],
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 						}
88 88
 						$hostname = $account->acc_imap_host;
89 89
 					}
90
-					catch(Exception $e) {
90
+					catch (Exception $e) {
91 91
 						unset($e);
92 92
 					}
93 93
 					if (empty($hostname)) $hostname = trim(system('hostname -f'));
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
 				$output = implode("\n", $output_arr);
100 100
 				if ($ret || !preg_match('/^Object created: (uid=.*)$/mui', $output, $matches))
101 101
 				{
102
-					$params[5] = '********';	// mask out password!
102
+					$params[5] = '********'; // mask out password!
103 103
 					$cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params));
104 104
 					throw new Api\Exception\WrongUserinput($cmd."\nreturned\n".$output);
105 105
 				}
106 106
 				$data['account_dn'] = $matches[1];
107 107
 				$data['account_id'] = $this->name2id($data['account_lid'], 'account_lid', 'u');
108 108
 			}
109
-			elseif($data['account_id'] && ($data['old_loginid'] || ($data['old_loginid'] = $this->id2name($data['account_id']))) &&
109
+			elseif ($data['account_id'] && ($data['old_loginid'] || ($data['old_loginid'] = $this->id2name($data['account_id']))) &&
110 110
 				$data['account_lid'] != $data['old_loginid'] &&
111 111
 				($data['account_dn'] = $this->id2name($data['account_id'], 'account_dn')))
112 112
 			{
@@ -123,12 +123,11 @@  discard block
 block discarded – undo
123 123
 				$output = implode("\n", $output_arr);
124 124
 				if ($ret || !preg_match('/^Object modified: ((uid|cn)=.*)$/mui', $output, $matches))
125 125
 				{
126
-					$params[5] = '********';	// mask out password!
126
+					$params[5] = '********'; // mask out password!
127 127
 					$cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params));
128 128
 					throw new Api\Exception\WrongUserinput($cmd."\nreturned\n".$output);
129 129
 				}
130
-				$data['account_dn'] = $data['account_type'] !== 'g' ? $matches[1] :
131
-					// duno why but directory-manager returns old dn for groups ...
130
+				$data['account_dn'] = $data['account_type'] !== 'g' ? $matches[1] : // duno why but directory-manager returns old dn for groups ...
132 131
 					preg_replace('/^cn=[^,]+,/', 'cn='.$data['account_lid'].',', $data['account_dn']);
133 132
 			}
134 133
 		}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -90,7 +90,10 @@
 block discarded – undo
90 90
 					catch(Exception $e) {
91 91
 						unset($e);
92 92
 					}
93
-					if (empty($hostname)) $hostname = trim(system('hostname -f'));
93
+					if (empty($hostname))
94
+					{
95
+						$hostname = trim(system('hostname -f'));
96
+					}
94 97
 					$params[] = '--set'; $params[] = 'mailHomeServer='.$hostname;
95 98
 				}
96 99
 				$cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params));
Please login to merge, or discard this patch.
api/src/Acl.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 * Delete ACL record in the repository of the class
167 167
 	 *
168 168
 	 * @param string $appname appname or '' for $GLOBALS['egw_info']['flags']['currentapp']
169
-	 * @param string/boolean $location location or false for all locations
169
+	 * @param boolean $location location or false for all locations
170 170
 	 * @return array all ACL records from $this->data.
171 171
 	 */
172 172
 	function delete($appname,$location)
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 	/**
268 268
 	 * check required rights agains the internal repository (included rights of $this->account_id and all it's memberships)
269 269
 	 *
270
-	 * @param $location app location
271
-	 * @param $required required right to check against
270
+	 * @param string $location app location
271
+	 * @param integer $required required right to check against
272 272
 	 * @param $appname optional defaults to currentapp
273 273
 	 * @return boolean
274 274
 	 */
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
 	/**
52 52
 	 * Constants for acl rights, like old EGW_ACL_* defines
53 53
 	 */
54
-	const READ      = 1;	// EGW_ACL_READ
55
-	const ADD       = 2;	// EGW_ACL_ADD
56
-	const EDIT      = 4;	// EGW_ACL_EDIT
57
-	const DELETE    = 8;	// EGW_ACL_DELETE
58
-	const PRIVAT    = 16;	// EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead!
59
-	const GROUPMGRS = 32;	// EGW_ACL_GROUP_MANAGERS
60
-	const CUSTOM1  = 64;		// EGW_ACL_CUSTOM_1
61
-	const CUSTOM2  = 128;	// EGW_ACL_CUSTOM_2
62
-	const CUSTOM3  = 256;	// EGW_ACL_CUSTOM_3
54
+	const READ      = 1; // EGW_ACL_READ
55
+	const ADD       = 2; // EGW_ACL_ADD
56
+	const EDIT      = 4; // EGW_ACL_EDIT
57
+	const DELETE    = 8; // EGW_ACL_DELETE
58
+	const PRIVAT    = 16; // EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead!
59
+	const GROUPMGRS = 32; // EGW_ACL_GROUP_MANAGERS
60
+	const CUSTOM1  = 64; // EGW_ACL_CUSTOM_1
61
+	const CUSTOM2  = 128; // EGW_ACL_CUSTOM_2
62
+	const CUSTOM3  = 256; // EGW_ACL_CUSTOM_3
63 63
 
64 64
 	/**
65 65
 	 * ACL constructor for setting account id
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		}
83 83
 		if ((int)$this->account_id != (int)$account_id)
84 84
 		{
85
-			$this->account_id = get_account_id((int)$account_id,@$GLOBALS['egw_info']['user']['account_id']);
85
+			$this->account_id = get_account_id((int)$account_id, @$GLOBALS['egw_info']['user']['account_id']);
86 86
 		}
87 87
 	}
88 88
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @param boolean|array $no_groups = false if true, do not use memberships, if array do not use given groups
97 97
 	 * @return array along with storing it in $acl->data.  <br>
98 98
 	 */
99
-	function read_repository($no_groups=false)
99
+	function read_repository($no_groups = false)
100 100
 	{
101 101
 		// For some reason, calling this via XML-RPC doesn't call the constructor.
102 102
 		// Here is yet another work around(tm) (jengo)
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
 		else
112 112
 		{
113 113
 			$acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true);
114
-			if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups);
115
-			array_unshift($acl_acc_list,$this->account_id);
114
+			if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list, $no_groups);
115
+			array_unshift($acl_acc_list, $this->account_id);
116 116
 		}
117 117
 
118 118
 		$this->data = Array();
119
-		foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row)
119
+		foreach ($this->db->select(self::TABLE, '*', array('acl_account' => $acl_acc_list), __LINE__, __FILE__) as $row)
120 120
 		{
121
-			$this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_');
121
+			$this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row, 'acl_');
122 122
 		}
123 123
 		return $this->data;
124 124
 	}
@@ -147,15 +147,15 @@  discard block
 block discarded – undo
147 147
 	 * @param int $rights rights
148 148
 	 * @return array all ACL records from $this->data.
149 149
 	 */
150
-	function add($appname,$location,$rights)
150
+	function add($appname, $location, $rights)
151 151
 	{
152 152
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
153 153
 
154 154
 		$row = array(
155 155
 			'appname'  => $appname,
156 156
 			'location' => $location,
157
-			'account'  => (int) $this->account_id,
158
-			'rights'   => (int) $rights
157
+			'account'  => (int)$this->account_id,
158
+			'rights'   => (int)$rights
159 159
 		);
160 160
 		$this->data[$row['appname'].'-'.$row['location'].'-'.$row['account']] = $row;
161 161
 
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 	 * @param string/boolean $location location or false for all locations
170 170
 	 * @return array all ACL records from $this->data.
171 171
 	 */
172
-	function delete($appname,$location)
172
+	function delete($appname, $location)
173 173
 	{
174 174
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
175 175
 
176
-		foreach($this->data as $idx => $value)
176
+		foreach ($this->data as $idx => $value)
177 177
 		{
178 178
 			if ($value['appname'] == $appname &&
179 179
 				($location === false || $value['location'] == $location) &&
@@ -192,24 +192,24 @@  discard block
 block discarded – undo
192 192
 	 */
193 193
 	function save_repository()
194 194
 	{
195
-		$this->db->delete(self::TABLE,array(
195
+		$this->db->delete(self::TABLE, array(
196 196
 			'acl_account' => $this->account_id,
197
-		),__LINE__,__FILE__);
197
+		), __LINE__, __FILE__);
198 198
 
199
-		foreach($this->data as $value)
199
+		foreach ($this->data as $value)
200 200
 		{
201 201
 			if ($value['account'] == $this->account_id)
202 202
 			{
203
-				$this->db->insert(self::TABLE,array(
203
+				$this->db->insert(self::TABLE, array(
204 204
 					'acl_appname'  => $value['appname'],
205 205
 					'acl_location' => $value['location'],
206 206
 					'acl_account'  => $this->account_id,
207 207
 					'acl_rights'   => $value['rights'],
208
-				),false,__LINE__,__FILE__);
208
+				), false, __LINE__, __FILE__);
209 209
 			}
210 210
 		}
211 211
 		if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] &&
212
-			method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
212
+			method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
213 213
 		{
214 214
 			$GLOBALS['egw']->invalidate_session_cache();
215 215
 		}
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 * @param string $appname optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
228 228
 	 * @return int all rights or'ed together
229 229
 	 */
230
-	function get_rights($location,$appname = '')
230
+	function get_rights($location, $appname = '')
231 231
 	{
232 232
 		// For XML-RPC, change this once its working correctly for passing parameters (jengo)
233 233
 		if (is_array($location))
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 			return True;
248 248
 		}
249 249
 		$rights = 0;
250
-		foreach($this->data as $value)
250
+		foreach ($this->data as $value)
251 251
 		{
252 252
 			if ($value['appname'] == $appname)
253 253
 			{
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
 	 */
275 275
 	function check($location, $required, $appname = False)
276 276
 	{
277
-		$rights = $this->get_rights($location,$appname);
277
+		$rights = $this->get_rights($location, $appname);
278 278
 
279
-		return !!($rights & $required);
279
+		return !!($rights&$required);
280 280
 	}
281 281
 
282 282
 	/**
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	 * @param array $memberships = array() additional account_id, eg. memberships to match beside $this->account_id, default none
288 288
 	 * @return int $rights
289 289
 	 */
290
-	function get_specific_rights($location, $appname = '', $memberships=array())
290
+	function get_specific_rights($location, $appname = '', $memberships = array())
291 291
 	{
292 292
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
293 293
 
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
 		}
298 298
 		$rights = 0;
299 299
 
300
-		foreach($this->data as $value)
300
+		foreach ($this->data as $value)
301 301
 		{
302 302
 			if ($value['appname'] == $appname &&
303
-				($value['location'] == $location ||	$value['location'] == 'everywhere') &&
303
+				($value['location'] == $location || $value['location'] == 'everywhere') &&
304 304
 				($value['account'] == $this->account_id || $memberships && in_array($value['account'], $memberships)))
305 305
 			{
306 306
 				if ($value['rights'] == 0)
@@ -323,9 +323,9 @@  discard block
 block discarded – undo
323 323
 	 */
324 324
 	function check_specific($location, $required, $appname = '')
325 325
 	{
326
-		$rights = $this->get_specific_rights($location,$appname);
326
+		$rights = $this->get_specific_rights($location, $appname);
327 327
 
328
-		return !!($rights & $required);
328
+		return !!($rights&$required);
329 329
 	}
330 330
 
331 331
 	/**************************************************************************\
@@ -344,16 +344,16 @@  discard block
 block discarded – undo
344 344
 	function add_repository($app, $location, $account_id, $rights)
345 345
 	{
346 346
 		//echo "<p>self::add_repository('$app','$location',$account_id,$rights);</p>\n";
347
-		$this->db->insert(self::TABLE,array(
347
+		$this->db->insert(self::TABLE, array(
348 348
 			'acl_rights' => $rights,
349
-		),array(
349
+		), array(
350 350
 			'acl_appname' => $app,
351 351
 			'acl_location' => $location,
352 352
 			'acl_account'  => $account_id,
353
-		),__LINE__,__FILE__);
353
+		), __LINE__, __FILE__);
354 354
 
355 355
 		if ($account_id == $GLOBALS['egw_info']['user']['account_id'] &&
356
-			method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
356
+			method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
357 357
 		{
358 358
 			$GLOBALS['egw']->invalidate_session_cache();
359 359
 		}
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @param int/boolean $accountid = '' account id, default 0=$this->account_id, or false to delete all entries for $app/$location
369 369
 	 * @return int number of rows deleted
370 370
 	 */
371
-	function delete_repository($app, $location, $accountid='')
371
+	function delete_repository($app, $location, $accountid = '')
372 372
 	{
373 373
 		static $cache_accountid = array();
374 374
 
@@ -378,22 +378,22 @@  discard block
 block discarded – undo
378 378
 		);
379 379
 		if ($accountid !== false)
380 380
 		{
381
-			if(isset($cache_accountid[$accountid]) && $cache_accountid[$accountid])
381
+			if (isset($cache_accountid[$accountid]) && $cache_accountid[$accountid])
382 382
 			{
383 383
 				$where['acl_account'] = $cache_accountid[$accountid];
384 384
 			}
385 385
 			else
386 386
 			{
387
-				$where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id);
387
+				$where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id);
388 388
 			}
389 389
 		}
390
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
390
+		if (method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
391 391
 		{
392 392
 			$GLOBALS['egw']->invalidate_session_cache();
393 393
 		}
394 394
 		if ($app == '%' || $app == '%%') unset($where['acl_appname']);
395 395
 
396
-		$this->db->delete(self::TABLE,$where,__LINE__,__FILE__);
396
+		$this->db->delete(self::TABLE, $where, __LINE__, __FILE__);
397 397
 
398 398
 		return $this->db->affected_rows();
399 399
 	}
@@ -406,15 +406,15 @@  discard block
 block discarded – undo
406 406
 	 * @param string $appname = '' defaults to current app
407 407
 	 * @return int/boolean rights or false if none exist
408 408
 	 */
409
-	function get_specific_rights_for_account($account_id,$location,$appname='')
409
+	function get_specific_rights_for_account($account_id, $location, $appname = '')
410 410
 	{
411 411
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
412 412
 
413
-		return $this->db->select(self::TABLE,'acl_rights',array(
413
+		return $this->db->select(self::TABLE, 'acl_rights', array(
414 414
 			'acl_location' => $location,
415 415
 			'acl_account'  => $account_id,
416 416
 			'acl_appname'  => $appname,
417
-		),__LINE__,__FILE__)->fetchColumn();
417
+		), __LINE__, __FILE__)->fetchColumn();
418 418
 	}
419 419
 
420 420
 	/**
@@ -424,15 +424,15 @@  discard block
 block discarded – undo
424 424
 	 * @param string $appname = '' defaults to current app
425 425
 	 * @return array with account => rights pairs
426 426
 	 */
427
-	function get_all_rights($location,$appname='')
427
+	function get_all_rights($location, $appname = '')
428 428
 	{
429 429
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
430 430
 
431 431
 		$rights = array();
432
-		foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array(
432
+		foreach ($this->db->select(self::TABLE, 'acl_account,acl_rights', array(
433 433
 			'acl_location' => $location,
434 434
 			'acl_appname'  => $appname,
435
-		),__LINE__,__FILE__) as $row)
435
+		), __LINE__, __FILE__) as $row)
436 436
 		{
437 437
 			$rights[$row['acl_account']] = $row['acl_rights'];
438 438
 		}
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 	 * @param boolean $use_memberships = true
448 448
 	 * @return array with location => rights pairs
449 449
 	 */
450
-	function get_all_location_rights($account_id,$appname='',$use_memberships=true)
450
+	function get_all_location_rights($account_id, $appname = '', $use_memberships = true)
451 451
 	{
452 452
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
453 453
 
@@ -458,10 +458,10 @@  discard block
 block discarded – undo
458 458
 			$accounts[] = $account_id;
459 459
 		}
460 460
 		$rights = array();
461
-		foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array(
461
+		foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array(
462 462
 			'acl_account' => $accounts,
463 463
 			'acl_appname' => $appname,
464
-		),__LINE__,__FILE__) as $row)
464
+		), __LINE__, __FILE__) as $row)
465 465
 		{
466 466
 			$rights[$row['acl_location']] |= $row['acl_rights'];
467 467
 		}
@@ -480,28 +480,28 @@  discard block
 block discarded – undo
480 480
 	{
481 481
 		static $cache_accountid = array();
482 482
 
483
-		if(isset($cache_accountid[$accountid]))
483
+		if (isset($cache_accountid[$accountid]))
484 484
 		{
485 485
 			$account_id = $cache_accountid[$accountid];
486 486
 		}
487 487
 		else
488 488
 		{
489
-			$account_id = get_account_id($accountid,$this->account_id);
489
+			$account_id = get_account_id($accountid, $this->account_id);
490 490
 			$cache_accountid[$accountid] = $account_id;
491 491
 		}
492 492
 		$rights = 0;
493 493
 		$apps = false;
494
-		foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array(
494
+		foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array(
495 495
 			'acl_location' => $location,
496 496
 			'acl_account'  => $account_id,
497
-		),__LINE__,__FILE__) as $row)
497
+		), __LINE__, __FILE__) as $row)
498 498
 		{
499 499
 			if ($row['acl_rights'] == 0)
500 500
 			{
501 501
 				return False;
502 502
 			}
503 503
 			$rights |= $row['acl_rights'];
504
-			if (!!($rights & $required))
504
+			if (!!($rights&$required))
505 505
 			{
506 506
 				$apps[] = $row['acl_appname'];
507 507
 			}
@@ -521,21 +521,21 @@  discard block
 block discarded – undo
521 521
 	{
522 522
 		static $cache_accountid = array();
523 523
 
524
-		if(isset($cache_accountid[$accountid]))
524
+		if (isset($cache_accountid[$accountid]))
525 525
 		{
526 526
 			$accountid = $cache_accountid[$accountid];
527 527
 		}
528 528
 		else
529 529
 		{
530
-			$accountid = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id);
530
+			$accountid = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id);
531 531
 		}
532 532
 		$locations = false;
533
-		foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array(
533
+		foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array(
534 534
 			'acl_appname' => $app,
535 535
 			'acl_account' => $accountid,
536
-		),__LINE__,__FILE__) as $row)
536
+		), __LINE__, __FILE__) as $row)
537 537
 		{
538
-			if ($row['acl_rights'] & $required)
538
+			if ($row['acl_rights']&$required)
539 539
 			{
540 540
 				$locations[] = $row['acl_location'];
541 541
 			}
@@ -556,14 +556,14 @@  discard block
 block discarded – undo
556 556
 		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
557 557
 
558 558
 		$accounts = false;
559
-		foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array(
559
+		foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights'), array(
560 560
 			'acl_appname'  => $app,
561 561
 			'acl_location' => $location,
562
-		),__LINE__,__FILE__) as $row)
562
+		), __LINE__, __FILE__) as $row)
563 563
 		{
564
-			if (!!($row['acl_rights'] & $required))
564
+			if (!!($row['acl_rights']&$required))
565 565
 			{
566
-				$accounts[] = (int) $row['acl_account'];
566
+				$accounts[] = (int)$row['acl_account'];
567 567
 			}
568 568
 		}
569 569
 		return $accounts;
@@ -575,14 +575,14 @@  discard block
 block discarded – undo
575 575
 	 * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
576 576
 	 * @return boolean/array false if there are no matching location in the db or array of locations
577 577
 	 */
578
-	function get_locations_for_app($app='')
578
+	function get_locations_for_app($app = '')
579 579
 	{
580 580
 		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
581 581
 
582 582
 		$locations = false;
583
-		foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array(
583
+		foreach ($this->db->select(self::TABLE, 'DISTINCT '.'acl_location', array(
584 584
 			'acl_appname'  => $app,
585
-		),__LINE__,__FILE__) as $row)
585
+		), __LINE__, __FILE__) as $row)
586 586
 		{
587 587
 			if (($location = $row['acl_location']) != 'run')
588 588
 			{
@@ -600,38 +600,38 @@  discard block
 block discarded – undo
600 600
 	 * @param boolean $add_implicit_apps = true true: add apps every user has implicit rights
601 601
 	 * @return array containing list of apps
602 602
 	 */
603
-	function get_user_applications($accountid = '', $use_memberships=true, $add_implicit_apps=true)
603
+	function get_user_applications($accountid = '', $use_memberships = true, $add_implicit_apps = true)
604 604
 	{
605 605
 		static $cache_accountid = array();
606 606
 
607
-		if(isset($cache_accountid[$accountid]))
607
+		if (isset($cache_accountid[$accountid]))
608 608
 		{
609 609
 			$account_id = $cache_accountid[$accountid];
610 610
 		}
611 611
 		else
612 612
 		{
613
-			$account_id = get_account_id($accountid,$this->account_id);
613
+			$account_id = get_account_id($accountid, $this->account_id);
614 614
 			$cache_accountid[$accountid] = $account_id;
615 615
 		}
616 616
 		if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true);
617 617
 		$memberships[] = (int)$account_id;
618 618
 
619 619
 		$apps = array();
620
-		foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array(
620
+		foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array(
621 621
 			'acl_location' => 'run',
622 622
 			'acl_account'  => $memberships,
623
-		),__LINE__,__FILE__) as $row)
623
+		), __LINE__, __FILE__) as $row)
624 624
 		{
625 625
 			$app = $row['acl_appname'];
626
-			if(!isset($apps[$app]))
626
+			if (!isset($apps[$app]))
627 627
 			{
628 628
 				$apps[$app] = 0;
629 629
 			}
630
-			$apps[$app] |= (int) $row['acl_rights'];
630
+			$apps[$app] |= (int)$row['acl_rights'];
631 631
 		}
632 632
 		if ($add_implicit_apps)
633 633
 		{
634
-			$apps['api'] = 1;	// give everyone implicit rights for the home app
634
+			$apps['api'] = 1; // give everyone implicit rights for the home app
635 635
 		}
636 636
 		return $apps;
637 637
 	}
@@ -645,29 +645,29 @@  discard block
 block discarded – undo
645 645
 	 * @param int $user = null user whos grants to return, default current user
646 646
 	 * @return array with account-ids (of owners) and granted rights as values
647 647
 	 */
648
-	function get_grants($app='',$enum_group_acls=true,$user=null)
648
+	function get_grants($app = '', $enum_group_acls = true, $user = null)
649 649
 	{
650 650
 		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
651 651
 		if (!$user) $user = $this->account_id;
652 652
 
653
-		static $cache = array();	// some caching withing the request
653
+		static $cache = array(); // some caching withing the request
654 654
 
655
-		$grants =& $cache[$app][$user];
655
+		$grants = & $cache[$app][$user];
656 656
 		if (!isset($grants))
657 657
 		{
658 658
 			if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true);
659 659
 			$memberships[] = $user;
660 660
 
661 661
 			$grants = $accounts = Array();
662
-			foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array(
662
+			foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights', 'acl_location'), array(
663 663
 				'acl_appname'  => $app,
664 664
 				'acl_location' => $memberships,
665
-			),__LINE__,__FILE__) as $row)
665
+			), __LINE__, __FILE__) as $row)
666 666
 			{
667 667
 				$grantor    = $row['acl_account'];
668 668
 				$rights     = $row['acl_rights'];
669 669
 
670
-				if(!isset($grants[$grantor]))
670
+				if (!isset($grants[$grantor]))
671 671
 				{
672 672
 					$grants[$grantor] = 0;
673 673
 				}
@@ -675,17 +675,17 @@  discard block
 block discarded – undo
675 675
 
676 676
 				// if the right is granted from a group and we enummerated group ACL's
677 677
 				if ($GLOBALS['egw']->accounts->get_type($grantor) == 'g' && $enum_group_acls &&
678
-					(!is_array($enum_group_acls) || !in_array($grantor,$enum_group_acls)))
678
+					(!is_array($enum_group_acls) || !in_array($grantor, $enum_group_acls)))
679 679
 				{
680 680
 					// return the grant for each member of the group (false = also for no longer active users)
681
-					foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor)
681
+					foreach ((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor)
682 682
 					{
683
-						if (!$grantor) continue;	// can happen if group has no members
683
+						if (!$grantor) continue; // can happen if group has no members
684 684
 
685 685
 						// Don't allow to override private with group ACL's!
686 686
 						$rights &= ~self::PRIVAT;
687 687
 
688
-						if(!isset($grants[$grantor]))
688
+						if (!isset($grants[$grantor]))
689 689
 						{
690 690
 							$grants[$grantor] = 0;
691 691
 						}
@@ -707,21 +707,21 @@  discard block
 block discarded – undo
707 707
 	 */
708 708
 	function delete_account($account_id)
709 709
 	{
710
-		if ((int) $account_id)
710
+		if ((int)$account_id)
711 711
 		{
712 712
 			// Delete all grants from this account
713
-			$this->db->delete(self::TABLE,array(
713
+			$this->db->delete(self::TABLE, array(
714 714
 				'acl_account' => $account_id
715
-			),__LINE__,__FILE__);
715
+			), __LINE__, __FILE__);
716 716
 			// Delete all grants to this account
717
-			$this->db->delete(self::TABLE,array(
717
+			$this->db->delete(self::TABLE, array(
718 718
 				'acl_location' => $account_id
719
-			),__LINE__, __FILE__);
719
+			), __LINE__, __FILE__);
720 720
 			// delete all memberships in account_id (if it is a group)
721
-			$this->db->delete(self::TABLE,array(
721
+			$this->db->delete(self::TABLE, array(
722 722
 				'acl_appname' => 'phpgw_group',
723 723
 				'acl_location' => $account_id,
724
-			),__LINE__,__FILE__);
724
+			), __LINE__, __FILE__);
725 725
 		}
726 726
 	}
727 727
 
@@ -732,15 +732,15 @@  discard block
 block discarded – undo
732 732
 	 * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
733 733
 	 * @return array with location => array(account => rights) pairs
734 734
 	 */
735
-	function get_location_grants($location,$app='')
735
+	function get_location_grants($location, $app = '')
736 736
 	{
737 737
 		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
738 738
 
739 739
 		$locations = array();
740
-		foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array(
740
+		foreach ($this->db->select(self::TABLE, 'acl_location,acl_account,acl_rights', array(
741 741
 			'acl_appname'  => $app,
742 742
 			'acl_location LIKE '.$this->db->quote($location),
743
-		),__LINE__,__FILE__) as $row)
743
+		), __LINE__, __FILE__) as $row)
744 744
 		{
745 745
 			if (($location = $row['acl_location']) != 'run')
746 746
 			{
Please login to merge, or discard this patch.
Braces   +81 added lines, -20 removed lines patch added patch discarded remove patch
@@ -111,7 +111,10 @@  discard block
 block discarded – undo
111 111
 		else
112 112
 		{
113 113
 			$acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true);
114
-			if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups);
114
+			if (is_array($no_groups))
115
+			{
116
+				$acl_acc_list = array_diff($acl_acc_list,$no_groups);
117
+			}
115 118
 			array_unshift($acl_acc_list,$this->account_id);
116 119
 		}
117 120
 
@@ -149,7 +152,10 @@  discard block
 block discarded – undo
149 152
 	 */
150 153
 	function add($appname,$location,$rights)
151 154
 	{
152
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
155
+		if (!$appname)
156
+		{
157
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
158
+		}
153 159
 
154 160
 		$row = array(
155 161
 			'appname'  => $appname,
@@ -171,7 +177,10 @@  discard block
 block discarded – undo
171 177
 	 */
172 178
 	function delete($appname,$location)
173 179
 	{
174
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
180
+		if (!$appname)
181
+		{
182
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
183
+		}
175 184
 
176 185
 		foreach($this->data as $idx => $value)
177 186
 		{
@@ -209,10 +218,13 @@  discard block
 block discarded – undo
209 218
 			}
210 219
 		}
211 220
 		if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] &&
212
-			method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
221
+			method_exists($GLOBALS['egw'],'invalidate_session_cache'))
222
+		{
223
+			// egw object in setup is limited
213 224
 		{
214 225
 			$GLOBALS['egw']->invalidate_session_cache();
215 226
 		}
227
+		}
216 228
 		return $this->data;
217 229
 	}
218 230
 
@@ -240,7 +252,10 @@  discard block
 block discarded – undo
240 252
 		{
241 253
 			$this->read_repository();
242 254
 		}
243
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
255
+		if (!$appname)
256
+		{
257
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
258
+		}
244 259
 
245 260
 		if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny')
246 261
 		{
@@ -289,7 +304,10 @@  discard block
 block discarded – undo
289 304
 	 */
290 305
 	function get_specific_rights($location, $appname = '', $memberships=array())
291 306
 	{
292
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
307
+		if (!$appname)
308
+		{
309
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
310
+		}
293 311
 
294 312
 		if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny')
295 313
 		{
@@ -353,10 +371,13 @@  discard block
 block discarded – undo
353 371
 		),__LINE__,__FILE__);
354 372
 
355 373
 		if ($account_id == $GLOBALS['egw_info']['user']['account_id'] &&
356
-			method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
374
+			method_exists($GLOBALS['egw'],'invalidate_session_cache'))
375
+		{
376
+			// egw object in setup is limited
357 377
 		{
358 378
 			$GLOBALS['egw']->invalidate_session_cache();
359 379
 		}
380
+		}
360 381
 		return True;
361 382
 	}
362 383
 
@@ -387,11 +408,17 @@  discard block
 block discarded – undo
387 408
 				$where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id);
388 409
 			}
389 410
 		}
390
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
411
+		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))
412
+		{
413
+			// egw object in setup is limited
391 414
 		{
392 415
 			$GLOBALS['egw']->invalidate_session_cache();
393 416
 		}
394
-		if ($app == '%' || $app == '%%') unset($where['acl_appname']);
417
+		}
418
+		if ($app == '%' || $app == '%%')
419
+		{
420
+			unset($where['acl_appname']);
421
+		}
395 422
 
396 423
 		$this->db->delete(self::TABLE,$where,__LINE__,__FILE__);
397 424
 
@@ -408,7 +435,10 @@  discard block
 block discarded – undo
408 435
 	 */
409 436
 	function get_specific_rights_for_account($account_id,$location,$appname='')
410 437
 	{
411
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
438
+		if (!$appname)
439
+		{
440
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
441
+		}
412 442
 
413 443
 		return $this->db->select(self::TABLE,'acl_rights',array(
414 444
 			'acl_location' => $location,
@@ -426,7 +456,10 @@  discard block
 block discarded – undo
426 456
 	 */
427 457
 	function get_all_rights($location,$appname='')
428 458
 	{
429
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
459
+		if (!$appname)
460
+		{
461
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
462
+		}
430 463
 
431 464
 		$rights = array();
432 465
 		foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array(
@@ -449,7 +482,10 @@  discard block
 block discarded – undo
449 482
 	 */
450 483
 	function get_all_location_rights($account_id,$appname='',$use_memberships=true)
451 484
 	{
452
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
485
+		if (!$appname)
486
+		{
487
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
488
+		}
453 489
 
454 490
 		$accounts = array($account_id);
455 491
 		if ($use_memberships && (int)$account_id > 0)
@@ -553,7 +589,10 @@  discard block
 block discarded – undo
553 589
 	 */
554 590
 	function get_ids_for_location($location, $required, $app = '')
555 591
 	{
556
-		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
592
+		if (!$app)
593
+		{
594
+			$app = $GLOBALS['egw_info']['flags']['currentapp'];
595
+		}
557 596
 
558 597
 		$accounts = false;
559 598
 		foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array(
@@ -577,7 +616,10 @@  discard block
 block discarded – undo
577 616
 	 */
578 617
 	function get_locations_for_app($app='')
579 618
 	{
580
-		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
619
+		if (!$app)
620
+		{
621
+			$app = $GLOBALS['egw_info']['flags']['currentapp'];
622
+		}
581 623
 
582 624
 		$locations = false;
583 625
 		foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array(
@@ -613,7 +655,10 @@  discard block
 block discarded – undo
613 655
 			$account_id = get_account_id($accountid,$this->account_id);
614 656
 			$cache_accountid[$accountid] = $account_id;
615 657
 		}
616
-		if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true);
658
+		if ($use_memberships && (int)$account_id > 0)
659
+		{
660
+			$memberships = $GLOBALS['egw']->accounts->memberships($account_id, true);
661
+		}
617 662
 		$memberships[] = (int)$account_id;
618 663
 
619 664
 		$apps = array();
@@ -647,15 +692,24 @@  discard block
 block discarded – undo
647 692
 	 */
648 693
 	function get_grants($app='',$enum_group_acls=true,$user=null)
649 694
 	{
650
-		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
651
-		if (!$user) $user = $this->account_id;
695
+		if (!$app)
696
+		{
697
+			$app = $GLOBALS['egw_info']['flags']['currentapp'];
698
+		}
699
+		if (!$user)
700
+		{
701
+			$user = $this->account_id;
702
+		}
652 703
 
653 704
 		static $cache = array();	// some caching withing the request
654 705
 
655 706
 		$grants =& $cache[$app][$user];
656 707
 		if (!isset($grants))
657 708
 		{
658
-			if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true);
709
+			if ((int)$user > 0)
710
+			{
711
+				$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
712
+			}
659 713
 			$memberships[] = $user;
660 714
 
661 715
 			$grants = $accounts = Array();
@@ -680,7 +734,11 @@  discard block
 block discarded – undo
680 734
 					// return the grant for each member of the group (false = also for no longer active users)
681 735
 					foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor)
682 736
 					{
683
-						if (!$grantor) continue;	// can happen if group has no members
737
+						if (!$grantor)
738
+						{
739
+							continue;
740
+						}
741
+						// can happen if group has no members
684 742
 
685 743
 						// Don't allow to override private with group ACL's!
686 744
 						$rights &= ~self::PRIVAT;
@@ -734,7 +792,10 @@  discard block
 block discarded – undo
734 792
 	 */
735 793
 	function get_location_grants($location,$app='')
736 794
 	{
737
-		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
795
+		if (!$app)
796
+		{
797
+			$app = $GLOBALS['egw_info']['flags']['currentapp'];
798
+		}
738 799
 
739 800
 		$locations = array();
740 801
 		foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array(
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	/**
37 37
 	 * @var array $data internal repository with acl rows for the given app and account-id (incl. memberships)
38 38
 	 */
39
-	var $data = Array();
39
+	var $data = array();
40 40
 	/**
41 41
 	 * internal copy of the db-object
42 42
 	 *
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 			array_unshift($acl_acc_list,$this->account_id);
116 116
 		}
117 117
 
118
-		$this->data = Array();
118
+		$this->data = array();
119 119
 		foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row)
120 120
 		{
121 121
 			$this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_');
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 			if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true);
659 659
 			$memberships[] = $user;
660 660
 
661
-			$grants = $accounts = Array();
661
+			$grants = $accounts = array();
662 662
 			foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array(
663 663
 				'acl_appname'  => $app,
664 664
 				'acl_location' => $memberships,
Please login to merge, or discard this patch.
api/src/Asyncservice.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	 * cancels a timer
325 325
 	 *
326 326
 	 * @param string $id has to be the one used to set it.
327
-	 * @return boolean True if the timer exists and is not expired.
327
+	 * @return integer True if the timer exists and is not expired.
328 328
 	 */
329 329
 	function cancel_timer($id)
330 330
 	{
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 	/**
471 471
 	 * reads all matching db-rows / jobs
472 472
 	 *
473
-	 * @param string $id =0 reads all expired rows / jobs ready to run\
473
+	 * @param integer $id =0 reads all expired rows / jobs ready to run\
474 474
 	 * 	!= 0 reads all rows/jobs matching $id (sql-wildcards '%' and '_' can be used)
475 475
 	 * @param array|string $cols ='*' string or array of column-names / select-expressions
476 476
 	 * @param int|bool $offset =False offset for a limited query or False (default)
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 	/**
559 559
 	 * delete db-row / job with $id
560 560
 	 *
561
-	 * @return boolean False if $id not found else True
561
+	 * @return integer False if $id not found else True
562 562
 	 */
563 563
 	function delete($id)
564 564
 	{
Please login to merge, or discard this patch.
Spacing   +74 added lines, -76 removed lines patch added patch discarded remove patch
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 		{
50 50
 			$this->db = $GLOBALS['egw_setup']->db;
51 51
 		}
52
-		$this->cronline = EGW_SERVER_ROOT . '/api/asyncservices.php '.$GLOBALS['egw_info']['user']['domain'];
52
+		$this->cronline = EGW_SERVER_ROOT.'/api/asyncservices.php '.$GLOBALS['egw_info']['user']['domain'];
53 53
 
54
-		$this->only_fallback = substr(php_uname(), 0, 7) == "Windows";	// atm cron-jobs dont work on win
54
+		$this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win
55 55
 	}
56 56
 
57 57
 	/**
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 	 * @param boolean $debug =false
72 72
 	 * @return boolean False if $id already exists, else True
73 73
 	 */
74
-	function set_timer($times,$id,$method,$data=null,$account_id=False,$debug=false)
74
+	function set_timer($times, $id, $method, $data = null, $account_id = False, $debug = false)
75 75
 	{
76 76
 		if (empty($id) || empty($method) || $this->read($id) ||
77
-				!($next = $this->next_run($times,$debug)))
77
+				!($next = $this->next_run($times, $debug)))
78 78
 		{
79 79
 			return False;
80 80
 		}
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 	 * @param int $now Use this time to calculate then next run from.  Defaults to time().
108 108
 	 * @return int a unix timestamp of the next execution time or False if no more executions
109 109
 	 */
110
-	function next_run($times,$debug=False, $now = null)
110
+	function next_run($times, $debug = False, $now = null)
111 111
 	{
112 112
 		if ($this->debug)
113 113
 		{
114
-			echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n";
115
-			$debug = True;	// enable syntax-error messages too
114
+			echo "<p>next_run("; print_r($times); echo ",'$debug', ".date('Y-m-d H:i', $now).")</p>\n";
115
+			$debug = True; // enable syntax-error messages too
116 116
 		}
117
-		if(is_null($now)) {
117
+		if (is_null($now)) {
118 118
 			$now = time();
119 119
 		}
120 120
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 			'dow'   => 6,
143 143
 			'day'   => 31,
144 144
 			'month' => 12,
145
-			'year'  => date('Y')+10	// else */[0-9] would never stop returning numbers
145
+			'year'  => date('Y') + 10	// else */[0-9] would never stop returning numbers
146 146
 		);
147 147
 		$min_unit = array(
148 148
 			'min'   => 0,
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 		// get set to the minimum after
159 159
 		//
160 160
 		$i = $first_set = $last_set = 0;
161
-		foreach($units as $u => $date_pattern)
161
+		foreach ($units as $u => $date_pattern)
162 162
 		{
163 163
 			++$i;
164 164
 			if (isset($times[$u]))
@@ -176,24 +176,24 @@  discard block
 block discarded – undo
176 176
 		// (as descript above), enumerations are arrays with unit-values as keys
177 177
 		//
178 178
 		$n = 0;
179
-		foreach($units as $u => $date_pattern)
179
+		foreach ($units as $u => $date_pattern)
180 180
 		{
181 181
 			++$n;
182
-			if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; }
182
+			if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u]) ? 'True' : 'False')."</p>\n"; }
183 183
 			if (isset($times[$u]))
184 184
 			{
185
-				if(is_array($times[$u])) {
185
+				if (is_array($times[$u])) {
186 186
 					$time = array_keys($times[$u]);
187 187
 				} else {
188
-					$time = explode(',',$times[$u]);
188
+					$time = explode(',', $times[$u]);
189 189
 				}
190 190
 				$times[$u] = array();
191 191
 
192
-				foreach($time as $t)
192
+				foreach ($time as $t)
193 193
 				{
194
-					if (strpos($t,'-') !== False && strpos($t,'/') === False)
194
+					if (strpos($t, '-') !== False && strpos($t, '/') === False)
195 195
 					{
196
-						list($min,$max) = $arr = explode('-',$t);
196
+						list($min, $max) = $arr = explode('-', $t);
197 197
 
198 198
 						if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max)
199 199
 						{
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 					{
211 211
 						if ((string)$t == '*') 	$t = '*/1';
212 212
 
213
-						list($one,$inc) = $arr = explode('/',$t);
213
+						list($one, $inc) = $arr = explode('/', $t);
214 214
 
215 215
 						if (!(is_numeric($one) && count($arr) == 1 ||
216 216
 									count($arr) == 2 && is_numeric($inc)))
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 						}
226 226
 						else
227 227
 						{
228
-							list($min,$max) = $arr = explode('-',$one);
228
+							list($min, $max) = $arr = explode('-', $one);
229 229
 							if (empty($one) || $one == '*')
230 230
 							{
231 231
 								$min = $min_unit[$u];
@@ -266,20 +266,19 @@  discard block
 block discarded – undo
266 266
 		{
267 267
 			$future = False;
268 268
 
269
-			foreach($units as $u => $date_pattern)
269
+			foreach ($units as $u => $date_pattern)
270 270
 			{
271
-				$unit_now = $u != 'dow' ? (int)date($date_pattern, $now) :
272
-					(int)date($date_pattern,mktime(12,0,0,$found['month'],$found['day'],$found['year']));
271
+				$unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : (int)date($date_pattern, mktime(12, 0, 0, $found['month'], $found['day'], $found['year']));
273 272
 
274 273
 				if (isset($found[$u]))
275 274
 				{
276 275
 					$future = $future || $found[$u] > $unit_now;
277 276
 					if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n";
278
-					continue;	// already set
277
+					continue; // already set
279 278
 				}
280
-				foreach(array_keys($times[$u]) as $unit_value)
279
+				foreach (array_keys($times[$u]) as $unit_value)
281 280
 				{
282
-					switch($u)
281
+					switch ($u)
283 282
 					{
284 283
 						case 'dow':
285 284
 							$valid = $unit_value == $unit_now;
@@ -302,12 +301,12 @@  discard block
 block discarded – undo
302 301
 				if (!isset($found[$u]))		// we have to try the next one, if it exists
303 302
 				{
304 303
 					$nexts = array_keys($units);
305
-					if (!isset($nexts[count($found)-1]))
304
+					if (!isset($nexts[count($found) - 1]))
306 305
 					{
307 306
 						if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n";
308 307
 						return False;
309 308
 					}
310
-					$next = $nexts[count($found)-1];
309
+					$next = $nexts[count($found) - 1];
311 310
 					$over = $found[$next];
312 311
 					unset($found[$next]);
313 312
 					if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n";
@@ -317,7 +316,7 @@  discard block
 block discarded – undo
317 316
 		}
318 317
 		if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; }
319 318
 
320
-		return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']);
319
+		return mktime($found['hour'], $found['min'], 0, $found['month'], $found['day'], $found['year']);
321 320
 	}
322 321
 
323 322
 	/**
@@ -339,7 +338,7 @@  discard block
 block discarded – undo
339 338
 	 * @return mixed if !$set array('start' => $start,'end' => $end) with timestamps of last check_run start and end,  \
340 339
 	 * 	!$end means check_run is just running. If $set returns True if it was able to get the semaphore, else False
341 340
 	 */
342
-	function last_check_run($semaphore=False,$release=False,$run_by='')
341
+	function last_check_run($semaphore = False, $release = False, $run_by = '')
343 342
 	{
344 343
 		//echo "<p>last_check_run(semaphore=".($semaphore?'True':'False').",release=".($release?'True':'False').")</p>\n";
345 344
 		if (($exists = $this->read('##last-check-run##')))
@@ -361,7 +360,7 @@  discard block
 block discarded – undo
361 360
 		}
362 361
 		else
363 362
 		{
364
-			@set_time_limit(0);		// dont stop for an execution-time-limit
363
+			@set_time_limit(0); // dont stop for an execution-time-limit
365 364
 			ignore_user_abort(True);
366 365
 
367 366
 			$last_run = array(
@@ -377,7 +376,7 @@  discard block
 block discarded – undo
377 376
 			);
378 377
 			// as the async_next column is used as a semaphore we only update it,
379 378
 			// if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts
380
-			if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600));
379
+			if ($exists) $where = array('async_next=0 OR async_next<'.(time() - 600));
381 380
 		}
382 381
 		//echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n";
383 382
 		return $this->write($last_run, !!$exists, $where) > 0;
@@ -386,20 +385,20 @@  discard block
 block discarded – undo
386 385
 	/**
387 386
 	 * checks if there are any jobs ready to run (timer expired) and executes them
388 387
 	 */
389
-	function check_run($run_by='')
388
+	function check_run($run_by = '')
390 389
 	{
391 390
 		if ($run_by === 'fallback') flush();
392 391
 
393
-		if (!$this->last_check_run(True,False,$run_by))
392
+		if (!$this->last_check_run(True, False, $run_by))
394 393
 		{
395
-			return False;	// cant obtain semaphore
394
+			return False; // cant obtain semaphore
396 395
 		}
397 396
 		// mark enviroment as async-service, check with isset()!
398 397
 		$GLOBALS['egw_info']['flags']['async-service'] = $run_by;
399 398
 
400 399
 		if (($jobs = $this->read()))
401 400
 		{
402
-			foreach($jobs as $job)
401
+			foreach ($jobs as $job)
403 402
 			{
404 403
 				// checking / setting up egw_info/user
405 404
 				//
@@ -408,7 +407,7 @@  discard block
 block discarded – undo
408 407
 					// run notifications, before changing account_id of enviroment
409 408
 					Link::run_notifies();
410 409
 					// unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data
411
-					foreach($GLOBALS as $name => $value)
410
+					foreach ($GLOBALS as $name => $value)
412 411
 					{
413 412
 						if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]);
414 413
 					}
@@ -420,7 +419,7 @@  discard block
 block discarded – undo
420 419
 					{
421 420
 						$GLOBALS['egw']->session->account_lid = $GLOBALS['egw']->accounts->id2name($job['account_id']);
422 421
 						$GLOBALS['egw']->session->account_domain = $domain;
423
-						$GLOBALS['egw_info']['user']  = $GLOBALS['egw']->session->read_repositories();
422
+						$GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories();
424 423
 
425 424
 						if ($lang != $GLOBALS['egw_info']['user']['preferences']['common']['lang'])
426 425
 						{
@@ -435,12 +434,11 @@  discard block
 block discarded – undo
435 434
 						$GLOBALS['egw_info']['user']['domain'] = $domain;
436 435
 					}
437 436
 				}
438
-				list($app) = strpos($job['method'],'::') !== false ? explode('_',$job['method']) :
439
-					explode('.',$job['method']);
437
+				list($app) = strpos($job['method'], '::') !== false ? explode('_', $job['method']) : explode('.', $job['method']);
440 438
 				Translation::add_app($app);
441 439
 				if (is_array($job['data']))
442 440
 				{
443
-					$job['data'] += array_diff_key($job,array('data' => false));
441
+					$job['data'] += array_diff_key($job, array('data' => false));
444 442
 				}
445 443
 				// update job before running it, to cope with jobs taking longer then async-frequency
446 444
 				if (($job['next'] = $this->next_run($job['times'])))
@@ -453,16 +451,16 @@  discard block
 block discarded – undo
453 451
 				}
454 452
 				try
455 453
 				{
456
-					ExecMethod($job['method'],$job['data']);
454
+					ExecMethod($job['method'], $job['data']);
457 455
 				}
458
-				catch(Exception $e)
456
+				catch (Exception $e)
459 457
 				{
460 458
 					// log the exception to error_log, but continue running other async jobs
461 459
 					_egw_log_exception($e);
462 460
 				}
463 461
 			}
464 462
 		}
465
-		$this->last_check_run(True,True,$run_by);	// release semaphore
463
+		$this->last_check_run(True, True, $run_by); // release semaphore
466 464
 
467 465
 		return $jobs ? count($jobs) : 0;
468 466
 	}
@@ -478,7 +476,7 @@  discard block
 block discarded – undo
478 476
 	 * @param int $num_rows =0 number of rows to return if offset set, default 0 = use default in user prefs
479 477
 	 * @return array/boolean db-rows / jobs as array or False if no matches
480 478
 	 */
481
-	function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0)
479
+	function read($id = 0, $cols = '*', $offset = False, $append = 'ORDER BY async_next', $num_rows = 0)
482 480
 	{
483 481
 		if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false;
484 482
 
@@ -486,7 +484,7 @@  discard block
 block discarded – undo
486 484
 		{
487 485
 			$where = "async_id != '##last-check-run##'";
488 486
 		}
489
-		elseif (!is_array($id) && (strpos($id,'%') !== False || strpos($id,'_') !== False))
487
+		elseif (!is_array($id) && (strpos($id, '%') !== False || strpos($id, '_') !== False))
490 488
 		{
491 489
 			$id = $this->db->quote($id);
492 490
 			$where = "async_id LIKE $id AND async_id != '##last-check-run##'";
@@ -500,21 +498,21 @@  discard block
 block discarded – undo
500 498
 			$where = array('async_id' => $id);
501 499
 		}
502 500
 		$jobs = array();
503
-		foreach($this->db->select($this->db_table,$cols,$where,__LINE__,__FILE__,$offset,$append,False,$num_rows) as $row)
501
+		foreach ($this->db->select($this->db_table, $cols, $where, __LINE__, __FILE__, $offset, $append, False, $num_rows) as $row)
504 502
 		{
505 503
 			$row['async_times'] = json_php_unserialize($row['async_times']);
506 504
 			// check for broken value during migration
507 505
 			if ($row['async_data'][0] == '"' && substr($row['async_data'], 0, 7) == '"\\"\\\\\\"')
508 506
 			{
509 507
 				$row['async_data'] = null;
510
-				$this->write(Db::strip_array_keys($row,'async_'), true);
508
+				$this->write(Db::strip_array_keys($row, 'async_'), true);
511 509
 			}
512 510
 			else
513 511
 			{
514 512
 				$row['async_data'] = !empty($row['async_data']) ?
515
-					json_php_unserialize($row['async_data'], true) : null;	// allow non-serialized data
513
+					json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data
516 514
 			}
517
-			$jobs[$row['async_id']] = Db::strip_array_keys($row,'async_');
515
+			$jobs[$row['async_id']] = Db::strip_array_keys($row, 'async_');
518 516
 		}
519 517
 		if (!count($jobs))
520 518
 		{
@@ -531,7 +529,7 @@  discard block
 block discarded – undo
531 529
 	 * @param array $where additional where statemetn to update only if a certain condition is met, used for the semaphore
532 530
 	 * @return int affected rows, can be 0 if an additional where statement is given
533 531
 	 */
534
-	function write($job, $exists = False, $where=array())
532
+	function write($job, $exists = False, $where = array())
535 533
 	{
536 534
 		if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0;
537 535
 
@@ -562,7 +560,7 @@  discard block
 block discarded – undo
562 560
 	 */
563 561
 	function delete($id)
564 562
 	{
565
-		$this->db->delete($this->db_table,array('async_id' => $id),__LINE__,__FILE__);
563
+		$this->db->delete($this->db_table, array('async_id' => $id), __LINE__, __FILE__);
566 564
 
567 565
 		return $this->db->affected_rows();
568 566
 	}
@@ -587,38 +585,38 @@  discard block
 block discarded – undo
587 585
 		{
588 586
 			$binarys = array(
589 587
 				'php'  => '/usr/bin/php',
590
-				'php5' => '/usr/bin/php5',		// SuSE 9.3 with php5
588
+				'php5' => '/usr/bin/php5', // SuSE 9.3 with php5
591 589
 				'crontab' => '/usr/bin/crontab'
592 590
 			);
593 591
 			foreach ($binarys as $name => $path)
594 592
 			{
595
-				$this->$name = $path;	// a reasonable default for *nix
593
+				$this->$name = $path; // a reasonable default for *nix
596 594
 
597 595
 				if (!($Ok = @is_executable($this->$name)))
598 596
 				{
599 597
 					if (file_exists($this->$name))
600 598
 					{
601
-						echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n";
599
+						echo '<p>'.lang('%1 is not executable by the webserver !!!', $this->$name)."</p>\n";
602 600
 						$perms = fileperms($this->$name);
603
-						if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid'))	// only executable by group
601
+						if (!($perms&0x0001) && ($perms&0x0008) && function_exists('posix_getuid'))	// only executable by group
604 602
 						{
605 603
 							$group = posix_getgrgid(filegroup($this->$name));
606
-							$webserver = posix_getpwuid(posix_getuid ());
607
-							echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n";							}
604
+							$webserver = posix_getpwuid(posix_getuid());
605
+							echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.", $webserver['name'], $group['name'])."</p>\n"; }
608 606
 					}
609
-					if (($fd = popen('/bin/sh -c "type -p '.$name.'"','r')))
607
+					if (($fd = popen('/bin/sh -c "type -p '.$name.'"', 'r')))
610 608
 					{
611
-						$this->$name = fgets($fd,256);
609
+						$this->$name = fgets($fd, 256);
612 610
 						@pclose($fd);
613 611
 					}
614
-					if (($pos = strpos($this->$name,"\n")))
612
+					if (($pos = strpos($this->$name, "\n")))
615 613
 					{
616
-						$this->$name = substr($this->$name,0,$pos);
614
+						$this->$name = substr($this->$name, 0, $pos);
617 615
 					}
618 616
 				}
619 617
 				if (!$Ok && !@is_executable($this->$name))
620 618
 				{
621
-					$this->$name = $name;	// hopefully its in the path
619
+					$this->$name = $name; // hopefully its in the path
622 620
 				}
623 621
 				//echo "<p>$name = '".$this->$name."'</p>\n";
624 622
 			}
@@ -649,15 +647,15 @@  discard block
 block discarded – undo
649 647
 		}
650 648
 		$times = False;
651 649
 		$this->other_cronlines = array();
652
-		if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1','r')) !== False)
650
+		if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1', 'r')) !== False)
653 651
 		{
654 652
 			$n = 0;
655
-			while ($line = fgets($crontab,256))
653
+			while ($line = fgets($crontab, 256))
656 654
 			{
657 655
 				if ($this->debug) echo 'line '.++$n.": $line<br>\n";
658
-				$parts = explode(' ',$line,6);
656
+				$parts = explode(' ', $line, 6);
659 657
 
660
-				if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php'))
658
+				if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5], 0, 3) != 'php'))
661 659
 				{
662 660
 					// ignore comments
663 661
 					if ($line{0} != '#')
@@ -665,12 +663,12 @@  discard block
 block discarded – undo
665 663
 						$times['error'] .= $line;
666 664
 					}
667 665
 				}
668
-				elseif (strpos($line,$this->cronline) !== False ||
666
+				elseif (strpos($line, $this->cronline) !== False ||
669 667
 					// also check of old phpgwapi/cron path
670 668
 					strpos($line, str_replace('/api/', '/phpgwapi/cron/', $this->cronline)) !== False)
671 669
 				{
672
-					$cron_units = array('min','hour','day','month','dow');
673
-					foreach($cron_units as $n => $u)
670
+					$cron_units = array('min', 'hour', 'day', 'month', 'dow');
671
+					foreach ($cron_units as $n => $u)
674 672
 					{
675 673
 						$times[$u] = $parts[$n];
676 674
 					}
@@ -701,29 +699,29 @@  discard block
 block discarded – undo
701 699
 		if ($this->only_fallback && $times !== False) {
702 700
 			return 0;
703 701
 		}
704
-		$this->installed();	// find other installed cronlines
702
+		$this->installed(); // find other installed cronlines
705 703
 
706
-		if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1','w')) !== False)
704
+		if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1', 'w')) !== False)
707 705
 		{
708 706
 			if (is_array($this->other_cronlines))
709 707
 			{
710 708
 				foreach ($this->other_cronlines as $cronline)
711 709
 				{
712
-					fwrite($crontab,$cronline);		// preserv the other lines on install
710
+					fwrite($crontab, $cronline); // preserv the other lines on install
713 711
 				}
714 712
 			}
715 713
 			if ($times !== False)
716 714
 			{
717
-				$cron_units = array('min','hour','day','month','dow');
715
+				$cron_units = array('min', 'hour', 'day', 'month', 'dow');
718 716
 				$cronline = '';
719
-				foreach($cron_units as $cu)
717
+				foreach ($cron_units as $cu)
720 718
 				{
721
-					$cronline .= (isset($times[$cu]) ? $times[$cu] : '*') . ' ';
719
+					$cronline .= (isset($times[$cu]) ? $times[$cu] : '*').' ';
722 720
 				}
723 721
 				// -d memory_limit=-1 --> no memory limit
724 722
 				$cronline .= $this->php.' -q -d memory_limit=-1 '.$this->cronline."\n";
725 723
 				//echo "<p>Installing: '$cronline'</p>\n";
726
-				fwrite($crontab,$cronline);
724
+				fwrite($crontab, $cronline);
727 725
 			}
728 726
 			@pclose($crontab);
729 727
 		}
Please login to merge, or discard this patch.
Braces   +98 added lines, -28 removed lines patch added patch discarded remove patch
@@ -114,7 +114,8 @@  discard block
 block discarded – undo
114 114
 			echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n";
115 115
 			$debug = True;	// enable syntax-error messages too
116 116
 		}
117
-		if(is_null($now)) {
117
+		if(is_null($now))
118
+		{
118 119
 			$now = time();
119 120
 		}
120 121
 
@@ -179,12 +180,17 @@  discard block
 block discarded – undo
179 180
 		foreach($units as $u => $date_pattern)
180 181
 		{
181 182
 			++$n;
182
-			if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; }
183
+			if ($this->debug)
184
+			{
185
+echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; }
183 186
 			if (isset($times[$u]))
184 187
 			{
185
-				if(is_array($times[$u])) {
188
+				if(is_array($times[$u]))
189
+				{
186 190
 					$time = array_keys($times[$u]);
187
-				} else {
191
+				}
192
+				else
193
+				{
188 194
 					$time = explode(',',$times[$u]);
189 195
 				}
190 196
 				$times[$u] = array();
@@ -197,7 +203,10 @@  discard block
 block discarded – undo
197 203
 
198 204
 						if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max)
199 205
 						{
200
-							if ($debug) echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n";
206
+							if ($debug)
207
+							{
208
+								echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n";
209
+							}
201 210
 
202 211
 							return False;
203 212
 						}
@@ -208,14 +217,20 @@  discard block
 block discarded – undo
208 217
 					}
209 218
 					else
210 219
 					{
211
-						if ((string)$t == '*') 	$t = '*/1';
220
+						if ((string)$t == '*')
221
+						{
222
+							$t = '*/1';
223
+						}
212 224
 
213 225
 						list($one,$inc) = $arr = explode('/',$t);
214 226
 
215 227
 						if (!(is_numeric($one) && count($arr) == 1 ||
216 228
 									count($arr) == 2 && is_numeric($inc)))
217 229
 						{
218
-							if ($debug) echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n";
230
+							if ($debug)
231
+							{
232
+								echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n";
233
+							}
219 234
 
220 235
 							return False;
221 236
 						}
@@ -233,7 +248,10 @@  discard block
 block discarded – undo
233 248
 							}
234 249
 							elseif (count($arr) != 2 || $min > $max)
235 250
 							{
236
-								if ($debug) echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n";
251
+								if ($debug)
252
+								{
253
+									echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n";
254
+								}
237 255
 								return False;
238 256
 							}
239 257
 							for ($i = $min; $i <= $max; $i += $inc)
@@ -244,9 +262,13 @@  discard block
 block discarded – undo
244 262
 					}
245 263
 				}
246 264
 			}
247
-			elseif ($n < $last_set || $u == 'dow')	// before last value set (or dow) => empty gets enumerated
265
+			elseif ($n < $last_set || $u == 'dow')
266
+			{
267
+				// before last value set (or dow) => empty gets enumerated
248 268
 			{
249
-				for ($i = $min_unit[$u]; $i <= $max_unit[$u]; ++$i)
269
+				for ($i = $min_unit[$u];
270
+			}
271
+			$i <= $max_unit[$u]; ++$i)
250 272
 				{
251 273
 					$times[$u][$i] = True;
252 274
 				}
@@ -256,7 +278,9 @@  discard block
 block discarded – undo
256 278
 				$times[$u][$min_unit[$u]] = True;
257 279
 			}
258 280
 		}
259
-		if ($this->debug) { echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; }
281
+		if ($this->debug)
282
+		{
283
+echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; }
260 284
 
261 285
 		// now we have the times enumerated, lets find the first not expired one
262 286
 		//
@@ -274,7 +298,10 @@  discard block
 block discarded – undo
274 298
 				if (isset($found[$u]))
275 299
 				{
276 300
 					$future = $future || $found[$u] > $unit_now;
277
-					if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n";
301
+					if ($this->debug)
302
+					{
303
+						echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n";
304
+					}
278 305
 					continue;	// already set
279 306
 				}
280 307
 				foreach(array_keys($times[$u]) as $unit_value)
@@ -292,30 +319,44 @@  discard block
 block discarded – undo
292 319
 							break;
293 320
 
294 321
 					}
295
-					if ($valid && ($u != $next || $unit_value > $over))	 // valid and not over
322
+					if ($valid && ($u != $next || $unit_value > $over))
323
+					{
324
+						// valid and not over
296 325
 					{
297 326
 						$found[$u] = $unit_value;
327
+					}
298 328
 						$future = $future || $unit_value > $unit_now;
299 329
 						break;
300 330
 					}
301 331
 				}
302
-				if (!isset($found[$u]))		// we have to try the next one, if it exists
332
+				if (!isset($found[$u]))
333
+				{
334
+					// we have to try the next one, if it exists
303 335
 				{
304 336
 					$nexts = array_keys($units);
337
+				}
305 338
 					if (!isset($nexts[count($found)-1]))
306 339
 					{
307
-						if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n";
340
+						if ($this->debug)
341
+						{
342
+							echo "<p>Nothing found, exiting !!!</p>\n";
343
+						}
308 344
 						return False;
309 345
 					}
310 346
 					$next = $nexts[count($found)-1];
311 347
 					$over = $found[$next];
312 348
 					unset($found[$next]);
313
-					if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n";
349
+					if ($this->debug)
350
+					{
351
+						echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n";
352
+					}
314 353
 					break;
315 354
 				}
316 355
 			}
317 356
 		}
318
-		if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; }
357
+		if ($this->debug)
358
+		{
359
+echo "<p>next="; print_r($found); echo "</p>\n"; }
319 360
 
320 361
 		return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']);
321 362
 	}
@@ -377,7 +418,10 @@  discard block
 block discarded – undo
377 418
 			);
378 419
 			// as the async_next column is used as a semaphore we only update it,
379 420
 			// if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts
380
-			if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600));
421
+			if ($exists)
422
+			{
423
+				$where = array('async_next=0 OR async_next<'.(time()-600));
424
+			}
381 425
 		}
382 426
 		//echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n";
383 427
 		return $this->write($last_run, !!$exists, $where) > 0;
@@ -388,7 +432,10 @@  discard block
 block discarded – undo
388 432
 	 */
389 433
 	function check_run($run_by='')
390 434
 	{
391
-		if ($run_by === 'fallback') flush();
435
+		if ($run_by === 'fallback')
436
+		{
437
+			flush();
438
+		}
392 439
 
393 440
 		if (!$this->last_check_run(True,False,$run_by))
394 441
 		{
@@ -410,7 +457,10 @@  discard block
 block discarded – undo
410 457
 					// unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data
411 458
 					foreach($GLOBALS as $name => $value)
412 459
 					{
413
-						if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]);
460
+						if ($name !== 'egw' && is_object($value))
461
+						{
462
+							unset($GLOBALS[$name]);
463
+						}
414 464
 					}
415 465
 					$domain = $GLOBALS['egw_info']['user']['domain'];
416 466
 					$lang   = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
@@ -480,7 +530,10 @@  discard block
 block discarded – undo
480 530
 	 */
481 531
 	function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0)
482 532
 	{
483
-		if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false;
533
+		if (!is_a($this->db, 'EGroupware\\Api\\Db'))
534
+		{
535
+			return false;
536
+		}
484 537
 
485 538
 		if ($id === '%')
486 539
 		{
@@ -533,9 +586,15 @@  discard block
 block discarded – undo
533 586
 	 */
534 587
 	function write($job, $exists = False, $where=array())
535 588
 	{
536
-		if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0;
589
+		if (!is_a($this->db, 'EGroupware\\Api\\Db'))
590
+		{
591
+			return 0;
592
+		}
537 593
 
538
-		if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) $job['data']['next'] = $job['next'];
594
+		if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next']))
595
+		{
596
+			$job['data']['next'] = $job['next'];
597
+		}
539 598
 		$data = array(
540 599
 			'async_next'      => $job['next'],
541 600
 			'async_times'     => json_encode($job['times']),
@@ -600,9 +659,12 @@  discard block
 block discarded – undo
600 659
 					{
601 660
 						echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n";
602 661
 						$perms = fileperms($this->$name);
603
-						if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid'))	// only executable by group
662
+						if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid'))
663
+						{
664
+							// only executable by group
604 665
 						{
605 666
 							$group = posix_getgrgid(filegroup($this->$name));
667
+						}
606 668
 							$webserver = posix_getpwuid(posix_getuid ());
607 669
 							echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n";							}
608 670
 					}
@@ -622,10 +684,13 @@  discard block
 block discarded – undo
622 684
 				}
623 685
 				//echo "<p>$name = '".$this->$name."'</p>\n";
624 686
 			}
625
-			if ($this->php5[0] == '/')	// we found a php5 binary
687
+			if ($this->php5[0] == '/')
688
+			{
689
+				// we found a php5 binary
626 690
 			{
627 691
 				$this->php = $this->php5;
628 692
 			}
693
+			}
629 694
 		}
630 695
 	}
631 696
 
@@ -637,7 +702,8 @@  discard block
 block discarded – undo
637 702
 	 */
638 703
 	function installed()
639 704
 	{
640
-		if ($this->only_fallback) {
705
+		if ($this->only_fallback)
706
+		{
641 707
 			return 0;
642 708
 		}
643 709
 		$this->find_binarys();
@@ -654,7 +720,10 @@  discard block
 block discarded – undo
654 720
 			$n = 0;
655 721
 			while ($line = fgets($crontab,256))
656 722
 			{
657
-				if ($this->debug) echo 'line '.++$n.": $line<br>\n";
723
+				if ($this->debug)
724
+				{
725
+					echo 'line '.++$n.": $line<br>\n";
726
+				}
658 727
 				$parts = explode(' ',$line,6);
659 728
 
660 729
 				if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php'))
@@ -698,7 +767,8 @@  discard block
 block discarded – undo
698 767
 	 */
699 768
 	function install($times)
700 769
 	{
701
-		if ($this->only_fallback && $times !== False) {
770
+		if ($this->only_fallback && $times !== False)
771
+		{
702 772
 			return 0;
703 773
 		}
704 774
 		$this->installed();	// find other installed cronlines
Please login to merge, or discard this patch.