Completed
Push — 14.2 ( 1730cb...8c75f3 )
by Ralf
73:29 queued 51:28
created
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.
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.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -94,22 +94,22 @@  discard block
 block discarded – undo
94 94
 	 * @param array _options options for specific backends
95 95
 	 * @return bool
96 96
 	 */
97
-	public function __construct( $_stream, array $_options ) {
97
+	public function __construct($_stream, array $_options) {
98 98
 		if (!is_object($GLOBALS['egw']->translation)) {
99 99
 			$GLOBALS['egw']->translation = new translation();
100 100
 		}
101 101
 		$this->translation = &$GLOBALS['egw']->translation;
102 102
 		$this->handle = $_stream;
103
-		if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
103
+		if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
104 104
 		$this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8';
105
-		if ( !empty( $_options ) ) {
106
-			$this->csv_options = array_merge( $this->csv_options, $_options );
105
+		if (!empty($_options)) {
106
+			$this->csv_options = array_merge($this->csv_options, $_options);
107 107
 		}
108 108
 		//error_log(__METHOD__.__LINE__.array2string($_options['appname']));
109
-		if(!bo_merge::is_export_limit_excepted()) {
109
+		if (!bo_merge::is_export_limit_excepted()) {
110 110
 			$this->export_limit = bo_merge::getExportLimit($_options['appname']);
111 111
 			//error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit);
112
-			if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled');
112
+			if ($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled');
113 113
 		}
114 114
 	}
115 115
 	
@@ -118,15 +118,15 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @param array $_mapping egw_field_name => csv_field_name
120 120
 	 */
121
-	public function set_mapping( array &$_mapping) {
121
+	public function set_mapping(array &$_mapping) {
122 122
 		if ($this->num_of_records > 0) {
123 123
 			throw new Exception('Error: Field mapping can\'t be set during ongoing export!');
124 124
 		}
125
-		if($_mapping['all_custom_fields']) {
125
+		if ($_mapping['all_custom_fields']) {
126 126
 			// Field value is the appname, so we can pull the fields
127 127
 			$custom = config::get_customfields($_mapping['all_custom_fields']);
128 128
 			unset($_mapping['all_custom_fields']);
129
-			foreach($custom as $field => $info) {
129
+			foreach ($custom as $field => $info) {
130 130
 				$_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field;
131 131
 			}
132 132
 		}
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @param array $_conversion
141 141
 	 */
142
-	public function set_conversion( array $_conversion) {
142
+	public function set_conversion(array $_conversion) {
143 143
 		$this->conversion = $_conversion;
144 144
 	}
145 145
 	
@@ -149,59 +149,59 @@  discard block
 block discarded – undo
149 149
 	 * @param importexport_iface_egw_record record
150 150
 	 * @return bool
151 151
 	 */
152
-	public function export_record( importexport_iface_egw_record $_record ) {
152
+	public function export_record(importexport_iface_egw_record $_record) {
153 153
 		$this->record = $_record;
154 154
 		$this->record_array = $_record->get_record_array();
155 155
 		
156 156
 		// begin with fieldnames ?
157
-		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) {
158
-			if($this->csv_options['begin_with_fieldnames'] == 'label') {
157
+		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames']) {
158
+			if ($this->csv_options['begin_with_fieldnames'] == 'label') {
159 159
 				// Load translations for app
160 160
 				list($appname, $part2) = explode('_', get_class($_record));
161
-				if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name
161
+				if (!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name
162 162
 
163 163
 				// Get translations from wizard, if possible
164
-				if(!$this->csv_options['no_header_translation'])
164
+				if (!$this->csv_options['no_header_translation'])
165 165
 				{
166 166
 					$backtrace = debug_backtrace();
167 167
 					$plugin = $backtrace[1]['class'];
168
-					$wizard_name = $appname . '_wizard_' . str_replace($appname . '_', '', $plugin);
168
+					$wizard_name = $appname.'_wizard_'.str_replace($appname.'_', '', $plugin);
169 169
 					try {
170 170
 						$wizard = new $wizard_name;
171 171
 						$fields = $wizard->get_export_fields();
172
-						foreach($this->mapping as $field => &$label)
172
+						foreach ($this->mapping as $field => &$label)
173 173
 						{
174
-							if($fields[$field])
174
+							if ($fields[$field])
175 175
 							{
176 176
 								$label = $label != $fields[$field] ? $fields[$field] : lang($label);
177 177
 							}
178 178
 							// Make sure no *
179
-							if(substr($label,-1) == '*') $label = substr($label,0,-1);
179
+							if (substr($label, -1) == '*') $label = substr($label, 0, -1);
180 180
 						}
181 181
 					} catch (Exception $e) {
182 182
 						translation::add_app($appname);
183
-						foreach($this->mapping as $field => &$label) {
183
+						foreach ($this->mapping as $field => &$label) {
184 184
 							$label = lang($label);
185 185
 						}
186 186
 					}
187 187
 				}
188 188
 			}
189
-			$mapping = ! empty( $this->mapping ) ? $this->mapping : array_keys ( $this->record_array );
190
-			self::fputcsv( $this->handle ,$mapping ,$this->csv_options['delimiter'], $this->csv_options['enclosure'] );
189
+			$mapping = !empty($this->mapping) ? $this->mapping : array_keys($this->record_array);
190
+			self::fputcsv($this->handle, $mapping, $this->csv_options['delimiter'], $this->csv_options['enclosure']);
191 191
 		}
192 192
 
193 193
 		// Check for limit
194
-		if($this->export_limit && $this->num_of_records >= $this->export_limit) {
194
+		if ($this->export_limit && $this->num_of_records >= $this->export_limit) {
195 195
 			return;
196 196
 		}
197 197
 		
198 198
 		// do conversions
199
-		if ( !empty( $this->conversion )) {
200
-			$this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion );
199
+		if (!empty($this->conversion)) {
200
+			$this->record_array = importexport_helper_functions::conversion($this->record_array, $this->conversion);
201 201
 		}
202 202
 		
203 203
 		// do fieldmapping
204
-		if ( !empty( $this->mapping ) ) {
204
+		if (!empty($this->mapping)) {
205 205
 			$record_data = $this->record_array;
206 206
 			$this->record_array = array();
207 207
 			foreach ($this->mapping as $egw_field => $csv_field) {
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			}
210 210
 		}
211 211
 		
212
-		self::fputcsv( $this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure'] );
212
+		self::fputcsv($this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure']);
213 213
 		$this->num_of_records++;
214 214
 	}
215 215
 
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 	 * @return Array of fields to be added to list of fields needing conversion
234 234
 	 */
235 235
 	public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) {
236
-		if(!$appname) return;
236
+		if (!$appname) return;
237 237
 
238 238
 		$fields = array();
239 239
 		$custom = config::get_customfields($appname);
240
-		foreach($custom as $name => $c_field) {
241
-			$name = '#' . $name;
242
-			switch($c_field['type']) {
240
+		foreach ($custom as $name => $c_field) {
241
+			$name = '#'.$name;
242
+			switch ($c_field['type']) {
243 243
 				case 'date':
244 244
 					$fields['date'][] = $name;
245 245
 					break;
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 					$fields['select-account'][] = $name;
251 251
 					break;
252 252
 				case 'ajax_select':
253
-					if($c_field['values']['get_title']) {
253
+					if ($c_field['values']['get_title']) {
254 254
 						$methods[$name] = $c_field['values']['get_title'];
255 255
 						break;
256 256
 					}
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 					$selects[$name] = $c_field['values'];
265 265
 					break;
266 266
 				default:
267
-					list($type) = explode('-',$c_field['type'],2);
268
-					if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) {
267
+					list($type) = explode('-', $c_field['type'], 2);
268
+					if (in_array($type, array_keys($GLOBALS['egw_info']['apps']))) {
269 269
 						$fields['links'][] = $name;
270 270
 						$links[$name] = $c_field['type'];
271 271
 					}
@@ -284,18 +284,18 @@  discard block
 block discarded – undo
284 284
 	 * @parem fields List of field types => field names to be converted
285 285
 	 * @param appname Current appname if you want to do custom fields too
286 286
 	 */
287
-	public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) {
288
-		if($appname) {
289
-			if(!self::$cf_parse_cache[$appname]) {
287
+	public static function convert(importexport_iface_egw_record&$record, Array $fields = array(), $appname = null, $selects = array()) {
288
+		if ($appname) {
289
+			if (!self::$cf_parse_cache[$appname]) {
290 290
 				$c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods);
291 291
 				self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
292 292
 			}
293 293
 			list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname];
294 294
 
295 295
 			// Add in any fields that are keys to another app
296
-			foreach((array)$fields['links'] as $link_field => $app)
296
+			foreach ((array)$fields['links'] as $link_field => $app)
297 297
 			{
298
-				if(is_numeric($link_field)) continue;
298
+				if (is_numeric($link_field)) continue;
299 299
 				$links[$link_field] = $app;
300 300
 				// Set it as a normal link field
301 301
 				$fields['links'][] = $link_field;
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
 			}
304 304
 
305 305
 			// Not quite a recursive merge, since only one level
306
-			foreach($fields as $type => &$list) {
307
-				if($c_fields[$type]) {
306
+			foreach ($fields as $type => &$list) {
307
+				if ($c_fields[$type]) {
308 308
 					$list = array_merge($c_fields[$type], $list);
309 309
 					unset($c_fields[$type]);
310 310
 				}
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 			$fields += $c_fields;
313 313
 			$selects += $c_selects;
314 314
 		}
315
-		foreach((array)$fields['select'] as $name) {
316
-			if($record->$name != null && is_array($selects) && $selects[$name]) {
315
+		foreach ((array)$fields['select'] as $name) {
316
+			if ($record->$name != null && is_array($selects) && $selects[$name]) {
317 317
 				$record->$name = explode(',', $record->$name);
318
-				if(is_array($record->$name)) {
318
+				if (is_array($record->$name)) {
319 319
 					$names = array();
320
-					foreach($record->$name as $_name) {
320
+					foreach ($record->$name as $_name) {
321 321
 						$names[] = lang($selects[$name][$_name]);
322 322
 					}
323 323
 					$record->$name = implode(', ', $names);
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
 				$record->$name = '';
331 331
 			}
332 332
 		}
333
-		foreach((array)$fields['links'] as $name) {
334
-			if($record->$name) {
335
-				if(is_numeric($record->$name) && !$links[$name]) {
333
+		foreach ((array)$fields['links'] as $name) {
334
+			if ($record->$name) {
335
+				if (is_numeric($record->$name) && !$links[$name]) {
336 336
 					$link = egw_link::get_link($record->$name);
337 337
 					$links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']);
338 338
 					$record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']);
339 339
 				}
340
-				if($links[$name]) {
340
+				if ($links[$name]) {
341 341
 					$record->$name = egw_link::title($links[$name], $record->$name);
342 342
 				}
343 343
 			}
@@ -346,12 +346,12 @@  discard block
 block discarded – undo
346 346
 				$record->$name = '';
347 347
 			}
348 348
 		}
349
-		foreach((array)$fields['select-account'] as $name) {
349
+		foreach ((array)$fields['select-account'] as $name) {
350 350
 			// Compare against null to deal with empty arrays
351 351
 			if ($record->$name !== null) {
352
-				if(is_array($record->$name)) {
352
+				if (is_array($record->$name)) {
353 353
 					$names = array();
354
-					foreach($record->$name as $_name) {
354
+					foreach ($record->$name as $_name) {
355 355
 						$names[] = common::grab_owner_name($_name);
356 356
 					}
357 357
 					$record->$name = implode(', ', $names);
@@ -364,64 +364,64 @@  discard block
 block discarded – undo
364 364
 				$record->$name = '';
365 365
 			}
366 366
 		}
367
-		foreach((array)$fields['select-bool'] as $name) {
368
-			if($record->$name !== null) {
367
+		foreach ((array)$fields['select-bool'] as $name) {
368
+			if ($record->$name !== null) {
369 369
 				$record->$name = $record->$name ? lang('Yes') : lang('No');
370 370
 			}
371 371
 		}
372
-		foreach((array)$fields['date-time'] as $name) {
372
+		foreach ((array)$fields['date-time'] as $name) {
373 373
 			//if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format
374 374
 			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
375
-			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
376
-				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format
375
+			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.
376
+				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'), $record->$name); // User date format
377 377
 			if (!$record->$name) $record->$name = '';
378 378
 		}
379
-		foreach((array)$fields['date'] as $name) {
379
+		foreach ((array)$fields['date'] as $name) {
380 380
 			//if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format
381 381
 			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
382 382
 			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format
383 383
 			if (!$record->$name) $record->$name = '';
384 384
 		}
385
-		foreach((array)$fields['float'] as $name)
385
+		foreach ((array)$fields['float'] as $name)
386 386
 		{
387
-			static $dec_separator,$thousands_separator;
387
+			static $dec_separator, $thousands_separator;
388 388
 			if (is_null($dec_separator))
389 389
 			{
390 390
 				$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
391 391
 				if (empty($dec_separator)) $dec_separator = '.';
392 392
 				$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
393 393
 			}
394
-			if($record->$name && (string)$record->$name != '')
394
+			if ($record->$name && (string)$record->$name != '')
395 395
 			{
396
-				if(!is_numeric($record->$name))
396
+				if (!is_numeric($record->$name))
397 397
 				{
398 398
 					$record->$name = floatval(str_replace($dec_separator, '.', preg_replace('/[^\d'.preg_quote($dec_separator).']/', '', $record->$name)));
399 399
 				}
400
-				$record->$name = number_format(str_replace(' ','',$record->$name), 2,
401
-					$dec_separator,$thousands_separator
400
+				$record->$name = number_format(str_replace(' ', '', $record->$name), 2,
401
+					$dec_separator, $thousands_separator
402 402
 				);
403 403
 			}
404 404
 		}
405 405
 
406 406
 		// Some custom methods for conversion
407
-		foreach((array)$methods as $name => $method) {
408
-			if($record->$name) $record->$name = ExecMethod($method, $record->$name);
407
+		foreach ((array)$methods as $name => $method) {
408
+			if ($record->$name) $record->$name = ExecMethod($method, $record->$name);
409 409
 		}
410 410
 
411 411
 		static $cat_object;
412
-		if(is_null($cat_object)) $cat_object = new categories(false,$appname);
413
-		foreach((array)$fields['select-cat'] as $name) {
414
-			if($record->$name) {
412
+		if (is_null($cat_object)) $cat_object = new categories(false, $appname);
413
+		foreach ((array)$fields['select-cat'] as $name) {
414
+			if ($record->$name) {
415 415
 				$cats = array();
416 416
 				$ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name);
417
-				foreach($ids as $n => $cat_id) {
417
+				foreach ($ids as $n => $cat_id) {
418 418
 
419
-					if ($cat_id && $cat_object->check_perms(EGW_ACL_READ,$cat_id))
419
+					if ($cat_id && $cat_object->check_perms(EGW_ACL_READ, $cat_id))
420 420
 					{
421 421
 						$cats[] = $cat_object->id2name($cat_id);
422 422
 					}
423 423
 				}
424
-				$record->$name = implode(', ',$cats);
424
+				$record->$name = implode(', ', $cats);
425 425
 			}
426 426
 			else
427 427
 			{
@@ -448,18 +448,18 @@  discard block
 block discarded – undo
448 448
 	 * @param char $delimiter
449 449
 	 * @param char $enclosure
450 450
 	 */
451
-	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){
451
+	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure) {
452 452
 		$string = "";
453 453
 		$writeDelimiter = false;
454
-		foreach($dataArray as $dataElement) {
455
-			if($writeDelimiter) $string .= $delimiter;
456
-			$string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure;
454
+		foreach ($dataArray as $dataElement) {
455
+			if ($writeDelimiter) $string .= $delimiter;
456
+			$string .= $enclosure.str_replace(array("\r\n", '"'), array("\n", '""'), $dataElement).$enclosure;
457 457
 			$writeDelimiter = true;
458 458
 		}
459 459
 		$string .= "\n";
460 460
 		
461 461
 		// do charset translation
462
-		$string = $this->translation->convert( $string, $this->translation->charset(), $this->csv_charset );
462
+		$string = $this->translation->convert($string, $this->translation->charset(), $this->csv_charset);
463 463
 		
464 464
 		fwrite($filePointer, $string);
465 465
 			
Please login to merge, or discard this patch.
Braces   +180 added lines, -71 removed lines patch added patch discarded remove patch
@@ -94,22 +94,32 @@  discard block
 block discarded – undo
94 94
 	 * @param array _options options for specific backends
95 95
 	 * @return bool
96 96
 	 */
97
-	public function __construct( $_stream, array $_options ) {
98
-		if (!is_object($GLOBALS['egw']->translation)) {
97
+	public function __construct( $_stream, array $_options )
98
+	{
99
+		if (!is_object($GLOBALS['egw']->translation))
100
+		{
99 101
 			$GLOBALS['egw']->translation = new translation();
100 102
 		}
101 103
 		$this->translation = &$GLOBALS['egw']->translation;
102 104
 		$this->handle = $_stream;
103
-		if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
105
+		if($_options['charset'] == 'user')
106
+		{
107
+			$_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
108
+		}
104 109
 		$this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8';
105
-		if ( !empty( $_options ) ) {
110
+		if ( !empty( $_options ) )
111
+		{
106 112
 			$this->csv_options = array_merge( $this->csv_options, $_options );
107 113
 		}
108 114
 		//error_log(__METHOD__.__LINE__.array2string($_options['appname']));
109
-		if(!bo_merge::is_export_limit_excepted()) {
115
+		if(!bo_merge::is_export_limit_excepted())
116
+		{
110 117
 			$this->export_limit = bo_merge::getExportLimit($_options['appname']);
111 118
 			//error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit);
112
-			if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled');
119
+			if($this->export_limit == 'no')
120
+			{
121
+				throw new egw_exception_no_permission_admin('Export disabled');
122
+			}
113 123
 		}
114 124
 	}
115 125
 	
@@ -118,15 +128,19 @@  discard block
 block discarded – undo
118 128
 	 *
119 129
 	 * @param array $_mapping egw_field_name => csv_field_name
120 130
 	 */
121
-	public function set_mapping( array &$_mapping) {
122
-		if ($this->num_of_records > 0) {
131
+	public function set_mapping( array &$_mapping)
132
+	{
133
+		if ($this->num_of_records > 0)
134
+		{
123 135
 			throw new Exception('Error: Field mapping can\'t be set during ongoing export!');
124 136
 		}
125
-		if($_mapping['all_custom_fields']) {
137
+		if($_mapping['all_custom_fields'])
138
+		{
126 139
 			// Field value is the appname, so we can pull the fields
127 140
 			$custom = config::get_customfields($_mapping['all_custom_fields']);
128 141
 			unset($_mapping['all_custom_fields']);
129
-			foreach($custom as $field => $info) {
142
+			foreach($custom as $field => $info)
143
+			{
130 144
 				$_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field;
131 145
 			}
132 146
 		}
@@ -139,7 +153,8 @@  discard block
 block discarded – undo
139 153
 	 *
140 154
 	 * @param array $_conversion
141 155
 	 */
142
-	public function set_conversion( array $_conversion) {
156
+	public function set_conversion( array $_conversion)
157
+	{
143 158
 		$this->conversion = $_conversion;
144 159
 	}
145 160
 	
@@ -149,16 +164,23 @@  discard block
 block discarded – undo
149 164
 	 * @param importexport_iface_egw_record record
150 165
 	 * @return bool
151 166
 	 */
152
-	public function export_record( importexport_iface_egw_record $_record ) {
167
+	public function export_record( importexport_iface_egw_record $_record )
168
+	{
153 169
 		$this->record = $_record;
154 170
 		$this->record_array = $_record->get_record_array();
155 171
 		
156 172
 		// begin with fieldnames ?
157
-		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) {
158
-			if($this->csv_options['begin_with_fieldnames'] == 'label') {
173
+		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] )
174
+		{
175
+			if($this->csv_options['begin_with_fieldnames'] == 'label')
176
+			{
159 177
 				// Load translations for app
160 178
 				list($appname, $part2) = explode('_', get_class($_record));
161
-				if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name
179
+				if(!$GLOBALS['egw_info']['apps'][$appname])
180
+				{
181
+					$appname .= $part2;
182
+				}
183
+				// Handle apps with _ in the name
162 184
 
163 185
 				// Get translations from wizard, if possible
164 186
 				if(!$this->csv_options['no_header_translation'])
@@ -176,11 +198,16 @@  discard block
 block discarded – undo
176 198
 								$label = $label != $fields[$field] ? $fields[$field] : lang($label);
177 199
 							}
178 200
 							// Make sure no *
179
-							if(substr($label,-1) == '*') $label = substr($label,0,-1);
201
+							if(substr($label,-1) == '*')
202
+							{
203
+								$label = substr($label,0,-1);
204
+							}
180 205
 						}
181
-					} catch (Exception $e) {
206
+					}
207
+					catch (Exception $e) {
182 208
 						translation::add_app($appname);
183
-						foreach($this->mapping as $field => &$label) {
209
+						foreach($this->mapping as $field => &$label)
210
+						{
184 211
 							$label = lang($label);
185 212
 						}
186 213
 					}
@@ -191,20 +218,24 @@  discard block
 block discarded – undo
191 218
 		}
192 219
 
193 220
 		// Check for limit
194
-		if($this->export_limit && $this->num_of_records >= $this->export_limit) {
221
+		if($this->export_limit && $this->num_of_records >= $this->export_limit)
222
+		{
195 223
 			return;
196 224
 		}
197 225
 		
198 226
 		// do conversions
199
-		if ( !empty( $this->conversion )) {
227
+		if ( !empty( $this->conversion ))
228
+		{
200 229
 			$this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion );
201 230
 		}
202 231
 		
203 232
 		// do fieldmapping
204
-		if ( !empty( $this->mapping ) ) {
233
+		if ( !empty( $this->mapping ) )
234
+		{
205 235
 			$record_data = $this->record_array;
206 236
 			$this->record_array = array();
207
-			foreach ($this->mapping as $egw_field => $csv_field) {
237
+			foreach ($this->mapping as $egw_field => $csv_field)
238
+			{
208 239
 				$this->record_array[$csv_field] = $record_data[$egw_field];
209 240
 			}
210 241
 		}
@@ -218,7 +249,8 @@  discard block
 block discarded – undo
218 249
 	 *
219 250
 	 * @return int
220 251
 	 */
221
-	public function get_num_of_records() {
252
+	public function get_num_of_records()
253
+	{
222 254
 		return $this->num_of_records;
223 255
 	}
224 256
 
@@ -232,14 +264,20 @@  discard block
 block discarded – undo
232 264
 	 *
233 265
 	 * @return Array of fields to be added to list of fields needing conversion
234 266
 	 */
235
-	public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) {
236
-		if(!$appname) return;
267
+	public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array())
268
+	{
269
+		if(!$appname)
270
+		{
271
+			return;
272
+		}
237 273
 
238 274
 		$fields = array();
239 275
 		$custom = config::get_customfields($appname);
240
-		foreach($custom as $name => $c_field) {
276
+		foreach($custom as $name => $c_field)
277
+		{
241 278
 			$name = '#' . $name;
242
-			switch($c_field['type']) {
279
+			switch($c_field['type'])
280
+			{
243 281
 				case 'date':
244 282
 					$fields['date'][] = $name;
245 283
 					break;
@@ -250,7 +288,8 @@  discard block
 block discarded – undo
250 288
 					$fields['select-account'][] = $name;
251 289
 					break;
252 290
 				case 'ajax_select':
253
-					if($c_field['values']['get_title']) {
291
+					if($c_field['values']['get_title'])
292
+					{
254 293
 						$methods[$name] = $c_field['values']['get_title'];
255 294
 						break;
256 295
 					}
@@ -265,7 +304,8 @@  discard block
 block discarded – undo
265 304
 					break;
266 305
 				default:
267 306
 					list($type) = explode('-',$c_field['type'],2);
268
-					if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) {
307
+					if(in_array($type, array_keys($GLOBALS['egw_info']['apps'])))
308
+					{
269 309
 						$fields['links'][] = $name;
270 310
 						$links[$name] = $c_field['type'];
271 311
 					}
@@ -284,9 +324,12 @@  discard block
 block discarded – undo
284 324
 	 * @parem fields List of field types => field names to be converted
285 325
 	 * @param appname Current appname if you want to do custom fields too
286 326
 	 */
287
-	public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) {
288
-		if($appname) {
289
-			if(!self::$cf_parse_cache[$appname]) {
327
+	public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array())
328
+	{
329
+		if($appname)
330
+		{
331
+			if(!self::$cf_parse_cache[$appname])
332
+			{
290 333
 				$c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods);
291 334
 				self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
292 335
 			}
@@ -295,7 +338,10 @@  discard block
 block discarded – undo
295 338
 			// Add in any fields that are keys to another app
296 339
 			foreach((array)$fields['links'] as $link_field => $app)
297 340
 			{
298
-				if(is_numeric($link_field)) continue;
341
+				if(is_numeric($link_field))
342
+				{
343
+					continue;
344
+				}
299 345
 				$links[$link_field] = $app;
300 346
 				// Set it as a normal link field
301 347
 				$fields['links'][] = $link_field;
@@ -303,8 +349,10 @@  discard block
 block discarded – undo
303 349
 			}
304 350
 
305 351
 			// Not quite a recursive merge, since only one level
306
-			foreach($fields as $type => &$list) {
307
-				if($c_fields[$type]) {
352
+			foreach($fields as $type => &$list)
353
+			{
354
+				if($c_fields[$type])
355
+				{
308 356
 					$list = array_merge($c_fields[$type], $list);
309 357
 					unset($c_fields[$type]);
310 358
 				}
@@ -312,16 +360,22 @@  discard block
 block discarded – undo
312 360
 			$fields += $c_fields;
313 361
 			$selects += $c_selects;
314 362
 		}
315
-		foreach((array)$fields['select'] as $name) {
316
-			if($record->$name != null && is_array($selects) && $selects[$name]) {
363
+		foreach((array)$fields['select'] as $name)
364
+		{
365
+			if($record->$name != null && is_array($selects) && $selects[$name])
366
+			{
317 367
 				$record->$name = explode(',', $record->$name);
318
-				if(is_array($record->$name)) {
368
+				if(is_array($record->$name))
369
+				{
319 370
 					$names = array();
320
-					foreach($record->$name as $_name) {
371
+					foreach($record->$name as $_name)
372
+					{
321 373
 						$names[] = lang($selects[$name][$_name]);
322 374
 					}
323 375
 					$record->$name = implode(', ', $names);
324
-				} else {
376
+				}
377
+				else
378
+				{
325 379
 					$record->$name = lang($selects[$name][$record->$name]);
326 380
 				}
327 381
 			}
@@ -330,14 +384,18 @@  discard block
 block discarded – undo
330 384
 				$record->$name = '';
331 385
 			}
332 386
 		}
333
-		foreach((array)$fields['links'] as $name) {
334
-			if($record->$name) {
335
-				if(is_numeric($record->$name) && !$links[$name]) {
387
+		foreach((array)$fields['links'] as $name)
388
+		{
389
+			if($record->$name)
390
+			{
391
+				if(is_numeric($record->$name) && !$links[$name])
392
+				{
336 393
 					$link = egw_link::get_link($record->$name);
337 394
 					$links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']);
338 395
 					$record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']);
339 396
 				}
340
-				if($links[$name]) {
397
+				if($links[$name])
398
+				{
341 399
 					$record->$name = egw_link::title($links[$name], $record->$name);
342 400
 				}
343 401
 			}
@@ -346,16 +404,22 @@  discard block
 block discarded – undo
346 404
 				$record->$name = '';
347 405
 			}
348 406
 		}
349
-		foreach((array)$fields['select-account'] as $name) {
407
+		foreach((array)$fields['select-account'] as $name)
408
+		{
350 409
 			// Compare against null to deal with empty arrays
351
-			if ($record->$name !== null) {
352
-				if(is_array($record->$name)) {
410
+			if ($record->$name !== null)
411
+			{
412
+				if(is_array($record->$name))
413
+				{
353 414
 					$names = array();
354
-					foreach($record->$name as $_name) {
415
+					foreach($record->$name as $_name)
416
+					{
355 417
 						$names[] = common::grab_owner_name($_name);
356 418
 					}
357 419
 					$record->$name = implode(', ', $names);
358
-				} else {
420
+				}
421
+				else
422
+				{
359 423
 					$record->$name = common::grab_owner_name($record->$name);
360 424
 				}
361 425
 			}
@@ -364,23 +428,49 @@  discard block
 block discarded – undo
364 428
 				$record->$name = '';
365 429
 			}
366 430
 		}
367
-		foreach((array)$fields['select-bool'] as $name) {
368
-			if($record->$name !== null) {
431
+		foreach((array)$fields['select-bool'] as $name)
432
+		{
433
+			if($record->$name !== null)
434
+			{
369 435
 				$record->$name = $record->$name ? lang('Yes') : lang('No');
370 436
 			}
371 437
 		}
372
-		foreach((array)$fields['date-time'] as $name) {
438
+		foreach((array)$fields['date-time'] as $name)
439
+		{
373 440
 			//if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format
374
-			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
375
-			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
376
-				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format
377
-			if (!$record->$name) $record->$name = '';
441
+			if ($record->$name && !is_numeric($record->$name))
442
+			{
443
+				$record->$name = strtotime($record->$name);
444
+			}
445
+			// Custom fields stored as string
446
+			if ($record->$name && is_numeric($record->$name))
447
+			{
448
+				$record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
449
+				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name);
450
+			}
451
+			// User date format
452
+			if (!$record->$name)
453
+			{
454
+				$record->$name = '';
455
+			}
378 456
 		}
379
-		foreach((array)$fields['date'] as $name) {
457
+		foreach((array)$fields['date'] as $name)
458
+		{
380 459
 			//if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format
381
-			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
382
-			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format
383
-			if (!$record->$name) $record->$name = '';
460
+			if ($record->$name && !is_numeric($record->$name))
461
+			{
462
+				$record->$name = strtotime($record->$name);
463
+			}
464
+			// Custom fields stored as string
465
+			if ($record->$name && is_numeric($record->$name))
466
+			{
467
+				$record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name);
468
+			}
469
+			// User date format
470
+			if (!$record->$name)
471
+			{
472
+				$record->$name = '';
473
+			}
384 474
 		}
385 475
 		foreach((array)$fields['float'] as $name)
386 476
 		{
@@ -388,7 +478,10 @@  discard block
 block discarded – undo
388 478
 			if (is_null($dec_separator))
389 479
 			{
390 480
 				$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
391
-				if (empty($dec_separator)) $dec_separator = '.';
481
+				if (empty($dec_separator))
482
+				{
483
+					$dec_separator = '.';
484
+				}
392 485
 				$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
393 486
 			}
394 487
 			if($record->$name && (string)$record->$name != '')
@@ -404,17 +497,27 @@  discard block
 block discarded – undo
404 497
 		}
405 498
 
406 499
 		// Some custom methods for conversion
407
-		foreach((array)$methods as $name => $method) {
408
-			if($record->$name) $record->$name = ExecMethod($method, $record->$name);
500
+		foreach((array)$methods as $name => $method)
501
+		{
502
+			if($record->$name)
503
+			{
504
+				$record->$name = ExecMethod($method, $record->$name);
505
+			}
409 506
 		}
410 507
 
411 508
 		static $cat_object;
412
-		if(is_null($cat_object)) $cat_object = new categories(false,$appname);
413
-		foreach((array)$fields['select-cat'] as $name) {
414
-			if($record->$name) {
509
+		if(is_null($cat_object))
510
+		{
511
+			$cat_object = new categories(false,$appname);
512
+		}
513
+		foreach((array)$fields['select-cat'] as $name)
514
+		{
515
+			if($record->$name)
516
+			{
415 517
 				$cats = array();
416 518
 				$ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name);
417
-				foreach($ids as $n => $cat_id) {
519
+				foreach($ids as $n => $cat_id)
520
+				{
418 521
 
419 522
 					if ($cat_id && $cat_object->check_perms(EGW_ACL_READ,$cat_id))
420 523
 					{
@@ -435,7 +538,8 @@  discard block
 block discarded – undo
435 538
 	 *
436 539
 	 * @return
437 540
 	 */
438
-	public function __destruct() {
541
+	public function __destruct()
542
+	{
439 543
 		
440 544
 	}
441 545
 
@@ -448,11 +552,16 @@  discard block
 block discarded – undo
448 552
 	 * @param char $delimiter
449 553
 	 * @param char $enclosure
450 554
 	 */
451
-	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){
555
+	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure)
556
+	{
452 557
 		$string = "";
453 558
 		$writeDelimiter = false;
454
-		foreach($dataArray as $dataElement) {
455
-			if($writeDelimiter) $string .= $delimiter;
559
+		foreach($dataArray as $dataElement)
560
+		{
561
+			if($writeDelimiter)
562
+			{
563
+				$string .= $delimiter;
564
+			}
456 565
 			$string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure;
457 566
 			$writeDelimiter = true;
458 567
 		}
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.
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.
Spacing   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -30,19 +30,19 @@  discard block
 block discarded – undo
30 30
 	 * Relative date ranges for filtering
31 31
 	 */
32 32
 	public static $relative_dates = array(      // Start: year,month,day,week, End: year,month,day,week
33
-                'Today'       => array(0,0,0,0,  0,0,1,0),
34
-                'Yesterday'   => array(0,0,-1,0, 0,0,0,0),
35
-                'This week'   => array(0,0,0,0,  0,0,0,1),
36
-                'Last week'   => array(0,0,0,-1, 0,0,0,0),
37
-                'This month'  => array(0,0,0,0,  0,1,0,0),
38
-                'Last month'  => array(0,-1,0,0, 0,0,0,0),
39
-                'Last 3 months' => array(0,-3,0,0, 0,0,0,0),
40
-                'This quarter'=> array(0,0,0,0,  0,0,0,0),      // Just a marker, needs special handling
41
-                'Last quarter'=> array(0,-4,0,0, 0,-4,0,0),     // Just a marker
42
-                'This year'   => array(0,0,0,0,  1,0,0,0),
43
-                'Last year'   => array(-1,0,0,0, 0,0,0,0),
44
-                '2 years ago' => array(-2,0,0,0, -1,0,0,0),
45
-                '3 years ago' => array(-3,0,0,0, -2,0,0,0),
33
+                'Today'       => array(0, 0, 0, 0, 0, 0, 1, 0),
34
+                'Yesterday'   => array(0, 0, -1, 0, 0, 0, 0, 0),
35
+                'This week'   => array(0, 0, 0, 0, 0, 0, 0, 1),
36
+                'Last week'   => array(0, 0, 0, -1, 0, 0, 0, 0),
37
+                'This month'  => array(0, 0, 0, 0, 0, 1, 0, 0),
38
+                'Last month'  => array(0, -1, 0, 0, 0, 0, 0, 0),
39
+                'Last 3 months' => array(0, -3, 0, 0, 0, 0, 0, 0),
40
+                'This quarter'=> array(0, 0, 0, 0, 0, 0, 0, 0), // Just a marker, needs special handling
41
+                'Last quarter'=> array(0, -4, 0, 0, 0, -4, 0, 0), // Just a marker
42
+                'This year'   => array(0, 0, 0, 0, 1, 0, 0, 0),
43
+                'Last year'   => array(-1, 0, 0, 0, 0, 0, 0, 0),
44
+                '2 years ago' => array(-2, 0, 0, 0, -1, 0, 0, 0),
45
+                '3 years ago' => array(-3, 0, 0, 0, -2, 0, 0, 0),
46 46
         );
47 47
 
48 48
 	/**
@@ -77,22 +77,22 @@  discard block
 block discarded – undo
77 77
 	 * @param string $_format format of time string e.g.: d.m.Y H:i
78 78
 	 * @param int $_is_dst is day light saving time? 0 = no, 1 = yes, -1 = system default
79 79
 	 */
80
-	public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) {
81
-		if ( empty( $_format ) ) return strtotime( $_string );
82
-		$fparams = explode( ',', chunk_split( $_format, 1, ',' ) );
80
+	public static function custom_strtotime($_string, $_format = '', $_is_dst = -1) {
81
+		if (empty($_format)) return strtotime($_string);
82
+		$fparams = explode(',', chunk_split($_format, 1, ','));
83 83
 		$spos = 0;
84
-		foreach ( $fparams as $fparam ) {
85
-
86
-			switch ( $fparam ) {
87
-				case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break;
88
-				case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break;
89
-				case 'y': (int)$year = substr( $_string, $spos, 2 ); $spos += 2; break;
90
-				case 'Y': (int)$year = substr( $_string, $spos, 4 ); $spos += 4; break;
91
-				case 'H': (int)$hour = substr( $_string, $spos, 2 ); $spos += 2; break;
92
-				case 'h': (int)$hour = substr( $_string, $spos, 2 ); $spos += 2; break;
93
-				case 'i': (int)$min =  substr( $_string, $spos, 2 ); $spos += 2; break;
94
-				case 's': (int)$sec =  substr( $_string, $spos, 2 ); $spos += 2; break;
95
-				case 'O': (int)$offset = $year = substr( $_string, $spos, 5 ); $spos += 5; break;
84
+		foreach ($fparams as $fparam) {
85
+
86
+			switch ($fparam) {
87
+				case 'd': (int)$day = substr($_string, $spos, 2); $spos += 2; break;
88
+				case 'm': (int)$mon = substr($_string, $spos, 2); $spos += 2; break;
89
+				case 'y': (int)$year = substr($_string, $spos, 2); $spos += 2; break;
90
+				case 'Y': (int)$year = substr($_string, $spos, 4); $spos += 4; break;
91
+				case 'H': (int)$hour = substr($_string, $spos, 2); $spos += 2; break;
92
+				case 'h': (int)$hour = substr($_string, $spos, 2); $spos += 2; break;
93
+				case 'i': (int)$min = substr($_string, $spos, 2); $spos += 2; break;
94
+				case 's': (int)$sec = substr($_string, $spos, 2); $spos += 2; break;
95
+				case 'O': (int)$offset = $year = substr($_string, $spos, 5); $spos += 5; break;
96 96
 				case 'a': (int)$hour = $fparam == 'am' ? $hour : $hour + 12; break;
97 97
 				case 'A': (int)$hour = $fparam == 'AM' ? $hour : $hour + 12; break;
98 98
 				default: $spos++; // seperator
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
 		$timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst);
104 104
 
105 105
 		// offset given?
106
-		if ( isset( $offset ) && strlen( $offset == 5 ) ) {
106
+		if (isset($offset) && strlen($offset == 5)) {
107 107
 			$operator = $offset{0};
108
-			$ohour = 60 * 60 * (int)substr( $offset, 1, 2 );
109
-			$omin = 60 * (int)substr( $offset, 3, 2 );
110
-			if ( $operator == '+' ) $timestamp += $ohour + $omin;
108
+			$ohour = 60 * 60 * (int)substr($offset, 1, 2);
109
+			$omin = 60 * (int)substr($offset, 3, 2);
110
+			if ($operator == '+') $timestamp += $ohour + $omin;
111 111
 			else $timestamp -= $ohour + $omin;
112 112
 		}
113 113
 		return $timestamp;
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
 	 * @param mixed $_account_lid comma seperated list or array with lids
119 119
 	 * @return mixed comma seperated list or array with ids
120 120
 	 */
121
-	public static function account_name2id( &$_account_lids ) {
122
-		$account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids );
121
+	public static function account_name2id(&$_account_lids) {
122
+		$account_lids = is_array($_account_lids) ? $_account_lids : explode(',', $_account_lids);
123 123
 		$skip = false;
124
-		foreach ( $account_lids as $key => $account_lid ) {
125
-			if($skip) {
124
+		foreach ($account_lids as $key => $account_lid) {
125
+			if ($skip) {
126 126
 				unset($account_lids[$key]);
127 127
 				$skip = false;
128 128
 				continue;
@@ -130,15 +130,15 @@  discard block
 block discarded – undo
130 130
 			$account_lid = trim($account_lid);
131 131
 
132 132
 			// Handle any IDs that slip in
133
-			if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) {
133
+			if (is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) {
134 134
 				unset($account_lids[$key]);
135 135
 				$account_ids[] = (int)$account_lid;
136 136
 				continue;
137 137
 			}
138 138
 			// Check for [username]
139
-			if(strpos($account_lid,'[') !== false)
139
+			if (strpos($account_lid, '[') !== false)
140 140
 			{
141
-				if(preg_match('/\[(.+)\]/',$account_lid,$matches))
141
+				if (preg_match('/\[(.+)\]/', $account_lid, $matches))
142 142
 				{
143 143
 					$account_id = $GLOBALS['egw']->accounts->name2id($matches[1]);
144 144
 					unset($account_lids[$key]);
@@ -149,46 +149,46 @@  discard block
 block discarded – undo
149 149
 
150 150
 			// Handle users listed as Lastname, Firstname instead of login ID
151 151
 			// Do this first, in case their first name matches a username
152
-			if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) {
152
+			if ($account_lids[$key + 1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id(trim($account_lids[$key + 1]).' '.$account_lid, 'account_fullname')) {
153 153
 				$account_ids[] = $account_id;
154 154
 				unset($account_lids[$key]);
155 155
 				$skip = true; // Skip the next one, it's the first name
156
-				continue ;
156
+				continue;
157 157
 			}
158 158
 
159 159
 			// Deal with groups listed as <name> Group, remove the Group
160
-			if(substr(trim($account_lid),-strlen(lang('Group'))) == lang('Group'))
160
+			if (substr(trim($account_lid), -strlen(lang('Group'))) == lang('Group'))
161 161
 			{
162 162
 				$account_lid = trim(substr(trim($account_lid), 0, -strlen(lang('Group'))));
163 163
 			}
164 164
 
165
-			if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) {
165
+			if ($account_id = $GLOBALS['egw']->accounts->name2id($account_lid)) {
166 166
 				$account_ids[] = $account_id;
167 167
 				unset($account_lids[$key]);
168 168
 				continue;
169 169
 			}
170
-			if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) {
170
+			if ($account_id = $GLOBALS['egw']->accounts->name2id(trim($account_lid), 'account_fullname')) {
171 171
 				$account_ids[] = $account_id;
172 172
 				unset($account_lids[$key]);
173 173
 				continue;
174 174
 			}
175 175
 
176 176
 			// Handle groups listed as Group, <name>
177
-			if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) {
177
+			if ($account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id($account_lid)) {
178 178
 				$account_ids[] = $account_id;
179
-				unset($account_lids[$key-1]);
179
+				unset($account_lids[$key - 1]);
180 180
 				unset($account_lids[$key]);
181 181
 				continue;
182 182
 			}
183 183
 			// Group, <name> - remove the Group part
184
-			if($account_lid == lang('Group'))
184
+			if ($account_lid == lang('Group'))
185 185
 			{
186 186
 				unset($account_lids[$key]);
187 187
 				continue;
188 188
 			}
189 189
 		}
190
-		$_account_lids = (is_array($_account_lids) ? $account_lids : implode(',',array_unique($account_lids)));
191
-		return is_array( $_account_lids ) ? array_unique($account_ids) : implode( ',', array_unique((array)$account_ids ));
190
+		$_account_lids = (is_array($_account_lids) ? $account_lids : implode(',', array_unique($account_lids)));
191
+		return is_array($_account_lids) ? array_unique($account_ids) : implode(',', array_unique((array)$account_ids));
192 192
 
193 193
 	} // end of member function account_lid2id
194 194
 
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
 	 * @param mixed $_account_ids comma seperated list or array with ids
199 199
 	 * @return mixed comma seperated list or array with lids
200 200
 	 */
201
-	public static function account_id2name( $_account_id ) {
202
-		$account_ids = is_array( $_account_id ) ? $_account_id : explode( ',', $_account_id );
203
-		foreach ( $account_ids as $account_id ) {
204
-			if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) {
201
+	public static function account_id2name($_account_id) {
202
+		$account_ids = is_array($_account_id) ? $_account_id : explode(',', $_account_id);
203
+		foreach ($account_ids as $account_id) {
204
+			if ($account_lid = $GLOBALS['egw']->accounts->id2name($account_id)) {
205 205
 				$account_lids[] = $account_lid;
206 206
 			}
207 207
 		}
208
-		return is_array( $_account_id ) ? $account_lids : implode( ',', (array)$account_lids );
208
+		return is_array($_account_id) ? $account_lids : implode(',', (array)$account_lids);
209 209
 	} // end of member function account_id2lid
210 210
 
211 211
 	/**
@@ -214,12 +214,12 @@  discard block
 block discarded – undo
214 214
 	 * @param mixed _cat_ids comma seperated list or array
215 215
 	 * @return mixed comma seperated list or array with cat_names
216 216
 	 */
217
-	public static function cat_id2name( $_cat_ids ) {
218
-		$cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids );
219
-		foreach ( $cat_ids as $cat_id ) {
220
-			$cat_names[] = categories::id2name( (int)$cat_id );
217
+	public static function cat_id2name($_cat_ids) {
218
+		$cat_ids = is_array($_cat_ids) ? $_cat_ids : explode(',', $_cat_ids);
219
+		foreach ($cat_ids as $cat_id) {
220
+			$cat_names[] = categories::id2name((int)$cat_id);
221 221
 		}
222
-		return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names);
222
+		return is_array($_cat_ids) ? $cat_names : implode(',', (array)$cat_names);
223 223
 	} // end of member function category_id2name
224 224
 
225 225
 	/**
@@ -230,24 +230,24 @@  discard block
 block discarded – undo
230 230
 	 * @param int $parent Optional parent ID to use for new categories
231 231
 	 * @return mixed comma seperated list or array with cat_ids
232 232
 	 */
233
-	public static function cat_name2id( $_cat_names, $parent = 0 ) {
234
-		$cats = new categories();	// uses current user and app (egw_info[flags][currentapp])
233
+	public static function cat_name2id($_cat_names, $parent = 0) {
234
+		$cats = new categories(); // uses current user and app (egw_info[flags][currentapp])
235 235
 
236
-		$cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names );
237
-		foreach ( $cat_names as $cat_name ) {
236
+		$cat_names = is_array($_cat_names) ? $_cat_names : explode(',', $_cat_names);
237
+		foreach ($cat_names as $cat_name) {
238 238
 			$cat_name = trim($cat_name);
239
-			if ( $cat_name == '' ) continue;
240
-			if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) {
241
-				$cat_id = $cats->add( array(
239
+			if ($cat_name == '') continue;
240
+			if (($cat_id = $cats->name2id($cat_name)) == 0 && !self::$dry_run) {
241
+				$cat_id = $cats->add(array(
242 242
 					'name' => $cat_name,
243 243
 					'parent' => $parent,
244 244
 					'access' => 'public',
245
-					'descr' => $cat_name. ' ('. lang('Automatically created by importexport'). ')'
245
+					'descr' => $cat_name.' ('.lang('Automatically created by importexport').')'
246 246
 				));
247 247
 			}
248 248
 			$cat_ids[] = $cat_id;
249 249
 		}
250
-		return is_array( $_cat_names ) ? $cat_ids : implode( ',', (array)$cat_ids );
250
+		return is_array($_cat_names) ? $cat_ids : implode(',', (array)$cat_ids);
251 251
 
252 252
 	} // end of member function category_name2id
253 253
 
@@ -286,76 +286,76 @@  discard block
 block discarded – undo
286 286
 	 * @param object &$cclass calling class to process the '@ evals'
287 287
 	 * @return bool
288 288
 	 */
289
-	public static function conversion( &$_record,  $_conversion, &$_cclass = null ) {
290
-		if (empty( $_conversion ) ) return $_record;
289
+	public static function conversion(&$_record, $_conversion, &$_cclass = null) {
290
+		if (empty($_conversion)) return $_record;
291 291
 
292
-		self::$cclass =& $_cclass;
292
+		self::$cclass = & $_cclass;
293 293
 
294 294
 		$PSep = '||'; // Pattern-Separator, separats the pattern-replacement-pairs in conversion
295 295
 		$ASep = '|>'; // Assignment-Separator, separats pattern and replacesment
296
-		$CPre = '|['; $CPos = ']';  // |[_record-idx] is expanded to the corespondig value
296
+		$CPre = '|['; $CPos = ']'; // |[_record-idx] is expanded to the corespondig value
297 297
 		$TPre = '|T{'; $TPos = '}'; // |{_record-idx} is trimmed
298
-		$CntlPre = '|TC{';		    // Filter all cntl-chars \x01-\x1f and trim
299
-		$CntlnCLPre  = '|TCnCL{';   // Like |C{ but allowes CR and LF
300
-		$INE = '|INE{';             // Only insert if stuff in ^^ is not empty
298
+		$CntlPre = '|TC{'; // Filter all cntl-chars \x01-\x1f and trim
299
+		$CntlnCLPre = '|TCnCL{'; // Like |C{ but allowes CR and LF
300
+		$INE = '|INE{'; // Only insert if stuff in ^^ is not empty
301 301
 
302
-		foreach ( $_conversion as $idx => $conversion_string ) {
303
-			if ( empty( $conversion_string ) ) continue;
302
+		foreach ($_conversion as $idx => $conversion_string) {
303
+			if (empty($conversion_string)) continue;
304 304
 
305 305
 			// fetch patterns ($rvalues)
306 306
 			$rvalues = array();
307
-			$pat_reps = explode( $PSep, stripslashes( $conversion_string ) );
308
-			foreach( $pat_reps as $k => $pat_rep ) {
309
-				list( $pattern, $replace ) = explode( $ASep, $pat_rep, 2 );
310
-				if( $replace == '' ) {
307
+			$pat_reps = explode($PSep, stripslashes($conversion_string));
308
+			foreach ($pat_reps as $k => $pat_rep) {
309
+				list($pattern, $replace) = explode($ASep, $pat_rep, 2);
310
+				if ($replace == '') {
311 311
 					$replace = $pattern; $pattern = '^.*$';
312 312
 				}
313
-				$rvalues[$pattern] = $replace;	// replace two with only one, added by the form
313
+				$rvalues[$pattern] = $replace; // replace two with only one, added by the form
314 314
 			}
315 315
 
316 316
 			// conversion list may be longer than $_record aka (no_csv)
317
-			$val = array_key_exists( $idx, $_record ) ? $_record[$idx] : '';
317
+			$val = array_key_exists($idx, $_record) ? $_record[$idx] : '';
318 318
 
319 319
 			$c_functions = array('cat', 'account', 'strtotime', 'list');
320
-			if($_cclass) {
320
+			if ($_cclass) {
321 321
 				// Add in additional methods
322 322
 				$reflection = new ReflectionClass(get_class($_cclass));
323 323
 				$methods = $reflection->getMethods(ReflectionMethod::IS_STATIC);
324
-				foreach($methods as $method) {
324
+				foreach ($methods as $method) {
325 325
 					$c_functions[] = $method->name;
326 326
 				}
327 327
 			}
328 328
 			$c_functions = implode('|', $c_functions);
329
-			foreach ( $rvalues as $pattern => $replace ) {
329
+			foreach ($rvalues as $pattern => $replace) {
330 330
 				// Allow to include record indexes in pattern
331 331
 				$reg = '/\|\[([0-9]+)\]/';
332
-				while( preg_match( $reg, $pattern, $vars ) ) {
332
+				while (preg_match($reg, $pattern, $vars)) {
333 333
 					// expand all _record fields
334 334
 					$pattern = str_replace(
335
-						$CPre . $vars[1] . $CPos,
335
+						$CPre.$vars[1].$CPos,
336 336
 						$_record[array_search($vars[1], array_keys($_record))],
337 337
 						$pattern
338 338
 					);
339 339
 				}
340
-				if( preg_match('/'. (string)$pattern.'/', $val) ) {
340
+				if (preg_match('/'.(string)$pattern.'/', $val)) {
341 341
 
342
-					$val = preg_replace( '/'.(string)$pattern.'/', $replace, (string)$val );
342
+					$val = preg_replace('/'.(string)$pattern.'/', $replace, (string)$val);
343 343
 
344 344
 					$reg = '/\|\[([a-zA-Z_0-9]+)\]/';
345
-					while( preg_match( $reg, $val, $vars ) ) {
345
+					while (preg_match($reg, $val, $vars)) {
346 346
 						// expand all _record fields
347 347
 						$val = str_replace(
348
-							$CPre . $vars[1] . $CPos,
348
+							$CPre.$vars[1].$CPos,
349 349
 							$_record[array_search($vars[1], array_keys($_record))],
350 350
 							$val
351 351
 						);
352 352
 					}
353
-					$val = preg_replace_callback( "/($c_functions)\(([^)]*)\)/i", array( self, 'c2_dispatcher') , $val );
353
+					$val = preg_replace_callback("/($c_functions)\(([^)]*)\)/i", array(self, 'c2_dispatcher'), $val);
354 354
 					break;
355 355
 				}
356 356
 			}
357 357
 			// clean each field
358
-			$val = preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{|\|INE\{)(.*)\}/", array( self, 'strclean'), $val );
358
+			$val = preg_replace_callback("/(\|T\{|\|TC\{|\|TCnCL\{|\|INE\{)(.*)\}/", array(self, 'strclean'), $val);
359 359
 
360 360
 			$_record[$idx] = $val;
361 361
 		}
@@ -369,42 +369,42 @@  discard block
 block discarded – undo
369 369
 	 *
370 370
 	 * @param array $_matches
371 371
 	 */
372
-	private static function c2_dispatcher( $_matches ) {
372
+	private static function c2_dispatcher($_matches) {
373 373
 		$action = &$_matches[1]; // cat or account ...
374
-		$data = &$_matches[2];   // datas for action
374
+		$data = &$_matches[2]; // datas for action
375 375
 
376
-		switch ( $action ) {
376
+		switch ($action) {
377 377
 			case 'strtotime' :
378
-				list( $string, $format ) = explode( ',', $data );
379
-				return self::custom_strtotime( trim( $string ), trim( $format ) );
378
+				list($string, $format) = explode(',', $data);
379
+				return self::custom_strtotime(trim($string), trim($format));
380 380
 			case 'list':
381
-				list( $split, $data, $index) = explode(',',$data);
381
+				list($split, $data, $index) = explode(',', $data);
382 382
 				$exploded = explode($split, $data);
383 383
 				// 1 based indexing for user ease
384 384
 				return $exploded[$index - 1];
385 385
 			default :
386
-				if(self::$cclass && method_exists(self::$cclass, $action)) {
386
+				if (self::$cclass && method_exists(self::$cclass, $action)) {
387 387
 					$class = get_class(self::$cclass);
388 388
 					return call_user_func("$class::$action", $data);
389 389
 				}
390
-				$method = (string)$action. ( is_int( $data ) ? '_id2name' : '_name2id' );
391
-				if(self::$cclass && method_exists(self::$cclass, $method)) {
390
+				$method = (string)$action.(is_int($data) ? '_id2name' : '_name2id');
391
+				if (self::$cclass && method_exists(self::$cclass, $method)) {
392 392
 					$class = get_class(self::$cclass);
393 393
 					return call_user_func("$class::$action", $data);
394 394
 				} else {
395
-					return self::$method( $data );
395
+					return self::$method($data);
396 396
 				}
397 397
 		}
398 398
 	}
399 399
 
400
-	private static function strclean( $_matches ) {
401
-		switch( $_matches[1] ) {
402
-			case '|T{' : return trim( $_matches[2] );
403
-			case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) );
404
-			case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) );
405
-			case '|INE{' : return preg_match( '/\^.+\^/', $_matches[2] ) ? $_matches[2] : '';
400
+	private static function strclean($_matches) {
401
+		switch ($_matches[1]) {
402
+			case '|T{' : return trim($_matches[2]);
403
+			case '|TC{' : return trim(preg_replace('/[\x01-\x1F]+/', '', $_matches[2]));
404
+			case '|TCnCL{' : return trim(preg_replace('/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2]));
405
+			case '|INE{' : return preg_match('/\^.+\^/', $_matches[2]) ? $_matches[2] : '';
406 406
 			default:
407
-				throw new Exception('Error in conversion string! "'. substr( $_matches[1], 0, -1 ). '" is not valid!');
407
+				throw new Exception('Error in conversion string! "'.substr($_matches[1], 0, -1).'" is not valid!');
408 408
 		}
409 409
 	}
410 410
 
@@ -415,23 +415,23 @@  discard block
 block discarded – undo
415 415
 	 * @param string $_appname {<appname> | all}
416 416
 	 * @return array(<appname> => array( <type> => array(<plugin> => <title>)))
417 417
 	 */
418
-	public static function get_plugins( $_appname = 'all', $_type = 'all' ) {
418
+	public static function get_plugins($_appname = 'all', $_type = 'all') {
419 419
 		$plugins = egw_cache::getTree(
420 420
 			__CLASS__,
421 421
 			'plugins',
422
-			array('importexport_helper_functions','_get_plugins'),
422
+			array('importexport_helper_functions', '_get_plugins'),
423 423
 			array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')),
424 424
 			self::CACHE_EXPIRATION
425 425
 		);
426 426
 		$appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname;
427
-		$types = $_type == 'all' ? array('import','export') : (array)$_type;
427
+		$types = $_type == 'all' ? array('import', 'export') : (array)$_type;
428 428
 
429 429
 		// Testing: comment out egw_cache call, use this
430 430
 		//$plugins = self::_get_plugins($appnames, $types);
431
-		foreach($plugins as $appname => $_types) {
432
-			if(!in_array($appname, $appnames)) unset($plugins[$appname]);
431
+		foreach ($plugins as $appname => $_types) {
432
+			if (!in_array($appname, $appnames)) unset($plugins[$appname]);
433 433
 		}
434
-		foreach($plugins as $appname => $types) {
434
+		foreach ($plugins as $appname => $types) {
435 435
 			$plugins[$appname] = array_intersect_key($plugins[$appname], $types);
436 436
 		}
437 437
 		return $plugins;
@@ -440,25 +440,25 @@  discard block
 block discarded – undo
440 440
 	public static function _get_plugins(Array $appnames, Array $types) {
441 441
 		$plugins = array();
442 442
 		foreach ($appnames as $appname) {
443
-			if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue;
443
+			if (array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue;
444 444
 
445
-			$appdir = EGW_INCLUDE_ROOT. "/$appname/inc";
446
-			if(!is_dir($appdir)) continue;
445
+			$appdir = EGW_INCLUDE_ROOT."/$appname/inc";
446
+			if (!is_dir($appdir)) continue;
447 447
 			$d = dir($appdir);
448 448
 
449 449
 			// step through each file in appdir
450 450
 			while (false !== ($entry = $d->read())) {
451 451
 				// Blacklisted?
452
-				if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname]))  continue;
452
+				if (is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname]))  continue;
453 453
 				if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) continue;
454 454
 				$classname = $matches[1];
455
-				$file = $appdir. '/'. $entry;
455
+				$file = $appdir.'/'.$entry;
456 456
 
457 457
 				foreach ($types as $type) {
458
-					if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) continue;
458
+					if (!is_file($file) || strpos($entry, $type) === false || strpos($entry, 'wizard') !== false) continue;
459 459
 					require_once($file);
460 460
 					$reflectionClass = new ReflectionClass($classname);
461
-					if($reflectionClass->IsInstantiable() &&
461
+					if ($reflectionClass->IsInstantiable() &&
462 462
 							$reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) {
463 463
 						try {
464 464
 							$plugin_object = new $classname;
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 			$d->close();
475 475
 
476 476
 			$config = config::read('importexport');
477
-			if($config['update'] == 'auto') {
477
+			if ($config['update'] == 'auto') {
478 478
 				self::load_defaults($appname);
479 479
 			}
480 480
 		}
@@ -489,37 +489,37 @@  discard block
 block discarded – undo
489 489
 	 * @return array $num => $appname
490 490
 	 */
491 491
 	public static function get_apps($_type, $ignore_acl = false) {
492
-		$apps = array_keys(self::get_plugins('all',$_type));
493
-		if($ignore_acl) return $apps;
492
+		$apps = array_keys(self::get_plugins('all', $_type));
493
+		if ($ignore_acl) return $apps;
494 494
 
495
-		foreach($apps as $key => $app) {
496
-			if(!self::has_definitions($app, $_type)) unset($apps[$key]);
495
+		foreach ($apps as $key => $app) {
496
+			if (!self::has_definitions($app, $_type)) unset($apps[$key]);
497 497
 		}
498 498
 		return $apps;
499 499
 	}
500 500
 
501 501
 	public static function load_defaults($appname) {
502 502
 		// Check for new definitions to import from $appname/setup/*.xml
503
-		$appdir = EGW_INCLUDE_ROOT. "/$appname/setup";
504
-		if(!is_dir($appdir)) return;
503
+		$appdir = EGW_INCLUDE_ROOT."/$appname/setup";
504
+		if (!is_dir($appdir)) return;
505 505
 		$d = dir($appdir);
506 506
 
507 507
 		// step through each file in app's setup
508 508
 		while (false !== ($entry = $d->read())) {
509
-			$file = $appdir. '/'. $entry;
510
-			list( $filename, $extension) = explode('.',$entry);
511
-			if ( $extension != 'xml' ) continue;
509
+			$file = $appdir.'/'.$entry;
510
+			list($filename, $extension) = explode('.', $entry);
511
+			if ($extension != 'xml') continue;
512 512
 			try {
513 513
 				// import will skip invalid files
514
-				importexport_definitions_bo::import( $file );
514
+				importexport_definitions_bo::import($file);
515 515
 			} catch (Exception $e) {
516
-				error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage());
516
+				error_log(__CLASS__.__FUNCTION__." import $appname definitions: ".$e->getMessage());
517 517
 			}
518 518
 		}
519 519
 		$d->close();
520 520
 	}
521 521
 
522
-	public static function guess_filetype( $_file ) {
522
+	public static function guess_filetype($_file) {
523 523
 
524 524
 	}
525 525
 
@@ -530,24 +530,24 @@  discard block
 block discarded – undo
530 530
 	 * @param string $_type {import | export | all}
531 531
 	 * @return boolean
532 532
 	 */
533
-	public static function has_definitions( $_appname = 'all', $_type = 'all' ) {
533
+	public static function has_definitions($_appname = 'all', $_type = 'all') {
534 534
 		$definitions = egw_cache::getSession(
535 535
 			__CLASS__,
536 536
 			'has_definitions',
537
-			array('importexport_helper_functions','_has_definitions'),
537
+			array('importexport_helper_functions', '_has_definitions'),
538 538
 			array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')),
539 539
 			self::CACHE_EXPIRATION
540 540
 		);
541 541
 		$appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname;
542
-		$types = $_type == 'all' ? array('import','export') : (array)$_type;
542
+		$types = $_type == 'all' ? array('import', 'export') : (array)$_type;
543 543
 
544 544
 		// Testing: Comment out cache call above, use this
545 545
 		//$definitions = self::_has_definitions($appnames, $types);
546 546
 
547
-		foreach($definitions as $appname => $_types) {
548
-			if(!in_array($appname, $appnames)) unset($definitions[$appname]);
547
+		foreach ($definitions as $appname => $_types) {
548
+			if (!in_array($appname, $appnames)) unset($definitions[$appname]);
549 549
 		}
550
-		foreach($definitions as $appname => $_types) {
550
+		foreach ($definitions as $appname => $_types) {
551 551
 			$definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types));
552 552
 		}
553 553
 		return count($definitions[$appname]) > 0;
@@ -557,11 +557,11 @@  discard block
 block discarded – undo
557 557
 	public static function _has_definitions(Array $appnames, Array $types) {
558 558
 		$def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types));
559 559
 		$list = array();
560
-		foreach((array)$def->get_definitions() as $id) {
560
+		foreach ((array)$def->get_definitions() as $id) {
561 561
 			// Need to instanciate it to check, but if the user doesn't have permission, it throws an exception
562 562
 			try {
563 563
 				$definition = new importexport_definition($id);
564
-				if($def->is_permitted($definition->get_record_array())) {
564
+				if ($def->is_permitted($definition->get_record_array())) {
565 565
 					$list[$definition->application][$definition->type][] = $id;
566 566
 				}
567 567
 			} catch (Exception $e) {
@@ -590,16 +590,16 @@  discard block
 block discarded – undo
590 590
 	{
591 591
 		$fields = array();
592 592
 		try {
593
-			if($record_classname == null) $record_classname = $app_name . '_egw_record';
594
-			if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname);
593
+			if ($record_classname == null) $record_classname = $app_name.'_egw_record';
594
+			if (!class_exists($record_classname)) throw new Exception('Bad class name '.$record_classname);
595 595
 
596 596
 			$plugin = is_object($plugin_name) ? $plugin_name : new $plugin_name();
597 597
 			$plugin_name = get_class($plugin);
598 598
 
599
-			if(!$wizard_plugin)
599
+			if (!$wizard_plugin)
600 600
 			{
601
-				$wizard_name = $app_name . '_wizard_' . str_replace($app_name . '_', '', $plugin_name);
602
-				if(!class_exists($wizard_name)) throw new Exception('Bad wizard name ' . $wizard_name);
601
+				$wizard_name = $app_name.'_wizard_'.str_replace($app_name.'_', '', $plugin_name);
602
+				if (!class_exists($wizard_name)) throw new Exception('Bad wizard name '.$wizard_name);
603 603
 				$wizard_plugin = new $wizard_name;
604 604
 			}
605 605
 		}
@@ -611,16 +611,16 @@  discard block
 block discarded – undo
611 611
 
612 612
 		// Get field -> label map and initialize fields using wizard field order
613 613
 		$fields = $export_fields = array();
614
-		if(method_exists($wizard_plugin, 'get_export_fields'))
614
+		if (method_exists($wizard_plugin, 'get_export_fields'))
615 615
 		{
616 616
 			$fields = $export_fields = $wizard_plugin->get_export_fields();
617 617
 		}
618 618
 
619
-		foreach($record_classname::$types as $type => $type_fields)
619
+		foreach ($record_classname::$types as $type => $type_fields)
620 620
 		{
621 621
 			// Only these for now, until filter methods for others are figured out
622
-			if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) continue;
623
-			foreach($type_fields as $field_name)
622
+			if (!in_array($type, array('select', 'select-cat', 'select-account', 'date', 'date-time'))) continue;
623
+			foreach ($type_fields as $field_name)
624 624
 			{
625 625
 				$fields[$field_name] = array(
626 626
 					'name' => $field_name,
@@ -631,21 +631,21 @@  discard block
 block discarded – undo
631 631
 		}
632 632
 		// Add custom fields
633 633
 		$custom = config::get_customfields($app_name);
634
-		foreach($custom as $field_name => $settings)
634
+		foreach ($custom as $field_name => $settings)
635 635
 		{
636 636
 			$settings['name'] = '#'.$field_name;
637 637
 			$fields['#'.$field_name] = $settings;
638 638
 		}
639 639
 
640
-		foreach($fields as $field_name => &$settings) {
640
+		foreach ($fields as $field_name => &$settings) {
641 641
 			// Can't really filter on these (or at least no generic, sane way figured out yet)
642
-			if(!is_array($settings) || in_array($settings['type'], array('text','button', 'label','url','url-email','url-phone','htmlarea')))
642
+			if (!is_array($settings) || in_array($settings['type'], array('text', 'button', 'label', 'url', 'url-email', 'url-phone', 'htmlarea')))
643 643
 			{
644 644
 				unset($fields[$field_name]);
645 645
 				continue;
646 646
 			}
647
-			if($settings['type'] == 'radio') $settings['type'] = 'select';
648
-			switch($settings['type'])
647
+			if ($settings['type'] == 'radio') $settings['type'] = 'select';
648
+			switch ($settings['type'])
649 649
 			{
650 650
 				case 'checkbox':
651 651
 					// This isn't quite right - there's only 2 options and you can select both
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
 			}
669 669
 		}
670 670
 
671
-		if(method_exists($plugin, 'get_filter_fields'))
671
+		if (method_exists($plugin, 'get_filter_fields'))
672 672
 		{
673 673
 			$plugin->get_filter_fields($fields);
674 674
 		}
@@ -684,65 +684,65 @@  discard block
 block discarded – undo
684 684
 	 */
685 685
 	public static function date_rel2abs($value)
686 686
 	{
687
-		if(is_array($value))
687
+		if (is_array($value))
688 688
 		{
689 689
 			$abs = array();
690
-			foreach($value as $key => $val)
690
+			foreach ($value as $key => $val)
691 691
 			{
692 692
 				$abs[$key] = self::date_rel2abs($val);
693 693
 			}
694 694
 			return $abs;
695 695
 		}
696
-		if($date = self::$relative_dates[$value])
696
+		if ($date = self::$relative_dates[$value])
697 697
 		{
698
-			$year  = (int) date('Y');
699
-			$month = (int) date('m');
700
-			$day   = (int) date('d');
701
-			$today = mktime(0,0,0,date('m'),date('d'),date('Y'));
698
+			$year  = (int)date('Y');
699
+			$month = (int)date('m');
700
+			$day   = (int)date('d');
701
+			$today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
702 702
 
703
-			list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) = $date;
703
+			list($syear, $smonth, $sday, $sweek, $eyear, $emonth, $eday, $eweek) = $date;
704 704
 
705
-			if(stripos($value, 'quarter') !== false)
705
+			if (stripos($value, 'quarter') !== false)
706 706
 			{
707 707
 				// Handle quarters
708
-				$start = mktime(0,0,0,((int)floor(($smonth+$month) / 3.1)) * 3 + 1, 1, $year);
709
-				$end = mktime(0,0,0,((int)floor(($emonth+$month) / 3.1)+1) * 3 + 1, 1, $year);
708
+				$start = mktime(0, 0, 0, ((int)floor(($smonth + $month) / 3.1)) * 3 + 1, 1, $year);
709
+				$end = mktime(0, 0, 0, ((int)floor(($emonth + $month) / 3.1) + 1) * 3 + 1, 1, $year);
710 710
 			}
711 711
 			elseif ($syear || $eyear)
712 712
 			{
713
-				$start = mktime(0,0,0,1,1,$syear+$year);
714
-				$end   = mktime(0,0,0,1,1,$eyear+$year);
713
+				$start = mktime(0, 0, 0, 1, 1, $syear + $year);
714
+				$end   = mktime(0, 0, 0, 1, 1, $eyear + $year);
715 715
 			}
716 716
 			elseif ($smonth || $emonth)
717 717
 			{
718
-				$start = mktime(0,0,0,$smonth+$month,1,$year);
719
-				$end   = mktime(0,0,0,$emonth+$month,1,$year);
718
+				$start = mktime(0, 0, 0, $smonth + $month, 1, $year);
719
+				$end   = mktime(0, 0, 0, $emonth + $month, 1, $year);
720 720
 			}
721 721
 			elseif ($sday || $eday)
722 722
 			{
723
-				$start = mktime(0,0,0,$month,$sday+$day,$year);
724
-				$end   = mktime(0,0,0,$month,$eday+$day,$year);
723
+				$start = mktime(0, 0, 0, $month, $sday + $day, $year);
724
+				$end   = mktime(0, 0, 0, $month, $eday + $day, $year);
725 725
 			}
726 726
 			elseif ($sweek || $eweek)
727 727
 			{
728
-				$wday = (int) date('w'); // 0=sun, ..., 6=sat
729
-				switch($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'])
728
+				$wday = (int)date('w'); // 0=sun, ..., 6=sat
729
+				switch ($GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'])
730 730
 				{
731 731
 					case 'Sunday':
732
-						$weekstart = $today - $wday * 24*60*60;
732
+						$weekstart = $today - $wday * 24 * 60 * 60;
733 733
 						break;
734 734
 					case 'Saturday':
735
-						$weekstart = $today - (6-$wday) * 24*60*60;
735
+						$weekstart = $today - (6 - $wday) * 24 * 60 * 60;
736 736
 						break;
737 737
 					case 'Moday':
738 738
 					default:
739
-						$weekstart = $today - ($wday ? $wday-1 : 6) * 24*60*60;
739
+						$weekstart = $today - ($wday ? $wday - 1 : 6) * 24 * 60 * 60;
740 740
 						break;
741 741
 				}
742
-				$start = $weekstart + $sweek*7*24*60*60;
743
-				$end   = $weekstart + $eweek*7*24*60*60;
742
+				$start = $weekstart + $sweek * 7 * 24 * 60 * 60;
743
+				$end   = $weekstart + $eweek * 7 * 24 * 60 * 60;
744 744
 			}
745
-			$end_param = $end - 24*60*60;
745
+			$end_param = $end - 24 * 60 * 60;
746 746
 		
747 747
 			// Take 1 second off end to provide an inclusive range.for filtering
748 748
 			$end -= 1;
Please login to merge, or discard this patch.
Braces   +210 added lines, -83 removed lines patch added patch discarded remove patch
@@ -14,7 +14,8 @@  discard block
 block discarded – undo
14 14
  * class importexport_helper_functions (only static methods)
15 15
  * use importexport_helper_functions::method
16 16
  */
17
-class importexport_helper_functions {
17
+class importexport_helper_functions
18
+{
18 19
 
19 20
 	/**
20 21
 	 * Plugins are scanned and cached for all instances using this source path for given time (in seconds)
@@ -77,13 +78,19 @@  discard block
 block discarded – undo
77 78
 	 * @param string $_format format of time string e.g.: d.m.Y H:i
78 79
 	 * @param int $_is_dst is day light saving time? 0 = no, 1 = yes, -1 = system default
79 80
 	 */
80
-	public static function custom_strtotime( $_string, $_format='', $_is_dst = -1) {
81
-		if ( empty( $_format ) ) return strtotime( $_string );
81
+	public static function custom_strtotime( $_string, $_format='', $_is_dst = -1)
82
+	{
83
+		if ( empty( $_format ) )
84
+		{
85
+			return strtotime( $_string );
86
+		}
82 87
 		$fparams = explode( ',', chunk_split( $_format, 1, ',' ) );
83 88
 		$spos = 0;
84
-		foreach ( $fparams as $fparam ) {
89
+		foreach ( $fparams as $fparam )
90
+		{
85 91
 
86
-			switch ( $fparam ) {
92
+			switch ( $fparam )
93
+			{
87 94
 				case 'd': (int)$day = substr( $_string, $spos, 2 ); $spos += 2; break;
88 95
 				case 'm': (int)$mon = substr( $_string, $spos, 2 ); $spos += 2; break;
89 96
 				case 'y': (int)$year = substr( $_string, $spos, 2 ); $spos += 2; break;
@@ -103,12 +110,18 @@  discard block
 block discarded – undo
103 110
 		$timestamp = mktime($hour, $min, $sec, $mon, $day, $year, $_is_dst);
104 111
 
105 112
 		// offset given?
106
-		if ( isset( $offset ) && strlen( $offset == 5 ) ) {
113
+		if ( isset( $offset ) && strlen( $offset == 5 ) )
114
+		{
107 115
 			$operator = $offset{0};
108 116
 			$ohour = 60 * 60 * (int)substr( $offset, 1, 2 );
109 117
 			$omin = 60 * (int)substr( $offset, 3, 2 );
110
-			if ( $operator == '+' ) $timestamp += $ohour + $omin;
111
-			else $timestamp -= $ohour + $omin;
118
+			if ( $operator == '+' )
119
+			{
120
+				$timestamp += $ohour + $omin;
121
+			}
122
+			else {
123
+				$timestamp -= $ohour + $omin;
124
+			}
112 125
 		}
113 126
 		return $timestamp;
114 127
 	}
@@ -118,11 +131,14 @@  discard block
 block discarded – undo
118 131
 	 * @param mixed $_account_lid comma seperated list or array with lids
119 132
 	 * @return mixed comma seperated list or array with ids
120 133
 	 */
121
-	public static function account_name2id( &$_account_lids ) {
134
+	public static function account_name2id( &$_account_lids )
135
+	{
122 136
 		$account_lids = is_array( $_account_lids ) ? $_account_lids : explode( ',', $_account_lids );
123 137
 		$skip = false;
124
-		foreach ( $account_lids as $key => $account_lid ) {
125
-			if($skip) {
138
+		foreach ( $account_lids as $key => $account_lid )
139
+		{
140
+			if($skip)
141
+			{
126 142
 				unset($account_lids[$key]);
127 143
 				$skip = false;
128 144
 				continue;
@@ -130,7 +146,8 @@  discard block
 block discarded – undo
130 146
 			$account_lid = trim($account_lid);
131 147
 
132 148
 			// Handle any IDs that slip in
133
-			if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid)) {
149
+			if(is_numeric($account_lid) && $GLOBALS['egw']->accounts->id2name($account_lid))
150
+			{
134 151
 				unset($account_lids[$key]);
135 152
 				$account_ids[] = (int)$account_lid;
136 153
 				continue;
@@ -149,7 +166,8 @@  discard block
 block discarded – undo
149 166
 
150 167
 			// Handle users listed as Lastname, Firstname instead of login ID
151 168
 			// Do this first, in case their first name matches a username
152
-			if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname')) {
169
+			if ( $account_lids[$key+1][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lids[$key+1]).' ' .$account_lid, 'account_fullname'))
170
+			{
153 171
 				$account_ids[] = $account_id;
154 172
 				unset($account_lids[$key]);
155 173
 				$skip = true; // Skip the next one, it's the first name
@@ -162,19 +180,22 @@  discard block
 block discarded – undo
162 180
 				$account_lid = trim(substr(trim($account_lid), 0, -strlen(lang('Group'))));
163 181
 			}
164 182
 
165
-			if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid )) {
183
+			if ( $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid ))
184
+			{
166 185
 				$account_ids[] = $account_id;
167 186
 				unset($account_lids[$key]);
168 187
 				continue;
169 188
 			}
170
-			if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' )) {
189
+			if ( $account_id = $GLOBALS['egw']->accounts->name2id( trim($account_lid), 'account_fullname' ))
190
+			{
171 191
 				$account_ids[] = $account_id;
172 192
 				unset($account_lids[$key]);
173 193
 				continue;
174 194
 			}
175 195
 
176 196
 			// Handle groups listed as Group, <name>
177
-			if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid)) {
197
+			if ( $account_lids[$key][0] == ' ' && $account_id = $GLOBALS['egw']->accounts->name2id( $account_lid))
198
+			{
178 199
 				$account_ids[] = $account_id;
179 200
 				unset($account_lids[$key-1]);
180 201
 				unset($account_lids[$key]);
@@ -198,10 +219,13 @@  discard block
 block discarded – undo
198 219
 	 * @param mixed $_account_ids comma seperated list or array with ids
199 220
 	 * @return mixed comma seperated list or array with lids
200 221
 	 */
201
-	public static function account_id2name( $_account_id ) {
222
+	public static function account_id2name( $_account_id )
223
+	{
202 224
 		$account_ids = is_array( $_account_id ) ? $_account_id : explode( ',', $_account_id );
203
-		foreach ( $account_ids as $account_id ) {
204
-			if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id )) {
225
+		foreach ( $account_ids as $account_id )
226
+		{
227
+			if ( $account_lid = $GLOBALS['egw']->accounts->id2name( $account_id ))
228
+			{
205 229
 				$account_lids[] = $account_lid;
206 230
 			}
207 231
 		}
@@ -214,9 +238,11 @@  discard block
 block discarded – undo
214 238
 	 * @param mixed _cat_ids comma seperated list or array
215 239
 	 * @return mixed comma seperated list or array with cat_names
216 240
 	 */
217
-	public static function cat_id2name( $_cat_ids ) {
241
+	public static function cat_id2name( $_cat_ids )
242
+	{
218 243
 		$cat_ids = is_array( $_cat_ids ) ? $_cat_ids : explode( ',', $_cat_ids );
219
-		foreach ( $cat_ids as $cat_id ) {
244
+		foreach ( $cat_ids as $cat_id )
245
+		{
220 246
 			$cat_names[] = categories::id2name( (int)$cat_id );
221 247
 		}
222 248
 		return is_array( $_cat_ids ) ? $cat_names : implode(',',(array)$cat_names);
@@ -230,14 +256,20 @@  discard block
 block discarded – undo
230 256
 	 * @param int $parent Optional parent ID to use for new categories
231 257
 	 * @return mixed comma seperated list or array with cat_ids
232 258
 	 */
233
-	public static function cat_name2id( $_cat_names, $parent = 0 ) {
259
+	public static function cat_name2id( $_cat_names, $parent = 0 )
260
+	{
234 261
 		$cats = new categories();	// uses current user and app (egw_info[flags][currentapp])
235 262
 
236 263
 		$cat_names = is_array( $_cat_names ) ? $_cat_names : explode( ',', $_cat_names );
237
-		foreach ( $cat_names as $cat_name ) {
264
+		foreach ( $cat_names as $cat_name )
265
+		{
238 266
 			$cat_name = trim($cat_name);
239
-			if ( $cat_name == '' ) continue;
240
-			if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run) {
267
+			if ( $cat_name == '' )
268
+			{
269
+				continue;
270
+			}
271
+			if ( ( $cat_id = $cats->name2id( $cat_name ) ) == 0 && !self::$dry_run)
272
+			{
241 273
 				$cat_id = $cats->add( array(
242 274
 					'name' => $cat_name,
243 275
 					'parent' => $parent,
@@ -286,8 +318,12 @@  discard block
 block discarded – undo
286 318
 	 * @param object &$cclass calling class to process the '@ evals'
287 319
 	 * @return bool
288 320
 	 */
289
-	public static function conversion( &$_record,  $_conversion, &$_cclass = null ) {
290
-		if (empty( $_conversion ) ) return $_record;
321
+	public static function conversion( &$_record,  $_conversion, &$_cclass = null )
322
+	{
323
+		if (empty( $_conversion ) )
324
+		{
325
+			return $_record;
326
+		}
291 327
 
292 328
 		self::$cclass =& $_cclass;
293 329
 
@@ -299,15 +335,21 @@  discard block
 block discarded – undo
299 335
 		$CntlnCLPre  = '|TCnCL{';   // Like |C{ but allowes CR and LF
300 336
 		$INE = '|INE{';             // Only insert if stuff in ^^ is not empty
301 337
 
302
-		foreach ( $_conversion as $idx => $conversion_string ) {
303
-			if ( empty( $conversion_string ) ) continue;
338
+		foreach ( $_conversion as $idx => $conversion_string )
339
+		{
340
+			if ( empty( $conversion_string ) )
341
+			{
342
+				continue;
343
+			}
304 344
 
305 345
 			// fetch patterns ($rvalues)
306 346
 			$rvalues = array();
307 347
 			$pat_reps = explode( $PSep, stripslashes( $conversion_string ) );
308
-			foreach( $pat_reps as $k => $pat_rep ) {
348
+			foreach( $pat_reps as $k => $pat_rep )
349
+			{
309 350
 				list( $pattern, $replace ) = explode( $ASep, $pat_rep, 2 );
310
-				if( $replace == '' ) {
351
+				if( $replace == '' )
352
+				{
311 353
 					$replace = $pattern; $pattern = '^.*$';
312 354
 				}
313 355
 				$rvalues[$pattern] = $replace;	// replace two with only one, added by the form
@@ -317,19 +359,23 @@  discard block
 block discarded – undo
317 359
 			$val = array_key_exists( $idx, $_record ) ? $_record[$idx] : '';
318 360
 
319 361
 			$c_functions = array('cat', 'account', 'strtotime', 'list');
320
-			if($_cclass) {
362
+			if($_cclass)
363
+			{
321 364
 				// Add in additional methods
322 365
 				$reflection = new ReflectionClass(get_class($_cclass));
323 366
 				$methods = $reflection->getMethods(ReflectionMethod::IS_STATIC);
324
-				foreach($methods as $method) {
367
+				foreach($methods as $method)
368
+				{
325 369
 					$c_functions[] = $method->name;
326 370
 				}
327 371
 			}
328 372
 			$c_functions = implode('|', $c_functions);
329
-			foreach ( $rvalues as $pattern => $replace ) {
373
+			foreach ( $rvalues as $pattern => $replace )
374
+			{
330 375
 				// Allow to include record indexes in pattern
331 376
 				$reg = '/\|\[([0-9]+)\]/';
332
-				while( preg_match( $reg, $pattern, $vars ) ) {
377
+				while( preg_match( $reg, $pattern, $vars ) )
378
+				{
333 379
 					// expand all _record fields
334 380
 					$pattern = str_replace(
335 381
 						$CPre . $vars[1] . $CPos,
@@ -337,12 +383,14 @@  discard block
 block discarded – undo
337 383
 						$pattern
338 384
 					);
339 385
 				}
340
-				if( preg_match('/'. (string)$pattern.'/', $val) ) {
386
+				if( preg_match('/'. (string)$pattern.'/', $val) )
387
+				{
341 388
 
342 389
 					$val = preg_replace( '/'.(string)$pattern.'/', $replace, (string)$val );
343 390
 
344 391
 					$reg = '/\|\[([a-zA-Z_0-9]+)\]/';
345
-					while( preg_match( $reg, $val, $vars ) ) {
392
+					while( preg_match( $reg, $val, $vars ) )
393
+					{
346 394
 						// expand all _record fields
347 395
 						$val = str_replace(
348 396
 							$CPre . $vars[1] . $CPos,
@@ -369,11 +417,13 @@  discard block
 block discarded – undo
369 417
 	 *
370 418
 	 * @param array $_matches
371 419
 	 */
372
-	private static function c2_dispatcher( $_matches ) {
420
+	private static function c2_dispatcher( $_matches )
421
+	{
373 422
 		$action = &$_matches[1]; // cat or account ...
374 423
 		$data = &$_matches[2];   // datas for action
375 424
 
376
-		switch ( $action ) {
425
+		switch ( $action )
426
+		{
377 427
 			case 'strtotime' :
378 428
 				list( $string, $format ) = explode( ',', $data );
379 429
 				return self::custom_strtotime( trim( $string ), trim( $format ) );
@@ -383,22 +433,28 @@  discard block
 block discarded – undo
383 433
 				// 1 based indexing for user ease
384 434
 				return $exploded[$index - 1];
385 435
 			default :
386
-				if(self::$cclass && method_exists(self::$cclass, $action)) {
436
+				if(self::$cclass && method_exists(self::$cclass, $action))
437
+				{
387 438
 					$class = get_class(self::$cclass);
388 439
 					return call_user_func("$class::$action", $data);
389 440
 				}
390 441
 				$method = (string)$action. ( is_int( $data ) ? '_id2name' : '_name2id' );
391
-				if(self::$cclass && method_exists(self::$cclass, $method)) {
442
+				if(self::$cclass && method_exists(self::$cclass, $method))
443
+				{
392 444
 					$class = get_class(self::$cclass);
393 445
 					return call_user_func("$class::$action", $data);
394
-				} else {
446
+				}
447
+				else
448
+				{
395 449
 					return self::$method( $data );
396 450
 				}
397 451
 		}
398 452
 	}
399 453
 
400
-	private static function strclean( $_matches ) {
401
-		switch( $_matches[1] ) {
454
+	private static function strclean( $_matches )
455
+	{
456
+		switch( $_matches[1] )
457
+		{
402 458
 			case '|T{' : return trim( $_matches[2] );
403 459
 			case '|TC{' : return trim( preg_replace( '/[\x01-\x1F]+/', '', $_matches[2] ) );
404 460
 			case '|TCnCL{' : return trim( preg_replace( '/[\x01-\x09\x11\x12\x14-\x1F]+/', '', $_matches[2] ) );
@@ -415,7 +471,8 @@  discard block
 block discarded – undo
415 471
 	 * @param string $_appname {<appname> | all}
416 472
 	 * @return array(<appname> => array( <type> => array(<plugin> => <title>)))
417 473
 	 */
418
-	public static function get_plugins( $_appname = 'all', $_type = 'all' ) {
474
+	public static function get_plugins( $_appname = 'all', $_type = 'all' )
475
+	{
419 476
 		$plugins = egw_cache::getTree(
420 477
 			__CLASS__,
421 478
 			'plugins',
@@ -428,38 +485,63 @@  discard block
 block discarded – undo
428 485
 
429 486
 		// Testing: comment out egw_cache call, use this
430 487
 		//$plugins = self::_get_plugins($appnames, $types);
431
-		foreach($plugins as $appname => $_types) {
432
-			if(!in_array($appname, $appnames)) unset($plugins[$appname]);
488
+		foreach($plugins as $appname => $_types)
489
+		{
490
+			if(!in_array($appname, $appnames))
491
+			{
492
+				unset($plugins[$appname]);
493
+			}
433 494
 		}
434
-		foreach($plugins as $appname => $types) {
495
+		foreach($plugins as $appname => $types)
496
+		{
435 497
 			$plugins[$appname] = array_intersect_key($plugins[$appname], $types);
436 498
 		}
437 499
 		return $plugins;
438 500
 	}
439 501
 
440
-	public static function _get_plugins(Array $appnames, Array $types) {
502
+	public static function _get_plugins(Array $appnames, Array $types)
503
+	{
441 504
 		$plugins = array();
442
-		foreach ($appnames as $appname) {
443
-			if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true) continue;
505
+		foreach ($appnames as $appname)
506
+		{
507
+			if(array_key_exists($appname, self::$blacklist_files) && self::$blacklist_files[$appname] === true)
508
+			{
509
+				continue;
510
+			}
444 511
 
445 512
 			$appdir = EGW_INCLUDE_ROOT. "/$appname/inc";
446
-			if(!is_dir($appdir)) continue;
513
+			if(!is_dir($appdir))
514
+			{
515
+				continue;
516
+			}
447 517
 			$d = dir($appdir);
448 518
 
449 519
 			// step through each file in appdir
450
-			while (false !== ($entry = $d->read())) {
520
+			while (false !== ($entry = $d->read()))
521
+			{
451 522
 				// Blacklisted?
452
-				if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname]))  continue;
453
-				if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches)) continue;
523
+				if(is_array(self::$blacklist_files[$appname]) && in_array($entry, self::$blacklist_files[$appname]))
524
+				{
525
+					continue;
526
+				}
527
+				if (!preg_match('/^class\.([^.]+)\.inc\.php$/', $entry, $matches))
528
+				{
529
+					continue;
530
+				}
454 531
 				$classname = $matches[1];
455 532
 				$file = $appdir. '/'. $entry;
456 533
 
457
-				foreach ($types as $type) {
458
-					if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false) continue;
534
+				foreach ($types as $type)
535
+				{
536
+					if( !is_file($file) || strpos($entry, $type) === false || strpos($entry,'wizard') !== false)
537
+					{
538
+						continue;
539
+					}
459 540
 					require_once($file);
460 541
 					$reflectionClass = new ReflectionClass($classname);
461 542
 					if($reflectionClass->IsInstantiable() &&
462
-							$reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin')) {
543
+							$reflectionClass->implementsInterface('importexport_iface_'.$type.'_plugin'))
544
+					{
463 545
 						try {
464 546
 							$plugin_object = new $classname;
465 547
 						}
@@ -474,7 +556,8 @@  discard block
 block discarded – undo
474 556
 			$d->close();
475 557
 
476 558
 			$config = config::read('importexport');
477
-			if($config['update'] == 'auto') {
559
+			if($config['update'] == 'auto')
560
+			{
478 561
 				self::load_defaults($appname);
479 562
 			}
480 563
 		}
@@ -488,38 +571,56 @@  discard block
 block discarded – undo
488 571
 	 * @param string $_type
489 572
 	 * @return array $num => $appname
490 573
 	 */
491
-	public static function get_apps($_type, $ignore_acl = false) {
574
+	public static function get_apps($_type, $ignore_acl = false)
575
+	{
492 576
 		$apps = array_keys(self::get_plugins('all',$_type));
493
-		if($ignore_acl) return $apps;
577
+		if($ignore_acl)
578
+		{
579
+			return $apps;
580
+		}
494 581
 
495
-		foreach($apps as $key => $app) {
496
-			if(!self::has_definitions($app, $_type)) unset($apps[$key]);
582
+		foreach($apps as $key => $app)
583
+		{
584
+			if(!self::has_definitions($app, $_type))
585
+			{
586
+				unset($apps[$key]);
587
+			}
497 588
 		}
498 589
 		return $apps;
499 590
 	}
500 591
 
501
-	public static function load_defaults($appname) {
592
+	public static function load_defaults($appname)
593
+	{
502 594
 		// Check for new definitions to import from $appname/setup/*.xml
503 595
 		$appdir = EGW_INCLUDE_ROOT. "/$appname/setup";
504
-		if(!is_dir($appdir)) return;
596
+		if(!is_dir($appdir))
597
+		{
598
+			return;
599
+		}
505 600
 		$d = dir($appdir);
506 601
 
507 602
 		// step through each file in app's setup
508
-		while (false !== ($entry = $d->read())) {
603
+		while (false !== ($entry = $d->read()))
604
+		{
509 605
 			$file = $appdir. '/'. $entry;
510 606
 			list( $filename, $extension) = explode('.',$entry);
511
-			if ( $extension != 'xml' ) continue;
607
+			if ( $extension != 'xml' )
608
+			{
609
+				continue;
610
+			}
512 611
 			try {
513 612
 				// import will skip invalid files
514 613
 				importexport_definitions_bo::import( $file );
515
-			} catch (Exception $e) {
614
+			}
615
+			catch (Exception $e) {
516 616
 				error_log(__CLASS__.__FUNCTION__. " import $appname definitions: " . $e->getMessage());
517 617
 			}
518 618
 		}
519 619
 		$d->close();
520 620
 	}
521 621
 
522
-	public static function guess_filetype( $_file ) {
622
+	public static function guess_filetype( $_file )
623
+	{
523 624
 
524 625
 	}
525 626
 
@@ -530,7 +631,8 @@  discard block
 block discarded – undo
530 631
 	 * @param string $_type {import | export | all}
531 632
 	 * @return boolean
532 633
 	 */
533
-	public static function has_definitions( $_appname = 'all', $_type = 'all' ) {
634
+	public static function has_definitions( $_appname = 'all', $_type = 'all' )
635
+	{
534 636
 		$definitions = egw_cache::getSession(
535 637
 			__CLASS__,
536 638
 			'has_definitions',
@@ -544,27 +646,36 @@  discard block
 block discarded – undo
544 646
 		// Testing: Comment out cache call above, use this
545 647
 		//$definitions = self::_has_definitions($appnames, $types);
546 648
 
547
-		foreach($definitions as $appname => $_types) {
548
-			if(!in_array($appname, $appnames)) unset($definitions[$appname]);
649
+		foreach($definitions as $appname => $_types)
650
+		{
651
+			if(!in_array($appname, $appnames))
652
+			{
653
+				unset($definitions[$appname]);
654
+			}
549 655
 		}
550
-		foreach($definitions as $appname => $_types) {
656
+		foreach($definitions as $appname => $_types)
657
+		{
551 658
 			$definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types));
552 659
 		}
553 660
 		return count($definitions[$appname]) > 0;
554 661
 	}
555 662
 
556 663
 	// egw_cache needs this public
557
-	public static function _has_definitions(Array $appnames, Array $types) {
664
+	public static function _has_definitions(Array $appnames, Array $types)
665
+	{
558 666
 		$def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types));
559 667
 		$list = array();
560
-		foreach((array)$def->get_definitions() as $id) {
668
+		foreach((array)$def->get_definitions() as $id)
669
+		{
561 670
 			// Need to instanciate it to check, but if the user doesn't have permission, it throws an exception
562 671
 			try {
563 672
 				$definition = new importexport_definition($id);
564
-				if($def->is_permitted($definition->get_record_array())) {
673
+				if($def->is_permitted($definition->get_record_array()))
674
+				{
565 675
 					$list[$definition->application][$definition->type][] = $id;
566 676
 				}
567
-			} catch (Exception $e) {
677
+			}
678
+			catch (Exception $e) {
568 679
 				// That one doesn't work, keep going
569 680
 			}
570 681
 			$definition = null;
@@ -590,8 +701,14 @@  discard block
 block discarded – undo
590 701
 	{
591 702
 		$fields = array();
592 703
 		try {
593
-			if($record_classname == null) $record_classname = $app_name . '_egw_record';
594
-			if(!class_exists($record_classname)) throw new Exception('Bad class name ' . $record_classname);
704
+			if($record_classname == null)
705
+			{
706
+				$record_classname = $app_name . '_egw_record';
707
+			}
708
+			if(!class_exists($record_classname))
709
+			{
710
+				throw new Exception('Bad class name ' . $record_classname);
711
+			}
595 712
 
596 713
 			$plugin = is_object($plugin_name) ? $plugin_name : new $plugin_name();
597 714
 			$plugin_name = get_class($plugin);
@@ -599,7 +716,10 @@  discard block
 block discarded – undo
599 716
 			if(!$wizard_plugin)
600 717
 			{
601 718
 				$wizard_name = $app_name . '_wizard_' . str_replace($app_name . '_', '', $plugin_name);
602
-				if(!class_exists($wizard_name)) throw new Exception('Bad wizard name ' . $wizard_name);
719
+				if(!class_exists($wizard_name))
720
+				{
721
+					throw new Exception('Bad wizard name ' . $wizard_name);
722
+				}
603 723
 				$wizard_plugin = new $wizard_name;
604 724
 			}
605 725
 		}
@@ -619,7 +739,10 @@  discard block
 block discarded – undo
619 739
 		foreach($record_classname::$types as $type => $type_fields)
620 740
 		{
621 741
 			// Only these for now, until filter methods for others are figured out
622
-			if(!in_array($type, array('select','select-cat','select-account','date','date-time'))) continue;
742
+			if(!in_array($type, array('select','select-cat','select-account','date','date-time')))
743
+			{
744
+				continue;
745
+			}
623 746
 			foreach($type_fields as $field_name)
624 747
 			{
625 748
 				$fields[$field_name] = array(
@@ -637,14 +760,18 @@  discard block
 block discarded – undo
637 760
 			$fields['#'.$field_name] = $settings;
638 761
 		}
639 762
 
640
-		foreach($fields as $field_name => &$settings) {
763
+		foreach($fields as $field_name => &$settings)
764
+		{
641 765
 			// Can't really filter on these (or at least no generic, sane way figured out yet)
642 766
 			if(!is_array($settings) || in_array($settings['type'], array('text','button', 'label','url','url-email','url-phone','htmlarea')))
643 767
 			{
644 768
 				unset($fields[$field_name]);
645 769
 				continue;
646 770
 			}
647
-			if($settings['type'] == 'radio') $settings['type'] = 'select';
771
+			if($settings['type'] == 'radio')
772
+			{
773
+				$settings['type'] = 'select';
774
+			}
648 775
 			switch($settings['type'])
649 776
 			{
650 777
 				case 'checkbox':
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_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.
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.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 	 * @param string $_resource resource containing data. May be each valid php-stream
81 81
 	 * @param array $_options options for the resource array with keys: charset and fieldsep
82 82
 	 */
83
-	public function __construct( $_resource,  array $_options ) {
83
+	public function __construct($_resource, array $_options) {
84 84
 		$this->resource = $_resource;
85 85
 		$this->csv_fieldsep = $_options['fieldsep'];
86
-		if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
86
+		if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
87 87
 		$this->csv_charset = $_options['charset'];
88 88
 		return;
89 89
 	} // end of member function __construct
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
 	 * @param mixed _position may be: {current|first|last|next|previous|somenumber}
101 101
 	 * @return mixed array with data / false if no furtor records
102 102
 	 */
103
-	public function get_record( $_position = 'next' ) {
103
+	public function get_record($_position = 'next') {
104 104
 		
105
-		if ($this->get_raw_record( $_position ) === false) {
105
+		if ($this->get_raw_record($_position) === false) {
106 106
 			return false;
107 107
 		}
108 108
 		
109 109
 		// skip empty records
110
-		if( count( array_unique( $this->record ) ) < 2 ) return $this->get_record( $_position );
110
+		if (count(array_unique($this->record)) < 2) return $this->get_record($_position);
111 111
 		
112
-		if ( !empty( $this->conversion ) ) {
112
+		if (!empty($this->conversion)) {
113 113
 			$this->do_conversions();
114 114
 		}
115 115
 		
116
-		if ( !empty( $this->mapping ) ) {
116
+		if (!empty($this->mapping)) {
117 117
 			$this->do_fieldmapping();
118 118
 		}
119 119
 		
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 	 *
126 126
 	 * @param int $_numToSkip
127 127
 	 */
128
-	public function skip_records( $_numToSkip ) {
129
-		while ( (int)$_numToSkip-- !== 0 ) {
130
-			fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep);
128
+	public function skip_records($_numToSkip) {
129
+		while ((int)$_numToSkip-- !== 0) {
130
+			fgetcsv($this->resource, self::csv_max_linelength, $this->csv_fieldsep);
131 131
 		}
132 132
 	}
133 133
 	
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 * @param mixed $_position
138 138
 	 * @return bool
139 139
 	 */
140
-	private function get_raw_record( $_position = 'next' ) {
140
+	private function get_raw_record($_position = 'next') {
141 141
 		switch ($_position) {
142 142
 			case 'current' :
143 143
 				if ($this->current_position == 0) {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 				}
152 152
 				
153 153
 			case 'next' :
154
-				$csv_data = fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep);
154
+				$csv_data = fgetcsv($this->resource, self::csv_max_linelength, $this->csv_fieldsep);
155 155
 				if (!is_array($csv_data)) {
156 156
 					return false;
157 157
 				}
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 		$this->record = array();
233 233
 		foreach ($this->mapping as $cvs_idx => $new_idx)
234 234
 		{
235
-			if( $new_idx == '' ) continue;
235
+			if ($new_idx == '') continue;
236 236
 			$this->record[$new_idx] = $record[$cvs_idx];
237 237
 		}
238 238
 		return true;
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	 * @return bool
245 245
 	 */
246 246
 	protected function do_conversions() {
247
-		if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) {
247
+		if ($record = importexport_helper_functions::conversion($this->record, $this->conversion, $this->conversion_class)) {
248 248
 			$this->record = $record;
249 249
 			return;
250 250
 		}
@@ -261,25 +261,25 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @return string warnings, if any
263 263
 	 */
264
-	public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) {
264
+	public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format = 0) {
265 265
 		$warnings = array();
266 266
 
267 267
 		// Automatic conversions
268
-		if($appname) {
268
+		if ($appname) {
269 269
 
270 270
 			// Load translations
271 271
 			translation::add_app($appname);
272 272
 
273
-			if(!self::$cf_parse_cache[$appname]) {
273
+			if (!self::$cf_parse_cache[$appname]) {
274 274
 				$c_fields = importexport_export_csv::convert_parse_custom_fields($appname, $selects, $links, $methods);
275 275
 				self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
276 276
 			}
277 277
 			list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname];
278 278
 
279 279
 			// Add in any fields that are keys to another app
280
-			foreach((array)$fields['links'] as $link_field => $app)
280
+			foreach ((array)$fields['links'] as $link_field => $app)
281 281
 			{
282
-				if(is_numeric($link_field)) continue;
282
+				if (is_numeric($link_field)) continue;
283 283
 				$links[$link_field] = $app;
284 284
 				// Set it as a normal link field
285 285
 				$fields['links'][] = $link_field;
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 			}
288 288
 
289 289
 			// Not quite a recursive merge, since only one level
290
-			foreach($fields as $type => &$list)
290
+			foreach ($fields as $type => &$list)
291 291
 			{
292
-				if($c_fields[$type]) {
292
+				if ($c_fields[$type]) {
293 293
 					$list = array_merge($c_fields[$type], $list);
294 294
 					unset($c_fields[$type]);
295 295
 				}
@@ -297,36 +297,36 @@  discard block
 block discarded – undo
297 297
 			$fields += $c_fields;
298 298
 			$selects += $c_selects;
299 299
 		}
300
-		if($fields) {
301
-			foreach((array)$fields['select'] as $name) {
302
-				if($record[$name] != null && is_array($selects) && $selects[$name]) {
303
-					$key = array_search(strtolower($record[$name]), array_map('strtolower',$selects[$name]));
304
-					if($key !== false)
300
+		if ($fields) {
301
+			foreach ((array)$fields['select'] as $name) {
302
+				if ($record[$name] != null && is_array($selects) && $selects[$name]) {
303
+					$key = array_search(strtolower($record[$name]), array_map('strtolower', $selects[$name]));
304
+					if ($key !== false)
305 305
 					{
306 306
 						$record[$name] = $key;
307 307
 					}
308 308
 					else
309 309
 					{
310
-						$key = array_search(strtolower($record[$name]), array_map('strtolower',array_map('lang',$selects[$name])));
311
-						if($key !== false) $record[$name] = $key;
310
+						$key = array_search(strtolower($record[$name]), array_map('strtolower', array_map('lang', $selects[$name])));
311
+						if ($key !== false) $record[$name] = $key;
312 312
 					}
313 313
 				}
314 314
 			}
315
-			foreach((array)$fields['links'] as $name) {
316
-				if($record[$name] && $links[$name])
315
+			foreach ((array)$fields['links'] as $name) {
316
+				if ($record[$name] && $links[$name])
317 317
 				{
318 318
 					// Primary key to another app, not a link
319 319
 					// Text - search for a matching record
320
-					if(!is_numeric($record[$name]))
320
+					if (!is_numeric($record[$name]))
321 321
 					{
322 322
 						$results = egw_link::query($links[$name], $record[$name]);
323
-						if(count($results) >= 1)
323
+						if (count($results) >= 1)
324 324
 						{
325 325
 							// More than 1 result.  Check for exact match
326 326
 							$exact_count = 0;
327
-							foreach($results as $id => $title)
327
+							foreach ($results as $id => $title)
328 328
 							{
329
-								if($title == $record[$name])
329
+								if ($title == $record[$name])
330 330
 								{
331 331
 									$exact_count++;
332 332
 									$app_id = $id;
@@ -335,11 +335,11 @@  discard block
 block discarded – undo
335 335
 								unset($results[$id]);
336 336
 							}
337 337
 							// Too many exact matches, or none good enough
338
-							if($exact_count > 1 || count($results) == 0)
338
+							if ($exact_count > 1 || count($results) == 0)
339 339
 							{
340 340
 								$warnings[] = lang('Unable to link to %1 "%2"',
341 341
 									lang($links[$name]), $record[$name]).
342
- 									' - ' .lang('too many matches');
342
+ 									' - '.lang('too many matches');
343 343
 								continue;
344 344
 							}
345 345
 							elseif ($exact_count == 1)
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 						{
353 353
 							$warnings[] = lang('Unable to link to %1 "%2"',
354 354
 								lang($links[$name]), $record[$name]).
355
- 								' - ' . lang('no matches');
355
+ 								' - '.lang('no matches');
356 356
 							continue;
357 357
 						} else {
358 358
 							$record[$name] = key($results);
@@ -360,17 +360,17 @@  discard block
 block discarded – undo
360 360
 					}
361 361
 				}
362 362
 			}
363
-			foreach((array)$fields['select-account'] as $name) {
363
+			foreach ((array)$fields['select-account'] as $name) {
364 364
 				// Compare against null to deal with empty arrays
365 365
 				if ($record[$name]) {
366 366
 					// Automatically handle text owner without explicit translation
367 367
 					$new_owner = importexport_helper_functions::account_name2id($record[$name]);
368
-					if(count($new_owner) != count(explode(',',$record[$name])))
368
+					if (count($new_owner) != count(explode(',', $record[$name])))
369 369
 					{
370 370
 						// Unable to parse value into account
371
-						$warnings[] = $name . ': ' .lang('%1 is not a known user or group', $record[$name]);
371
+						$warnings[] = $name.': '.lang('%1 is not a known user or group', $record[$name]);
372 372
 					}
373
-					if($new_owner != '') {
373
+					if ($new_owner != '') {
374 374
 						$record[$name] = $new_owner;
375 375
 					} else {
376 376
 						// Clear it to prevent trouble later on
@@ -378,24 +378,24 @@  discard block
 block discarded – undo
378 378
 					}
379 379
 				}
380 380
 			}
381
-			foreach((array)$fields['select-bool'] as $name) {
382
-				if($record[$name] != null && $record[$name] != '') {
381
+			foreach ((array)$fields['select-bool'] as $name) {
382
+				if ($record[$name] != null && $record[$name] != '') {
383 383
 					$record[$name] = ($record[$name] == lang('Yes') || $record[$name] == '1' ? 1 : 0);
384 384
 				}
385 385
 			}
386
-			foreach((array)$fields['date-time'] as $name) {
386
+			foreach ((array)$fields['date-time'] as $name) {
387 387
 				if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0)
388 388
 				{
389 389
 					// Need to handle format first
390
-					if($format == 1)
390
+					if ($format == 1)
391 391
 					{
392 392
 						$formatted = egw_time::createFromFormat(
393
-							'!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat,
393
+							'!'.egw_time::$user_dateformat.' '.egw_time::$user_timeformat,
394 394
 							$record[$name],
395 395
 							egw_time::$user_timezone
396 396
 						);
397 397
 
398
-						if(!$formatted && $errors = egw_time::getLastErrors())
398
+						if (!$formatted && $errors = egw_time::getLastErrors())
399 399
 						{
400 400
 							// Try again, without time
401 401
 							$formatted = egw_time::createFromFormat(
@@ -404,70 +404,70 @@  discard block
 block discarded – undo
404 404
 								egw_time::$user_timezone
405 405
 							);
406 406
 							
407
-							if(!$formatted && $errors = egw_time::getLastErrors())
407
+							if (!$formatted && $errors = egw_time::getLastErrors())
408 408
 							{
409 409
 								// Try again, anything goes
410 410
 								try {
411 411
 									$formatted = new egw_time($record[$name]);
412 412
 								} catch (Exception $e) {
413
-									$warnings[] = $name.': ' . $e->getMessage() . "\n" .
414
-										'Format: '.'!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat;
413
+									$warnings[] = $name.': '.$e->getMessage()."\n".
414
+										'Format: '.'!'.egw_time::$user_dateformat.' '.egw_time::$user_timeformat;
415 415
 									continue;
416 416
 								}
417 417
 								$errors = egw_time::getLastErrors();
418
-								foreach($errors['errors'] as $char => $msg)
418
+								foreach ($errors['errors'] as $char => $msg)
419 419
 								{
420 420
 									$warnings[] = "$name: [$char] $msg\n".
421
-										'Format: '.'!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat;
421
+										'Format: '.'!'.egw_time::$user_dateformat.' '.egw_time::$user_timeformat;
422 422
 								}
423 423
 							}
424 424
 						}
425
-						if($formatted)
425
+						if ($formatted)
426 426
 						{
427 427
 							$record[$name] = $formatted->getTimestamp();
428 428
 							// Timestamp is apparently in server time, but apps will do the same conversion
429
-							$record[$name] = egw_time::server2user($record[$name],'ts');
429
+							$record[$name] = egw_time::server2user($record[$name], 'ts');
430 430
 						}
431 431
 					}
432 432
 					
433
-					if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) &&
433
+					if (is_array(self::$cf_parse_cache[$appname][0]['date-time']) &&
434 434
 							in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) {
435 435
 						// Custom fields stored in a particular format (from customfields_widget)
436 436
 						$record[$name] = date('Y-m-d H:i:s', $record[$name]);
437 437
 					}
438 438
 				}
439
-				if(array_key_exists($name, $record) && strlen(trim($record[$name])) == 0)
439
+				if (array_key_exists($name, $record) && strlen(trim($record[$name])) == 0)
440 440
 				{
441 441
 					$record[$name] = null;
442 442
 				}
443 443
 			}
444
-			foreach((array)$fields['date'] as $name) {
444
+			foreach ((array)$fields['date'] as $name) {
445 445
 				if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0)
446 446
 				{
447 447
 					// Need to handle format first
448
-					if($format == 1)
448
+					if ($format == 1)
449 449
 					{
450 450
 						$formatted = egw_time::createFromFormat('!'.egw_time::$user_dateformat, $record[$name]);
451
-						if($formatted && $errors = egw_time::getLastErrors() && $errors['error_count'] == 0)
451
+						if ($formatted && $errors = egw_time::getLastErrors() && $errors['error_count'] == 0)
452 452
 						{
453 453
 							$record[$name] = $formatted->getTimestamp();
454 454
 						}
455 455
 					}
456
-					$record[$name] = egw_time::server2user($record[$name],'ts');
457
-					if(is_array(self::$cf_parse_cache[$appname][0]['date']) &&
456
+					$record[$name] = egw_time::server2user($record[$name], 'ts');
457
+					if (is_array(self::$cf_parse_cache[$appname][0]['date']) &&
458 458
 							in_array($name, self::$cf_parse_cache[$appname][0]['date'])) {
459 459
 						// Custom fields stored in a particular format (from customfields_widget)
460 460
 						$record[$name] = date('Y-m-d', $record[$name]);
461 461
 					}
462 462
 				}
463
-				if(array_key_exists($name, $record) && strlen(trim($record[$name])) == 0)
463
+				if (array_key_exists($name, $record) && strlen(trim($record[$name])) == 0)
464 464
 				{
465 465
 					$record[$name] = null;
466 466
 				}
467 467
 			}
468
-			foreach((array)$fields['float'] as $name)
468
+			foreach ((array)$fields['float'] as $name)
469 469
 			{
470
-				if($record[$name] != null && $record[$name] != '') {
470
+				if ($record[$name] != null && $record[$name] != '') {
471 471
 					$dec_point = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
472 472
 					if (empty($dec_point)) $dec_point = '.';
473 473
 					$record[$name] = floatval(str_replace($dec_point, '.', preg_replace('/[^\d'.preg_quote($dec_point).']/', '', $record[$name])));
@@ -475,23 +475,23 @@  discard block
 block discarded – undo
475 475
 			}
476 476
 
477 477
 			// Some custom methods for conversion
478
-			foreach((array)$methods as $name => $method) {
479
-				if($record[$name]) $record[$name] = ExecMethod($method, $record[$name]);
478
+			foreach ((array)$methods as $name => $method) {
479
+				if ($record[$name]) $record[$name] = ExecMethod($method, $record[$name]);
480 480
 			}
481 481
 
482 482
 			// cat_name2id will use currentapp to create new categories
483 483
 			$current_app = $GLOBALS['egw_info']['flags']['currentapp'];
484
-			if($appname) {
484
+			if ($appname) {
485 485
 				$GLOBALS['egw_info']['flags']['currentapp'] = $appname;
486 486
 			}
487
-			$categories = new categories('',$appname);
488
-			foreach((array)$fields['select-cat'] as $name) {
489
-				if($record[$name]) {
487
+			$categories = new categories('', $appname);
488
+			foreach ((array)$fields['select-cat'] as $name) {
489
+				if ($record[$name]) {
490 490
 					// Only parse name if it needs it
491
-					if($format == 1)
491
+					if ($format == 1)
492 492
 					{
493
-						$existing_cat = $categories->exists('all',$record[$name]);
494
-						if($existing_cat)
493
+						$existing_cat = $categories->exists('all', $record[$name]);
494
+						if ($existing_cat)
495 495
 						{
496 496
 							$cat_id = $existing_cat;
497 497
 						}
@@ -500,14 +500,14 @@  discard block
 block discarded – undo
500 500
 							$cat_id = importexport_helper_functions::cat_name2id($record[$name]);
501 501
 						}
502 502
 						// Don't clear it if it wasn't found
503
-						if($cat_id) $record[$name] = $cat_id;
503
+						if ($cat_id) $record[$name] = $cat_id;
504 504
 					}
505 505
 				}
506 506
 			}
507 507
 			$GLOBALS['egw_info']['flags']['currentapp'] = $current_app;
508 508
 		}
509 509
 
510
-		return implode("\n",$warnings);
510
+		return implode("\n", $warnings);
511 511
 	}
512 512
 } // end of import_csv
513 513
 ?>
Please login to merge, or discard this patch.
importexport/inc/class.importexport_import_ui.inc.php 5 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -295,7 +295,7 @@
 block discarded – undo
295 295
 		 *
296 296
 		 * @param importexport_iface_import_plugin $plugin Instance of plugin to be used
297 297
 		 * @param resource $stream
298
-		 * @param importexport_definition $definition
298
+		 * @param importexport_definition $definition_obj
299 299
 		 * @return String HTML fragment illustrating how the data will be understood by Egw
300 300
 		 */
301 301
 		protected function preview(importexport_iface_import_plugin &$plugin, &$stream, importexport_definition &$definition_obj)
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 		}
42 42
 
43 43
 		/**
44
-		*  Step user through importing their file
45
-		*/
44
+		 *  Step user through importing their file
45
+		 */
46 46
 		public function import_dialog($content = array()) {
47 47
 			$appname = $_GET['appname'] ? $_GET['appname'] : $content['appname'];
48 48
 			$definition = $_GET['definition'] ? $_GET['definition'] : $content['definition'];
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 		}
225 225
 
226 226
 		/**
227
-		* Get options for select boxes
228
-		*/
227
+		 * Get options for select boxes
228
+		 */
229 229
 		public static function get_select_options(Array $data) {
230 230
 			$options = array(
231 231
 				'delimiter' => array(
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 		}
275 275
 
276 276
 		/**
277
-		* Get definitions via ajax
278
-		*/
277
+		 * Get definitions via ajax
278
+		 */
279 279
 		public function ajax_get_definitions($appname, $file=null) {
280 280
 			$options = self::get_select_options(array('appname'=>$appname, 'file'=>$file));
281 281
 			$response = new xajaxResponse();
Please login to merge, or discard this patch.
Braces   +81 added lines, -35 removed lines patch added patch discarded remove patch
@@ -20,7 +20,8 @@  discard block
 block discarded – undo
20 20
  *
21 21
 */
22 22
 
23
-	class importexport_import_ui {
23
+	class importexport_import_ui
24
+	{
24 25
 
25 26
 		const _appname = 'importexport';
26 27
 
@@ -35,7 +36,8 @@  discard block
 block discarded – undo
35 36
 		 */
36 37
 		private $plugins;
37 38
 
38
-		public function __construct() {
39
+		public function __construct()
40
+		{
39 41
 			$this->plugins = importexport_helper_functions::get_plugins('all','import');
40 42
 			$GLOBALS['egw_info']['flags']['include_xajax'] = true;
41 43
 		}
@@ -43,7 +45,8 @@  discard block
 block discarded – undo
43 45
 		/**
44 46
 		*  Step user through importing their file
45 47
 		*/
46
-		public function import_dialog($content = array()) {
48
+		public function import_dialog($content = array())
49
+		{
47 50
 			$appname = $_GET['appname'] ? $_GET['appname'] : $content['appname'];
48 51
 			$definition = $_GET['definition'] ? $_GET['definition'] : $content['definition'];
49 52
 
@@ -57,16 +60,19 @@  discard block
 block discarded – undo
57 60
 			{
58 61
 				Api\Translation::add_app($appname);
59 62
 			}
60
-			if($content['import'] && $definition) {
63
+			if($content['import'] && $definition)
64
+			{
61 65
 				try {
62 66
 					$definition_obj = new importexport_definition($content['definition']);
63
-					if($content['dry-run']) {
67
+					if($content['dry-run'])
68
+					{
64 69
 						// Set this so plugin doesn't do any data changes
65 70
 						$definition_obj->plugin_options = (array)$definition_obj->plugin_options + array('dry_run' => true);
66 71
 					}
67 72
 					$options =& $definition_obj->plugin_options;
68 73
 					$options['no_notification'] = $content['no_notifications'];
69
-					if($content['delimiter']) {
74
+					if($content['delimiter'])
75
+					{
70 76
 						$options['fieldsep'] =
71 77
 							$content['delimiter'] == 'other' ? $content['other_delimiter'] : $content['delimiter'];
72 78
 					}
@@ -109,7 +115,8 @@  discard block
 block discarded – undo
109 115
 						// Keep file
110 116
 						if($dst_file)
111 117
 						{
112
-							if($content['file']['name'] && copy($content['file']['tmp_name'],$dst_file)) {
118
+							if($content['file']['name'] && copy($content['file']['tmp_name'],$dst_file))
119
+							{
113 120
 								$preserve['file']['tmp_name'] = $dst_file;
114 121
 							}
115 122
 						}
@@ -162,31 +169,41 @@  discard block
 block discarded – undo
162 169
 						Framework::refresh_opener(lang('%1 records processed',$count), $appname, null,null,$appname);
163 170
 					}
164 171
 					$total_processed = 0;
165
-					foreach($plugin->get_results() as $action => $a_count) {
172
+					foreach($plugin->get_results() as $action => $a_count)
173
+					{
166 174
 						$this->message .= "<br />\n" . lang($action) . ": $a_count";
167 175
 						$total_processed += $a_count;
168 176
 					}
169
-					if(count($plugin->get_warnings())) {
177
+					if(count($plugin->get_warnings()))
178
+					{
170 179
 						$this->message .= "<br />\n".lang('Warnings').':';
171
-						foreach($plugin->get_warnings() as $record => $message) {
180
+						foreach($plugin->get_warnings() as $record => $message)
181
+						{
172 182
 							$this->message .= "\n$record: $message";
173 183
 						}
174 184
 					}
175
-					if(count($plugin->get_errors())) {
185
+					if(count($plugin->get_errors()))
186
+					{
176 187
 						$this->message .= "<br />\n".lang('Problems during import:');
177
-						foreach($plugin->get_errors() as $record => $message) {
188
+						foreach($plugin->get_errors() as $record => $message)
189
+						{
178 190
 							$this->message .= "<br />\n$record: $message";
179 191
 						}
180
-						if($count != $total_processed) $this->message .= "<br />\n".lang('Some records may not have been imported');
192
+						if($count != $total_processed)
193
+						{
194
+							$this->message .= "<br />\n".lang('Some records may not have been imported');
195
+						}
181 196
 					}
182
-					if ($dst_file && $content['file']['tmp_name'] == $dst_file) {
197
+					if ($dst_file && $content['file']['tmp_name'] == $dst_file)
198
+					{
183 199
 						// Remove file
184 200
 						$cachefile->delete(Api\Cache::keys(Api\Cache::INSTANCE, 'importexport',
185 201
 							'import_'.md5($content['file']['name'].$GLOBALS['egw_info']['user']['account_id'])));
186 202
 						unset($dst_file);
187 203
 					}
188 204
 
189
-				} catch (Exception $e) {
205
+				}
206
+				catch (Exception $e) {
190 207
 					$this->message .= $e->getMessage();
191 208
 				}
192 209
 			}
@@ -218,7 +235,10 @@  discard block
 block discarded – undo
218 235
 			$data['message'] = $this->message;
219 236
 			Framework::includeJS('.','importexport','importexport');
220 237
 
221
-			if($_GET['appname']) $readonlys['appname'] = true;
238
+			if($_GET['appname'])
239
+			{
240
+				$readonlys['appname'] = true;
241
+			}
222 242
 
223 243
 			$template->exec('importexport.importexport_import_ui.import_dialog', $data, $sel_options, $readonlys, $preserve, 2);
224 244
 		}
@@ -226,7 +246,8 @@  discard block
 block discarded – undo
226 246
 		/**
227 247
 		* Get options for select boxes
228 248
 		*/
229
-		public static function get_select_options(Array $data) {
249
+		public static function get_select_options(Array $data)
250
+		{
230 251
 			$options = array(
231 252
 				'delimiter' => array(
232 253
 					''	=>	lang('From definition'),
@@ -242,17 +263,20 @@  discard block
 block discarded – undo
242 263
 			(array)$apps = importexport_helper_functions::get_apps('import');
243 264
 			$options['appname'] = array('' => lang('Select one')) + array_combine($apps,$apps);
244 265
 
245
-			if($data['appname']) {
266
+			if($data['appname'])
267
+			{
246 268
 				$options['definition'] = array();
247 269
 
248
-				if($data['file'] && !is_array($data['file'])) {
270
+				if($data['file'] && !is_array($data['file']))
271
+				{
249 272
 					$extension = substr($data['file'], -3);
250 273
 				}
251 274
 				$definitions = new importexport_definitions_bo(array(
252 275
 					'type' => 'import',
253 276
 					'application' => $data['appname']
254 277
 				));
255
-				foreach ((array)$definitions->get_definitions() as $identifier) {
278
+				foreach ((array)$definitions->get_definitions() as $identifier)
279
+				{
256 280
 					try
257 281
 					{
258 282
 						$definition = new importexport_definition($identifier);
@@ -262,7 +286,8 @@  discard block
 block discarded – undo
262 286
 						// Permission error
263 287
 						continue;
264 288
 					}
265
-					if ($title = $definition->get_title()) {
289
+					if ($title = $definition->get_title())
290
+					{
266 291
 						$options['definition'][$title] = $title;
267 292
 					}
268 293
 					unset($definition);
@@ -276,12 +301,15 @@  discard block
 block discarded – undo
276 301
 		/**
277 302
 		* Get definitions via ajax
278 303
 		*/
279
-		public function ajax_get_definitions($appname, $file=null) {
304
+		public function ajax_get_definitions($appname, $file=null)
305
+		{
280 306
 			$options = self::get_select_options(array('appname'=>$appname, 'file'=>$file));
281 307
 			$response = new xajaxResponse();
282 308
 			$response->addScript("clear_options('exec[definition]');");
283
-			if(is_array($options['definition'])) {
284
-				foreach ($options['definition'] as $value => $title) {
309
+			if(is_array($options['definition']))
310
+			{
311
+				foreach ($options['definition'] as $value => $title)
312
+				{
285 313
 					$response->addScript("selectbox_add_option('exec[definition]','$title', '$value',false);");
286 314
 				}
287 315
 			}
@@ -317,9 +345,15 @@  discard block
 block discarded – undo
317 345
 				for($row = 0; $row < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; $row++)
318 346
 				{
319 347
 					$row_data = $import_csv->get_record();
320
-					if($row_data === false) break;
348
+					if($row_data === false)
349
+					{
350
+						break;
351
+					}
321 352
 					$rows[$import_csv->get_current_position() <= $definition_obj->plugin_options['num_header_lines'] ? 'h1' : $row] = $row_data;
322
-					if($import_csv->get_current_position() <= $definition_obj->plugin_options['num_header_lines']) $row--;
353
+					if($import_csv->get_current_position() <= $definition_obj->plugin_options['num_header_lines'])
354
+					{
355
+						$row--;
356
+					}
323 357
 				}
324 358
 				$preview = Api\Html::table($rows);
325 359
 				rewind($stream);
@@ -328,19 +362,26 @@  discard block
 block discarded – undo
328 362
 			{
329 363
 				$preview = lang('Preview not supported by %1', $plugin->get_name());
330 364
 			}
331
-			if(count($plugin->get_warnings())) {
365
+			if(count($plugin->get_warnings()))
366
+			{
332 367
 				$this->message .= "<br />\n".lang('Warnings').':';
333
-				foreach($plugin->get_warnings() as $record => $message) {
368
+				foreach($plugin->get_warnings() as $record => $message)
369
+				{
334 370
 					$this->message .= "\n$record: $message";
335 371
 				}
336 372
 				$this->message .= "<br />\n";
337 373
 			};
338
-			if(count($plugin->get_errors())) {
374
+			if(count($plugin->get_errors()))
375
+			{
339 376
 				$this->message .= "<br />\n".lang('Problems during import:');
340
-				foreach($plugin->get_errors() as $record => $message) {
377
+				foreach($plugin->get_errors() as $record => $message)
378
+				{
341 379
 					$this->message .= "<br />\n$record: $message";
342 380
 				}
343
-				if($count != $total_processed) $this->message .= "<br />\n".lang('Some records may not have been imported');
381
+				if($count != $total_processed)
382
+				{
383
+					$this->message .= "<br />\n".lang('Some records may not have been imported');
384
+				}
344 385
 				$this->message .= "<br />\n";
345 386
 			}
346 387
 			return '<div class="header">' . lang('Preview') . ' - ' . $plugin->get_name() . '</div>' . $preview;
@@ -365,10 +406,16 @@  discard block
 block discarded – undo
365 406
 			$message_count = count($message);
366 407
 
367 408
 			// Only CSV files
368
-			if(!$options['csv_fields']) return true;
409
+			if(!$options['csv_fields'])
410
+			{
411
+				return true;
412
+			}
369 413
 
370 414
 			// Can't check if definition has no header
371
-			if($options['num_header_lines'] == 0) return true;
415
+			if($options['num_header_lines'] == 0)
416
+			{
417
+				return true;
418
+			}
372 419
 
373 420
 			$preference = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
374 421
 			$charset = $options['charset'] == 'user' || !$options['charset'] ? $preference : $options['charset'];
@@ -412,8 +459,7 @@  discard block
 block discarded – undo
412 459
 				if($lang_defn == $lang_file ||
413 460
 					$lang_defn == mb_strtoupper($header) ||
414 461
 					$lang_file == mb_strtoupper($options['csv_fields'][$index])
415
-				)
416
-				{
462
+				) {
417 463
 					continue;
418 464
 				}
419 465
 
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -226,7 +226,7 @@
 block discarded – undo
226 226
 		/**
227 227
 		* Get options for select boxes
228 228
 		*/
229
-		public static function get_select_options(Array $data) {
229
+		public static function get_select_options(array $data) {
230 230
 			$options = array(
231 231
 				'delimiter' => array(
232 232
 					''	=>	lang('From definition'),
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 		private $plugins;
33 33
 
34 34
 		public function __construct() {
35
-			$this->plugins = importexport_helper_functions::get_plugins('all','import');
35
+			$this->plugins = importexport_helper_functions::get_plugins('all', 'import');
36 36
 			$GLOBALS['egw_info']['flags']['include_xajax'] = true;
37 37
 		}
38 38
 
@@ -49,20 +49,20 @@  discard block
 block discarded – undo
49 49
 			$template = new etemplate_new('importexport.import_dialog');
50 50
 
51 51
 			// Load application's translations
52
-			if($appname)
52
+			if ($appname)
53 53
 			{
54 54
 				translation::add_app($appname);
55 55
 			}
56
-			if($content['import'] && $definition) {
56
+			if ($content['import'] && $definition) {
57 57
 				try {
58 58
 					$definition_obj = new importexport_definition($content['definition']);
59
-					if($content['dry-run']) {
59
+					if ($content['dry-run']) {
60 60
 						// Set this so plugin doesn't do any data changes
61 61
 						$definition_obj->plugin_options = (array)$definition_obj->plugin_options + array('dry_run' => true);
62 62
 					}
63
-					$options =& $definition_obj->plugin_options;
63
+					$options = & $definition_obj->plugin_options;
64 64
 					$options['no_notification'] = $content['no_notifications'];
65
-					if($content['delimiter']) {
65
+					if ($content['delimiter']) {
66 66
 						$options['fieldsep'] =
67 67
 							$content['delimiter'] == 'other' ? $content['other_delimiter'] : $content['delimiter'];
68 68
 					}
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 					$plugin = new $definition_obj->plugin;
72 72
 
73 73
 					// Check file encoding matches import
74
-					$sample = file_get_contents($content['file']['tmp_name'],false, null, 0, 1024);
75
-					if($appname == 'addressbook' && $definition_obj->plugin == 'addressbook_import_vcard')
74
+					$sample = file_get_contents($content['file']['tmp_name'], false, null, 0, 1024);
75
+					if ($appname == 'addressbook' && $definition_obj->plugin == 'addressbook_import_vcard')
76 76
 					{
77 77
 						$preference = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset'];
78 78
 					}
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 					}
83 83
 					$required = $options['charset'] == 'user' || !$options['charset'] ? $preference : $options['charset'];
84 84
 					$encoding = translation::detect_encoding($sample, $required);
85
-					if($encoding && strtoupper($required) != strtoupper($encoding))
85
+					if ($encoding && strtoupper($required) != strtoupper($encoding))
86 86
 					{
87 87
 						$this->message = lang("Encoding mismatch.  Expected %1 file, you uploaded %2.<br />\n",
88 88
 							$required,
@@ -97,37 +97,37 @@  discard block
 block discarded – undo
97 97
 					$GLOBALS['egw_info']['flags']['currentapp'] = $appname;
98 98
 
99 99
 					// Destination if we need to hold the file
100
-					if($file)
100
+					if ($file)
101 101
 					{
102 102
 						$cachefile = new egw_cache_files(array());
103 103
 						$dst_file = $cachefile->filename(egw_cache::keys(egw_cache::INSTANCE, 'importexport',
104
-							'import_'.md5($content['file']['name'].$GLOBALS['egw_info']['user']['account_id']), true),true);
104
+							'import_'.md5($content['file']['name'].$GLOBALS['egw_info']['user']['account_id']), true), true);
105 105
 						// Keep file
106
-						if($dst_file)
106
+						if ($dst_file)
107 107
 						{
108
-							if($content['file']['name'] && copy($content['file']['tmp_name'],$dst_file)) {
108
+							if ($content['file']['name'] && copy($content['file']['tmp_name'], $dst_file)) {
109 109
 								$preserve['file']['tmp_name'] = $dst_file;
110 110
 							}
111 111
 						}
112 112
 
113 113
 						// Check on matching columns
114 114
 						$check_message = array();
115
-						if(!self::check_file($file, $definition_obj, $check_message, $dst_file))
115
+						if (!self::check_file($file, $definition_obj, $check_message, $dst_file))
116 116
 						{
117 117
 							// Set this so plugin doesn't do any data changes
118 118
 							$content['dry-run'] = true;
119 119
 							importexport_helper_functions::$dry_run = true;
120
-							$this->message .= '<b>' . lang('Import aborted').":</b><br />\n";
120
+							$this->message .= '<b>'.lang('Import aborted').":</b><br />\n";
121 121
 							$definition_obj->plugin_options = (array)$definition_obj->plugin_options + array('dry_run' => true);
122 122
 						}
123
-						if(count($check_message))
123
+						if (count($check_message))
124 124
 						{
125
-							$this->message .= implode($check_message, "<br />\n") . "<br />\n";
125
+							$this->message .= implode($check_message, "<br />\n")."<br />\n";
126 126
 						}
127
-						if($content['dry-run'])
127
+						if ($content['dry-run'])
128 128
 						{
129 129
 							$preview = $this->preview($plugin, $file, $definition_obj);
130
-							if(trim($this->message) == '')
130
+							if (trim($this->message) == '')
131 131
 							{
132 132
 								// Clear first, to prevent request from being collected if the result is the same
133 133
 								$template->setElementAttribute('preview', 'value', '');
@@ -146,34 +146,34 @@  discard block
 block discarded – undo
146 146
 						$this->message .= lang('please select file to import'."<br />\n");
147 147
 					}
148 148
 
149
-					if($content['dry-run'])
149
+					if ($content['dry-run'])
150 150
 					{
151
-						$this->message .= '<b>' . lang('test only').":</b><br />\n";
151
+						$this->message .= '<b>'.lang('test only').":</b><br />\n";
152 152
 					}
153 153
 					$this->message .= lang('%1 records processed', $count);
154 154
 
155 155
 					// Refresh opening window
156
-					if(!$content['dry-run'])
156
+					if (!$content['dry-run'])
157 157
 					{
158
-						egw_framework::refresh_opener(lang('%1 records processed',$count), $appname, null,null,$appname);
158
+						egw_framework::refresh_opener(lang('%1 records processed', $count), $appname, null, null, $appname);
159 159
 					}
160 160
 					$total_processed = 0;
161
-					foreach($plugin->get_results() as $action => $a_count) {
162
-						$this->message .= "<br />\n" . lang($action) . ": $a_count";
161
+					foreach ($plugin->get_results() as $action => $a_count) {
162
+						$this->message .= "<br />\n".lang($action).": $a_count";
163 163
 						$total_processed += $a_count;
164 164
 					}
165
-					if(count($plugin->get_warnings())) {
165
+					if (count($plugin->get_warnings())) {
166 166
 						$this->message .= "<br />\n".lang('Warnings').':';
167
-						foreach($plugin->get_warnings() as $record => $message) {
167
+						foreach ($plugin->get_warnings() as $record => $message) {
168 168
 							$this->message .= "\n$record: $message";
169 169
 						}
170 170
 					}
171
-					if(count($plugin->get_errors())) {
171
+					if (count($plugin->get_errors())) {
172 172
 						$this->message .= "<br />\n".lang('Problems during import:');
173
-						foreach($plugin->get_errors() as $record => $message) {
173
+						foreach ($plugin->get_errors() as $record => $message) {
174 174
 							$this->message .= "<br />\n$record: $message";
175 175
 						}
176
-						if($count != $total_processed) $this->message .= "<br />\n".lang('Some records may not have been imported');
176
+						if ($count != $total_processed) $this->message .= "<br />\n".lang('Some records may not have been imported');
177 177
 					}
178 178
 					if ($dst_file && $content['file']['tmp_name'] == $dst_file) {
179 179
 						// Remove file
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 					$this->message .= $e->getMessage();
187 187
 				}
188 188
 			}
189
-			elseif($content['cancel'])
189
+			elseif ($content['cancel'])
190 190
 			{
191 191
 				$GLOBALS['egw']->js->set_onload('window.close();');
192 192
 			}
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 				);
200 200
 			}
201 201
 
202
-			if(!array_key_exists('dry-run',$content))
202
+			if (!array_key_exists('dry-run', $content))
203 203
 			{
204 204
 				$data['dry-run'] = true;
205 205
 			}
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
 			$data['appname'] = $preserve['appname'] = $appname ? $appname : ($definition_obj ? $definition_obj->application : '');
208 208
 			$data['definition'] = $definition;
209 209
 			$data['delimiter'] = $definition_obj->plugin_options['delimiter'];
210
-			$data['no_notifications'] = true;	// switch notifications off by default
210
+			$data['no_notifications'] = true; // switch notifications off by default
211 211
 
212 212
 			$sel_options = self::get_select_options($data);
213 213
 
214 214
 			$data['message'] = $this->message;
215
-			$GLOBALS['egw']->js->validate_file('.','importexport','importexport');
215
+			$GLOBALS['egw']->js->validate_file('.', 'importexport', 'importexport');
216 216
 
217
-			if($_GET['appname']) $readonlys['appname'] = true;
217
+			if ($_GET['appname']) $readonlys['appname'] = true;
218 218
 
219 219
 			$template->exec('importexport.importexport_import_ui.import_dialog', $data, $sel_options, $readonlys, $preserve, 2);
220 220
 		}
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 			);
237 237
 
238 238
 			(array)$apps = importexport_helper_functions::get_apps('import');
239
-			$options['appname'] = array('' => lang('Select one')) + array_combine($apps,$apps);
239
+			$options['appname'] = array('' => lang('Select one')) + array_combine($apps, $apps);
240 240
 
241
-			if($data['appname']) {
241
+			if ($data['appname']) {
242 242
 				$options['definition'] = array();
243 243
 
244
-				if($data['file'] && !is_array($data['file'])) {
244
+				if ($data['file'] && !is_array($data['file'])) {
245 245
 					$extension = substr($data['file'], -3);
246 246
 				}
247 247
 				$definitions = new importexport_definitions_bo(array(
@@ -272,11 +272,11 @@  discard block
 block discarded – undo
272 272
 		/**
273 273
 		* Get definitions via ajax
274 274
 		*/
275
-		public function ajax_get_definitions($appname, $file=null) {
275
+		public function ajax_get_definitions($appname, $file = null) {
276 276
 			$options = self::get_select_options(array('appname'=>$appname, 'file'=>$file));
277 277
 			$response = new xajaxResponse();
278 278
 			$response->addScript("clear_options('exec[definition]');");
279
-			if(is_array($options['definition'])) {
279
+			if (is_array($options['definition'])) {
280 280
 				foreach ($options['definition'] as $value => $title) {
281 281
 					$response->addScript("selectbox_add_option('exec[definition]','$title', '$value',false);");
282 282
 				}
@@ -294,28 +294,28 @@  discard block
 block discarded – undo
294 294
 		 * @param importexport_definition $definition
295 295
 		 * @return String HTML fragment illustrating how the data will be understood by egw
296 296
 		 */
297
-		protected function preview(importexport_iface_import_plugin &$plugin, &$stream, importexport_definition &$definition_obj)
297
+		protected function preview(importexport_iface_import_plugin&$plugin, &$stream, importexport_definition&$definition_obj)
298 298
 		{
299
-			if(method_exists($plugin, 'preview'))
299
+			if (method_exists($plugin, 'preview'))
300 300
 			{
301 301
 				$preview = $plugin->preview($stream, $definition_obj);
302 302
 			}
303
-			elseif($definition_obj->plugin_options['csv_fields'])
303
+			elseif ($definition_obj->plugin_options['csv_fields'])
304 304
 			{
305
-				$import_csv = new importexport_import_csv( $stream, array(
305
+				$import_csv = new importexport_import_csv($stream, array(
306 306
 					'fieldsep' => $definition_obj->plugin_options['fieldsep'],
307 307
 					'charset' => $definition_obj->plugin_options['charset'],
308 308
 				));
309 309
 				// set FieldMapping.
310 310
 				$import_csv->mapping = $definition_obj->plugin_options['field_mapping'];
311 311
 
312
-				$rows = array('h1'=>array(),'f1'=>array(),'.h1'=>'class=th');
313
-				for($row = 0; $row < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; $row++)
312
+				$rows = array('h1'=>array(), 'f1'=>array(), '.h1'=>'class=th');
313
+				for ($row = 0; $row < $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; $row++)
314 314
 				{
315 315
 					$row_data = $import_csv->get_record();
316
-					if($row_data === false) break;
316
+					if ($row_data === false) break;
317 317
 					$rows[$import_csv->get_current_position() <= $definition_obj->plugin_options['num_header_lines'] ? 'h1' : $row] = $row_data;
318
-					if($import_csv->get_current_position() <= $definition_obj->plugin_options['num_header_lines']) $row--;
318
+					if ($import_csv->get_current_position() <= $definition_obj->plugin_options['num_header_lines']) $row--;
319 319
 				}
320 320
 				$preview = html::table($rows);
321 321
 				rewind($stream);
@@ -324,22 +324,22 @@  discard block
 block discarded – undo
324 324
 			{
325 325
 				$preview = lang('Preview not supported by %1', $plugin->get_name());
326 326
 			}
327
-			if(count($plugin->get_warnings())) {
327
+			if (count($plugin->get_warnings())) {
328 328
 				$this->message .= "<br />\n".lang('Warnings').':';
329
-				foreach($plugin->get_warnings() as $record => $message) {
329
+				foreach ($plugin->get_warnings() as $record => $message) {
330 330
 					$this->message .= "\n$record: $message";
331 331
 				}
332 332
 				$this->message .= "<br />\n";
333 333
 			};
334
-			if(count($plugin->get_errors())) {
334
+			if (count($plugin->get_errors())) {
335 335
 				$this->message .= "<br />\n".lang('Problems during import:');
336
-				foreach($plugin->get_errors() as $record => $message) {
336
+				foreach ($plugin->get_errors() as $record => $message) {
337 337
 					$this->message .= "<br />\n$record: $message";
338 338
 				}
339
-				if($count != $total_processed) $this->message .= "<br />\n".lang('Some records may not have been imported');
339
+				if ($count != $total_processed) $this->message .= "<br />\n".lang('Some records may not have been imported');
340 340
 				$this->message .= "<br />\n";
341 341
 			}
342
-			return '<div class="header">' . lang('Preview') . ' - ' . $plugin->get_name() . '</div>' . $preview;
342
+			return '<div class="header">'.lang('Preview').' - '.$plugin->get_name().'</div>'.$preview;
343 343
 		}
344 344
 
345 345
 		/**
@@ -357,24 +357,24 @@  discard block
 block discarded – undo
357 357
 		 */
358 358
 		public static function check_file(&$file, &$definition, &$message = array(), $dst_file = false)
359 359
 		{
360
-			$options =& $definition->plugin_options;
360
+			$options = & $definition->plugin_options;
361 361
 			$message_count = count($message);
362 362
 
363 363
 			// Only CSV files
364
-			if(!$options['csv_fields']) return true;
364
+			if (!$options['csv_fields']) return true;
365 365
 
366 366
 			// Can't check if definition has no header
367
-			if($options['num_header_lines'] == 0) return true;
367
+			if ($options['num_header_lines'] == 0) return true;
368 368
 
369 369
 			$preference = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
370 370
 			$charset = $options['charset'] == 'user' || !$options['charset'] ? $preference : $options['charset'];
371 371
 
372 372
 			$data = fgetcsv($file, 8000, $options['fieldsep']);
373 373
 			rewind($file);
374
-			$data = translation::convert($data,$charset);
374
+			$data = translation::convert($data, $charset);
375 375
 
376 376
 			$ok = true;
377
-			if(count($data) != count($options['csv_fields']) && max(array_keys($data)) != max(array_keys($options['csv_fields'])))
377
+			if (count($data) != count($options['csv_fields']) && max(array_keys($data)) != max(array_keys($options['csv_fields'])))
378 378
 			{
379 379
 				$message[] = lang("Column mismatch.  Expected %1 columns, your file has %2.",
380 380
 					count($options['field_mapping']),
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
 				);
383 383
 				$ok = false;
384 384
 			}
385
-			foreach($data as $index => $header)
385
+			foreach ($data as $index => $header)
386 386
 			{
387
-				if($index < count($options['csv_fields']) && !$options['field_mapping'][$index])
387
+				if ($index < count($options['csv_fields']) && !$options['field_mapping'][$index])
388 388
 				{
389 389
 					// Skipped column in definition
390 390
 					continue;
@@ -396,16 +396,16 @@  discard block
 block discarded – undo
396 396
 				}
397 397
 
398 398
 				// Check for matching headers
399
-				if($options['csv_fields'][$index] == $header)
399
+				if ($options['csv_fields'][$index] == $header)
400 400
 				{
401 401
 					// Simple match
402 402
 					continue;
403 403
 				}
404 404
 				// Check column headers, taking into account different translations - make sure no *
405
-				$lang_defn = mb_strtoupper(translation::translate($options['csv_fields'][$index],false,''));
406
-				$lang_file = mb_strtoupper(translation::translate($header,false,''));
405
+				$lang_defn = mb_strtoupper(translation::translate($options['csv_fields'][$index], false, ''));
406
+				$lang_file = mb_strtoupper(translation::translate($header, false, ''));
407 407
 
408
-				if($lang_defn == $lang_file ||
408
+				if ($lang_defn == $lang_file ||
409 409
 					$lang_defn == mb_strtoupper($header) ||
410 410
 					$lang_file == mb_strtoupper($options['csv_fields'][$index])
411 411
 				)
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 				$file_message_id = translation::get_message_id($header, $definition->application);
418 418
 				$defn_message_id = translation::get_message_id($options['csv_fields'][$index], $definition->application);
419 419
 
420
-				if($file_message_id && $defn_message_id && $file_message_id == $defn_message_id)
420
+				if ($file_message_id && $defn_message_id && $file_message_id == $defn_message_id)
421 421
 				{
422 422
 					continue;
423 423
 				}
@@ -425,19 +425,19 @@  discard block
 block discarded – undo
425 425
 
426 426
 				// Problem
427 427
 				$message[] = lang("Column mismatch: %1 should be %2, not %3",
428
-					$index,$options['csv_fields'][$index], $header);
428
+					$index, $options['csv_fields'][$index], $header);
429 429
 				// But can still continue
430 430
 				// $ok = false;
431 431
 			}
432
-			if(!$ok || count($message) != $message_count)
432
+			if (!$ok || count($message) != $message_count)
433 433
 			{
434 434
 				// Add links for new / edit definition
435 435
 				$config = config::read('importexport');
436
-				if($GLOBALS['egw_info']['user']['apps']['admin'] || $config['users_create_definitions'])
436
+				if ($GLOBALS['egw_info']['user']['apps']['admin'] || $config['users_create_definitions'])
437 437
 				{
438 438
 					$actions = '';
439 439
 					// New definition
440
-					$add_link = egw::link('/index.php',array(
440
+					$add_link = egw::link('/index.php', array(
441 441
 						'menuaction' => 'importexport.importexport_definitions_ui.edit',
442 442
 						'application' => $definition->application,
443 443
 						'plugin' => $definition->plugin,
@@ -449,13 +449,13 @@  discard block
 block discarded – undo
449 449
 							'menuaction' => 'importexport.importexport_import_ui.import_dialog',
450 450
 							// Don't set appname, or user won't be able to select & see their new definition
451 451
 							//'appname' => $definition->application,
452
-						)) . "';
452
+						))."';
453 453
 						egw_openWindowCentered2('$add_link','_blank',500,500,'yes');
454 454
 					";
455 455
 					$actions[] = lang('Create a <a href="%1">new definition</a> for this file', $add_link);
456 456
 
457 457
 					// Edit selected definition, if allowed
458
-					if($definition->owner == $GLOBALS['egw_info']['user']['account_id'] ||
458
+					if ($definition->owner == $GLOBALS['egw_info']['user']['account_id'] ||
459 459
 						!$definition->owner && $GLOBALS['egw_info']['user']['apps']['admin'])
460 460
 					{
461 461
 						$edit_link = array(
@@ -464,20 +464,20 @@  discard block
 block discarded – undo
464 464
 							// Jump to file step
465 465
 							'step' => 'wizard_step21'
466 466
 						);
467
-						if($dst_file)
467
+						if ($dst_file)
468 468
 						{
469 469
 							// Still have uploaded file, jump there
470
-							$GLOBALS['egw']->session->appsession('csvfile','',$dst_file);
470
+							$GLOBALS['egw']->session->appsession('csvfile', '', $dst_file);
471 471
 							$edit_link['step'] = 'wizard_step30';
472 472
 						}
473
-						$edit_link = egw::link('/index.php',$edit_link);
473
+						$edit_link = egw::link('/index.php', $edit_link);
474 474
 						$edit_link = "javascript:egw_openWindowCentered2('$edit_link','_blank',500,500,'yes')";
475 475
 						$actions[] = lang('Edit definition <a href="%1">%2</a> to match your file',
476
-							$edit_link, $definition->name );
476
+							$edit_link, $definition->name);
477 477
 					}
478
-					$actions[] = lang('Edit your file to match the definition:') . ' '
479
-					. implode(array_map('lang',array_intersect_key($options['csv_fields'],$options['field_mapping'])),', ');
480
-					$message[] = "\n<li>".implode($actions,"\n<li>");
478
+					$actions[] = lang('Edit your file to match the definition:').' '
479
+					. implode(array_map('lang', array_intersect_key($options['csv_fields'], $options['field_mapping'])), ', ');
480
+					$message[] = "\n<li>".implode($actions, "\n<li>");
481 481
 				}
482 482
 			}
483 483
 			return $ok;
Please login to merge, or discard this patch.
infolog/inc/class.infolog_import_infologs_csv.inc.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -108,8 +108,7 @@  discard block
 block discarded – undo
108 108
 	/**
109 109
 	 * imports entries according to given definition object.
110 110
 	 * @param resource $_stream
111
-	 * @param string $_charset
112
-	 * @param definition $_definition
111
+	 * @param importexport_definition $_definition
113 112
 	 */
114 113
 	public function import( $_stream, importexport_definition $_definition ) {
115 114
 		$import_csv = new importexport_import_csv( $_stream, array(
@@ -527,6 +526,7 @@  discard block
 block discarded – undo
527 526
 	 *
528 527
 	 * This is a copy of what's in importexport_basic_import_csv, and can go
529 528
 	 * away if this is changed to extend it
529
+	 * @param integer $record_num
530 530
 	 */
531 531
 	protected function link_by_cf($record_num, $app, $fieldname, $_value)
532 532
 	{
Please login to merge, or discard this patch.
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 	private $boinfolog;
75 75
 
76 76
 	/**
77
-	* For figuring out if a record has changed
78
-	*
79
-	* @var infolog_tracking::
80
-	*/
77
+	 * For figuring out if a record has changed
78
+	 *
79
+	 * @var infolog_tracking::
80
+	 */
81 81
 	protected $tracking;
82 82
 
83 83
 	/**
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	protected $errors = array();
102 102
 
103 103
 	/**
104
- 	* List of actions, and how many times that action was taken
104
+	 * List of actions, and how many times that action was taken
105 105
 	 */
106 106
 	protected $results = array();
107 107
 
@@ -466,37 +466,37 @@  discard block
 block discarded – undo
466 466
 	}
467 467
 
468 468
 	/**
469
-	* Returns warnings that were encountered during importing
470
-	* Maximum of one warning message per record, but you can append if you need to
471
-	*
472
-	* @return Array (
473
-	*       record_# => warning message
474
-	*       )
475
-	*/
469
+	 * Returns warnings that were encountered during importing
470
+	 * Maximum of one warning message per record, but you can append if you need to
471
+	 *
472
+	 * @return Array (
473
+	 *       record_# => warning message
474
+	 *       )
475
+	 */
476 476
 	public function get_warnings() {
477 477
 		return $this->warnings;
478 478
 	}
479 479
 
480 480
 	/**
481
-	* Returns errors that were encountered during importing
482
-	* Maximum of one error message per record, but you can append if you need to
483
-	*
484
-	* @return Array (
485
-	*       record_# => error message
486
-	*       )
487
-	*/
481
+	 * Returns errors that were encountered during importing
482
+	 * Maximum of one error message per record, but you can append if you need to
483
+	 *
484
+	 * @return Array (
485
+	 *       record_# => error message
486
+	 *       )
487
+	 */
488 488
 	public function get_errors() {
489 489
 		return $this->errors;
490 490
 	}
491 491
 
492 492
 	/**
493
-	* Returns a list of actions taken, and the number of records for that action.
494
-	* Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
495
-	*
496
-	* @return Array (
497
-	*       action => record count
498
-	* )
499
-	*/
493
+	 * Returns a list of actions taken, and the number of records for that action.
494
+	 * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
495
+	 *
496
+	 * @return Array (
497
+	 *       action => record count
498
+	 * )
499
+	 */
500 500
 	public function get_results() {
501 501
 		return $this->results;
502 502
 	}
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@  discard block
 block discarded – undo
14 14
 /**
15 15
  * class import_csv for infolog
16 16
  */
17
-class infolog_import_infologs_csv implements importexport_iface_import_plugin  {
17
+class infolog_import_infologs_csv implements importexport_iface_import_plugin {
18 18
 
19 19
 	private static $plugin_options = array(
20
-		'fieldsep', 		// char
21
-		'charset', 			// string
22
-		'contact_owner', 	// int
23
-		'update_cats', 			// string {override|add} overides record
20
+		'fieldsep', // char
21
+		'charset', // string
22
+		'contact_owner', // int
23
+		'update_cats', // string {override|add} overides record
24 24
 								// with cat(s) from csv OR add the cat from
25 25
 								// csv file to exeisting cat(s) of record
26 26
 		'num_header_lines', // int number of header lines
27 27
 		'field_conversion', // array( $csv_col_num => conversion)
28
-		'field_mapping',	// array( $csv_col_num => adb_filed)
29
-		'conditions',		/* => array containing condition arrays:
28
+		'field_mapping', // array( $csv_col_num => adb_filed)
29
+		'conditions', /* => array containing condition arrays:
30 30
 				'type' => exists, // exists
31 31
 				'string' => '#kundennummer',
32 32
 				'true' => array(
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 	/**
53 53
 	 * actions wich could be done to data entries
54 54
 	 */
55
-	protected static $actions = array( 'none', 'update', 'insert', 'delete', );
55
+	protected static $actions = array('none', 'update', 'insert', 'delete',);
56 56
 
57 57
 	/**
58 58
 	 * conditions for actions
59 59
 	 *
60 60
 	 * @var array
61 61
 	 */
62
-	protected static $conditions = array( 'exists' );
62
+	protected static $conditions = array('exists');
63 63
 
64 64
 	/**
65 65
 	 * @var definition
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 * @param string $_charset
110 110
 	 * @param definition $_definition
111 111
 	 */
112
-	public function import( $_stream, importexport_definition $_definition ) {
113
-		$import_csv = new importexport_import_csv( $_stream, array(
112
+	public function import($_stream, importexport_definition $_definition) {
113
+		$import_csv = new importexport_import_csv($_stream, array(
114 114
 			'fieldsep' => $_definition->plugin_options['fieldsep'],
115 115
 			'charset' => $_definition->plugin_options['charset'],
116 116
 		));
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		$this->user = $GLOBALS['egw_info']['user']['account_id'];
121 121
 
122 122
 		// dry run?
123
-		$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] :  false;
123
+		$this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false;
124 124
 
125 125
 		// fetch the infolog bo
126 126
 		$this->boinfolog = new infolog_bo();
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 		$import_csv->conversion_class = $this;
142 142
 
143 143
 		//check if file has a header lines
144
-		if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
144
+		if (isset($_definition->plugin_options['num_header_lines']) && $_definition->plugin_options['num_header_lines'] > 0) {
145 145
 			$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
146
-		} elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
146
+		} elseif (isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
147 147
 			// First method is preferred
148 148
 			$import_csv->skip_records(1);
149 149
 		}
@@ -168,18 +168,18 @@  discard block
 block discarded – undo
168 168
 		$this->errors = array();
169 169
 		$this->warnings = array();
170 170
 
171
-		while ( $record = $import_csv->get_record() ) {
171
+		while ($record = $import_csv->get_record()) {
172 172
 			$success = false;
173 173
 
174 174
 			// don't import empty records
175
-			if( count( array_unique( $record ) ) < 2 ) continue;
175
+			if (count(array_unique($record)) < 2) continue;
176 176
 
177 177
 			$lookups = $_lookups;
178 178
 
179 179
 			// Early detection of type, to load appropriate statuses
180
-			foreach(array($lookups['info_type'], array_map('strtolower',array_map('lang',$lookups['info_type']))) as $types)
180
+			foreach (array($lookups['info_type'], array_map('strtolower', array_map('lang', $lookups['info_type']))) as $types)
181 181
 			{
182
-				if($record['info_type'] && $key = array_search(strtolower($record['info_type']),$types))
182
+				if ($record['info_type'] && $key = array_search(strtolower($record['info_type']), $types))
183 183
 				{
184 184
 					$lookups['info_status'] = $this->boinfolog->status[$key];
185 185
 					break;
@@ -187,34 +187,34 @@  discard block
 block discarded – undo
187 187
 			}
188 188
 
189 189
 			$result = importexport_import_csv::convert($record, infolog_egw_record::$types, 'infolog', $lookups, $_definition->plugin_options['convert']);
190
-			if($result) $this->warnings[$import_csv->get_current_position()] = $result;
190
+			if ($result) $this->warnings[$import_csv->get_current_position()] = $result;
191 191
 
192 192
 			// Make sure type is valid
193
-			if(!$record['info_type'] || $record['info_type'] && !$this->boinfolog->enums['type'][$record['info_type']])
193
+			if (!$record['info_type'] || $record['info_type'] && !$this->boinfolog->enums['type'][$record['info_type']])
194 194
 			{
195 195
 				// Check for translated type
196
-				$un_trans = translation::get_message_id($record['info_type'],'infolog');
197
-				if($record['info_type'] && $this->boinfolog->enums['type'][$un_trans])
196
+				$un_trans = translation::get_message_id($record['info_type'], 'infolog');
197
+				if ($record['info_type'] && $this->boinfolog->enums['type'][$un_trans])
198 198
 				{
199 199
 					$record['info_type'] = $un_trans;
200 200
 				}
201 201
 				else
202 202
 				{
203
-					$this->errors[$import_csv->get_current_position()] .= ($this->errors[$import_csv->get_current_position()] ? "\n":'').
203
+					$this->errors[$import_csv->get_current_position()] .= ($this->errors[$import_csv->get_current_position()] ? "\n" : '').
204 204
 						lang('Unknown type: %1', $record['info_type']);
205 205
 				}
206 206
 			}
207 207
 
208 208
 			// Set default status for type, if not specified
209
-			if(!$record['info_status'] && $record['info_type'])
209
+			if (!$record['info_status'] && $record['info_type'])
210 210
 			{
211 211
 				$record['info_status'] = $this->boinfolog->status['defaults'][$record['info_type']];
212 212
 			}
213 213
 
214 214
 			// Set owner, unless it's supposed to come from CSV file
215
-			if($_definition->plugin_options['owner_from_csv'])
215
+			if ($_definition->plugin_options['owner_from_csv'])
216 216
 			{
217
-				if(!is_numeric($record['info_owner']))
217
+				if (!is_numeric($record['info_owner']))
218 218
 				{
219 219
 					$this->errors[$import_csv->get_current_position()] = lang(
220 220
 						'Invalid owner ID: %1.  Might be a bad field translation.  Used %2 instead.',
@@ -231,51 +231,51 @@  discard block
 block discarded – undo
231 231
 			if (!isset($record['info_owner'])) $record['info_owner'] = $GLOBALS['egw_info']['user']['account_id'];
232 232
 
233 233
 			// Responsible has to be an array
234
-			$record['info_responsible'] = $record['info_responsible'] ? explode(',',$record['info_responsible']) : 0;
234
+			$record['info_responsible'] = $record['info_responsible'] ? explode(',', $record['info_responsible']) : 0;
235 235
 
236 236
 			// Special values
237 237
 			if ($record['addressbook'] && !is_numeric($record['addressbook']))
238 238
 			{
239
-				list($lastname,$firstname,$org_name) = explode(',',$record['addressbook']);
240
-				$record['addressbook'] = importexport_basic_import_csv::addr_id($lastname,$firstname,$org_name);
239
+				list($lastname, $firstname, $org_name) = explode(',', $record['addressbook']);
240
+				$record['addressbook'] = importexport_basic_import_csv::addr_id($lastname, $firstname, $org_name);
241 241
 			}
242 242
 			if ($record['projectmanager'] && !is_numeric($record['projectmanager']))
243 243
 			{
244 244
 				$record['projectmanager'] = self::project_id($record['projectmanager']);
245 245
 			}
246 246
 
247
-			if ( $_definition->plugin_options['conditions'] )
247
+			if ($_definition->plugin_options['conditions'])
248 248
 			{
249
-				foreach ( $_definition->plugin_options['conditions'] as $condition )
249
+				foreach ($_definition->plugin_options['conditions'] as $condition)
250 250
 				{
251 251
 					$results = array();
252
-					switch ( $condition['type'] )
252
+					switch ($condition['type'])
253 253
 					{
254 254
 						// exists
255 255
 						case 'exists' :
256
-							if($record[$condition['string']]) {
257
-								$query['col_filter'] = array( $condition['string'] => $record[$condition['string']],);
256
+							if ($record[$condition['string']]) {
257
+								$query['col_filter'] = array($condition['string'] => $record[$condition['string']],);
258 258
 								// Needed to query custom fields
259
-								if($condition['string'][0] == '#') $query['custom_fields'] = true;
259
+								if ($condition['string'][0] == '#') $query['custom_fields'] = true;
260 260
 								$results = $this->boinfolog->search($query);
261 261
 							}
262 262
 
263
-							if ( is_array( $results ) && count( array_keys( $results )) >= 1) {
263
+							if (is_array($results) && count(array_keys($results)) >= 1) {
264 264
 								// apply action to all records matching this exists condition
265 265
 								$action = $condition['true'];
266
-								foreach ( (array)$results as $contact ) {
266
+								foreach ((array)$results as $contact) {
267 267
 									$record['info_id'] = $contact['info_id'];
268 268
 									$record['info_owner'] = $contact['info_owner'];
269
-									if ( $_definition->plugin_options['update_cats'] == 'add' ) {
270
-										if ( !is_array( $contact['cat_id'] ) ) $contact['cat_id'] = explode( ',', $contact['cat_id'] );
271
-										if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] );
272
-										$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $contact['cat_id'] ) ) );
269
+									if ($_definition->plugin_options['update_cats'] == 'add') {
270
+										if (!is_array($contact['cat_id'])) $contact['cat_id'] = explode(',', $contact['cat_id']);
271
+										if (!is_array($record['cat_id'])) $record['cat_id'] = explode(',', $record['cat_id']);
272
+										$record['cat_id'] = implode(',', array_unique(array_merge($record['cat_id'], $contact['cat_id'])));
273 273
 									}
274
-									$success = $this->action(  $action['action'], $record, $import_csv->get_current_position() );
274
+									$success = $this->action($action['action'], $record, $import_csv->get_current_position());
275 275
 								}
276 276
 							} else {
277 277
 								$action = $condition['false'];
278
-								$success = ($this->action(  $action['action'], $record, $import_csv->get_current_position() ));
278
+								$success = ($this->action($action['action'], $record, $import_csv->get_current_position()));
279 279
 							}
280 280
 							break;
281 281
 
@@ -290,14 +290,14 @@  discard block
 block discarded – undo
290 290
 			else
291 291
 			{
292 292
 				// unconditional insert
293
-				$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
293
+				$success = $this->action('insert', $record, $import_csv->get_current_position());
294 294
 			}
295
-			if($success) $count++;
296
-			if($this->warnings[$import_csv->get_current_position()]) {
297
-				$this->warnings[$import_csv->get_current_position()] .= "\nRecord:\n" .array2string($record);
295
+			if ($success) $count++;
296
+			if ($this->warnings[$import_csv->get_current_position()]) {
297
+				$this->warnings[$import_csv->get_current_position()] .= "\nRecord:\n".array2string($record);
298 298
 			}
299
-			if($this->errors[$import_csv->get_current_position()]) {
300
-				$this->errors[$import_csv->get_current_position()] .= "\nRecord:\n" .array2string($record);
299
+			if ($this->errors[$import_csv->get_current_position()]) {
300
+				$this->errors[$import_csv->get_current_position()] .= "\nRecord:\n".array2string($record);
301 301
 			}
302 302
 		}
303 303
 		return $count;
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	 * @param array $_data contact data for the action
311 311
 	 * @return bool success or not
312 312
 	 */
313
-	private function action ( $_action, $_data, $record_num = 0 ) {
313
+	private function action($_action, $_data, $record_num = 0) {
314 314
 		$result = true;
315 315
 		switch ($_action) {
316 316
 			case 'none' :
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 				// Only update if there are changes
320 320
 				$old = $this->boinfolog->read($_data['info_id']);
321 321
 
322
-				if(!$this->definition->plugin_options['change_owner']) {
322
+				if (!$this->definition->plugin_options['change_owner']) {
323 323
 					// Don't change addressbook of an existing contact
324 324
 					unset($_data['owner']);
325 325
 				}
@@ -327,19 +327,19 @@  discard block
 block discarded – undo
327 327
 				// Merge to deal with fields not in import record
328 328
 				$_data = array_merge($old, $_data);
329 329
 				$changed = $this->tracking->changed_fields($_data, $old);
330
-				if(count($changed) == 0 && !$this->definition->plugin_options['update_timestamp']) {
330
+				if (count($changed) == 0 && !$this->definition->plugin_options['update_timestamp']) {
331 331
 					break;
332 332
 				}
333 333
 
334 334
 				// Fall through
335 335
 			case 'insert' :
336
-				if ( $this->dry_run ) {
336
+				if ($this->dry_run) {
337 337
 					//print_r($_data);
338 338
 
339 339
 					// Check for link during dry run
340
-					if($_data['link_custom'])
340
+					if ($_data['link_custom'])
341 341
 					{
342
-						list($app, $app_id) = explode(':', $_data['link_custom'],2);
342
+						list($app, $app_id) = explode(':', $_data['link_custom'], 2);
343 343
 						$app_id = $this->link_by_cf($record_num, $app, $field, $app_id);
344 344
 					}
345 345
 
@@ -347,12 +347,12 @@  discard block
 block discarded – undo
347 347
 					break;
348 348
 				} else {
349 349
 					$result = $this->boinfolog->write(
350
-						$_data, true, 2,true, 	// 2 = dont touch modification date
350
+						$_data, true, 2, true, // 2 = dont touch modification date
351 351
 						$this->definition->plugin_options['no_notification']
352 352
 					);
353
-					if(!$result)
353
+					if (!$result)
354 354
 					{
355
-						if($result === false)
355
+						if ($result === false)
356 356
 						{
357 357
 							$this->errors[$record_num] = lang('Permissions error - %1 could not %2',
358 358
 								$GLOBALS['egw']->accounts->id2name($_data['info_owner']),
@@ -375,17 +375,17 @@  discard block
 block discarded – undo
375 375
 		}
376 376
 
377 377
 		// Process some additional fields
378
-		if(!is_numeric($result)) {
378
+		if (!is_numeric($result)) {
379 379
 			return $result;
380 380
 		}
381 381
 		$info_link_id = $_data['info_link_id'];
382
-		foreach(self::$special_fields as $field => $desc) {
383
-			if(!$_data[$field]) continue;
384
-			if(strpos($field, 'link') === 0) {
385
-				list($app, $app_id) = explode(':', $_data[$field],2);
382
+		foreach (self::$special_fields as $field => $desc) {
383
+			if (!$_data[$field]) continue;
384
+			if (strpos($field, 'link') === 0) {
385
+				list($app, $app_id) = explode(':', $_data[$field], 2);
386 386
 
387 387
 				// Linking to another entry based on matching custom fields
388
-				if($field == 'link_custom')
388
+				if ($field == 'link_custom')
389 389
 				{
390 390
 					$app_id = $this->link_by_cf($record_num, $app, $field, $app_id);
391 391
 				}
@@ -396,14 +396,14 @@  discard block
 block discarded – undo
396 396
 			if ($app && $app_id) {
397 397
 				$id = $_data['info_id'] ? $_data['info_id'] : (int)$result;
398 398
 				//echo "<p>linking infolog:$id with $app:$app_id</p>\n";
399
-				$link_id = egw_link::link('infolog',$id,$app,$app_id);
399
+				$link_id = egw_link::link('infolog', $id, $app, $app_id);
400 400
 				if ($link_id && !$info_link_id)
401 401
 				{
402 402
 					$to_write = array(
403 403
 						'info_id'      => $id,
404 404
 						'info_link_id' => $link_id,
405 405
 					);
406
-					$this->boinfolog->write($to_write,False,false,true,true);	// last true = no notifications, as no real change
406
+					$this->boinfolog->write($to_write, False, false, true, true); // last true = no notifications, as no real change
407 407
 					$info_link_id = $link_id;
408 408
 				}
409 409
 			}
@@ -530,18 +530,18 @@  discard block
 block discarded – undo
530 530
 	{
531 531
 		$app_id = false;
532 532
 
533
-		list($custom_field, $value) = explode(':',$value);
533
+		list($custom_field, $value) = explode(':', $value);
534 534
 		// Find matching entry
535
-		if($app && $custom_field && $value)
535
+		if ($app && $custom_field && $value)
536 536
 		{
537 537
 			$cfs = config::get_customfields($app);
538 538
 			// Error if no custom fields, probably something wrong in definition
539
-			if(!$cfs[$custom_field])
539
+			if (!$cfs[$custom_field])
540 540
 			{
541 541
 				// Check for users specifing label instead of name
542
-				foreach($cfs as $name => $settings)
542
+				foreach ($cfs as $name => $settings)
543 543
 				{
544
-					if(strtolower($settings['label']) == strtolower($custom_field))
544
+					if (strtolower($settings['label']) == strtolower($custom_field))
545 545
 					{
546 546
 						$custom_field = $name;
547 547
 						break;
@@ -550,23 +550,23 @@  discard block
 block discarded – undo
550 550
 			}
551 551
 
552 552
 			// Couldn't find field, give an error - something's wrong
553
-			if(!$cfs[$custom_field] && !$cfs[substr($custom_field,1)]) {
553
+			if (!$cfs[$custom_field] && !$cfs[substr($custom_field, 1)]) {
554 554
 				$this->errors[$record_num] .= lang('No custom field "%1" for %2.',
555 555
 					$custom_field, lang($app));
556 556
 				return false;
557 557
 			}
558
-			if($custom_field[0] != '#') $custom_field = '#' . $custom_field;
558
+			if ($custom_field[0] != '#') $custom_field = '#'.$custom_field;
559 559
 
560 560
 			// Search
561
-			if(egw_link::get_registry($app, 'query'))
561
+			if (egw_link::get_registry($app, 'query'))
562 562
 			{
563
-				$options = array('filter' => array("$custom_field = " . $GLOBALS['egw']->db->quote($value)));
563
+				$options = array('filter' => array("$custom_field = ".$GLOBALS['egw']->db->quote($value)));
564 564
 				$result = egw_link::query($app, '', $options);
565 565
 
566 566
 				// Only one allowed
567
-				if(count($result) != 1)
567
+				if (count($result) != 1)
568 568
 				{
569
-					$this->warnings[$record_num] .= ($this->warnings[$record_num] ? "\n" : '') .
569
+					$this->warnings[$record_num] .= ($this->warnings[$record_num] ? "\n" : '').
570 570
 						lang('Unable to link to %3 by custom field "%1": "%4".  %2 matches.',
571 571
 						$custom_field, count($result), lang($app), $options['filter'][0]
572 572
 					);
Please login to merge, or discard this patch.
Braces   +112 added lines, -43 removed lines patch added patch discarded remove patch
@@ -14,7 +14,8 @@  discard block
 block discarded – undo
14 14
 /**
15 15
  * class import_csv for infolog
16 16
  */
17
-class infolog_import_infologs_csv implements importexport_iface_import_plugin  {
17
+class infolog_import_infologs_csv implements importexport_iface_import_plugin
18
+{
18 19
 
19 20
 	private static $plugin_options = array(
20 21
 		'fieldsep', 		// char
@@ -109,7 +110,8 @@  discard block
 block discarded – undo
109 110
 	 * @param string $_charset
110 111
 	 * @param definition $_definition
111 112
 	 */
112
-	public function import( $_stream, importexport_definition $_definition ) {
113
+	public function import( $_stream, importexport_definition $_definition )
114
+	{
113 115
 		$import_csv = new importexport_import_csv( $_stream, array(
114 116
 			'fieldsep' => $_definition->plugin_options['fieldsep'],
115 117
 			'charset' => $_definition->plugin_options['charset'],
@@ -141,9 +143,12 @@  discard block
 block discarded – undo
141 143
 		$import_csv->conversion_class = $this;
142 144
 
143 145
 		//check if file has a header lines
144
-		if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
146
+		if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0)
147
+		{
145 148
 			$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
146
-		} elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
149
+		}
150
+		elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line'])
151
+		{
147 152
 			// First method is preferred
148 153
 			$import_csv->skip_records(1);
149 154
 		}
@@ -168,11 +173,15 @@  discard block
 block discarded – undo
168 173
 		$this->errors = array();
169 174
 		$this->warnings = array();
170 175
 
171
-		while ( $record = $import_csv->get_record() ) {
176
+		while ( $record = $import_csv->get_record() )
177
+		{
172 178
 			$success = false;
173 179
 
174 180
 			// don't import empty records
175
-			if( count( array_unique( $record ) ) < 2 ) continue;
181
+			if( count( array_unique( $record ) ) < 2 )
182
+			{
183
+				continue;
184
+			}
176 185
 
177 186
 			$lookups = $_lookups;
178 187
 
@@ -187,7 +196,10 @@  discard block
 block discarded – undo
187 196
 			}
188 197
 
189 198
 			$result = importexport_import_csv::convert($record, infolog_egw_record::$types, 'infolog', $lookups, $_definition->plugin_options['convert']);
190
-			if($result) $this->warnings[$import_csv->get_current_position()] = $result;
199
+			if($result)
200
+			{
201
+				$this->warnings[$import_csv->get_current_position()] = $result;
202
+			}
191 203
 
192 204
 			// Make sure type is valid
193 205
 			if(!$record['info_type'] || $record['info_type'] && !$this->boinfolog->enums['type'][$record['info_type']])
@@ -228,7 +240,10 @@  discard block
 block discarded – undo
228 240
 			{
229 241
 				$record['info_owner'] = $_definition->plugin_options['record_owner'];
230 242
 			}
231
-			if (!isset($record['info_owner'])) $record['info_owner'] = $GLOBALS['egw_info']['user']['account_id'];
243
+			if (!isset($record['info_owner']))
244
+			{
245
+				$record['info_owner'] = $GLOBALS['egw_info']['user']['account_id'];
246
+			}
232 247
 
233 248
 			// Responsible has to be an array
234 249
 			$record['info_responsible'] = $record['info_responsible'] ? explode(',',$record['info_responsible']) : 0;
@@ -253,27 +268,42 @@  discard block
 block discarded – undo
253 268
 					{
254 269
 						// exists
255 270
 						case 'exists' :
256
-							if($record[$condition['string']]) {
271
+							if($record[$condition['string']])
272
+							{
257 273
 								$query['col_filter'] = array( $condition['string'] => $record[$condition['string']],);
258 274
 								// Needed to query custom fields
259
-								if($condition['string'][0] == '#') $query['custom_fields'] = true;
275
+								if($condition['string'][0] == '#')
276
+								{
277
+									$query['custom_fields'] = true;
278
+								}
260 279
 								$results = $this->boinfolog->search($query);
261 280
 							}
262 281
 
263
-							if ( is_array( $results ) && count( array_keys( $results )) >= 1) {
282
+							if ( is_array( $results ) && count( array_keys( $results )) >= 1)
283
+							{
264 284
 								// apply action to all records matching this exists condition
265 285
 								$action = $condition['true'];
266
-								foreach ( (array)$results as $contact ) {
286
+								foreach ( (array)$results as $contact )
287
+								{
267 288
 									$record['info_id'] = $contact['info_id'];
268 289
 									$record['info_owner'] = $contact['info_owner'];
269
-									if ( $_definition->plugin_options['update_cats'] == 'add' ) {
270
-										if ( !is_array( $contact['cat_id'] ) ) $contact['cat_id'] = explode( ',', $contact['cat_id'] );
271
-										if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] );
290
+									if ( $_definition->plugin_options['update_cats'] == 'add' )
291
+									{
292
+										if ( !is_array( $contact['cat_id'] ) )
293
+										{
294
+											$contact['cat_id'] = explode( ',', $contact['cat_id'] );
295
+										}
296
+										if ( !is_array( $record['cat_id'] ) )
297
+										{
298
+											$record['cat_id'] = explode( ',', $record['cat_id'] );
299
+										}
272 300
 										$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $contact['cat_id'] ) ) );
273 301
 									}
274 302
 									$success = $this->action(  $action['action'], $record, $import_csv->get_current_position() );
275 303
 								}
276
-							} else {
304
+							}
305
+							else
306
+							{
277 307
 								$action = $condition['false'];
278 308
 								$success = ($this->action(  $action['action'], $record, $import_csv->get_current_position() ));
279 309
 							}
@@ -284,7 +314,10 @@  discard block
 block discarded – undo
284 314
 							die('condition / action not supported!!!');
285 315
 							break;
286 316
 					}
287
-					if ($action['last']) break;
317
+					if ($action['last'])
318
+					{
319
+						break;
320
+					}
288 321
 				}
289 322
 			}
290 323
 			else
@@ -292,11 +325,16 @@  discard block
 block discarded – undo
292 325
 				// unconditional insert
293 326
 				$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
294 327
 			}
295
-			if($success) $count++;
296
-			if($this->warnings[$import_csv->get_current_position()]) {
328
+			if($success)
329
+			{
330
+				$count++;
331
+			}
332
+			if($this->warnings[$import_csv->get_current_position()])
333
+			{
297 334
 				$this->warnings[$import_csv->get_current_position()] .= "\nRecord:\n" .array2string($record);
298 335
 			}
299
-			if($this->errors[$import_csv->get_current_position()]) {
336
+			if($this->errors[$import_csv->get_current_position()])
337
+			{
300 338
 				$this->errors[$import_csv->get_current_position()] .= "\nRecord:\n" .array2string($record);
301 339
 			}
302 340
 		}
@@ -310,16 +348,19 @@  discard block
 block discarded – undo
310 348
 	 * @param array $_data contact data for the action
311 349
 	 * @return bool success or not
312 350
 	 */
313
-	private function action ( $_action, $_data, $record_num = 0 ) {
351
+	private function action ( $_action, $_data, $record_num = 0 )
352
+	{
314 353
 		$result = true;
315
-		switch ($_action) {
354
+		switch ($_action)
355
+		{
316 356
 			case 'none' :
317 357
 				return true;
318 358
 			case 'update' :
319 359
 				// Only update if there are changes
320 360
 				$old = $this->boinfolog->read($_data['info_id']);
321 361
 
322
-				if(!$this->definition->plugin_options['change_owner']) {
362
+				if(!$this->definition->plugin_options['change_owner'])
363
+				{
323 364
 					// Don't change addressbook of an existing contact
324 365
 					unset($_data['owner']);
325 366
 				}
@@ -327,13 +368,15 @@  discard block
 block discarded – undo
327 368
 				// Merge to deal with fields not in import record
328 369
 				$_data = array_merge($old, $_data);
329 370
 				$changed = $this->tracking->changed_fields($_data, $old);
330
-				if(count($changed) == 0 && !$this->definition->plugin_options['update_timestamp']) {
371
+				if(count($changed) == 0 && !$this->definition->plugin_options['update_timestamp'])
372
+				{
331 373
 					break;
332 374
 				}
333 375
 
334 376
 				// Fall through
335 377
 			case 'insert' :
336
-				if ( $this->dry_run ) {
378
+				if ( $this->dry_run )
379
+				{
337 380
 					//print_r($_data);
338 381
 
339 382
 					// Check for link during dry run
@@ -345,7 +388,9 @@  discard block
 block discarded – undo
345 388
 
346 389
 					$this->results[$_action]++;
347 390
 					break;
348
-				} else {
391
+				}
392
+				else
393
+				{
349 394
 					$result = $this->boinfolog->write(
350 395
 						$_data, true, 2,true, 	// 2 = dont touch modification date
351 396
 						$this->definition->plugin_options['no_notification']
@@ -375,13 +420,19 @@  discard block
 block discarded – undo
375 420
 		}
376 421
 
377 422
 		// Process some additional fields
378
-		if(!is_numeric($result)) {
423
+		if(!is_numeric($result))
424
+		{
379 425
 			return $result;
380 426
 		}
381 427
 		$info_link_id = $_data['info_link_id'];
382
-		foreach(self::$special_fields as $field => $desc) {
383
-			if(!$_data[$field]) continue;
384
-			if(strpos($field, 'link') === 0) {
428
+		foreach(self::$special_fields as $field => $desc)
429
+		{
430
+			if(!$_data[$field])
431
+			{
432
+				continue;
433
+			}
434
+			if(strpos($field, 'link') === 0)
435
+			{
385 436
 				list($app, $app_id) = explode(':', $_data[$field],2);
386 437
 
387 438
 				// Linking to another entry based on matching custom fields
@@ -389,11 +440,14 @@  discard block
 block discarded – undo
389 440
 				{
390 441
 					$app_id = $this->link_by_cf($record_num, $app, $field, $app_id);
391 442
 				}
392
-			} else {
443
+			}
444
+			else
445
+			{
393 446
 				$app = $field;
394 447
 				$app_id = $_data[$field];
395 448
 			}
396
-			if ($app && $app_id) {
449
+			if ($app && $app_id)
450
+			{
397 451
 				$id = $_data['info_id'] ? $_data['info_id'] : (int)$result;
398 452
 				//echo "<p>linking infolog:$id with $app:$app_id</p>\n";
399 453
 				$link_id = egw_link::link('infolog',$id,$app,$app_id);
@@ -416,7 +470,8 @@  discard block
 block discarded – undo
416 470
 	 *
417 471
 	 * @return string name
418 472
 	 */
419
-	public static function get_name() {
473
+	public static function get_name()
474
+	{
420 475
 		return lang('Infolog CSV import');
421 476
 	}
422 477
 
@@ -425,7 +480,8 @@  discard block
 block discarded – undo
425 480
 	 *
426 481
 	 * @return string descriprion
427 482
 	 */
428
-	public static function get_description() {
483
+	public static function get_description()
484
+	{
429 485
 		return lang("Imports entries into the infolog from a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators.");
430 486
 	}
431 487
 
@@ -434,7 +490,8 @@  discard block
 block discarded – undo
434 490
 	 *
435 491
 	 * @return string suffix (comma seperated)
436 492
 	 */
437
-	public static function get_filesuffix() {
493
+	public static function get_filesuffix()
494
+	{
438 495
 		return 'csv';
439 496
 	}
440 497
 
@@ -450,7 +507,8 @@  discard block
 block discarded – undo
450 507
 	 * 		preserv		=> array,
451 508
 	 * )
452 509
 	 */
453
-	public function get_options_etpl() {
510
+	public function get_options_etpl()
511
+	{
454 512
 		// lets do it!
455 513
 	}
456 514
 
@@ -459,7 +517,8 @@  discard block
 block discarded – undo
459 517
 	 *
460 518
 	 * @return string etemplate name
461 519
 	 */
462
-	public function get_selectors_etpl() {
520
+	public function get_selectors_etpl()
521
+	{
463 522
 		// lets do it!
464 523
 	}
465 524
 
@@ -471,7 +530,8 @@  discard block
 block discarded – undo
471 530
 	*       record_# => warning message
472 531
 	*       )
473 532
 	*/
474
-	public function get_warnings() {
533
+	public function get_warnings()
534
+	{
475 535
 		return $this->warnings;
476 536
 	}
477 537
 
@@ -483,7 +543,8 @@  discard block
 block discarded – undo
483 543
 	*       record_# => error message
484 544
 	*       )
485 545
 	*/
486
-	public function get_errors() {
546
+	public function get_errors()
547
+	{
487 548
 		return $this->errors;
488 549
 	}
489 550
 
@@ -495,7 +556,8 @@  discard block
 block discarded – undo
495 556
 	*       action => record count
496 557
 	* )
497 558
 	*/
498
-	public function get_results() {
559
+	public function get_results()
560
+	{
499 561
 		return $this->results;
500 562
 	}
501 563
 	// end of iface_export_plugin
@@ -505,7 +567,10 @@  discard block
 block discarded – undo
505 567
 	{
506 568
 		static $boprojects;
507 569
 
508
-		if (!$num_or_title) return false;
570
+		if (!$num_or_title)
571
+		{
572
+			return false;
573
+		}
509 574
 
510 575
 		if (!is_object($boprojects))
511 576
 		{
@@ -550,12 +615,16 @@  discard block
 block discarded – undo
550 615
 			}
551 616
 
552 617
 			// Couldn't find field, give an error - something's wrong
553
-			if(!$cfs[$custom_field] && !$cfs[substr($custom_field,1)]) {
618
+			if(!$cfs[$custom_field] && !$cfs[substr($custom_field,1)])
619
+			{
554 620
 				$this->errors[$record_num] .= lang('No custom field "%1" for %2.',
555 621
 					$custom_field, lang($app));
556 622
 				return false;
557 623
 			}
558
-			if($custom_field[0] != '#') $custom_field = '#' . $custom_field;
624
+			if($custom_field[0] != '#')
625
+			{
626
+				$custom_field = '#' . $custom_field;
627
+			}
559 628
 
560 629
 			// Search
561 630
 			if(egw_link::get_registry($app, 'query'))
Please login to merge, or discard this patch.
infolog/inc/class.infolog_tracking.inc.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -125,7 +125,6 @@
 block discarded – undo
125 125
 	/**
126 126
 	 * Constructor
127 127
 	 *
128
-	 * @param botracker $botracker
129 128
 	 * @return tracker_tracking
130 129
 	 */
131 130
 	function __construct(&$infolog_bo)
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	function __construct(&$infolog_bo)
129 129
 	{
130
-		parent::__construct('infolog');	// add custom fields from infolog
130
+		parent::__construct('infolog'); // add custom fields from infolog
131 131
 
132
-		$this->infolog =& $infolog_bo;
132
+		$this->infolog = & $infolog_bo;
133 133
 	}
134 134
 
135 135
 	/**
@@ -141,23 +141,23 @@  discard block
 block discarded – undo
141 141
 	 * @param array $old
142 142
 	 * @return string
143 143
 	 */
144
-	function get_subject($data,$old)
144
+	function get_subject($data, $old)
145 145
 	{
146 146
 		if ($data['prefix'])
147 147
 		{
148
-			$prefix = $data['prefix'];	// async notification
148
+			$prefix = $data['prefix']; // async notification
149 149
 		}
150 150
 		elseif (!$old || $old['info_status'] == 'deleted')
151 151
 		{
152
-			$prefix = lang('New %1',lang($this->infolog->enums['type'][$data['info_type']]));
152
+			$prefix = lang('New %1', lang($this->infolog->enums['type'][$data['info_type']]));
153 153
 		}
154
-		elseif($data['info_status'] == 'deleted')
154
+		elseif ($data['info_status'] == 'deleted')
155 155
 		{
156
-			$prefix = lang('%1 deleted',lang($this->infolog->enums['type'][$data['info_type']]));
156
+			$prefix = lang('%1 deleted', lang($this->infolog->enums['type'][$data['info_type']]));
157 157
 		}
158 158
 		else
159 159
 		{
160
-			$prefix = lang('%1 modified',lang($this->infolog->enums['type'][$data['info_type']]));
160
+			$prefix = lang('%1 modified', lang($this->infolog->enums['type'][$data['info_type']]));
161 161
 		}
162 162
 		return $prefix.': '.$data['info_subject'];
163 163
 	}
@@ -169,22 +169,22 @@  discard block
 block discarded – undo
169 169
 	 * @param array $old
170 170
 	 * @return string
171 171
 	 */
172
-	function get_message($data,$old)
172
+	function get_message($data, $old)
173 173
 	{
174
-		if ($data['message']) return $data['message'];	// async notification
174
+		if ($data['message']) return $data['message']; // async notification
175 175
 
176 176
 		if (!$old || $old['info_status'] == 'deleted')
177 177
 		{
178
-			return lang('New %1 created by %2 at %3',lang($this->infolog->enums['type'][$data['info_type']]),
179
-				common::grab_owner_name($this->infolog->user),$this->datetime('now'));
178
+			return lang('New %1 created by %2 at %3', lang($this->infolog->enums['type'][$data['info_type']]),
179
+				common::grab_owner_name($this->infolog->user), $this->datetime('now'));
180 180
 		}
181
-		elseif($data['info_status'] == 'deleted')
181
+		elseif ($data['info_status'] == 'deleted')
182 182
 		{
183
-			return lang('%1 deleted by %2 at %3',lang($this->infolog->enums['type'][$data['info_type']]),
183
+			return lang('%1 deleted by %2 at %3', lang($this->infolog->enums['type'][$data['info_type']]),
184 184
 				common::grab_owner_name($data['info_modifier']),
185 185
 				$this->datetime($data['info_datemodified']));
186 186
 		}
187
-		return lang('%1 modified by %2 at %3',lang($this->infolog->enums['type'][$data['info_type']]),
187
+		return lang('%1 modified by %2 at %3', lang($this->infolog->enums['type'][$data['info_type']]),
188 188
 			common::grab_owner_name($data['info_modifier']),
189 189
 			$this->datetime($data['info_datemodified']));
190 190
 	}
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
 	 * @param int|string $receiver nummeric account_id or email address
197 197
 	 * @return array of details as array with values for keys 'label','value','type'
198 198
 	 */
199
-	function get_details($data,$receiver=null)
199
+	function get_details($data, $receiver = null)
200 200
 	{
201
-		unset($receiver);	// not used, but required function signature
201
+		unset($receiver); // not used, but required function signature
202 202
 		//error_log(__METHOD__.__LINE__.' Data:'.array2string($data));
203 203
 		$responsible = array();
204 204
 		if ($data['info_responsible'])
205 205
 		{
206
-			foreach($data['info_responsible'] as $uid)
206
+			foreach ($data['info_responsible'] as $uid)
207 207
 			{
208 208
 				$responsible[] = common::grab_owner_name($uid);
209 209
 			}
@@ -212,31 +212,31 @@  discard block
 block discarded – undo
212 212
 		{
213 213
 			$id = ' #'.$data['info_id'];
214 214
 		}
215
-		foreach(array(
215
+		foreach (array(
216 216
 			'info_type'      => lang($this->infolog->enums['type'][$data['info_type']]).$id,
217 217
 			'info_from'      => $data['info_from'],
218 218
 			'info_addr'      => $data['info_addr'],
219 219
 			'info_cat'       => $data['info_cat'] ? $GLOBALS['egw']->categories->id2name($data['info_cat']) : '',
220 220
 			'info_priority'  => lang($this->infolog->enums['priority'][$data['info_priority']]),
221 221
 			'info_owner'     => common::grab_owner_name($data['info_owner']),
222
-			'info_status'    => lang($data['info_status']=='deleted'?'deleted':$this->infolog->status[$data['info_type']][$data['info_status']]),
222
+			'info_status'    => lang($data['info_status'] == 'deleted' ? 'deleted' : $this->infolog->status[$data['info_type']][$data['info_status']]),
223 223
 			'info_percent'   => (int)$data['info_percent'].'%',
224 224
 			'info_datecompleted' => $data['info_datecompleted'] ? $this->datetime($data['info_datecompleted']) : '',
225 225
 			'info_location'  => $data['info_location'],
226
-			'info_startdate' => $data['info_startdate'] ? $this->datetime($data['info_startdate'],null) : '',
227
-			'info_enddate'   => $data['info_enddate'] ? $this->datetime($data['info_enddate'],null) : '',
228
-			'info_responsible' => implode(', ',$responsible),
226
+			'info_startdate' => $data['info_startdate'] ? $this->datetime($data['info_startdate'], null) : '',
227
+			'info_enddate'   => $data['info_enddate'] ? $this->datetime($data['info_enddate'], null) : '',
228
+			'info_responsible' => implode(', ', $responsible),
229 229
 			'info_subject'   => $data['info_subject'],
230 230
 		) as $name => $value)
231 231
 		{
232 232
 			//error_log(__METHOD__.__LINE__.' Key:'.$name.' val:'.array2string($value));
233
-			if ($name=='info_from' && empty($value) && !empty($data['info_contact']) && is_array($data['link_to']['to_id']))
233
+			if ($name == 'info_from' && empty($value) && !empty($data['info_contact']) && is_array($data['link_to']['to_id']))
234 234
 			{
235 235
 				$lkeys = array_keys($data['link_to']['to_id']);
236
-				if (in_array($data['info_contact'],$lkeys))
236
+				if (in_array($data['info_contact'], $lkeys))
237 237
 				{
238
-					list($app,$id) = explode(':',$data['info_contact']);
239
-					if (!empty($app)&&!empty($id)) $value = egw_link::title($app,$id);
238
+					list($app, $id) = explode(':', $data['info_contact']);
239
+					if (!empty($app) && !empty($id)) $value = egw_link::title($app, $id);
240 240
 				}
241 241
 			}
242 242
 			$details[$name] = array(
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * @param boolean $skip_notification = false do NOT send any notification
269 269
 	 * @return int|boolean false on error, integer number of changes logged or true for new entries ($old == null)
270 270
 	 */
271
-	public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null,$skip_notification=false)
271
+	public function track(array $data, array $old = null, $user = null, $deleted = null, array $changed_fields = null, $skip_notification = false)
272 272
 	{
273 273
 		//error_log(__METHOD__.__LINE__.' notify?'.($skip_notification?'no':'yes').function_backtrace());
274 274
 		$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
@@ -277,23 +277,23 @@  discard block
 block discarded – undo
277 277
 
278 278
 		if ($old && $this->field2history)
279 279
 		{
280
-			$changes = $this->save_history($data,$old,$deleted,$changed_fields);
280
+			$changes = $this->save_history($data, $old, $deleted, $changed_fields);
281 281
 		}
282 282
 
283 283
 		// Don't notify if the only change was to the modified date
284
-		if(is_null($changed_fields))
284
+		if (is_null($changed_fields))
285 285
 		{
286 286
 			$changed_fields = $this->changed_fields($data, $old);
287 287
 			$changes = count($changed_fields); // we need that since TRUE evaluates to 1
288 288
 		}
289 289
 		//error_log(__METHOD__.__LINE__.array2string($changed_fields));
290
-		if(is_array($changed_fields) && $changes == 1 && in_array('info_datemodified', $changed_fields))
290
+		if (is_array($changed_fields) && $changes == 1 && in_array('info_datemodified', $changed_fields))
291 291
 		{
292 292
 			return count($changes);
293 293
 		}
294 294
 
295 295
 		// do not run do_notifications if we have no changes
296
-		if ($changes && !$skip_notification && !$this->do_notifications($data,$old,$deleted))
296
+		if ($changes && !$skip_notification && !$this->do_notifications($data, $old, $deleted))
297 297
 		{
298 298
 			$changes = false;
299 299
 		}
@@ -311,16 +311,16 @@  discard block
 block discarded – undo
311 311
 	 * @param array $old = null old/last state of the entry or null for a new entry
312 312
 	 * @return mixed
313 313
 	 */
314
-	function get_config($name,$data,$old=null)
314
+	function get_config($name, $data, $old = null)
315 315
 	{
316
-		unset($old);	// not used, but required function signature
317
-		switch($name)
316
+		unset($old); // not used, but required function signature
317
+		switch ($name)
318 318
 		{
319 319
 			case 'copy':	// include the info_cc addresses
320
-				if ($data['info_access'] == 'private') return array();	// no copies for private entries
320
+				if ($data['info_access'] == 'private') return array(); // no copies for private entries
321 321
 				if ($data['info_cc'])
322 322
 				{
323
-					$config = preg_split('/, ?/',$data['info_cc']);
323
+					$config = preg_split('/, ?/', $data['info_cc']);
324 324
 				}
325 325
 				else
326 326
 				{
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 				break;
330 330
 			case self::CUSTOM_NOTIFICATION:
331 331
 				$info_config = config::read('infolog');
332
-				if(!$info_config[self::CUSTOM_NOTIFICATION])
332
+				if (!$info_config[self::CUSTOM_NOTIFICATION])
333 333
 				{
334 334
 					return '';
335 335
 				}
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 				$global = $info_config[self::CUSTOM_NOTIFICATION]['~global~'];
339 339
 
340 340
 				// Disabled
341
-				if(!$type_config['use_custom'] && !$global['use_custom']) return '';
341
+				if (!$type_config['use_custom'] && !$global['use_custom']) return '';
342 342
 
343 343
 				// Type or globabl
344 344
 				$config = trim(strip_tags($type_config['message'])) != '' && $type_config['use_custom'] ? $type_config['message'] : $global['message'];
Please login to merge, or discard this patch.
Braces   +22 added lines, -5 removed lines patch added patch discarded remove patch
@@ -171,7 +171,11 @@  discard block
 block discarded – undo
171 171
 	 */
172 172
 	function get_message($data,$old)
173 173
 	{
174
-		if ($data['message']) return $data['message'];	// async notification
174
+		if ($data['message'])
175
+		{
176
+			return $data['message'];
177
+		}
178
+		// async notification
175 179
 
176 180
 		if (!$old || $old['info_status'] == 'deleted')
177 181
 		{
@@ -236,14 +240,20 @@  discard block
 block discarded – undo
236 240
 				if (in_array($data['info_contact'],$lkeys))
237 241
 				{
238 242
 					list($app,$id) = explode(':',$data['info_contact']);
239
-					if (!empty($app)&&!empty($id)) $value = egw_link::title($app,$id);
243
+					if (!empty($app)&&!empty($id))
244
+					{
245
+						$value = egw_link::title($app,$id);
246
+					}
240 247
 				}
241 248
 			}
242 249
 			$details[$name] = array(
243 250
 				'label' => lang($this->field2label[$name]),
244 251
 				'value' => $value,
245 252
 			);
246
-			if ($name == 'info_subject') $details[$name]['type'] = 'summary';
253
+			if ($name == 'info_subject')
254
+			{
255
+				$details[$name]['type'] = 'summary';
256
+			}
247 257
 		}
248 258
 		$details['info_des'] = array(
249 259
 			'value' => $data['info_des'],
@@ -317,7 +327,11 @@  discard block
 block discarded – undo
317 327
 		switch($name)
318 328
 		{
319 329
 			case 'copy':	// include the info_cc addresses
320
-				if ($data['info_access'] == 'private') return array();	// no copies for private entries
330
+				if ($data['info_access'] == 'private')
331
+				{
332
+					return array();
333
+				}
334
+				// no copies for private entries
321 335
 				if ($data['info_cc'])
322 336
 				{
323 337
 					$config = preg_split('/, ?/',$data['info_cc']);
@@ -338,7 +352,10 @@  discard block
 block discarded – undo
338 352
 				$global = $info_config[self::CUSTOM_NOTIFICATION]['~global~'];
339 353
 
340 354
 				// Disabled
341
-				if(!$type_config['use_custom'] && !$global['use_custom']) return '';
355
+				if(!$type_config['use_custom'] && !$global['use_custom'])
356
+				{
357
+					return '';
358
+				}
342 359
 
343 360
 				// Type or globabl
344 361
 				$config = trim(strip_tags($type_config['message'])) != '' && $type_config['use_custom'] ? $type_config['message'] : $global['message'];
Please login to merge, or discard this patch.