Completed
Push — master ( 9d054b...106a1b )
by Klaus
23:45 queued 04:19
created
importexport/inc/class.importexport_definitions_bo.inc.php 5 patches
Doc Comments   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -139,7 +139,6 @@  discard block
 block discarded – undo
139 139
 	/**
140 140
 	* Save a definition
141 141
 	*
142
-	* @param definition $definition
143 142
 	*/
144 143
 	public function save(Array $data) {
145 144
 		$definition = new importexport_definition();
@@ -209,7 +208,7 @@  discard block
 block discarded – undo
209 208
 	/**
210 209
 	 * imports definitions from file
211 210
 	 *
212
-	 * @param string $import_file
211
+	 * @param string $_import_file
213 212
 	 * @throws Exeption
214 213
 	 * @return void
215 214
 	 */
@@ -268,7 +267,6 @@  discard block
 block discarded – undo
268 267
 	 * It is not possible to handle some plugin options automatically, because they
269 268
 	 * just don't have equivalents.  (eg: What to do with unknown categories)
270 269
 	 *
271
-	 * @param importexport_definition $definition Import definition
272 270
 	 *
273 271
 	 * @return importexport_definition Export definition
274 272
 	 */
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -137,10 +137,10 @@
 block discarded – undo
137 137
 	}
138 138
 
