Completed
Pull Request — master (#43)
by Marcel
27:43
created
admin/inc/class.admin_export_groups_csv.inc.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	/**
20 20
 	 * Exports records as defined in $_definition
21 21
 	 *
22
-	 * @param egw_record $_definition
22
+	 * @param importexport_definition $_definition
23 23
 	 */
24 24
 	public function export( $_stream, importexport_definition $_definition) {
25 25
 		$options = $_definition->plugin_options;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * return html for options.
89 89
 	 * this way the plugin has all opportunities for options tab
90 90
 	 *
91
-	 * @return string html
91
+	 * @return boolean html
92 92
 	 */
93 93
 	public function get_options_etpl() {
94 94
 		return false;
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@
 block discarded – undo
81 81
 	}
82 82
 
83 83
 	public static function get_mimetype() {
84
-                return 'text/csv';
85
-        }
84
+				return 'text/csv';
85
+		}
86 86
 
87 87
 	/**
88 88
 	 * return html for options.
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param egw_record $_definition
23 23
 	 */
24
-	public function export( $_stream, importexport_definition $_definition) {
24
+	public function export($_stream, importexport_definition $_definition) {
25 25
 		$options = $_definition->plugin_options;
26 26
 
27 27
 		$query = array(
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
 		// $_record is an array, that's what search() returns
41 41
 		foreach ($selection as $_record) {
42 42
 			$record = new admin_egw_group_record($_record);
43
-			if($options['convert']) {
43
+			if ($options['convert']) {
44 44
 				importexport_export_csv::convert($record, admin_egw_group_record::$types, 'admin', $lookups);
45 45
 			} else {
46 46
 				// Implode arrays, so they don't say 'Array'
47
-				foreach($record->get_record_array() as $key => $value) {
48
-					if(is_array($value)) $record->$key = implode(',', $value);
47
+				foreach ($record->get_record_array() as $key => $value) {
48
+					if (is_array($value)) $record->$key = implode(',', $value);
49 49
 				}
50 50
  			}
51 51
 			$export_object->export_record($record);
Please login to merge, or discard this patch.
Braces   +27 added lines, -12 removed lines patch added patch discarded remove patch
@@ -21,7 +21,8 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param egw_record $_definition
23 23
 	 */
24
-	public function export( $_stream, importexport_definition $_definition) {
24
+	public function export( $_stream, importexport_definition $_definition)
25
+	{
25 26
 		$options = $_definition->plugin_options;
26 27
 
27 28
 		$query = array(
@@ -38,14 +39,22 @@  discard block
 block discarded – undo
38 39
 		);
39 40
 
40 41
 		// $_record is an array, that's what search() returns
41
-		foreach ($selection as $_record) {
42
+		foreach ($selection as $_record)
43
+		{
42 44
 			$record = new admin_egw_group_record($_record);
43
-			if($options['convert']) {
45
+			if($options['convert'])
46
+			{
44 47
 				importexport_export_csv::convert($record, admin_egw_group_record::$types, 'admin', $lookups);
45
-			} else {
48
+			}
49
+			else
50
+			{
46 51
 				// Implode arrays, so they don't say 'Array'
47
-				foreach($record->get_record_array() as $key => $value) {
48
-					if(is_array($value)) $record->$key = implode(',', $value);
52
+				foreach($record->get_record_array() as $key => $value)
53
+				{
54
+					if(is_array($value))
55
+					{
56
+						$record->$key = implode(',', $value);
57
+					}
49 58
 				}
50 59
  			}
51 60
 			$export_object->export_record($record);
@@ -58,7 +67,8 @@  discard block
 block discarded – undo
58 67
 	 *
59 68
 	 * @return string name
60 69
 	 */
61
-	public static function get_name() {
70
+	public static function get_name()
71
+	{
62 72
 		return lang('Group CSV export');
63 73
 	}
64 74
 
@@ -67,7 +77,8 @@  discard block
 block discarded – undo
67 77
 	 *
68 78
 	 * @return string descriprion
69 79
 	 */
70
-	public static function get_description() {
80
+	public static function get_description()
81
+	{
71 82
 		return lang("Exports groups into a CSV File. ");
72 83
 	}
73 84
 
@@ -76,11 +87,13 @@  discard block
 block discarded – undo
76 87
 	 *
77 88
 	 * @return string suffix
78 89
 	 */
79
-	public static function get_filesuffix() {
90
+	public static function get_filesuffix()
91
+	{
80 92
 		return 'csv';
81 93
 	}
82 94
 
83
-	public static function get_mimetype() {
95
+	public static function get_mimetype()
96
+	{
84 97
                 return 'text/csv';
85 98
         }
86 99
 
@@ -90,7 +103,8 @@  discard block
 block discarded – undo
90 103
 	 *
91 104
 	 * @return string html
92 105
 	 */
93
-	public function get_options_etpl() {
106
+	public function get_options_etpl()
107
+	{
94 108
 		return false;
95 109
 	}
96 110
 
@@ -98,7 +112,8 @@  discard block
 block discarded – undo
98 112
 	 * returns slectors of this plugin via xajax
99 113
 	 *
100 114
 	 */
101
-	public function get_selectors_etpl() {
115
+	public function get_selectors_etpl()
116
+	{
102 117
 		return array(
103 118
 			'preserv' => array('no_error_for_no_selection'),
104 119
 		);
Please login to merge, or discard this patch.
admin/inc/class.admin_import_groups_csv.inc.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,8 +77,7 @@
 block discarded – undo
77 77
 	/**
78 78
 	 * imports entries according to given definition object.
79 79
 	 * @param resource $_stream
80
-	 * @param string $_charset
81
-	 * @param definition $_definition
80
+	 * @param importexport_definition $_definition
82 81
 	 */
83 82
 	public function import( $_stream, importexport_definition $_definition ) {
84 83
 		$import_csv = new importexport_import_csv( $_stream, array(
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -15,15 +15,15 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * class import_csv for admin (groups)
17 17
  */
18
-class admin_import_groups_csv implements importexport_iface_import_plugin  {
18
+class admin_import_groups_csv implements importexport_iface_import_plugin {
19 19
 
20 20
 	private static $plugin_options = array(
21
-		'fieldsep', 		// char
22
-		'charset', 		// string
21
+		'fieldsep', // char
22
+		'charset', // string
23 23
 		'num_header_lines', // int number of header lines
24 24
 		'field_conversion', // array( $csv_col_num => conversion)
25
-		'field_mapping',	// array( $csv_col_num => adb_filed)
26
-		'conditions',		/* => array containing condition arrays:
25
+		'field_mapping', // array( $csv_col_num => adb_filed)
26
+		'conditions', /* => array containing condition arrays:
27 27
 				'type' => exists, // exists
28 28
 				'string' => '#kundennummer',
29 29
 				'true' => array(
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
 	/**
41 41
 	 * actions which could be done to data entries
42 42
 	 */
43
-	protected static $actions = array( 'none', 'update', 'create', 'delete');
43
+	protected static $actions = array('none', 'update', 'create', 'delete');
44 44
 
45 45
 	/**
46 46
 	 * conditions for actions
47 47
 	 *
48 48
 	 * @var array
49 49
 	 */
50
-	protected static $conditions = array( 'exists' );
50
+	protected static $conditions = array('exists');
51 51
 
52 52
 	/**
53 53
 	 * @var definition
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 	 * @param string $_charset
81 81
 	 * @param definition $_definition
82 82
 	 */
83
-	public function import( $_stream, importexport_definition $_definition ) {
84
-		$import_csv = new importexport_import_csv( $_stream, array(
83
+	public function import($_stream, importexport_definition $_definition) {
84
+		$import_csv = new importexport_import_csv($_stream, array(
85 85
 			'fieldsep' => $_definition->plugin_options['fieldsep'],
86 86
 			'charset' => $_definition->plugin_options['charset'],
87 87
 		));
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		$this->definition = $_definition;
90 90
 
91 91
 		// dry run?
92
-		$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] :  false;
92
+		$this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false;
93 93
 
94 94
 		// set FieldMapping.
95 95
 		$import_csv->mapping = $_definition->plugin_options['field_mapping'];
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 		$import_csv->conversion = $_definition->plugin_options['field_conversion'];
99 99
 
100 100
 		//check if file has a header lines
101
-		if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
101
+		if (isset($_definition->plugin_options['num_header_lines']) && $_definition->plugin_options['num_header_lines'] > 0) {
102 102
 			$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
103
-		} elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
103
+		} elseif (isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
104 104
 			// First method is preferred
105 105
 			$import_csv->skip_records(1);
106 106
 		}
@@ -112,22 +112,22 @@  discard block
 block discarded – undo
112 112
 		// Failures
113 113
 		$this->errors = array();
114 114
 
115
-		while ( $record = $import_csv->get_record() ) {
115
+		while ($record = $import_csv->get_record()) {
116 116
 			$success = false;
117 117
 			// don't import empty records
118
-			if( count( array_unique( $record ) ) < 2 ) continue;
118
+			if (count(array_unique($record)) < 2) continue;
119 119
 
120 120
 			importexport_import_csv::convert($record, admin_egw_group_record::$types, 'admin');
121 121
 
122
-			if ( $_definition->plugin_options['conditions'] ) {
123
-				foreach ( $_definition->plugin_options['conditions'] as $condition ) {
124
-					switch ( $condition['type'] ) {
122
+			if ($_definition->plugin_options['conditions']) {
123
+				foreach ($_definition->plugin_options['conditions'] as $condition) {
124
+					switch ($condition['type']) {
125 125
 						// exists
126 126
 						case 'exists' :
127 127
 							$accounts = array();
128 128
 
129 129
 							// Skip the search if the field is empty
130
-							if($record[$condition['string']] !== '') {
130
+							if ($record[$condition['string']] !== '') {
131 131
 
132 132
 								$accounts = $GLOBALS['egw']->accounts->search(array(
133 133
 									'type' => 'groups',
@@ -136,25 +136,25 @@  discard block
 block discarded – undo
136 136
 								));
137 137
 							}
138 138
 							// Search looks in the given field, but doesn't do an exact match
139
-							foreach ( (array)$accounts as $key => $account )
139
+							foreach ((array)$accounts as $key => $account)
140 140
 							{
141
-								if($account[$condition['string']] != $record[$condition['string']]) unset($accounts[$key]);
141
+								if ($account[$condition['string']] != $record[$condition['string']]) unset($accounts[$key]);
142 142
 							}
143
-							if ( is_array( $accounts ) && count( $accounts ) >= 1 ) {
143
+							if (is_array($accounts) && count($accounts) >= 1) {
144 144
 								$account = current($accounts);
145 145
 								// apply action to all contacts matching this exists condition
146 146
 								$action = $condition['true'];
147
-								foreach ( (array)$accounts as $account ) {
147
+								foreach ((array)$accounts as $account) {
148 148
 									// Read full account, and copy needed info for accounts->save()
149 149
 									$account = $GLOBALS['egw']->accounts->read($account['account_id']);
150 150
 									$record['account_id'] = $account['account_id'];
151 151
 									$record['account_firstname'] = $account['account_firstname'];
152 152
 									$record['account_lastname'] = $account['account_lastname'];
153
-									$success = $this->action(  $action['action'], $record, $import_csv->get_current_position() );
153
+									$success = $this->action($action['action'], $record, $import_csv->get_current_position());
154 154
 								}
155 155
 							} else {
156 156
 								$action = $condition['false'];
157
-								$success = ($this->action(  $action['action'], $record, $import_csv->get_current_position() ));
157
+								$success = ($this->action($action['action'], $record, $import_csv->get_current_position()));
158 158
 							}
159 159
 							break;
160 160
 
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
 				}
168 168
 			} else {
169 169
 				// unconditional insert
170
-				$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
170
+				$success = $this->action('insert', $record, $import_csv->get_current_position());
171 171
 			}
172
-			if($success) $count++;
172
+			if ($success) $count++;
173 173
 		}
174 174
 		return $count;
175 175
 	}
@@ -181,18 +181,18 @@  discard block
 block discarded – undo
181 181
 	 * @param array $_data contact data for the action
182 182
 	 * @return bool success or not
183 183
 	 */
184
-	private function action ( $_action, $_data, $record_num = 0 ) {
184
+	private function action($_action, $_data, $record_num = 0) {
185 185
 		switch ($_action) {
186 186
 			case 'none' :
187 187
 				return true;
188 188
 			case 'update' :
189 189
 			case 'create' :
190
-				if(count($_data['account_members']) < 1) {
190
+				if (count($_data['account_members']) < 1) {
191 191
 					$this->errors[$record_num] = lang('You must select at least one group member.');
192 192
 					return false;
193 193
 				}
194 194
 				$command = new admin_cmd_edit_group($_action == 'create' ? false : $_data['account_lid'], $_data);
195
-				if($this->dry_run) {
195
+				if ($this->dry_run) {
196 196
 					$this->results[$_action]++;
197 197
 					return true;
198 198
 				}
Please login to merge, or discard this patch.
Braces   +71 added lines, -30 removed lines patch added patch discarded remove patch
@@ -15,7 +15,8 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * class import_csv for admin (groups)
17 17
  */
18
-class admin_import_groups_csv implements importexport_iface_import_plugin  {
18
+class admin_import_groups_csv implements importexport_iface_import_plugin
19
+{
19 20
 
20 21
 	private static $plugin_options = array(
21 22
 		'fieldsep', 		// char
@@ -80,7 +81,8 @@  discard block
 block discarded – undo
80 81
 	 * @param string $_charset
81 82
 	 * @param definition $_definition
82 83
 	 */
83
-	public function import( $_stream, importexport_definition $_definition ) {
84
+	public function import( $_stream, importexport_definition $_definition )
85
+	{
84 86
 		$import_csv = new importexport_import_csv( $_stream, array(
85 87
 			'fieldsep' => $_definition->plugin_options['fieldsep'],
86 88
 			'charset' => $_definition->plugin_options['charset'],
@@ -98,9 +100,12 @@  discard block
 block discarded – undo
98 100
 		$import_csv->conversion = $_definition->plugin_options['field_conversion'];
99 101
 
100 102
 		//check if file has a header lines
101
-		if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
103
+		if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0)
104
+		{
102 105
 			$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
103
-		} elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
106
+		}
107
+		elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line'])
108
+		{
104 109
 			// First method is preferred
105 110
 			$import_csv->skip_records(1);
106 111
 		}
@@ -112,22 +117,30 @@  discard block
 block discarded – undo
112 117
 		// Failures
113 118
 		$this->errors = array();
114 119
 
115
-		while ( $record = $import_csv->get_record() ) {
120
+		while ( $record = $import_csv->get_record() )
121
+		{
116 122
 			$success = false;
117 123
 			// don't import empty records
118
-			if( count( array_unique( $record ) ) < 2 ) continue;
124
+			if( count( array_unique( $record ) ) < 2 )
125
+			{
126
+				continue;
127
+			}
119 128
 
120 129
 			importexport_import_csv::convert($record, admin_egw_group_record::$types, 'admin');
121 130
 
122
-			if ( $_definition->plugin_options['conditions'] ) {
123
-				foreach ( $_definition->plugin_options['conditions'] as $condition ) {
124
-					switch ( $condition['type'] ) {
131
+			if ( $_definition->plugin_options['conditions'] )
132
+			{
133
+				foreach ( $_definition->plugin_options['conditions'] as $condition )
134
+				{
135
+					switch ( $condition['type'] )
136
+					{
125 137
 						// exists
126 138
 						case 'exists' :
127 139
 							$accounts = array();
128 140
 
129 141
 							// Skip the search if the field is empty
130
-							if($record[$condition['string']] !== '') {
142
+							if($record[$condition['string']] !== '')
143
+							{
131 144
 
132 145
 								$accounts = $GLOBALS['egw']->accounts->search(array(
133 146
 									'type' => 'groups',
@@ -138,13 +151,18 @@  discard block
 block discarded – undo
138 151
 							// Search looks in the given field, but doesn't do an exact match
139 152
 							foreach ( (array)$accounts as $key => $account )
140 153
 							{
141
-								if($account[$condition['string']] != $record[$condition['string']]) unset($accounts[$key]);
154
+								if($account[$condition['string']] != $record[$condition['string']])
155
+								{
156
+									unset($accounts[$key]);
157
+								}
142 158
 							}
143
-							if ( is_array( $accounts ) && count( $accounts ) >= 1 ) {
159
+							if ( is_array( $accounts ) && count( $accounts ) >= 1 )
160
+							{
144 161
 								$account = current($accounts);
145 162
 								// apply action to all contacts matching this exists condition
146 163
 								$action = $condition['true'];
147
-								foreach ( (array)$accounts as $account ) {
164
+								foreach ( (array)$accounts as $account )
165
+								{
148 166
 									// Read full account, and copy needed info for accounts->save()
149 167
 									$account = $GLOBALS['egw']->accounts->read($account['account_id']);
150 168
 									$record['account_id'] = $account['account_id'];
@@ -152,7 +170,9 @@  discard block
 block discarded – undo
152 170
 									$record['account_lastname'] = $account['account_lastname'];
153 171
 									$success = $this->action(  $action['action'], $record, $import_csv->get_current_position() );
154 172
 								}
155
-							} else {
173
+							}
174
+							else
175
+							{
156 176
 								$action = $condition['false'];
157 177
 								$success = ($this->action(  $action['action'], $record, $import_csv->get_current_position() ));
158 178
 							}
@@ -162,13 +182,21 @@  discard block
 block discarded – undo
162 182
 						default :
163 183
 							die('condition / action not supported!!!');
164 184
 					}
165
-					if ($action['last']) break;
185
+					if ($action['last'])
186
+					{
187
+						break;
188
+					}
166 189
 				}
167
-			} else {
190
+			}
191
+			else
192
+			{
168 193
 				// unconditional insert
169 194
 				$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
170 195
 			}
171
-			if($success) $count++;
196
+			if($success)
197
+			{
198
+				$count++;
199
+			}
172 200
 		}
173 201
 		return $count;
174 202
 	}
@@ -180,24 +208,29 @@  discard block
 block discarded – undo
180 208
 	 * @param array $_data contact data for the action
181 209
 	 * @return bool success or not
182 210
 	 */
183
-	private function action ( $_action, $_data, $record_num = 0 ) {
184
-		switch ($_action) {
211
+	private function action ( $_action, $_data, $record_num = 0 )
212
+	{
213
+		switch ($_action)
214
+		{
185 215
 			case 'none' :
186 216
 				return true;
187 217
 			case 'update' :
188 218
 			case 'create' :
189
-				if(count($_data['account_members']) < 1) {
219
+				if(count($_data['account_members']) < 1)
220
+				{
190 221
 					$this->errors[$record_num] = lang('You must select at least one group member.');
191 222
 					return false;
192 223
 				}
193 224
 				$command = new admin_cmd_edit_group($_action == 'create' ? false : $_data['account_lid'], $_data);
194
-				if($this->dry_run) {
225
+				if($this->dry_run)
226
+				{
195 227
 					$this->results[$_action]++;
196 228
 					return true;
197 229
 				}
198 230
 				try {
199 231
 					$command->run();
200
-				} catch (Exception $e) {
232
+				}
233
+				catch (Exception $e) {
201 234
 					$this->errors[$record_num] = $e->getMessage();
202 235
 					return false;
203 236
 				}
@@ -214,7 +247,8 @@  discard block
 block discarded – undo
214 247
 	 *
215 248
 	 * @return string name
216 249
 	 */
217
-	public static function get_name() {
250
+	public static function get_name()
251
+	{
218 252
 		return lang('Group CSV import');
219 253
 	}
220 254
 
@@ -223,7 +257,8 @@  discard block
 block discarded – undo
223 257
 	 *
224 258
 	 * @return string descriprion
225 259
 	 */
226
-	public static function get_description() {
260
+	public static function get_description()
261
+	{
227 262
 		return lang("Creates / updates user groups from CSV file");
228 263
 	}
229 264
 
@@ -232,7 +267,8 @@  discard block
 block discarded – undo
232 267
 	 *
233 268
 	 * @return string suffix (comma seperated)
234 269
 	 */
235
-	public static function get_filesuffix() {
270
+	public static function get_filesuffix()
271
+	{
236 272
 		return 'csv';
237 273
 	}
238 274
 
@@ -248,7 +284,8 @@  discard block
 block discarded – undo
248 284
 	 * 		preserv		=> array,
249 285
 	 * )
250 286
 	 */
251
-	public function get_options_etpl() {
287
+	public function get_options_etpl()
288
+	{
252 289
 		// lets do it!
253 290
 	}
254 291
 
@@ -257,7 +294,8 @@  discard block
 block discarded – undo
257 294
 	 *
258 295
 	 * @return string etemplate name
259 296
 	 */
260
-	public function get_selectors_etpl() {
297
+	public function get_selectors_etpl()
298
+	{
261 299
 		// lets do it!
262 300
 	}
263 301
 
@@ -269,7 +307,8 @@  discard block
 block discarded – undo
269 307
 	 *       record_# => warning message
270 308
 	 * )
271 309
 	 */
272
-	public function get_warnings() {
310
+	public function get_warnings()
311
+	{
273 312
 		return $this->warnings;
274 313
 	}
275 314
 
@@ -281,7 +320,8 @@  discard block
 block discarded – undo
281 320
 	 *       record_# => error message
282 321
 	 * )
283 322
 	 */
284
-	public function get_errors() {
323
+	public function get_errors()
324
+	{
285 325
 		return $this->errors;
286 326
 	}
287 327
 
@@ -293,7 +333,8 @@  discard block
 block discarded – undo
293 333
 	 *       action => record count
294 334
 	 * )
295 335
 	 */
296
-	public function get_results() {
336
+	public function get_results()
337
+	{
297 338
 		return $this->results;
298 339
 	}
299 340
 }
Please login to merge, or discard this patch.
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   +38 added lines, -42 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
 		{
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		//$content['msg'] = 'Hi Ralf ;-)';
76 76
 		$sel_options['tree'] = $this->tree_data();
77 77
 		$sel_options['filter'] = array('' => lang('All groups'));
78
-		foreach(self::$accounts->search(array(
78
+		foreach (self::$accounts->search(array(
79 79
 			'type' => 'groups',
80 80
 			'start' => false,
81 81
 			'order' => 'account_lid',
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		}
106 106
 		else
107 107
 		{
108
-			$content['iframe'] = 'about:blank';	// we show accounts-list be default now
108
+			$content['iframe'] = 'about:blank'; // we show accounts-list be default now
109 109
 		}
110 110
 
111 111
 		$tpl->exec('admin.admin_ui.index', $content, $sel_options);
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	{
121 121
 		$actions = static::group_actions();
122 122
 
123
-		foreach($actions as $action_id =>  &$action)
123
+		foreach ($actions as $action_id =>  &$action)
124 124
 		{
125 125
 			if (!isset($action['enableId']) && !in_array($action_id, array('add')))
126 126
 			{
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 					'default' => true,
149 149
 					'allowOnMultiple' => false,
150 150
 					'onExecute' => 'javaScript:app.admin.account',
151
-					'group' => $group=0,
151
+					'group' => $group = 0,
152 152
 				),
153 153
 				'add' => array(
154 154
 					'caption' => 'Add user',
@@ -159,25 +159,25 @@  discard block
 block discarded – undo
159 159
 			// generate urls for add/edit accounts via addressbook
160 160
 			$edit = Link::get_registry('addressbook', 'edit');
161 161
 			$edit['account_id'] = '$id';
162
-			foreach($edit as $name => $val)
162
+			foreach ($edit as $name => $val)
163 163
 			{
164 164
 				$actions['edit']['url'] .= ($actions['edit']['url'] ? '&' : '').$name.'='.$val;
165 165
 			}
166 166
 			unset($edit['account_id']);
167 167
 			$edit['owner'] = 0;
168
-			foreach($edit as $name => $val)
168
+			foreach ($edit as $name => $val)
169 169
 			{
170 170
 				$actions['add']['url'] .= ($actions['edit']['url'] ? '&' : '').$name.'='.$val;
171 171
 			}
172 172
 			++$group;
173 173
 			// supporting both old way using $GLOBALS['menuData'] and new just returning data in hook
174 174
 			$apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_user')));
175
-			foreach($apps as $app)
175
+			foreach ($apps as $app)
176 176
 			{
177 177
 				$GLOBALS['menuData'] = $data = array();
178 178
 				$data = Api\Hooks::single('edit_user', $app);
179 179
 				if (!is_array($data)) $data = $GLOBALS['menuData'];
180
-				foreach($data as $item)
180
+				foreach ($data as $item)
181 181
 				{
182 182
 					// allow hook to return "real" actions, but still support legacy: description, url, extradata, options
183 183
 					if (empty($item['caption']))
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
 				'onExecute' => 'javaScript:app.admin.group',
233 233
 				'caption' => 'Show members',
234 234
 				'default' => true,
235
-				'group' => $group=1,
235
+				'group' => $group = 1,
236 236
 				'allowOnMultiple' => false
237 237
 			),
238 238
 			'add' => array(
239 239
 				'group' => $group,
240
-			)+$user_actions['add'],
240
+			) + $user_actions['add'],
241 241
 			'acl' => array(
242 242
 				'onExecute' => 'javaScript:app.admin.group',
243 243
 				'caption' => 'Access control',
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 				'allowOnMultiple' => false
249 249
 			),
250 250
 		);
251
-		if (!$GLOBALS['egw']->acl->check('account_access',64,'admin'))	// no rights to set ACL-rights
251
+		if (!$GLOBALS['egw']->acl->check('account_access', 64, 'admin'))	// no rights to set ACL-rights
252 252
 		{
253 253
 			$actions['deny'] = array(
254 254
 				'caption'   => 'Deny access',
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
 			);
261 261
 		}
262 262
 
263
-		$group = 5;	// allow to place actions in different groups by hook, this is the default
263
+		$group = 5; // allow to place actions in different groups by hook, this is the default
264 264
 
265 265
 		// supporting both old way using $GLOBALS['menuData'] and new just returning data in hook
266 266
 		$apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_group')));
267
-		foreach($apps as $app)
267
+		foreach ($apps as $app)
268 268
 		{
269 269
 			$GLOBALS['menuData'] = $data = array();
270 270
 			$data = Api\Hooks::single('edit_group', $app);
271 271
 			if (!is_array($data)) $data = $GLOBALS['menuData'];
272 272
 
273
-			foreach($data as $item)
273
+			foreach ($data as $item)
274 274
 			{
275 275
 				// allow hook to return "real" actions, but still support legacy: description, url, extradata, options
276 276
 				if (empty($item['caption']))
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	 * @param array &$rows=null
311 311
 	 * @return int total number of rows available
312 312
 	 */
313
-	public static function get_users(array $query, array &$rows=null)
313
+	public static function get_users(array $query, array &$rows = null)
314 314
 	{
315 315
 		$params = array(
316 316
 			'type' => (int)$query['filter'] ? (int)$query['filter'] : 'accounts',
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 			$params['query'] = $query['searchletter'];
326 326
 			$params['query_type'] = 'start';
327 327
 		}
328
-		elseif($query['search'])
328
+		elseif ($query['search'])
329 329
 		{
330 330
 			$params['query'] = $query['search'];
331 331
 			$params['query_type'] = 'all';
@@ -334,13 +334,10 @@  discard block
 block discarded – undo
334 334
 		$rows = array_values(self::$accounts->search($params));
335 335
 		//error_log(__METHOD__."() accounts->search(".array2string($params).") total=".self::$accounts->total);
336 336
 
337
-		foreach($rows as &$row)
337
+		foreach ($rows as &$row)
338 338
 		{
339 339
 			$row['status'] = self::$accounts->is_expired($row) ?
340
-				lang('Expired').' '.Api\DateTime::to($row['account_expires'], true) :
341
-					(!self::$accounts->is_active($row) ? lang('Disabled') :
342
-						($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) :
343
-							lang('Enabled')));
340
+				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')));
344 341
 
345 342
 			if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive';
346 343
 		}
@@ -362,29 +359,29 @@  discard block
 block discarded – undo
362 359
 			));
363 360
 
364 361
 		$apps = array();
365
-		foreach($GLOBALS['egw_info']['apps'] as $app => $data)
362
+		foreach ($GLOBALS['egw_info']['apps'] as $app => $data)
366 363
 		{
367 364
 			if (!$data['enabled'] || !$data['status'] || $data['status'] == 3)
368 365
 			{
369
-				continue;	// do NOT show disabled apps, or our API (status = 3)
366
+				continue; // do NOT show disabled apps, or our API (status = 3)
370 367
 			}
371 368
 
372 369
 			$apps[] = $app;
373 370
 		}
374 371
 
375 372
 		$rows = array();
376
-		foreach($groups as &$group)
373
+		foreach ($groups as &$group)
377 374
 		{
378 375
 			$run_rights = $GLOBALS['egw']->acl->get_user_applications($group['account_id'], false, false);
379
-			foreach($apps as $app)
376
+			foreach ($apps as $app)
380 377
 			{
381
-				if((boolean)$run_rights[$app])
378
+				if ((boolean)$run_rights[$app])
382 379
 				{
383 380
 					$group['apps'][] = $app;
384 381
 				}
385 382
 			}
386 383
 
387
-			$group['members'] = $GLOBALS['egw']->accounts->members($group['account_id'],true);
384
+			$group['members'] = $GLOBALS['egw']->accounts->members($group['account_id'], true);
388 385
 			$rows[] = $group;
389 386
 		}
390 387
 
@@ -424,14 +421,14 @@  discard block
 block discarded – undo
424 421
 		if ($root == '/')
425 422
 		{
426 423
 			$hook_data = self::call_hook();
427
-			foreach($hook_data as $app => $app_data)
424
+			foreach ($hook_data as $app => $app_data)
428 425
 			{
429
-				if(!is_array($app_data))
426
+				if (!is_array($app_data))
430 427
 				{
431 428
 					// Application has no data
432 429
 					continue;
433 430
 				}
434
-				foreach($app_data as $text => $data)
431
+				foreach ($app_data as $text => $data)
435 432
 				{
436 433
 					if (!is_array($data))
437 434
 					{
@@ -462,18 +459,17 @@  discard block
 block discarded – undo
462 459
 						}
463 460
 					}
464 461
 					unset($data['icon']);
465
-					$parent =& $tree['item'];
462
+					$parent = & $tree['item'];
466 463
 					$parts = explode('/', $data['id']);
467
-					if ($data['id'][0] == '/') array_shift($parts);	// remove root
464
+					if ($data['id'][0] == '/') array_shift($parts); // remove root
468 465
 					array_pop($parts);
469 466
 					$path = '';
470
-					foreach($parts as $part)
467
+					foreach ($parts as $part)
471 468
 					{
472 469
 						$path .= ($path == '/' ? '' : '/').$part;
473 470
 						if (!isset($parent[$path]))
474 471
 						{
475
-							$icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') :
476
-								(($i=Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav')));
472
+							$icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') : (($i = Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav')));
477 473
 							$parent[$path] = array(
478 474
 								'id' => $path,
479 475
 								'text' => $part == 'apps' ? lang('Applications') : lang($part),
@@ -485,7 +481,7 @@  discard block
 block discarded – undo
485 481
 							);
486 482
 							if ($path == '/admin') $parent[$path]['open'] = true;
487 483
 						}
488
-						$parent =& $parent[$path]['item'];
484
+						$parent = & $parent[$path]['item'];
489 485
 					}
490 486
 					$data['text'] = lang($data['text']);
491 487
 					if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']);
@@ -497,7 +493,7 @@  discard block
 block discarded – undo
497 493
 		}
498 494
 		elseif ($root == '/groups')
499 495
 		{
500
-			foreach($GLOBALS['egw']->accounts->search(array(
496
+			foreach ($GLOBALS['egw']->accounts->search(array(
501 497
 				'type' => 'groups',
502 498
 				'order' => 'account_lid',
503 499
 				'sort' => 'ASC',
@@ -524,8 +520,8 @@  discard block
 block discarded – undo
524 520
 	private static function fix_userdata(array $data)
525 521
 	{
526 522
 		// store link as userdata, maybe we should store everything not directly understood by tree this way ...
527
-		foreach(array_diff_key($data, array_flip(array(
528
-			'id','text','tooltip','im0','im1','im2','item','child','select','open','call',
523
+		foreach (array_diff_key($data, array_flip(array(
524
+			'id', 'text', 'tooltip', 'im0', 'im1', 'im2', 'item', 'child', 'select', 'open', 'call',
529 525
 		))) as $name => $content)
530 526
 		{
531 527
 			$data['userdata'][] = array(
@@ -545,7 +541,7 @@  discard block
 block discarded – undo
545 541
 	private static function strip_item_keys(array &$items)
546 542
 	{
547 543
 		$items = array_values($items);
548
-		foreach($items as &$item)
544
+		foreach ($items as &$item)
549 545
 		{
550 546
 			if (is_array($item) && isset($item['item']))
551 547
 			{
@@ -563,7 +559,7 @@  discard block
 block discarded – undo
563 559
 	protected static function call_hook()
564 560
 	{
565 561
 		self::$hook_data = array();
566
-		function display_section($appname,$file,$file2=False)
562
+		function display_section($appname, $file, $file2 = False)
567 563
 		{
568 564
 			admin_ui::$hook_data[$appname] = $file2 ? $file2 : $file;
569 565
 			//error_log(__METHOD__."(".array2string(func_get_args()).")");
Please login to merge, or discard this patch.
Braces   +81 added lines, -20 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,
@@ -176,7 +179,10 @@  discard block
 block discarded – undo
176 179
 			{
177 180
 				$GLOBALS['menuData'] = $data = array();
178 181
 				$data = Api\Hooks::single('edit_user', $app);
179
-				if (!is_array($data)) $data = $GLOBALS['menuData'];
182
+				if (!is_array($data))
183
+				{
184
+					$data = $GLOBALS['menuData'];
185
+				}
180 186
 				foreach($data as $item)
181 187
 				{
182 188
 					// allow hook to return "real" actions, but still support legacy: description, url, extradata, options
@@ -194,15 +200,30 @@  discard block
 block discarded – undo
194 200
 						if ($item['options'] && preg_match('/(egw_openWindowCentered2?|window.open)\([^)]+,(\d+),(\d+).*(title="([^"]+)")?/', $item['options'], $matches))
195 201
 						{
196 202
 							$item['popup'] = $matches[2].'x'.$matches[3];
197
-							if (isset($matches[5])) $item['tooltip'] = $matches[5];
203
+							if (isset($matches[5]))
204
+							{
205
+								$item['tooltip'] = $matches[5];
206
+							}
198 207
 							unset($item['options']);
199 208
 						}
200 209
 					}
201
-					if (empty($item['icon'])) $item['icon'] = $app.'/navbar';
202
-					if (empty($item['group'])) $item['group'] = $group;
203
-					if (empty($item['onExecute'])) $item['onExecute'] = $item['popup'] ?
210
+					if (empty($item['icon']))
211
+					{
212
+						$item['icon'] = $app.'/navbar';
213
+					}
214
+					if (empty($item['group']))
215
+					{
216
+						$item['group'] = $group;
217
+					}
218
+					if (empty($item['onExecute']))
219
+					{
220
+						$item['onExecute'] = $item['popup'] ?
204 221
 						'javaScript:nm_action' : 'javaScript:app.admin.iframe_location';
205
-					if (!isset($item['allowOnMultiple'])) $item['allowOnMultiple'] = false;
222
+					}
223
+					if (!isset($item['allowOnMultiple']))
224
+					{
225
+						$item['allowOnMultiple'] = false;
226
+					}
206 227
 
207 228
 					$actions[$item['id']] = $item;
208 229
 				}
@@ -248,7 +269,9 @@  discard block
 block discarded – undo
248 269
 				'allowOnMultiple' => false
249 270
 			),
250 271
 		);
251
-		if (!$GLOBALS['egw']->acl->check('account_access',64,'admin'))	// no rights to set ACL-rights
272
+		if (!$GLOBALS['egw']->acl->check('account_access',64,'admin'))
273
+		{
274
+			// no rights to set ACL-rights
252 275
 		{
253 276
 			$actions['deny'] = array(
254 277
 				'caption'   => 'Deny access',
@@ -259,6 +282,7 @@  discard block
 block discarded – undo
259 282
 				'allowOnMultiple' => false
260 283
 			);
261 284
 		}
285
+		}
262 286
 
263 287
 		$group = 5;	// allow to place actions in different groups by hook, this is the default
264 288
 
@@ -268,7 +292,10 @@  discard block
 block discarded – undo
268 292
 		{
269 293
 			$GLOBALS['menuData'] = $data = array();
270 294
 			$data = Api\Hooks::single('edit_group', $app);
271
-			if (!is_array($data)) $data = $GLOBALS['menuData'];
295
+			if (!is_array($data))
296
+			{
297
+				$data = $GLOBALS['menuData'];
298
+			}
272 299
 
273 300
 			foreach($data as $item)
274 301
 			{
@@ -288,14 +315,29 @@  discard block
 block discarded – undo
288 315
 					{
289 316
 						$item['popup'] = $matches[2].'x'.$matches[3];
290 317
 						$item['onExecute'] = 'javaScript:nm_action';
291
-						if (isset($matches[5])) $item['tooltip'] = $matches[5];
318
+						if (isset($matches[5]))
319
+						{
320
+							$item['tooltip'] = $matches[5];
321
+						}
292 322
 						unset($item['options']);
293 323
 					}
294 324
 				}
295
-				if (empty($item['icon'])) $item['icon'] = $app.'/navbar';
296
-				if (empty($item['group'])) $item['group'] = $group;
297
-				if (empty($item['onExecute'])) $item['onExecute'] = 'javaScript:app.admin.group';
298
-				if (!isset($item['allowOnMultiple'])) $item['allowOnMultiple'] = false;
325
+				if (empty($item['icon']))
326
+				{
327
+					$item['icon'] = $app.'/navbar';
328
+				}
329
+				if (empty($item['group']))
330
+				{
331
+					$item['group'] = $group;
332
+				}
333
+				if (empty($item['onExecute']))
334
+				{
335
+					$item['onExecute'] = 'javaScript:app.admin.group';
336
+				}
337
+				if (!isset($item['allowOnMultiple']))
338
+				{
339
+					$item['allowOnMultiple'] = false;
340
+				}
299 341
 
300 342
 				$actions[$item['id']] = $item;
301 343
 			}
@@ -342,7 +384,10 @@  discard block
 block discarded – undo
342 384
 						($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) :
343 385
 							lang('Enabled')));
344 386
 
345
-			if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive';
387
+			if (!self::$accounts->is_active($row))
388
+			{
389
+				$row['status_class'] = 'adminAccountInactive';
390
+			}
346 391
 		}
347 392
 
348 393
 		return self::$accounts->total;
@@ -439,7 +484,10 @@  discard block
 block discarded – undo
439 484
 							'link' => $data,
440 485
 						);
441 486
 					}
442
-					if (empty($data['text'])) $data['text'] = $text;
487
+					if (empty($data['text']))
488
+					{
489
+						$data['text'] = $text;
490
+					}
443 491
 					if (empty($data['id']))
444 492
 					{
445 493
 						$data['id'] = $root.($app == 'admin' ? 'admin' : 'apps/'.$app).'/';
@@ -464,7 +512,11 @@  discard block
 block discarded – undo
464 512
 					unset($data['icon']);
465 513
 					$parent =& $tree['item'];
466 514
 					$parts = explode('/', $data['id']);
467
-					if ($data['id'][0] == '/') array_shift($parts);	// remove root
515
+					if ($data['id'][0] == '/')
516
+					{
517
+						array_shift($parts);
518
+					}
519
+					// remove root
468 520
 					array_pop($parts);
469 521
 					$path = '';
470 522
 					foreach($parts as $part)
@@ -483,14 +535,23 @@  discard block
 block discarded – undo
483 535
 								'item' => array(),
484 536
 								'child' => 1,
485 537
 							);
486
-							if ($path == '/admin') $parent[$path]['open'] = true;
538
+							if ($path == '/admin')
539
+							{
540
+								$parent[$path]['open'] = true;
541
+							}
487 542
 						}
488 543
 						$parent =& $parent[$path]['item'];
489 544
 					}
490 545
 					$data['text'] = lang($data['text']);
491
-					if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']);
546
+					if (!empty($data['tooltip']))
547
+					{
548
+						$data['tooltip'] = lang($data['tooltip']);
549
+					}
492 550
 					// make sure keys are unique, as we overwrite tree entries otherwise
493
-					if (isset($parent[$data['id']])) $data['id'] .= md5($data['link']);
551
+					if (isset($parent[$data['id']]))
552
+					{
553
+						$data['id'] .= md5($data['link']);
554
+					}
494 555
 					$parent[$data['id']] = self::fix_userdata($data);
495 556
 				}
496 557
 			}
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.
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.
Spacing   +139 added lines, -142 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:
@@ -725,7 +722,7 @@  discard block
 block discarded – undo
725 722
 					}
726 723
 				}
727 724
 				// add account_filter to filter (user has to be '*', as we otherwise only search uid's)
728
-				$filter .= str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$this->account_filter);
725
+				$filter .= str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $this->account_filter);
729 726
 				$filter .= ')';
730 727
 
731 728
 				if ($param['type'] != 'both')
@@ -744,9 +741,9 @@  discard block
 block discarded – undo
744 741
 						'account_fullname'  => 'cn',
745 742
 						'account_primary_group' => 'gidnumber',
746 743
 					);
747
-					$orders = explode(',',$param['order']);
744
+					$orders = explode(',', $param['order']);
748 745
 					$order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid';
749
-					$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid', $order));
746
+					$sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', $order));
750 747
 					$fullSet = array();
751 748
 					foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry)
752 749
 					{
@@ -756,7 +753,7 @@  discard block
 block discarded – undo
756 753
 					if (is_numeric($param['type'])) // return only group-members
757 754
 					{
758 755
 						$relevantAccounts = array();
759
-						$sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid'));
756
+						$sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=".abs($param['type'])."))", array('memberuid'));
760 757
 						$group = ldap_get_entries($this->ds, $sri);
761 758
 						$fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array();
762 759
 					}
@@ -765,26 +762,26 @@  discard block
 block discarded – undo
765 762
 					$sortFn = $param['sort'] == 'DESC' ? 'arsort' : 'asort';
766 763
 					$sortFn($fullSet);
767 764
 					$relevantAccounts = is_numeric($start) ? array_slice(array_keys($fullSet), $start, $offset) : array_keys($fullSet);
768
-					$filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')';
769
-					$filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter);
765
+					$filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=', $relevantAccounts).'))'.$this->account_filter.')';
766
+					$filter = str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $filter);
770 767
 				}
771
-				$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn',static::MAIL_ATTR,'shadowExpire','createtimestamp','modifytimestamp','objectclass','gidNumber'));
768
+				$sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', 'uidNumber', 'givenname', 'sn', static::MAIL_ATTR, 'shadowExpire', 'createtimestamp', 'modifytimestamp', 'objectclass', 'gidNumber'));
772 769
 
773 770
 				$utc_diff = date('Z');
774
-				foreach(ldap_get_entries($this->ds, $sri) as $allVals)
771
+				foreach (ldap_get_entries($this->ds, $sri) as $allVals)
775 772
 				{
776
-					settype($allVals,'array');
773
+					settype($allVals, 'array');
777 774
 					$test = @$allVals['uid'][0];
778 775
 					if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0])
779 776
 					{
780 777
 						$account = Array(
781 778
 							'account_id'        => $allVals['uidnumber'][0],
782
-							'account_lid'       => Api\Translation::convert($allVals['uid'][0],'utf-8'),
779
+							'account_lid'       => Api\Translation::convert($allVals['uid'][0], 'utf-8'),
783 780
 							'account_type'      => 'u',
784
-							'account_firstname' => Api\Translation::convert($allVals['givenname'][0],'utf-8'),
785
-							'account_lastname'  => Api\Translation::convert($allVals['sn'][0],'utf-8'),
786
-							'account_status'    => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A',
787
-							'account_expires'   => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC
781
+							'account_firstname' => Api\Translation::convert($allVals['givenname'][0], 'utf-8'),
782
+							'account_lastname'  => Api\Translation::convert($allVals['sn'][0], 'utf-8'),
783
+							'account_status'    => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0] * 24 * 3600 - $utc_diff < time() ? false : 'A',
784
+							'account_expires'   => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC
788 785
 							'account_email'     => $allVals[static::MAIL_ATTR][0],
789 786
 							'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null,
790 787
 							'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null,
@@ -810,13 +807,13 @@  discard block
 block discarded – undo
810 807
 			}
811 808
 			if ($param['type'] == 'groups' || $param['type'] == 'both')
812 809
 			{
813
-				if(empty($query) || $query == '*')
810
+				if (empty($query) || $query == '*')
814 811
 				{
815 812
 					$filter = '(objectclass=posixgroup)';
816 813
 				}
817 814
 				else
818 815
 				{
819
-					switch($param['query_type'])
816
+					switch ($param['query_type'])
820 817
 					{
821 818
 						case 'all':
822 819
 						default:
@@ -830,21 +827,21 @@  discard block
 block discarded – undo
830 827
 					}
831 828
 					$filter = "(&(objectclass=posixgroup)(cn=$query))";
832 829
 				}
833
-				$sri = ldap_search($this->ds, $this->group_context, $filter,array('cn','gidNumber'));
834
-				foreach((array)ldap_get_entries($this->ds, $sri) as $allVals)
830
+				$sri = ldap_search($this->ds, $this->group_context, $filter, array('cn', 'gidNumber'));
831
+				foreach ((array)ldap_get_entries($this->ds, $sri) as $allVals)
835 832
 				{
836
-					settype($allVals,'array');
833
+					settype($allVals, 'array');
837 834
 					$test = $allVals['cn'][0];
838 835
 					if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0])
839 836
 					{
840 837
 						$accounts[(string)-$allVals['gidnumber'][0]] = Array(
841 838
 							'account_id'        => -$allVals['gidnumber'][0],
842
-							'account_lid'       => Api\Translation::convert($allVals['cn'][0],'utf-8'),
839
+							'account_lid'       => Api\Translation::convert($allVals['cn'][0], 'utf-8'),
843 840
 							'account_type'      => 'g',
844
-							'account_firstname' => Api\Translation::convert($allVals['cn'][0],'utf-8'),
841
+							'account_firstname' => Api\Translation::convert($allVals['cn'][0], 'utf-8'),
845 842
 							'account_lastname'  => lang('Group'),
846 843
 							'account_status'    => 'A',
847
-							'account_fullname'  => Api\Translation::convert($allVals['cn'][0],'utf-8'),
844
+							'account_fullname'  => Api\Translation::convert($allVals['cn'][0], 'utf-8'),
848 845
 						);
849 846
 						if (isset($totalcount)) ++$totalcount;
850 847
 					}
@@ -852,13 +849,13 @@  discard block
 block discarded – undo
852 849
 			}
853 850
 			// sort the array
854 851
 			$this->_callback_sort = strtoupper($param['sort']);
855
-			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']);
856
-			foreach($this->_callback_order as &$col)
852
+			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']);
853
+			foreach ($this->_callback_order as &$col)
857 854
 			{
858 855
 				if (substr($col, 0, 8) !== 'account_') $col = 'account_'.$col;
859 856
 			}
860 857
 			$sortedAccounts = $accounts;
861
-			uasort($sortedAccounts,array($this,'_sort_callback'));
858
+			uasort($sortedAccounts, array($this, '_sort_callback'));
862 859
 			$this->total = isset($totalcount) ? $totalcount : count($accounts);
863 860
 
864 861
 			// if totalcount is set, $sortedAccounts is NOT the full set, but already a limited set!
@@ -870,7 +867,7 @@  discard block
 block discarded – undo
870 867
 		}
871 868
 		// return only the wanted accounts
872 869
 		reset($sortedAccounts);
873
-		if(is_numeric($start) && is_numeric($offset))
870
+		if (is_numeric($start) && is_numeric($offset))
874 871
 		{
875 872
 			$account_search[$serial]['total'] = $this->total;
876 873
 			return $account_search[$serial]['data'] = isset($totalcount) ? $sortedAccounts : array_slice($sortedAccounts, $start, $offset);
@@ -898,19 +895,19 @@  discard block
 block discarded – undo
898 895
 	 * @param array $b
899 896
 	 * @return int
900 897
 	 */
901
-	function _sort_callback($a,$b)
898
+	function _sort_callback($a, $b)
902 899
 	{
903
-		foreach($this->_callback_order as $col )
900
+		foreach ($this->_callback_order as $col)
904 901
 		{
905
-			if($this->_callback_sort != 'DESC')
902
+			if ($this->_callback_sort != 'DESC')
906 903
 			{
907
-				$cmp = strcasecmp( $a[$col], $b[$col] );
904
+				$cmp = strcasecmp($a[$col], $b[$col]);
908 905
 			}
909 906
 			else
910 907
 			{
911
-				$cmp = strcasecmp( $b[$col], $a[$col] );
908
+				$cmp = strcasecmp($b[$col], $a[$col]);
912 909
 			}
913
-			if ( $cmp != 0 )
910
+			if ($cmp != 0)
914 911
 			{
915 912
 				return $cmp;
916 913
 			}
@@ -929,8 +926,8 @@  discard block
 block discarded – undo
929 926
 	{
930 927
 		if (!empty($date))
931 928
 		{
932
-			return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2),
933
-				substr($date,4,2),substr($date,6,2),substr($date,0,4));
929
+			return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2),
930
+				substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4));
934 931
 		}
935 932
 		return NULL;
936 933
 	}
@@ -947,14 +944,14 @@  discard block
 block discarded – undo
947 944
 	 * @param string $account_type u = user, g = group, default null = try both
948 945
 	 * @return int|false numeric account_id or false on error ($name not found)
949 946
 	 */
950
-	function name2id($_name,$which='account_lid',$account_type=null)
947
+	function name2id($_name, $which = 'account_lid', $account_type = null)
951 948
 	{
952
-		$name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8'));
949
+		$name = Api\Ldap::quote(Api\Translation::convert($_name, Api\Translation::charset(), 'utf-8'));
953 950
 
954 951
 		if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid
955 952
 		{
956 953
 
957
-			$sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber'));
954
+			$sri = ldap_search($this->ds, $this->group_context, '(&(cn='.$name.')(objectclass=posixgroup))', array('gidNumber'));
958 955
 			$allValues = ldap_get_entries($this->ds, $sri);
959 956
 
960 957
 			if (@$allValues[0]['gidnumber'][0])
@@ -971,7 +968,7 @@  discard block
 block discarded – undo
971 968
 		    return False;
972 969
 		}
973 970
 
974
-		$sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber'));
971
+		$sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'='.$name.')(objectclass=posixaccount))', array('uidNumber'));
975 972
 
976 973
 		$allValues = ldap_get_entries($this->ds, $sri);
977 974
 
@@ -991,9 +988,9 @@  discard block
 block discarded – undo
991 988
 	 * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
992 989
 	 * @return string/false converted value or false on error ($account_id not found)
993 990
 	 */
994
-	function id2name($account_id,$which='account_lid')
991
+	function id2name($account_id, $which = 'account_lid')
995 992
 	{
996
-		return $this->frontend->id2name($account_id,$which);
993
+		return $this->frontend->id2name($account_id, $which);
997 994
 	}
998 995
 
999 996
 	/**
@@ -1006,7 +1003,7 @@  discard block
 block discarded – undo
1006 1003
 	function update_lastlogin($_account_id, $ip)
1007 1004
 	{
1008 1005
 		unset($_account_id, $ip);
1009
-		return false;	// not longer supported
1006
+		return false; // not longer supported
1010 1007
 	}
1011 1008
 
1012 1009
 	/**
@@ -1017,11 +1014,11 @@  discard block
 block discarded – undo
1017 1014
 	 */
1018 1015
 	function memberships($account_id)
1019 1016
 	{
1020
-		if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false;
1017
+		if (!(int)$account_id || !($account_lid = $this->id2name($account_id))) return false;
1021 1018
 
1022
-		$sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber'));
1019
+		$sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))', array('cn', 'gidnumber'));
1023 1020
 		$memberships = array();
1024
-		foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data)
1021
+		foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $data)
1025 1022
 		{
1026 1023
 			if ($key === 'count') continue;
1027 1024
 
@@ -1042,13 +1039,13 @@  discard block
 block discarded – undo
1042 1039
 		if (!is_numeric($_gid))
1043 1040
 		{
1044 1041
 			// try to recover
1045
-			$_gid = $this->name2id($_gid,'account_lid','g');
1042
+			$_gid = $this->name2id($_gid, 'account_lid', 'g');
1046 1043
 			if (!is_numeric($_gid)) return false;
1047 1044
 		}
1048 1045
 
1049
-		$gid = abs($_gid);	// our gid is negative!
1046
+		$gid = abs($_gid); // our gid is negative!
1050 1047
 
1051
-		$sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=$gid))",array('memberuid'));
1048
+		$sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=$gid))", array('memberuid'));
1052 1049
 		$group = ldap_get_entries($this->ds, $sri);
1053 1050
 
1054 1051
 		$members = array();
@@ -1056,7 +1053,7 @@  discard block
 block discarded – undo
1056 1053
 		{
1057 1054
 			unset($group[0]['memberuid']['count']);
1058 1055
 
1059
-			foreach($group[0]['memberuid'] as $lid)
1056
+			foreach ($group[0]['memberuid'] as $lid)
1060 1057
 			{
1061 1058
 				if (($id = $this->name2id($lid, 'account_lid', 'u')))
1062 1059
 				{
@@ -1073,27 +1070,27 @@  discard block
 block discarded – undo
1073 1070
 	 * @param array $groups array with gidnumbers
1074 1071
 	 * @param int $account_id uidnumber
1075 1072
 	 */
1076
-	function set_memberships($groups,$account_id)
1073
+	function set_memberships($groups, $account_id)
1077 1074
 	{
1078 1075
 		// remove not longer existing memberships
1079 1076
 		if (($old_memberships = $this->memberships($account_id)))
1080 1077
 		{
1081 1078
 			$old_memberships = array_keys($old_memberships);
1082
-			foreach(array_diff($old_memberships,$groups) as $gid)
1079
+			foreach (array_diff($old_memberships, $groups) as $gid)
1083 1080
 			{
1084 1081
 				if (($members = $this->members($gid)))
1085 1082
 				{
1086 1083
 					unset($members[$account_id]);
1087
-					$this->set_members($members,$gid);
1084
+					$this->set_members($members, $gid);
1088 1085
 				}
1089 1086
 			}
1090 1087
 		}
1091 1088
 		// adding new memberships
1092
-		foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid)
1089
+		foreach ($old_memberships ? array_diff($groups, $old_memberships) : $groups as $gid)
1093 1090
 		{
1094 1091
 			if (!($members = $this->members($gid))) $members = array();
1095 1092
 			$members[$account_id] = $this->id2name($account_id);
1096
-			$this->set_members($members,$gid);
1093
+			$this->set_members($members, $gid);
1097 1094
 		}
1098 1095
 	}
1099 1096
 
@@ -1107,15 +1104,15 @@  discard block
 block discarded – undo
1107 1104
 	 * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it)
1108 1105
 	 * @return boolean/array false on failure, array or true otherwise
1109 1106
 	 */
1110
-	function set_members($members, $gid, array $objectclass=null, $use_cn=null)
1107
+	function set_members($members, $gid, array $objectclass = null, $use_cn = null)
1111 1108
 	{
1112 1109
 		if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false;
1113 1110
 
1114 1111
 		// do that group is a groupOf(Unique)Names or univentionGroup?
1115
-		if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass');
1112
+		if (is_null($objectclass)) $objectclass = $this->id2name($gid, 'objectclass');
1116 1113
 
1117 1114
 		$to_write = array('memberuid' => array());
1118
-		foreach((array)$members as $key => $member)
1115
+		foreach ((array)$members as $key => $member)
1119 1116
 		{
1120 1117
 			$member_dn = $this->id2name($member, 'account_dn');
1121 1118
 			if (is_numeric($member)) $member = $this->id2name($member);
@@ -1127,7 +1124,7 @@  discard block
 block discarded – undo
1127 1124
 				{
1128 1125
 					$to_write['member'][] = $member_dn;
1129 1126
 				}
1130
-				if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass))
1127
+				if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass))
1131 1128
 				{
1132 1129
 					$to_write['uniquemember'][] = $member_dn;
1133 1130
 				}
@@ -1138,31 +1135,31 @@  discard block
 block discarded – undo
1138 1135
 		{
1139 1136
 			$to_write['member'][] = 'uid=dummy'.','.$this->user_context;
1140 1137
 		}
1141
-		if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass) && !$to_write['uniquemember'])
1138
+		if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass) && !$to_write['uniquemember'])
1142 1139
 		{
1143 1140
 			$to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context;
1144 1141
 		}
1145 1142
 		if ($use_cn) return $to_write;
1146 1143
 
1147 1144
 		// set the member email addresses as forwards
1148
-		if ($this->id2name($gid,'account_email') &&	($objectclass = $this->id2name($gid,'mailAllowed')))
1145
+		if ($this->id2name($gid, 'account_email') && ($objectclass = $this->id2name($gid, 'mailAllowed')))
1149 1146
 		{
1150 1147
 			$forward = $this->group_mail_classes[$objectclass];
1151
-			if (is_array($forward)) list($forward,$extra_attr) = $forward;
1148
+			if (is_array($forward)) list($forward, $extra_attr) = $forward;
1152 1149
 			if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid;
1153 1150
 
1154 1151
 			if ($forward)
1155 1152
 			{
1156 1153
 				$to_write[$forward] = array();
1157
-				foreach($members as $key => $member)
1154
+				foreach ($members as $key => $member)
1158 1155
 				{
1159
-					if (($email = $this->id2name($member,'account_email')))	$to_write[$forward][] = $email;
1156
+					if (($email = $this->id2name($member, 'account_email')))	$to_write[$forward][] = $email;
1160 1157
 				}
1161 1158
 			}
1162 1159
 		}
1163
-		if (!ldap_modify($this->ds,'cn='.Api\Ldap::quote($cn).','.$this->group_context,$to_write))
1160
+		if (!ldap_modify($this->ds, 'cn='.Api\Ldap::quote($cn).','.$this->group_context, $to_write))
1164 1161
 		{
1165
-			echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write,true)."))\n";
1162
+			echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write, true)."))\n";
1166 1163
 			return false;
1167 1164
 		}
1168 1165
 		return true;
@@ -1175,7 +1172,7 @@  discard block
 block discarded – undo
1175 1172
 	 * @param string $account_type ='u' (optional, default to 'u')
1176 1173
 	 * @return int|boolean integer account_id (negative for groups) or false if none is free anymore
1177 1174
 	 */
1178
-	protected function _get_nextid($account_type='u')
1175
+	protected function _get_nextid($account_type = 'u')
1179 1176
 	{
1180 1177
 		$min = $this->frontend->config['account_min_id'] ? $this->frontend->config['account_min_id'] : 0;
1181 1178
 		$max = $this->frontend->config['account_max_id'] ? $this->frontend->config['account_max_id'] : 0;
@@ -1197,16 +1194,16 @@  discard block
 block discarded – undo
1197 1194
 		/* Loop until we find a free id */
1198 1195
 		do
1199 1196
 		{
1200
-			$account_id = (int) self::next_id($type,$min,$max);
1197
+			$account_id = (int)self::next_id($type, $min, $max);
1201 1198
 		}
1202
-		while ($account_id && ($this->frontend->exists($sign * $account_id) ||	// check need to include the sign!
1199
+		while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign!
1203 1200
 			$this->frontend->exists(-1 * $sign * $account_id) ||
1204 1201
 			// if sambaadmin is installed, call it to check there's not yet a relative id (last part of SID) with that number
1205 1202
 			// to ease migration to AD or Samba4
1206 1203
 			file_exists(EGW_SERVER_ROOT.'/sambaadmin') && $GLOBALS['egw_info']['apps']['sambaadmin'] &&
1207 1204
 				ExecMethod2('sambaadmin.sosambaadmin.sidExists', $account_id)));
1208 1205
 
1209
-		if	(!$account_id || $max && $account_id > $max)
1206
+		if (!$account_id || $max && $account_id > $max)
1210 1207
 		{
1211 1208
 			return False;
1212 1209
 		}
@@ -1221,14 +1218,14 @@  discard block
 block discarded – undo
1221 1218
 	 * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false
1222 1219
 	 * @return int|boolean the next id or false if $max given and exceeded
1223 1220
 	 */
1224
-	static function next_id($location,$min=0,$max=0)
1221
+	static function next_id($location, $min = 0, $max = 0)
1225 1222
 	{
1226 1223
 		if (!$location)
1227 1224
 		{
1228 1225
 			return -1;
1229 1226
 		}
1230 1227
 
1231
-		$id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location];
1228
+		$id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location];
1232 1229
 
1233 1230
 		if ($max && $id >= $max)
1234 1231
 		{
@@ -1236,10 +1233,10 @@  discard block
 block discarded – undo
1236 1233
 		}
1237 1234
 		++$id;
1238 1235
 
1239
-		if($id < $min) $id = $min;
1236
+		if ($id < $min) $id = $min;
1240 1237
 
1241 1238
 		Api\Config::save_value($key, $id, 'phpgwapi', true);
1242
-		$GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id;
1239
+		$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location] = $id;
1243 1240
 
1244 1241
 		return (int)$id;
1245 1242
 	}
@@ -1252,18 +1249,18 @@  discard block
 block discarded – undo
1252 1249
 	 * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false
1253 1250
 	 * @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.
1254 1251
 	 */
1255
-	static function last_id($location,$min=0,$max=0)
1252
+	static function last_id($location, $min = 0, $max = 0)
1256 1253
 	{
1257 1254
 		if (!$location)
1258 1255
 		{
1259 1256
 			return -1;
1260 1257
 		}
1261 1258
 
1262
-		$id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location];
1259
+		$id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location];
1263 1260
 
1264 1261
 		if (!$id || $id < $min)
1265 1262
 		{
1266
-			return self::next_id($location,$min,$max);
1263
+			return self::next_id($location, $min, $max);
1267 1264
 		}
1268 1265
 		if ($max && $id > $max)
1269 1266
 		{
@@ -1278,6 +1275,6 @@  discard block
 block discarded – undo
1278 1275
 	function __wakeup()
1279 1276
 	{
1280 1277
 		$this->ds = Api\Ldap::factory(true, $this->frontend->config['ldap_host'],
1281
-			$this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']);
1278
+			$this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']);
1282 1279
 	}
1283 1280
 }
Please login to merge, or discard this patch.
Braces   +176 added lines, -45 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);
@@ -750,12 +823,18 @@  discard block
 block discarded – undo
750 823
 					$fullSet = array();
751 824
 					foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry)
752 825
 					{
753
-						if ($key !== 'count') $fullSet[$entry['uid'][0]] = $entry[$order][0];
826
+						if ($key !== 'count')
827
+						{
828
+							$fullSet[$entry['uid'][0]] = $entry[$order][0];
829
+						}
754 830
 					}
755 831
 
756
-					if (is_numeric($param['type'])) // return only group-members
832
+					if (is_numeric($param['type']))
833
+					{
834
+						// return only group-members
757 835
 					{
758 836
 						$relevantAccounts = array();
837
+					}
759 838
 						$sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid'));
760 839
 						$group = ldap_get_entries($this->ds, $sri);
761 840
 						$fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array();
@@ -793,7 +872,10 @@  discard block
 block discarded – undo
793 872
 						//error_log(__METHOD__."() ldap=".array2string($allVals)." --> account=".array2string($account));
794 873
 						if ($param['active'] && !$this->frontend->is_active($account))
795 874
 						{
796
-							if (isset($totalcount)) --$totalcount;
875
+							if (isset($totalcount))
876
+							{
877
+								--$totalcount;
878
+							}
797 879
 							continue;
798 880
 						}
799 881
 						$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'],
@@ -846,7 +928,10 @@  discard block
 block discarded – undo
846 928
 							'account_status'    => 'A',
847 929
 							'account_fullname'  => Api\Translation::convert($allVals['cn'][0],'utf-8'),
848 930
 						);
849
-						if (isset($totalcount)) ++$totalcount;
931
+						if (isset($totalcount))
932
+						{
933
+							++$totalcount;
934
+						}
850 935
 					}
851 936
 				}
852 937
 			}
@@ -855,7 +940,10 @@  discard block
 block discarded – undo
855 940
 			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']);
856 941
 			foreach($this->_callback_order as &$col)
857 942
 			{
858
-				if (substr($col, 0, 8) !== 'account_') $col = 'account_'.$col;
943
+				if (substr($col, 0, 8) !== 'account_')
944
+				{
945
+					$col = 'account_'.$col;
946
+				}
859 947
 			}
860 948
 			$sortedAccounts = $accounts;
861 949
 			uasort($sortedAccounts,array($this,'_sort_callback'));
@@ -951,10 +1039,13 @@  discard block
 block discarded – undo
951 1039
 	{
952 1040
 		$name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8'));
953 1041
 
954
-		if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid
1042
+		if ($which == 'account_lid' && $account_type !== 'u')
1043
+		{
1044
+			// groups only support account_lid
955 1045
 		{
956 1046
 
957 1047
 			$sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber'));
1048
+		}
958 1049
 			$allValues = ldap_get_entries($this->ds, $sri);
959 1050
 
960 1051
 			if (@$allValues[0]['gidnumber'][0])
@@ -967,7 +1058,8 @@  discard block
 block discarded – undo
967 1058
 			'account_email' => static::MAIL_ATTR,
968 1059
 			'account_fullname' => 'cn',
969 1060
 		);
970
-		if (!isset($to_ldap[$which]) || $account_type === 'g') {
1061
+		if (!isset($to_ldap[$which]) || $account_type === 'g')
1062
+		{
971 1063
 		    return False;
972 1064
 		}
973 1065
 
@@ -1017,13 +1109,19 @@  discard block
 block discarded – undo
1017 1109
 	 */
1018 1110
 	function memberships($account_id)
1019 1111
 	{
1020
-		if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false;
1112
+		if (!(int) $account_id || !($account_lid = $this->id2name($account_id)))
1113
+		{
1114
+			return false;
1115
+		}
1021 1116
 
1022 1117
 		$sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber'));
1023 1118
 		$memberships = array();
1024 1119
 		foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data)
1025 1120
 		{
1026
-			if ($key === 'count') continue;
1121
+			if ($key === 'count')
1122
+			{
1123
+				continue;
1124
+			}
1027 1125
 
1028 1126
 			$memberships[(string) -$data['gidnumber'][0]] = $data['cn'][0];
1029 1127
 		}
@@ -1043,7 +1141,10 @@  discard block
 block discarded – undo
1043 1141
 		{
1044 1142
 			// try to recover
1045 1143
 			$_gid = $this->name2id($_gid,'account_lid','g');
1046
-			if (!is_numeric($_gid)) return false;
1144
+			if (!is_numeric($_gid))
1145
+			{
1146
+				return false;
1147
+			}
1047 1148
 		}
1048 1149
 
1049 1150
 		$gid = abs($_gid);	// our gid is negative!
@@ -1091,7 +1192,10 @@  discard block
 block discarded – undo
1091 1192
 		// adding new memberships
1092 1193
 		foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid)
1093 1194
 		{
1094
-			if (!($members = $this->members($gid))) $members = array();
1195
+			if (!($members = $this->members($gid)))
1196
+			{
1197
+				$members = array();
1198
+			}
1095 1199
 			$members[$account_id] = $this->id2name($account_id);
1096 1200
 			$this->set_members($members,$gid);
1097 1201
 		}
@@ -1109,16 +1213,25 @@  discard block
 block discarded – undo
1109 1213
 	 */
1110 1214
 	function set_members($members, $gid, array $objectclass=null, $use_cn=null)
1111 1215
 	{
1112
-		if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false;
1216
+		if (!($cn = $use_cn) && !($cn = $this->id2name($gid)))
1217
+		{
1218
+			return false;
1219
+		}
1113 1220
 
1114 1221
 		// do that group is a groupOf(Unique)Names or univentionGroup?
1115
-		if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass');
1222
+		if (is_null($objectclass))
1223
+		{
1224
+			$objectclass = $this->id2name($gid,'objectclass');
1225
+		}
1116 1226
 
1117 1227
 		$to_write = array('memberuid' => array());
1118 1228
 		foreach((array)$members as $key => $member)
1119 1229
 		{
1120 1230
 			$member_dn = $this->id2name($member, 'account_dn');
1121
-			if (is_numeric($member)) $member = $this->id2name($member);
1231
+			if (is_numeric($member))
1232
+			{
1233
+				$member = $this->id2name($member);
1234
+			}
1122 1235
 
1123 1236
 			if ($member)
1124 1237
 			{
@@ -1142,21 +1255,33 @@  discard block
 block discarded – undo
1142 1255
 		{
1143 1256
 			$to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context;
1144 1257
 		}
1145
-		if ($use_cn) return $to_write;
1258
+		if ($use_cn)
1259
+		{
1260
+			return $to_write;
1261
+		}
1146 1262
 
1147 1263
 		// set the member email addresses as forwards
1148 1264
 		if ($this->id2name($gid,'account_email') &&	($objectclass = $this->id2name($gid,'mailAllowed')))
1149 1265
 		{
1150 1266
 			$forward = $this->group_mail_classes[$objectclass];
1151
-			if (is_array($forward)) list($forward,$extra_attr) = $forward;
1152
-			if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid;
1267
+			if (is_array($forward))
1268
+			{
1269
+				list($forward,$extra_attr) = $forward;
1270
+			}
1271
+			if ($extra_attr && ($uid = $this->id2name($gid)))
1272
+			{
1273
+				$to_write[$extra_attr] = $uid;
1274
+			}
1153 1275
 
1154 1276
 			if ($forward)
1155 1277
 			{
1156 1278
 				$to_write[$forward] = array();
1157 1279
 				foreach($members as $key => $member)
1158 1280
 				{
1159
-					if (($email = $this->id2name($member,'account_email')))	$to_write[$forward][] = $email;
1281
+					if (($email = $this->id2name($member,'account_email')))
1282
+					{
1283
+						$to_write[$forward][] = $email;
1284
+					}
1160 1285
 				}
1161 1286
 			}
1162 1287
 		}
@@ -1182,7 +1307,10 @@  discard block
 block discarded – undo
1182 1307
 
1183 1308
 		// prefer ids above 1000 (below reserved for system users under AD or Linux),
1184 1309
 		// if that's possible within what is configured, or nothing is configured
1185
-		if ($min < 1000 && (!$max || $max > 1000)) $min = 1000;
1310
+		if ($min < 1000 && (!$max || $max > 1000))
1311
+		{
1312
+			$min = 1000;
1313
+		}
1186 1314
 
1187 1315
 		if ($account_type == 'g')
1188 1316
 		{
@@ -1236,7 +1364,10 @@  discard block
 block discarded – undo
1236 1364
 		}
1237 1365
 		++$id;
1238 1366
 
1239
-		if($id < $min) $id = $min;
1367
+		if($id < $min)
1368
+		{
1369
+			$id = $min;
1370
+		}
1240 1371
 
1241 1372
 		Api\Config::save_value($key, $id, 'phpgwapi', true);
1242 1373
 		$GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id;
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.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	/**
33 33
 	 * @var array $data internal repository with acl rows for the given app and account-id (incl. memberships)
34 34
 	 */
35
-	var $data = Array();
35
+	var $data = array();
36 36
 	/**
37 37
 	 * internal reference to global db-object
38 38
 	 *
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			array_unshift($acl_acc_list,$this->account_id);
134 134
 		}
135 135
 
136
-		$this->data = Array();
136
+		$this->data = array();
137 137
 		foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row)
138 138
 		{
139 139
 			$this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_');
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true);
677 677
 			$memberships[] = $user;
678 678
 
679
-			$grants = $accounts = Array();
679
+			$grants = $accounts = array();
680 680
 			foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array(
681 681
 				'acl_appname'  => $app,
682 682
 				'acl_location' => $memberships,
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -47,15 +47,15 @@  discard block
 block discarded – undo
47 47
 	/**
48 48
 	 * Constants for acl rights, like old EGW_ACL_* defines
49 49
 	 */
50
-	const READ      = 1;	// EGW_ACL_READ
51
-	const ADD       = 2;	// EGW_ACL_ADD
52
-	const EDIT      = 4;	// EGW_ACL_EDIT
53
-	const DELETE    = 8;	// EGW_ACL_DELETE
54
-	const PRIVAT    = 16;	// EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead!
55
-	const GROUPMGRS = 32;	// EGW_ACL_GROUP_MANAGERS
56
-	const CUSTOM1  = 64;		// EGW_ACL_CUSTOM_1
57
-	const CUSTOM2  = 128;	// EGW_ACL_CUSTOM_2
58
-	const CUSTOM3  = 256;	// EGW_ACL_CUSTOM_3
50
+	const READ      = 1; // EGW_ACL_READ
51
+	const ADD       = 2; // EGW_ACL_ADD
52
+	const EDIT      = 4; // EGW_ACL_EDIT
53
+	const DELETE    = 8; // EGW_ACL_DELETE
54
+	const PRIVAT    = 16; // EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead!
55
+	const GROUPMGRS = 32; // EGW_ACL_GROUP_MANAGERS
56
+	const CUSTOM1  = 64; // EGW_ACL_CUSTOM_1
57
+	const CUSTOM2  = 128; // EGW_ACL_CUSTOM_2
58
+	const CUSTOM3  = 256; // EGW_ACL_CUSTOM_3
59 59
 
60 60
 	/**
61 61
 	 * ACL constructor for setting account id
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		}
79 79
 		if ((int)$this->account_id != (int)$account_id)
80 80
 		{
81
-			$this->account_id = get_account_id((int)$account_id,@$GLOBALS['egw_info']['user']['account_id']);
81
+			$this->account_id = get_account_id((int)$account_id, @$GLOBALS['egw_info']['user']['account_id']);
82 82
 		}
83 83
 		$this->data = array();
84 84
 	}
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	function __sleep()
93 93
 	{
94
-		return array('account_id','db');
94
+		return array('account_id', 'db');
95 95
 	}
96 96
 
97 97
 	/**************************************************************************\
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @param boolean|array $no_groups = false if true, do not use memberships, if array do not use given groups
105 105
 	 * @return array along with storing it in $acl->data.  <br>
106 106
 	 */
107
-	function read_repository($no_groups=false)
107
+	function read_repository($no_groups = false)
108 108
 	{
109 109
 		// For some reason, calling this via XML-RPC doesn't call the constructor.
110 110
 		// Here is yet another work around(tm) (jengo)
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
 		else
120 120
 		{
121 121
 			$acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true);
122
-			if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups);
123
-			array_unshift($acl_acc_list,$this->account_id);
122
+			if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list, $no_groups);
123
+			array_unshift($acl_acc_list, $this->account_id);
124 124
 		}
125 125
 
126 126
 		$this->data = Array();
127
-		foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row)
127
+		foreach ($this->db->select(self::TABLE, '*', array('acl_account' => $acl_acc_list), __LINE__, __FILE__) as $row)
128 128
 		{
129
-			$this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_');
129
+			$this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row, 'acl_');
130 130
 		}
131 131
 		return $this->data;
132 132
 	}
@@ -155,15 +155,15 @@  discard block
 block discarded – undo
155 155
 	 * @param int $rights rights
156 156
 	 * @return array all ACL records from $this->data.
157 157
 	 */
158
-	function add($appname,$location,$rights)
158
+	function add($appname, $location, $rights)
159 159
 	{
160 160
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
161 161
 
162 162
 		$row = array(
163 163
 			'appname'  => $appname,
164 164
 			'location' => $location,
165
-			'account'  => (int) $this->account_id,
166
-			'rights'   => (int) $rights
165
+			'account'  => (int)$this->account_id,
166
+			'rights'   => (int)$rights
167 167
 		);
168 168
 		$this->data[$row['appname'].'-'.$row['location'].'-'.$row['account']] = $row;
169 169
 
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 	 * @param string/boolean $location location or false for all locations
178 178
 	 * @return array all ACL records from $this->data.
179 179
 	 */
180
-	function delete($appname,$location)
180
+	function delete($appname, $location)
181 181
 	{
182 182
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
183 183
 
184
-		foreach($this->data as $idx => $value)
184
+		foreach ($this->data as $idx => $value)
185 185
 		{
186 186
 			if ($value['appname'] == $appname &&
187 187
 				($location === false || $value['location'] == $location) &&
@@ -200,24 +200,24 @@  discard block
 block discarded – undo
200 200
 	 */
201 201
 	function save_repository()
202 202
 	{
203
-		$this->db->delete(self::TABLE,array(
203
+		$this->db->delete(self::TABLE, array(
204 204
 			'acl_account' => $this->account_id,
205
-		),__LINE__,__FILE__);
205
+		), __LINE__, __FILE__);
206 206
 
207
-		foreach($this->data as $value)
207
+		foreach ($this->data as $value)
208 208
 		{
209 209
 			if ($value['account'] == $this->account_id)
210 210
 			{
211
-				$this->db->insert(self::TABLE,array(
211
+				$this->db->insert(self::TABLE, array(
212 212
 					'acl_appname'  => $value['appname'],
213 213
 					'acl_location' => $value['location'],
214 214
 					'acl_account'  => $this->account_id,
215 215
 					'acl_rights'   => $value['rights'],
216
-				),false,__LINE__,__FILE__);
216
+				), false, __LINE__, __FILE__);
217 217
 			}
218 218
 		}
219 219
 		if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] &&
220
-			method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
220
+			method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
221 221
 		{
222 222
 			$GLOBALS['egw']->invalidate_session_cache();
223 223
 		}
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	 * @param string $appname optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
236 236
 	 * @return int all rights or'ed together
237 237
 	 */
238
-	function get_rights($location,$appname = '')
238
+	function get_rights($location, $appname = '')
239 239
 	{
240 240
 		// For XML-RPC, change this once its working correctly for passing parameters (jengo)
241 241
 		if (is_array($location))
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 			return True;
256 256
 		}
257 257
 		$rights = 0;
258
-		foreach($this->data as $value)
258
+		foreach ($this->data as $value)
259 259
 		{
260 260
 			if ($value['appname'] == $appname)
261 261
 			{
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
 	 */
283 283
 	function check($location, $required, $appname = False)
284 284
 	{
285
-		$rights = $this->get_rights($location,$appname);
285
+		$rights = $this->get_rights($location, $appname);
286 286
 
287
-		return !!($rights & $required);
287
+		return !!($rights&$required);
288 288
 	}
289 289
 
290 290
 	/**
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	 * @param array $memberships = array() additional account_id, eg. memberships to match beside $this->account_id, default none
296 296
 	 * @return int $rights
297 297
 	 */
298
-	function get_specific_rights($location, $appname = '', $memberships=array())
298
+	function get_specific_rights($location, $appname = '', $memberships = array())
299 299
 	{
300 300
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
301 301
 
@@ -305,10 +305,10 @@  discard block
 block discarded – undo
305 305
 		}
306 306
 		$rights = 0;
307 307
 
308
-		foreach($this->data as $value)
308
+		foreach ($this->data as $value)
309 309
 		{
310 310
 			if ($value['appname'] == $appname &&
311
-				($value['location'] == $location ||	$value['location'] == 'everywhere') &&
311
+				($value['location'] == $location || $value['location'] == 'everywhere') &&
312 312
 				($value['account'] == $this->account_id || $memberships && in_array($value['account'], $memberships)))
313 313
 			{
314 314
 				if ($value['rights'] == 0)
@@ -331,9 +331,9 @@  discard block
 block discarded – undo
331 331
 	 */
332 332
 	function check_specific($location, $required, $appname = '')
333 333
 	{
334
-		$rights = $this->get_specific_rights($location,$appname);
334
+		$rights = $this->get_specific_rights($location, $appname);
335 335
 
336
-		return !!($rights & $required);
336
+		return !!($rights&$required);
337 337
 	}
338 338
 
339 339
 	/**************************************************************************\
@@ -350,19 +350,19 @@  discard block
 block discarded – undo
350 350
 	 * @param boolean $invalidate_session =true false: do NOT invalidate session
351 351
 	 * @return boolean allways true
352 352
 	 */
353
-	function add_repository($app, $location, $account_id, $rights, $invalidate_session=true)
353
+	function add_repository($app, $location, $account_id, $rights, $invalidate_session = true)
354 354
 	{
355 355
 		//echo "<p>self::add_repository('$app','$location',$account_id,$rights);</p>\n";
356
-		$this->db->insert(self::TABLE,array(
356
+		$this->db->insert(self::TABLE, array(
357 357
 			'acl_rights' => $rights,
358
-		),array(
358
+		), array(
359 359
 			'acl_appname' => $app,
360 360
 			'acl_location' => $location,
361 361
 			'acl_account'  => $account_id,
362
-		),__LINE__,__FILE__);
362
+		), __LINE__, __FILE__);
363 363
 
364 364
 		if ($invalidate_session && $account_id == $GLOBALS['egw_info']['user']['account_id'] &&
365
-			method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
365
+			method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
366 366
 		{
367 367
 			$GLOBALS['egw']->invalidate_session_cache();
368 368
 		}
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	 * @param boolean $invalidate_session =true false: do NOT invalidate session
379 379
 	 * @return int number of rows deleted
380 380
 	 */
381
-	function delete_repository($app, $location, $accountid='', $invalidate_session=true)
381
+	function delete_repository($app, $location, $accountid = '', $invalidate_session = true)
382 382
 	{
383 383
 		static $cache_accountid = array();
384 384
 
@@ -388,22 +388,22 @@  discard block
 block discarded – undo
388 388
 		);
389 389
 		if ($accountid !== false)
390 390
 		{
391
-			if(isset($cache_accountid[$accountid]) && $cache_accountid[$accountid])
391
+			if (isset($cache_accountid[$accountid]) && $cache_accountid[$accountid])
392 392
 			{
393 393
 				$where['acl_account'] = $cache_accountid[$accountid];
394 394
 			}
395 395
 			else
396 396
 			{
397
-				$where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id);
397
+				$where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id);
398 398
 			}
399 399
 		}
400 400
 		if ($app == '%' || $app == '%%') unset($where['acl_appname']);
401 401
 
402
-		$this->db->delete(self::TABLE,$where,__LINE__,__FILE__);
402
+		$this->db->delete(self::TABLE, $where, __LINE__, __FILE__);
403 403
 
404 404
 		$deleted = $this->db->affected_rows();
405 405
 
406
-		if ($invalidate_session && $deleted && method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
406
+		if ($invalidate_session && $deleted && method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
407 407
 		{
408 408
 			$GLOBALS['egw']->invalidate_session_cache();
409 409
 		}
@@ -418,15 +418,15 @@  discard block
 block discarded – undo
418 418
 	 * @param string $appname = '' defaults to current app
419 419
 	 * @return int/boolean rights or false if none exist
420 420
 	 */
421
-	function get_specific_rights_for_account($account_id,$location,$appname='')
421
+	function get_specific_rights_for_account($account_id, $location, $appname = '')
422 422
 	{
423 423
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
424 424
 
425
-		return $this->db->select(self::TABLE,'acl_rights',array(
425
+		return $this->db->select(self::TABLE, 'acl_rights', array(
426 426
 			'acl_location' => $location,
427 427
 			'acl_account'  => $account_id,
428 428
 			'acl_appname'  => $appname,
429
-		),__LINE__,__FILE__)->fetchColumn();
429
+		), __LINE__, __FILE__)->fetchColumn();
430 430
 	}
431 431
 
432 432
 	/**
@@ -436,15 +436,15 @@  discard block
 block discarded – undo
436 436
 	 * @param string $appname = '' defaults to current app
437 437
 	 * @return array with account => rights pairs
438 438
 	 */
439
-	function get_all_rights($location,$appname='')
439
+	function get_all_rights($location, $appname = '')
440 440
 	{
441 441
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
442 442
 
443 443
 		$rights = array();
444
-		foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array(
444
+		foreach ($this->db->select(self::TABLE, 'acl_account,acl_rights', array(
445 445
 			'acl_location' => $location,
446 446
 			'acl_appname'  => $appname,
447
-		),__LINE__,__FILE__) as $row)
447
+		), __LINE__, __FILE__) as $row)
448 448
 		{
449 449
 			$rights[$row['acl_account']] = $row['acl_rights'];
450 450
 		}
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 	 * @param boolean $use_memberships = true
460 460
 	 * @return array with location => rights pairs
461 461
 	 */
462
-	function get_all_location_rights($account_id,$appname='',$use_memberships=true)
462
+	function get_all_location_rights($account_id, $appname = '', $use_memberships = true)
463 463
 	{
464 464
 		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
465 465
 
@@ -470,10 +470,10 @@  discard block
 block discarded – undo
470 470
 			$accounts[] = $account_id;
471 471
 		}
472 472
 		$rights = array();
473
-		foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array(
473
+		foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array(
474 474
 			'acl_account' => $accounts,
475 475
 			'acl_appname' => $appname,
476
-		),__LINE__,__FILE__) as $row)
476
+		), __LINE__, __FILE__) as $row)
477 477
 		{
478 478
 			$rights[$row['acl_location']] |= $row['acl_rights'];
479 479
 		}
@@ -492,28 +492,28 @@  discard block
 block discarded – undo
492 492
 	{
493 493
 		static $cache_accountid = array();
494 494
 
495
-		if(isset($cache_accountid[$accountid]))
495
+		if (isset($cache_accountid[$accountid]))
496 496
 		{
497 497
 			$account_id = $cache_accountid[$accountid];
498 498
 		}
499 499
 		else
500 500
 		{
501
-			$account_id = get_account_id($accountid,$this->account_id);
501
+			$account_id = get_account_id($accountid, $this->account_id);
502 502
 			$cache_accountid[$accountid] = $account_id;
503 503
 		}
504 504
 		$rights = 0;
505 505
 		$apps = false;
506
-		foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array(
506
+		foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array(
507 507
 			'acl_location' => $location,
508 508
 			'acl_account'  => $account_id,
509
-		),__LINE__,__FILE__) as $row)
509
+		), __LINE__, __FILE__) as $row)
510 510
 		{
511 511
 			if ($row['acl_rights'] == 0)
512 512
 			{
513 513
 				return False;
514 514
 			}
515 515
 			$rights |= $row['acl_rights'];
516
-			if (!!($rights & $required))
516
+			if (!!($rights&$required))
517 517
 			{
518 518
 				$apps[] = $row['acl_appname'];
519 519
 			}
@@ -533,21 +533,21 @@  discard block
 block discarded – undo
533 533
 	{
534 534
 		static $cache_accountid = array();
535 535
 
536
-		if(isset($cache_accountid[$accountid]))
536
+		if (isset($cache_accountid[$accountid]))
537 537
 		{
538 538
 			$accountid = $cache_accountid[$accountid];
539 539
 		}
540 540
 		else
541 541
 		{
542
-			$accountid = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id);
542
+			$accountid = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id);
543 543
 		}
544 544
 		$locations = false;
545
-		foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array(
545
+		foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array(
546 546
 			'acl_appname' => $app,
547 547
 			'acl_account' => $accountid,
548
-		),__LINE__,__FILE__) as $row)
548
+		), __LINE__, __FILE__) as $row)
549 549
 		{
550
-			if ($row['acl_rights'] & $required)
550
+			if ($row['acl_rights']&$required)
551 551
 			{
552 552
 				$locations[] = $row['acl_location'];
553 553
 			}
@@ -568,14 +568,14 @@  discard block
 block discarded – undo
568 568
 		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
569 569
 
570 570
 		$accounts = false;
571
-		foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array(
571
+		foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights'), array(
572 572
 			'acl_appname'  => $app,
573 573
 			'acl_location' => $location,
574
-		),__LINE__,__FILE__) as $row)
574
+		), __LINE__, __FILE__) as $row)
575 575
 		{
576
-			if (!!($row['acl_rights'] & $required))
576
+			if (!!($row['acl_rights']&$required))
577 577
 			{
578
-				$accounts[] = (int) $row['acl_account'];
578
+				$accounts[] = (int)$row['acl_account'];
579 579
 			}
580 580
 		}
581 581
 		return $accounts;
@@ -587,14 +587,14 @@  discard block
 block discarded – undo
587 587
 	 * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
588 588
 	 * @return boolean/array false if there are no matching location in the db or array of locations
589 589
 	 */
590
-	function get_locations_for_app($app='')
590
+	function get_locations_for_app($app = '')
591 591
 	{
592 592
 		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
593 593
 
594 594
 		$locations = false;
595
-		foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array(
595
+		foreach ($this->db->select(self::TABLE, 'DISTINCT '.'acl_location', array(
596 596
 			'acl_appname'  => $app,
597
-		),__LINE__,__FILE__) as $row)
597
+		), __LINE__, __FILE__) as $row)
598 598
 		{
599 599
 			if (($location = $row['acl_location']) != 'run')
600 600
 			{
@@ -612,38 +612,38 @@  discard block
 block discarded – undo
612 612
 	 * @param boolean $add_implicit_apps = true true: add apps every user has implicit rights
613 613
 	 * @return array containing list of apps
614 614
 	 */
615
-	function get_user_applications($accountid = '', $use_memberships=true, $add_implicit_apps=true)
615
+	function get_user_applications($accountid = '', $use_memberships = true, $add_implicit_apps = true)
616 616
 	{
617 617
 		static $cache_accountid = array();
618 618
 
619
-		if(isset($cache_accountid[$accountid]))
619
+		if (isset($cache_accountid[$accountid]))
620 620
 		{
621 621
 			$account_id = $cache_accountid[$accountid];
622 622
 		}
623 623
 		else
624 624
 		{
625
-			$account_id = get_account_id($accountid,$this->account_id);
625
+			$account_id = get_account_id($accountid, $this->account_id);
626 626
 			$cache_accountid[$accountid] = $account_id;
627 627
 		}
628 628
 		if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true);
629 629
 		$memberships[] = (int)$account_id;
630 630
 
631 631
 		$apps = array();
632
-		foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array(
632
+		foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array(
633 633
 			'acl_location' => 'run',
634 634
 			'acl_account'  => $memberships,
635
-		),__LINE__,__FILE__) as $row)
635
+		), __LINE__, __FILE__) as $row)
636 636
 		{
637 637
 			$app = $row['acl_appname'];
638
-			if(!isset($apps[$app]))
638
+			if (!isset($apps[$app]))
639 639
 			{
640 640
 				$apps[$app] = 0;
641 641
 			}
642
-			$apps[$app] |= (int) $row['acl_rights'];
642
+			$apps[$app] |= (int)$row['acl_rights'];
643 643
 		}
644 644
 		if ($add_implicit_apps)
645 645
 		{
646
-			$apps['api'] = 1;	// give everyone implicit rights for the home app
646
+			$apps['api'] = 1; // give everyone implicit rights for the home app
647 647
 		}
648 648
 		return $apps;
649 649
 	}
@@ -657,29 +657,29 @@  discard block
 block discarded – undo
657 657
 	 * @param int $user = null user whos grants to return, default current user
658 658
 	 * @return array with account-ids (of owners) and granted rights as values
659 659
 	 */
660
-	function get_grants($app='',$enum_group_acls=true,$user=null)
660
+	function get_grants($app = '', $enum_group_acls = true, $user = null)
661 661
 	{
662 662
 		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
663 663
 		if (!$user) $user = $this->account_id;
664 664
 
665
-		static $cache = array();	// some caching withing the request
665
+		static $cache = array(); // some caching withing the request
666 666
 
667
-		$grants =& $cache[$app][$user];
667
+		$grants = & $cache[$app][$user];
668 668
 		if (!isset($grants))
669 669
 		{
670 670
 			if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true);
671 671
 			$memberships[] = $user;
672 672
 
673 673
 			$grants = $accounts = Array();
674
-			foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array(
674
+			foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights', 'acl_location'), array(
675 675
 				'acl_appname'  => $app,
676 676
 				'acl_location' => $memberships,
677
-			),__LINE__,__FILE__) as $row)
677
+			), __LINE__, __FILE__) as $row)
678 678
 			{
679 679
 				$grantor    = $row['acl_account'];
680 680
 				$rights     = $row['acl_rights'];
681 681
 
682
-				if(!isset($grants[$grantor]))
682
+				if (!isset($grants[$grantor]))
683 683
 				{
684 684
 					$grants[$grantor] = 0;
685 685
 				}
@@ -687,17 +687,17 @@  discard block
 block discarded – undo
687 687
 
688 688
 				// if the right is granted from a group and we enummerated group ACL's
689 689
 				if ($GLOBALS['egw']->accounts->get_type($grantor) == 'g' && $enum_group_acls &&
690
-					(!is_array($enum_group_acls) || !in_array($grantor,$enum_group_acls)))
690
+					(!is_array($enum_group_acls) || !in_array($grantor, $enum_group_acls)))
691 691
 				{
692 692
 					// return the grant for each member of the group (false = also for no longer active users)
693
-					foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor)
693
+					foreach ((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor)
694 694
 					{
695
-						if (!$grantor) continue;	// can happen if group has no members
695
+						if (!$grantor) continue; // can happen if group has no members
696 696
 
697 697
 						// Don't allow to override private with group ACL's!
698 698
 						$rights &= ~self::PRIVAT;
699 699
 
700
-						if(!isset($grants[$grantor]))
700
+						if (!isset($grants[$grantor]))
701 701
 						{
702 702
 							$grants[$grantor] = 0;
703 703
 						}
@@ -719,21 +719,21 @@  discard block
 block discarded – undo
719 719
 	 */
720 720
 	function delete_account($account_id)
721 721
 	{
722
-		if ((int) $account_id)
722
+		if ((int)$account_id)
723 723
 		{
724 724
 			// Delete all grants from this account
725
-			$this->db->delete(self::TABLE,array(
725
+			$this->db->delete(self::TABLE, array(
726 726
 				'acl_account' => $account_id
727
-			),__LINE__,__FILE__);
727
+			), __LINE__, __FILE__);
728 728
 			// Delete all grants to this account
729
-			$this->db->delete(self::TABLE,array(
729
+			$this->db->delete(self::TABLE, array(
730 730
 				'acl_location' => $account_id
731
-			),__LINE__, __FILE__);
731
+			), __LINE__, __FILE__);
732 732
 			// delete all memberships in account_id (if it is a group)
733
-			$this->db->delete(self::TABLE,array(
733
+			$this->db->delete(self::TABLE, array(
734 734
 				'acl_appname' => 'phpgw_group',
735 735
 				'acl_location' => $account_id,
736
-			),__LINE__,__FILE__);
736
+			), __LINE__, __FILE__);
737 737
 		}
738 738
 	}
739 739
 
@@ -744,15 +744,15 @@  discard block
 block discarded – undo
744 744
 	 * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp'];
745 745
 	 * @return array with location => array(account => rights) pairs
746 746
 	 */
747
-	function get_location_grants($location,$app='')
747
+	function get_location_grants($location, $app = '')
748 748
 	{
749 749
 		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
750 750
 
751 751
 		$locations = array();
752
-		foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array(
752
+		foreach ($this->db->select(self::TABLE, 'acl_location,acl_account,acl_rights', array(
753 753
 			'acl_appname'  => $app,
754 754
 			'acl_location LIKE '.$this->db->quote($location),
755
-		),__LINE__,__FILE__) as $row)
755
+		), __LINE__, __FILE__) as $row)
756 756
 		{
757 757
 			if (($location = $row['acl_location']) != 'run')
758 758
 			{
Please login to merge, or discard this patch.
Braces   +81 added lines, -20 removed lines patch added patch discarded remove patch
@@ -119,7 +119,10 @@  discard block
 block discarded – undo
119 119
 		else
120 120
 		{
121 121
 			$acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true);
122
-			if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups);
122
+			if (is_array($no_groups))
123
+			{
124
+				$acl_acc_list = array_diff($acl_acc_list,$no_groups);
125
+			}
123 126
 			array_unshift($acl_acc_list,$this->account_id);
124 127
 		}
125 128
 
@@ -157,7 +160,10 @@  discard block
 block discarded – undo
157 160
 	 */
158 161
 	function add($appname,$location,$rights)
159 162
 	{
160
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
163
+		if (!$appname)
164
+		{
165
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
166
+		}
161 167
 
162 168
 		$row = array(
163 169
 			'appname'  => $appname,
@@ -179,7 +185,10 @@  discard block
 block discarded – undo
179 185
 	 */
180 186
 	function delete($appname,$location)
181 187
 	{
182
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
188
+		if (!$appname)
189
+		{
190
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
191
+		}
183 192
 
184 193
 		foreach($this->data as $idx => $value)
185 194
 		{
@@ -217,10 +226,13 @@  discard block
 block discarded – undo
217 226
 			}
218 227
 		}
219 228
 		if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] &&
220
-			method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
229
+			method_exists($GLOBALS['egw'],'invalidate_session_cache'))
230
+		{
231
+			// egw object in setup is limited
221 232
 		{
222 233
 			$GLOBALS['egw']->invalidate_session_cache();
223 234
 		}
235
+		}
224 236
 		return $this->data;
225 237
 	}
226 238
 
@@ -248,7 +260,10 @@  discard block
 block discarded – undo
248 260
 		{
249 261
 			$this->read_repository();
250 262
 		}
251
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
263
+		if (!$appname)
264
+		{
265
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
266
+		}
252 267
 
253 268
 		if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny')
254 269
 		{
@@ -297,7 +312,10 @@  discard block
 block discarded – undo
297 312
 	 */
298 313
 	function get_specific_rights($location, $appname = '', $memberships=array())
299 314
 	{
300
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
315
+		if (!$appname)
316
+		{
317
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
318
+		}
301 319
 
302 320
 		if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny')
303 321
 		{
@@ -362,10 +380,13 @@  discard block
 block discarded – undo
362 380
 		),__LINE__,__FILE__);
363 381
 
364 382
 		if ($invalidate_session && $account_id == $GLOBALS['egw_info']['user']['account_id'] &&
365
-			method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
383
+			method_exists($GLOBALS['egw'],'invalidate_session_cache'))
384
+		{
385
+			// egw object in setup is limited
366 386
 		{
367 387
 			$GLOBALS['egw']->invalidate_session_cache();
368 388
 		}
389
+		}
369 390
 		return True;
370 391
 	}
371 392
 
@@ -397,16 +418,22 @@  discard block
 block discarded – undo
397 418
 				$where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id);
398 419
 			}
399 420
 		}
400
-		if ($app == '%' || $app == '%%') unset($where['acl_appname']);
421
+		if ($app == '%' || $app == '%%')
422
+		{
423
+			unset($where['acl_appname']);
424
+		}
401 425
 
402 426
 		$this->db->delete(self::TABLE,$where,__LINE__,__FILE__);
403 427
 
404 428
 		$deleted = $this->db->affected_rows();
405 429
 
406
-		if ($invalidate_session && $deleted && method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
430
+		if ($invalidate_session && $deleted && method_exists($GLOBALS['egw'],'invalidate_session_cache'))
431
+		{
432
+			// egw object in setup is limited
407 433
 		{
408 434
 			$GLOBALS['egw']->invalidate_session_cache();
409 435
 		}
436
+		}
410 437
 		return $deleted;
411 438
 	}
412 439
 
@@ -420,7 +447,10 @@  discard block
 block discarded – undo
420 447
 	 */
421 448
 	function get_specific_rights_for_account($account_id,$location,$appname='')
422 449
 	{
423
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
450
+		if (!$appname)
451
+		{
452
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
453
+		}
424 454
 
425 455
 		return $this->db->select(self::TABLE,'acl_rights',array(
426 456
 			'acl_location' => $location,
@@ -438,7 +468,10 @@  discard block
 block discarded – undo
438 468
 	 */
439 469
 	function get_all_rights($location,$appname='')
440 470
 	{
441
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
471
+		if (!$appname)
472
+		{
473
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
474
+		}
442 475
 
443 476
 		$rights = array();
444 477
 		foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array(
@@ -461,7 +494,10 @@  discard block
 block discarded – undo
461 494
 	 */
462 495
 	function get_all_location_rights($account_id,$appname='',$use_memberships=true)
463 496
 	{
464
-		if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
497
+		if (!$appname)
498
+		{
499
+			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
500
+		}
465 501
 
466 502
 		$accounts = array($account_id);
467 503
 		if ($use_memberships && (int)$account_id > 0)
@@ -565,7 +601,10 @@  discard block
 block discarded – undo
565 601
 	 */
566 602
 	function get_ids_for_location($location, $required, $app = '')
567 603
 	{
568
-		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
604
+		if (!$app)
605
+		{
606
+			$app = $GLOBALS['egw_info']['flags']['currentapp'];
607
+		}
569 608
 
570 609
 		$accounts = false;
571 610
 		foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array(
@@ -589,7 +628,10 @@  discard block
 block discarded – undo
589 628
 	 */
590 629
 	function get_locations_for_app($app='')
591 630
 	{
592
-		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
631
+		if (!$app)
632
+		{
633
+			$app = $GLOBALS['egw_info']['flags']['currentapp'];
634
+		}
593 635
 
594 636
 		$locations = false;
595 637
 		foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array(
@@ -625,7 +667,10 @@  discard block
 block discarded – undo
625 667
 			$account_id = get_account_id($accountid,$this->account_id);
626 668
 			$cache_accountid[$accountid] = $account_id;
627 669
 		}
628
-		if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true);
670
+		if ($use_memberships && (int)$account_id > 0)
671
+		{
672
+			$memberships = $GLOBALS['egw']->accounts->memberships($account_id, true);
673
+		}
629 674
 		$memberships[] = (int)$account_id;
630 675
 
631 676
 		$apps = array();
@@ -659,15 +704,24 @@  discard block
 block discarded – undo
659 704
 	 */
660 705
 	function get_grants($app='',$enum_group_acls=true,$user=null)
661 706
 	{
662
-		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
663
-		if (!$user) $user = $this->account_id;
707
+		if (!$app)
708
+		{
709
+			$app = $GLOBALS['egw_info']['flags']['currentapp'];
710
+		}
711
+		if (!$user)
712
+		{
713
+			$user = $this->account_id;
714
+		}
664 715
 
665 716
 		static $cache = array();	// some caching withing the request
666 717
 
667 718
 		$grants =& $cache[$app][$user];
668 719
 		if (!isset($grants))
669 720
 		{
670
-			if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true);
721
+			if ((int)$user > 0)
722
+			{
723
+				$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
724
+			}
671 725
 			$memberships[] = $user;
672 726
 
673 727
 			$grants = $accounts = Array();
@@ -692,7 +746,11 @@  discard block
 block discarded – undo
692 746
 					// return the grant for each member of the group (false = also for no longer active users)
693 747
 					foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor)
694 748
 					{
695
-						if (!$grantor) continue;	// can happen if group has no members
749
+						if (!$grantor)
750
+						{
751
+							continue;
752
+						}
753
+						// can happen if group has no members
696 754
 
697 755
 						// Don't allow to override private with group ACL's!
698 756
 						$rights &= ~self::PRIVAT;
@@ -746,7 +804,10 @@  discard block
 block discarded – undo
746 804
 	 */
747 805
 	function get_location_grants($location,$app='')
748 806
 	{
749
-		if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
807
+		if (!$app)
808
+		{
809
+			$app = $GLOBALS['egw_info']['flags']['currentapp'];
810
+		}
750 811
 
751 812
 		$locations = array();
752 813
 		foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array(
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   +75 added lines, -77 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
 			}
@@ -640,7 +638,7 @@  discard block
 block discarded – undo
640 638
 	 *
641 639
 	 * @return int
642 640
 	 */
643
-	function installed(array &$other_cronlines=array())
641
+	function installed(array &$other_cronlines = array())
644 642
 	{
645 643
 		if ($this->only_fallback) {
646 644
 			return 0;
@@ -654,15 +652,15 @@  discard block
 block discarded – undo
654 652
 		}
655 653
 		$times = False;
656 654
 		$other_cronlines = array();
657
-		if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1','r')) !== False)
655
+		if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1', 'r')) !== False)
658 656
 		{
659 657
 			$n = 0;
660
-			while ($line = fgets($crontab,256))
658
+			while ($line = fgets($crontab, 256))
661 659
 			{
662 660
 				if ($this->debug) echo 'line '.++$n.": $line<br>\n";
663
-				$parts = explode(' ',$line,6);
661
+				$parts = explode(' ', $line, 6);
664 662
 
665
-				if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php'))
663
+				if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5], 0, 3) != 'php'))
666 664
 				{
667 665
 					// ignore comments
668 666
 					if ($line{0} != '#')
@@ -670,12 +668,12 @@  discard block
 block discarded – undo
670 668
 						$times['error'] .= $line;
671 669
 					}
672 670
 				}
673
-				elseif (strpos($line,$this->cronline) !== False ||
671
+				elseif (strpos($line, $this->cronline) !== False ||
674 672
 					// also check of old phpgwapi/cron path
675 673
 					strpos($line, str_replace('/api/', '/phpgwapi/cron/', $this->cronline)) !== False)
676 674
 				{
677
-					$cron_units = array('min','hour','day','month','dow');
678
-					foreach($cron_units as $n => $u)
675
+					$cron_units = array('min', 'hour', 'day', 'month', 'dow');
676
+					foreach ($cron_units as $n => $u)
679 677
 					{
680 678
 						$times[$u] = $parts[$n];
681 679
 					}
@@ -707,26 +705,26 @@  discard block
 block discarded – undo
707 705
 			return 0;
708 706
 		}
709 707
 		$other_cronlines = array();
710
-		$this->installed($other_cronlines);	// find other installed cronlines
708
+		$this->installed($other_cronlines); // find other installed cronlines
711 709
 
712
-		if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1','w')) !== False)
710
+		if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1', 'w')) !== False)
713 711
 		{
714 712
 			foreach ($other_cronlines as $cronline)
715 713
 			{
716
-				fwrite($crontab,$cronline);		// preserv the other lines on install
714
+				fwrite($crontab, $cronline); // preserv the other lines on install
717 715
 			}
718 716
 			if ($times !== False)
719 717
 			{
720
-				$cron_units = array('min','hour','day','month','dow');
718
+				$cron_units = array('min', 'hour', 'day', 'month', 'dow');
721 719
 				$cronline = '';
722
-				foreach($cron_units as $cu)
720
+				foreach ($cron_units as $cu)
723 721
 				{
724
-					$cronline .= (isset($times[$cu]) ? $times[$cu] : '*') . ' ';
722
+					$cronline .= (isset($times[$cu]) ? $times[$cu] : '*').' ';
725 723
 				}
726 724
 				// -d memory_limit=-1 --> no memory limit
727 725
 				$cronline .= $this->php.' -q -d memory_limit=-1 '.$this->cronline."\n";
728 726
 				//echo "<p>Installing: '$cronline'</p>\n";
729
-				fwrite($crontab,$cronline);
727
+				fwrite($crontab, $cronline);
730 728
 			}
731 729
 			@pclose($crontab);
732 730
 		}
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
 
@@ -642,7 +707,8 @@  discard block
 block discarded – undo
642 707
 	 */
643 708
 	function installed(array &$other_cronlines=array())
644 709
 	{
645
-		if ($this->only_fallback) {
710
+		if ($this->only_fallback)
711
+		{
646 712
 			return 0;
647 713
 		}
648 714
 		$this->find_binarys();
@@ -659,7 +725,10 @@  discard block
 block discarded – undo
659 725
 			$n = 0;
660 726
 			while ($line = fgets($crontab,256))
661 727
 			{
662
-				if ($this->debug) echo 'line '.++$n.": $line<br>\n";
728
+				if ($this->debug)
729
+				{
730
+					echo 'line '.++$n.": $line<br>\n";
731
+				}
663 732
 				$parts = explode(' ',$line,6);
664 733
 
665 734
 				if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php'))
@@ -703,7 +772,8 @@  discard block
 block discarded – undo
703 772
 	 */
704 773
 	function install($times)
705 774
 	{
706
-		if ($this->only_fallback && $times !== False) {
775
+		if ($this->only_fallback && $times !== False)
776
+		{
707 777
 			return 0;
708 778
 		}
709 779
 		$other_cronlines = array();
Please login to merge, or discard this patch.
api/src/Auth.php 4 patches
Doc Comments   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	 * check if users are supposed to change their password every x sdays, then check if password is of old age
85 85
 	 * or the devil-admin reset the users password and forced the user to change his password on next login.
86 86
 	 *
87
-	 * @param string& $message =null on return false: message why password needs to be changed
88
-	 * @return boolean true: all good, false: password change required, null: password expires in N days
87
+	 * @param string $message =null on return false: message why password needs to be changed
88
+	 * @return boolean|null true: all good, false: password change required, null: password expires in N days
89 89
 	 */
90 90
 	static function check_password_change(&$message=null)
91 91
 	{
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	 *
295 295
 	 * uses the encryption type set in setup and calls the appropriate encryption functions
296 296
 	 *
297
-	 * @param $password password to encrypt
297
+	 * @param string $password password to encrypt
298 298
 	 */
299 299
 	static function encrypt_password($password,$sql=False)
300 300
 	{
@@ -406,6 +406,7 @@  discard block
 block discarded – undo
406 406
 	 * @param string $form_val user input value for comparison
407 407
 	 * @param string $db_val   stored value / hash (from database)
408 408
 	 * @param string &$type    detected crypt type on return
409
+	 * @param string $type
409 410
 	 * @return boolean	 True on successful comparison
410 411
 	*/
411 412
 	static function crypt_compare($form_val, $db_val, &$type)
@@ -618,7 +619,7 @@  discard block
 block discarded – undo
618 619
 	 * @param string $forbid_name =null if "yes" username or full-name split by delimiters AND longer then 3 chars are
619 620
 	 *  forbidden to be included in password, default to whatever set in config for "passwd_forbid_name"
620 621
 	 * @param array|int $account =null array with account_lid and account_fullname or account_id for $forbid_name check
621
-	 * @return mixed false if password is considered "safe" (or no requirements) or a string $message if "unsafe"
622
+	 * @return string|false false if password is considered "safe" (or no requirements) or a string $message if "unsafe"
622 623
 	 */
623 624
 	static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null)
624 625
 	{
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	 * @param string $db_val   stored value / hash (from database)
408 408
 	 * @param string &$type    detected crypt type on return
409 409
 	 * @return boolean	 True on successful comparison
410
-	*/
410
+	 */
411 411
 	static function crypt_compare($form_val, $db_val, &$type)
412 412
 	{
413 413
 		// detect type of hash by salt part of $db_val
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 	 * @param string $form_val user input value for comparison
707 707
 	 * @param string $db_val stored value (from database)
708 708
 	 * @return boolean True on successful comparison
709
-	*/
709
+	 */
710 710
 	static function smd5_compare($form_val,$db_val)
711 711
 	{
712 712
 		/* Start with the first char after {SMD5} */
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 	 * @param string $form_val user input value for comparison
729 729
 	 * @param string $db_val   stored value (from database)
730 730
 	 * @return boolean True on successful comparison
731
-	*/
731
+	 */
732 732
 	static function sha_compare($form_val,$db_val)
733 733
 	{
734 734
 		/* Start with the first char after {SHA} */
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
 	 * @param string $form_val user input value for comparison
746 746
 	 * @param string $db_val   stored value (from database)
747 747
 	 * @return boolean	 True on successful comparison
748
-	*/
748
+	 */
749 749
 	static function ssha_compare($form_val,$db_val)
750 750
 	{
751 751
 		/* Start with the first char after {SSHA} */
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 {
21 21
 	$GLOBALS['egw_info']['server']['auth_type'] = $GLOBALS['egw_info']['server']['auth_type_'.$GLOBALS['egw_info']['flags']['currentapp']];
22 22
 }
23
-if(empty($GLOBALS['egw_info']['server']['auth_type']))
23
+if (empty($GLOBALS['egw_info']['server']['auth_type']))
24 24
 {
25 25
 	$GLOBALS['egw_info']['server']['auth_type'] = 'sql';
26 26
 }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @param Backend $type =null
67 67
 	 */
68
-	static function backend($type=null)
68
+	static function backend($type = null)
69 69
 	{
70 70
 		if (is_null($type)) $type = $GLOBALS['egw_info']['server']['auth_type'];
71 71
 
@@ -92,29 +92,29 @@  discard block
 block discarded – undo
92 92
 	 * @param string& $message =null on return false: message why password needs to be changed
93 93
 	 * @return boolean true: all good, false: password change required, null: password expires in N days
94 94
 	 */
95
-	static function check_password_change(&$message=null)
95
+	static function check_password_change(&$message = null)
96 96
 	{
97 97
 		// dont check anything for anonymous sessions/ users that are flagged as anonymous
98 98
 		if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') return true;
99 99
 
100 100
 		// some statics (and initialisation to make information and timecalculation a) more readable in conditions b) persistent per request
101 101
 		// if user has to be warned about an upcomming passwordchange, remember for the session, that he was informed
102
-		static $UserKnowsAboutPwdChange=null;
103
-		if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange');
102
+		static $UserKnowsAboutPwdChange = null;
103
+		if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange = & Cache::getSession('phpgwapi', 'auth_UserKnowsAboutPwdChange');
104 104
 
105 105
 		// retrieve the timestamp regarding the last change of the password from auth system and store it with the session
106
-		static $alpwchange_val=null;
107
-		static $pwdTsChecked=null;
106
+		static $alpwchange_val = null;
107
+		static $pwdTsChecked = null;
108 108
 		if (is_null($pwdTsChecked) && is_null($alpwchange_val) || (string)$alpwchange_val === '0')
109 109
 		{
110
-			$alpwchange_val =& Cache::getSession('phpgwapi','auth_alpwchange_val'); // set that one with the session stored value
110
+			$alpwchange_val = & Cache::getSession('phpgwapi', 'auth_alpwchange_val'); // set that one with the session stored value
111 111
 			// initalize statics - better readability of conditions
112 112
 			if (is_null($alpwchange_val) || (string)$alpwchange_val === '0')
113 113
 			{
114 114
 				$backend = self::backend();
115 115
 				// this may change behavior, as it should detect forced PasswordChanges from your Authentication System too.
116 116
 				// on the other side, if your auth system does not require an forcedPasswordChange, you will not be asked.
117
-				if (method_exists($backend,'getLastPwdChange'))
117
+				if (method_exists($backend, 'getLastPwdChange'))
118 118
 				{
119 119
 					$alpwchange_val = $backend->getLastPwdChange($GLOBALS['egw']->session->account_lid);
120 120
 					$pwdTsChecked = true;
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 				//error_log(__METHOD__.__LINE__.'#'.$alpwchange_val.'# is null:'.is_null($alpwchange_val).'# is empty:'.empty($alpwchange_val).'# is set:'.isset($alpwchange_val));
129 129
 			}
130 130
 		}
131
-		static $passwordAgeBorder=null;
132
-		static $daysLeftUntilChangeReq=null;
131
+		static $passwordAgeBorder = null;
132
+		static $daysLeftUntilChangeReq = null;
133 133
 
134 134
 		// if neither timestamp isset return true, nothing to do (exept this means the password is too old)
135 135
 		if (is_null($alpwchange_val) &&
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
 		}
140 140
 		if (is_null($passwordAgeBorder) && $GLOBALS['egw_info']['server']['change_pwd_every_x_days'])
141 141
 		{
142
-			$passwordAgeBorder = (DateTime::to('now','ts')-($GLOBALS['egw_info']['server']['change_pwd_every_x_days']*86400));
142
+			$passwordAgeBorder = (DateTime::to('now', 'ts') - ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] * 86400));
143 143
 		}
144 144
 		if (is_null($daysLeftUntilChangeReq) && $GLOBALS['egw_info']['server']['warn_about_upcoming_pwd_change'])
145 145
 		{
146 146
 			// maxage - passwordage = days left until change is required
147
-			$daysLeftUntilChangeReq = ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] - ((DateTime::to('now','ts')-($alpwchange_val?$alpwchange_val:0))/86400));
147
+			$daysLeftUntilChangeReq = ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] - ((DateTime::to('now', 'ts') - ($alpwchange_val ? $alpwchange_val : 0)) / 86400));
148 148
 		}
149
-		if ($alpwchange_val == 0 ||	// admin requested password change
150
-			$passwordAgeBorder > $alpwchange_val ||	// change password every N days policy requests change
149
+		if ($alpwchange_val == 0 || // admin requested password change
150
+			$passwordAgeBorder > $alpwchange_val || // change password every N days policy requests change
151 151
 			// user should be warned N days in advance about change and is not yet
152 152
 			$GLOBALS['egw_info']['server']['change_pwd_every_x_days'] &&
153 153
 			$GLOBALS['egw_info']['user']['apps']['preferences'] &&
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 				error_log(__METHOD__.' Password of '.$GLOBALS['egw_info']['user']['account_lid'].' ('.$GLOBALS['egw_info']['user']['account_fullname'].') is of old age.'.array2string(array(
165 165
 					'ts'=> $alpwchange_val,
166 166
 					'date'=>DateTime::to($alpwchange_val))));
167
-				$message = lang('It has been more then %1 days since you changed your password',$GLOBALS['egw_info']['server']['change_pwd_every_x_days']);
167
+				$message = lang('It has been more then %1 days since you changed your password', $GLOBALS['egw_info']['server']['change_pwd_every_x_days']);
168 168
 			}
169 169
 			else
170 170
 			{
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 				{
176 176
 					$UserKnowsAboutPwdChange = true;
177 177
 				}
178
-				$message = lang('Your password is about to expire in %1 days, you may change your password now',round($daysLeftUntilChangeReq));
178
+				$message = lang('Your password is about to expire in %1 days, you may change your password now', round($daysLeftUntilChangeReq));
179 179
 				// user has no rights to change password --> do NOT warn, as only forced check ignores rights
180 180
 				if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) return true;
181 181
 				return null;
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	function getLastPwdChange($username)
195 195
 	{
196
-		if (method_exists($this->backend,'getLastPwdChange'))
196
+		if (method_exists($this->backend, 'getLastPwdChange'))
197 197
 		{
198 198
 			return $this->backend->getLastPwdChange($username);
199 199
 		}
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
 	 * @param int $lastpwdchange must be a unixtimestamp
209 209
 	 * @return boolean true if account_lastpwd_change successful changed, false otherwise
210 210
 	 */
211
-	function setLastPwdChange($account_id=0, $passwd=NULL, $lastpwdchange=NULL)
211
+	function setLastPwdChange($account_id = 0, $passwd = NULL, $lastpwdchange = NULL)
212 212
 	{
213
-		if (method_exists($this->backend,'setLastPwdChange'))
213
+		if (method_exists($this->backend, 'setLastPwdChange'))
214 214
 		{
215 215
 			return $this->backend->setLastPwdChange($account_id, $passwd, $lastpwdchange);
216 216
 		}
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 * @param string $passwd_type ='text' 'text' for cleartext passwords (default)
226 226
 	 * @return boolean true if successful authenticated, false otherwise
227 227
 	 */
228
-	function authenticate($username, $passwd, $passwd_type='text')
228
+	function authenticate($username, $passwd, $passwd_type = 'text')
229 229
 	{
230 230
 		return $this->backend->authenticate($username, $passwd, $passwd_type);
231 231
 	}
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
 	 * @throws Exception from backends having extra requirements
241 241
 	 * @return boolean true if password successful changed, false otherwise
242 242
 	 */
243
-	function change_password($old_passwd, $new_passwd, $account_id=0)
243
+	function change_password($old_passwd, $new_passwd, $account_id = 0)
244 244
 	{
245
-		if (($err = self::crackcheck($new_passwd,null,null,null,$account_id)))
245
+		if (($err = self::crackcheck($new_passwd, null, null, null, $account_id)))
246 246
 		{
247 247
 			throw new Exception\WrongUserinput($err);
248 248
 		}
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 				// need to change current users password in session
254 254
 				Cache::setSession('phpgwapi', 'password', base64_encode($new_passwd));
255 255
 				$GLOBALS['egw_info']['user']['passwd'] = $new_passwd;
256
-				$GLOBALS['egw_info']['user']['account_lastpwd_change'] = DateTime::to('now','ts');
256
+				$GLOBALS['egw_info']['user']['account_lastpwd_change'] = DateTime::to('now', 'ts');
257 257
 				// invalidate EGroupware session, as password is stored in egw_info in session
258 258
 				Egw::invalidate_session_cache();
259 259
 			}
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 * @param string $new_passwd =null new password, default session password
274 274
 	 * @param int $account_id =null account_id, default current user
275 275
 	 */
276
-	static function changepwd($old_passwd, $new_passwd=null, $account_id=null)
276
+	static function changepwd($old_passwd, $new_passwd = null, $account_id = null)
277 277
 	{
278 278
 		if (!isset($account_id)) $account_id = $GLOBALS['egw']->session->account_id;
279 279
 		if (!isset($new_passwd)) $new_passwd = $GLOBALS['egw']->session->passwd;
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 			'old_passwd'  => $old_passwd,
286 286
 			'new_passwd'  => $new_passwd,
287 287
 		);
288
-		Hooks::process($GLOBALS['hook_values']+array(
288
+		Hooks::process($GLOBALS['hook_values'] + array(
289 289
 			'location' => 'changepassword'
290
-		),False,True);	// called for every app now, not only enabled ones)
290
+		), False, True); // called for every app now, not only enabled ones)
291 291
 	}
292 292
 
293 293
 	/**
@@ -295,13 +295,13 @@  discard block
 block discarded – undo
295 295
 	 *
296 296
 	 * @param $size int-size of random string to return
297 297
 	 */
298
-	static function randomstring($size, $use_specialchars=false)
298
+	static function randomstring($size, $use_specialchars = false)
299 299
 	{
300 300
 		$random_char = array(
301
-			'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f',
302
-			'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
303
-			'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L',
304
-			'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
301
+			'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
302
+			'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
303
+			'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
304
+			'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
305 305
 		);
306 306
 
307 307
 		// we need special chars
@@ -314,9 +314,9 @@  discard block
 block discarded – undo
314 314
 		$func = function_exists('random_int') ? 'random_int' : 'mt_rand';
315 315
 
316 316
 		$s = '';
317
-		for ($i=0; $i < $size; $i++)
317
+		for ($i = 0; $i < $size; $i++)
318 318
 		{
319
-			$s .= $random_char[$func(0, count($random_char)-1)];
319
+			$s .= $random_char[$func(0, count($random_char) - 1)];
320 320
 		}
321 321
 		return $s;
322 322
 	}
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
 	 *
329 329
 	 * @param $password password to encrypt
330 330
 	 */
331
-	static function encrypt_password($password,$sql=False)
331
+	static function encrypt_password($password, $sql = False)
332 332
 	{
333
-		if($sql)
333
+		if ($sql)
334 334
 		{
335 335
 			return self::encrypt_sql($password);
336 336
 		}
@@ -349,21 +349,21 @@  discard block
 block discarded – undo
349 349
 	 * @param string &$type =null on return detected type of hash
350 350
 	 * @return boolean
351 351
 	 */
352
-	static function compare_password($cleartext, $encrypted, $type_in, $username='', &$type=null)
352
+	static function compare_password($cleartext, $encrypted, $type_in, $username = '', &$type = null)
353 353
 	{
354 354
 		// allow to specify the hash type to prefix the hash, to easy migrate passwords from ldap
355 355
 		$type = $type_in;
356 356
 		$saved_enc = $encrypted;
357 357
 		$matches = null;
358
-		if (preg_match('/^\\{([a-z_5]+)\\}(.+)$/i',$encrypted,$matches))
358
+		if (preg_match('/^\\{([a-z_5]+)\\}(.+)$/i', $encrypted, $matches))
359 359
 		{
360 360
 			$type = strtolower($matches[1]);
361 361
 			$encrypted = $matches[2];
362 362
 
363
-			switch($type)	// some hashs are specially "packed" in ldap
363
+			switch ($type)	// some hashs are specially "packed" in ldap
364 364
 			{
365 365
 				case 'md5':
366
-					$encrypted = implode('',unpack('H*',base64_decode($encrypted)));
366
+					$encrypted = implode('', unpack('H*', base64_decode($encrypted)));
367 367
 					break;
368 368
 				case 'plain':
369 369
 				case 'crypt':
@@ -374,24 +374,24 @@  discard block
 block discarded – undo
374 374
 					break;
375 375
 			}
376 376
 		}
377
-		elseif($encrypted[0] == '$')
377
+		elseif ($encrypted[0] == '$')
378 378
 		{
379 379
 			$type = 'crypt';
380 380
 		}
381 381
 
382
-		switch($type)
382
+		switch ($type)
383 383
 		{
384 384
 			case 'plain':
385 385
 				$ret = $cleartext === $encrypted;
386 386
 				break;
387 387
 			case 'smd5':
388
-				$ret = self::smd5_compare($cleartext,$encrypted);
388
+				$ret = self::smd5_compare($cleartext, $encrypted);
389 389
 				break;
390 390
 			case 'sha':
391
-				$ret = self::sha_compare($cleartext,$encrypted);
391
+				$ret = self::sha_compare($cleartext, $encrypted);
392 392
 				break;
393 393
 			case 'ssha':
394
-				$ret = self::ssha_compare($cleartext,$encrypted);
394
+				$ret = self::ssha_compare($cleartext, $encrypted);
395 395
 				break;
396 396
 			case 'crypt':
397 397
 			case 'des':
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 				$ret = self::crypt_compare($cleartext, $encrypted, $type);
405 405
 				break;
406 406
 			case 'md5_hmac':
407
-				$ret = self::md5_hmac_compare($cleartext,$encrypted,$username);
407
+				$ret = self::md5_hmac_compare($cleartext, $encrypted, $username);
408 408
 				break;
409 409
 			default:
410 410
 				$type = 'md5';
@@ -427,9 +427,9 @@  discard block
 block discarded – undo
427 427
 		'ext_crypt' => array('CRYPT_EXT_DES', '_J9..', 4, ''),
428 428
 		'md5_crypt' => array('CRYPT_MD5', '$1$', 8, '$'),
429 429
 		//'old_blowfish_crypt' => array('CRYPT_BLOWFISH', '$2$', 13, ''),	// old blowfish hash not in line with php.net docu, but could be in use
430
-		'blowfish_crypt' => array('CRYPT_BLOWFISH', '$2a$12$', 22, ''),	// $2a$12$ = 2^12 = 4096 rounds
431
-		'sha256_crypt' => array('CRYPT_SHA256', '$5$', 16, '$'),	// no "round=N$" --> default of 5000 rounds
432
-		'sha512_crypt' => array('CRYPT_SHA512', '$6$', 16, '$'),	// no "round=N$" --> default of 5000 rounds
430
+		'blowfish_crypt' => array('CRYPT_BLOWFISH', '$2a$12$', 22, ''), // $2a$12$ = 2^12 = 4096 rounds
431
+		'sha256_crypt' => array('CRYPT_SHA256', '$5$', 16, '$'), // no "round=N$" --> default of 5000 rounds
432
+		'sha512_crypt' => array('CRYPT_SHA512', '$6$', 16, '$'), // no "round=N$" --> default of 5000 rounds
433 433
 	);
434 434
 
435 435
 	/**
@@ -444,17 +444,17 @@  discard block
 block discarded – undo
444 444
 	{
445 445
 		// detect type of hash by salt part of $db_val
446 446
 		list($first, $dollar, $salt, $salt2) = explode('$', $db_val);
447
-		foreach(self::$crypt_params as $type => $params)
447
+		foreach (self::$crypt_params as $type => $params)
448 448
 		{
449 449
 			list(,$prefix, $random, $postfix) = $params;
450 450
 			list(,$d) = explode('$', $prefix);
451 451
 			if ($dollar === $d || !$dollar && ($first[0] === $prefix[0] || $first[0] !== '_' && !$prefix))
452 452
 			{
453
-				$len = !$postfix ? strlen($prefix)+$random : strlen($prefix.$salt.$postfix);
453
+				$len = !$postfix ? strlen($prefix) + $random : strlen($prefix.$salt.$postfix);
454 454
 				// sha(256|512) might contain options, explicit $rounds=N$ prefix in salt
455 455
 				if (($type == 'sha256_crypt' || $type == 'sha512_crypt') && substr($salt, 0, 7) === 'rounds=')
456 456
 				{
457
-					$len += strlen($salt2)+1;
457
+					$len += strlen($salt2) + 1;
458 458
 				}
459 459
 				break;
460 460
 			}
@@ -476,12 +476,12 @@  discard block
 block discarded – undo
476 476
 	 * @param string $type =null default to $GLOBALS['egw_info']['server']['ldap_encryption_type']
477 477
 	 * @return string
478 478
 	 */
479
-	static function encrypt_ldap($password, $type=null)
479
+	static function encrypt_ldap($password, $type = null)
480 480
 	{
481 481
 		if (is_null($type)) $type = $GLOBALS['egw_info']['server']['ldap_encryption_type'];
482 482
 
483 483
 		$salt = '';
484
-		switch(strtolower($type))
484
+		switch (strtolower($type))
485 485
 		{
486 486
 			default:	// eg. setup >> config never saved
487 487
 			case 'des':
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 			case 'md5_crypt':
496 496
 			case 'ext_crypt':
497 497
 				list($const, $prefix, $len, $postfix) = self::$crypt_params[$type];
498
-				if(defined($const) && constant($const) == 1)
498
+				if (defined($const) && constant($const) == 1)
499 499
 				{
500 500
 					$salt = $prefix.self::randomstring($len).$postfix;
501 501
 					$e_password = '{crypt}'.crypt($password, $salt);
@@ -508,20 +508,20 @@  discard block
 block discarded – undo
508 508
 				/* New method taken from the openldap-software list as recommended by
509 509
 				 * Kervin L. Pierre" <[email protected]>
510 510
 				 */
511
-				$e_password = '{md5}' . base64_encode(pack("H*",md5($password)));
511
+				$e_password = '{md5}'.base64_encode(pack("H*", md5($password)));
512 512
 				break;
513 513
 			case 'smd5':
514 514
 				$salt = self::randomstring(16);
515
-				$hash = md5($password . $salt, true);
516
-				$e_password = '{SMD5}' . base64_encode($hash . $salt);
515
+				$hash = md5($password.$salt, true);
516
+				$e_password = '{SMD5}'.base64_encode($hash.$salt);
517 517
 				break;
518 518
 			case 'sha':
519
-				$e_password = '{SHA}' . base64_encode(sha1($password,true));
519
+				$e_password = '{SHA}'.base64_encode(sha1($password, true));
520 520
 				break;
521 521
 			case 'ssha':
522 522
 				$salt = self::randomstring(16);
523
-				$hash = sha1($password . $salt, true);
524
-				$e_password = '{SSHA}' . base64_encode($hash . $salt);
523
+				$hash = sha1($password.$salt, true);
524
+				$e_password = '{SSHA}'.base64_encode($hash.$salt);
525 525
 				break;
526 526
 			case 'plain':
527 527
 				// if plain no type is prepended
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 	 * @param string $type =null default $GLOBALS['egw_info']['server']['sql_encryption_type'], if valid otherwise blowfish_crypt
540 540
 	 * @return string hash
541 541
 	 */
542
-	static function encrypt_sql($password, $type=null)
542
+	static function encrypt_sql($password, $type = null)
543 543
 	{
544 544
 		/* Grab configured type, or default to md5() (old method) */
545 545
 		if (is_null($type))
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 			$type = @$GLOBALS['egw_info']['server']['sql_encryption_type'] ?
548 548
 				strtolower($GLOBALS['egw_info']['server']['sql_encryption_type']) : 'md5';
549 549
 		}
550
-		switch($type)
550
+		switch ($type)
551 551
 		{
552 552
 			case 'plain':
553 553
 				// since md5 is the default, type plain must be prepended, for eGroupware to understand
@@ -587,28 +587,28 @@  discard block
 block discarded – undo
587 587
 	 * @param string &$securest =null on return securest available hash
588 588
 	 * @return array hash => label
589 589
 	 */
590
-	public static function passwdhashes(&$securest=null)
590
+	public static function passwdhashes(&$securest = null)
591 591
 	{
592 592
 		$hashes = array();
593 593
 
594 594
 		/* Check for available crypt methods based on what is defined by php */
595
-		if(defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1)
595
+		if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1)
596 596
 		{
597 597
 			$hashes['blowfish_crypt'] = 'blowfish_crypt';
598 598
 		}
599
-		if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1)
599
+		if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1)
600 600
 		{
601 601
 			$hashes['sha512_crypt'] = 'sha512_crypt';
602 602
 		}
603
-		if(defined('CRYPT_SHA256') && CRYPT_SHA256 == 1)
603
+		if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1)
604 604
 		{
605 605
 			$hashes['sha256_crypt'] = 'sha256_crypt';
606 606
 		}
607
-		if(defined('CRYPT_MD5') && CRYPT_MD5 == 1)
607
+		if (defined('CRYPT_MD5') && CRYPT_MD5 == 1)
608 608
 		{
609 609
 			$hashes['md5_crypt'] = 'md5_crypt';
610 610
 		}
611
-		if(defined('CRYPT_EXT_DES') && CRYPT_EXT_DES == 1)
611
+		if (defined('CRYPT_EXT_DES') && CRYPT_EXT_DES == 1)
612 612
 		{
613 613
 			$hashes['ext_crypt'] = 'ext_crypt';
614 614
 		}
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 			'smd5' => 'smd5',
618 618
 			'sha'  => 'sha',
619 619
 		);
620
-		if(@defined('CRYPT_STD_DES') && CRYPT_STD_DES == 1)
620
+		if (@defined('CRYPT_STD_DES') && CRYPT_STD_DES == 1)
621 621
 		{
622 622
 			$hashes['crypt'] = 'crypt';
623 623
 		}
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 	 * @param array|int $account =null array with account_lid and account_fullname or account_id for $forbid_name check
651 651
 	 * @return mixed false if password is considered "safe" (or no requirements) or a string $message if "unsafe"
652 652
 	 */
653
-	static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null)
653
+	static function crackcheck($passwd, $reqstrength = null, $minlength = null, $forbid_name = null, $account = null)
654 654
 	{
655 655
 		if (!isset($reqstrength)) $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength'];
656 656
 		if (!isset($minlength)) $minlength = $GLOBALS['egw_info']['server']['force_pwd_length'];
@@ -664,11 +664,11 @@  discard block
 block discarded – undo
664 664
 		{
665 665
 			if (!isset($reqstrength) || $reqstrength == 5)
666 666
 			{
667
-				Config::save_value('force_pwd_strength', $reqstrength=4, 'phpgwapi');
667
+				Config::save_value('force_pwd_strength', $reqstrength = 4, 'phpgwapi');
668 668
 			}
669 669
 			if (!isset($minlength))
670 670
 			{
671
-				Config::save_value('force_pwd_length', $minlength=7, 'phpgwapi');
671
+				Config::save_value('force_pwd_length', $minlength = 7, 'phpgwapi');
672 672
 			}
673 673
 			Config::save_value('check_save_passwd', null, 'phpgwapi');
674 674
 		}
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 				throw new Exception\WrongParameter('crackcheck(..., forbid_name=true, account) requires account-data!');
688 688
 			}
689 689
 			$parts = preg_split("/[,._ \t0-9-]+/", $account['account_fullname'].','.$account['account_lid']);
690
-			foreach($parts as $part)
690
+			foreach ($parts as $part)
691 691
 			{
692 692
 				if (strlen($part) > 2 && stripos($passwd, $part) !== false)
693 693
 				{
@@ -700,15 +700,15 @@  discard block
 block discarded – undo
700 700
 		if ($reqstrength)
701 701
 		{
702 702
 			$missing = array();
703
-			if (!preg_match('/(.*\d.*){'. ($non=1). ',}/',$passwd))
703
+			if (!preg_match('/(.*\d.*){'.($non = 1).',}/', $passwd))
704 704
 			{
705 705
 				$missing[] = lang('numbers');
706 706
 			}
707
-			if (!preg_match('/(.*[[:upper:]].*){'. ($nou=1). ',}/',$passwd))
707
+			if (!preg_match('/(.*[[:upper:]].*){'.($nou = 1).',}/', $passwd))
708 708
 			{
709 709
 				$missing[] = lang('uppercase letters');
710 710
 			}
711
-			if (!preg_match('/(.*[[:lower:]].*){'. ($nol=1). ',}/',$passwd))
711
+			if (!preg_match('/(.*[[:lower:]].*){'.($nol = 1).',}/', $passwd))
712 712
 			{
713 713
 				$missing[] = lang('lowercase letters');
714 714
 			}
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 			if (4 - count($missing) < $reqstrength)
720 720
 			{
721 721
 				$errors[] = lang('password contains only %1 of required %2 character classes: no %3',
722
-					4-count($missing), $reqstrength, implode(', ', $missing));
722
+					4 - count($missing), $reqstrength, implode(', ', $missing));
723 723
 			}
724 724
 		}
725 725
 		if ($errors)
@@ -737,19 +737,19 @@  discard block
 block discarded – undo
737 737
 	 * @param string $db_val stored value (from database)
738 738
 	 * @return boolean True on successful comparison
739 739
 	*/
740
-	static function smd5_compare($form_val,$db_val)
740
+	static function smd5_compare($form_val, $db_val)
741 741
 	{
742 742
 		/* Start with the first char after {SMD5} */
743
-		$hash = base64_decode(substr($db_val,6));
743
+		$hash = base64_decode(substr($db_val, 6));
744 744
 
745 745
 		/* SMD5 hashes are 16 bytes long */
746
-		$orig_hash = cut_bytes($hash, 0, 16);	// binary string need to use cut_bytes, not mb_substr(,,'utf-8')!
746
+		$orig_hash = cut_bytes($hash, 0, 16); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')!
747 747
 		$salt = cut_bytes($hash, 16);
748 748
 
749
-		$new_hash = md5($form_val . $salt,true);
749
+		$new_hash = md5($form_val.$salt, true);
750 750
 		//echo '<br>  DB: ' . base64_encode($orig_hash) . '<br>FORM: ' . base64_encode($new_hash);
751 751
 
752
-		return strcmp($orig_hash,$new_hash) == 0;
752
+		return strcmp($orig_hash, $new_hash) == 0;
753 753
 	}
754 754
 
755 755
 	/**
@@ -759,14 +759,14 @@  discard block
 block discarded – undo
759 759
 	 * @param string $db_val   stored value (from database)
760 760
 	 * @return boolean True on successful comparison
761 761
 	*/
762
-	static function sha_compare($form_val,$db_val)
762
+	static function sha_compare($form_val, $db_val)
763 763
 	{
764 764
 		/* Start with the first char after {SHA} */
765
-		$hash = base64_decode(substr($db_val,5));
766
-		$new_hash = sha1($form_val,true);
765
+		$hash = base64_decode(substr($db_val, 5));
766
+		$new_hash = sha1($form_val, true);
767 767
 		//echo '<br>  DB: ' . base64_encode($orig_hash) . '<br>FORM: ' . base64_encode($new_hash);
768 768
 
769
-		return strcmp($hash,$new_hash) == 0;
769
+		return strcmp($hash, $new_hash) == 0;
770 770
 	}
771 771
 
772 772
 	/**
@@ -776,18 +776,18 @@  discard block
 block discarded – undo
776 776
 	 * @param string $db_val   stored value (from database)
777 777
 	 * @return boolean	 True on successful comparison
778 778
 	*/
779
-	static function ssha_compare($form_val,$db_val)
779
+	static function ssha_compare($form_val, $db_val)
780 780
 	{
781 781
 		/* Start with the first char after {SSHA} */
782 782
 		$hash = base64_decode(substr($db_val, 6));
783 783
 
784 784
 		// SHA-1 hashes are 160 bits long
785
-		$orig_hash = cut_bytes($hash, 0, 20);	// binary string need to use cut_bytes, not mb_substr(,,'utf-8')!
785
+		$orig_hash = cut_bytes($hash, 0, 20); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')!
786 786
 		$salt = cut_bytes($hash, 20);
787
-		$new_hash = sha1($form_val . $salt,true);
787
+		$new_hash = sha1($form_val.$salt, true);
788 788
 
789 789
 		//error_log(__METHOD__."('$form_val', '$db_val') hash='$hash', orig_hash='$orig_hash', salt='$salt', new_hash='$new_hash' returning ".array2string(strcmp($orig_hash,$new_hash) == 0));
790
-		return strcmp($orig_hash,$new_hash) == 0;
790
+		return strcmp($orig_hash, $new_hash) == 0;
791 791
 	}
792 792
 
793 793
 	/**
@@ -798,11 +798,11 @@  discard block
 block discarded – undo
798 798
 	 * @param string $_key       key for md5_hmac-encryption (username for imported smf users)
799 799
 	 * @return boolean	 True on successful comparison
800 800
 	 */
801
-	static function md5_hmac_compare($form_val,$db_val,$_key)
801
+	static function md5_hmac_compare($form_val, $db_val, $_key)
802 802
 	{
803 803
 		$key = str_pad(strlen($_key) <= 64 ? $_key : pack('H*', md5($_key)), 64, chr(0x00));
804
-		$md5_hmac = md5(($key ^ str_repeat(chr(0x5c), 64)) . pack('H*', md5(($key ^ str_repeat(chr(0x36), 64)). $form_val)));
804
+		$md5_hmac = md5(($key^str_repeat(chr(0x5c), 64)).pack('H*', md5(($key^str_repeat(chr(0x36), 64)).$form_val)));
805 805
 
806
-		return strcmp($md5_hmac,$db_val) == 0;
806
+		return strcmp($md5_hmac, $db_val) == 0;
807 807
 	}
808 808
 }
Please login to merge, or discard this patch.
Braces   +40 added lines, -10 removed lines patch added patch discarded remove patch
@@ -67,7 +67,10 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	static function backend($type=null)
69 69
 	{
70
-		if (is_null($type)) $type = $GLOBALS['egw_info']['server']['auth_type'];
70
+		if (is_null($type))
71
+		{
72
+			$type = $GLOBALS['egw_info']['server']['auth_type'];
73
+		}
71 74
 
72 75
 		$backend_class = __CLASS__.'\\'.ucfirst($type);
73 76
 
@@ -95,12 +98,18 @@  discard block
 block discarded – undo
95 98
 	static function check_password_change(&$message=null)
96 99
 	{
97 100
 		// dont check anything for anonymous sessions/ users that are flagged as anonymous
98
-		if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') return true;
101
+		if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A')
102
+		{
103
+			return true;
104
+		}
99 105
 
100 106
 		// some statics (and initialisation to make information and timecalculation a) more readable in conditions b) persistent per request
101 107
 		// if user has to be warned about an upcomming passwordchange, remember for the session, that he was informed
102 108
 		static $UserKnowsAboutPwdChange=null;
103
-		if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange');
109
+		if (is_null($UserKnowsAboutPwdChange))
110
+		{
111
+			$UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange');
112
+		}
104 113
 
105 114
 		// retrieve the timestamp regarding the last change of the password from auth system and store it with the session
106 115
 		static $alpwchange_val=null;
@@ -177,7 +186,10 @@  discard block
 block discarded – undo
177 186
 				}
178 187
 				$message = lang('Your password is about to expire in %1 days, you may change your password now',round($daysLeftUntilChangeReq));
179 188
 				// user has no rights to change password --> do NOT warn, as only forced check ignores rights
180
-				if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) return true;
189
+				if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences'))
190
+				{
191
+					return true;
192
+				}
181 193
 				return null;
182 194
 			}
183 195
 			return false;
@@ -275,8 +287,14 @@  discard block
 block discarded – undo
275 287
 	 */
276 288
 	static function changepwd($old_passwd, $new_passwd=null, $account_id=null)
277 289
 	{
278
-		if (!isset($account_id)) $account_id = $GLOBALS['egw']->session->account_id;
279
-		if (!isset($new_passwd)) $new_passwd = $GLOBALS['egw']->session->passwd;
290
+		if (!isset($account_id))
291
+		{
292
+			$account_id = $GLOBALS['egw']->session->account_id;
293
+		}
294
+		if (!isset($new_passwd))
295
+		{
296
+			$new_passwd = $GLOBALS['egw']->session->passwd;
297
+		}
280 298
 
281 299
 		// run changepwasswd hook
282 300
 		$GLOBALS['hook_values'] = array(
@@ -478,7 +496,10 @@  discard block
 block discarded – undo
478 496
 	 */
479 497
 	static function encrypt_ldap($password, $type=null)
480 498
 	{
481
-		if (is_null($type)) $type = $GLOBALS['egw_info']['server']['ldap_encryption_type'];
499
+		if (is_null($type))
500
+		{
501
+			$type = $GLOBALS['egw_info']['server']['ldap_encryption_type'];
502
+		}
482 503
 
483 504
 		$salt = '';
484 505
 		switch(strtolower($type))
@@ -652,9 +673,18 @@  discard block
 block discarded – undo
652 673
 	 */
653 674
 	static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null)
654 675
 	{
655
-		if (!isset($reqstrength)) $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength'];
656
-		if (!isset($minlength)) $minlength = $GLOBALS['egw_info']['server']['force_pwd_length'];
657
-		if (!isset($forbid_name)) $forbid_name = $GLOBALS['egw_info']['server']['passwd_forbid_name'];
676
+		if (!isset($reqstrength))
677
+		{
678
+			$reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength'];
679
+		}
680
+		if (!isset($minlength))
681
+		{
682
+			$minlength = $GLOBALS['egw_info']['server']['force_pwd_length'];
683
+		}
684
+		if (!isset($forbid_name))
685
+		{
686
+			$forbid_name = $GLOBALS['egw_info']['server']['passwd_forbid_name'];
687
+		}
658 688
 
659 689
 		// load preferences translations, as changepassword get's called from admin too
660 690
 		Translation::add_app('preferences');
Please login to merge, or discard this patch.