Completed
Push — 16.1 ( 4f61bc...7abf1b )
by Nathan
32:13 queued 18:43
created
importexport/inc/class.importexport_export_ui.inc.php 1 patch
Braces   +129 added lines, -53 removed lines patch added patch discarded remove patch
@@ -18,7 +18,8 @@  discard block
 block discarded – undo
18 18
  * userinterface for exports
19 19
  *
20 20
  */
21
-class importexport_export_ui {
21
+class importexport_export_ui
22
+{
22 23
 	const _appname = 'importexport';
23 24
 
24 25
 	public $public_functions = array(
@@ -35,7 +36,8 @@  discard block
 block discarded – undo
35 36
 	 */
36 37
 	private $export_plugins;
37 38
 
38
-	public function __construct() {
39
+	public function __construct()
40
+	{
39 41
 		Framework::includeJS('.','export_dialog','importexport');
40 42
 		Framework::includeJS('.','importexport','importexport');
41 43
 		$this->user = $GLOBALS['egw_info']['user']['user_id'];
@@ -43,7 +45,8 @@  discard block
 block discarded – undo
43 45
 
44 46
 	}
45 47
 
46
-	public function export_dialog($_content=array()) {
48
+	public function export_dialog($_content=array())
49
+	{
47 50
 		$tabs = 'general_tab|selection_tab|options_tab';
48 51
 		$sel_options = array();
49 52
 		$readonlys = array();
@@ -54,14 +57,22 @@  discard block
 block discarded – undo
54 57
 		$_definition = $_content['definition'] ? $_content['definition'] : $_GET['definition'];
55 58
 		$_plugin = $_content['plugin'] ? $_content['plugin'] : $_GET['plugin'];
56 59
 		// Select all from context menu, means use all search results, not just selected
57
-		if($_GET['select_all'] == 'true') $_GET['selection'] = 'search';
60
+		if($_GET['select_all'] == 'true')
61
+		{
62
+			$_GET['selection'] = 'search';
63
+		}
58 64
 		$_selection = $_content['selection'] ? $_content['selection'] : $_GET['selection'];
59
-		if($_GET['selection'] || $_content['selection_passed']) $content['selection_passed'] = $preserv['selection_passed'] = true;
65
+		if($_GET['selection'] || $_content['selection_passed'])
66
+		{
67
+			$content['selection_passed'] = $preserv['selection_passed'] = true;
68
+		}
60 69
 
61 70
 		// Check global setting
62
-		if(!Api\Storage\Merge::is_export_limit_excepted()) {
71
+		if(!Api\Storage\Merge::is_export_limit_excepted())
72
+		{
63 73
 			$export_limit = Api\Storage\Merge::getExportLimit($_appname);
64
-			if($export_limit == 'no') {
74
+			if($export_limit == 'no')
75
+			{
65 76
 				die(lang('Admin disabled exporting'));
66 77
 			}
67 78
 		}
@@ -70,12 +81,14 @@  discard block
 block discarded – undo
70 81
 		$readonlys['appname'] = (!empty($_appname) && $GLOBALS['egw']->acl->check('run',1,$_appname));
71 82
 		$content['appname'] = $_appname;
72 83
 		$preserv['appname'] = $_appname;
73
-		if(empty($_appname)) {
84
+		if(empty($_appname))
85
+		{
74 86
 			$et->setElementAttribute('select_definition','disabled',true);
75 87
 		}
76 88
 
77 89
 		// Check for preferred definition
78
-		if(!$_definition && $_appname) {
90
+		if(!$_definition && $_appname)
91
+		{
79 92
 			$_definition = $GLOBALS['egw_info']['user']['preferences'][$_appname]['nextmatch-export-definition'];
80 93
 		}
81 94
 		// fill definitions
@@ -85,26 +98,31 @@  discard block
 block discarded – undo
85 98
 			'application' => isset($content['appname']) ? $content['appname'] : '*',
86 99
 			'plugin' => $_plugin ? $_plugin : '*'
87 100
 		));
88
-		foreach ((array)$definitions->get_definitions() as $identifier) {
101
+		foreach ((array)$definitions->get_definitions() as $identifier)
102
+		{
89 103
 			try {
90 104
 				$definition = new importexport_definition($identifier);
91
-			} catch (Exception $e) {
105
+			}
106
+			catch (Exception $e) {
92 107
 				// permission error
93 108
 				continue;
94 109
 			}
95
-			if ($title = $definition->get_title()) {
110
+			if ($title = $definition->get_title())
111
+			{
96 112
 				$sel_options['definition'][$definition->get_identifier()] = $title;
97 113
 			}
98 114
 			unset($definition);
99 115
 		}
100
-		if(count($sel_options['definition']) == 2 && !$content['definition']) {
116
+		if(count($sel_options['definition']) == 2 && !$content['definition'])
117
+		{
101 118
 			$content['definition'] = end($sel_options['definition']);
102 119
 			unset($sel_options['definition']['']);
103 120
 		}
104 121
 		unset($definitions);
105 122
 		//$sel_options['definition']['expert'] = lang('Expert options');
106 123
 
107
-		if(isset($_definition) && array_key_exists($_definition,$sel_options['definition'])) {
124
+		if(isset($_definition) && array_key_exists($_definition,$sel_options['definition']))
125
+		{
108 126
 			$content['definition'] = $_definition;
109 127
 		}
110 128
 
@@ -112,8 +130,10 @@  discard block
 block discarded – undo
112 130
 		$sel_options['plugin'] = $this->export_plugins[$_appname]['export'];
113 131
 
114 132
 		// show definitions or plugins in ui?
115
-		if($content['definition'] == 'expert') {
116
-			if(isset($_plugin) && array_key_exists($_plugin,$sel_options['plugin'])) {
133
+		if($content['definition'] == 'expert')
134
+		{
135
+			if(isset($_plugin) && array_key_exists($_plugin,$sel_options['plugin']))
136
+			{
117 137
 				$content['plugin'] = $_plugin;
118 138
 				$selected_plugin = $_plugin;
119 139
 			}
@@ -126,12 +146,14 @@  discard block
 block discarded – undo
126 146
 */
127 147
 			}
128 148
 		}
129
-		else {
149
+		else
150
+		{
130 151
 			$readonlys['plugin'] = true;
131 152
 			$readonlys['save_definition'] = true;
132 153
 
133 154
 			$definition = new importexport_definition($content['definition']);
134
-			if($definition) {
155
+			if($definition)
156
+			{
135 157
 				$content += (array)$definition->plugin_options;
136 158
 				$selected_plugin = $definition->plugin;
137 159
 				$content['description'] = $definition->description;
@@ -148,64 +170,90 @@  discard block
 block discarded – undo
148 170
 			'|'	=>	'|',
149 171
 			''	=>	lang('Other')
150 172
 		);
151
-		if(!$sel_options['delimiter'][$content['delimiter']]) $sel_options['delimiter'][$content['delimiter']] = $content['delimiter'];
173
+		if(!$sel_options['delimiter'][$content['delimiter']])
174
+		{
175
+			$sel_options['delimiter'][$content['delimiter']] = $content['delimiter'];
176
+		}
152 177
 		$sel_options['delimiter'][$content['delimiter']] = lang('Use default') . ' "' . $sel_options['delimiter'][$content['delimiter']] . '"';
153 178
 
154
-		if(!$_content['delimiter']) $et->setElementAttribute('other_delimiter','disabled',true);
179
+		if(!$_content['delimiter'])
180
+		{
181
+			$et->setElementAttribute('other_delimiter','disabled',true);
182
+		}
155 183
 
156 184
 		// Other delimiter (options)
157
-		if($_content['other_delimiter']) $_content['delimiter'] = $_content['other_delimiter'];
185
+		if($_content['other_delimiter'])
186
+		{
187
+			$_content['delimiter'] = $_content['other_delimiter'];
188
+		}
158 189
 
159 190
 		// handle selector
160
-		if($selected_plugin) {
191
+		if($selected_plugin)
192
+		{
161 193
 			$content['plugin'] = $selected_plugin;
162 194
 			$plugin_object = new $selected_plugin;
163 195
 
164 196
 			$content['description'] = $plugin_object->get_description();
165 197
 
166 198
 			// fill options tab
167
- 			if(method_exists($plugin_object, 'get_selectors_html')) {
199
+ 			if(method_exists($plugin_object, 'get_selectors_html'))
200
+ 			{
168 201
 				$content['plugin_options_html'] = $plugin_object->get_options_html();
169
-			} else {
202
+			}
203
+			else
204
+			{
170 205
 				$options = $plugin_object->get_options_etpl($definition);
171
-				if(is_array($options)) {
206
+				if(is_array($options))
207
+				{
172 208
 					$content['plugin_options_template'] = $options['name'];
173 209
 					$content += (array)$options['content'];
174 210
 					$sel_options += (array)$options['sel_options'];
175 211
 					$readonlys += (array)$options['readonlys'];
176 212
 					$preserv += (array)$options['preserv'];
177
-				} else {
213
+				}
214
+				else
215
+				{
178 216
 					$content['plugin_options_template'] = $options;
179 217
 				}
180 218
 			}
181 219
 		}
182 220
 
183 221
 		// fill selection tab
184
-		if($definition && is_array($definition->plugin_options) && $definition->plugin_options['selection'] && !$content['selection_passed']) {
222
+		if($definition && is_array($definition->plugin_options) && $definition->plugin_options['selection'] && !$content['selection_passed'])
223
+		{
185 224
 			$_selection = $definition->plugin_options['selection'];
186 225
 		}
187 226
 
188
-		if ($_selection && ($content['old_definition'] == $content['definition'] || $content['selection_passed'])) {
227
+		if ($_selection && ($content['old_definition'] == $content['definition'] || $content['selection_passed']))
228
+		{
189 229
 			$readonlys[$tabs]['selection_tab'] = true;
190 230
 			$content['selection'] = $_selection;
191 231
 			$preserv['selection'] = $_selection;
192 232
 		}
193
-		elseif ($plugin_object) {
194
- 			if(method_exists($plugin_object, 'get_selectors_html')) {
233
+		elseif ($plugin_object)
234
+		{
235
+ 			if(method_exists($plugin_object, 'get_selectors_html'))
236
+ 			{
195 237
 				$content['plugin_selectors_html'] = $plugin_object->get_selectors_html();
196
-			} else {
238
+			}
239
+			else
240
+			{
197 241
 				$options = $plugin_object->get_selectors_etpl($definition);
198
-				if(is_array($options)) {
242
+				if(is_array($options))
243
+				{
199 244
 					$content += is_array($options['content']) ? $options['content'] : array('selection' => $options['content']);
200 245
 					$sel_options += (array)$options['sel_options'];
201 246
 					$readonlys['selection'] = (array)$options['readonlys'];
202 247
 					$preserv['selection'] = (array)$options['preserv'];
203 248
 					$content['plugin_selectors_template'] = $options['name'];
204
-				} else {
249
+				}
250
+				else
251
+				{
205 252
 					$content['plugin_selectors_template'] = $options;
206 253
 				}
207 254
 			}
208
-			if(!$content['plugin_selectors_html'] && !$content['plugin_selectors_template']) {
255
+			if(!$content['plugin_selectors_html'] && !$content['plugin_selectors_template'])
256
+			{
209 257
 				$readonlys[$tabs]['selection_tab'] = true;
210 258
 			}
211 259
 			$content['filter'] = $definition->filter;
@@ -237,10 +285,17 @@  discard block
 block discarded – undo
237 285
 		unset ($plugin_object);
238 286
 		$apps = importexport_helper_functions::get_apps('export');
239 287
 		//error_log(__METHOD__.__LINE__.array2string($apps));
240
-		if (empty($apps)) throw new Exception('Error: no application profiles available for export');
241
-		if (!is_array($apps) && $apps) $apps = (array)$apps;
288
+		if (empty($apps))
289
+		{
290
+			throw new Exception('Error: no application profiles available for export');
291
+		}
292
+		if (!is_array($apps) && $apps)
293
+		{
294
+			$apps = (array)$apps;
295
+		}
242 296
 		$sel_options['appname'] = array('' => lang('Select one')) + array_combine($apps,$apps);
243
-		if(!$_application && !$selected_plugin) {
297
+		if(!$_application && !$selected_plugin)
298
+		{
244 299
 			$content['plugin_selectors_html'] = $content['plugin_options_html'] =
245 300
 			lang('You need to select an app and format first!');
246 301
 			$readonlys[$tabs] = array('selection_tab' => true, 'options_tab' => true);
@@ -251,7 +306,8 @@  discard block
 block discarded – undo
251 306
 			//error_log(__LINE__.__FILE__.'$_content: '.print_r($_content,true));
252 307
 			$response = Api\Json\Response::get();
253 308
 
254
-			if ($_content['definition'] == 'expert') {
309
+			if ($_content['definition'] == 'expert')
310
+			{
255 311
 				$definition = new importexport_definition();
256 312
 				$definition->definition_id	= $_content['definition_id'] ? $_content['definition_id'] : '';
257 313
 				$definition->name		= $_content['name'] ? $_content['name'] : '';
@@ -261,11 +317,13 @@  discard block
 block discarded – undo
261 317
 				$definition->allowed_users	= $_content['allowed_users'] ? $_content['allowed_users'] : $this->user;
262 318
 				$definition->owner		= $_content['owner'] ? $_content['owner'] : $this->user;
263 319
 			}
264
-			else {
320
+			else
321
+			{
265 322
 				$definition = new importexport_definition($_content['definition']);
266 323
 			}
267 324
 
268
-			if(!is_array($definition->plugin_options)) {
325
+			if(!is_array($definition->plugin_options))
326
+			{
269 327
 				$definition->plugin_options = array(
270 328
 					'mapping'	=>	array()
271 329
 				);
@@ -280,7 +338,10 @@  discard block
 block discarded – undo
280 338
 				foreach($_content['filter'] as $key => $value)
281 339
 				{
282 340
 					// Handle multiple values
283
-					if(!is_array($value) && strpos($value,',') !== false) $value = explode(',',$value);
341
+					if(!is_array($value) && strpos($value,',') !== false)
342
+					{
343
+						$value = explode(',',$value);
344
+					}
284 345
 
285 346
 					$filter[$key] = $value;
286 347
 
@@ -312,14 +373,16 @@  discard block
 block discarded – undo
312 373
 				$_content
313 374
 			);
314 375
 
315
-			if(!$definition->plugin_options['selection']) {
376
+			if(!$definition->plugin_options['selection'])
377
+			{
316 378
 				$response->alert( lang('No records selected'));
317 379
 				return;
318 380
 			}
319 381
 
320 382
 			$tmpfname = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'export');
321 383
 			$file = fopen($tmpfname, "w+");
322
-			if (! $charset = $definition->plugin_options['charset']) {
384
+			if (! $charset = $definition->plugin_options['charset'])
385
+			{
323 386
 				$charset = Api\Translation::charset();
324 387
 			}
325 388
 			if($charset == 'user')
@@ -344,7 +407,8 @@  discard block
 block discarded – undo
344 407
 			// Store charset to use in header
345 408
 			Api\Cache::setSession('importexport', $tmpfname, $charset, 100);
346 409
 
347
-			if($_content['export'] == 'pressed') {
410
+			if($_content['export'] == 'pressed')
411
+			{
348 412
 				fclose($file);
349 413
 				$filename = pathinfo($tmpfname, PATHINFO_FILENAME);
350 414
 				$link_query = array(
@@ -364,7 +428,8 @@  discard block
 block discarded – undo
364 428
 				Framework::window_close();
365 429
 				return;
366 430
 			}
367
-			elseif($_content['preview'] == 'pressed') {
431
+			elseif($_content['preview'] == 'pressed')
432
+			{
368 433
 				fseek($file, 0);
369 434
 				$item_count = 1;
370 435
 				$preview = '';
@@ -373,7 +438,8 @@  discard block
 block discarded – undo
373 438
 								'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
374 439
 				$replace = $preview = '';
375 440
 
376
-				while(!feof($file) && $item_count < 30) {
441
+				while(!feof($file) && $item_count < 30)
442
+				{
377 443
 					$preview .= preg_replace($search,$replace,fgets($file,1024));
378 444
 					$item_count++;
379 445
 				}
@@ -394,7 +460,9 @@  discard block
 block discarded – undo
394 460
 			}
395 461
 			//nothing else expected!
396 462
 			throw new Exception('Error: unexpected submit in export_dialog!');
397
-		} else {
463
+		}
464
+		else
465
+		{
398 466
 			$readonlys[$tabs]['selection'] = true;
399 467
 			$readonlys[$tabs]['selection'] = false;
400 468
 		}
@@ -402,14 +470,16 @@  discard block
 block discarded – undo
402 470
 		return $et->exec(self::_appname. '.importexport_export_ui.export_dialog',$content,$sel_options,$readonlys,$preserv,2);
403 471
 	}
404 472
 
405
-	public function ajax_get_definition_description($_definition) {
473
+	public function ajax_get_definition_description($_definition)
474
+	{
406 475
 
407 476
 		$_response = Api\Json\Response::get();
408 477
 		$description = '';
409 478
 		if ($_definition)
410 479
 		{
411 480
 			$_object = new importexport_definition($_definition);
412
-			if (is_a($_object, 'importexport_definition')) {
481
+			if (is_a($_object, 'importexport_definition'))
482
+			{
413 483
 				$description = $_object->description;
414 484
 			}
415 485
 			unset ($_object);
@@ -417,11 +487,13 @@  discard block
 block discarded – undo
417 487
 		$_response->assign('importexport-export_dialog_plugin_description','innerHTML',$description);
418 488
 	}
419 489
 
420
-	public function ajax_get_plugin_description($_plugin) {
490
+	public function ajax_get_plugin_description($_plugin)
491
+	{
421 492
 		$_respone = Api\Json\Response::get();
422 493
 
423 494
 		$plugin_object = new $_plugin;
424
-		if (is_a($plugin_object, 'importexport_iface_export_plugin')) {
495
+		if (is_a($plugin_object, 'importexport_iface_export_plugin'))
496
+		{
425 497
 			$description = $plugin_object->get_description();
426 498
 		}
427 499
 		$_response->addAssign('importexport-export_dialog_plugin_description','innerHTML',$description);
@@ -435,10 +507,14 @@  discard block
 block discarded – undo
435 507
 	 * @param sting $_tmpfname
436 508
 	 * @todo we need a suffix atibute in plugins e.g. .csv
437 509
 	 */
438
-	public function download($_tmpfname = '') {
510
+	public function download($_tmpfname = '')
511
+	{
439 512
 		$tmpfname = $_tmpfname ? $_tmpfname : $_GET['_filename'];
440 513
 		$tmpfname = $GLOBALS['egw_info']['server']['temp_dir'] .'/'. $tmpfname;
441
-		if (!is_readable($tmpfname)) die();
514
+		if (!is_readable($tmpfname))
515
+		{
516
+			die();
517
+		}
442 518
 
443 519
 		$appname = $_GET['_appname'];
444 520
 		$nicefname = $_GET['filename'] ? $_GET['filename'] : 'egw_export_'.$appname.'-'.date('Y-m-d');
Please login to merge, or discard this patch.