139 139
 	/**
140
-	* Save a definition
141
-	*
142
-	* @param definition $definition
143
-	*/
140
+	 * Save a definition
141
+	 *
142
+	 * @param definition $definition
143
+	 */
144 144
 	public function save(Array $data) {
145 145
 		$definition = new importexport_definition();
146 146
 		$definition->set_record($data);
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	private $definitions;
33 33
 
34
-	public function __construct($_query=false, $ignore_acl = false)
34
+	public function __construct($_query = false, $ignore_acl = false)
35 35
 	{
36
-		$this->so_sql = new Api\Storage\Base(self::_appname, self::_defintion_table );
36
+		$this->so_sql = new Api\Storage\Base(self::_appname, self::_defintion_table);
37 37
 		if ($_query) {
38 38
 			$definitions = $this->so_sql->search($_query, false);
39 39
 			foreach ((array)$definitions as $definition) {
40
-				if(self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id'];
40
+				if (self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id'];
41 41
 			}
42 42
 		}
43 43
 	}
@@ -45,16 +45,16 @@  discard block
 block discarded – undo
45 45
 	public function get_rows(&$query, &$rows, &$readonlys)
46 46
 	{
47 47
 		// Filter only definitions user is allowed to use
48
-		if(!$GLOBALS['egw_info']['user']['apps']['admin']) {
48
+		if (!$GLOBALS['egw_info']['user']['apps']['admin']) {
49 49
 			$this_membership = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true);
50 50
 			$this_membership[] = $GLOBALS['egw_info']['user']['account_id'];
51 51
 			$sql .= ' (';
52 52
 			$read = array();
53
-			foreach($this_membership as $id)
53
+			foreach ($this_membership as $id)
54 54
 			{
55 55
 				$read[] = 'allowed_users '.
56 56
 					$GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '.
57
-					$GLOBALS['egw']->db->quote('%,'.str_replace('_','\\_',$id) .',%');
57
+					$GLOBALS['egw']->db->quote('%,'.str_replace('_', '\\_', $id).',%');
58 58
 			}
59 59
 			$sql .= implode(' OR ', $read);
60 60
 			$sql .= ') OR owner = '.$GLOBALS['egw_info']['user']['account_id'];
@@ -62,37 +62,37 @@  discard block
 block discarded – undo
62 62
 		}
63 63
 		
64 64
 		// Handle allowed filter
65
-		if($query['col_filter']['allowed_users'])
65
+		if ($query['col_filter']['allowed_users'])
66 66
 		{
67 67
 			$allowed = array();
68
-			foreach((array)$query['col_filter']['allowed_users'] as $id)
68
+			foreach ((array)$query['col_filter']['allowed_users'] as $id)
69 69
 			{
70 70
 				$allowed[] = 'allowed_users '.
71 71
 					$GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '.
72
-					$GLOBALS['egw']->db->quote('%,'.str_replace('_','\\_',$id) .',%');
72
+					$GLOBALS['egw']->db->quote('%,'.str_replace('_', '\\_', $id).',%');
73 73
 			}
74
-			if($allowed)
74
+			if ($allowed)
75 75
 			{
76 76
 				unset($query['col_filter']['allowed_users']);
77
-				$query['col_filter'][] = '('.implode(' OR ', $allowed) . ')';
77
+				$query['col_filter'][] = '('.implode(' OR ', $allowed).')';
78 78
 			}
79 79
 		}
80 80
 		
81 81
 		$total = $this->so_sql->get_rows($query, $rows, $readonlys);
82 82
 		$ro_count = 0;
83
-		foreach($rows as &$row) {
83
+		foreach ($rows as &$row) {
84 84
 			// Strip off leading + trailing ,
85
-			$row['allowed_users'] = substr($row['allowed_users'],1,-1);
85
+			$row['allowed_users'] = substr($row['allowed_users'], 1, -1);
86 86
 
87 87
 			$readonlys["edit[{$row['definition_id']}]"] = $readonlys["delete[{$row['definition_id']}]"] =
88 88
 				($row['owner'] != $GLOBALS['egw_info']['user']['account_id']) &&
89 89
 				!$GLOBALS['egw_info']['user']['apps']['admin'];
90
-			if($readonlys["edit[{$row['definition_id']}]"])
90
+			if ($readonlys["edit[{$row['definition_id']}]"])
91 91
 			{
92 92
 				$row['class'] .= 'rowNoEdit rowNoDelete';
93 93
 				$ro_count++;
94 94
 			}
95
-			$row['class'] .= ' ' . $row['type'];
95
+			$row['class'] .= ' '.$row['type'];
96 96
 		}
97 97
 		$readonlys['delete_selected'] = $ro_count == count($rows);
98 98
 		return $total;
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 		return $this->definitions;
108 108
 	}
109 109
 	public function read($definition_id) {
110
-		if(is_numeric($definition_id)) {
110
+		if (is_numeric($definition_id)) {
111 111
 			$this->so_sql->read($definition_id);
112 112
 			$definition = new importexport_definition($this->so_sql->data['name']);
113 113
 		} else {
114
-			$definition = new importexport_definition( $definition_id['name'] );
114
+			$definition = new importexport_definition($definition_id['name']);
115 115
 		}
116 116
 		return $definition->get_record_array();
117 117
 	}
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
 		foreach ($keys as $index => $key) {
125 125
 			// Check for ownership
126 126
 			$definition = $this->read($key);
127
-			if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) {
127
+			if ($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) {
128 128
 				// clear private cache
129
-				unset($this->definitions[array_search($key,$this->definitions)]);
129
+				unset($this->definitions[array_search($key, $this->definitions)]);
130 130
 			} else {
131 131
 				unset($keys[$index]);
132 132
 			}
133 133
 		}
134
-		if(count($keys) > 0) {
134
+		if (count($keys) > 0) {
135 135
 			$this->so_sql->delete(array('definition_id' => $keys));
136 136
 		}
137 137
 	}
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 	 * @return bool
155 155
 	 */
156 156
 	static public function is_permitted($_definition) {
157
-		$allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']);
157
+		$allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',', $_definition['allowed_users']);
158 158
 		$this_user_id = $GLOBALS['egw_info']['user']['account_id'];
159 159
 		$this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true);
160 160
 		$this_membership[] = $this_user_id;
161 161
 		$this_membership[] = 'all';
162
-		$alluser = array_intersect($allowed_user,$this_membership);
162
+		$alluser = array_intersect($allowed_user, $this_membership);
163 163
 		return ($this_user_id == $_definition['owner'] || count($alluser) > 0);
164 164
 	}
165 165
 
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 
179 179
 		$export_data['definitions'] = array();
180 180
 		foreach ($keys as $definition_id) {
181
-			$definition = new importexport_definition( $definition_id );
181
+			$definition = new importexport_definition($definition_id);
182 182
 			$export_data['definitions'][$definition->name] = $definition->get_record_array();
183 183
 			$export_data['definitions'][$definition->name]['allowed_users'] =
184 184
 				importexport_helper_functions::account_id2name(
185 185
 					$export_data['definitions'][$definition->name]['allowed_users']
186 186
 				);
187
-			if($export_date['definitions'][$definition->name]['owner']) {
187
+			if ($export_date['definitions'][$definition->name]['owner']) {
188 188
 				$export_data['definitions'][$definition->name]['owner'] =
189 189
 					importexport_helper_functions::account_id2name(
190 190
 						$export_data['definitions'][$definition->name]['owner']
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 			unset($export_data['definitions'][$definition->name]['definition_id']);
196 196
 			unset($export_data['definitions'][$definition->name]['description']);
197 197
 			unset($export_data['definitions'][$definition->name]['user_timezone_read']);
198
-			if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) {
198
+			if (is_array($export_data['definitions'][$definition->name]['plugin_options'])) {
199 199
 				unset($export_data['definitions'][$definition->name]['plugin_options']['user_timezone_read']);
200 200
 			}
201 201
 			unset($definition);
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
 	 * @throws Exeption
214 214
 	 * @return void
215 215
 	 */
216
-	public static function import( $_import_file )
216
+	public static function import($_import_file)
217 217
 	{
218
-		if ( !is_file( $_import_file ) ) {
219
-			throw new Exception("'$_import_file' does not exist or is not readable" );
218
+		if (!is_file($_import_file)) {
219
+			throw new Exception("'$_import_file' does not exist or is not readable");
220 220
 		}
221 221
 
222
-		$data = importexport_arrayxml::xml2array( file_get_contents( $_import_file ) );
222
+		$data = importexport_arrayxml::xml2array(file_get_contents($_import_file));
223 223
 
224 224
 		$metainfo = $data['importExportDefinitions']['metainfo'];
225 225
 		$definitions = $data['importExportDefinitions']['definitions'];
226
-		unset ( $data );
226
+		unset ($data);
227 227
 
228 228
 		// convert charset into internal used charset
229 229
 		$definitions = Api\Translation::convert(
@@ -233,26 +233,26 @@  discard block
 block discarded – undo
233 233
 		);
234 234
 
235 235
 		// Avoid warning if no definitions found
236
-		if(!is_array($definitions)) return lang('None found');
236
+		if (!is_array($definitions)) return lang('None found');
237 237
 
238 238
 		// save definition(s) into internal table
239
-		foreach ( $definitions as $name => $definition_data )
239
+		foreach ($definitions as $name => $definition_data)
240 240
 		{
241 241
 			// convert allowed_user
242
-			$definition_data['allowed_users'] = importexport_helper_functions::account_name2id( $definition_data['allowed_users'] );
243
-			if($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all';
242
+			$definition_data['allowed_users'] = importexport_helper_functions::account_name2id($definition_data['allowed_users']);
243
+			if ($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all';
244 244
 
245
-			$definition_data['owner'] = importexport_helper_functions::account_name2id( $definition_data['owner'] );
245
+			$definition_data['owner'] = importexport_helper_functions::account_name2id($definition_data['owner']);
246 246
 
247
-			$definition = new importexport_definition( $definition_data['name'] );
247
+			$definition = new importexport_definition($definition_data['name']);
248 248
 
249 249
 			// Only update if the imported is newer
250
-			if(strtotime($definition->modified) < strtotime($definition_data['modified']) || $definition->modified == 0)
250
+			if (strtotime($definition->modified) < strtotime($definition_data['modified']) || $definition->modified == 0)
251 251
 			{
252 252
 				$definition_id = $definition->get_identifier() ? $definition->get_identifier() : NULL;
253 253
 
254
-				$definition->set_record( $definition_data );
255
-				$definition->save( $definition_id );
254
+				$definition->set_record($definition_data);
255
+				$definition->save($definition_id);
256 256
 			}
257 257
 		}
258 258
 		return $definitions;
@@ -275,28 +275,28 @@  discard block
 block discarded – undo
275 275
 	public static function export_from_import(importexport_definition $import)
276 276
 	{
277 277
 		// Only operates on import definitions
278
-		if($import->type != 'import') throw new Api\Exception\WrongParameter('Only import definitions');
278
+		if ($import->type != 'import') throw new Api\Exception\WrongParameter('Only import definitions');
279 279
 
280 280
 		// Find export plugin
281
-		$plugin = str_replace('import', 'export',$import->plugin);
281
+		$plugin = str_replace('import', 'export', $import->plugin);
282 282
 		$plugin_list = importexport_helper_functions::get_plugins($import->application, 'export');
283
-		foreach($plugin_list as $appname => $type)
283
+		foreach ($plugin_list as $appname => $type)
284 284
 		{
285 285
 			$plugins = $type['export'];
286
-			foreach($plugins as $name => $label)
286
+			foreach ($plugins as $name => $label)
287 287
 			{
288
-				if($plugin == $name) break;
288
+				if ($plugin == $name) break;
289 289
 			}
290
-			if($plugin !== $name) $plugin = $name;
290
+			if ($plugin !== $name) $plugin = $name;
291 291
 		}
292 292
 
293 293
 		$export = new importexport_definition();
294 294
 
295 295
 		// Common settings
296
-		$export->name = str_replace('import', 'export',$import->name);
297
-		if($export->name == $import->name) $export->name = $export->name . '-export';
296
+		$export->name = str_replace('import', 'export', $import->name);
297
+		if ($export->name == $import->name) $export->name = $export->name.'-export';
298 298
 		$test = new importexport_definition($export->name);
299
-		if($test->name) $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid'];
299
+		if ($test->name) $export->name = $export->name.'-'.$GLOBALS['egw_info']['user']['account_lid'];
300 300
 
301 301
 		$export->application = $import->application;
302 302
 		$export->plugin = $plugin;
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 		);
313 313
 
314 314
 		// Mapping
315
-		foreach($i_options['field_mapping'] as $col_num => $field)
315
+		foreach ($i_options['field_mapping'] as $col_num => $field)
316 316
 		{
317 317
 			// Try to use heading from import file, if possible
318 318
 			$e_options['mapping'][$field] = $i_options['csv_fields'][$col_num] ? $i_options['csv_fields'][$col_num] : $field;
Please login to merge, or discard this patch.
Braces   +77 added lines, -29 removed lines patch added patch discarded remove patch
@@ -16,7 +16,8 @@  discard block
 block discarded – undo
16 16
  *
17 17
  * @todo make this class an egw_record_pool!
18 18
  */
19
-class importexport_definitions_bo {
19
+class importexport_definitions_bo
20
+{
20 21
 
21 22
 	const _appname = 'importexport';
22 23
 	const _defintion_table = 'egw_importexport_definitions';
@@ -34,10 +35,15 @@  discard block
 block discarded – undo
34 35
 	public function __construct($_query=false, $ignore_acl = false)
35 36
 	{
36 37
 		$this->so_sql = new Api\Storage\Base(self::_appname, self::_defintion_table );
37
-		if ($_query) {
38
+		if ($_query)
39
+		{
38 40
 			$definitions = $this->so_sql->search($_query, false);
39
-			foreach ((array)$definitions as $definition) {
40
-				if(self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id'];
41
+			foreach ((array)$definitions as $definition)
42
+			{
43
+				if(self::is_permitted($definition) || $ignore_acl)
44
+				{
45
+					$this->definitions[] = $definition['definition_id'];
46
+				}
41 47
 			}
42 48
 		}
43 49
 	}
@@ -45,7 +51,8 @@  discard block
 block discarded – undo
45 51
 	public function get_rows(&$query, &$rows, &$readonlys)
46 52
 	{
47 53
 		// Filter only definitions user is allowed to use
48
-		if(!$GLOBALS['egw_info']['user']['apps']['admin']) {
54
+		if(!$GLOBALS['egw_info']['user']['apps']['admin'])
55
+		{
49 56
 			$this_membership = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true);
50 57
 			$this_membership[] = $GLOBALS['egw_info']['user']['account_id'];
51 58
 			$sql .= ' (';
@@ -80,7 +87,8 @@  discard block
 block discarded – undo
80 87
 		
81 88
 		$total = $this->so_sql->get_rows($query, $rows, $readonlys);
82 89
 		$ro_count = 0;
83
-		foreach($rows as &$row) {
90
+		foreach($rows as &$row)
91
+		{
84 92
 			// Strip off leading + trailing ,
85 93
 			$row['allowed_users'] = substr($row['allowed_users'],1,-1);
86 94
 
@@ -103,14 +111,19 @@  discard block
 block discarded – undo
103 111
 	 *
104 112
 	 * @return array
105 113
 	 */
106
-	public function get_definitions() {
114
+	public function get_definitions()
115
+	{
107 116
 		return $this->definitions;
108 117
 	}
109
-	public function read($definition_id) {
110
-		if(is_numeric($definition_id)) {
118
+	public function read($definition_id)
119
+	{
120
+		if(is_numeric($definition_id))
121
+		{
111 122
 			$this->so_sql->read($definition_id);
112 123
 			$definition = new importexport_definition($this->so_sql->data['name']);
113
-		} else {
124
+		}
125
+		else
126
+		{
114 127
 			$definition = new importexport_definition( $definition_id['name'] );
115 128
 		}
116 129
 		return $definition->get_record_array();
@@ -120,18 +133,24 @@  discard block
 block discarded – undo
120 133
 	 *
121 134
 	 * @param array $keys
122 135
 	 */
123
-	public function delete($keys) {
124
-		foreach ($keys as $index => $key) {
136
+	public function delete($keys)
137
+	{
138
+		foreach ($keys as $index => $key)
139
+		{
125 140
 			// Check for ownership
126 141
 			$definition = $this->read($key);
127
-			if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) {
142
+			if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin'])
143
+			{
128 144
 				// clear private cache
129 145
 				unset($this->definitions[array_search($key,$this->definitions)]);
130
-			} else {
146
+			}
147
+			else
148
+			{
131 149
 				unset($keys[$index]);
132 150
 			}
133 151
 		}
134
-		if(count($keys) > 0) {
152
+		if(count($keys) > 0)
153
+		{
135 154
 			$this->so_sql->delete(array('definition_id' => $keys));
136 155
 		}
137 156
 	}
@@ -141,7 +160,8 @@  discard block
 block discarded – undo
141 160
 	*
142 161
 	* @param definition $definition
143 162
 	*/
144
-	public function save(Array $data) {
163
+	public function save(Array $data)
164
+	{
145 165
 		$definition = new importexport_definition();
146 166
 		$definition->set_record($data);
147 167
 		$definition->save($data['definition_id']);
@@ -153,7 +173,8 @@  discard block
 block discarded – undo
153 173
 	 * @param array $_definition
154 174
 	 * @return bool
155 175
 	 */
156
-	static public function is_permitted($_definition) {
176
+	static public function is_permitted($_definition)
177
+	{
157 178
 		$allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']);
158 179
 		$this_user_id = $GLOBALS['egw_info']['user']['account_id'];
159 180
 		$this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true);
@@ -177,25 +198,30 @@  discard block
 block discarded – undo
177 198
 		));
178 199
 
179 200
 		$export_data['definitions'] = array();
180
-		foreach ($keys as $definition_id) {
201
+		foreach ($keys as $definition_id)
202
+		{
181 203
 			$definition = new importexport_definition( $definition_id );
182 204
 			$export_data['definitions'][$definition->name] = $definition->get_record_array();
183 205
 			$export_data['definitions'][$definition->name]['allowed_users'] =
184 206
 				importexport_helper_functions::account_id2name(
185 207
 					$export_data['definitions'][$definition->name]['allowed_users']
186 208
 				);
187
-			if($export_date['definitions'][$definition->name]['owner']) {
209
+			if($export_date['definitions'][$definition->name]['owner'])
210
+			{
188 211
 				$export_data['definitions'][$definition->name]['owner'] =
189 212
 					importexport_helper_functions::account_id2name(
190 213
 						$export_data['definitions'][$definition->name]['owner']
191 214
 					);
192
-			} else {
215
+			}
216
+			else
217
+			{
193 218
 				unset($export_data['definitions'][$definition->name]['owner']);
194 219
 			}
195 220
 			unset($export_data['definitions'][$definition->name]['definition_id']);
196 221
 			unset($export_data['definitions'][$definition->name]['description']);
197 222
 			unset($export_data['definitions'][$definition->name]['user_timezone_read']);
198
-			if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) {
223
+			if(is_array($export_data['definitions'][$definition->name]['plugin_options']))
224
+			{
199 225
 				unset($export_data['definitions'][$definition->name]['plugin_options']['user_timezone_read']);
200 226
 			}
201 227
 			unset($definition);
@@ -215,7 +241,8 @@  discard block
 block discarded – undo
215 241
 	 */
216 242
 	public static function import( $_import_file )
217 243
 	{
218
-		if ( !is_file( $_import_file ) ) {
244
+		if ( !is_file( $_import_file ) )
245
+		{
219 246
 			throw new Exception("'$_import_file' does not exist or is not readable" );
220 247
 		}
221 248
 
@@ -233,14 +260,20 @@  discard block
 block discarded – undo
233 260
 		);
234 261
 
235 262
 		// Avoid warning if no definitions found
236
-		if(!is_array($definitions)) return lang('None found');
263
+		if(!is_array($definitions))
264
+		{
265
+			return lang('None found');
266
+		}
237 267
 
238 268
 		// save definition(s) into internal table
239 269
 		foreach ( $definitions as $name => $definition_data )
240 270
 		{
241 271
 			// convert allowed_user
242 272
 			$definition_data['allowed_users'] = importexport_helper_functions::account_name2id( $definition_data['allowed_users'] );
243
-			if($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all';
273
+			if($definition_data['all_users'] && !$definition_data['allowed_users'])
274
+			{
275
+				$definition_data['allowed_users'] = 'all';
276
+			}
244 277
 
245 278
 			$definition_data['owner'] = importexport_helper_functions::account_name2id( $definition_data['owner'] );
246 279
 
@@ -275,7 +308,10 @@  discard block
 block discarded – undo
275 308
 	public static function export_from_import(importexport_definition $import)
276 309
 	{
277 310
 		// Only operates on import definitions
278
-		if($import->type != 'import') throw new Api\Exception\WrongParameter('Only import definitions');
311
+		if($import->type != 'import')
312
+		{
313
+			throw new Api\Exception\WrongParameter('Only import definitions');
314
+		}
279 315
 
280 316
 		// Find export plugin
281 317
 		$plugin = str_replace('import', 'export',$import->plugin);
@@ -285,18 +321,30 @@  discard block
 block discarded – undo
285 321
 			$plugins = $type['export'];
286 322
 			foreach($plugins as $name => $label)
287 323
 			{
288
-				if($plugin == $name) break;
324
+				if($plugin == $name)
325
+				{
326
+					break;
327
+				}
328
+			}
329
+			if($plugin !== $name)
330
+			{
331
+				$plugin = $name;
289 332
 			}
290
-			if($plugin !== $name) $plugin = $name;
291 333
 		}
292 334
 
293 335
 		$export = new importexport_definition();
294 336
 
295 337
 		// Common settings
296 338
 		$export->name = str_replace('import', 'export',$import->name);
297
-		if($export->name == $import->name) $export->name = $export->name . '-export';
339
+		if($export->name == $import->name)
340
+		{
341
+			$export->name = $export->name . '-export';
342
+		}
298 343
 		$test = new importexport_definition($export->name);
299
-		if($test->name) $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid'];
344
+		if($test->name)
345
+		{
346
+			$export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid'];
347
+		}
300 348
 
301 349
 		$export->application = $import->application;
302 350
 		$export->plugin = $plugin;
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@
 block discarded – undo
141 141
 	*
142 142
 	* @param definition $definition
143 143
 	*/
144
-	public function save(Array $data) {
144
+	public function save(array $data) {
145 145
 		$definition = new importexport_definition();
146 146
 		$definition->set_record($data);
147 147
 		$definition->save($data['definition_id']);
Please login to merge, or discard this patch.
importexport/inc/class.importexport_definitions_ui.inc.php 4 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	/**
83 83
 	 * List defined {im|ex}ports
84 84
 	 *
85
-	 * @param array $content=null
85
+	 * @param array $content
86 86
 	 */
87 87
 	function index($content = null,$msg='')
88 88
 	{
@@ -309,8 +309,9 @@  discard block
 block discarded – undo
309 309
 	 * @param int &$success number of succeded actions
310 310
 	 * @param int &$failed number of failed actions (not enought permissions)
311 311
 	 * @param string &$action_msg translated verb for the actions, to be used in a message like %1 entries 'deleted'
312
-	 * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup
313
-	 * @return boolean true if all actions succeded, false otherwise
312
+	 * @param string $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup
313
+	 * @param string $msg
314
+	 * @return null|boolean true if all actions succeded, false otherwise
314 315
 	 */
315 316
 	function action($action,$selected,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg)
316 317
 	{
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -940,7 +940,7 @@
 block discarded – undo
940 940
 	 * Determine if the user is allowed to edit the definition
941 941
 	 *
942 942
 	 */
943
-	protected function can_edit(Array $definition)
943
+	protected function can_edit(array $definition)
944 944
 	{
945 945
 		if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'])
946 946
 		{
Please login to merge, or discard this patch.
Braces   +119 added lines, -44 removed lines patch added patch discarded remove patch
@@ -81,14 +81,18 @@  discard block
 block discarded – undo
81 81
 	{
82 82
 		$filter = array('name' => '*');
83 83
 
84
-		if($GLOBALS['egw_info']['user']['apps']['admin']) {
84
+		if($GLOBALS['egw_info']['user']['apps']['admin'])
85
+		{
85 86
 			// Any public definition
86 87
 			$filter[] = '(owner=0 OR owner IS NULL OR allowed_users IS NOT NULL OR owner = ' . $GLOBALS['egw_info']['user']['account_id'] . ')';
87
-		} else {
88
+		}
89
+		else
90
+		{
88 91
 			// Filter private definitions
89 92
 			$filter['owner'] = $GLOBALS['egw_info']['user']['account_id'];
90 93
 			$config = Api\Config::read('phpgwapi');
91
-			if($config['export_limit'] == 'no' && !Api\Storage\Merge::is_export_limit_excepted()) {
94
+			if($config['export_limit'] == 'no' && !Api\Storage\Merge::is_export_limit_excepted())
95
+			{
92 96
 				$filter['type'] = 'import';
93 97
 			}
94 98
 		}
@@ -104,7 +108,10 @@  discard block
 block discarded – undo
104 108
 			elseif(($button = array_search('pressed',$content['nm']['rows'])) !== false)
105 109
 			{
106 110
 				$selected = $content['nm']['rows']['selected'];
107
-				if(count($selected) < 1 || !is_array($selected)) exit();
111
+				if(count($selected) < 1 || !is_array($selected))
112
+				{
113
+					exit();
114
+				}
108 115
 				switch ($button)
109 116
 				{
110 117
 					case 'delete_selected' :
@@ -160,7 +167,8 @@  discard block
 block discarded – undo
160 167
 			}
161 168
 		}
162 169
 
163
-		if(!is_array($content['nm'])) {
170
+		if(!is_array($content['nm']))
171
+		{
164 172
 			$content['nm'] = array(
165 173
 				'get_rows'	=> 'importexport.importexport_definitions_ui.get_rows',
166 174
 				'no_cat'	=> true,
@@ -171,7 +179,10 @@  discard block
 block discarded – undo
171 179
 				'row_id'	=> 'definition_id',
172 180
 				'placeholder_actions' => array('add')
173 181
 			);
174
-			if($_GET['application']) $content['nm']['col_filter']['application'] = $_GET['application'];
182
+			if($_GET['application'])
183
+			{
184
+				$content['nm']['col_filter']['application'] = $_GET['application'];
185
+			}
175 186
 		}
176 187
 		if(Api\Cache::getSession('importexport', 'index'))
177 188
 		{
@@ -190,17 +201,22 @@  discard block
 block discarded – undo
190 201
 		);
191 202
 		foreach ($this->plugins as $appname => $options)
192 203
 		{
193
-			if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) {
204
+			if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin'])
205
+			{
194 206
 				$sel_options['application'][$appname] = lang($appname);
195 207
 			}
196 208
 		}
197
-		if($msg) $content['msg'] = $msg;
209
+		if($msg)
210
+		{
211
+			$content['msg'] = $msg;
212
+		}
198 213
 
199 214
 		$etpl = new Etemplate(self::_appname.'.definition_index');
200 215
 		return $etpl->exec( self::_appname.'.importexport_definitions_ui.index', $content, $sel_options, $readonlys, $preserv );
201 216
 	}
202 217
 
203
-	private function get_actions() {
218
+	private function get_actions()
219
+	{
204 220
 		$group = 0;
205 221
 		$actions = array(
206 222
 			'edit' => array(
@@ -319,7 +335,8 @@  discard block
 block discarded – undo
319 335
 			$this->get_rows($query,$rows,$readonlys);
320 336
 
321 337
 			$selected = array();
322
-			foreach($rows as $row) {
338
+			foreach($rows as $row)
339
+			{
323 340
 				$selected[] = $row['definition_id'];
324 341
 			}
325 342
 			if(!is_array($session_name))
@@ -334,18 +351,24 @@  discard block
 block discarded – undo
334 351
 
335 352
 		$bodefinitions = new importexport_definitions_bo(false, true);
336 353
 
337
-		switch($action) {
354
+		switch($action)
355
+		{
338 356
 			case 'allowed':
339 357
 				// Field is allowed_users, popup doesn't like _
340 358
 				$action = 'allowed_users';
341 359
 				// Fall through
342 360
 			case 'owner':
343 361
 				$action_msg = lang('changed'. ' ' . $action);
344
-				foreach($selected as $id) {
362
+				foreach($selected as $id)
363
+				{
345 364
 					$definition = $bodefinitions->read((int)$id);
346
-					if($definition['definition_id']) {
365
+					if($definition['definition_id'])
366
+					{
347 367
 						// Prevent private with no owner
348
-						if(!$definition['owner'] && !$settings) $definition['owner'] = $GLOBALS['egw_info']['user']['account_id'];
368
+						if(!$definition['owner'] && !$settings)
369
+						{
370
+							$definition['owner'] = $GLOBALS['egw_info']['user']['account_id'];
371
+						}
349 372
 
350 373
 						$definition[$action] = $settings;
351 374
 						$bodefinitions->save($definition);
@@ -372,18 +395,22 @@  discard block
 block discarded – undo
372 395
 			case 'copy':
373 396
 				$action_msg = lang('copied');
374 397
 				// Should only be one selected
375
-				foreach($selected as $id) {
398
+				foreach($selected as $id)
399
+				{
376 400
 					$definition = $bodefinitions->read((int)$id);
377
-					if($definition['definition_id']) {
401
+					if($definition['definition_id'])
402
+					{
378 403
 						unset($definition['definition_id']);
379 404
 						$definition['name'] = $settings ? $settings : $definition['name'] . ' copy';
380 405
 						try {
381 406
 							$bodefinitions->save($definition);
382
-						} catch (Exception $e) {
407
+						}
408
+						catch (Exception $e) {
383 409
 							try {
384 410
 								$definition['name'] .= ' ' . $GLOBALS['egw_info']['user']['account_lid'];
385 411
 								$bodefinitions->save($definition);
386
-							} catch (Exception $ex) {
412
+							}
413
+							catch (Exception $ex) {
387 414
 								$failed++;
388 415
 								$msg .= lang('Duplicate name, please choose another.');
389 416
 								continue;
@@ -396,18 +423,21 @@  discard block
 block discarded – undo
396 423
 			case 'createexport':
397 424
 				$action_msg = lang('created');
398 425
 				// Should only be one selected
399
-				foreach($selected as $id) {
426
+				foreach($selected as $id)
427
+				{
400 428
 					$definition = new importexport_definition($id);
401 429
 					try {
402 430
 						$export = $bodefinitions->export_from_import($definition);
403 431
 						$export->save();
404
-					} catch (Exception $e) {
432
+					}
433
+					catch (Exception $e) {
405 434
 						if($export)
406 435
 						{
407 436
 							try {
408 437
 								$export->name = $export->name.' ' . $GLOBALS['egw_info']['user']['account_lid'];
409 438
 								$export->save();
410
-							} catch (Exception $ex) {
439
+							}
440
+							catch (Exception $ex) {
411 441
 								$failed++;
412 442
 								$msg .= lang('Duplicate name, please choose another.');
413 443
 								continue;
@@ -425,7 +455,8 @@  discard block
 block discarded – undo
425 455
 		return !$failed;
426 456
 	}
427 457
 
428
-	public function get_rows(&$query, &$rows, &$readonlys) {
458
+	public function get_rows(&$query, &$rows, &$readonlys)
459
+	{
429 460
 		$rows = array();
430 461
 		Api\Cache::setSession('importexport', 'index', $query);
431 462
 
@@ -500,7 +531,10 @@  discard block
 block discarded – undo
500 531
 
501 532
 		if(is_array($content) &&! $content['edit'])
502 533
 		{
503
-			if(self::_debug) error_log('importexport.wizard->$content '. print_r($content,true));
534
+			if(self::_debug)
535
+			{
536
+				error_log('importexport.wizard->$content '. print_r($content,true));
537
+			}
504 538
 			//foreach($content as $key => $val) error_log(" $key : ".array2string($val));
505 539
 			// fetch plugin object
506 540
 			if($content['plugin'] && $content['application'])
@@ -517,13 +551,18 @@  discard block
 block discarded – undo
517 551
 					$wizard_plugin = $content['plugin'];
518 552
 				}
519 553
 				// App translations
520
-				if($content['application']) Api\Translation::add_app($content['application']);
554
+				if($content['application'])
555
+				{
556
+					Api\Translation::add_app($content['application']);
557
+				}
521 558
 
522 559
 				$this->plugin = is_object($GLOBALS['egw']->$wizard_plugin) ? $GLOBALS['egw']->$wizard_plugin : new $wizard_plugin;
523 560
 
524 561
 				// Global object needs to be the same, or references to plugin don't work
525 562
 				if(!is_object($GLOBALS['egw']->importexport_definitions_ui) || $GLOBALS['egw']->importexport_definitions_ui !== $this)
526
-					$GLOBALS['egw']->importexport_definitions_ui =& $this;
563
+				{
564
+									$GLOBALS['egw']->importexport_definitions_ui =& $this;
565
+				}
527 566
 			}
528 567
 			// deal with buttons even if we are not on ajax
529 568
 			if(isset($content['button']) && array_search('pressed',$content['button']) === false && count($content['button']) == 1)
@@ -653,7 +692,10 @@  discard block
 block discarded – undo
653 692
 
654 693
 	function wizard_step10(&$content, &$sel_options, &$readonlys, &$preserv)
655 694
 	{
656
-		if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content,true));
695
+		if(self::_debug)
696
+		{
697
+			error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content,true));
698
+		}
657 699
 
658 700
 		// return from step10
659 701
 		if ($content['step'] == 'wizard_step10')
@@ -675,7 +717,8 @@  discard block
 block discarded – undo
675 717
 			$content['text'] = $this->steps['wizard_step10'];
676 718
 			foreach ($this->plugins as $appname => $options)
677 719
 			{
678
-				if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) {
720
+				if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin'])
721
+				{
679 722
 					$sel_options['application'][$appname] = lang($appname);
680 723
 				}
681 724
 			}
@@ -691,7 +734,10 @@  discard block
 block discarded – undo
691 734
 	// get plugin
692 735
 	function wizard_step20(&$content, &$sel_options, &$readonlys, &$preserv)
693 736
 	{
694
-		if(self::_debug) error_log('importexport.' . get_class($this) . '::wizard_step20->$content '.print_r($content,true));
737
+		if(self::_debug)
738
+		{
739
+			error_log('importexport.' . get_class($this) . '::wizard_step20->$content '.print_r($content,true));
740
+		}
695 741
 
696 742
 		// return from step20
697 743
 		if ($content['step'] == 'wizard_step20')
@@ -700,11 +746,16 @@  discard block
 block discarded – undo
700 746
 			{
701 747
 				case 'next':
702 748
 					// There's no real reason the plugin has to come from any of these, as long as it has a $steps variable
703
-					if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) {
749
+					if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false)
750
+					{
704 751
 						$content['type'] = 'import';
705
-					} elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin),'export') !== false) {
752
+					}
753
+					elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin),'export') !== false)
754
+					{
706 755
 						$content['type'] = 'export';
707
-					} else {
756
+					}
757
+					else
758
+					{
708 759
 						throw new Api\Exception('Invalid plugin');
709 760
 					}
710 761
 					return $this->get_step($content['step'],1);
@@ -722,9 +773,14 @@  discard block
 block discarded – undo
722 773
 		{
723 774
 			$content['text'] = $this->steps['wizard_step20'];
724 775
 			$config = Api\Config::read('phpgwapi');
725
-			foreach ($this->plugins[$content['application']] as $type => $plugins) {
726
-				if($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') continue;
727
-				foreach($plugins as $plugin => $name) {
776
+			foreach ($this->plugins[$content['application']] as $type => $plugins)
777
+			{
778
+				if($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export')
779
+				{
780
+					continue;
781
+				}
782
+				foreach($plugins as $plugin => $name)
783
+				{
728 784
 					$sel_options['plugin'][$plugin] = $name;
729 785
 				}
730 786
 			}
@@ -740,7 +796,10 @@  discard block
 block discarded – undo
740 796
 	// name
741 797
 	function wizard_step21(&$content, &$sel_options, &$readonlys, &$preserv)
742 798
 	{
743
-		if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content,true));
799
+		if(self::_debug)
800
+		{
801
+			error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content,true));
802
+		}
744 803
 
745 804
 		// Check for duplicate name
746 805
 		$duplicate = isset($content['duplicate_error']);
@@ -752,7 +811,8 @@  discard block
 block discarded – undo
752 811
 				{
753 812
 					throw new Exception('Already exists');
754 813
 				}
755
-			} catch (Exception $e) {
814
+			}
815
+			catch (Exception $e) {
756 816
 			//		throw new Exception('Already exists');
757 817
 				$content['duplicate_error'] = lang('Duplicate name, please choose another.');
758 818
 
@@ -763,13 +823,16 @@  discard block
 block discarded – undo
763 823
 					$content['name'] .'-'. Api\DateTime::to('now', true),
764 824
 					//$content['name'] .'-'. rand(0,100),
765 825
 				);
766
-				foreach($suggestions as $key => $suggestion) {
826
+				foreach($suggestions as $key => $suggestion)
827
+				{
767 828
 					$sug_definition = new importexport_definition($suggestion);
768
-					if($sug_definition->definition_id) {
829
+					if($sug_definition->definition_id)
830
+					{
769 831
 						unset($suggestions[$key]);
770 832
 					}
771 833
 				}
772
-				if($suggestions) {
834
+				if($suggestions)
835
+				{
773 836
 					$content['duplicate_error'] .= '  '. lang('Try')." \n" . implode("\n", $suggestions);
774 837
 				}
775 838
 				return $this->get_step($content['step'],0);
@@ -806,7 +869,10 @@  discard block
 block discarded – undo
806 869
 	// allowed users
807 870
 	function wizard_step90(&$content, &$sel_options, &$readonlys, &$preserv)
808 871
 	{
809
-		if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content,true));
872
+		if(self::_debug)
873
+		{
874
+			error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content,true));
875
+		}
810 876
 
811 877
 		// return from step90
812 878
 		if ($content['step'] == 'wizard_step90')
@@ -876,7 +942,10 @@  discard block
 block discarded – undo
876 942
 
877 943
 	function wizard_finish(&$content)
878 944
 	{
879
-		if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content,true));
945
+		if(self::_debug)
946
+		{
947
+			error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content,true));
948
+		}
880 949
 		// Take out some UI leavings
881 950
 		unset($content['text']);
882 951
 		unset($content['step']);
@@ -905,7 +974,8 @@  discard block
 block discarded – undo
905 974
 			if($content['update'])
906 975
 			{
907 976
 				$applist = importexport_helper_functions::get_apps('all', true);
908
-				foreach($applist as $appname) {
977
+				foreach($applist as $appname)
978
+				{
909 979
 					importexport_helper_functions::load_defaults($appname);
910 980
 				}
911 981
 				return $this->index();
@@ -971,7 +1041,9 @@  discard block
 block discarded – undo
971 1041
 			{
972 1042
 				Api\Config::save_value($key, $value, 'importexport');
973 1043
 			}
974
-		} elseif (isset($content['cancel'])) {
1044
+		}
1045
+		elseif (isset($content['cancel']))
1046
+		{
975 1047
 			$GLOBALS['egw']->redirect_link('/admin/index.php');
976 1048
 		}
977 1049
 
@@ -985,7 +1057,10 @@  discard block
 block discarded – undo
985 1057
 			unset($sel_options['import_charsets'][strtoupper($charset)]);
986 1058
 		}
987 1059
 
988
-		if(!$data['update']) $data['update'] = 'request';
1060
+		if(!$data['update'])
1061
+		{
1062
+			$data['update'] = 'request';
1063
+		}
989 1064
 
990 1065
 		$GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration') . ' - ' . lang(self::_appname);
991 1066
 		$etpl = new etemplate(self::_appname.'.config');
Please login to merge, or discard this patch.
Spacing   +152 added lines, -153 removed lines patch added patch discarded remove patch
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
 	function __construct()
56 56
 	{
57 57
 		// we cant deal with notice and warnings, as we are on ajax!
58
-		error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
58
+		error_reporting(E_ALL&~E_NOTICE&~E_WARNING);
59 59
 		Api\Translation::add_app(self::_appname);
60 60
 		$GLOBALS['egw_info']['flags']['currentapp'] = self::_appname;
61 61
 
62 62
 		$this->etpl = new Etemplate();
63
-		$this->clock = Api\Html::image(self::_appname,'clock');
63
+		$this->clock = Api\Html::image(self::_appname, 'clock');
64 64
 		$this->steps = array(
65 65
 			'wizard_step10' => lang('Choose an application'),
66 66
 			'wizard_step20' => lang('Choose a plugin'),
@@ -77,18 +77,18 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @param array $content=null
79 79
 	 */
80
-	function index($content = null,$msg='')
80
+	function index($content = null, $msg = '')
81 81
 	{
82 82
 		$filter = array('name' => '*');
83 83
 
84
-		if($GLOBALS['egw_info']['user']['apps']['admin']) {
84
+		if ($GLOBALS['egw_info']['user']['apps']['admin']) {
85 85
 			// Any public definition
86
-			$filter[] = '(owner=0 OR owner IS NULL OR allowed_users IS NOT NULL OR owner = ' . $GLOBALS['egw_info']['user']['account_id'] . ')';
86
+			$filter[] = '(owner=0 OR owner IS NULL OR allowed_users IS NOT NULL OR owner = '.$GLOBALS['egw_info']['user']['account_id'].')';
87 87
 		} else {
88 88
 			// Filter private definitions
89 89
 			$filter['owner'] = $GLOBALS['egw_info']['user']['account_id'];
90 90
 			$config = Api\Config::read('phpgwapi');
91
-			if($config['export_limit'] == 'no' && !Api\Storage\Merge::is_export_limit_excepted()) {
91
+			if ($config['export_limit'] == 'no' && !Api\Storage\Merge::is_export_limit_excepted()) {
92 92
 				$filter['type'] = 'import';
93 93
 			}
94 94
 		}
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
 			if (isset($content['nm']['rows']['delete']))
100 100
 			{
101 101
 				$content['nm']['action'] = 'delete';
102
-				$content['nm']['selected'] = array_keys($content['nm']['rows']['delete'],'pressed');
102
+				$content['nm']['selected'] = array_keys($content['nm']['rows']['delete'], 'pressed');
103 103
 			}
104
-			elseif(($button = array_search('pressed',$content['nm']['rows'])) !== false)
104
+			elseif (($button = array_search('pressed', $content['nm']['rows'])) !== false)
105 105
 			{
106 106
 				$selected = $content['nm']['rows']['selected'];
107
-				if(count($selected) < 1 || !is_array($selected)) exit();
107
+				if (count($selected) < 1 || !is_array($selected)) exit();
108 108
 				switch ($button)
109 109
 				{
110 110
 					case 'delete_selected' :
@@ -126,54 +126,54 @@  discard block
 block discarded – undo
126 126
 				else
127 127
 				{
128 128
 					// Action has an additional parameter
129
-					if(in_array($content['nm']['action'], array('owner', 'allowed')))
129
+					if (in_array($content['nm']['action'], array('owner', 'allowed')))
130 130
 					{
131 131
 						$action = $content['nm']['action'];
132
-						if($content['nm']['action'] == 'allowed')
132
+						if ($content['nm']['action'] == 'allowed')
133 133
 						{
134 134
 							$content['allowed'] = $content['allowed_popup']['allowed_private'] == 'true' ? null : (
135
-								$content['allowed_popup']['all_users']=='true' ? 'all' : implode(',',$content['allowed_popup']['allowed'])
135
+								$content['allowed_popup']['all_users'] == 'true' ? 'all' : implode(',', $content['allowed_popup']['allowed'])
136 136
 							);
137 137
 						}
138 138
 						else
139 139
 						{
140 140
 							$content['owner'] = $content['owner_popup']['owner'];
141 141
 						}
142
-						if(is_array($content[$content['nm']['action']]))
142
+						if (is_array($content[$content['nm']['action']]))
143 143
 						{
144
-							$content[$content['nm']['action']] = implode(',',$content[$content['nm']['action']]);
144
+							$content[$content['nm']['action']] = implode(',', $content[$content['nm']['action']]);
145 145
 						}
146
-						$content['nm']['action'] .= '_' . $content[$action];
146
+						$content['nm']['action'] .= '_'.$content[$action];
147 147
 						unset($content[$action]);
148 148
 						unset($content['allowed_popup']);
149 149
 					}
150
-					if ($this->action($content['nm']['action'],$content['nm']['selected'],$content['nm']['select_all'],
151
-						$success,$failed,$action_msg,'index',$msg))
150
+					if ($this->action($content['nm']['action'], $content['nm']['selected'], $content['nm']['select_all'],
151
+						$success, $failed, $action_msg, 'index', $msg))
152 152
 					{
153
-						$msg .= lang('%1 definition(s) %2',$success,$action_msg);
153
+						$msg .= lang('%1 definition(s) %2', $success, $action_msg);
154 154
 					}
155
-					elseif(empty($msg))
155
+					elseif (empty($msg))
156 156
 					{
157
-						$msg .= lang('%1 definition(s) %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
157
+						$msg .= lang('%1 definition(s) %2, %3 failed because of insufficent rights !!!', $success, $action_msg, $failed);
158 158
 					}
159 159
 				}
160 160
 			}
161 161
 		}
162 162
 
163
-		if(!is_array($content['nm'])) {
163
+		if (!is_array($content['nm'])) {
164 164
 			$content['nm'] = array(
165 165
 				'get_rows'	=> 'importexport.importexport_definitions_ui.get_rows',
166 166
 				'no_cat'	=> true,
167 167
 				'no_filter'	=> true,
168 168
 				'no_filter2'	=> true,
169
-				'csv_fields'	=> false,	// Disable CSV export, uses own export
170
-				'default_cols'  => '!actions',  // switch legacy actions column and row off by default
169
+				'csv_fields'	=> false, // Disable CSV export, uses own export
170
+				'default_cols'  => '!actions', // switch legacy actions column and row off by default
171 171
 				'row_id'	=> 'definition_id',
172 172
 				'placeholder_actions' => array('add')
173 173
 			);
174
-			if($_GET['application']) $content['nm']['col_filter']['application'] = $_GET['application'];
174
+			if ($_GET['application']) $content['nm']['col_filter']['application'] = $_GET['application'];
175 175
 		}
176
-		if(Api\Cache::getSession('importexport', 'index'))
176
+		if (Api\Cache::getSession('importexport', 'index'))
177 177
 		{
178 178
 			$content['nm'] = array_merge($content['nm'], Api\Cache::getSession('importexport', 'index'));
179 179
 		}
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
 		);
191 191
 		foreach ($this->plugins as $appname => $options)
192 192
 		{
193
-			if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) {
193
+			if ($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) {
194 194
 				$sel_options['application'][$appname] = lang($appname);
195 195
 			}
196 196
 		}
197
-		if($msg) $content['msg'] = $msg;
197
+		if ($msg) $content['msg'] = $msg;
198 198
 
199 199
 		$etpl = new Etemplate(self::_appname.'.definition_index');
200
-		return $etpl->exec( self::_appname.'.importexport_definitions_ui.index', $content, $sel_options, $readonlys, $preserv );
200
+		return $etpl->exec(self::_appname.'.importexport_definitions_ui.index', $content, $sel_options, $readonlys, $preserv);
201 201
 	}
202 202
 
203 203
 	private function get_actions() {
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 		);
287 287
 
288 288
 		// Unset admin actions
289
-		if(!$GLOBALS['egw_info']['user']['apps']['admin'])
289
+		if (!$GLOBALS['egw_info']['user']['apps']['admin'])
290 290
 		{
291 291
 			unset($actions['schedule']);
292 292
 		}
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	 * @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup
306 306
 	 * @return boolean true if all actions succeded, false otherwise
307 307
 	 */
308
-	function action($action,$selected,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg)
308
+	function action($action, $selected, $use_all, &$success, &$failed, &$action_msg, $session_name, &$msg)
309 309
 	{
310 310
 		//error_log( __METHOD__."('$action', ".array2string($selected).', '.array2string($use_all).",,, '$session_name')");
311 311
 		if ($use_all)
@@ -313,16 +313,16 @@  discard block
 block discarded – undo
313 313
 			// get the whole selection
314 314
 			$old_query = $query = is_array($session_name) ? $session_name : Api\Cache::getSession('importexport', $session_name);
315 315
 
316
-			@set_time_limit(0);				// switch off the execution time limit, as it's for big selections to small
317
-			$query['num_rows'] = -1;		// all
318
-			$query['csv_export'] = true;	// so get_rows method _can_ produce different content or not store state in the session
319
-			$this->get_rows($query,$rows,$readonlys);
316
+			@set_time_limit(0); // switch off the execution time limit, as it's for big selections to small
317
+			$query['num_rows'] = -1; // all
318
+			$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
319
+			$this->get_rows($query, $rows, $readonlys);
320 320
 
321 321
 			$selected = array();
322
-			foreach($rows as $row) {
322
+			foreach ($rows as $row) {
323 323
 				$selected[] = $row['definition_id'];
324 324
 			}
325
-			if(!is_array($session_name))
325
+			if (!is_array($session_name))
326 326
 			{
327 327
 				// Restore old query
328 328
 				Api\Cache::setSession('importexport', $session_name, $old_query);
@@ -334,18 +334,18 @@  discard block
 block discarded – undo
334 334
 
335 335
 		$bodefinitions = new importexport_definitions_bo(false, true);
336 336
 
337
-		switch($action) {
337
+		switch ($action) {
338 338
 			case 'allowed':
339 339
 				// Field is allowed_users, popup doesn't like _
340 340
 				$action = 'allowed_users';
341 341
 				// Fall through
342 342
 			case 'owner':
343
-				$action_msg = lang('changed'. ' ' . $action);
344
-				foreach($selected as $id) {
343
+				$action_msg = lang('changed'.' '.$action);
344
+				foreach ($selected as $id) {
345 345
 					$definition = $bodefinitions->read((int)$id);
346
-					if($definition['definition_id']) {
346
+					if ($definition['definition_id']) {
347 347
 						// Prevent private with no owner
348
-						if(!$definition['owner'] && !$settings) $definition['owner'] = $GLOBALS['egw_info']['user']['account_id'];
348
+						if (!$definition['owner'] && !$settings) $definition['owner'] = $GLOBALS['egw_info']['user']['account_id'];
349 349
 
350 350
 						$definition[$action] = $settings;
351 351
 						$bodefinitions->save($definition);
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 				$mime_type = ($GLOBALS['egw']->html->user_agent == 'msie' || $GLOBALS['egw']->html->user_agent == 'opera') ?
364 364
 					'application/octetstream' : 'application/octet-stream';
365 365
 				$name = 'importexport_definition.xml';
366
-				header('Content-Type: ' . $mime_type);
366
+				header('Content-Type: '.$mime_type);
367 367
 				header('Content-Disposition: attachment; filename="'.$name.'"');
368 368
 				echo $bodefinitions->export($selected);
369 369
 				exit();
@@ -372,16 +372,16 @@  discard block
 block discarded – undo
372 372
 			case 'copy':
373 373
 				$action_msg = lang('copied');
374 374
 				// Should only be one selected
375
-				foreach($selected as $id) {
375
+				foreach ($selected as $id) {
376 376
 					$definition = $bodefinitions->read((int)$id);
377
-					if($definition['definition_id']) {
377
+					if ($definition['definition_id']) {
378 378
 						unset($definition['definition_id']);
379
-						$definition['name'] = $settings ? $settings : $definition['name'] . ' copy';
379
+						$definition['name'] = $settings ? $settings : $definition['name'].' copy';
380 380
 						try {
381 381
 							$bodefinitions->save($definition);
382 382
 						} catch (Exception $e) {
383 383
 							try {
384
-								$definition['name'] .= ' ' . $GLOBALS['egw_info']['user']['account_lid'];
384
+								$definition['name'] .= ' '.$GLOBALS['egw_info']['user']['account_lid'];
385 385
 								$bodefinitions->save($definition);
386 386
 							} catch (Exception $ex) {
387 387
 								$failed++;
@@ -396,16 +396,16 @@  discard block
 block discarded – undo
396 396
 			case 'createexport':
397 397
 				$action_msg = lang('created');
398 398
 				// Should only be one selected
399
-				foreach($selected as $id) {
399
+				foreach ($selected as $id) {
400 400
 					$definition = new importexport_definition($id);
401 401
 					try {
402 402
 						$export = $bodefinitions->export_from_import($definition);
403 403
 						$export->save();
404 404
 					} catch (Exception $e) {
405
-						if($export)
405
+						if ($export)
406 406
 						{
407 407
 							try {
408
-								$export->name = $export->name.' ' . $GLOBALS['egw_info']['user']['account_lid'];
408
+								$export->name = $export->name.' '.$GLOBALS['egw_info']['user']['account_lid'];
409 409
 								$export->save();
410 410
 							} catch (Exception $ex) {
411 411
 								$failed++;
@@ -430,10 +430,10 @@  discard block
 block discarded – undo
430 430
 		Api\Cache::setSession('importexport', 'index', $query);
431 431
 
432 432
 		// Special handling for allowed users 'private'
433
-		if($query['col_filter']['allowed_users'] == 'private')
433
+		if ($query['col_filter']['allowed_users'] == 'private')
434 434
 		{
435 435
 			unset($query['col_filter']['allowed_users']);
436
-			$query['col_filter'][] = 'allowed_users = ' . $GLOBALS['egw']->db->quote(',,');
436
+			$query['col_filter'][] = 'allowed_users = '.$GLOBALS['egw']->db->quote(',,');
437 437
 		}
438 438
 		$bodefinitions = new importexport_definitions_bo($query['col_filter'], true);
439 439
 		// We don't care about readonlys for the UI
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 	 */
449 449
 	function edit()
450 450
 	{
451
-		if(!$_definition = $_GET['definition'])
451
+		if (!$_definition = $_GET['definition'])
452 452
 		{
453 453
 			$content = array(
454 454
 				'edit'		=> true,
@@ -457,11 +457,11 @@  discard block
 block discarded – undo
457 457
 			);
458 458
 
459 459
 			// Jump to a step
460
-			if($_GET['step'])
460
+			if ($_GET['step'])
461 461
 			{
462 462
 				$content['edit'] = false;
463 463
 				// Wizard will process previous step, then advance
464
-				$content['step'] = $this->get_step($_GET['step'],-1);
464
+				$content['step'] = $this->get_step($_GET['step'], -1);
465 465
 				$content['button']['next'] = 'pressed';
466 466
 				$this->wizard($content);
467 467
 			}
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 			}
473 473
 			return;
474 474
 		}
475
-		if(is_numeric($_GET['definition']))
475
+		if (is_numeric($_GET['definition']))
476 476
 		{
477 477
 			$definition = (int)$_GET['definition'];
478 478
 		}
@@ -484,31 +484,31 @@  discard block
 block discarded – undo
484 484
 		$definition = $bodefinitions->read($definition);
485 485
 		$definition['edit'] = true;
486 486
 		// Jump to a step
487
-		if($_GET['step'])
487
+		if ($_GET['step'])
488 488
 		{
489 489
 			$definition['edit'] = false;
490 490
 			// Wizard will process previous step, then advance
491
-			$definition['step'] = $_GET['step'];;
491
+			$definition['step'] = $_GET['step']; ;
492 492
 			$definition['button'] = array('next' => 'pressed');
493 493
 		}
494 494
 		$this->wizard($definition);
495 495
 	}
496 496
 
497
-	function wizard($content = null, $msg='')
497
+	function wizard($content = null, $msg = '')
498 498
 	{
499 499
 		$this->etpl->read('importexport.wizardbox');
500 500
 
501
-		if(is_array($content) &&! $content['edit'])
501
+		if (is_array($content) && !$content['edit'])
502 502
 		{
503
-			if(self::_debug) error_log('importexport.wizard->$content '. print_r($content,true));
503
+			if (self::_debug) error_log('importexport.wizard->$content '.print_r($content, true));
504 504
 			//foreach($content as $key => $val) error_log(" $key : ".array2string($val));
505 505
 			// fetch plugin object
506
-			if($content['plugin'] && $content['application'])
506
+			if ($content['plugin'] && $content['application'])
507 507
 			{
508
-				$wizard_name = $content['application'] . '_wizard_' . str_replace($content['application'] . '_', '', $content['plugin']);
508
+				$wizard_name = $content['application'].'_wizard_'.str_replace($content['application'].'_', '', $content['plugin']);
509 509
 
510 510
 				// we need to deal with the wizard object if exists
511
-				if (file_exists(EGW_SERVER_ROOT . '/'. $content['application']."/inc/class.$wizard_name.inc.php"))
511
+				if (file_exists(EGW_SERVER_ROOT.'/'.$content['application']."/inc/class.$wizard_name.inc.php"))
512 512
 				{
513 513
 					$wizard_plugin = $wizard_name;
514 514
 				}
@@ -517,38 +517,38 @@  discard block
 block discarded – undo
517 517
 					$wizard_plugin = $content['plugin'];
518 518
 				}
519 519
 				// App translations
520
-				if($content['application']) Api\Translation::add_app($content['application']);
520
+				if ($content['application']) Api\Translation::add_app($content['application']);
521 521
 
522 522
 				$this->plugin = is_object($GLOBALS['egw']->$wizard_plugin) ? $GLOBALS['egw']->$wizard_plugin : new $wizard_plugin;
523 523
 
524 524
 				// Global object needs to be the same, or references to plugin don't work
525
-				if(!is_object($GLOBALS['egw']->importexport_definitions_ui) || $GLOBALS['egw']->importexport_definitions_ui !== $this)
526
-					$GLOBALS['egw']->importexport_definitions_ui =& $this;
525
+				if (!is_object($GLOBALS['egw']->importexport_definitions_ui) || $GLOBALS['egw']->importexport_definitions_ui !== $this)
526
+					$GLOBALS['egw']->importexport_definitions_ui = & $this;
527 527
 			}
528 528
 			// deal with buttons even if we are not on ajax
529
-			if(isset($content['button']) && array_search('pressed',$content['button']) === false && count($content['button']) == 1)
529
+			if (isset($content['button']) && array_search('pressed', $content['button']) === false && count($content['button']) == 1)
530 530
 			{
531 531
 				$button = array_keys($content['button']);
532 532
 				$content['button'] = array($button[0] => 'pressed');
533 533
 			}
534 534
 
535 535
 			// post process submitted step
536
-			if($content['step'])
536
+			if ($content['step'])
537 537
 			{
538
-				if(!$this->can_edit($content))
538
+				if (!$this->can_edit($content))
539 539
 				{
540 540
 					// Each step changes definition, reload it
541 541
 					$bodefinitions = new importexport_definitions_bo();
542 542
 					$definition = $bodefinitions->read($content);
543 543
 					$content = $definition + array('step' => $content['step'], 'button' => $content['button']);
544 544
 				}
545
-				if(!key_exists($content['step'],$this->steps))
545
+				if (!key_exists($content['step'], $this->steps))
546 546
 				{
547
-					$next_step = $this->plugin->{$content['step']}($content,$sel_options,$readonlys,$preserv);
547
+					$next_step = $this->plugin->{$content['step']}($content, $sel_options, $readonlys, $preserv);
548 548
 				}
549 549
 				else
550 550
 				{
551
-					$next_step = $this->{$content['step']}($content,$sel_options,$readonlys,$preserv);
551
+					$next_step = $this->{$content['step']}($content, $sel_options, $readonlys, $preserv);
552 552
 				}
553 553
 			}
554 554
 			else
@@ -560,23 +560,23 @@  discard block
 block discarded – undo
560 560
 			$sel_options = $readonlys = $preserv = array();
561 561
 
562 562
 			// Disable finish button if required fields are missing
563
-			if(!$content['name'] || !$content['type'] || !$content['plugin'])
563
+			if (!$content['name'] || !$content['type'] || !$content['plugin'])
564 564
 			{
565 565
 				$readonlys['button[finish]'] = true;
566 566
 			}
567 567
 			do
568 568
 			{
569
-				if(!key_exists($next_step,$this->steps))
569
+				if (!key_exists($next_step, $this->steps))
570 570
 				{
571
-					$this->wizard_content_template = $this->plugin->$next_step($content,$sel_options,$readonlys,$preserv);
571
+					$this->wizard_content_template = $this->plugin->$next_step($content, $sel_options, $readonlys, $preserv);
572 572
 				}
573 573
 				else
574 574
 				{
575
-					$this->wizard_content_template = $this->$next_step($content,$sel_options,$readonlys,$preserv);
575
+					$this->wizard_content_template = $this->$next_step($content, $sel_options, $readonlys, $preserv);
576 576
 				}
577
-				if($this->wizard_content_template == self::SKIP)
577
+				if ($this->wizard_content_template == self::SKIP)
578 578
 				{
579
-					if(!key_exists($content['step'],$this->steps))
579
+					if (!key_exists($content['step'], $this->steps))
580 580
 					{
581 581
 						$next_step = $this->plugin->{$content['step']}($content);
582 582
 					}
@@ -585,9 +585,9 @@  discard block
 block discarded – undo
585 585
 						$next_step = $this->{$content['step']}($content);
586 586
 					}
587 587
 				}
588
-			} while($this->wizard_content_template == self::SKIP);
588
+			} while ($this->wizard_content_template == self::SKIP);
589 589
 
590
-			if(!$this->can_edit($content))
590
+			if (!$this->can_edit($content))
591 591
 			{
592 592
 				$readonlys[$this->wizard_content_template] = true;
593 593
 				$preserve = $content;
@@ -596,21 +596,21 @@  discard block
 block discarded – undo
596 596
 
597 597
 			unset($content['button']);
598 598
 			$content['wizard_content'] = $this->wizard_content_template;
599
-			$this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,2);
599
+			$this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard', $content, $sel_options, $readonlys, $preserv, 2);
600 600
 		}
601 601
 		else
602 602
 		{
603 603
 			// initial content
604 604
 			$sel_options = $readonlys = $preserv = array();
605 605
 			$readonlys['button[previous]'] = true;
606
-			if($content['edit'])
606
+			if ($content['edit'])
607 607
 			{
608 608
 				unset ($content['edit']);
609 609
 			}
610 610
 
611 611
 			$this->wizard_content_template = $this->wizard_step10($content, $sel_options, $readonlys, $preserv);
612 612
 
613
-			if(!$this->can_edit($content))
613
+			if (!$this->can_edit($content))
614 614
 			{
615 615
 				$readonlys[$this->wizard_content_template] = true;
616 616
 				$preserve = $content;
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 			}
619 619
 
620 620
 			$content['wizard_content'] = $this->wizard_content_template;
621
-			$this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,2);
621
+			$this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard', $content, $sel_options, $readonlys, $preserv, 2);
622 622
 		}
623 623
 	}
624 624
 
@@ -629,31 +629,31 @@  discard block
 block discarded – undo
629 629
 	 * @param int $step_width
630 630
 	 * @return string containing function name of next step
631 631
 	 */
632
-	function get_step ($curr_step, $step_width)
632
+	function get_step($curr_step, $step_width)
633 633
 	{
634 634
 		/*if($content['plugin'] && $content['application']&& !is_object($this->plugin))
635 635
 		{
636 636
 			$plugin_definition =  $this->plugins[$content['application']][$content['plugin']]['definition'];
637 637
 			if($plugin_definition) $this->plugin = new $plugin_definition;
638 638
 		}*/
639
-		if(is_object($this->plugin) && is_array($this->plugin->steps))
639
+		if (is_object($this->plugin) && is_array($this->plugin->steps))
640 640
 		{
641
-			$steps = array_merge($this->steps,$this->plugin->steps);
642
-			$steps = array_flip($steps); asort($steps);	$steps = array_flip($steps);
641
+			$steps = array_merge($this->steps, $this->plugin->steps);
642
+			$steps = array_flip($steps); asort($steps); $steps = array_flip($steps);
643 643
 		}
644 644
 		else
645 645
 		{
646 646
 			$steps = $this->steps;
647 647
 		}
648 648
 		$step_keys = array_keys($steps);
649
-		$nn = array_search($curr_step,$step_keys)+(int)$step_width;
650
-		return (key_exists($nn,$step_keys)) ? $step_keys[$nn] : 'wizard_finish';
649
+		$nn = array_search($curr_step, $step_keys) + (int)$step_width;
650
+		return (key_exists($nn, $step_keys)) ? $step_keys[$nn] : 'wizard_finish';
651 651
 	}
652 652
 
653 653
 
654 654
 	function wizard_step10(&$content, &$sel_options, &$readonlys, &$preserv)
655 655
 	{
656
-		if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content,true));
656
+		if (self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content, true));
657 657
 
658 658
 		// return from step10
659 659
 		if ($content['step'] == 'wizard_step10')
@@ -661,11 +661,11 @@  discard block
 block discarded – undo
661 661
 			switch (array_search('pressed', $content['button']))
662 662
 			{
663 663
 				case 'next':
664
-					return $this->get_step($content['step'],1);
664
+					return $this->get_step($content['step'], 1);
665 665
 				case 'finish':
666 666
 					return 'wizard_finish';
667 667
 				default :
668
-					return $this->wizard_step10($content,$sel_options,$readonlys,$preserv);
668
+					return $this->wizard_step10($content, $sel_options, $readonlys, $preserv);
669 669
 			}
670 670
 
671 671
 		}
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 			$content['text'] = $this->steps['wizard_step10'];
676 676
 			foreach ($this->plugins as $appname => $options)
677 677
 			{
678
-				if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) {
678
+				if ($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) {
679 679
 					$sel_options['application'][$appname] = lang($appname);
680 680
 				}
681 681
 			}
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 	// get plugin
692 692
 	function wizard_step20(&$content, &$sel_options, &$readonlys, &$preserv)
693 693
 	{
694
-		if(self::_debug) error_log('importexport.' . get_class($this) . '::wizard_step20->$content '.print_r($content,true));
694
+		if (self::_debug) error_log('importexport.'.get_class($this).'::wizard_step20->$content '.print_r($content, true));
695 695
 
696 696
 		// return from step20
697 697
 		if ($content['step'] == 'wizard_step20')
@@ -700,21 +700,21 @@  discard block
 block discarded – undo
700 700
 			{
701 701
 				case 'next':
702 702
 					// There's no real reason the plugin has to come from any of these, as long as it has a $steps variable
703
-					if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) {
703
+					if ($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) {
704 704
 						$content['type'] = 'import';
705
-					} elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin),'export') !== false) {
705
+					} elseif ($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin), 'export') !== false) {
706 706
 						$content['type'] = 'export';
707 707
 					} else {
708 708
 						throw new Api\Exception('Invalid plugin');
709 709
 					}
710
-					return $this->get_step($content['step'],1);
710
+					return $this->get_step($content['step'], 1);
711 711
 				case 'previous' :
712 712
 					$readonlys['button[previous]'] = true;
713
-					return $this->get_step($content['step'],-1);
713
+					return $this->get_step($content['step'], -1);
714 714
 				case 'finish':
715 715
 					return 'wizard_finish';
716 716
 				default :
717
-					return $this->wizard_step20($content,$sel_options,$readonlys,$preserv);
717
+					return $this->wizard_step20($content, $sel_options, $readonlys, $preserv);
718 718
 			}
719 719
 		}
720 720
 		// init step20
@@ -723,8 +723,8 @@  discard block
 block discarded – undo
723 723
 			$content['text'] = $this->steps['wizard_step20'];
724 724
 			$config = Api\Config::read('phpgwapi');
725 725
 			foreach ($this->plugins[$content['application']] as $type => $plugins) {
726
-				if($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') continue;
727
-				foreach($plugins as $plugin => $name) {
726
+				if ($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') continue;
727
+				foreach ($plugins as $plugin => $name) {
728 728
 					$sel_options['plugin'][$plugin] = $name;
729 729
 				}
730 730
 			}
@@ -740,15 +740,15 @@  discard block
 block discarded – undo
740 740
 	// name
741 741
 	function wizard_step21(&$content, &$sel_options, &$readonlys, &$preserv)
742 742
 	{
743
-		if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content,true));
743
+		if (self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content, true));
744 744
 
745 745
 		// Check for duplicate name
746 746
 		$duplicate = isset($content['duplicate_error']);
747
-		if($content['name'] && !$duplicate)
747
+		if ($content['name'] && !$duplicate)
748 748
 		{
749 749
 			try {
750 750
 				$check_definition = new importexport_definition($content['name']);
751
-				if($check_definition && $check_definition->definition_id && $check_definition->definition_id != $content['definition_id'])
751
+				if ($check_definition && $check_definition->definition_id && $check_definition->definition_id != $content['definition_id'])
752 752
 				{
753 753
 					throw new Exception('Already exists');
754 754
 				}
@@ -758,21 +758,21 @@  discard block
 block discarded – undo
758 758
 
759 759
 				// Try some suggestions
760 760
 				$suggestions = array(
761
-					$content['name'] .'-'. $GLOBALS['egw_info']['user']['account_lid'],
762
-					$content['name'] .'-'. $GLOBALS['egw_info']['user']['account_id'],
763
-					$content['name'] .'-'. Api\DateTime::to('now', true),
761
+					$content['name'].'-'.$GLOBALS['egw_info']['user']['account_lid'],
762
+					$content['name'].'-'.$GLOBALS['egw_info']['user']['account_id'],
763
+					$content['name'].'-'.Api\DateTime::to('now', true),
764 764
 					//$content['name'] .'-'. rand(0,100),
765 765
 				);
766
-				foreach($suggestions as $key => $suggestion) {
766
+				foreach ($suggestions as $key => $suggestion) {
767 767
 					$sug_definition = new importexport_definition($suggestion);
768
-					if($sug_definition->definition_id) {
768
+					if ($sug_definition->definition_id) {
769 769
 						unset($suggestions[$key]);
770 770
 					}
771 771
 				}
772
-				if($suggestions) {
773
-					$content['duplicate_error'] .= '  '. lang('Try')." \n" . implode("\n", $suggestions);
772
+				if ($suggestions) {
773
+					$content['duplicate_error'] .= '  '.lang('Try')." \n".implode("\n", $suggestions);
774 774
 				}
775
-				return $this->get_step($content['step'],0);
775
+				return $this->get_step($content['step'], 0);
776 776
 			}
777 777
 		}
778 778
 
@@ -782,19 +782,19 @@  discard block
 block discarded – undo
782 782
 			switch (array_search('pressed', $content['button']))
783 783
 			{
784 784
 				case 'next':
785
-					return $this->get_step($content['step'],1);
785
+					return $this->get_step($content['step'], 1);
786 786
 				case 'previous' :
787
-					return $this->get_step($content['step'],-1);
787
+					return $this->get_step($content['step'], -1);
788 788
 				case 'finish':
789 789
 					return 'wizard_finish';
790 790
 				default :
791
-					return $this->wizard_step21($content,$sel_options,$readonlys,$preserv);
791
+					return $this->wizard_step21($content, $sel_options, $readonlys, $preserv);
792 792
 			}
793 793
 		}
794 794
 		// init step21
795 795
 		else
796 796
 		{
797
-			$content['text'] = $this->steps['wizard_step21'] . ($duplicate ? "\n".$content['duplicate_error'] : '');
797
+			$content['text'] = $this->steps['wizard_step21'].($duplicate ? "\n".$content['duplicate_error'] : '');
798 798
 			$content['step'] = 'wizard_step21';
799 799
 			unset($content['duplicate_error']);
800 800
 			$preserv = $content;
@@ -806,17 +806,16 @@  discard block
 block discarded – undo
806 806
 	// allowed users
807 807
 	function wizard_step90(&$content, &$sel_options, &$readonlys, &$preserv)
808 808
 	{
809
-		if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content,true));
809
+		if (self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content, true));
810 810
 
811 811
 		// return from step90
812 812
 		if ($content['step'] == 'wizard_step90')
813 813
 		{
814
-			if($this->can_edit($content))
814
+			if ($this->can_edit($content))
815 815
 			{
816
-				$content['owner'] = $content['just_me'] || !$GLOBALS['egw']->acl->check('share_definitions', Acl::READ,'importexport') ?
817
-					($content['owner'] ? $content['owner'] : $GLOBALS['egw_info']['user']['account_id']) :
818
-					null;
819
-				$content['allowed_users'] = $content['just_me'] ? '' : ($content['all_users'] ? 'all' : implode(',',$content['allowed_users']));
816
+				$content['owner'] = $content['just_me'] || !$GLOBALS['egw']->acl->check('share_definitions', Acl::READ, 'importexport') ?
817
+					($content['owner'] ? $content['owner'] : $GLOBALS['egw_info']['user']['account_id']) : null;
818
+				$content['allowed_users'] = $content['just_me'] ? '' : ($content['all_users'] ? 'all' : implode(',', $content['allowed_users']));
820 819
 				unset($content['just_me']);
821 820
 			}
822 821
 
@@ -824,12 +823,12 @@  discard block
 block discarded – undo
824 823
 			switch (array_search('pressed', $content['button']))
825 824
 			{
826 825
 				case 'previous' :
827
-					return $this->get_step($content['step'],-1);
826
+					return $this->get_step($content['step'], -1);
828 827
 				case 'next':
829 828
 				case 'finish':
830 829
 					return 'wizard_finish';
831 830
 				default :
832
-					return $this->wizard_step90($content,$sel_options,$readonlys,$preserv);
831
+					return $this->wizard_step90($content, $sel_options, $readonlys, $preserv);
833 832
 			}
834 833
 		}
835 834
 		// init step90
@@ -840,10 +839,10 @@  discard block
 block discarded – undo
840 839
 			$preserv = $content;
841 840
 
842 841
 			// Set owner for non-admins
843
-			$content['just_me'] = ((!$content['allowed_users'] || !$content['allowed_users'][0] && count($content['allowed_users']) ==1) && $content['owner']);
844
-			$content['all_users'] = is_array($content['allowed_users']) && array_key_exists('0',$content['allowed_users']) && $content['allowed_users'][0] == 'all' ||
842
+			$content['just_me'] = ((!$content['allowed_users'] || !$content['allowed_users'][0] && count($content['allowed_users']) == 1) && $content['owner']);
843
+			$content['all_users'] = is_array($content['allowed_users']) && array_key_exists('0', $content['allowed_users']) && $content['allowed_users'][0] == 'all' ||
845 844
 			$content['allowed_users'] == 'all';
846
-			if(!$GLOBALS['egw']->acl->check('share_definition', Acl::READ, 'importexport') && !$GLOBALS['egw_info']['user']['apps']['admin'])
845
+			if (!$GLOBALS['egw']->acl->check('share_definition', Acl::READ, 'importexport') && !$GLOBALS['egw_info']['user']['apps']['admin'])
847 846
 			{
848 847
 				$content['allowed_users'] = array();
849 848
 				$readonlys['allowed_users'] = true;
@@ -859,11 +858,11 @@  discard block
 block discarded – undo
859 858
 				)
860 859
 			);
861 860
 			// Hide 'just me' checkbox, users get confused by read-only
862
-			if($readonlys['just_me'] || !$this->can_edit($content))
861
+			if ($readonlys['just_me'] || !$this->can_edit($content))
863 862
 			{
864 863
 				$content['no_just_me'] = true;
865 864
 			}
866
-			if($readonlys['all_users'] || !$this->can_edit($content))
865
+			if ($readonlys['all_users'] || !$this->can_edit($content))
867 866
 			{
868 867
 				$content['no_all_users'] = true;
869 868
 			}
@@ -876,7 +875,7 @@  discard block
 block discarded – undo
876 875
 
877 876
 	function wizard_finish(&$content)
878 877
 	{
879
-		if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content,true));
878
+		if (self::_debug) error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content, true));
880 879
 		// Take out some UI leavings
881 880
 		unset($content['text']);
882 881
 		unset($content['step']);
@@ -886,26 +885,26 @@  discard block
 block discarded – undo
886 885
 		$bodefinitions->save($content);
887 886
 		// This message is displayed if browser cant close window
888 887
 		$content['msg'] = lang('ImportExport wizard finished successfully!');
889
-		Framework::refresh_opener('','importexport');
888
+		Framework::refresh_opener('', 'importexport');
890 889
 		Framework::window_close();
891 890
 		return 'importexport.wizard_close';
892 891
 	}
893 892
 
894
-	function import_definition($content='')
893
+	function import_definition($content = '')
895 894
 	{
896 895
 		$bodefinitions = new importexport_definitions_bo();
897 896
 		if (is_array($content))
898 897
 		{
899
-			if($content['import_file']['tmp_name'])
898
+			if ($content['import_file']['tmp_name'])
900 899
 			{
901 900
 				$result = $bodefinitions->import($content['import_file']['tmp_name']);
902
-				$msg = lang('%1 definitions %2', count($result), lang('imported')) ."\n". implode("\n", array_keys($result));
901
+				$msg = lang('%1 definitions %2', count($result), lang('imported'))."\n".implode("\n", array_keys($result));
903 902
 				return $this->index(null, $msg);
904 903
 			}
905
-			if($content['update'])
904
+			if ($content['update'])
906 905
 			{
907 906
 				$applist = importexport_helper_functions::get_apps('all', true);
908
-				foreach($applist as $appname) {
907
+				foreach ($applist as $appname) {
909 908
 					importexport_helper_functions::load_defaults($appname);
910 909
 				}
911 910
 				return $this->index();
@@ -915,7 +914,7 @@  discard block
 block discarded – undo
915 914
 		{
916 915
 			$content = array();
917 916
 			$etpl = new etemplate(self::_appname.'.import_definition');
918
-			return $etpl->exec(self::_appname.'.importexport_definitions_ui.import_definition',$content,array(),$readonlys,$preserv);
917
+			return $etpl->exec(self::_appname.'.importexport_definitions_ui.import_definition', $content, array(), $readonlys, $preserv);
919 918
 		}
920 919
 	}
921 920
 
@@ -925,17 +924,17 @@  discard block
 block discarded – undo
925 924
 	 */
926 925
 	protected function can_edit(Array $definition)
927 926
 	{
928
-		if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'])
927
+		if ($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'])
929 928
 		{
930 929
 			// Definition belongs to user
931 930
 			return true;
932 931
 		}
933
-		elseif($definition['definition_id'] && !$definition['owner'] && $GLOBALS['egw_info']['user']['apps']['admin'])
932
+		elseif ($definition['definition_id'] && !$definition['owner'] && $GLOBALS['egw_info']['user']['apps']['admin'])
934 933
 		{
935 934
 			// Definition is unowned, and user is an admin
936 935
 			return true;
937 936
 		}
938
-		elseif(!$definition['definition_id'])
937
+		elseif (!$definition['definition_id'])
939 938
 		{
940 939
 			// Definition is in-progress, not saved yet
941 940
 			return true;
@@ -948,26 +947,26 @@  discard block
 block discarded – undo
948 947
 	 */
949 948
 	public function site_config($content = array())
950 949
 	{
951
-		if(!$GLOBALS['egw_info']['user']['apps']['admin'])
950
+		if (!$GLOBALS['egw_info']['user']['apps']['admin'])
952 951
 		{
953 952
 			Egw::redirect_link('/home');
954 953
 		}
955
-		if($content['save'])
954
+		if ($content['save'])
956 955
 		{
957 956
 			unset($content['save']);
958 957
 
959 958
 			// ACL
960
-			$GLOBALS['egw']->acl->delete_repository(self::_appname, 'definition',false);
961
-			$GLOBALS['egw']->acl->delete_repository(self::_appname, 'share_definition',false);
959
+			$GLOBALS['egw']->acl->delete_repository(self::_appname, 'definition', false);
960
+			$GLOBALS['egw']->acl->delete_repository(self::_appname, 'share_definition', false);
962 961
 
963
-			foreach($content['share_definition'] as $group)
962
+			foreach ($content['share_definition'] as $group)
964 963
 			{
965
-				$GLOBALS['egw']->acl->add_repository(self::_appname, 'share_definition', $group,Acl::READ);
964
+				$GLOBALS['egw']->acl->add_repository(self::_appname, 'share_definition', $group, Acl::READ);
966 965
 			}
967 966
 			unset($content['share_definition']);
968 967
 
969 968
 			// Other Api\Config
970
-			foreach($content as $key=>$value)
969
+			foreach ($content as $key=>$value)
971 970
 			{
972 971
 				Api\Config::save_value($key, $value, 'importexport');
973 972
 			}
@@ -977,18 +976,18 @@  discard block
 block discarded – undo
977 976
 
978 977
 		$data = Api\Config::read(self::_appname);
979 978
 		$data['share_definition'] = $GLOBALS['egw']->acl->get_ids_for_location('share_definition', Acl::READ, self::_appname);
980
-		$sel_options['import_charsets'] = array_combine(mb_list_encodings(),mb_list_encodings());
979
+		$sel_options['import_charsets'] = array_combine(mb_list_encodings(), mb_list_encodings());
981 980
 
982 981
 		// Remove 'standard' encodings to prevent doubles
983
-		foreach(Api\Translation::get_installed_charsets() as $charset => $label)
982
+		foreach (Api\Translation::get_installed_charsets() as $charset => $label)
984 983
 		{
985 984
 			unset($sel_options['import_charsets'][strtoupper($charset)]);
986 985
 		}
987 986
 
988
-		if(!$data['update']) $data['update'] = 'request';
987
+		if (!$data['update']) $data['update'] = 'request';
989 988
 
990
-		$GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration') . ' - ' . lang(self::_appname);
989
+		$GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration').' - '.lang(self::_appname);
991 990
 		$etpl = new etemplate(self::_appname.'.config');
992
-		$etpl->exec(self::_appname.'.importexport_definitions_ui.site_config',$data,$sel_options,$readonlys,$preserv);
991
+		$etpl->exec(self::_appname.'.importexport_definitions_ui.site_config', $data, $sel_options, $readonlys, $preserv);
993 992
 	}
994 993
 }
Please login to merge, or discard this patch.
importexport/inc/class.importexport_export_csv.inc.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * @param stram $_stream resource where records are exported to.
98 98
 	 * @param array _options options for specific backends
99
-	 * @return bool
99
+	 * @return boolean|null
100 100
 	 */
101 101
 	public function __construct( $_stream, array $_options ) {
102 102
 		if (!is_object($GLOBALS['egw']->translation)) {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * exports a record into resource of handle
152 152
 	 *
153 153
 	 * @param importexport_iface_egw_record record
154
-	 * @return bool
154
+	 * @return boolean|null
155 155
 	 */
156 156
 	public function export_record( importexport_iface_egw_record $_record ) {
157 157
 		$this->record = $_record;
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	 *
285 285
 	 * Uses the static variable $types to convert various datatypes.
286 286
 	 *
287
-	 * @param record Record to be converted
287
+	 * @param record importexport_iface_egw_record to be converted
288 288
 	 * @parem fields List of field types => field names to be converted
289 289
 	 * @param appname Current appname if you want to do custom fields too
290 290
 	 */
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -98,22 +98,22 @@  discard block
 block discarded – undo
98 98
 	 * @param array _options options for specific backends
99 99
 	 * @return bool
100 100
 	 */
101
-	public function __construct( $_stream, array $_options ) {
101
+	public function __construct($_stream, array $_options) {
102 102
 		if (!is_object($GLOBALS['egw']->translation)) {
103 103
 			$GLOBALS['egw']->translation = new Api\Translation();
104 104
 		}
105 105
 		$this->translation = &$GLOBALS['egw']->translation;
106 106
 		$this->handle = $_stream;
107
-		if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
107
+		if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
108 108
 		$this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8';
109
-		if ( !empty( $_options ) ) {
110
-			$this->csv_options = array_merge( $this->csv_options, $_options );
109
+		if (!empty($_options)) {
110
+			$this->csv_options = array_merge($this->csv_options, $_options);
111 111
 		}
112 112
 		//error_log(__METHOD__.__LINE__.array2string($_options['appname']));
113
-		if(!Api\Storage\Merge::is_export_limit_excepted()) {
113
+		if (!Api\Storage\Merge::is_export_limit_excepted()) {
114 114
 			$this->export_limit = Api\Storage\Merge::getExportLimit($_options['appname']);
115 115
 			//error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit);
116
-			if($this->export_limit == 'no') throw new Api\Exception\NoPermission\Admin('Export disabled');
116
+			if ($this->export_limit == 'no') throw new Api\Exception\NoPermission\Admin('Export disabled');
117 117
 		}
118 118
 	}
119 119
 	
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 	 *
123 123
 	 * @param array $_mapping egw_field_name => csv_field_name
124 124
 	 */
125
-	public function set_mapping( array &$_mapping) {
125
+	public function set_mapping(array &$_mapping) {
126 126
 		if ($this->num_of_records > 0) {
127 127
 			throw new Exception('Error: Field mapping can\'t be set during ongoing export!');
128 128
 		}
129
-		if($_mapping['all_custom_fields']) {
129
+		if ($_mapping['all_custom_fields']) {
130 130
 			// Field value is the appname, so we can pull the fields
131 131
 			$custom = Api\Storage\Customfields::get($_mapping['all_custom_fields']);
132 132
 			unset($_mapping['all_custom_fields']);
133
-			foreach($custom as $field => $info) {
133
+			foreach ($custom as $field => $info) {
134 134
 				$_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field;
135 135
 			}
136 136
 		}
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 *
144 144
 	 * @param array $_conversion
145 145
 	 */
146
-	public function set_conversion( array $_conversion) {
146
+	public function set_conversion(array $_conversion) {
147 147
 		$this->conversion = $_conversion;
148 148
 	}
149 149
 	
@@ -153,59 +153,59 @@  discard block
 block discarded – undo
153 153
 	 * @param importexport_iface_egw_record record
154 154
 	 * @return bool
155 155
 	 */
156
-	public function export_record( importexport_iface_egw_record $_record ) {
156
+	public function export_record(importexport_iface_egw_record $_record) {
157 157
 		$this->record = $_record;
158 158
 		$this->record_array = $_record->get_record_array();
159 159
 		
160 160
 		// begin with fieldnames ?
161
-		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) {
162
-			if($this->csv_options['begin_with_fieldnames'] == 'label') {
161
+		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames']) {
162
+			if ($this->csv_options['begin_with_fieldnames'] == 'label') {
163 163
 				// Load translations for app
164 164
 				list($appname, $part2) = explode('_', get_class($_record));
165
-				if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name
165
+				if (!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name
166 166
 
167 167
 				// Get translations from wizard, if possible
168
-				if(!$this->csv_options['no_header_translation'])
168
+				if (!$this->csv_options['no_header_translation'])
169 169
 				{
170 170
 					$backtrace = debug_backtrace();
171 171
 					$plugin = $backtrace[1]['class'];
172
-					$wizard_name = $appname . '_wizard_' . str_replace($appname . '_', '', $plugin);
172
+					$wizard_name = $appname.'_wizard_'.str_replace($appname.'_', '', $plugin);
173 173
 					try {
174 174
 						$wizard = new $wizard_name;
175 175
 						$fields = $wizard->get_export_fields();
176
-						foreach($this->mapping as $field => &$label)
176
+						foreach ($this->mapping as $field => &$label)
177 177
 						{
178
-							if($fields[$field])
178
+							if ($fields[$field])
179 179
 							{
180 180
 								$label = $label != $fields[$field] ? $fields[$field] : lang($label);
181 181
 							}
182 182
 							// Make sure no *
183
-							if(substr($label,-1) == '*') $label = substr($label,0,-1);
183
+							if (substr($label, -1) == '*') $label = substr($label, 0, -1);
184 184
 						}
185 185
 					} catch (Exception $e) {
186 186
 						Api\Translation::add_app($appname);
187
-						foreach($this->mapping as $field => &$label) {
187
+						foreach ($this->mapping as $field => &$label) {
188 188
 							$label = lang($label);
189 189
 						}
190 190
 					}
191 191
 				}
192 192
 			}
193
-			$mapping = ! empty( $this->mapping ) ? $this->mapping : array_keys ( $this->record_array );
194
-			self::fputcsv( $this->handle ,$mapping ,$this->csv_options['delimiter'], $this->csv_options['enclosure'] );
193
+			$mapping = !empty($this->mapping) ? $this->mapping : array_keys($this->record_array);
194
+			self::fputcsv($this->handle, $mapping, $this->csv_options['delimiter'], $this->csv_options['enclosure']);
195 195
 		}
196 196
 
197 197
 		// Check for limit
198
-		if($this->export_limit && $this->num_of_records >= $this->export_limit) {
198
+		if ($this->export_limit && $this->num_of_records >= $this->export_limit) {
199 199
 			return;
200 200
 		}
201 201
 		
202 202
 		// do conversions
203
-		if ( !empty( $this->conversion )) {
204
-			$this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion );
203
+		if (!empty($this->conversion)) {
204
+			$this->record_array = importexport_helper_functions::conversion($this->record_array, $this->conversion);
205 205
 		}
206 206
 		
207 207
 		// do fieldmapping
208
-		if ( !empty( $this->mapping ) ) {
208
+		if (!empty($this->mapping)) {
209 209
 			$record_data = $this->record_array;
210 210
 			$this->record_array = array();
211 211
 			foreach ($this->mapping as $egw_field => $csv_field) {
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			}
214 214
 		}
215 215
 		
216
-		self::fputcsv( $this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure'] );
216
+		self::fputcsv($this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure']);
217 217
 		$this->num_of_records++;
218 218
 	}
219 219
 
@@ -237,13 +237,13 @@  discard block
 block discarded – undo
237 237
 	 * @return Array of fields to be added to list of fields needing conversion
238 238
 	 */
239 239
 	public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) {
240
-		if(!$appname) return;
240
+		if (!$appname) return;
241 241
 
242 242
 		$fields = array();
243 243
 		$custom = Api\Storage\Customfields::get($appname);
244
-		foreach($custom as $name => $c_field) {
245
-			$name = '#' . $name;
246
-			switch($c_field['type']) {
244
+		foreach ($custom as $name => $c_field) {
245
+			$name = '#'.$name;
246
+			switch ($c_field['type']) {
247 247
 				case 'date':
248 248
 					$fields['date'][] = $name;
249 249
 					break;
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 					$fields['select-account'][] = $name;
255 255
 					break;
256 256
 				case 'ajax_select':
257
-					if($c_field['values']['get_title']) {
257
+					if ($c_field['values']['get_title']) {
258 258
 						$methods[$name] = $c_field['values']['get_title'];
259 259
 						break;
260 260
 					}
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 					$selects[$name] = $c_field['values'];
269 269
 					break;
270 270
 				default:
271
-					list($type) = explode('-',$c_field['type'],2);
272
-					if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) {
271
+					list($type) = explode('-', $c_field['type'], 2);
272
+					if (in_array($type, array_keys($GLOBALS['egw_info']['apps']))) {
273 273
 						$fields['links'][] = $name;
274 274
 						$links[$name] = $c_field['type'];
275 275
 					}
@@ -288,18 +288,18 @@  discard block
 block discarded – undo
288 288
 	 * @parem fields List of field types => field names to be converted
289 289
 	 * @param appname Current appname if you want to do custom fields too
290 290
 	 */
291
-	public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) {
292
-		if($appname) {
293
-			if(!self::$cf_parse_cache[$appname]) {
291
+	public static function convert(importexport_iface_egw_record&$record, Array $fields = array(), $appname = null, $selects = array()) {
292
+		if ($appname) {
293
+			if (!self::$cf_parse_cache[$appname]) {
294 294
 				$c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods);
295 295
 				self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
296 296
 			}
297 297
 			list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname];
298 298
 
299 299
 			// Add in any fields that are keys to another app
300
-			foreach((array)$fields['links'] as $link_field => $app)
300
+			foreach ((array)$fields['links'] as $link_field => $app)
301 301
 			{
302
-				if(is_numeric($link_field)) continue;
302
+				if (is_numeric($link_field)) continue;
303 303
 				$links[$link_field] = $app;
304 304
 				// Set it as a normal link field
305 305
 				$fields['links'][] = $link_field;
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
 			}
308 308
 
309 309
 			// Not quite a recursive merge, since only one level
310
-			foreach($fields as $type => &$list) {
311
-				if($c_fields[$type]) {
310
+			foreach ($fields as $type => &$list) {
311
+				if ($c_fields[$type]) {
312 312
 					$list = array_merge($c_fields[$type], $list);
313 313
 					unset($c_fields[$type]);
314 314
 				}
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
 			$fields += $c_fields;
317 317
 			$selects += $c_selects;
318 318
 		}
319
-		foreach((array)$fields['select'] as $name) {
320
-			if($record->$name != null && is_array($selects) && $selects[$name]) {
319
+		foreach ((array)$fields['select'] as $name) {
320
+			if ($record->$name != null && is_array($selects) && $selects[$name]) {
321 321
 				$record->$name = explode(',', $record->$name);
322
-				if(is_array($record->$name)) {
322
+				if (is_array($record->$name)) {
323 323
 					$names = array();
324
-					foreach($record->$name as $_name) {
324
+					foreach ($record->$name as $_name) {
325 325
 						$names[] = lang($selects[$name][$_name]);
326 326
 					}
327 327
 					$record->$name = implode(', ', $names);
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
 				$record->$name = '';
335 335
 			}
336 336
 		}
337
-		foreach((array)$fields['links'] as $name) {
338
-			if($record->$name) {
339
-				if(is_numeric($record->$name) && !$links[$name]) {
337
+		foreach ((array)$fields['links'] as $name) {
338
+			if ($record->$name) {
339
+				if (is_numeric($record->$name) && !$links[$name]) {
340 340
 					$link = Link::get_link($record->$name);
341 341
 					$links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']);
342 342
 					$record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']);
343 343
 				}
344
-				if($links[$name]) {
344
+				if ($links[$name]) {
345 345
 					$record->$name = Link::title($links[$name], $record->$name);
346 346
 				}
347 347
 			}
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 				$record->$name = '';
351 351
 			}
352 352
 		}
353
-		foreach((array)$fields['select-account'] as $name) {
353
+		foreach ((array)$fields['select-account'] as $name) {
354 354
 			// Compare against null to deal with empty arrays
355 355
 			if ($record->$name !== null) {
356
-				if(is_array($record->$name)) {
356
+				if (is_array($record->$name)) {
357 357
 					$names = array();
358
-					foreach($record->$name as $_name) {
358
+					foreach ($record->$name as $_name) {
359 359
 						$names[] = Api\Accounts::username($_name);
360 360
 					}
361 361
 					$record->$name = implode(', ', $names);
@@ -368,64 +368,64 @@  discard block
 block discarded – undo
368 368
 				$record->$name = '';
369 369
 			}
370 370
 		}
371
-		foreach((array)$fields['select-bool'] as $name) {
372
-			if($record->$name !== null) {
371
+		foreach ((array)$fields['select-bool'] as $name) {
372
+			if ($record->$name !== null) {
373 373
 				$record->$name = $record->$name ? lang('Yes') : lang('No');
374 374
 			}
375 375
 		}
376
-		foreach((array)$fields['date-time'] as $name) {
376
+		foreach ((array)$fields['date-time'] as $name) {
377 377
 			//if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format
378 378
 			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
379
-			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
380
-				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format
379
+			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.
380
+				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'), $record->$name); // User date format
381 381
 			if (!$record->$name) $record->$name = '';
382 382
 		}
383
-		foreach((array)$fields['date'] as $name) {
383
+		foreach ((array)$fields['date'] as $name) {
384 384
 			//if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format
385 385
 			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
386 386
 			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format
387 387
 			if (!$record->$name) $record->$name = '';
388 388
 		}
389
-		foreach((array)$fields['float'] as $name)
389
+		foreach ((array)$fields['float'] as $name)
390 390
 		{
391
-			static $dec_separator,$thousands_separator;
391
+			static $dec_separator, $thousands_separator;
392 392
 			if (is_null($dec_separator))
393 393
 			{
394 394
 				$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
395 395
 				if (empty($dec_separator)) $dec_separator = '.';
396 396
 				$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
397 397
 			}
398
-			if($record->$name && (string)$record->$name != '')
398
+			if ($record->$name && (string)$record->$name != '')
399 399
 			{
400
-				if(!is_numeric($record->$name))
400
+				if (!is_numeric($record->$name))
401 401
 				{
402 402
 					$record->$name = floatval(str_replace($dec_separator, '.', preg_replace('/[^\d'.preg_quote($dec_separator).']/', '', $record->$name)));
403 403
 				}
404
-				$record->$name = number_format(str_replace(' ','',$record->$name), 2,
405
-					$dec_separator,$thousands_separator
404
+				$record->$name = number_format(str_replace(' ', '', $record->$name), 2,
405
+					$dec_separator, $thousands_separator
406 406
 				);
407 407
 			}
408 408
 		}
409 409
 
410 410
 		// Some custom methods for conversion
411
-		foreach((array)$methods as $name => $method) {
412
-			if($record->$name) $record->$name = ExecMethod($method, $record->$name);
411
+		foreach ((array)$methods as $name => $method) {
412
+			if ($record->$name) $record->$name = ExecMethod($method, $record->$name);
413 413
 		}
414 414
 
415 415
 		static $cat_object;
416
-		if(is_null($cat_object)) $cat_object = new Api\Categories(false,$appname);
417
-		foreach((array)$fields['select-cat'] as $name) {
418
-			if($record->$name) {
416
+		if (is_null($cat_object)) $cat_object = new Api\Categories(false, $appname);
417
+		foreach ((array)$fields['select-cat'] as $name) {
418
+			if ($record->$name) {
419 419
 				$cats = array();
420 420
 				$ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name);
421
-				foreach($ids as $n => $cat_id) {
421
+				foreach ($ids as $n => $cat_id) {
422 422
 
423
-					if ($cat_id && $cat_object->check_perms(Acl::READ,$cat_id))
423
+					if ($cat_id && $cat_object->check_perms(Acl::READ, $cat_id))
424 424
 					{
425 425
 						$cats[] = $cat_object->id2name($cat_id);
426 426
 					}
427 427
 				}
428
-				$record->$name = implode(', ',$cats);
428
+				$record->$name = implode(', ', $cats);
429 429
 			}
430 430
 			else
431 431
 			{
@@ -452,18 +452,18 @@  discard block
 block discarded – undo
452 452
 	 * @param char $delimiter
453 453
 	 * @param char $enclosure
454 454
 	 */
455
-	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){
455
+	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure) {
456 456
 		$string = "";
457 457
 		$writeDelimiter = false;
458
-		foreach($dataArray as $dataElement) {
459
-			if($writeDelimiter) $string .= $delimiter;
460
-			$string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure;
458
+		foreach ($dataArray as $dataElement) {
459
+			if ($writeDelimiter) $string .= $delimiter;
460
+			$string .= $enclosure.str_replace(array("\r\n", '"'), array("\n", '""'), $dataElement).$enclosure;
461 461
 			$writeDelimiter = true;
462 462
 		}
463 463
 		$string .= "\n";
464 464
 		
465 465
 		// do charset translation
466
-		$string = $this->translation->convert( $string, $this->translation->charset(), $this->csv_charset );
466
+		$string = $this->translation->convert($string, $this->translation->charset(), $this->csv_charset);
467 467
 		
468 468
 		fwrite($filePointer, $string);
469 469
 			
Please login to merge, or discard this patch.
Braces   +180 added lines, -71 removed lines patch added patch discarded remove patch
@@ -98,22 +98,32 @@  discard block
 block discarded – undo
98 98
 	 * @param array _options options for specific backends
99 99
 	 * @return bool
100 100
 	 */
101
-	public function __construct( $_stream, array $_options ) {
102
-		if (!is_object($GLOBALS['egw']->translation)) {
101
+	public function __construct( $_stream, array $_options )
102
+	{
103
+		if (!is_object($GLOBALS['egw']->translation))
104
+		{
103 105
 			$GLOBALS['egw']->translation = new Api\Translation();
104 106
 		}
105 107
 		$this->translation = &$GLOBALS['egw']->translation;
106 108
 		$this->handle = $_stream;
107
-		if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
109
+		if($_options['charset'] == 'user')
110
+		{
111
+			$_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
112
+		}
108 113
 		$this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8';
109
-		if ( !empty( $_options ) ) {
114
+		if ( !empty( $_options ) )
115
+		{
110 116
 			$this->csv_options = array_merge( $this->csv_options, $_options );
111 117
 		}
112 118
 		//error_log(__METHOD__.__LINE__.array2string($_options['appname']));
113
-		if(!Api\Storage\Merge::is_export_limit_excepted()) {
119
+		if(!Api\Storage\Merge::is_export_limit_excepted())
120
+		{
114 121
 			$this->export_limit = Api\Storage\Merge::getExportLimit($_options['appname']);
115 122
 			//error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit);
116
-			if($this->export_limit == 'no') throw new Api\Exception\NoPermission\Admin('Export disabled');
123
+			if($this->export_limit == 'no')
124
+			{
125
+				throw new Api\Exception\NoPermission\Admin('Export disabled');
126
+			}
117 127
 		}
118 128
 	}
119 129
 	
@@ -122,15 +132,19 @@  discard block
 block discarded – undo
122 132
 	 *
123 133
 	 * @param array $_mapping egw_field_name => csv_field_name
124 134
 	 */
125
-	public function set_mapping( array &$_mapping) {
126
-		if ($this->num_of_records > 0) {
135
+	public function set_mapping( array &$_mapping)
136
+	{
137
+		if ($this->num_of_records > 0)
138
+		{
127 139
 			throw new Exception('Error: Field mapping can\'t be set during ongoing export!');
128 140
 		}
129
-		if($_mapping['all_custom_fields']) {
141
+		if($_mapping['all_custom_fields'])
142
+		{
130 143
 			// Field value is the appname, so we can pull the fields
131 144
 			$custom = Api\Storage\Customfields::get($_mapping['all_custom_fields']);
132 145
 			unset($_mapping['all_custom_fields']);
133
-			foreach($custom as $field => $info) {
146
+			foreach($custom as $field => $info)
147
+			{
134 148
 				$_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field;
135 149
 			}
136 150
 		}
@@ -143,7 +157,8 @@  discard block
 block discarded – undo
143 157
 	 *
144 158
 	 * @param array $_conversion
145 159
 	 */
146
-	public function set_conversion( array $_conversion) {
160
+	public function set_conversion( array $_conversion)
161
+	{
147 162
 		$this->conversion = $_conversion;
148 163
 	}
149 164
 	
@@ -153,16 +168,23 @@  discard block
 block discarded – undo
153 168
 	 * @param importexport_iface_egw_record record
154 169
 	 * @return bool
155 170
 	 */
156
-	public function export_record( importexport_iface_egw_record $_record ) {
171
+	public function export_record( importexport_iface_egw_record $_record )
172
+	{
157 173
 		$this->record = $_record;
158 174
 		$this->record_array = $_record->get_record_array();
159 175
 		
160 176
 		// begin with fieldnames ?
161
-		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) {
162
-			if($this->csv_options['begin_with_fieldnames'] == 'label') {
177
+		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] )
178
+		{
179
+			if($this->csv_options['begin_with_fieldnames'] == 'label')
180
+			{
163 181
 				// Load translations for app
164 182
 				list($appname, $part2) = explode('_', get_class($_record));
165
-				if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name
183
+				if(!$GLOBALS['egw_info']['apps'][$appname])
184
+				{
185
+					$appname .= $part2;
186
+				}
187
+				// Handle apps with _ in the name
166 188
 
167 189
 				// Get translations from wizard, if possible
168 190
 				if(!$this->csv_options['no_header_translation'])
@@ -180,11 +202,16 @@  discard block
 block discarded – undo
180 202
 								$label = $label != $fields[$field] ? $fields[$field] : lang($label);
181 203
 							}
182 204
 							// Make sure no *
183
-							if(substr($label,-1) == '*') $label = substr($label,0,-1);
205
+							if(substr($label,-1) == '*')
206
+							{
207
+								$label = substr($label,0,-1);
208
+							}
184 209
 						}
185
-					} catch (Exception $e) {
210
+					}
211
+					catch (Exception $e) {
186 212
 						Api\Translation::add_app($appname);
187
-						foreach($this->mapping as $field => &$label) {
213
+						foreach($this->mapping as $field => &$label)
214
+						{
188 215
 							$label = lang($label);
189 216
 						}
190 217
 					}
@@ -195,20 +222,24 @@  discard block
 block discarded – undo
195 222
 		}
196 223
 
197 224
 		// Check for limit
198
-		if($this->export_limit && $this->num_of_records >= $this->export_limit) {
225
+		if($this->export_limit && $this->num_of_records >= $this->export_limit)
226
+		{
199 227
 			return;
200 228
 		}
201 229
 		
202 230
 		// do conversions
203
-		if ( !empty( $this->conversion )) {
231
+		if ( !empty( $this->conversion ))
232
+		{
204 233
 			$this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion );
205 234
 		}
206 235
 		
207 236
 		// do fieldmapping
208
-		if ( !empty( $this->mapping ) ) {
237
+		if ( !empty( $this->mapping ) )
238
+		{
209 239
 			$record_data = $this->record_array;
210 240
 			$this->record_array = array();
211
-			foreach ($this->mapping as $egw_field => $csv_field) {
241
+			foreach ($this->mapping as $egw_field => $csv_field)
242
+			{
212 243
 				$this->record_array[$csv_field] = $record_data[$egw_field];
213 244
 			}
214 245
 		}
@@ -222,7 +253,8 @@  discard block
 block discarded – undo
222 253
 	 *
223 254
 	 * @return int
224 255
 	 */
225
-	public function get_num_of_records() {
256
+	public function get_num_of_records()
257
+	{
226 258
 		return $this->num_of_records;
227 259
 	}
228 260
 
@@ -236,14 +268,20 @@  discard block
 block discarded – undo
236 268
 	 *
237 269
 	 * @return Array of fields to be added to list of fields needing conversion
238 270
 	 */
239
-	public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) {
240
-		if(!$appname) return;
271
+	public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array())
272
+	{
273
+		if(!$appname)
274
+		{
275
+			return;
276
+		}
241 277
 
242 278
 		$fields = array();
243 279
 		$custom = Api\Storage\Customfields::get($appname);
244
-		foreach($custom as $name => $c_field) {
280
+		foreach($custom as $name => $c_field)
281
+		{
245 282
 			$name = '#' . $name;
246
-			switch($c_field['type']) {
283
+			switch($c_field['type'])
284
+			{
247 285
 				case 'date':
248 286
 					$fields['date'][] = $name;
249 287
 					break;
@@ -254,7 +292,8 @@  discard block
 block discarded – undo
254 292
 					$fields['select-account'][] = $name;
255 293
 					break;
256 294
 				case 'ajax_select':
257
-					if($c_field['values']['get_title']) {
295
+					if($c_field['values']['get_title'])
296
+					{
258 297
 						$methods[$name] = $c_field['values']['get_title'];
259 298
 						break;
260 299
 					}
@@ -269,7 +308,8 @@  discard block
 block discarded – undo
269 308
 					break;
270 309
 				default:
271 310
 					list($type) = explode('-',$c_field['type'],2);
272
-					if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) {
311
+					if(in_array($type, array_keys($GLOBALS['egw_info']['apps'])))
312
+					{
273 313
 						$fields['links'][] = $name;
274 314
 						$links[$name] = $c_field['type'];
275 315
 					}
@@ -288,9 +328,12 @@  discard block
 block discarded – undo
288 328
 	 * @parem fields List of field types => field names to be converted
289 329
 	 * @param appname Current appname if you want to do custom fields too
290 330
 	 */
291
-	public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) {
292
-		if($appname) {
293
-			if(!self::$cf_parse_cache[$appname]) {
331
+	public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array())
332
+	{
333
+		if($appname)
334
+		{
335
+			if(!self::$cf_parse_cache[$appname])
336
+			{
294 337
 				$c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods);
295 338
 				self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
296 339
 			}
@@ -299,7 +342,10 @@  discard block
 block discarded – undo
299 342
 			// Add in any fields that are keys to another app
300 343
 			foreach((array)$fields['links'] as $link_field => $app)
301 344
 			{
302
-				if(is_numeric($link_field)) continue;
345
+				if(is_numeric($link_field))
346
+				{
347
+					continue;
348
+				}
303 349
 				$links[$link_field] = $app;
304 350
 				// Set it as a normal link field
305 351
 				$fields['links'][] = $link_field;
@@ -307,8 +353,10 @@  discard block
 block discarded – undo
307 353
 			}
308 354
 
309 355
 			// Not quite a recursive merge, since only one level
310
-			foreach($fields as $type => &$list) {
311
-				if($c_fields[$type]) {
356
+			foreach($fields as $type => &$list)
357
+			{
358
+				if($c_fields[$type])
359
+				{
312 360
 					$list = array_merge($c_fields[$type], $list);
313 361
 					unset($c_fields[$type]);
314 362
 				}
@@ -316,16 +364,22 @@  discard block
 block discarded – undo
316 364
 			$fields += $c_fields;
317 365
 			$selects += $c_selects;
318 366
 		}
319
-		foreach((array)$fields['select'] as $name) {
320
-			if($record->$name != null && is_array($selects) && $selects[$name]) {
367
+		foreach((array)$fields['select'] as $name)
368
+		{
369
+			if($record->$name != null && is_array($selects) && $selects[$name])
370
+			{
321 371
 				$record->$name = explode(',', $record->$name);
322
-				if(is_array($record->$name)) {
372
+				if(is_array($record->$name))
373
+				{
323 374
 					$names = array();
324
-					foreach($record->$name as $_name) {
375
+					foreach($record->$name as $_name)
376
+					{
325 377
 						$names[] = lang($selects[$name][$_name]);
326 378
 					}
327 379
 					$record->$name = implode(', ', $names);
328
-				} else {
380
+				}
381
+				else
382
+				{
329 383
 					$record->$name = lang($selects[$name][$record->$name]);
330 384
 				}
331 385
 			}
@@ -334,14 +388,18 @@  discard block
 block discarded – undo
334 388
 				$record->$name = '';
335 389
 			}
336 390
 		}
337
-		foreach((array)$fields['links'] as $name) {
338
-			if($record->$name) {
339
-				if(is_numeric($record->$name) && !$links[$name]) {
391
+		foreach((array)$fields['links'] as $name)
392
+		{
393
+			if($record->$name)
394
+			{
395
+				if(is_numeric($record->$name) && !$links[$name])
396
+				{
340 397
 					$link = Link::get_link($record->$name);
341 398
 					$links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']);
342 399
 					$record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']);
343 400
 				}
344
-				if($links[$name]) {
401
+				if($links[$name])
402
+				{
345 403
 					$record->$name = Link::title($links[$name], $record->$name);
346 404
 				}
347 405
 			}
@@ -350,16 +408,22 @@  discard block
 block discarded – undo
350 408
 				$record->$name = '';
351 409
 			}
352 410
 		}
353
-		foreach((array)$fields['select-account'] as $name) {
411
+		foreach((array)$fields['select-account'] as $name)
412
+		{
354 413
 			// Compare against null to deal with empty arrays
355
-			if ($record->$name !== null) {
356
-				if(is_array($record->$name)) {
414
+			if ($record->$name !== null)
415
+			{
416
+				if(is_array($record->$name))
417
+				{
357 418
 					$names = array();
358
-					foreach($record->$name as $_name) {
419
+					foreach($record->$name as $_name)
420
+					{
359 421
 						$names[] = Api\Accounts::username($_name);
360 422
 					}
361 423
 					$record->$name = implode(', ', $names);
362
-				} else {
424
+				}
425
+				else
426
+				{
363 427
 					$record->$name = Api\Accounts::username($record->$name);
364 428
 				}
365 429
 			}
@@ -368,23 +432,49 @@  discard block
 block discarded – undo
368 432
 				$record->$name = '';
369 433
 			}
370 434
 		}
371
-		foreach((array)$fields['select-bool'] as $name) {
372
-			if($record->$name !== null) {
435
+		foreach((array)$fields['select-bool'] as $name)
436
+		{
437
+			if($record->$name !== null)
438
+			{
373 439
 				$record->$name = $record->$name ? lang('Yes') : lang('No');
374 440
 			}
375 441
 		}
376
-		foreach((array)$fields['date-time'] as $name) {
442
+		foreach((array)$fields['date-time'] as $name)
443
+		{
377 444
 			//if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format
378
-			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
379
-			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
380
-				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format
381
-			if (!$record->$name) $record->$name = '';
445
+			if ($record->$name && !is_numeric($record->$name))
446
+			{
447
+				$record->$name = strtotime($record->$name);
448
+			}
449
+			// Custom fields stored as string
450
+			if ($record->$name && is_numeric($record->$name))
451
+			{
452
+				$record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
453
+				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name);
454
+			}
455
+			// User date format
456
+			if (!$record->$name)
457
+			{
458
+				$record->$name = '';
459
+			}
382 460
 		}
383
-		foreach((array)$fields['date'] as $name) {
461
+		foreach((array)$fields['date'] as $name)
462
+		{
384 463
 			//if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format
385
-			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
386
-			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format
387
-			if (!$record->$name) $record->$name = '';
464
+			if ($record->$name && !is_numeric($record->$name))
465
+			{
466
+				$record->$name = strtotime($record->$name);
467
+			}
468
+			// Custom fields stored as string
469
+			if ($record->$name && is_numeric($record->$name))
470
+			{
471
+				$record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name);
472
+			}
473
+			// User date format
474
+			if (!$record->$name)
475
+			{
476
+				$record->$name = '';
477
+			}
388 478
 		}
389 479
 		foreach((array)$fields['float'] as $name)
390 480
 		{
@@ -392,7 +482,10 @@  discard block
 block discarded – undo
392 482
 			if (is_null($dec_separator))
393 483
 			{
394 484
 				$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
395
-				if (empty($dec_separator)) $dec_separator = '.';
485
+				if (empty($dec_separator))
486
+				{
487
+					$dec_separator = '.';
488
+				}
396 489
 				$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
397 490
 			}
398 491
 			if($record->$name && (string)$record->$name != '')
@@ -408,17 +501,27 @@  discard block
 block discarded – undo
408 501
 		}
409 502
 
410 503
 		// Some custom methods for conversion
411
-		foreach((array)$methods as $name => $method) {
412
-			if($record->$name) $record->$name = ExecMethod($method, $record->$name);
504
+		foreach((array)$methods as $name => $method)
505
+		{
506
+			if($record->$name)
507
+			{
508
+				$record->$name = ExecMethod($method, $record->$name);
509
+			}
413 510
 		}
414 511
 
415 512
 		static $cat_object;
416
-		if(is_null($cat_object)) $cat_object = new Api\Categories(false,$appname);
417
-		foreach((array)$fields['select-cat'] as $name) {
418
-			if($record->$name) {
513
+		if(is_null($cat_object))
514
+		{
515
+			$cat_object = new Api\Categories(false,$appname);
516
+		}
517
+		foreach((array)$fields['select-cat'] as $name)
518
+		{
519
+			if($record->$name)
520
+			{
419 521
 				$cats = array();
420 522
 				$ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name);
421
-				foreach($ids as $n => $cat_id) {
523
+				foreach($ids as $n => $cat_id)
524
+				{
422 525
 
423 526
 					if ($cat_id && $cat_object->check_perms(Acl::READ,$cat_id))
424 527
 					{
@@ -439,7 +542,8 @@  discard block
 block discarded – undo
439 542
 	 *
440 543
 	 * @return
441 544
 	 */
442
-	public function __destruct() {
545
+	public function __destruct()
546
+	{
443 547
 		
444 548
 	}
445 549
 
@@ -452,11 +556,16 @@  discard block
 block discarded – undo
452 556
 	 * @param char $delimiter
453 557
 	 * @param char $enclosure
454 558
 	 */
455
-	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){
559
+	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure)
560
+	{
456 561
 		$string = "";
457 562
 		$writeDelimiter = false;
458
-		foreach($dataArray as $dataElement) {
459
-			if($writeDelimiter) $string .= $delimiter;
563
+		foreach($dataArray as $dataElement)
564
+		{
565
+			if($writeDelimiter)
566
+			{
567
+				$string .= $delimiter;
568
+			}
460 569
 			$string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure;
461 570
 			$writeDelimiter = true;
462 571
 		}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 	 * @parem fields List of field types => field names to be converted
289 289
 	 * @param appname Current appname if you want to do custom fields too
290 290
 	 */
291
-	public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) {
291
+	public static function convert(importexport_iface_egw_record &$record, array $fields = array(), $appname = null, $selects = array()) {
292 292
 		if($appname) {
293 293
 			if(!self::$cf_parse_cache[$appname]) {
294 294
 				$c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods);
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 	 * @param char $delimiter
453 453
 	 * @param char $enclosure
454 454
 	 */
455
-	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){
455
+	protected function fputcsv($filePointer, array $dataArray, $delimiter, $enclosure){
456 456
 		$string = "";
457 457
 		$writeDelimiter = false;
458 458
 		foreach($dataArray as $dataElement) {
Please login to merge, or discard this patch.
importexport/inc/class.importexport_helper_functions.inc.php 5 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	/**
124 124
 	 * converts accound_lid to account_id
125 125
 	 *
126
-	 * @param mixed $_account_lid comma seperated list or array with lids
126
+	 * @param mixed $_account_lids comma seperated list or array with lids
127 127
 	 * @return mixed comma seperated list or array with ids
128 128
 	 */
129 129
 	public static function account_name2id( &$_account_lids ) {
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	/**
204 204
 	 * converts account_ids to account_lids
205 205
 	 *
206
-	 * @param mixed $_account_ids comma seperated list or array with ids
206
+	 * @param mixed $_account_id comma seperated list or array with ids
207 207
 	 * @return mixed comma seperated list or array with lids
208 208
 	 */
209 209
 	public static function account_id2name( $_account_id ) {
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	/**
420 420
 	 * returns a list of importexport plugins
421 421
 	 *
422
-	 * @param string $_tpye {import | export | all}
422
+	 * @param string $_type {import | export | all}
423 423
 	 * @param string $_appname {<appname> | all}
424 424
 	 * @return array(<appname> => array( <type> => array(<plugin> => <title>)))
425 425
 	 */
@@ -591,6 +591,7 @@  discard block
 block discarded – undo
591 591
 	 *
592 592
 	 * @param $app_name String name of app
593 593
 	 * @param $plugin_name Name of the plugin
594
+	 * @param importexport_wizard_basic_export_csv $wizard_plugin
594 595
 	 *
595 596
 	 * @return Array ([fieldname] => array(widget settings), ...)
596 597
 	 */
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -32,25 +32,25 @@  discard block
 block discarded – undo
32 32
 	 * Relative date ranges for filtering
33 33
 	 */
34 34
 	public static $relative_dates = array(      // Start: year,month,day,week, End: year,month,day,week
35
-                'Today'       => array(0,0,0,0,  0,0,1,0),
36
-                'Yesterday'   => array(0,0,-1,0, 0,0,0,0),
37
-                'This week'   => array(0,0,0,0,  0,0,0,1),
38
-                'Last week'   => array(0,0,0,-1, 0,0,0,0),
39
-                'This month'  => array(0,0,0,0,  0,1,0,0),
40
-                'Last month'  => array(0,-1,0,0, 0,0,0,0),
41
-                'Last 3 months' => array(0,-3,0,0, 0,0,0,0),
42
-                'This quarter'=> array(0,0,0,0,  0,0,0,0),      // Just a marker, needs special handling
43
-                'Last quarter'=> array(0,-4,0,0, 0,-4,0,0),     // Just a marker
44
-                'This year'   => array(0,0,0,0,  1,0,0,0),
45
-                'Last year'   => array(-1,0,0,0, 0,0,0,0),
46
-                '2 years ago' => array(-2,0,0,0, -1,0,0,0),
47
-                '3 years ago' => array(-3,0,0,0, -2,0,0,0),
48
-        );
35
+				'Today'       => array(0,0,0,0,  0,0,1,0),
36
+				'Yesterday'   => array(0,0,-1,0, 0,0,0,0),
37
+				'This week'   => array(0,0,0,0,  0,0,0,1),
38
+				'Last week'   => array(0,0,0,-1, 0,0,0,0),
39
+				'This month'  => array(0,0,0,0,  0,1,0,0),
40
+				'Last month'  => array(0,-1,0,0, 0,0,0,0),
41
+				'Last 3 months' => array(0,-3,0,0, 0,0,0,0),
42
+				'This quarter'=> array(0,0,0,0,  0,0,0,0),      // Just a marker, needs special handling
43
+				'Last quarter'=> array(0,-4,0,0, 0,-4,0,0),     // Just a marker
44
+				'This year'   => array(0,0,0,0,  1,0,0,0),
45
+				'Last year'   => array(-1,0,0,0, 0,0,0,0),
46
+				'2 years ago' => array(-2,0,0,0, -1,0,0,0),
47
+				'3 years ago' => array(-3,0,0,0, -2,0,0,0),
48
+		);
49 49
 
50 50
 	/**
51
-	* Files known to cause problems, and will be skipped in a plugin scan
52
-	* If you put appname => true, the whole app will be skipped.
53
-	*/
51
+	 * Files known to cause problems, and will be skipped in a plugin scan
52
+	 * If you put appname => true, the whole app will be skipped.
53
+	 */
54 54
 	protected static $blacklist_files = array(
55 55
 		'api' => true,
56 56
 		'etemplate' => true,
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	);
65 65
 
66 66
 	/**
67
-	* Class used to provide extra conversion functions
68
-	*
69
-	* Passed in as a param to conversion()
70
-	*/
67
+	 * Class used to provide extra conversion functions
68
+	 *
69
+	 * Passed in as a param to conversion()
70
+	 */
71 71
 	protected static $cclass = null;
72 72
 
73 73
 	/**
Please login to merge, or discard this patch.
Spacing   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
 	 * Relative date ranges for filtering
33 33
 	 */
34 34
 	public static $relative_dates = array(      // Start: year,month,day,week, End: year,month,day,week
35
-                'Today'       => array(0,0,0,0,  0,0,1,0),
36
-                'Yesterday'   => array(0,0,-1,0, 0,0,0,0),
37
-                'This week'   => array(0,0,0,0,  0,0,0,1),
38
-                'Last week'   => array(0,0,0,-1, 0,0,0,0),
39
-                'This month'  => array(0,0,0,0,  0,1,0,0),
40
-                'Last month'  => array(0,-1,0,0, 0,0,0,0),
41
-                'Last 3 months' => array(0,-3,0,0, 0,0,0,0),
42
-                'This quarter'=> array(0,0,0,0,  0,0,0,0),      // Just a marker, needs special handling
43
-                'Last quarter'=> array(0,-4,0,0, 0,-4,0,0),     // Just a marker
44
-                'This year'   => array(0,0,0,0,  1,0,0,0),
45
-                'Last year'   => array(-1,0,0,0, 0,0,0,0),
46
-                '2 years ago' => array(-2,0,0,0, -1,0,0,0),
47
-                '3 years ago' => array(-3,0,0,0, -2,0,0,0),
35
+                'Today'       => array(0, 0, 0, 0, 0, 0, 1, 0),
36
+                'Yesterday'   => array(0, 0, -1, 0, 0, 0, 0, 0),
37
+                'This week'   => array(0, 0, 0, 0, 0, 0, 0, 1),
38
+                'Last week'   => array(0, 0, 0, -1, 0, 0, 0, 0),
39
+                'This month'  => array(0, 0, 0, 0, 0, 1, 0, 0),
40
+                'Last month'  => array(0, -1, 0, 0, 0, 0, 0, 0),
41
+                'Last 3 months' => array(0, -3, 0, 0, 0, 0, 0, 0),
42
+                'This quarter'=> array(0, 0, 0, 0, 0, 0, 0, 0), // Just a marker, needs special handling
43
+                'Last quarter'=> array(0, -4, 0, 0, 0, -4, 0, 0), // Just a marker
44
+                'This year'   => array(0, 0, 0, 0, 1, 0, 0, 0),
45
+                'Last year'   => array(-1, 0, 0, 0, 0, 0, 0, 0),
46
+                '2 years ago' => array(-2, 0, 0, 0, -1, 0, 0, 0),
47
+                '3 years ago' => array(-3, 0, 0, 0, -2, 0, 0, 0),
48 48
         );
49 49
 
50 50
 	/**
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
 	 * @param string $_format format of time string e.g.: d.m.Y H:i
86 86
 	 * @param int $_is_dst is day light saving time? 0 = no, 1 = yes, -1 = system default
87 87
 	 */
88
-	public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) {
89
-		if ( empty( $_format ) ) return strtotime( $_string );
90
-		$fparams = explode( ',', chunk_split( $_format, 1, ',' ) );
88
+	public static function custom_strtotime($_string, $_format = '', $_is_dst = -1) {
89
+		if (empty($_format)) return strtotime($_string);
90
+		$fparams = explode(',', chunk_split($_format, 1, ','));
91 91
 		$spos = 0;
92
-		foreach ( $fparams as $fparam ) {
93
-
94
-			switch ( $fparam ) {
95
-				case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break;
96
-				case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break;
97
-				case 'y': (int)$year = substr( $_string, $spos, 2 ); $spos += 2; break;
98
-				case 'Y': (int)$year = substr( $_string, $spos, 4 ); $spos += 4; break;
99
-				case 'H': (int)$hour = substr( $_string, $spos, 2 ); $spos += 2; break;
100
-				case 'h': (int)$hour = substr( $_string, $spos, 2 ); $spos += 2; break;
101
-				case 'i': (int)$min =  substr( $_string, $spos, 2 ); $spos += 2; break;
102
-				case 's': (int)$sec =  substr( $_string, $spos, 2 ); $spos += 2; break;
103
-				case 'O': (int)$offset = $year = substr( $_string, $spos, 5 ); $spos += 5; break;
92
+		foreach ($fparams as $fparam) {
93
+
94
+			switch ($fparam) {
95
+				case 'd': (int)$day = substr($_string, $spos, 2); $spos += 2; break;
96
+				case 'm': (int)$mon = substr($_string, $spos, 2); $spos += 2; break;
97
+				case 'y': (int)$year = substr($_string, $spos, 2); $spos += 2; break;
98
+				case 'Y': (int)$year = substr($_string, $spos, 4); $spos += 4; break;
99
+				case 'H': (int)$hour = substr($_string, $spos, 2); $spos += 2; break;
100
+				case 'h': (int)$hour = substr($_string, $spos, 2); $spos += 2; break;
101
+				case 'i': (int)$min = substr($_string, $spos, 2); $spos += 2; break;
102
+				case 's': (int)$sec = substr($_string, $spos, 2); $spos += 2; break;
103
+				case 'O': (int)$offset = $year = substr($_string, $spos, 5); $spos += 5; break;
104 104
 				case 'a': (int)$hour = $fparam == 'am' ? $hour : $hour + 12; break;
105 105
 				case 'A': (int)$hour = $fparam == 'AM' ? $hour : $hour + 12; break;
106 106
 				default: $spos++; // seperator
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 		$timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst);
112 112
 
113 113
 		// offset given?
114
-		if ( isset( $offset ) && strlen( $offset == 5 ) ) {
114
+		if (isset($offset) && strlen($offset == 5)) {
115 115
 			$operator = $offset{0};
116
-			$ohour = 60 * 60 * (int)substr( $offset, 1, 2 );
117
-			$omin = 60 * (int)substr( $offset, 3, 2 );
118
-			if ( $operator == '+' ) $timestamp += $ohour + $omin;
116
+			$ohour = 60 * 60 * (int)substr($offset, 1, 2);
117
+			$omin = 60 * (int)substr($offset, 3, 2);
118
+			if ($operator == '+') $timestamp += $ohour + $omin;
119 119
 			else $timestamp -= $ohour + $omin;
120 120
 		}
121 121
 		return $timestamp;
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 	 * @param mixed $_account_lid comma seperated list or array with lids
127 127
 	 * @return mixed comma seperated list or array with ids
128 128
 	 */
129
-	public static function account_name2id( &$_account_lids ) {
130
-		$account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids );
129
+	public static function account_name2id(&$_account_lids) {
130
+		$account_lids = is_array($_account_lids) ? $_account_lids : explode(',', $_account_lids);
131 131
 		$skip = false;
132
-		foreach ( $account_lids as $key => $account_lid ) {
133
-			if($skip) {
132
+		foreach ($account_lids as $key => $account_lid) {
133
+			if ($skip) {
134 134
 				unset($account_lids[$key]);
135 135
 				$skip = false;
136 136
 				continue;
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 			$account_lid = trim($account_lid);
139 139
 
140 140
 			// Handle any IDs that slip in
141
-			if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) {
141
+			if (is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) {
142 142
 				unset($account_lids[$key]);
143 143
 				$account_ids[] = (int)$account_lid;
144 144
 				continue;
145 145
 			}
146 146
 			// Check for [username]
147
-			if(strpos($account_lid,'[') !== false)
147
+			if (strpos($account_lid, '[') !== false)
148 148
 			{
149
-				if(preg_match('/\[(.+)\]/',$account_lid,$matches))
149
+				if (preg_match('/\[(.+)\]/', $account_lid, $matches))
150 150
 				{
151 151
 					$account_id = $GLOBALS['egw']->accounts->name2id($matches[1]);
152 152
 					unset($account_lids[$key]);
@@ -157,46 +157,46 @@  discard block
 block discarded – undo
157 157
 
158 158
 			// Handle users listed as Lastname, Firstname instead of login ID
159 159
 			// Do this first, in case their first name matches a username
160
-			if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) {
160
+			if ($account_lids[$key + 1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id(trim($account_lids[$key + 1]).' '.$account_lid, 'account_fullname')) {
161 161
 				$account_ids[] = $account_id;
162 162
 				unset($account_lids[$key]);
163 163
 				$skip = true; // Skip the next one, it's the first name
164
-				continue ;
164
+				continue;
165 165
 			}
166 166
 
167 167
 			// Deal with groups listed as <name> Group, remove the Group
168
-			if(substr(trim($account_lid),-strlen(lang('Group'))) == lang('Group'))
168
+			if (substr(trim($account_lid), -strlen(lang('Group'))) == lang('Group'))
169 169
 			{
170 170
 				$account_lid = trim(substr(trim($account_lid), 0, -strlen(lang('Group'))));
171 171
 			}
172 172
 
173
-			if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) {
173
+			if ($account_id = $GLOBALS['egw']->accounts->name2id($account_lid)) {
174 174
 				$account_ids[] = $account_id;
175 175
 				unset($account_lids[$key]);
176 176
 				continue;
177 177
 			}
178
-			if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) {
178
+			if ($account_id = $GLOBALS['egw']->accounts->name2id(trim($account_lid), 'account_fullname')) {
179 179
 				$account_ids[] = $account_id;
180 180
 				unset($account_lids[$key]);
181 181
 				continue;
182 182
 			}
183 183
 
184 184
 			// Handle groups listed as Group, <name>
185
-			if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) {
185
+			if ($account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id($account_lid)) {
186 186
 				$account_ids[] = $account_id;
187
-				unset($account_lids[$key-1]);
187
+				unset($account_lids[$key - 1]);
188 188
 				unset($account_lids[$key]);
189 189
 				continue;
190 190
 			}
191 191
 			// Group, <name> - remove the Group part
192
-			if($account_lid == lang('Group'))
192
+			if ($account_lid == lang('Group'))
193 193
 			{
194 194
 				unset($account_lids[$key]);
195 195
 				continue;
196 196
 			}
197 197
 		}
198
-		$_account_lids = (is_array($_account_lids) ? $account_lids : implode(',',array_unique($account_lids)));
199
-		return is_array( $_account_lids ) ? array_unique($account_ids) : implode( ',', array_unique((array)$account_ids ));
198
+		$_account_lids = (is_array($_account_lids) ? $account_lids : implode(',', array_unique($account_lids)));
199
+		return is_array($_account_lids) ? array_unique($account_ids) : implode(',', array_unique((array)$account_ids));
200 200
 
201 201
 	} // end of member function account_lid2id
202 202
 
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
 	 * @param mixed $_account_ids comma seperated list or array with ids
207 207
 	 * @return mixed comma seperated list or array with lids
208 208
 	 */
209
-	public static function account_id2name( $_account_id ) {
210
-		$account_ids = is_array( $_account_id ) ? $_account_id : explode( ',', $_account_id );
211
-		foreach ( $account_ids as $account_id ) {
212
-			if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) {
209
+	public static function account_id2name($_account_id) {
210
+		$account_ids = is_array($_account_id) ? $_account_id : explode(',', $_account_id);
211
+		foreach ($account_ids as $account_id) {
212
+			if ($account_lid = $GLOBALS['egw']->accounts->id2name($account_id)) {
213 213
 				$account_lids[] = $account_lid;
214 214
 			}
215 215
 		}
216
-		return is_array( $_account_id ) ? $account_lids : implode( ',', (array)$account_lids );
216
+		return is_array($_account_id) ? $account_lids : implode(',', (array)$account_lids);
217 217
 	} // end of member function account_id2lid
218 218
 
219 219
 	/**
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
 	 * @param mixed _cat_ids comma seperated list or array
223 223
 	 * @return mixed comma seperated list or array with cat_names
224 224
 	 */
225
-	public static function cat_id2name( $_cat_ids ) {
226
-		$cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids );
227
-		foreach ( $cat_ids as $cat_id ) {
228
-			$cat_names[] = Api\Categories::id2name( (int)$cat_id );
225
+	public static function cat_id2name($_cat_ids) {
226
+		$cat_ids = is_array($_cat_ids) ? $_cat_ids : explode(',', $_cat_ids);
227
+		foreach ($cat_ids as $cat_id) {
228
+			$cat_names[] = Api\Categories::id2name((int)$cat_id);
229 229
 		}
230
-		return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names);
230
+		return is_array($_cat_ids) ? $cat_names : implode(',', (array)$cat_names);
231 231
 	} // end of member function category_id2name
232 232
 
233 233
 	/**
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
 	 * @param int $parent Optional parent ID to use for new categories
239 239
 	 * @return mixed comma seperated list or array with cat_ids
240 240
 	 */
241
-	public static function cat_name2id( $_cat_names, $parent = 0 ) {
242
-		$cats = new Api\Categories();	// uses current user and app (egw_info[flags][currentapp])
241
+	public static function cat_name2id($_cat_names, $parent = 0) {
242
+		$cats = new Api\Categories(); // uses current user and app (egw_info[flags][currentapp])
243 243
 
244
-		$cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names );
245
-		foreach ( $cat_names as $cat_name ) {
244
+		$cat_names = is_array($_cat_names) ? $_cat_names : explode(',', $_cat_names);
245
+		foreach ($cat_names as $cat_name) {
246 246
 			$cat_name = trim($cat_name);
247
-			if ( $cat_name == '' ) continue;
248
-			if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) {
249
-				$cat_id = $cats->add( array(
247
+			if ($cat_name == '') continue;
248
+			if (($cat_id = $cats->name2id($cat_name)) == 0 && !self::$dry_run) {
249
+				$cat_id = $cats->add(array(
250 250
 					'name' => $cat_name,
251 251
 					'parent' => $parent,
252 252
 					'access' => 'public',
253
-					'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')'
253
+					'descr' => $cat_name.' ('.lang('Automatically created by importexport').')'
254 254
 				));
255 255
 			}
256 256
 			$cat_ids[] = $cat_id;
257 257
 		}
258
-		return is_array( $_cat_names ) ? $cat_ids : implode( ',', (array)$cat_ids );
258
+		return is_array($_cat_names) ? $cat_ids : implode(',', (array)$cat_ids);
259 259
 
260 260
 	} // end of member function category_name2id
261 261
 
@@ -294,76 +294,76 @@  discard block
 block discarded – undo
294 294
 	 * @param object &$cclass calling class to process the '@ evals'
295 295
 	 * @return bool
296 296
 	 */
297
-	public static function conversion( &$_record,  $_conversion, &$_cclass = null ) {
298
-		if (empty( $_conversion ) ) return $_record;
297
+	public static function conversion(&$_record, $_conversion, &$_cclass = null) {
298
+		if (empty($_conversion)) return $_record;
299 299
 
300
-		self::$cclass =& $_cclass;
300
+		self::$cclass = & $_cclass;
301 301
 
302 302
 		$PSep = '||'; // Pattern-Separator, separats the pattern-replacement-pairs in conversion
303 303
 		$ASep = '|>'; // Assignment-Separator, separats pattern and replacesment
304
-		$CPre = '|['; $CPos = ']';  // |[_record-idx] is expanded to the corespondig value
304
+		$CPre = '|['; $CPos = ']'; // |[_record-idx] is expanded to the corespondig value
305 305
 		$TPre = '|T{'; $TPos = '}'; // |{_record-idx} is trimmed
306
-		$CntlPre = '|TC{';		    // Filter all cntl-chars \x01-\x1f and trim
307
-		$CntlnCLPre  = '|TCnCL{';   // Like |C{ but allowes CR and LF
308
-		$INE = '|INE{';             // Only insert if stuff in ^^ is not empty
306
+		$CntlPre = '|TC{'; // Filter all cntl-chars \x01-\x1f and trim
307
+		$CntlnCLPre = '|TCnCL{'; // Like |C{ but allowes CR and LF
308
+		$INE = '|INE{'; // Only insert if stuff in ^^ is not empty
309 309
 
310
-		foreach ( $_conversion as $idx => $conversion_string ) {
311
-			if ( empty( $conversion_string ) ) continue;
310
+		foreach ($_conversion as $idx => $conversion_string) {
311
+			if (empty($conversion_string)) continue;
312 312
 
313 313
 			// fetch patterns ($rvalues)
314 314
 			$rvalues = array();
315
-			$pat_reps = explode( $PSep, stripslashes( $conversion_string ) );
316
-			foreach( $pat_reps as $k => $pat_rep ) {
317
-				list( $pattern, $replace ) = explode( $ASep, $pat_rep, 2 );
318
-				if( $replace == '' ) {
315
+			$pat_reps = explode($PSep, stripslashes($conversion_string));
316
+			foreach ($pat_reps as $k => $pat_rep) {
317
+				list($pattern, $replace) = explode($ASep, $pat_rep, 2);
318
+				if ($replace == '') {
319 319
 					$replace = $pattern; $pattern = '^.*$';
320 320
 				}
321
-				$rvalues[$pattern] = $replace;	// replace two with only one, added by the form
321
+				$rvalues[$pattern] = $replace; // replace two with only one, added by the form
322 322
 			}
323 323
 
324 324
 			// conversion list may be longer than $_record aka (no_csv)
325
-			$val = array_key_exists( $idx, $_record ) ? $_record[$idx] : '';
325
+			$val = array_key_exists($idx, $_record) ? $_record[$idx] : '';
326 326
 
327 327
 			$c_functions = array('cat', 'account', 'strtotime', 'list');
328
-			if($_cclass) {
328
+			if ($_cclass) {
329 329
 				// Add in additional methods
330 330
 				$reflection = new ReflectionClass(get_class($_cclass));
331 331
 				$methods = $reflection->getMethods(ReflectionMethod::IS_STATIC);
332
-				foreach($methods as $method) {
332
+				foreach ($methods as $method) {
333 333
 					$c_functions[] = $method->name;
334 334
 				}
335 335
 			}
336 336
 			$c_functions = implode('|', $c_functions);
337
-			foreach ( $rvalues as $pattern => $replace ) {
337
+			foreach ($rvalues as $pattern => $replace) {
338 338
 				// Allow to include record indexes in pattern
339 339
 				$reg = '/\|\[([0-9]+)\]/';
340
-				while( preg_match( $reg, $pattern, $vars ) ) {
340
+				while (preg_match($reg, $pattern, $vars)) {
341 341
 					// expand all _record fields
342 342
 					$pattern = str_replace(
343
-						$CPre . $vars[1] . $CPos,
343
+						$CPre.$vars[1].$CPos,
344 344
 						$_record[array_search($vars[1], array_keys($_record))],
345 345
 						$pattern
346 346
 					);
347 347
 				}
348
-				if( preg_match('/'. (string)$pattern.'/', $val) ) {
348
+				if (preg_match('/'.(string)$pattern.'/', $val)) {
349 349
 
350
-					$val = preg_replace( '/'.(string)$pattern.'/', $replace, (string)$val );
350
+					$val = preg_replace('/'.(string)$pattern.'/', $replace, (string)$val);
351 351
 
352 352
 					$reg = '/\|\[([a-zA-Z_0-9]+)\]/';
353
-					while( preg_match( $reg, $val, $vars ) ) {
353
+					while (preg_match($reg, $val, $vars)) {
354 354
 						// expand all _record fields
355 355
 						$val = str_replace(
356
-							$CPre . $vars[1] . $CPos,
356
+							$CPre.$vars[1].$CPos,
357 357
 							$_record[array_search($vars[1], array_keys($_record))],
358 358
 							$val
359 359
 						);
360 360
 					}
361
-					$val = preg_replace_callback( "/($c_functions)\(([^)]*)\)/i", array( self, 'c2_dispatcher') , $val );
361
+					$val = preg_replace_callback("/($c_functions)\(([^)]*)\)/i", array(self, 'c2_dispatcher'), $val);
362 362
 					break;
363 363
 				}
364 364
 			}
365 365
 			// clean each field
366
-			$val = preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{|\|INE\{)(.*)\}/", array( self, 'strclean'), $val );
366
+			$val = preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{|\|INE\{)(.*)\}/", array(self, 'strclean'), $val);
367 367
 
368 368
 			$_record[$idx] = $val;
369 369
 		}
@@ -377,42 +377,42 @@  discard block
 block discarded – undo
377 377
 	 *
378 378
 	 * @param array $_matches
379 379
 	 */
380
-	private static function c2_dispatcher( $_matches ) {
380
+	private static function c2_dispatcher($_matches) {
381 381
 		$action = &$_matches[1]; // cat or account ...
382
-		$data = &$_matches[2];   // datas for action
382
+		$data = &$_matches[2]; // datas for action
383 383
 
384
-		switch ( $action ) {
384
+		switch ($action) {
385 385
 			case 'strtotime' :
386
-				list( $string, $format ) = explode( ',', $data );
387
-				return self::custom_strtotime( trim( $string ), trim( $format ) );
386
+				list($string, $format) = explode(',', $data);
387
+				return self::custom_strtotime(trim($string), trim($format));
388 388
 			case 'list':
389
-				list( $split, $data, $index) = explode(',',$data);
389
+				list($split, $data, $index) = explode(',', $data);
390 390
 				$exploded = explode($split, $data);
391 391
 				// 1 based indexing for user ease
392 392
 				return $exploded[$index - 1];
393 393
 			default :
394
-				if(self::$cclass && method_exists(self::$cclass, $action)) {
394
+				if (self::$cclass && method_exists(self::$cclass, $action)) {
395 395
 					$class = get_class(self::$cclass);
396 396
 					return call_user_func("$class::$action", $data);
397 397
 				}
398
-				$method = (string)$action. ( is_int( $data ) ? '_id2name' : '_name2id' );
399
-				if(self::$cclass && method_exists(self::$cclass, $method)) {
398
+				$method = (string)$action.(is_int($data) ? '_id2name' : '_name2id');
399
+				if (self::$cclass && method_exists(self::$cclass, $method)) {
400 400
 					$class = get_class(self::$cclass);
401 401
 					return call_user_func("$class::$action", $data);
402 402
 				} else {
403
-					return self::$method( $data );
403
+					return self::$method($data);
404 404
 				}
405 405
 		}
406 406
 	}
407 407
 
408
-	private static function strclean( $_matches ) {
409
-		switch( $_matches[1] ) {
410
-			case '|T{' : return trim( $_matches[2] );
411
-			case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) );
412
-			case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) );
413
-			case '|INE{' : return preg_match( '/\^.+\^/', $_matches[2] ) ? $_matches[2] : '';
408
+	private static function strclean($_matches) {
409
+		switch ($_matches[1]) {
410
+			case '|T{' : return trim($_matches[2]);
411
+			case '|TC{' : return trim(preg_replace('/[\x01-\x1F]+/', '', $_matches[2]));
412
+			case '|TCnCL{' : return trim(preg_replace('/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2]));
413
+			case '|INE{' : return preg_match('/\^.+\^/', $_matches[2]) ? $_matches[2] : '';
414 414
 			default:
415
-				throw new Exception('Error in conversion string! "'. substr( $_matches[1], 0, -1 ). '" is not valid!');
415
+				throw new Exception('Error in conversion string! "'.substr($_matches[1], 0, -1).'" is not valid!');
416 416
 		}
417 417
 	}
418 418
 
@@ -423,23 +423,23 @@  discard block
 block discarded – undo
423 423
 	 * @param string $_appname {<appname> | all}
424 424
 	 * @return array(<appname> => array( <type> => array(<plugin> => <title>)))
425 425
 	 */
426
-	public static function get_plugins( $_appname = 'all', $_type = 'all' ) {
426
+	public static function get_plugins($_appname = 'all', $_type = 'all') {
427 427
 		$plugins = Api\Cache::getTree(
428 428
 			__CLASS__,
429 429
 			'plugins',
430
-			array('importexport_helper_functions','_get_plugins'),
430
+			array('importexport_helper_functions', '_get_plugins'),
431 431
 			array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')),
432 432
 			self::CACHE_EXPIRATION
433 433
 		);
434 434
 		$appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname;
435
-		$types = $_type == 'all' ? array('import','export') : (array)$_type;
435
+		$types = $_type == 'all' ? array('import', 'export') : (array)$_type;
436 436
 
437 437
 		// Testing: comment out Api\Cache call, use this
438 438
 		//$plugins = self::_get_plugins($appnames, $types);
439
-		foreach($plugins as $appname => $_types) {
440
-			if(!in_array($appname, $appnames)) unset($plugins[$appname]);
439
+		foreach ($plugins as $appname => $_types) {
440
+			if (!in_array($appname, $appnames)) unset($plugins[$appname]);
441 441
 		}
442
-		foreach($plugins as $appname => $types) {
442
+		foreach ($plugins as $appname => $types) {
443 443
 			$plugins[$appname] = array_intersect_key($plugins[$appname], $types);
444 444
 		}
445 445
 		return $plugins;
@@ -448,25 +448,25 @@  discard block
 block discarded – undo
448 448
 	public static function _get_plugins(Array $appnames, Array $types) {
449 449
 		$plugins = array();
450 450
 		foreach ($appnames as $appname) {
451
-			if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue;
451
+			if (array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue;
452 452
 
453
-			$appdir = EGW_INCLUDE_ROOT. "/$appname/inc";
454
-			if(!is_dir($appdir)) continue;
453
+			$appdir = EGW_INCLUDE_ROOT."/$appname/inc";
454
+			if (!is_dir($appdir)) continue;
455 455
 			$d = dir($appdir);
456 456
 
457 457
 			// step through each file in appdir
458 458
 			while (false !== ($entry = $d->read())) {
459 459
 				// Blacklisted?
460
-				if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname]))  continue;
460
+				if (is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname]))  continue;
461 461
 				if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) continue;
462 462
 				$classname = $matches[1];
463
-				$file = $appdir. '/'. $entry;
463
+				$file = $appdir.'/'.$entry;
464 464
 
465 465
 				foreach ($types as $type) {
466
-					if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) continue;
466
+					if (!is_file($file) || strpos($entry, $type) === false || strpos($entry, 'wizard') !== false) continue;
467 467
 					require_once($file);
468 468
 					$reflectionClass = new ReflectionClass($classname);
469
-					if($reflectionClass->IsInstantiable() &&
469
+					if ($reflectionClass->IsInstantiable() &&
470 470
 							$reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) {
471 471
 						try {
472 472
 							$plugin_object = new $classname;
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 			$d->close();
483 483
 
484 484
 			$config = Api\Config::read('importexport');
485
-			if($config['update'] == 'auto') {
485
+			if ($config['update'] == 'auto') {
486 486
 				self::load_defaults($appname);
487 487
 			}
488 488
 		}
@@ -497,37 +497,37 @@  discard block
 block discarded – undo
497 497
 	 * @return array $num => $appname
498 498
 	 */
499 499
 	public static function get_apps($_type, $ignore_acl = false) {
500
-		$apps = array_keys(self::get_plugins('all',$_type));
501
-		if($ignore_acl) return $apps;
500
+		$apps = array_keys(self::get_plugins('all', $_type));
501
+		if ($ignore_acl) return $apps;
502 502
 
503
-		foreach($apps as $key => $app) {
504
-			if(!self::has_definitions($app, $_type)) unset($apps[$key]);
503
+		foreach ($apps as $key => $app) {
504
+			if (!self::has_definitions($app, $_type)) unset($apps[$key]);
505 505
 		}
506 506
 		return $apps;
507 507
 	}
508 508
 
509 509
 	public static function load_defaults($appname) {
510 510
 		// Check for new definitions to import from $appname/setup/*.xml
511
-		$appdir = EGW_INCLUDE_ROOT. "/$appname/setup";
512
-		if(!is_dir($appdir)) return;
511
+		$appdir = EGW_INCLUDE_ROOT."/$appname/setup";
512
+		if (!is_dir($appdir)) return;
513 513
 		$d = dir($appdir);
514 514
 
515 515
 		// step through each file in app's setup
516 516
 		while (false !== ($entry = $d->read())) {
517
-			$file = $appdir. '/'. $entry;
518
-			list( $filename, $extension) = explode('.',$entry);
519
-			if ( $extension != 'xml' ) continue;
517
+			$file = $appdir.'/'.$entry;
518
+			list($filename, $extension) = explode('.', $entry);
519
+			if ($extension != 'xml') continue;
520 520
 			try {
521 521
 				// import will skip invalid files
522
-				importexport_definitions_bo::import( $file );
522
+				importexport_definitions_bo::import($file);
523 523
 			} catch (Exception $e) {
524
-				error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage());
524
+				error_log(__CLASS__.__FUNCTION__." import $appname definitions: ".$e->getMessage());
525 525
 			}
526 526
 		}
527 527
 		$d->close();
528 528
 	}
529 529
 
530
-	public static function guess_filetype( $_file ) {
530
+	public static function guess_filetype($_file) {
531 531
 
532 532
 	}
533 533
 
@@ -538,24 +538,24 @@  discard block
 block discarded – undo
538 538
 	 * @param string $_type {import | export | all}
539 539
 	 * @return boolean
540 540
 	 */
541
-	public static function has_definitions( $_appname = 'all', $_type = 'all' ) {
541
+	public static function has_definitions($_appname = 'all', $_type = 'all') {
542 542
 		$definitions = Api\Cache::getSession(
543 543
 			__CLASS__,
544 544
 			'has_definitions',
545
-			array('importexport_helper_functions','_has_definitions'),
545
+			array('importexport_helper_functions', '_has_definitions'),
546 546
 			array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')),
547 547
 			self::CACHE_EXPIRATION
548 548
 		);
549 549
 		$appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname;
550
-		$types = $_type == 'all' ? array('import','export') : (array)$_type;
550
+		$types = $_type == 'all' ? array('import', 'export') : (array)$_type;
551 551
 
552 552
 		// Testing: Comment out cache call above, use this
553 553
 		//$definitions = self::_has_definitions($appnames, $types);
554 554
 
555
-		foreach($definitions as $appname => $_types) {
556
-			if(!in_array($appname, $appnames)) unset($definitions[$appname]);
555
+		foreach ($definitions as $appname => $_types) {
556
+			if (!in_array($appname, $appnames)) unset($definitions[$appname]);
557 557
 		}
558
-		foreach($definitions as $appname => $_types) {
558
+		foreach ($definitions as $appname => $_types) {
559 559
 			$definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types));
560 560
 		}
561 561
 		return count($definitions[$appname]) > 0;
@@ -565,11 +565,11 @@  discard block
 block discarded – undo
565 565
 	public static function _has_definitions(Array $appnames, Array $types) {
566 566
 		$def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types));
567 567
 		$list = array();
568
-		foreach((array)$def->get_definitions() as $id) {
568
+		foreach ((array)$def->get_definitions() as $id) {
569 569
 			// Need to instanciate it to check, but if the user doesn't have permission, it throws an exception
570 570
 			try {
571 571
 				$definition = new importexport_definition($id);
572
-				if($def->is_permitted($definition->get_record_array())) {
572
+				if ($def->is_permitted($definition->get_record_array())) {
573 573
 					$list[$definition->application][$definition->type][] = $id;
574 574
 				}
575 575
 			} catch (Exception $e) {
@@ -601,13 +601,13 @@  discard block
 block discarded – undo
601 601
 			$plugin = is_object($plugin_name) ? $plugin_name : new $plugin_name();
602 602
 			$plugin_name = get_class($plugin);
603 603
 
604
-			if($record_classname == null) $record_classname = $plugin::get_egw_record_class();
605
-			if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname);
604
+			if ($record_classname == null) $record_classname = $plugin::get_egw_record_class();
605
+			if (!class_exists($record_classname)) throw new Exception('Bad class name '.$record_classname);
606 606
 
607
-			if(!$wizard_plugin)
607
+			if (!$wizard_plugin)
608 608
 			{
609
-				$wizard_name = $app_name . '_wizard_' . str_replace($app_name . '_', '', $plugin_name);
610
-				if(!class_exists($wizard_name)) throw new Exception('Bad wizard name ' . $wizard_name);
609
+				$wizard_name = $app_name.'_wizard_'.str_replace($app_name.'_', '', $plugin_name);
610
+				if (!class_exists($wizard_name)) throw new Exception('Bad wizard name '.$wizard_name);
611 611
 				$wizard_plugin = new $wizard_name;
612 612
 			}
613 613
 		}
@@ -619,16 +619,16 @@  discard block
 block discarded – undo
619 619
 
620 620
 		// Get field -> label map and initialize fields using wizard field order
621 621
 		$fields = $export_fields = array();
622
-		if(method_exists($wizard_plugin, 'get_export_fields'))
622
+		if (method_exists($wizard_plugin, 'get_export_fields'))
623 623
 		{
624 624
 			$fields = $export_fields = $wizard_plugin->get_export_fields();
625 625
 		}
626 626
 
627
-		foreach($record_classname::$types as $type => $type_fields)
627
+		foreach ($record_classname::$types as $type => $type_fields)
628 628
 		{
629 629
 			// Only these for now, until filter methods for others are figured out
630
-			if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) continue;
631
-			foreach($type_fields as $field_name)
630
+			if (!in_array($type, array('select', 'select-cat', 'select-account', 'date', 'date-time'))) continue;
631
+			foreach ($type_fields as $field_name)
632 632
 			{
633 633
 				$fields[$field_name] = array(
634 634
 					'name' => $field_name,
@@ -639,21 +639,21 @@  discard block
 block discarded – undo
639 639
 		}
640 640
 		// Add custom fields
641 641
 		$custom = Api\Storage\Customfields::get($app_name);
642
-		foreach($custom as $field_name => $settings)
642
+		foreach ($custom as $field_name => $settings)
643 643
 		{
644 644
 			$settings['name'] = '#'.$field_name;
645 645
 			$fields['#'.$field_name] = $settings;
646 646
 		}
647 647
 
648
-		foreach($fields as $field_name => &$settings) {
648
+		foreach ($fields as $field_name => &$settings) {
649 649
 			// Can't really filter on these (or at least no generic, sane way figured out yet)
650
-			if(!is_array($settings) || in_array($settings['type'], array('text','button', 'label','url','url-email','url-phone','htmlarea')))
650
+			if (!is_array($settings) || in_array($settings['type'], array('text', 'button', 'label', 'url', 'url-email', 'url-phone', 'htmlarea')))
651 651
 			{
652 652
 				unset($fields[$field_name]);
653 653
 				continue;
654 654
 			}
655
-			if($settings['type'] == 'radio') $settings['type'] = 'select';
656
-			switch($settings['type'])
655
+			if ($settings['type'] == 'radio') $settings['type'] = 'select';
656
+			switch ($settings['type'])
657 657
 			{
658 658
 				case 'checkbox':
659 659
 					// This isn't quite right - there's only 2 options and you can select both
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			}
677 677
 		}
678 678
 
679
-		if(method_exists($plugin, 'get_filter_fields'))
679
+		if (method_exists($plugin, 'get_filter_fields'))
680 680
 		{
681 681
 			$plugin->get_filter_fields($fields);
682 682
 		}
@@ -692,65 +692,65 @@  discard block
 block discarded – undo
692 692
 	 */
693 693
 	public static function date_rel2abs($value)
694 694
 	{
695
-		if(is_array($value))
695
+		if (is_array($value))
696 696
 		{
697 697
 			$abs = array();
698
-			foreach($value as $key => $val)
698
+			foreach ($value as $key => $val)
699 699
 			{
700 700
 				$abs[$key] = self::date_rel2abs($val);
701 701
 			}
702 702
 			return $abs;
703 703
 		}
704
-		if($date = self::$relative_dates[$value])
704
+		if ($date = self::$relative_dates[$value])
705 705
 		{
706
-			$year  = (int) date('Y');
707
-			$month = (int) date('m');
708
-			$day   = (int) date('d');
709
-			$today = mktime(0,0,0,date('m'),date('d'),date('Y'));
706
+			$year  = (int)date('Y');
707
+			$month = (int)date('m');
708
+			$day   = (int)date('d');
709
+			$today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
710 710
 
711
-			list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) = $date;
711
+			list($syear, $smonth, $sday, $sweek, $eyear, $emonth, $eday, $eweek) = $date;
712 712
 
713
-			if(stripos($value, 'quarter') !== false)
713
+			if (stripos($value, 'quarter') !== false)
714 714
 			{
715 715
 				// Handle quarters
716
-				$start = mktime(0,0,0,((int)floor(($smonth+$month) / 3.1)) * 3 + 1, 1, $year);
717
-				$end = mktime(0,0,0,((int)floor(($emonth+$month) / 3.1)+1) * 3 + 1, 1, $year);
716
+				$start = mktime(0, 0, 0, ((int)floor(($smonth + $month) / 3.1)) * 3 + 1, 1, $year);
717
+				$end = mktime(0, 0, 0, ((int)floor(($emonth + $month) / 3.1) + 1) * 3 + 1, 1, $year);
718 718
 			}
719 719
 			elseif ($syear || $eyear)
720 720
 			{
721
-				$start = mktime(0,0,0,1,1,$syear+$year);
722
-				$end   = mktime(0,0,0,1,1,$eyear+$year);
721
+				$start = mktime(0, 0, 0, 1, 1, $syear + $year);
722
+				$end   = mktime(0, 0, 0, 1, 1, $eyear + $year);
723 723
 			}
724 724
 			elseif ($smonth || $emonth)
725 725
 			{
726
-				$start = mktime(0,0,0,$smonth+$month,1,$year);
727
-				$end   = mktime(0,0,0,$emonth+$month,1,$year);
726
+				$start = mktime(0, 0, 0, $smonth + $month, 1, $year);
727
+				$end   = mktime(0, 0, 0, $emonth + $month, 1, $year);
728 728
 			}
729 729
 			elseif ($sday || $eday)
730 730
 			{
731
-				$start = mktime(0,0,0,$month,$sday+$day,$year);
732
-				$end   = mktime(0,0,0,$month,$eday+$day,$year);
731
+				$start = mktime(0, 0, 0, $month, $sday + $day, $year);
732
+				$end   = mktime(0, 0, 0, $month, $eday + $day, $year);
733 733
 			}
734 734
 			elseif ($sweek || $eweek)
735 735
 			{
736
-				$wday = (int) date('w'); // 0=sun, ..., 6=sat
737
-				switch($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'])
736
+				$wday = (int)date('w'); // 0=sun, ..., 6=sat
737
+				switch ($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'])
738 738
 				{
739 739
 					case 'Sunday':
740
-						$weekstart = $today - $wday * 24*60*60;
740
+						$weekstart = $today - $wday * 24 * 60 * 60;
741 741
 						break;
742 742
 					case 'Saturday':
743
-						$weekstart = $today - (6-$wday) * 24*60*60;
743
+						$weekstart = $today - (6 - $wday) * 24 * 60 * 60;
744 744
 						break;
745 745
 					case 'Moday':
746 746
 					default:
747
-						$weekstart = $today - ($wday ? $wday-1 : 6) * 24*60*60;
747
+						$weekstart = $today - ($wday ? $wday - 1 : 6) * 24 * 60 * 60;
748 748
 						break;
749 749
 				}
750
-				$start = $weekstart + $sweek*7*24*60*60;
751
-				$end   = $weekstart + $eweek*7*24*60*60;
750
+				$start = $weekstart + $sweek * 7 * 24 * 60 * 60;
751
+				$end   = $weekstart + $eweek * 7 * 24 * 60 * 60;
752 752
 			}
753
-			$end_param = $end - 24*60*60;
753
+			$end_param = $end - 24 * 60 * 60;
754 754
 
755 755
 			// Take 1 second off end to provide an inclusive range.for filtering
756 756
 			$end -= 1;
Please login to merge, or discard this patch.
Braces   +210 added lines, -83 removed lines patch added patch discarded remove patch
@@ -16,7 +16,8 @@  discard block
 block discarded – undo
16 16
  * class importexport_helper_functions (only static methods)
17 17
  * use importexport_helper_functions::method
18 18
  */
19
-class importexport_helper_functions {
19
+class importexport_helper_functions
20
+{
20 21
 
21 22
 	/**
22 23
 	 * Plugins are scanned and cached for all instances using this source path for given time (in seconds)
@@ -85,13 +86,19 @@  discard block
 block discarded – undo
85 86
 	 * @param string $_format format of time string e.g.: d.m.Y H:i
86 87
 	 * @param int $_is_dst is day light saving time? 0 = no, 1 = yes, -1 = system default
87 88
 	 */
88
-	public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) {
89
-		if ( empty( $_format ) ) return strtotime( $_string );
89
+	public static function custom_strtotime( $_string, $_format='', $_is_dst = -1)
90
+	{
91
+		if ( empty( $_format ) )
92
+		{
93
+			return strtotime( $_string );
94
+		}
90 95
 		$fparams = explode( ',', chunk_split( $_format, 1, ',' ) );
91 96
 		$spos = 0;
92
-		foreach ( $fparams as $fparam ) {
97
+		foreach ( $fparams as $fparam )
98
+		{
93 99
 
94
-			switch ( $fparam ) {
100
+			switch ( $fparam )
101
+			{
95 102
 				case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break;
96 103
 				case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break;
97 104
 				case 'y': (int)$year = substr( $_string, $spos, 2 ); $spos += 2; break;
@@ -111,12 +118,18 @@  discard block
 block discarded – undo
111 118
 		$timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst);
112 119
 
113 120
 		// offset given?
114
-		if ( isset( $offset ) && strlen( $offset == 5 ) ) {
121
+		if ( isset( $offset ) && strlen( $offset == 5 ) )
122
+		{
115 123
 			$operator = $offset{0};
116 124
 			$ohour = 60 * 60 * (int)substr( $offset, 1, 2 );
117 125
 			$omin = 60 * (int)substr( $offset, 3, 2 );
118
-			if ( $operator == '+' ) $timestamp += $ohour + $omin;
119
-			else $timestamp -= $ohour + $omin;
126
+			if ( $operator == '+' )
127
+			{
128
+				$timestamp += $ohour + $omin;
129
+			}
130
+			else {
131
+				$timestamp -= $ohour + $omin;
132
+			}
120 133
 		}
121 134
 		return $timestamp;
122 135
 	}
@@ -126,11 +139,14 @@  discard block
 block discarded – undo
126 139
 	 * @param mixed $_account_lid comma seperated list or array with lids
127 140
 	 * @return mixed comma seperated list or array with ids
128 141
 	 */
129
-	public static function account_name2id( &$_account_lids ) {
142
+	public static function account_name2id( &$_account_lids )
143
+	{
130 144
 		$account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids );
131 145
 		$skip = false;
132
-		foreach ( $account_lids as $key => $account_lid ) {
133
-			if($skip) {
146
+		foreach ( $account_lids as $key => $account_lid )
147
+		{
148
+			if($skip)
149
+			{
134 150
 				unset($account_lids[$key]);
135 151
 				$skip = false;
136 152
 				continue;
@@ -138,7 +154,8 @@  discard block
 block discarded – undo
138 154
 			$account_lid = trim($account_lid);
139 155
 
140 156
 			// Handle any IDs that slip in
141
-			if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) {
157
+			if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid))
158
+			{
142 159
 				unset($account_lids[$key]);
143 160
 				$account_ids[] = (int)$account_lid;
144 161
 				continue;
@@ -157,7 +174,8 @@  discard block
 block discarded – undo
157 174
 
158 175
 			// Handle users listed as Lastname, Firstname instead of login ID
159 176
 			// Do this first, in case their first name matches a username
160
-			if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) {
177
+			if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname'))
178
+			{
161 179
 				$account_ids[] = $account_id;
162 180
 				unset($account_lids[$key]);
163 181
 				$skip = true; // Skip the next one, it's the first name
@@ -170,19 +188,22 @@  discard block
 block discarded – undo
170 188
 				$account_lid = trim(substr(trim($account_lid), 0, -strlen(lang('Group'))));
171 189
 			}
172 190
 
173
-			if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) {
191
+			if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid ))
192
+			{
174 193
 				$account_ids[] = $account_id;
175 194
 				unset($account_lids[$key]);
176 195
 				continue;
177 196
 			}
178
-			if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) {
197
+			if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' ))
198
+			{
179 199
 				$account_ids[] = $account_id;
180 200
 				unset($account_lids[$key]);
181 201
 				continue;
182 202
 			}
183 203
 
184 204
 			// Handle groups listed as Group, <name>
185
-			if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) {
205
+			if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid))
206
+			{
186 207
 				$account_ids[] = $account_id;
187 208
 				unset($account_lids[$key-1]);
188 209
 				unset($account_lids[$key]);
@@ -206,10 +227,13 @@  discard block
 block discarded – undo
206 227
 	 * @param mixed $_account_ids comma seperated list or array with ids
207 228
 	 * @return mixed comma seperated list or array with lids
208 229
 	 */
209
-	public static function account_id2name( $_account_id ) {
230
+	public static function account_id2name( $_account_id )
231
+	{
210 232
 		$account_ids = is_array( $_account_id ) ? $_account_id : explode( ',', $_account_id );
211
-		foreach ( $account_ids as $account_id ) {
212
-			if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) {
233
+		foreach ( $account_ids as $account_id )
234
+		{
235
+			if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id ))
236
+			{
213 237
 				$account_lids[] = $account_lid;
214 238
 			}
215 239
 		}
@@ -222,9 +246,11 @@  discard block
 block discarded – undo
222 246
 	 * @param mixed _cat_ids comma seperated list or array
223 247
 	 * @return mixed comma seperated list or array with cat_names
224 248
 	 */
225
-	public static function cat_id2name( $_cat_ids ) {
249
+	public static function cat_id2name( $_cat_ids )
250
+	{
226 251
 		$cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids );
227
-		foreach ( $cat_ids as $cat_id ) {
252
+		foreach ( $cat_ids as $cat_id )
253
+		{
228 254
 			$cat_names[] = Api\Categories::id2name( (int)$cat_id );
229 255
 		}
230 256
 		return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names);
@@ -238,14 +264,20 @@  discard block
 block discarded – undo
238 264
 	 * @param int $parent Optional parent ID to use for new categories
239 265
 	 * @return mixed comma seperated list or array with cat_ids
240 266
 	 */
241
-	public static function cat_name2id( $_cat_names, $parent = 0 ) {
267
+	public static function cat_name2id( $_cat_names, $parent = 0 )
268
+	{
242 269
 		$cats = new Api\Categories();	// uses current user and app (egw_info[flags][currentapp])
243 270
 
244 271
 		$cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names );
245
-		foreach ( $cat_names as $cat_name ) {
272
+		foreach ( $cat_names as $cat_name )
273
+		{
246 274
 			$cat_name = trim($cat_name);
247
-			if ( $cat_name == '' ) continue;
248
-			if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) {
275
+			if ( $cat_name == '' )
276
+			{
277
+				continue;
278
+			}
279
+			if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run)
280
+			{
249 281
 				$cat_id = $cats->add( array(
250 282
 					'name' => $cat_name,
251 283
 					'parent' => $parent,
@@ -294,8 +326,12 @@  discard block
 block discarded – undo
294 326
 	 * @param object &$cclass calling class to process the '@ evals'
295 327
 	 * @return bool
296 328
 	 */
297
-	public static function conversion( &$_record,  $_conversion, &$_cclass = null ) {
298
-		if (empty( $_conversion ) ) return $_record;
329
+	public static function conversion( &$_record,  $_conversion, &$_cclass = null )
330
+	{
331
+		if (empty( $_conversion ) )
332
+		{
333
+			return $_record;
334
+		}
299 335
 
300 336
 		self::$cclass =& $_cclass;
301 337
 
@@ -307,15 +343,21 @@  discard block
 block discarded – undo
307 343
 		$CntlnCLPre  = '|TCnCL{';   // Like |C{ but allowes CR and LF
308 344
 		$INE = '|INE{';             // Only insert if stuff in ^^ is not empty
309 345
 
310
-		foreach ( $_conversion as $idx => $conversion_string ) {
311
-			if ( empty( $conversion_string ) ) continue;
346
+		foreach ( $_conversion as $idx => $conversion_string )
347
+		{
348
+			if ( empty( $conversion_string ) )
349
+			{
350
+				continue;
351
+			}
312 352
 
313 353
 			// fetch patterns ($rvalues)
314 354
 			$rvalues = array();
315 355
 			$pat_reps = explode( $PSep, stripslashes( $conversion_string ) );
316
-			foreach( $pat_reps as $k => $pat_rep ) {
356
+			foreach( $pat_reps as $k => $pat_rep )
357
+			{
317 358
 				list( $pattern, $replace ) = explode( $ASep, $pat_rep, 2 );
318
-				if( $replace == '' ) {
359
+				if( $replace == '' )
360
+				{
319 361
 					$replace = $pattern; $pattern = '^.*$';
320 362
 				}
321 363
 				$rvalues[$pattern] = $replace;	// replace two with only one, added by the form
@@ -325,19 +367,23 @@  discard block
 block discarded – undo
325 367
 			$val = array_key_exists( $idx, $_record ) ? $_record[$idx] : '';
326 368
 
327 369
 			$c_functions = array('cat', 'account', 'strtotime', 'list');
328
-			if($_cclass) {
370
+			if($_cclass)
371
+			{
329 372
 				// Add in additional methods
330 373
 				$reflection = new ReflectionClass(get_class($_cclass));
331 374
 				$methods = $reflection->getMethods(ReflectionMethod::IS_STATIC);
332
-				foreach($methods as $method) {
375
+				foreach($methods as $method)
376
+				{
333 377
 					$c_functions[] = $method->name;
334 378
 				}
335 379
 			}
336 380
 			$c_functions = implode('|', $c_functions);
337
-			foreach ( $rvalues as $pattern => $replace ) {
381
+			foreach ( $rvalues as $pattern => $replace )
382
+			{
338 383
 				// Allow to include record indexes in pattern
339 384
 				$reg = '/\|\[([0-9]+)\]/';
340
-				while( preg_match( $reg, $pattern, $vars ) ) {
385
+				while( preg_match( $reg, $pattern, $vars ) )
386
+				{
341 387
 					// expand all _record fields
342 388
 					$pattern = str_replace(
343 389
 						$CPre . $vars[1] . $CPos,
@@ -345,12 +391,14 @@  discard block
 block discarded – undo
345 391
 						$pattern
346 392
 					);
347 393
 				}
348
-				if( preg_match('/'. (string)$pattern.'/', $val) ) {
394
+				if( preg_match('/'. (string)$pattern.'/', $val) )
395
+				{
349 396
 
350 397
 					$val = preg_replace( '/'.(string)$pattern.'/', $replace, (string)$val );
351 398
 
352 399
 					$reg = '/\|\[([a-zA-Z_0-9]+)\]/';
353
-					while( preg_match( $reg, $val, $vars ) ) {
400
+					while( preg_match( $reg, $val, $vars ) )
401
+					{
354 402
 						// expand all _record fields
355 403
 						$val = str_replace(
356 404
 							$CPre . $vars[1] . $CPos,
@@ -377,11 +425,13 @@  discard block
 block discarded – undo
377 425
 	 *
378 426
 	 * @param array $_matches
379 427
 	 */
380
-	private static function c2_dispatcher( $_matches ) {
428
+	private static function c2_dispatcher( $_matches )
429
+	{
381 430
 		$action = &$_matches[1]; // cat or account ...
382 431
 		$data = &$_matches[2];   // datas for action
383 432
 
384
-		switch ( $action ) {
433
+		switch ( $action )
434
+		{
385 435
 			case 'strtotime' :
386 436
 				list( $string, $format ) = explode( ',', $data );
387 437
 				return self::custom_strtotime( trim( $string ), trim( $format ) );
@@ -391,22 +441,28 @@  discard block
 block discarded – undo
391 441
 				// 1 based indexing for user ease
392 442
 				return $exploded[$index - 1];
393 443
 			default :
394
-				if(self::$cclass && method_exists(self::$cclass, $action)) {
444
+				if(self::$cclass && method_exists(self::$cclass, $action))
445
+				{
395 446
 					$class = get_class(self::$cclass);
396 447
 					return call_user_func("$class::$action", $data);
397 448
 				}
398 449
 				$method = (string)$action. ( is_int( $data ) ? '_id2name' : '_name2id' );
399
-				if(self::$cclass && method_exists(self::$cclass, $method)) {
450
+				if(self::$cclass && method_exists(self::$cclass, $method))
451
+				{
400 452
 					$class = get_class(self::$cclass);
401 453
 					return call_user_func("$class::$action", $data);
402
-				} else {
454
+				}
455
+				else
456
+				{
403 457
 					return self::$method( $data );
404 458
 				}
405 459
 		}
406 460
 	}
407 461
 
408
-	private static function strclean( $_matches ) {
409
-		switch( $_matches[1] ) {
462
+	private static function strclean( $_matches )
463
+	{
464
+		switch( $_matches[1] )
465
+		{
410 466
 			case '|T{' : return trim( $_matches[2] );
411 467
 			case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) );
412 468
 			case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) );
@@ -423,7 +479,8 @@  discard block
 block discarded – undo
423 479
 	 * @param string $_appname {<appname> | all}
424 480
 	 * @return array(<appname> => array( <type> => array(<plugin> => <title>)))
425 481
 	 */
426
-	public static function get_plugins( $_appname = 'all', $_type = 'all' ) {
482
+	public static function get_plugins( $_appname = 'all', $_type = 'all' )
483
+	{
427 484
 		$plugins = Api\Cache::getTree(
428 485
 			__CLASS__,
429 486
 			'plugins',
@@ -436,38 +493,63 @@  discard block
 block discarded – undo
436 493
 
437 494
 		// Testing: comment out Api\Cache call, use this
438 495
 		//$plugins = self::_get_plugins($appnames, $types);
439
-		foreach($plugins as $appname => $_types) {
440
-			if(!in_array($appname, $appnames)) unset($plugins[$appname]);
496
+		foreach($plugins as $appname => $_types)
497
+		{
498
+			if(!in_array($appname, $appnames))
499
+			{
500
+				unset($plugins[$appname]);
501
+			}
441 502
 		}
442
-		foreach($plugins as $appname => $types) {
503
+		foreach($plugins as $appname => $types)
504
+		{
443 505
 			$plugins[$appname] = array_intersect_key($plugins[$appname], $types);
444 506
 		}
445 507
 		return $plugins;
446 508
 	}
447 509
 
448
-	public static function _get_plugins(Array $appnames, Array $types) {
510
+	public static function _get_plugins(Array $appnames, Array $types)
511
+	{
449 512
 		$plugins = array();
450
-		foreach ($appnames as $appname) {
451
-			if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue;
513
+		foreach ($appnames as $appname)
514
+		{
515
+			if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true)
516
+			{
517
+				continue;
518
+			}
452 519
 
453 520
 			$appdir = EGW_INCLUDE_ROOT. "/$appname/inc";
454
-			if(!is_dir($appdir)) continue;
521
+			if(!is_dir($appdir))
522
+			{
523
+				continue;
524
+			}
455 525
 			$d = dir($appdir);
456 526
 
457 527
 			// step through each file in appdir
458
-			while (false !== ($entry = $d->read())) {
528
+			while (false !== ($entry = $d->read()))
529
+			{
459 530
 				// Blacklisted?
460
-				if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname]))  continue;
461
-				if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) continue;
531
+				if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname]))
532
+				{
533
+					continue;
534
+				}
535
+				if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches))
536
+				{
537
+					continue;
538
+				}
462 539
 				$classname = $matches[1];
463 540
 				$file = $appdir. '/'. $entry;
464 541
 
465
-				foreach ($types as $type) {
466
-					if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) continue;
542
+				foreach ($types as $type)
543
+				{
544
+					if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false)
545
+					{
546
+						continue;
547
+					}
467 548
 					require_once($file);
468 549
 					$reflectionClass = new ReflectionClass($classname);
469 550
 					if($reflectionClass->IsInstantiable() &&
470
-							$reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) {
551
+							$reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin'))
552
+					{
471 553
 						try {
472 554
 							$plugin_object = new $classname;
473 555
 						}
@@ -482,7 +564,8 @@  discard block
 block discarded – undo
482 564
 			$d->close();
483 565
 
484 566
 			$config = Api\Config::read('importexport');
485
-			if($config['update'] == 'auto') {
567
+			if($config['update'] == 'auto')
568
+			{
486 569
 				self::load_defaults($appname);
487 570
 			}
488 571
 		}
@@ -496,38 +579,56 @@  discard block
 block discarded – undo
496 579
 	 * @param string $_type
497 580
 	 * @return array $num => $appname
498 581
 	 */
499
-	public static function get_apps($_type, $ignore_acl = false) {
582
+	public static function get_apps($_type, $ignore_acl = false)
583
+	{
500 584
 		$apps = array_keys(self::get_plugins('all',$_type));
501
-		if($ignore_acl) return $apps;
585
+		if($ignore_acl)
586
+		{
587
+			return $apps;
588
+		}
502 589
 
503
-		foreach($apps as $key => $app) {
504
-			if(!self::has_definitions($app, $_type)) unset($apps[$key]);
590
+		foreach($apps as $key => $app)
591
+		{
592
+			if(!self::has_definitions($app, $_type))
593
+			{
594
+				unset($apps[$key]);
595
+			}
505 596
 		}
506 597
 		return $apps;
507 598
 	}
508 599
 
509
-	public static function load_defaults($appname) {
600
+	public static function load_defaults($appname)
601
+	{
510 602
 		// Check for new definitions to import from $appname/setup/*.xml
511 603
 		$appdir = EGW_INCLUDE_ROOT. "/$appname/setup";
512
-		if(!is_dir($appdir)) return;
604
+		if(!is_dir($appdir))
605
+		{
606
+			return;
607
+		}
513 608
 		$d = dir($appdir);
514 609
 
515 610
 		// step through each file in app's setup
516
-		while (false !== ($entry = $d->read())) {
611
+		while (false !== ($entry = $d->read()))
612
+		{
517 613
 			$file = $appdir. '/'. $entry;
518 614
 			list( $filename, $extension) = explode('.',$entry);
519
-			if ( $extension != 'xml' ) continue;
615
+			if ( $extension != 'xml' )
616
+			{
617
+				continue;
618
+			}
520 619
 			try {
521 620
 				// import will skip invalid files
522 621
 				importexport_definitions_bo::import( $file );
523
-			} catch (Exception $e) {
622
+			}
623
+			catch (Exception $e) {
524 624
 				error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage());
525 625
 			}
526 626
 		}
527 627
 		$d->close();
528 628
 	}
529 629
 
530
-	public static function guess_filetype( $_file ) {
630
+	public static function guess_filetype( $_file )
631
+	{
531 632
 
532 633
 	}
533 634
 
@@ -538,7 +639,8 @@  discard block
 block discarded – undo
538 639
 	 * @param string $_type {import | export | all}
539 640
 	 * @return boolean
540 641
 	 */
541
-	public static function has_definitions( $_appname = 'all', $_type = 'all' ) {
642
+	public static function has_definitions( $_appname = 'all', $_type = 'all' )
643
+	{
542 644
 		$definitions = Api\Cache::getSession(
543 645
 			__CLASS__,
544 646
 			'has_definitions',
@@ -552,27 +654,36 @@  discard block
 block discarded – undo
552 654
 		// Testing: Comment out cache call above, use this
553 655
 		//$definitions = self::_has_definitions($appnames, $types);
554 656
 
555
-		foreach($definitions as $appname => $_types) {
556
-			if(!in_array($appname, $appnames)) unset($definitions[$appname]);
657
+		foreach($definitions as $appname => $_types)
658
+		{
659
+			if(!in_array($appname, $appnames))
660
+			{
661
+				unset($definitions[$appname]);
662
+			}
557 663
 		}
558
-		foreach($definitions as $appname => $_types) {
664
+		foreach($definitions as $appname => $_types)
665
+		{
559 666
 			$definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types));
560 667
 		}
561 668
 		return count($definitions[$appname]) > 0;
562 669
 	}
563 670
 
564 671
 	// Api\Cache needs this public
565
-	public static function _has_definitions(Array $appnames, Array $types) {
672
+	public static function _has_definitions(Array $appnames, Array $types)
673
+	{
566 674
 		$def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types));
567 675
 		$list = array();
568
-		foreach((array)$def->get_definitions() as $id) {
676
+		foreach((array)$def->get_definitions() as $id)
677
+		{
569 678
 			// Need to instanciate it to check, but if the user doesn't have permission, it throws an exception
570 679
 			try {
571 680
 				$definition = new importexport_definition($id);
572
-				if($def->is_permitted($definition->get_record_array())) {
681
+				if($def->is_permitted($definition->get_record_array()))
682
+				{
573 683
 					$list[$definition->application][$definition->type][] = $id;
574 684
 				}
575
-			} catch (Exception $e) {
685
+			}
686
+			catch (Exception $e) {
576 687
 				// That one doesn't work, keep going
577 688
 			}
578 689
 			$definition = null;
@@ -601,13 +712,22 @@  discard block
 block discarded – undo
601 712
 			$plugin = is_object($plugin_name) ? $plugin_name : new $plugin_name();
602 713
 			$plugin_name = get_class($plugin);
603 714
 
604
-			if($record_classname == null) $record_classname = $plugin::get_egw_record_class();
605
-			if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname);
715
+			if($record_classname == null)
716
+			{
717
+				$record_classname = $plugin::get_egw_record_class();
718
+			}
719
+			if(!class_exists($record_classname))
720
+			{
721
+				throw new Exception('Bad class name ' . $record_classname);
722
+			}
606 723
 
607 724
 			if(!$wizard_plugin)
608 725
 			{
609 726
 				$wizard_name = $app_name . '_wizard_' . str_replace($app_name . '_', '', $plugin_name);
610
-				if(!class_exists($wizard_name)) throw new Exception('Bad wizard name ' . $wizard_name);
727
+				if(!class_exists($wizard_name))
728
+				{
729
+					throw new Exception('Bad wizard name ' . $wizard_name);
730
+				}
611 731
 				$wizard_plugin = new $wizard_name;
612 732
 			}
613 733
 		}
@@ -627,7 +747,10 @@  discard block
 block discarded – undo
627 747
 		foreach($record_classname::$types as $type => $type_fields)
628 748
 		{
629 749
 			// Only these for now, until filter methods for others are figured out
630
-			if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) continue;
750
+			if(!in_array($type, array('select','select-cat','select-account','date','date-time')))
751
+			{
752
+				continue;
753
+			}
631 754
 			foreach($type_fields as $field_name)
632 755
 			{
633 756
 				$fields[$field_name] = array(
@@ -645,14 +768,18 @@  discard block
 block discarded – undo
645 768
 			$fields['#'.$field_name] = $settings;
646 769
 		}
647 770
 
648
-		foreach($fields as $field_name => &$settings) {
771
+		foreach($fields as $field_name => &$settings)
772
+		{
649 773
 			// Can't really filter on these (or at least no generic, sane way figured out yet)
650 774
 			if(!is_array($settings) || in_array($settings['type'], array('text','button', 'label','url','url-email','url-phone','htmlarea')))
651 775
 			{
652 776
 				unset($fields[$field_name]);
653 777
 				continue;
654 778
 			}
655
-			if($settings['type'] == 'radio') $settings['type'] = 'select';
779
+			if($settings['type'] == 'radio')
780
+			{
781
+				$settings['type'] = 'select';
782
+			}
656 783
 			switch($settings['type'])
657 784
 			{
658 785
 				case 'checkbox':
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 		return $plugins;
446 446
 	}
447 447
 
448
-	public static function _get_plugins(Array $appnames, Array $types) {
448
+	public static function _get_plugins(array $appnames, array $types) {
449 449
 		$plugins = array();
450 450
 		foreach ($appnames as $appname) {
451 451
 			if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue;
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 	}
563 563
 
564 564
 	// Api\Cache needs this public
565
-	public static function _has_definitions(Array $appnames, Array $types) {
565
+	public static function _has_definitions(array $appnames, array $types) {
566 566
 		$def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types));
567 567
 		$list = array();
568 568
 		foreach((array)$def->get_definitions() as $id) {
Please login to merge, or discard this patch.
importexport/inc/class.importexport_iface_egw_record.inc.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -35,6 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * reads record from backend if identifier is given.
36 36
 	 *
37 37
 	 * @param string $_identifier
38
+	 * @return void
38 39
 	 */
39 40
 	public function __construct( $_identifier='' );
40 41
 	
@@ -50,6 +51,7 @@  discard block
 block discarded – undo
50 51
 	 *
51 52
 	 * @param string $_attribute_name
52 53
 	 * @param data $data
54
+	 * @return void
53 55
 	 */
54 56
 	public function __set($_attribute_name, $data);
55 57
 	
@@ -126,6 +128,7 @@  discard block
 block discarded – undo
126 128
 	/**
127 129
 	 * destructor
128 130
 	 *
131
+	 * @return void
129 132
 	 */
130 133
 	public function __destruct();
131 134
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @param string $_identifier
38 38
 	 */
39
-	public function __construct( $_identifier='' );
39
+	public function __construct($_identifier = '');
40 40
 	
41 41
 	/**
42 42
 	 * magic method to set attributes of record
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @return string identifier
99 99
 	 */
100
-	public function save ( $_dst_identifier );
100
+	public function save($_dst_identifier);
101 101
 	
102 102
 	/**
103 103
 	 * copys current record to record identified by $_dst_identifier
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @param string $_dst_identifier
106 106
 	 * @return string dst_identifier
107 107
 	 */
108
-	public function copy ( $_dst_identifier );
108
+	public function copy($_dst_identifier);
109 109
 	
110 110
 	/**
111 111
 	 * moves current record to record identified by $_dst_identifier
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 	 * @param string $_dst_identifier
115 115
 	 * @return string dst_identifier
116 116
 	 */
117
-	public function move ( $_dst_identifier );
117
+	public function move($_dst_identifier);
118 118
 	
119 119
 	/**
120 120
 	 * delets current record from backend
121 121
 	 * @return void
122 122
 	 *
123 123
 	 */
124
-	public function delete ();
124
+	public function delete();
125 125
 	
126 126
 	/**
127 127
 	 * destructor
Please login to merge, or discard this patch.
importexport/inc/class.importexport_iface_export_plugin.inc.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@
 block discarded – undo
107 107
 	 * and automatic conversions.  In most cases they are named <appname>_egw_record,
108 108
 	 * but projectmanager is an exception to this.
109 109
 	 *
110
-	 * @return string;
110
+	 * @return string
111 111
 	 */
112 112
 	public static function get_egw_record_class();
113 113
 } // end of iface_export_plugin
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,8 @@
 block discarded – undo
34 34
  *
35 35
  * get_selector();  //returns array
36 36
  */
37
-interface importexport_iface_export_plugin {
37
+interface importexport_iface_export_plugin
38
+{
38 39
 	
39 40
 	/**
40 41
 	 * exports entries according to given definition object.
Please login to merge, or discard this patch.
importexport/inc/class.importexport_iface_import_plugin.inc.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
 	/**
30 30
 	 * imports entries according to given definition object.
31 31
 	 *
32
-	 * @param stram $_stram
33
-	 * @param definition $_definition
32
+	 * @param stram $_stream
33
+	 * @param importexport_definition $_definition
34 34
 	 * @return int number of successful imports
35 35
 	 */
36 36
 	public function import( $_stream, importexport_definition $_definition );
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -88,33 +88,33 @@
 block discarded – undo
88 88
 	public function get_selectors_etpl();
89 89
 
90 90
 	/**
91
-	* Returns errors that were encountered during importing
92
-	* Maximum of one error message per record, but you can concatenate them if you need to
93
-	*
94
-	* @return Array (
95
-	*	record_# => error message
96
-	*	)
97
-	*/
91
+	 * Returns errors that were encountered during importing
92
+	 * Maximum of one error message per record, but you can concatenate them if you need to
93
+	 *
94
+	 * @return Array (
95
+	 *	record_# => error message
96
+	 *	)
97
+	 */
98 98
 	public function get_errors();
99 99
 
100 100
 	/**
101
-	* Returns warnings that were encountered during importing
102
-	* Maximum of one warning message per record, but you can concatenate them if you need to
103
-	*
104
-	* @return Array (
105
-	*	record_# => warning message
106
-	*	)
107
-	*/
101
+	 * Returns warnings that were encountered during importing
102
+	 * Maximum of one warning message per record, but you can concatenate them if you need to
103
+	 *
104
+	 * @return Array (
105
+	 *	record_# => warning message
106
+	 *	)
107
+	 */
108 108
 	public function get_warnings();
109 109
 
110 110
 	/**
111
-	* Returns a list of actions taken, and the number of records for that action.
112
-	* Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
113
-	*
114
-	* @return Array (
115
-	*	action => record count
116
-	* )
117
-	*/
111
+	 * Returns a list of actions taken, and the number of records for that action.
112
+	 * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
113
+	 *
114
+	 * @return Array (
115
+	 *	action => record count
116
+	 * )
117
+	 */
118 118
 	public function get_results();
119 119
 
120 120
 } // end of iface_export_plugin
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	 * @param definition $_definition
34 34
 	 * @return int number of successful imports
35 35
 	 */
36
-	public function import( $_stream, importexport_definition $_definition );
36
+	public function import($_stream, importexport_definition $_definition);
37 37
 
38 38
 	/**
39 39
 	 * Reads entries, and presents them back as they will be understood
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,8 @@
 block discarded – undo
24 24
  * So this interface just garanties the interaction with userinterfaces. It
25 25
  * has nothing to do with datatypes.
26 26
  */
27
-interface importexport_iface_import_plugin {
27
+interface importexport_iface_import_plugin
28
+{
28 29
 	
29 30
 	/**
30 31
 	 * imports entries according to given definition object.
Please login to merge, or discard this patch.
importexport/inc/class.importexport_iface_import_record.inc.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	 * cleanup
34 34
 	 *
35 35
 	 * @return 
36
-	 */
36
+	 void
37 37
 	public function __destruct( );
38 38
 
39 39
 	/**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 * @param array $_options options for specific backends
28 28
 	 * @return bool
29 29
 	 */
30
-	public function __construct( $_stream, array $_options );
30
+	public function __construct($_stream, array $_options);
31 31
 
32 32
 	/**
33 33
 	 * cleanup
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @param string _position may be: {first|last|next|previous|somenumber}
43 43
 	 * @return bool
44 44
 	 */
45
-	public function get_record( $_position = 'next' );
45
+	public function get_record($_position = 'next');
46 46
 
47 47
 	/**
48 48
 	 * Retruns total number of records for the open resource.
Please login to merge, or discard this patch.
importexport/inc/class.importexport_import_csv.inc.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	/**
138 138
 	 * updates $this->record
139 139
 	 *
140
-	 * @param mixed $_position
141
-	 * @return bool
140
+	 * @param string $_position
141
+	 * @return null|false
142 142
 	 */
143 143
 	private function get_raw_record( $_position = 'next' ) {
144 144
 		switch ($_position) {
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	/**
245 245
 	 * does conversions according to $this->conversion
246 246
 	 *
247
-	 * @return bool
247
+	 * @return boolean|null
248 248
 	 */
249 249
 	protected function do_conversions() {
250 250
 		if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) {
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 	 * @param string $_resource resource containing data. May be each valid php-stream
84 84
 	 * @param array $_options options for the resource array with keys: charset and fieldsep
85 85
 	 */
86
-	public function __construct( $_resource,  array $_options ) {
86
+	public function __construct($_resource, array $_options) {
87 87
 		$this->resource = $_resource;
88 88
 		$this->csv_fieldsep = $_options['fieldsep'];
89
-		if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
89
+		if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
90 90
 		$this->csv_charset = $_options['charset'];
91 91
 		return;
92 92
 	} // end of member function __construct
@@ -103,20 +103,20 @@  discard block
 block discarded – undo
103 103
 	 * @param mixed _position may be: {current|first|last|next|previous|somenumber}
104 104
 	 * @return mixed array with data / false if no furtor records
105 105
 	 */
106
-	public function get_record( $_position = 'next' ) {
106
+	public function get_record($_position = 'next') {
107 107
 		
108
-		if ($this->get_raw_record( $_position ) === false) {
108
+		if ($this->get_raw_record($_position) === false) {
109 109
 			return false;
110 110
 		}
111 111
 		
112 112
 		// skip empty records
113
-		if( count( array_unique( $this->record ) ) < 2 ) return $this->get_record( $_position );
113
+		if (count(array_unique($this->record)) < 2) return $this->get_record($_position);
114 114
 		
115
-		if ( !empty( $this->conversion ) ) {
115
+		if (!empty($this->conversion)) {
116 116
 			$this->do_conversions();
117 117
 		}
118 118
 		
119
-		if ( !empty( $this->mapping ) ) {
119
+		if (!empty($this->mapping)) {
120 120
 			$this->do_fieldmapping();
121 121
 		}
122 122
 		
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 	 *
129 129
 	 * @param int $_numToSkip
130 130
 	 */
131
-	public function skip_records( $_numToSkip ) {
132
-		while ( (int)$_numToSkip-- !== 0 ) {
133
-			fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep);
131
+	public function skip_records($_numToSkip) {
132
+		while ((int)$_numToSkip-- !== 0) {
133
+			fgetcsv($this->resource, self::csv_max_linelength, $this->csv_fieldsep);
134 134
 		}
135 135
 	}
136 136
 	
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 * @param mixed $_position
141 141
 	 * @return bool
142 142
 	 */
143
-	private function get_raw_record( $_position = 'next' ) {
143
+	private function get_raw_record($_position = 'next') {
144 144
 		switch ($_position) {
145 145
 			case 'current' :
146 146
 				if ($this->current_position == 0) {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 				}
155 155
 				
156 156
 			case 'next' :
157
-				$csv_data = fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep);
157
+				$csv_data = fgetcsv($this->resource, self::csv_max_linelength, $this->csv_fieldsep);
158 158
 				if (!is_array($csv_data)) {
159 159
 					return false;
160 160
 				}
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 		$this->record = array();
236 236
 		foreach ($this->mapping as $cvs_idx => $new_idx)
237 237
 		{
238
-			if( $new_idx == '' ) continue;
238
+			if ($new_idx == '') continue;
239 239
 			$this->record[$new_idx] = $record[$cvs_idx];
240 240
 		}
241 241
 		return true;
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 	 * @return bool
248 248
 	 */
249 249
 	protected function do_conversions() {
250
-		if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) {
250
+		if ($record = importexport_helper_functions::conversion($this->record, $this->conversion, $this->conversion_class)) {
251 251
 			$this->record = $record;
252 252
 			return;
253 253
 		}
@@ -264,25 +264,25 @@  discard block
 block discarded – undo
264 264
 	 *
265 265
 	 * @return string warnings, if any
266 266
 	 */
267
-	public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) {
267
+	public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format = 0) {
268 268
 		$warnings = array();
269 269
 
270 270
 		// Automatic conversions
271
-		if($appname) {
271
+		if ($appname) {
272 272
 
273 273
 			// Load translations
274 274
 			Api\Translation::add_app($appname);
275 275
 
276
-			if(!self::$cf_parse_cache[$appname]) {
276
+			if (!self::$cf_parse_cache[$appname]) {
277 277
 				$c_fields = importexport_export_csv::convert_parse_custom_fields($appname, $selects, $links, $methods);
278 278
 				self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
279 279
 			}
280 280
 			list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname];
281 281
 
282 282
 			// Add in any fields that are keys to another app
283
-			foreach((array)$fields['links'] as $link_field => $app)
283
+			foreach ((array)$fields['links'] as $link_field => $app)
284 284
 			{
285
-				if(is_numeric($link_field)) continue;
285
+				if (is_numeric($link_field)) continue;
286 286
 				$links[$link_field] = $app;
287 287
 				// Set it as a normal link field
288 288
 				$fields['links'][] = $link_field;
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
 			}
291 291
 
292 292
 			// Not quite a recursive merge, since only one level
293
-			foreach($fields as $type => &$list)
293
+			foreach ($fields as $type => &$list)
294 294
 			{
295
-				if($c_fields[$type]) {
295
+				if ($c_fields[$type]) {
296 296
 					$list = array_merge($c_fields[$type], $list);
297 297
 					unset($c_fields[$type]);
298 298
 				}
@@ -300,36 +300,36 @@  discard block
 block discarded – undo
300 300
 			$fields += $c_fields;
301 301
 			$selects += $c_selects;
302 302
 		}
303
-		if($fields) {
304
-			foreach((array)$fields['select'] as $name) {
305
-				if($record[$name] != null && is_array($selects) && $selects[$name]) {
306
-					$key = array_search(strtolower($record[$name]), array_map('strtolower',$selects[$name]));
307
-					if($key !== false)
303
+		if ($fields) {
304
+			foreach ((array)$fields['select'] as $name) {
305
+				if ($record[$name] != null && is_array($selects) && $selects[$name]) {
306
+					$key = array_search(strtolower($record[$name]), array_map('strtolower', $selects[$name]));
307
+					if ($key !== false)
308 308
 					{
309 309
 						$record[$name] = $key;
310 310
 					}
311 311
 					else
312 312
 					{
313
-						$key = array_search(strtolower($record[$name]), array_map('strtolower',array_map('lang',$selects[$name])));
314
-						if($key !== false) $record[$name] = $key;
313
+						$key = array_search(strtolower($record[$name]), array_map('strtolower', array_map('lang', $selects[$name])));
314
+						if ($key !== false) $record[$name] = $key;
315 315
 					}
316 316
 				}
317 317
 			}
318
-			foreach((array)$fields['links'] as $name) {
319
-				if($record[$name] && $links[$name])
318
+			foreach ((array)$fields['links'] as $name) {
319
+				if ($record[$name] && $links[$name])
320 320
 				{
321 321
 					// Primary key to another app, not a link
322 322
 					// Text - search for a matching record
323
-					if(!is_numeric($record[$name]))
323
+					if (!is_numeric($record[$name]))
324 324
 					{
325 325
 						$results = Link::query($links[$name], $record[$name]);
326
-						if(count($results) >= 1)
326
+						if (count($results) >= 1)
327 327
 						{
328 328
 							// More than 1 result.  Check for exact match
329 329
 							$exact_count = 0;
330
-							foreach($results as $id => $title)
330
+							foreach ($results as $id => $title)
331 331
 							{
332
-								if($title == $record[$name])
332
+								if ($title == $record[$name])
333 333
 								{
334 334
 									$exact_count++;
335 335
 									$app_id = $id;
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
 								unset($results[$id]);
339 339
 							}
340 340
 							// Too many exact matches, or none good enough
341
-							if($exact_count > 1 || count($results) == 0)
341
+							if ($exact_count > 1 || count($results) == 0)
342 342
 							{
343 343
 								$warnings[] = lang('Unable to link to %1 "%2"',
344 344
 									lang($links[$name]), $record[$name]).
345
- 									' - ' .lang('too many matches');
345
+ 									' - '.lang('too many matches');
346 346
 								continue;
347 347
 							}
348 348
 							elseif ($exact_count == 1)
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 						{
356 356
 							$warnings[] = lang('Unable to link to %1 "%2"',
357 357
 								lang($links[$name]), $record[$name]).
358
- 								' - ' . lang('no matches');
358
+ 								' - '.lang('no matches');
359 359
 							continue;
360 360
 						} else {
361 361
 							$record[$name] = key($results);
@@ -363,17 +363,17 @@  discard block
 block discarded – undo
363 363
 					}
364 364
 				}
365 365
 			}
366
-			foreach((array)$fields['select-account'] as $name) {
366
+			foreach ((array)$fields['select-account'] as $name) {
367 367
 				// Compare against null to deal with empty arrays
368 368
 				if ($record[$name]) {
369 369
 					// Automatically handle text owner without explicit translation
370 370
 					$new_owner = importexport_helper_functions::account_name2id($record[$name]);
371
-					if(count($new_owner) != count(explode(',',$record[$name])))
371
+					if (count($new_owner) != count(explode(',', $record[$name])))
372 372
 					{
373 373
 						// Unable to parse value into account
374
-						$warnings[] = $name . ': ' .lang('%1 is not a known user or group', $record[$name]);
374
+						$warnings[] = $name.': '.lang('%1 is not a known user or group', $record[$name]);
375 375
 					}
376
-					if($new_owner != '') {
376
+					if ($new_owner != '') {
377 377
 						$record[$name] = $new_owner;
378 378
 					} else {
379 379
 						// Clear it to prevent trouble later on
@@ -381,24 +381,24 @@  discard block
 block discarded – undo
381 381
 					}
382 382
 				}
383 383
 			}
384
-			foreach((array)$fields['select-bool'] as $name) {
385
-				if($record[$name] != null && $record[$name] != '') {
384
+			foreach ((array)$fields['select-bool'] as $name) {
385
+				if ($record[$name] != null && $record[$name] != '') {
386 386
 					$record[$name] = ($record[$name] == lang('Yes') || $record[$name] == '1' ? 1 : 0);
387 387
 				}
388 388
 			}
389
-			foreach((array)$fields['date-time'] as $name) {
389
+			foreach ((array)$fields['date-time'] as $name) {
390 390
 				if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0)
391 391
 				{
392 392
 					// Need to handle format first
393
-					if($format == 1)
393
+					if ($format == 1)
394 394
 					{
395 395
 						$formatted = Api\DateTime::createFromFormat(
396
-							'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat,
396
+							'!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat,
397 397
 							$record[$name],
398 398
 							Api\DateTime::$user_timezone
399 399
 						);
400 400
 
401
-						if(!$formatted && $errors = Api\DateTime::getLastErrors())
401
+						if (!$formatted && $errors = Api\DateTime::getLastErrors())
402 402
 						{
403 403
 							// Try again, without time
404 404
 							$formatted = Api\DateTime::createFromFormat(
@@ -407,70 +407,70 @@  discard block
 block discarded – undo
407 407
 								Api\DateTime::$user_timezone
408 408
 							);
409 409
 							
410
-							if(!$formatted && $errors = Api\DateTime::getLastErrors())
410
+							if (!$formatted && $errors = Api\DateTime::getLastErrors())
411 411
 							{
412 412
 								// Try again, anything goes
413 413
 								try {
414 414
 									$formatted = new Api\DateTime($record[$name]);
415 415
 								} catch (Exception $e) {
416
-									$warnings[] = $name.': ' . $e->getMessage() . "\n" .
417
-										'Format: '.'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat;
416
+									$warnings[] = $name.': '.$e->getMessage()."\n".
417
+										'Format: '.'!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat;
418 418
 									continue;
419 419
 								}
420 420
 								$errors = Api\DateTime::getLastErrors();
421
-								foreach($errors['errors'] as $char => $msg)
421
+								foreach ($errors['errors'] as $char => $msg)
422 422
 								{
423 423
 									$warnings[] = "$name: [$char] $msg\n".
424
-										'Format: '.'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat;
424
+										'Format: '.'!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat;
425 425
 								}
426 426
 							}
427 427
 						}
428
-						if($formatted)
428
+						if ($formatted)
429 429
 						{
430 430
 							$record[$name] = $formatted->getTimestamp();
431 431
 							// Timestamp is apparently in server time, but apps will do the same conversion
432
-							$record[$name] = Api\DateTime::server2user($record[$name],'ts');
432
+							$record[$name] = Api\DateTime::server2user($record[$name], 'ts');
433 433
 						}
434 434
 					}
435 435
 					
436
-					if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) &&
436
+					if (is_array(self::$cf_parse_cache[$appname][0]['date-time']) &&
437 437
 							in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) {
438 438
 						// Custom fields stored in a particular format (from customfields_widget)
439 439
 						$record[$name] = date('Y-m-d H:i:s', $record[$name]);
440 440
 					}
441 441
 				}
442
-				if(array_key_exists($name, $record) && strlen(trim($record[$name])) == 0)
442
+				if (array_key_exists($name, $record) && strlen(trim($record[$name])) == 0)
443 443
 				{
444 444
 					$record[$name] = null;
445 445
 				}
446 446
 			}
447
-			foreach((array)$fields['date'] as $name) {
447
+			foreach ((array)$fields['date'] as $name) {
448 448
 				if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0)
449 449
 				{
450 450
 					// Need to handle format first
451
-					if($format == 1)
451
+					if ($format == 1)
452 452
 					{
453 453
 						$formatted = Api\DateTime::createFromFormat('!'.Api\DateTime::$user_dateformat, $record[$name]);
454
-						if($formatted && $errors = Api\DateTime::getLastErrors() && $errors['error_count'] == 0)
454
+						if ($formatted && $errors = Api\DateTime::getLastErrors() && $errors['error_count'] == 0)
455 455
 						{
456 456
 							$record[$name] = $formatted->getTimestamp();
457 457
 						}
458 458
 					}
459
-					$record[$name] = Api\DateTime::server2user($record[$name],'ts');
460
-					if(is_array(self::$cf_parse_cache[$appname][0]['date']) &&
459
+					$record[$name] = Api\DateTime::server2user($record[$name], 'ts');
460
+					if (is_array(self::$cf_parse_cache[$appname][0]['date']) &&
461 461
 							in_array($name, self::$cf_parse_cache[$appname][0]['date'])) {
462 462
 						// Custom fields stored in a particular format (from customfields_widget)
463 463
 						$record[$name] = date('Y-m-d', $record[$name]);
464 464
 					}
465 465
 				}
466
-				if(array_key_exists($name, $record) && strlen(trim($record[$name])) == 0)
466
+				if (array_key_exists($name, $record) && strlen(trim($record[$name])) == 0)
467 467
 				{
468 468
 					$record[$name] = null;
469 469
 				}
470 470
 			}
471
-			foreach((array)$fields['float'] as $name)
471
+			foreach ((array)$fields['float'] as $name)
472 472
 			{
473
-				if($record[$name] != null && $record[$name] != '') {
473
+				if ($record[$name] != null && $record[$name] != '') {
474 474
 					$dec_point = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
475 475
 					if (empty($dec_point)) $dec_point = '.';
476 476
 					$record[$name] = floatval(str_replace($dec_point, '.', preg_replace('/[^\d'.preg_quote($dec_point).']/', '', $record[$name])));
@@ -478,23 +478,23 @@  discard block
 block discarded – undo
478 478
 			}
479 479
 
480 480
 			// Some custom methods for conversion
481
-			foreach((array)$methods as $name => $method) {
482
-				if($record[$name]) $record[$name] = ExecMethod($method, $record[$name]);
481
+			foreach ((array)$methods as $name => $method) {
482
+				if ($record[$name]) $record[$name] = ExecMethod($method, $record[$name]);
483 483
 			}
484 484
 
485 485
 			// cat_name2id will use currentapp to create new categories
486 486
 			$current_app = $GLOBALS['egw_info']['flags']['currentapp'];
487
-			if($appname) {
487
+			if ($appname) {
488 488
 				$GLOBALS['egw_info']['flags']['currentapp'] = $appname;
489 489
 			}
490
-			$categories = new Api\Categories('',$appname);
491
-			foreach((array)$fields['select-cat'] as $name) {
492
-				if($record[$name]) {
490
+			$categories = new Api\Categories('', $appname);
491
+			foreach ((array)$fields['select-cat'] as $name) {
492
+				if ($record[$name]) {
493 493
 					// Only parse name if it needs it
494
-					if($format == 1)
494
+					if ($format == 1)
495 495
 					{
496
-						$existing_cat = $categories->exists('all',$record[$name]);
497
-						if($existing_cat)
496
+						$existing_cat = $categories->exists('all', $record[$name]);
497
+						if ($existing_cat)
498 498
 						{
499 499
 							$cat_id = $existing_cat;
500 500
 						}
@@ -503,14 +503,14 @@  discard block
 block discarded – undo
503 503
 							$cat_id = importexport_helper_functions::cat_name2id($record[$name]);
504 504
 						}
505 505
 						// Don't clear it if it wasn't found
506
-						if($cat_id) $record[$name] = $cat_id;
506
+						if ($cat_id) $record[$name] = $cat_id;
507 507
 					}
508 508
 				}
509 509
 			}
510 510
 			$GLOBALS['egw_info']['flags']['currentapp'] = $current_app;
511 511
 		}
512 512
 
513
-		return implode("\n",$warnings);
513
+		return implode("\n", $warnings);
514 514
 	}
515 515
 } // end of import_csv
516 516
 ?>
Please login to merge, or discard this patch.
Braces   +143 added lines, -61 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
  * @todo Throw away spechial chars and trim() entries ?
23 23
  * @todo Check for XSS like userinput! (see common_functions)
24 24
  */
25
-class importexport_import_csv implements importexport_iface_import_record { //, Iterator {
25
+class importexport_import_csv implements importexport_iface_import_record
26
+{
27
+//, Iterator {
26 28
 
27 29
 	const csv_max_linelength = 8000;
28 30
 	
@@ -83,10 +85,14 @@  discard block
 block discarded – undo
83 85
 	 * @param string $_resource resource containing data. May be each valid php-stream
84 86
 	 * @param array $_options options for the resource array with keys: charset and fieldsep
85 87
 	 */
86
-	public function __construct( $_resource,  array $_options ) {
88
+	public function __construct( $_resource,  array $_options )
89
+	{
87 90
 		$this->resource = $_resource;
88 91
 		$this->csv_fieldsep = $_options['fieldsep'];
89
-		if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
92
+		if($_options['charset'] == 'user')
93
+		{
94
+			$_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
95
+		}
90 96
 		$this->csv_charset = $_options['charset'];
91 97
 		return;
92 98
 	} // end of member function __construct
@@ -94,7 +100,8 @@  discard block
 block discarded – undo
94 100
 	/**
95 101
 	 * cleanup
96 102
 	 */
97
-	public function __destruct( ) {
103
+	public function __destruct( )
104
+	{
98 105
 	} // end of member function __destruct
99 106
 
100 107
 	/**
@@ -103,20 +110,27 @@  discard block
 block discarded – undo
103 110
 	 * @param mixed _position may be: {current|first|last|next|previous|somenumber}
104 111
 	 * @return mixed array with data / false if no furtor records
105 112
 	 */
106
-	public function get_record( $_position = 'next' ) {
113
+	public function get_record( $_position = 'next' )
114
+	{
107 115
 		
108
-		if ($this->get_raw_record( $_position ) === false) {
116
+		if ($this->get_raw_record( $_position ) === false)
117
+		{
109 118
 			return false;
110 119
 		}
111 120
 		
112 121
 		// skip empty records
113
-		if( count( array_unique( $this->record ) ) < 2 ) return $this->get_record( $_position );
122
+		if( count( array_unique( $this->record ) ) < 2 )
123
+		{
124
+			return $this->get_record( $_position );
125
+		}
114 126
 		
115
-		if ( !empty( $this->conversion ) ) {
127
+		if ( !empty( $this->conversion ) )
128
+		{
116 129
 			$this->do_conversions();
117 130
 		}
118 131
 		
119
-		if ( !empty( $this->mapping ) ) {
132
+		if ( !empty( $this->mapping ) )
133
+		{
120 134
 			$this->do_fieldmapping();
121 135
 		}
122 136
 		
@@ -128,8 +142,10 @@  discard block
 block discarded – undo
128 142
 	 *
129 143
 	 * @param int $_numToSkip
130 144
 	 */
131
-	public function skip_records( $_numToSkip ) {
132
-		while ( (int)$_numToSkip-- !== 0 ) {
145
+	public function skip_records( $_numToSkip )
146
+	{
147
+		while ( (int)$_numToSkip-- !== 0 )
148
+		{
133 149
 			fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep);
134 150
 		}
135 151
 	}
@@ -140,22 +156,27 @@  discard block
 block discarded – undo
140 156
 	 * @param mixed $_position
141 157
 	 * @return bool
142 158
 	 */
143
-	private function get_raw_record( $_position = 'next' ) {
144
-		switch ($_position) {
159
+	private function get_raw_record( $_position = 'next' )
160
+	{
161
+		switch ($_position)
162
+		{
145 163
 			case 'current' :
146
-				if ($this->current_position == 0) {
164
+				if ($this->current_position == 0)
165
+				{
147 166
 					return;
148 167
 				}
149 168
 				break;
150 169
 			case 'first' :
151
-				if (!$this->current_position == 0) {
170
+				if (!$this->current_position == 0)
171
+				{
152 172
 					$this->current_position = 0;
153 173
 					rewind($this->resource);
154 174
 				}
155 175
 				
156 176
 			case 'next' :
157 177
 				$csv_data = fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep);
158
-				if (!is_array($csv_data)) {
178
+				if (!is_array($csv_data))
179
+				{
159 180
 					return false;
160 181
 				}
161 182
 				$this->current_position++;
@@ -163,33 +184,41 @@  discard block
 block discarded – undo
163 184
 				break;
164 185
 				
165 186
 			case 'previous' :
166
-				if ($this->current_position < 2) {
187
+				if ($this->current_position < 2)
188
+				{
167 189
 					throw new Exception('Error: There is no previous record!');
168 190
 				}
169 191
 				$final_position = --$this->current_position;
170 192
 				$this->current_position = 0;
171 193
 				rewind($this->resource);
172
-				while ($this->current_position !== $final_position) {
194
+				while ($this->current_position !== $final_position)
195
+				{
173 196
 					$this->get_raw_record();
174 197
 				}
175 198
 				break;
176 199
 				
177 200
 			case 'last' :
178
-				while ($this->get_raw_record()) {}
201
+				while ($this->get_raw_record())
202
+				{
203
+}
179 204
 				break;
180 205
 				
181 206
 			default: //somenumber
182
-				if (!is_int($_position)) {
207
+				if (!is_int($_position))
208
+				{
183 209
 					throw new Exception('Error: $position must be one of {current|first|last|next|previous} or an integer value');
184 210
 				}
185
-				if ($_position == $this->current_position) {
211
+				if ($_position == $this->current_position)
212
+				{
186 213
 					break;
187 214
 				}
188
-				elseif ($_position < $this->current_position) {
215
+				elseif ($_position < $this->current_position)
216
+				{
189 217
 					$this->current_position = 0;
190 218
 					rewind($this->resource);
191 219
 				}
192
-				while ($this->current_position !== $_position) {
220
+				while ($this->current_position !== $_position)
221
+				{
193 222
 					$this->get_raw_record();
194 223
 				}
195 224
 				break;				
@@ -202,12 +231,16 @@  discard block
 block discarded – undo
202 231
 	 *
203 232
 	 * @return int
204 233
 	 */
205
-	public function get_num_of_records( ) {
206
-		if ($this->num_of_records > 0) {
234
+	public function get_num_of_records( )
235
+	{
236
+		if ($this->num_of_records > 0)
237
+		{
207 238
 			return $this->num_of_records;
208 239
 		}
209 240
 		$current_position = $this->current_position;
210
-		while ($this->get_raw_record()) {}
241
+		while ($this->get_raw_record())
242
+		{
243
+}
211 244
 		$this->num_of_records = $this->current_position;
212 245
 		$this->get_record($current_position);
213 246
 		return $this->num_of_records;
@@ -218,7 +251,8 @@  discard block
 block discarded – undo
218 251
 	 *
219 252
 	 * @return int
220 253
 	 */
221
-	public function get_current_position( ) {
254
+	public function get_current_position( )
255
+	{
222 256
 		
223 257
 		return $this->current_position;
224 258
 		
@@ -230,12 +264,16 @@  discard block
 block discarded – undo
230 264
 	 *
231 265
 	 * @return
232 266
 	 */
233
-	protected function do_fieldmapping( ) {
267
+	protected function do_fieldmapping( )
268
+	{
234 269
 		$record = $this->record;
235 270
 		$this->record = array();
236 271
 		foreach ($this->mapping as $cvs_idx => $new_idx)
237 272
 		{
238
-			if( $new_idx == '' ) continue;
273
+			if( $new_idx == '' )
274
+			{
275
+				continue;
276
+			}
239 277
 			$this->record[$new_idx] = $record[$cvs_idx];
240 278
 		}
241 279
 		return true;
@@ -246,8 +284,10 @@  discard block
 block discarded – undo
246 284
 	 *
247 285
 	 * @return bool
248 286
 	 */
249
-	protected function do_conversions() {
250
-		if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) {
287
+	protected function do_conversions()
288
+	{
289
+		if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class ))
290
+		{
251 291
 			$this->record = $record;
252 292
 			return;
253 293
 		}
@@ -264,16 +304,19 @@  discard block
 block discarded – undo
264 304
 	 *
265 305
 	 * @return string warnings, if any
266 306
 	 */
267
-	public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) {
307
+	public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0)
308
+	{
268 309
 		$warnings = array();
269 310
 
270 311
 		// Automatic conversions
271
-		if($appname) {
312
+		if($appname)
313
+		{
272 314
 
273 315
 			// Load translations
274 316
 			Api\Translation::add_app($appname);
275 317
 
276
-			if(!self::$cf_parse_cache[$appname]) {
318
+			if(!self::$cf_parse_cache[$appname])
319
+			{
277 320
 				$c_fields = importexport_export_csv::convert_parse_custom_fields($appname, $selects, $links, $methods);
278 321
 				self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
279 322
 			}
@@ -282,7 +325,10 @@  discard block
 block discarded – undo
282 325
 			// Add in any fields that are keys to another app
283 326
 			foreach((array)$fields['links'] as $link_field => $app)
284 327
 			{
285
-				if(is_numeric($link_field)) continue;
328
+				if(is_numeric($link_field))
329
+				{
330
+					continue;
331
+				}
286 332
 				$links[$link_field] = $app;
287 333
 				// Set it as a normal link field
288 334
 				$fields['links'][] = $link_field;
@@ -292,7 +338,8 @@  discard block
 block discarded – undo
292 338
 			// Not quite a recursive merge, since only one level
293 339
 			foreach($fields as $type => &$list)
294 340
 			{
295
-				if($c_fields[$type]) {
341
+				if($c_fields[$type])
342
+				{
296 343
 					$list = array_merge($c_fields[$type], $list);
297 344
 					unset($c_fields[$type]);
298 345
 				}
@@ -300,9 +347,12 @@  discard block
 block discarded – undo
300 347
 			$fields += $c_fields;
301 348
 			$selects += $c_selects;
302 349
 		}
303
-		if($fields) {
304
-			foreach((array)$fields['select'] as $name) {
305
-				if($record[$name] != null && is_array($selects) && $selects[$name]) {
350
+		if($fields)
351
+		{
352
+			foreach((array)$fields['select'] as $name)
353
+			{
354
+				if($record[$name] != null && is_array($selects) && $selects[$name])
355
+				{
306 356
 					$key = array_search(strtolower($record[$name]), array_map('strtolower',$selects[$name]));
307 357
 					if($key !== false)
308 358
 					{
@@ -311,11 +361,15 @@  discard block
 block discarded – undo
311 361
 					else
312 362
 					{
313 363
 						$key = array_search(strtolower($record[$name]), array_map('strtolower',array_map('lang',$selects[$name])));
314
-						if($key !== false) $record[$name] = $key;
364
+						if($key !== false)
365
+						{
366
+							$record[$name] = $key;
367
+						}
315 368
 					}
316 369
 				}
317 370
 			}
318
-			foreach((array)$fields['links'] as $name) {
371
+			foreach((array)$fields['links'] as $name)
372
+			{
319 373
 				if($record[$name] && $links[$name])
320 374
 				{
321 375
 					// Primary key to another app, not a link
@@ -357,15 +411,19 @@  discard block
 block discarded – undo
357 411
 								lang($links[$name]), $record[$name]).
358 412
  								' - ' . lang('no matches');
359 413
 							continue;
360
-						} else {
414
+						}
415
+						else
416
+						{
361 417
 							$record[$name] = key($results);
362 418
 						}
363 419
 					}
364 420
 				}
365 421
 			}
366
-			foreach((array)$fields['select-account'] as $name) {
422
+			foreach((array)$fields['select-account'] as $name)
423
+			{
367 424
 				// Compare against null to deal with empty arrays
368
-				if ($record[$name]) {
425
+				if ($record[$name])
426
+				{
369 427
 					// Automatically handle text owner without explicit translation
370 428
 					$new_owner = importexport_helper_functions::account_name2id($record[$name]);
371 429
 					if(count($new_owner) != count(explode(',',$record[$name])))
@@ -373,20 +431,26 @@  discard block
 block discarded – undo
373 431
 						// Unable to parse value into account
374 432
 						$warnings[] = $name . ': ' .lang('%1 is not a known user or group', $record[$name]);
375 433
 					}
376
-					if($new_owner != '') {
434
+					if($new_owner != '')
435
+					{
377 436
 						$record[$name] = $new_owner;
378
-					} else {
437
+					}
438
+					else
439
+					{
379 440
 						// Clear it to prevent trouble later on
380 441
 						$record[$name] = '';
381 442
 					}
382 443
 				}
383 444
 			}
384
-			foreach((array)$fields['select-bool'] as $name) {
385
-				if($record[$name] != null && $record[$name] != '') {
445
+			foreach((array)$fields['select-bool'] as $name)
446
+			{
447
+				if($record[$name] != null && $record[$name] != '')
448
+				{
386 449
 					$record[$name] = ($record[$name] == lang('Yes') || $record[$name] == '1' ? 1 : 0);
387 450
 				}
388 451
 			}
389
-			foreach((array)$fields['date-time'] as $name) {
452
+			foreach((array)$fields['date-time'] as $name)
453
+			{
390 454
 				if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0)
391 455
 				{
392 456
 					// Need to handle format first
@@ -412,7 +476,8 @@  discard block
 block discarded – undo
412 476
 								// Try again, anything goes
413 477
 								try {
414 478
 									$formatted = new Api\DateTime($record[$name]);
415
-								} catch (Exception $e) {
479
+								}
480
+								catch (Exception $e) {
416 481
 									$warnings[] = $name.': ' . $e->getMessage() . "\n" .
417 482
 										'Format: '.'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat;
418 483
 									continue;
@@ -434,7 +499,8 @@  discard block
 block discarded – undo
434 499
 					}
435 500
 					
436 501
 					if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) &&
437
-							in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) {
502
+							in_array($name, self::$cf_parse_cache[$appname][0]['date-time']))
503
+					{
438 504
 						// Custom fields stored in a particular format (from customfields_widget)
439 505
 						$record[$name] = date('Y-m-d H:i:s', $record[$name]);
440 506
 					}
@@ -444,7 +510,8 @@  discard block
 block discarded – undo
444 510
 					$record[$name] = null;
445 511
 				}
446 512
 			}
447
-			foreach((array)$fields['date'] as $name) {
513
+			foreach((array)$fields['date'] as $name)
514
+			{
448 515
 				if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0)
449 516
 				{
450 517
 					// Need to handle format first
@@ -458,7 +525,8 @@  discard block
 block discarded – undo
458 525
 					}
459 526
 					$record[$name] = Api\DateTime::server2user($record[$name],'ts');
460 527
 					if(is_array(self::$cf_parse_cache[$appname][0]['date']) &&
461
-							in_array($name, self::$cf_parse_cache[$appname][0]['date'])) {
528
+							in_array($name, self::$cf_parse_cache[$appname][0]['date']))
529
+					{
462 530
 						// Custom fields stored in a particular format (from customfields_widget)
463 531
 						$record[$name] = date('Y-m-d', $record[$name]);
464 532
 					}
@@ -470,26 +538,37 @@  discard block
 block discarded – undo
470 538
 			}
471 539
 			foreach((array)$fields['float'] as $name)
472 540
 			{
473
-				if($record[$name] != null && $record[$name] != '') {
541
+				if($record[$name] != null && $record[$name] != '')
542
+				{
474 543
 					$dec_point = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
475
-					if (empty($dec_point)) $dec_point = '.';
544
+					if (empty($dec_point))
545
+					{
546
+						$dec_point = '.';
547
+					}
476 548
 					$record[$name] = floatval(str_replace($dec_point, '.', preg_replace('/[^\d'.preg_quote($dec_point).']/', '', $record[$name])));
477 549
 				}
478 550
 			}
479 551
 
480 552
 			// Some custom methods for conversion
481
-			foreach((array)$methods as $name => $method) {
482
-				if($record[$name]) $record[$name] = ExecMethod($method, $record[$name]);
553
+			foreach((array)$methods as $name => $method)
554
+			{
555
+				if($record[$name])
556
+				{
557
+					$record[$name] = ExecMethod($method, $record[$name]);
558
+				}
483 559
 			}
484 560
 
485 561
 			// cat_name2id will use currentapp to create new categories
486 562
 			$current_app = $GLOBALS['egw_info']['flags']['currentapp'];
487
-			if($appname) {
563
+			if($appname)
564
+			{
488 565
 				$GLOBALS['egw_info']['flags']['currentapp'] = $appname;
489 566
 			}
490 567
 			$categories = new Api\Categories('',$appname);
491
-			foreach((array)$fields['select-cat'] as $name) {
492
-				if($record[$name]) {
568
+			foreach((array)$fields['select-cat'] as $name)
569
+			{
570
+				if($record[$name])
571
+				{
493 572
 					// Only parse name if it needs it
494 573
 					if($format == 1)
495 574
 					{
@@ -503,7 +582,10 @@  discard block
 block discarded – undo
503 582
 							$cat_id = importexport_helper_functions::cat_name2id($record[$name]);
504 583
 						}
505 584
 						// Don't clear it if it wasn't found
506
-						if($cat_id) $record[$name] = $cat_id;
585
+						if($cat_id)
586
+						{
587
+							$record[$name] = $cat_id;
588
+						}
507 589
 					}
508 590
 				}
509 591
 			}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -264,7 +264,7 @@
 block discarded – undo
264 264
 	 *
265 265
 	 * @return string warnings, if any
266 266
 	 */
267
-	public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) {
267
+	public static function convert(array &$record, array $fields = array(), $appname = null, array $selects = array(), $format=0) {
268 268
 		$warnings = array();
269 269
 
270 270
 		// Automatic conversions
Please login to merge, or discard this patch.