Completed
Push — 16.1 ( 4f61bc...7abf1b )
by Nathan
32:13 queued 18:43
created
calendar/inc/class.calendar_merge.inc.php 2 patches
Spacing   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -84,14 +84,14 @@  discard block
 block discarded – undo
84 84
 
85 85
 		// Register table plugins
86 86
 		$this->table_plugins['participant'] = 'participant';
87
-		for($i = 0; $i < 7; $i++)
87
+		for ($i = 0; $i < 7; $i++)
88 88
 		{
89 89
 			$this->table_plugins[date('l', strtotime("+$i days"))] = 'day_plugin';
90 90
 		}
91
-		for($i = 1; $i <= 31; $i++) {
91
+		for ($i = 1; $i <= 31; $i++) {
92 92
 			$this->table_plugins['day_'.$i] = 'day'; // Numerically by day number (1-31)
93 93
 		}
94
-		foreach(self::$relative as $day) {
94
+		foreach (self::$relative as $day) {
95 95
 			$this->table_plugins[$day] = 'day'; // Current day
96 96
 		}
97 97
 		$this->query = is_array($this->bo->cal_prefs['saved_states']) ?
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 	 * @param string $charset=null charset to override default set by mimetype or export charset
118 118
 	 * @return string|boolean merged document or false on error
119 119
 	 */
120
-	function merge_string($content,$ids,$err,$mimetype,$fix)
120
+	function merge_string($content, $ids, $err, $mimetype, $fix)
121 121
 	{
122 122
 		//error_log(__METHOD__ . ' IDs: ' . array2string($ids));
123 123
 		// Handle merging a list of events into a document with range instead of pagerepeat
124
-		if((strpos($content, '$$range') !== false || strpos($content, '{{range') !== false) && is_array($ids))
124
+		if ((strpos($content, '$$range') !== false || strpos($content, '{{range') !== false) && is_array($ids))
125 125
 		{
126 126
 			//error_log(__METHOD__ . ' Got list of events(?), no pagerepeat tag');
127 127
 			// Merging more than one something will fail without pagerepeat
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 				$events = $ids;
132 132
 				$ids = array('start' => PHP_INT_MAX, 'end' => 0);
133 133
 				$this->ids = array();
134
-				foreach($events as $event) {
135
-					if($event['start'] && Api\DateTime::to($event['start'],'ts') < $ids['start']) $ids['start'] = Api\DateTime::to($event['start'],'ts');
136
-					if($event['end'] && Api\DateTime::to($event['end'],'ts') > $ids['end']) $ids['end'] = Api\DateTime::to($event['end'],'ts');
134
+				foreach ($events as $event) {
135
+					if ($event['start'] && Api\DateTime::to($event['start'], 'ts') < $ids['start']) $ids['start'] = Api\DateTime::to($event['start'], 'ts');
136
+					if ($event['end'] && Api\DateTime::to($event['end'], 'ts') > $ids['end']) $ids['end'] = Api\DateTime::to($event['end'], 'ts');
137 137
 					// Keep ids for future use
138 138
 					$this->ids[] = $event['id'];
139 139
 				}
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 				'cfs' => strpos($content, '#') !== false ? array_keys(Api\Storage\Customfields::get('calendar')) : null
155 155
 			));
156 156
 			$ids = array();
157
-			foreach($events as $event) {
157
+			foreach ($events as $event) {
158 158
 				$ids[] = $event;
159 159
 			}
160 160
 		}
161 161
 
162
-		return parent::merge_string($content, $ids, $err, $mimetype,$fix);
162
+		return parent::merge_string($content, $ids, $err, $mimetype, $fix);
163 163
 	}
164 164
 
165 165
 	/**
@@ -169,20 +169,20 @@  discard block
 block discarded – undo
169 169
 	 * @param string &$content=null content to create some replacements only if they are used
170 170
 	 * @return array|boolean
171 171
 	 */
172
-	protected function get_replacements($id,&$content=null)
172
+	protected function get_replacements($id, &$content = null)
173 173
 	{
174 174
 		$prefix = '';
175 175
 		// List events ?
176
-		if(is_array($id) && !$id['id'] && !$id[0]['id'])
176
+		if (is_array($id) && !$id['id'] && !$id[0]['id'])
177 177
 		{
178 178
 			$events = $this->bo->search($this->query + $id + array(
179 179
 				'offset' => 0,
180 180
 				'order' => 'cal_start',
181 181
 				'cfs' => strpos($content, '#') !== false ? array_keys(Api\Storage\Customfields::get('calendar')) : null
182 182
 			));
183
-			if(strpos($content,'$$calendar/') !== false || strpos($content, '$$table/day') !== false)
183
+			if (strpos($content, '$$calendar/') !== false || strpos($content, '$$table/day') !== false)
184 184
 			{
185
-				array_unshift($events,false); unset($events[0]);	// renumber the array to start with key 1, instead of 0
185
+				array_unshift($events, false); unset($events[0]); // renumber the array to start with key 1, instead of 0
186 186
 				$prefix = 'calendar/%d';
187 187
 			}
188 188
 		}
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 			$events = $id;
193 193
 			$id = array('start' => PHP_INT_MAX, 'end' => 0);
194 194
 			$this->ids = array();
195
-			foreach($events as $event) {
196
-				if($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
197
-				if($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
195
+			foreach ($events as $event) {
196
+				if ($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
197
+				if ($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
198 198
 				// Keep ids for future use
199
-				$this->ids[]  = $event['id'];
199
+				$this->ids[] = $event['id'];
200 200
 			}
201 201
 			$id = array($id);
202 202
 		}
@@ -208,20 +208,20 @@  discard block
 block discarded – undo
208 208
 		// as this function allows to pass query- parameters, we need to check the result of the query against export_limit restrictions
209 209
 		if (Api\Storage\Merge::hasExportLimit($this->export_limit) && !Api\Storage\Merge::is_export_limit_excepted() && count($events) > (int)$this->export_limit)
210 210
 		{
211
-			$err = lang('No rights to export more than %1 entries!',(int)$this->export_limit);
211
+			$err = lang('No rights to export more than %1 entries!', (int)$this->export_limit);
212 212
 			throw new Api\Exception\WrongUserinput($err);
213 213
 		}
214 214
 		$replacements = array();
215 215
 		$n = 0;
216
-		foreach($events as $event)
216
+		foreach ($events as $event)
217 217
 		{
218
-			$values = $this->calendar_replacements($event,sprintf($prefix,++$n), $content);
219
-			if(is_array($id) && $id['start'])
218
+			$values = $this->calendar_replacements($event, sprintf($prefix, ++$n), $content);
219
+			if (is_array($id) && $id['start'])
220 220
 			{
221
-				foreach(self::$range_tags as $key => $format)
221
+				foreach (self::$range_tags as $key => $format)
222 222
 				{
223 223
 					$value = date($format, $key == 'end' ? $id['end'] : $id['start']);
224
-					if($key == 'month') $value = lang($value);
224
+					if ($key == 'month') $value = lang($value);
225 225
 					$values["$\$range/$key$$"] = $value;
226 226
 				}
227 227
 			}
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 	 * @param boolean $last_event_too=false also include information about the last event
238 238
 	 * @return array
239 239
 	 */
240
-	public function calendar_replacements($id,$prefix = '', &$content = '')
240
+	public function calendar_replacements($id, $prefix = '', &$content = '')
241 241
 	{
242 242
 		$replacements = array();
243
-		if(!is_array($id) || !$id['start']) {
243
+		if (!is_array($id) || !$id['start']) {
244 244
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
245 245
 		} else {
246 246
 			$event = $id;
@@ -253,68 +253,68 @@  discard block
 block discarded – undo
253 253
 		importexport_export_csv::convert($record, $types, 'calendar');
254 254
 
255 255
 		$array = $record->get_record_array();
256
-		foreach($array as $key => $value)
256
+		foreach ($array as $key => $value)
257 257
 		{
258
-			$replacements['$$'.($prefix?$prefix.'/':'').$key.'$$'] = $value;
258
+			$replacements['$$'.($prefix ? $prefix.'/' : '').$key.'$$'] = $value;
259 259
 		}
260 260
 
261
-		$replacements['$$' . ($prefix ? $prefix . '/' : '') . 'calendar_id'. '$$'] = $event['id'];
262
-		foreach($this->bo->event2array($event) as $name => $data)
261
+		$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_id'.'$$'] = $event['id'];
262
+		foreach ($this->bo->event2array($event) as $name => $data)
263 263
 		{
264
-			if (substr($name,-4) == 'date') $name = substr($name,0,-4);
265
-			$replacements['$$' . ($prefix ? $prefix . '/' : '') . 'calendar_'.$name . '$$'] = is_array($data['data']) ? implode(', ',$data['data']) : $data['data'];
264
+			if (substr($name, -4) == 'date') $name = substr($name, 0, -4);
265
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_'.$name.'$$'] = is_array($data['data']) ? implode(', ', $data['data']) : $data['data'];
266 266
 		}
267 267
 		// Add seperate lists of participants by type
268
-		if(strpos($content, 'calendar_participants/')!== false)
268
+		if (strpos($content, 'calendar_participants/') !== false)
269 269
 		{
270 270
 			$types = array();
271
-			foreach($this->bo->resources as $resource)
271
+			foreach ($this->bo->resources as $resource)
272 272
 			{
273 273
 				$types[$resource['app']] = array();
274 274
 			}
275
-			foreach($event['participants'] as $uid => $status)
275
+			foreach ($event['participants'] as $uid => $status)
276 276
 			{
277 277
 				$type = $this->bo->resources[$uid[0]]['app'];
278
-				if($type == 'api-accounts')
278
+				if ($type == 'api-accounts')
279 279
 				{
280 280
 					$type = ($GLOBALS['egw']->accounts->get_type($uid) == 'g' ? 'group' : 'account');
281 281
 				}
282 282
 				$types[$type][] = $this->bo->participant_name($uid);
283 283
 			}
284
-			foreach($types as $t_id => $type)
284
+			foreach ($types as $t_id => $type)
285 285
 			{
286
-				$replacements['$$'.($prefix ? $prefix . '/' : '') . "calendar_participants/{$t_id}$$"] = implode(', ',$type);
286
+				$replacements['$$'.($prefix ? $prefix.'/' : '')."calendar_participants/{$t_id}$$"] = implode(', ', $type);
287 287
 			}
288 288
 		}
289
-		if(!$replacements['$$'.($prefix ? $prefix . '/' : '') . 'calendar_recur_type$$'])
289
+		if (!$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_recur_type$$'])
290 290
 		{
291 291
 			// Need to set it to '' if not set or previous record may be used
292
-			$replacements['$$'.($prefix ? $prefix . '/' : '') . 'calendar_recur_type$$'] = '';
292
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_recur_type$$'] = '';
293 293
 		}
294
-		foreach(array('start','end') as $what)
294
+		foreach (array('start', 'end') as $what)
295 295
 		{
296
-			foreach(array(
296
+			foreach (array(
297 297
 				'date' => $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],
298 298
 				'day'  => 'l',
299
-				'time' => (date('Ymd',$event['start']) != date('Ymd',$event['end']) ? $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' ' : '') . ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'),
299
+				'time' => (date('Ymd', $event['start']) != date('Ymd', $event['end']) ? $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' ' : '').($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'),
300 300
 			) as $name => $format)
301 301
 			{
302
-				$value = Api\DateTime::to($event[$what],$format);
302
+				$value = Api\DateTime::to($event[$what], $format);
303 303
 				if ($format == 'l') $value = lang($value);
304
-				$replacements['$$' .($prefix ? $prefix.'/':'').'calendar_'.$what.$name.'$$'] = $value;
304
+				$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_'.$what.$name.'$$'] = $value;
305 305
 			}
306 306
 		}
307
-		$duration = ($event['end'] - $event['start'])/60;
308
-		$replacements['$$'.($prefix?$prefix.'/':'').'calendar_duration$$'] = floor($duration/60).lang('h').($duration%60 ? $duration%60 : '');
307
+		$duration = ($event['end'] - $event['start']) / 60;
308
+		$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_duration$$'] = floor($duration / 60).lang('h').($duration % 60 ? $duration % 60 : '');
309 309
 
310 310
 		// Add in contact stuff for owner
311
-		if (strpos($content,'$$calendar_owner/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($event['owner'],'person_id')))
311
+		if (strpos($content, '$$calendar_owner/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($event['owner'], 'person_id')))
312 312
 		{
313
-			$replacements += $this->contact_replacements($user,($prefix ? $prefix.'/':'').'calendar_owner');
314
-			$replacements['$$'.($prefix?$prefix.'/':'').'calendar_owner/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($event['owner'],'account_primary_group'));
313
+			$replacements += $this->contact_replacements($user, ($prefix ? $prefix.'/' : '').'calendar_owner');
314
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_owner/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($event['owner'], 'account_primary_group'));
315 315
 		}
316 316
 
317
-		if($content && strpos($content, '$$#') !== FALSE)
317
+		if ($content && strpos($content, '$$#') !== FALSE)
318 318
 		{
319 319
 			$this->cf_link_to_expand($event, $content, $replacements);
320 320
 		}
@@ -340,82 +340,82 @@  discard block
 block discarded – undo
340 340
 	* @param string $repeat Text being repeated for each entry
341 341
 	* @return array
342 342
 	*/
343
-	public function day_plugin($plugin,$date,$n,$repeat)
343
+	public function day_plugin($plugin, $date, $n, $repeat)
344 344
 	{
345 345
 		static $days = null;
346
-		if(is_array($date) && !$date['start']) {
346
+		if (is_array($date) && !$date['start']) {
347 347
 			// List of IDs
348
-			if($date[0]['start']) {
348
+			if ($date[0]['start']) {
349 349
 				$id = array('start' => PHP_INT_MAX, 'end' => 0);
350
-				foreach($date as $event) {
351
-					if($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
352
-					if($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
350
+				foreach ($date as $event) {
351
+					if ($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
352
+					if ($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
353 353
 				}
354 354
 				$date = $id;
355 355
 			} else {
356 356
 				$event = $this->bo->read(is_array($date) ? $date['id'] : $date, is_array($date) ? $date['recur_date'] : null);
357
-				if(date('l',$event['start']) != $plugin) return array();
357
+				if (date('l', $event['start']) != $plugin) return array();
358 358
 				$date = $event['start'];
359 359
 			}
360 360
 		}
361 361
 
362 362
 		$_date = $date['start'] ? $date['start'] : $date;
363
-		if($days[date('Ymd',$_date)][$plugin]) return $days[date('Ymd',$_date)][$plugin][$n];
363
+		if ($days[date('Ymd', $_date)][$plugin]) return $days[date('Ymd', $_date)][$plugin][$n];
364 364
 
365 365
 		$events = $this->bo->search($this->query + array(
366
-			'start' => $date['end'] ? $date['start'] : mktime(0,0,0,date('m',$_date),date('d',$_date),date('Y',$_date)),
367
-			'end' => $date['end'] ? $date['end'] : mktime(23,59,59,date('m',$_date),date('d',$_date),date('Y',$_date)),
366
+			'start' => $date['end'] ? $date['start'] : mktime(0, 0, 0, date('m', $_date), date('d', $_date), date('Y', $_date)),
367
+			'end' => $date['end'] ? $date['end'] : mktime(23, 59, 59, date('m', $_date), date('d', $_date), date('Y', $_date)),
368 368
 			'offset' => 0,
369 369
 			'num_rows' => 20,
370 370
 			'order' => 'cal_start',
371 371
 			'daywise' => true,
372
-			'cfs' => array(),	// read all custom-fields
372
+			'cfs' => array(), // read all custom-fields
373 373
 		));
374 374
 
375 375
 		if (true) $days = array();
376 376
 		$replacements = array();
377 377
 		$time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i';
378
-		foreach($events as $day => $list)
378
+		foreach ($events as $day => $list)
379 379
 		{
380
-			foreach($list as $event)
380
+			foreach ($list as $event)
381 381
 			{
382
-				if($this->ids && !in_array($event['id'], $this->ids)) continue;
382
+				if ($this->ids && !in_array($event['id'], $this->ids)) continue;
383 383
 				$start = Api\DateTime::to($event['start'], 'array');
384 384
 				$end = Api\DateTime::to($event['end'], 'array');
385 385
 				$replacements = $this->calendar_replacements($event);
386
-				if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
387
-					$dow = date('l',$event['start']);
386
+				if ($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
387
+					$dow = date('l', $event['start']);
388 388
 				} else {
389 389
 					$dow = date('l', strtotime($day));
390 390
 					// Fancy date+time formatting for multi-day events
391
-					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0,0,0,0,0,1));
392
-					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23,59,59,0,0,0));
391
+					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0, 0, 0, 0, 0, 1));
392
+					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23, 59, 59, 0, 0, 0));
393 393
 				}
394 394
 
395
-				$days[date('Ymd',$_date)][$dow][] = $replacements;
395
+				$days[date('Ymd', $_date)][$dow][] = $replacements;
396 396
 			}
397
-			if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
397
+			if (strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
398 398
 				$date_marker = array(
399 399
 					'$$day/date$$' => date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], strtotime($day)),
400 400
 					'$$day/name$$' => lang(date('l', strtotime($day)))
401 401
 				);
402
-				if(!is_array($days[date('Ymd',$_date)][date('l',strtotime($day))])) {
402
+				if (!is_array($days[date('Ymd', $_date)][date('l', strtotime($day))])) {
403 403
 					$blank = $this->calendar_replacements(array());
404
-					foreach($blank as &$value)
404
+					foreach ($blank as &$value)
405 405
 					{
406 406
 						$value = '';
407 407
 					}
408
-					$days[date('Ymd',$_date)][date('l',strtotime($day))][] = $blank;
408
+					$days[date('Ymd', $_date)][date('l', strtotime($day))][] = $blank;
409 409
 				}
410
-				$days[date('Ymd',$_date)][date('l',strtotime($day))][0] += $date_marker;
410
+				$days[date('Ymd', $_date)][date('l', strtotime($day))][0] += $date_marker;
411 411
 			}
412 412
 			// Add in birthdays
413
-			if(strpos($repeat, 'day/birthdays') !== false)
413
+			if (strpos($repeat, 'day/birthdays') !== false)
414 414
 			{
415
-				$days[date('Ymd', $_date)][date('l',strtotime($day))][0]['$$day/birthdays$$'] = $this->get_birthdays($day);
415
+				$days[date('Ymd', $_date)][date('l', strtotime($day))][0]['$$day/birthdays$$'] = $this->get_birthdays($day);
416 416
 			}
417 417
 		}
418
-		return $days[date('Ymd',$_date)][$plugin][0];
418
+		return $days[date('Ymd', $_date)][$plugin][0];
419 419
 	}
420 420
 
421 421
 	/**
@@ -429,27 +429,27 @@  discard block
 block discarded – undo
429 429
 	* @param string $repeat Text being repeated for each entry
430 430
 	* @return array
431 431
 	*/
432
-	public function day($plugin,$id,$n,$repeat)
432
+	public function day($plugin, $id, $n, $repeat)
433 433
 	{
434 434
 		static $days = null;
435 435
 
436 436
 		// Figure out which day
437
-		list($type, $which) = explode('_',$plugin);
438
-		if($type == 'day' && $which)
437
+		list($type, $which) = explode('_', $plugin);
438
+		if ($type == 'day' && $which)
439 439
 		{
440
-			if($id[0]['start'])
440
+			if ($id[0]['start'])
441 441
 			{
442 442
 				$dates = array('start' => PHP_INT_MAX, 'end' => 0);
443
-				foreach($id as $event) {
444
-					if($event['start'] && $event['start'] < $dates['start']) $dates['start'] = $event['start'];
445
-					if($event['end'] && $event['end'] > $dates['end']) $dates['end'] = $event['end'];
443
+				foreach ($id as $event) {
444
+					if ($event['start'] && $event['start'] < $dates['start']) $dates['start'] = $event['start'];
445
+					if ($event['end'] && $event['end'] > $dates['end']) $dates['end'] = $event['end'];
446 446
 				}
447 447
 				$id = $dates;
448 448
 			}
449 449
 			$arr = $this->bo->date2array($id['start']);
450 450
 			$arr['day'] = $which;
451 451
 			$date = $this->bo->date2ts($arr);
452
-			if(is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end'])) return array();
452
+			if (is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end'])) return array();
453 453
 		}
454 454
 		elseif ($plugin == 'selected')
455 455
 		{
@@ -459,69 +459,69 @@  discard block
 block discarded – undo
459 459
 		{
460 460
 			$date = strtotime($plugin);
461 461
 		}
462
-		if($type == 'day' && is_array($id) && !$id['start']) {
462
+		if ($type == 'day' && is_array($id) && !$id['start']) {
463 463
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
464
-			if($which && date('d',$event['start']) != $which) return array();
465
-			if(date('Ymd',$date) != date('Ymd', $event['start'])) return array();
464
+			if ($which && date('d', $event['start']) != $which) return array();
465
+			if (date('Ymd', $date) != date('Ymd', $event['start'])) return array();
466 466
 			return $n == 0 ? $this->calendar_replacements($event) : array();
467 467
 		}
468 468
 
469 469
 		// Use start for cache, in case of multiple months
470 470
 		$_date = $id['start'] ? $id['start'] : $date;
471
-		if($days[date('Ymd',$_date)][$plugin]) return $days[date('Ymd',$_date)][$plugin][$n];
471
+		if ($days[date('Ymd', $_date)][$plugin]) return $days[date('Ymd', $_date)][$plugin][$n];
472 472
 
473 473
 		$events = $this->bo->search($this->query + array(
474 474
 			'start' => $date,
475
-			'end' => mktime(23,59,59,date('m',$date),date('d',$date),date('Y',$date)),
475
+			'end' => mktime(23, 59, 59, date('m', $date), date('d', $date), date('Y', $date)),
476 476
 			'offset' => 0,
477 477
 			'num_rows' => 20,
478 478
 			'order' => 'cal_start',
479 479
 			'daywise' => true,
480
-			'cfs' => array(),	// read all custom-fields
480
+			'cfs' => array(), // read all custom-fields
481 481
 		));
482 482
 
483 483
 		$replacements = array();
484 484
 		if (true) $days = array();
485 485
 		$time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i';
486
-		foreach($events as $day => $list)
486
+		foreach ($events as $day => $list)
487 487
 		{
488
-			foreach($list as $event)
488
+			foreach ($list as $event)
489 489
 			{
490
-				if($this->ids && !in_array($event['id'], $this->ids)) continue;
490
+				if ($this->ids && !in_array($event['id'], $this->ids)) continue;
491 491
 				$start = Api\DateTime::to($event['start'], 'array');
492 492
 				$end = Api\DateTime::to($event['end'], 'array');
493 493
 				$replacements = $this->calendar_replacements($event);
494
-				if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
494
+				if ($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
495 495
 					//$dow = date('l',$event['start']);
496 496
 				} else {
497 497
 					// Fancy date+time formatting for multi-day events
498
-					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0,0,0,0,0,1));
499
-					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23,59,59,0,0,0));
498
+					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0, 0, 0, 0, 0, 1));
499
+					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23, 59, 59, 0, 0, 0));
500 500
 				}
501
-				$days[date('Ymd',$_date)][$plugin][] = $replacements;
501
+				$days[date('Ymd', $_date)][$plugin][] = $replacements;
502 502
 			}
503
-			if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
503
+			if (strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
504 504
 				$date_marker = array(
505 505
 					'$$day/date$$' => date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], strtotime($day)),
506 506
 					'$$day/name$$' => lang(date('l', strtotime($day)))
507 507
 				);
508
-				if(!is_array($days[date('Ymd',$_date)][$plugin])) {
508
+				if (!is_array($days[date('Ymd', $_date)][$plugin])) {
509 509
 					$blank = $this->calendar_replacements(array());
510
-					foreach($blank as &$value)
510
+					foreach ($blank as &$value)
511 511
 					{
512 512
 						$value = '';
513 513
 					}
514
-					$days[date('Ymd',$_date)][$plugin][] = $blank;
514
+					$days[date('Ymd', $_date)][$plugin][] = $blank;
515 515
 				}
516
-				$days[date('Ymd',$_date)][$plugin][0] += $date_marker;
516
+				$days[date('Ymd', $_date)][$plugin][0] += $date_marker;
517 517
 			}
518 518
 			// Add in birthdays
519
-			if(strpos($repeat, 'day/birthdays') !== false)
519
+			if (strpos($repeat, 'day/birthdays') !== false)
520 520
 			{
521
-				$days[date('Ymd', $_date)][date('l',strtotime($day))][0]['$$day/birthdays$$'] = $this->get_birthdays($day);
521
+				$days[date('Ymd', $_date)][date('l', strtotime($day))][0]['$$day/birthdays$$'] = $this->get_birthdays($day);
522 522
 			}
523 523
 		}
524
-		return $days[date('Ymd',$_date)][$plugin][0];
524
+		return $days[date('Ymd', $_date)][$plugin][0];
525 525
 	}
526 526
 
527 527
 	/**
@@ -534,30 +534,30 @@  discard block
 block discarded – undo
534 534
 	* @param int $n
535 535
 	* @return array
536 536
 	*/
537
-	public function participant($plugin,$id,$n)
537
+	public function participant($plugin, $id, $n)
538 538
 	{
539
-		unset($plugin);	// not used, but required by function signature
539
+		unset($plugin); // not used, but required by function signature
540 540
 
541
-		if(!is_array($id) || !$id['start']) {
541
+		if (!is_array($id) || !$id['start']) {
542 542
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
543 543
 		} else {
544 544
 			$event = $id;
545 545
 		}
546 546
 
547
-		if(!is_array($event['participants']) || $n >= count($event['participants'])) return array();
547
+		if (!is_array($event['participants']) || $n >= count($event['participants'])) return array();
548 548
 
549 549
 		$participant = null;
550 550
 		$status = null;
551 551
 		$i = -1;
552
-		foreach($event['participants'] as $participant => $status) {
553
-			if(++$i == $n) break;
552
+		foreach ($event['participants'] as $participant => $status) {
553
+			if (++$i == $n) break;
554 554
 		}
555 555
 
556
-		if(!$participant) return array();
556
+		if (!$participant) return array();
557 557
 
558 558
 		// Add some common information
559 559
 		$quantity = $role = null;
560
-		calendar_so::split_status($status,$quantity,$role);
560
+		calendar_so::split_status($status, $quantity, $role);
561 561
 		if ($role != 'REQ-PARTICIPANT')
562 562
 		{
563 563
 			if (isset($this->bo->roles[$role]))
@@ -565,13 +565,13 @@  discard block
 block discarded – undo
565 565
 				$role = lang($this->bo->roles[$role]);
566 566
 			}
567 567
 			// allow to use cats as roles (beside regular iCal ones)
568
-			elseif (substr($role,0,6) == 'X-CAT-' && ($cat_id = (int)substr($role,6)) > 0)
568
+			elseif (substr($role, 0, 6) == 'X-CAT-' && ($cat_id = (int)substr($role, 6)) > 0)
569 569
 			{
570 570
 				$role = $GLOBALS['egw']->categories->id2name($cat_id);
571 571
 			}
572 572
 			else
573 573
 			{
574
-				$role = lang(str_replace('X-','',$role));
574
+				$role = lang(str_replace('X-', '', $role));
575 575
 			}
576 576
 		}
577 577
 		$info = array(
@@ -584,26 +584,26 @@  discard block
 block discarded – undo
584 584
 		switch ($participant[0])
585 585
 		{
586 586
 			case 'c':
587
-				$replacements = $this->contact_replacements(substr($participant,1),'');
587
+				$replacements = $this->contact_replacements(substr($participant, 1), '');
588 588
 				break;
589 589
 			case 'r':
590 590
 				if (is_null(self::$resources)) self::$resources = new resources_bo();
591
-				if (($resource = self::$resources->read(substr($participant,1))))
591
+				if (($resource = self::$resources->read(substr($participant, 1))))
592 592
 				{
593
-					foreach($resource as $name => $value)
593
+					foreach ($resource as $name => $value)
594 594
 					{
595 595
 					    $replacements['$$'.$name.'$$'] = $value;
596 596
 					}
597 597
 				}
598 598
 				break;
599 599
 			default:
600
-				if (is_numeric($participant) && ($contact = $GLOBALS['egw']->accounts->id2name($participant,'person_id')))
600
+				if (is_numeric($participant) && ($contact = $GLOBALS['egw']->accounts->id2name($participant, 'person_id')))
601 601
 				{
602
-					$replacements = $this->contact_replacements($contact,'');
602
+					$replacements = $this->contact_replacements($contact, '');
603 603
 				}
604 604
 				break;
605 605
 		}
606
-		foreach($info as $name => $value)
606
+		foreach ($info as $name => $value)
607 607
 		{
608 608
 			$replacements['$$'.$name.'$$'] = $value;
609 609
 		}
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 	{
619 619
 		$contacts = new Api\Contacts();
620 620
 		$birthdays = Array();
621
-		foreach($contacts->get_addressbooks() as $owner => $name)
621
+		foreach ($contacts->get_addressbooks() as $owner => $name)
622 622
 		{
623 623
 			$birthdays += $contacts->read_birthdays($owner, substr($day, 0, 4));
624 624
 		}
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 		echo '<tr><td colspan="4"><h3>'.lang('Calendar fields:')."</h3></td></tr>";
641 641
 
642 642
 		$n = 0;
643
-		foreach(array(
643
+		foreach (array(
644 644
 			'calendar_id' => lang('Calendar ID'),
645 645
 			'calendar_title' => lang('Title'),
646 646
 			'calendar_description' => lang('Description'),
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 			'calendar_owner'    => lang('Owner'),
664 664
 		) as $name => $label)
665 665
 		{
666
-			if (in_array($name,array('start','end')) && $n&1)		// main values, which should be in the first column
666
+			if (in_array($name, array('start', 'end')) && $n&1)		// main values, which should be in the first column
667 667
 			{
668 668
 				echo "</tr>\n";
669 669
 				$n++;
@@ -676,13 +676,13 @@  discard block
 block discarded – undo
676 676
 
677 677
 		echo '<tr><td colspan="4"><h3>'.lang('Range fields').":</h3></td></tr>";
678 678
 		echo '<tr><td colspan="4">'.lang('If you select a range (month, week, etc) instead of a list of entries, these extra fields are available').'</td></tr>';
679
-		foreach(array_keys(self::$range_tags) as $name)
679
+		foreach (array_keys(self::$range_tags) as $name)
680 680
 		{
681 681
 			echo '<tr><td>{{range/'.$name.'}}</td><td>'.lang($name)."</td></tr>\n";
682 682
 		}
683 683
 		echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
684 684
 		$custom = Api\Storage\Customfields::get('calendar');
685
-		foreach($custom as $name => $field)
685
+		foreach ($custom as $name => $field)
686 686
 		{
687 687
 			echo '<tr><td>{{#'.$name.'}}</td><td colspan="3">'.$field['label']."</td></tr>\n";
688 688
 		}
@@ -691,9 +691,9 @@  discard block
 block discarded – undo
691 691
 		echo '<tr><td colspan="4"><h3>'.lang('Participants').":</h3></td></tr>";
692 692
 		echo '<tr><td>{{calendar_participants/account}}</td><td colspan="3">'.lang('Accounts')."</td></tr>\n";
693 693
 		echo '<tr><td>{{calendar_participants/group}}</td><td colspan="3">'.lang('Groups')."</td></tr>\n";
694
-		foreach($this->bo->resources as $resource)
694
+		foreach ($this->bo->resources as $resource)
695 695
 		{
696
-			if($resource['type'])
696
+			if ($resource['type'])
697 697
 			{
698 698
 				echo '<tr><td>{{calendar_participants/'.$resource['app'].'}}</td><td colspan="3">'.lang($resource['app'])."</td></tr>\n";
699 699
 			}
@@ -710,19 +710,19 @@  discard block
 block discarded – undo
710 710
 		echo '<tr style="vertical-align:top"><td colspan="2"><table >';
711 711
 		echo '<tr><td><h3>'.lang('Day of week tables').":</h3></td></tr>";
712 712
 		$days = array();
713
-		for($i = 0; $i < 7; $i++)
713
+		for ($i = 0; $i < 7; $i++)
714 714
 		{
715
-			$days[date('N',strtotime("+$i days"))] = date('l',strtotime("+$i days"));
715
+			$days[date('N', strtotime("+$i days"))] = date('l', strtotime("+$i days"));
716 716
 		}
717 717
 		ksort($days);
718
-		foreach($days as $day)
718
+		foreach ($days as $day)
719 719
 		{
720
-			echo '<tr><td>{{table/'.$day. '}} ... {{endtable}}</td></tr>';
720
+			echo '<tr><td>{{table/'.$day.'}} ... {{endtable}}</td></tr>';
721 721
 		}
722 722
 		echo '</table></td><td colspan="2"><table >';
723 723
 		echo '<tr><td><h3>'.lang('Daily tables').":</h3></td></tr>";
724
-		foreach(self::$relative as $value) {
725
-			echo '<tr><td>{{table/'.$value. '}} ... {{endtable}}</td></tr>';
724
+		foreach (self::$relative as $value) {
725
+			echo '<tr><td>{{table/'.$value.'}} ... {{endtable}}</td></tr>';
726 726
 		}
727 727
 		echo '<tr><td>{{table/day_n}} ... {{endtable}}</td><td>1 <= n <= 31</td></tr>';
728 728
 		echo '</table></td></tr>';
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
 		echo '<tr><td>{{day/birthdays}}</td><td colspan="3">'.lang('Birthdays').'</td></tr>';
733 733
 
734 734
 		echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";
735
-		foreach(array(
735
+		foreach (array(
736 736
 			'link' => lang('HTML link to the current record'),
737 737
 			'links' => lang('Titles of any entries linked to the current record, excluding attached files'),
738 738
 			'attachments' => lang('List of files linked to the current record'),
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -617,7 +617,7 @@
 block discarded – undo
617 617
 	protected function get_birthdays($day)
618 618
 	{
619 619
 		$contacts = new Api\Contacts();
620
-		$birthdays = Array();
620
+		$birthdays = array();
621 621
 		foreach($contacts->get_addressbooks() as $owner => $name)
622 622
 		{
623 623
 			$birthdays += $contacts->read_birthdays($owner, substr($day, 0, 4));
Please login to merge, or discard this patch.
importexport/inc/class.importexport_widget_filter.inc.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -41,18 +41,18 @@  discard block
 block discarded – undo
41 41
 	public function beforeSendToClient($cname, Array $expand = Array())
42 42
 	{
43 43
 		$form_name = self::form_name($cname, $this->id);
44
-		if($this->getElementAttribute($form_name, 'customfields'))
44
+		if ($this->getElementAttribute($form_name, 'customfields'))
45 45
 		{
46 46
 			// Already done?  Still need to process, or sel_options may be missing
47 47
 			unset(self::$request->modifications[$form_name]);
48 48
 		}
49
-		$value =& self::get_array(self::$request->content, $form_name, true);
49
+		$value = & self::get_array(self::$request->content, $form_name, true);
50 50
 		$fields = $value['fields'];
51 51
 		unset($value['fields']);
52 52
 		$relative_dates = $this->attrs['relative_dates'];
53 53
 
54 54
 		// Fallback, so there's something there...
55
-		if(!is_array($fields))
55
+		if (!is_array($fields))
56 56
 		{
57 57
 			error_log("$this has no fields");
58 58
 			self::$transformation = array(
@@ -69,14 +69,14 @@  discard block
 block discarded – undo
69 69
 		$this->setElementAttribute($form_name, 'prefix', self::$prefix);
70 70
 		
71 71
 		$n = 1;
72
-		foreach($fields as $lname => &$field)
72
+		foreach ($fields as $lname => &$field)
73 73
 		{
74
-			$type =& $field['type'];
74
+			$type = & $field['type'];
75 75
 			
76 76
 			// No filters are required
77 77
 			$field['needed'] = false;
78 78
 			
79
-			switch($type)
79
+			switch ($type)
80 80
 			{
81 81
 				case 'date':
82 82
 				case 'date-time':
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 						'get_rows'      => 'etemplate.ajax_select_widget.array_rows',
94 94
 						'id_field'      => ajax_select_widget::ARRAY_KEY,
95 95
 					);
96
-					if($field['rows']) {
96
+					if ($field['rows']) {
97 97
 						$options['num_rows'] = $field['rows'];
98 98
 					}
99 99
 
@@ -112,22 +112,22 @@  discard block
 block discarded – undo
112 112
 					break;
113 113
 				case 'select':
114 114
 				default:
115
-					if(strpos($field['type'],'select') === 0)
115
+					if (strpos($field['type'], 'select') === 0)
116 116
 					{
117 117
 						if (count($field['values']) == 1 && isset($field['values']['@']))
118 118
 						{
119 119
 							$field['values'] = Api\Storage\Customfields::get_options_from_file($field['values']['@']);
120 120
 						}
121
-						foreach((array)$field['values'] as $key => $val)
121
+						foreach ((array)$field['values'] as $key => $val)
122 122
 						{
123
-							if (substr($val = lang($val),-1) != '*')
123
+							if (substr($val = lang($val), -1) != '*')
124 124
 							{
125 125
 								$field['values'][$key] = $val;
126 126
 							}
127 127
 						}
128 128
 
129 129
 						// We don't want the 'All' or 'Select...' if it's there
130
-						if(is_array($field['values']) && $field['values'][''])
130
+						if (is_array($field['values']) && $field['values'][''])
131 131
 						{
132 132
 							unset($field['values']['']);
133 133
 						}
@@ -135,27 +135,27 @@  discard block
 block discarded – undo
135 135
 						$this->setElementAttribute($form_name.'['.self::$prefix.$lname.']', 'tags', TRUE);
136 136
 						$this->setElementAttribute($form_name.'['.self::$prefix.$lname.']', 'multiple', TRUE);
137 137
 					}
138
-					else if( $GLOBALS['egw_info']['apps'][$field['type']])
138
+					else if ($GLOBALS['egw_info']['apps'][$field['type']])
139 139
 					{
140 140
 						// Links
141 141
 					}
142 142
 					else
143 143
 					{
144
-						error_log('Trying to filter with unsupported field type ' . $lname . ': ' . $field['type']);
144
+						error_log('Trying to filter with unsupported field type '.$lname.': '.$field['type']);
145 145
 					}
146 146
 			}
147 147
 
148 148
 			// Send select options
149
-			if($field['values'])
149
+			if ($field['values'])
150 150
 			{
151 151
 				self::$request->sel_options[self::$prefix.$lname] = $field['values'];
152 152
 			}
153 153
 			$widget = self::factory($type, '<'.$type.' type="'.$type.'" id="'.self::$prefix.$lname.'"/>', self::$prefix.$lname);
154
-			if(method_exists($widget, 'beforeSendToClient'))
154
+			if (method_exists($widget, 'beforeSendToClient'))
155 155
 			{
156 156
 				$widget->id = self::$prefix.$lname;
157 157
 				$widget->attrs['type'] = $type;
158
-				if($type == 'link-to')
158
+				if ($type == 'link-to')
159 159
 				{
160 160
 					$widget->attrs['only_app'] = $field['type'];
161 161
 				}
@@ -167,22 +167,22 @@  discard block
 block discarded – undo
167 167
 		parent::beforeSendToClient($cname, $expand);
168 168
 
169 169
 		$this->setElementAttribute($form_name, 'customfields', $fields);
170
-		$this->setElementAttribute($form_name, 'fields',array_fill_keys(array_keys($fields), true));
170
+		$this->setElementAttribute($form_name, 'fields', array_fill_keys(array_keys($fields), true));
171 171
 		return false;
172 172
 	}
173 173
 	
174
-	public function validate($cname, array $expand, array $content, &$validated=array())
174
+	public function validate($cname, array $expand, array $content, &$validated = array())
175 175
 	{
176 176
 		$form_name = self::form_name($cname, $this->id, $expand);
177 177
 		if (!$this->is_readonly($cname, $form_name))
178 178
 		{
179 179
 			$value_in = (array)self::get_array($content, $form_name);
180
-			$valid =& self::get_array($validated, $this->id ? $form_name : $field, true);
180
+			$valid = & self::get_array($validated, $this->id ? $form_name : $field, true);
181 181
 
182
-			foreach($value_in as $key => $value)
182
+			foreach ($value_in as $key => $value)
183 183
 			{
184 184
 				// Client side cf widget automatically prefixes #
185
-				$valid[substr($key,strlen(self::$prefix))] = $value;
185
+				$valid[substr($key, strlen(self::$prefix))] = $value;
186 186
 			}
187 187
 		}
188 188
 	}
Please login to merge, or discard this patch.
importexport/inc/class.importexport_export_ui.inc.php 2 patches
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -36,46 +36,46 @@  discard block
 block discarded – undo
36 36
 	private $export_plugins;
37 37
 
38 38
 	public function __construct() {
39
-		Framework::includeJS('.','export_dialog','importexport');
40
-		Framework::includeJS('.','importexport','importexport');
39
+		Framework::includeJS('.', 'export_dialog', 'importexport');
40
+		Framework::includeJS('.', 'importexport', 'importexport');
41 41
 		$this->user = $GLOBALS['egw_info']['user']['user_id'];
42
-		$this->export_plugins = importexport_helper_functions::get_plugins('all','export');
42
+		$this->export_plugins = importexport_helper_functions::get_plugins('all', 'export');
43 43
 
44 44
 	}
45 45
 
46
-	public function export_dialog($_content=array()) {
46
+	public function export_dialog($_content = array()) {
47 47
 		$tabs = 'general_tab|selection_tab|options_tab';
48 48
 		$sel_options = array();
49 49
 		$readonlys = array();
50 50
 		$preserv = array();
51 51
 
52
-		$et = new Etemplate(self::_appname. '.export_dialog');
52
+		$et = new Etemplate(self::_appname.'.export_dialog');
53 53
 		$_appname = $_content['appname'] ? $_content['appname'] : $_GET['appname'];
54 54
 		$_definition = $_content['definition'] ? $_content['definition'] : $_GET['definition'];
55 55
 		$_plugin = $_content['plugin'] ? $_content['plugin'] : $_GET['plugin'];
56 56
 		// Select all from context menu, means use all search results, not just selected
57
-		if($_GET['select_all'] == 'true') $_GET['selection'] = 'search';
57
+		if ($_GET['select_all'] == 'true') $_GET['selection'] = 'search';
58 58
 		$_selection = $_content['selection'] ? $_content['selection'] : $_GET['selection'];
59
-		if($_GET['selection'] || $_content['selection_passed']) $content['selection_passed'] = $preserv['selection_passed'] = true;
59
+		if ($_GET['selection'] || $_content['selection_passed']) $content['selection_passed'] = $preserv['selection_passed'] = true;
60 60
 
61 61
 		// Check global setting
62
-		if(!Api\Storage\Merge::is_export_limit_excepted()) {
62
+		if (!Api\Storage\Merge::is_export_limit_excepted()) {
63 63
 			$export_limit = Api\Storage\Merge::getExportLimit($_appname);
64
-			if($export_limit == 'no') {
64
+			if ($export_limit == 'no') {
65 65
 				die(lang('Admin disabled exporting'));
66 66
 			}
67 67
 		}
68 68
 			//error_log(__FILE__.__FUNCTION__. '::$_GET[\'appname\']='. $_appname. ',$_GET[\'definition\']='. $_definition. ',$_GET[\'plugin\']='.$_plugin. ',$_GET[\'selection\']='.$_selection);
69 69
 		// if appname is given and valid, list available definitions (if no definition is given)
70
-		$readonlys['appname'] = (!empty($_appname) && $GLOBALS['egw']->acl->check('run',1,$_appname));
70
+		$readonlys['appname'] = (!empty($_appname) && $GLOBALS['egw']->acl->check('run', 1, $_appname));
71 71
 		$content['appname'] = $_appname;
72 72
 		$preserv['appname'] = $_appname;
73
-		if(empty($_appname)) {
74
-			$et->setElementAttribute('select_definition','disabled',true);
73
+		if (empty($_appname)) {
74
+			$et->setElementAttribute('select_definition', 'disabled', true);
75 75
 		}
76 76
 
77 77
 		// Check for preferred definition
78
-		if(!$_definition && $_appname) {
78
+		if (!$_definition && $_appname) {
79 79
 			$_definition = $GLOBALS['egw_info']['user']['preferences'][$_appname]['nextmatch-export-definition'];
80 80
 		}
81 81
 		// fill definitions
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
 			}
98 98
 			unset($definition);
99 99
 		}
100
-		if(count($sel_options['definition']) == 2 && !$content['definition']) {
100
+		if (count($sel_options['definition']) == 2 && !$content['definition']) {
101 101
 			$content['definition'] = end($sel_options['definition']);
102 102
 			unset($sel_options['definition']['']);
103 103
 		}
104 104
 		unset($definitions);
105 105
 		//$sel_options['definition']['expert'] = lang('Expert options');
106 106
 
107
-		if(isset($_definition) && array_key_exists($_definition,$sel_options['definition'])) {
107
+		if (isset($_definition) && array_key_exists($_definition, $sel_options['definition'])) {
108 108
 			$content['definition'] = $_definition;
109 109
 		}
110 110
 
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 		$sel_options['plugin'] = $this->export_plugins[$_appname]['export'];
113 113
 
114 114
 		// show definitions or plugins in ui?
115
-		if($content['definition'] == 'expert') {
116
-			if(isset($_plugin) && array_key_exists($_plugin,$sel_options['plugin'])) {
115
+		if ($content['definition'] == 'expert') {
116
+			if (isset($_plugin) && array_key_exists($_plugin, $sel_options['plugin'])) {
117 117
 				$content['plugin'] = $_plugin;
118 118
 				$selected_plugin = $_plugin;
119 119
 			}
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 			$readonlys['save_definition'] = true;
132 132
 
133 133
 			$definition = new importexport_definition($content['definition']);
134
-			if($definition) {
134
+			if ($definition) {
135 135
 				$content += (array)$definition->plugin_options;
136 136
 				$selected_plugin = $definition->plugin;
137 137
 				$content['description'] = $definition->description;
@@ -148,27 +148,27 @@  discard block
 block discarded – undo
148 148
 			'|'	=>	'|',
149 149
 			''	=>	lang('Other')
150 150
 		);
151
-		if(!$sel_options['delimiter'][$content['delimiter']]) $sel_options['delimiter'][$content['delimiter']] = $content['delimiter'];
152
-		$sel_options['delimiter'][$content['delimiter']] = lang('Use default') . ' "' . $sel_options['delimiter'][$content['delimiter']] . '"';
151
+		if (!$sel_options['delimiter'][$content['delimiter']]) $sel_options['delimiter'][$content['delimiter']] = $content['delimiter'];
152
+		$sel_options['delimiter'][$content['delimiter']] = lang('Use default').' "'.$sel_options['delimiter'][$content['delimiter']].'"';
153 153
 
154
-		if(!$_content['delimiter']) $et->setElementAttribute('other_delimiter','disabled',true);
154
+		if (!$_content['delimiter']) $et->setElementAttribute('other_delimiter', 'disabled', true);
155 155
 
156 156
 		// Other delimiter (options)
157
-		if($_content['other_delimiter']) $_content['delimiter'] = $_content['other_delimiter'];
157
+		if ($_content['other_delimiter']) $_content['delimiter'] = $_content['other_delimiter'];
158 158
 
159 159
 		// handle selector
160
-		if($selected_plugin) {
160
+		if ($selected_plugin) {
161 161
 			$content['plugin'] = $selected_plugin;
162 162
 			$plugin_object = new $selected_plugin;
163 163
 
164 164
 			$content['description'] = $plugin_object->get_description();
165 165
 
166 166
 			// fill options tab
167
- 			if(method_exists($plugin_object, 'get_selectors_html')) {
167
+ 			if (method_exists($plugin_object, 'get_selectors_html')) {
168 168
 				$content['plugin_options_html'] = $plugin_object->get_options_html();
169 169
 			} else {
170 170
 				$options = $plugin_object->get_options_etpl($definition);
171
-				if(is_array($options)) {
171
+				if (is_array($options)) {
172 172
 					$content['plugin_options_template'] = $options['name'];
173 173
 					$content += (array)$options['content'];
174 174
 					$sel_options += (array)$options['sel_options'];
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		}
182 182
 
183 183
 		// fill selection tab
184
-		if($definition && is_array($definition->plugin_options) && $definition->plugin_options['selection'] && !$content['selection_passed']) {
184
+		if ($definition && is_array($definition->plugin_options) && $definition->plugin_options['selection'] && !$content['selection_passed']) {
185 185
 			$_selection = $definition->plugin_options['selection'];
186 186
 		}
187 187
 
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
 			$preserv['selection'] = $_selection;
192 192
 		}
193 193
 		elseif ($plugin_object) {
194
- 			if(method_exists($plugin_object, 'get_selectors_html')) {
194
+ 			if (method_exists($plugin_object, 'get_selectors_html')) {
195 195
 				$content['plugin_selectors_html'] = $plugin_object->get_selectors_html();
196 196
 			} else {
197 197
 				$options = $plugin_object->get_selectors_etpl($definition);
198
-				if(is_array($options)) {
198
+				if (is_array($options)) {
199 199
 					$content += is_array($options['content']) ? $options['content'] : array('selection' => $options['content']);
200 200
 					$sel_options += (array)$options['sel_options'];
201 201
 					$readonlys['selection'] = (array)$options['readonlys'];
@@ -205,12 +205,12 @@  discard block
 block discarded – undo
205 205
 					$content['plugin_selectors_template'] = $options;
206 206
 				}
207 207
 			}
208
-			if(!$content['plugin_selectors_html'] && !$content['plugin_selectors_template']) {
208
+			if (!$content['plugin_selectors_html'] && !$content['plugin_selectors_template']) {
209 209
 				$readonlys[$tabs]['selection_tab'] = true;
210 210
 			}
211 211
 			$content['filter'] = $definition->filter;
212 212
 			$content['filter']['fields'] = importexport_helper_functions::get_filter_fields($_appname, $selected_plugin);
213
-			if(!$content['filter']['fields'])
213
+			if (!$content['filter']['fields'])
214 214
 			{
215 215
 				$content['no_filter'] = true;
216 216
 			}
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		{
229 229
 			$content['selection'] = 'filter';
230 230
 		}
231
-		if(!$content['selection'])
231
+		if (!$content['selection'])
232 232
 		{
233 233
 			$content['selection'] = 'search';
234 234
 		}
@@ -239,33 +239,33 @@  discard block
 block discarded – undo
239 239
 		//error_log(__METHOD__.__LINE__.array2string($apps));
240 240
 		if (empty($apps)) throw new Exception('Error: no application profiles available for export');
241 241
 		if (!is_array($apps) && $apps) $apps = (array)$apps;
242
-		$sel_options['appname'] = array('' => lang('Select one')) + array_combine($apps,$apps);
243
-		if(!$_application && !$selected_plugin) {
242
+		$sel_options['appname'] = array('' => lang('Select one')) + array_combine($apps, $apps);
243
+		if (!$_application && !$selected_plugin) {
244 244
 			$content['plugin_selectors_html'] = $content['plugin_options_html'] =
245 245
 			lang('You need to select an app and format first!');
246 246
 			$readonlys[$tabs] = array('selection_tab' => true, 'options_tab' => true);
247 247
 		}
248 248
 
249
-		if($_content['preview'] || $_content['export'])
249
+		if ($_content['preview'] || $_content['export'])
250 250
 		{
251 251
 			//error_log(__LINE__.__FILE__.'$_content: '.print_r($_content,true));
252 252
 			$response = Api\Json\Response::get();
253 253
 
254 254
 			if ($_content['definition'] == 'expert') {
255 255
 				$definition = new importexport_definition();
256
-				$definition->definition_id	= $_content['definition_id'] ? $_content['definition_id'] : '';
256
+				$definition->definition_id = $_content['definition_id'] ? $_content['definition_id'] : '';
257 257
 				$definition->name		= $_content['name'] ? $_content['name'] : '';
258
-				$definition->application	= $_content['appname'];
259
-				$definition->plugin		= $_content['plugin'];
258
+				$definition->application = $_content['appname'];
259
+				$definition->plugin = $_content['plugin'];
260 260
 				$definition->type		= 'export';
261
-				$definition->allowed_users	= $_content['allowed_users'] ? $_content['allowed_users'] : $this->user;
262
-				$definition->owner		= $_content['owner'] ? $_content['owner'] : $this->user;
261
+				$definition->allowed_users = $_content['allowed_users'] ? $_content['allowed_users'] : $this->user;
262
+				$definition->owner = $_content['owner'] ? $_content['owner'] : $this->user;
263 263
 			}
264 264
 			else {
265 265
 				$definition = new importexport_definition($_content['definition']);
266 266
 			}
267 267
 
268
-			if(!is_array($definition->plugin_options)) {
268
+			if (!is_array($definition->plugin_options)) {
269 269
 				$definition->plugin_options = array(
270 270
 					'mapping'	=>	array()
271 271
 				);
@@ -275,30 +275,30 @@  discard block
 block discarded – undo
275 275
 			// Note that because not all dates are DB dates, the plugin has to handle them
276 276
 			$filter = array();
277 277
 			$_content['filter'] = $_content['filter_html'] ? $_content['filter_html'] : $_content['filter_tpl'];
278
-			if(is_array($_content['filter']))
278
+			if (is_array($_content['filter']))
279 279
 			{
280
-				foreach($_content['filter'] as $key => $value)
280
+				foreach ($_content['filter'] as $key => $value)
281 281
 				{
282 282
 					// Handle multiple values
283
-					if(!is_array($value) && strpos($value,',') !== false) $value = explode(',',$value);
283
+					if (!is_array($value) && strpos($value, ',') !== false) $value = explode(',', $value);
284 284
 
285 285
 					$filter[$key] = $value;
286 286
 
287 287
 					// Skip empty values or empty ranges
288
-					if($value == "" || is_null($value) || (is_array($value) && count($value) == 0) || is_array($value) && array_key_exists('from',$value) && !$value['from'] && !$value['to'] )
288
+					if ($value == "" || is_null($value) || (is_array($value) && count($value) == 0) || is_array($value) && array_key_exists('from', $value) && !$value['from'] && !$value['to'])
289 289
 					{
290 290
 						unset($filter[$key]);
291 291
 					}
292
-					if(is_array($value) && array_key_exists('from', $value) && $value['from'])
292
+					if (is_array($value) && array_key_exists('from', $value) && $value['from'])
293 293
 					{
294
-						$filter[$key]['from'] = Api\DateTime::to($value['from'],'ts');
294
+						$filter[$key]['from'] = Api\DateTime::to($value['from'], 'ts');
295 295
 					}
296 296
 					// If user selects an end date, they most likely want entries including that date
297
-					if(is_array($value) && array_key_exists('to',$value) && $value['to'] )
297
+					if (is_array($value) && array_key_exists('to', $value) && $value['to'])
298 298
 					{
299 299
 						// Adjust time to 23:59:59
300 300
 						$filter[$key]['to'] = new Api\DateTime($value['to']);
301
-						$filter[$key]['to']->setTime(23,59,59);
301
+						$filter[$key]['to']->setTime(23, 59, 59);
302 302
 						$filter[$key]['to'] = $filter[$key]['to']->format('ts');
303 303
 					}
304 304
 				}
@@ -312,19 +312,19 @@  discard block
 block discarded – undo
312 312
 				$_content
313 313
 			);
314 314
 
315
-			if(!$definition->plugin_options['selection']) {
316
-				$response->alert( lang('No records selected'));
315
+			if (!$definition->plugin_options['selection']) {
316
+				$response->alert(lang('No records selected'));
317 317
 				return;
318 318
 			}
319 319
 
320
-			$tmpfname = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'export');
320
+			$tmpfname = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'export');
321 321
 			$file = fopen($tmpfname, "w+");
322
-			if (! $charset = $definition->plugin_options['charset']) {
322
+			if (!$charset = $definition->plugin_options['charset']) {
323 323
 				$charset = Api\Translation::charset();
324 324
 			}
325
-			if($charset == 'user')
325
+			if ($charset == 'user')
326 326
 			{
327
-				switch($definition->plugin)
327
+				switch ($definition->plugin)
328 328
 				{
329 329
 					case 'addressbook_export_vcard':
330 330
 						$charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset'];
@@ -334,9 +334,9 @@  discard block
 block discarded – undo
334 334
 				}
335 335
 			}
336 336
 			$plugin_object = new $definition->plugin;
337
-			$result = $plugin_object->export( $file, $definition );
337
+			$result = $plugin_object->export($file, $definition);
338 338
 
339
-			if(is_object($result) && method_exists($result, 'get_num_of_records'))
339
+			if (is_object($result) && method_exists($result, 'get_num_of_records'))
340 340
 			{
341 341
 				$record_count = $result->get_num_of_records();
342 342
 			}
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 			// Store charset to use in header
345 345
 			Api\Cache::setSession('importexport', $tmpfname, $charset, 100);
346 346
 
347
-			if($_content['export'] == 'pressed') {
347
+			if ($_content['export'] == 'pressed') {
348 348
 				fclose($file);
349 349
 				$filename = pathinfo($tmpfname, PATHINFO_FILENAME);
350 350
 				$link_query = array(
@@ -356,25 +356,25 @@  discard block
 block discarded – undo
356 356
 				);
357 357
 
358 358
 				// Allow plugins to suggest a file name - return false if they have no suggestion
359
-				if(method_exists($plugin_object, 'get_filename') && $plugin_filename = $plugin_object->get_filename())
359
+				if (method_exists($plugin_object, 'get_filename') && $plugin_filename = $plugin_object->get_filename())
360 360
 				{
361 361
 					$link_query['filename'] = $plugin_filename;
362 362
 				}
363
-				$response->redirect( $GLOBALS['egw']->link('/index.php',$link_query),true);
363
+				$response->redirect($GLOBALS['egw']->link('/index.php', $link_query), true);
364 364
 				Framework::window_close();
365 365
 				return;
366 366
 			}
367
-			elseif($_content['preview'] == 'pressed') {
367
+			elseif ($_content['preview'] == 'pressed') {
368 368
 				fseek($file, 0);
369 369
 				$item_count = 1;
370 370
 				$preview = '';
371
-				$search = array('[\016]','[\017]',
372
-								'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
373
-								'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
371
+				$search = array('[\016]', '[\017]',
372
+								'[\020]', '[\021]', '[\022]', '[\023]', '[\024]', '[\025]', '[\026]', '[\027]',
373
+								'[\030]', '[\031]', '[\032]', '[\033]', '[\034]', '[\035]', '[\036]', '[\037]');
374 374
 				$replace = $preview = '';
375 375
 
376
-				while(!feof($file) && $item_count < 30) {
377
-					$preview .= preg_replace($search,$replace,fgets($file,1024));
376
+				while (!feof($file) && $item_count < 30) {
377
+					$preview .= preg_replace($search, $replace, fgets($file, 1024));
378 378
 					$item_count++;
379 379
 				}
380 380
 
@@ -382,12 +382,12 @@  discard block
 block discarded – undo
382 382
 				unlink($tmpfname);
383 383
 
384 384
 				// Convert back to system charset for display
385
-				$preview = Api\Translation::convert( $preview,
385
+				$preview = Api\Translation::convert($preview,
386 386
 					$charset,
387 387
 					Api\Translation::charset()
388 388
 				);
389 389
 
390
-				$preview = "<div class='header'>".lang('Preview') . "<span class='count'>".(int)$record_count."</span></div>".$preview;
390
+				$preview = "<div class='header'>".lang('Preview')."<span class='count'>".(int)$record_count."</span></div>".$preview;
391 391
 
392 392
 				$et->setElementAttribute('preview-box', 'value', nl2br($preview));
393 393
 				return;
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 			$readonlys[$tabs]['selection'] = false;
400 400
 		}
401 401
 		//error_log(print_r($content,true));
402
-		return $et->exec(self::_appname. '.importexport_export_ui.export_dialog',$content,$sel_options,$readonlys,$preserv,2);
402
+		return $et->exec(self::_appname.'.importexport_export_ui.export_dialog', $content, $sel_options, $readonlys, $preserv, 2);
403 403
 	}
404 404
 
405 405
 	public function ajax_get_definition_description($_definition) {
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 			}
415 415
 			unset ($_object);
416 416
 		}
417
-		$_response->assign('importexport-export_dialog_plugin_description','innerHTML',$description);
417
+		$_response->assign('importexport-export_dialog_plugin_description', 'innerHTML', $description);
418 418
 	}
419 419
 
420 420
 	public function ajax_get_plugin_description($_plugin) {
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 		if (is_a($plugin_object, 'importexport_iface_export_plugin')) {
425 425
 			$description = $plugin_object->get_description();
426 426
 		}
427
-		$_response->addAssign('importexport-export_dialog_plugin_description','innerHTML',$description);
427
+		$_response->addAssign('importexport-export_dialog_plugin_description', 'innerHTML', $description);
428 428
 
429 429
 		unset ($plugin_object);
430 430
 	}
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 */
438 438
 	public function download($_tmpfname = '') {
439 439
 		$tmpfname = $_tmpfname ? $_tmpfname : $_GET['_filename'];
440
-		$tmpfname = $GLOBALS['egw_info']['server']['temp_dir'] .'/'. $tmpfname;
440
+		$tmpfname = $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpfname;
441 441
 		if (!is_readable($tmpfname)) die();
442 442
 
443 443
 		$appname = $_GET['_appname'];
@@ -446,13 +446,13 @@  discard block
 block discarded – undo
446 446
 		// Turn off all output buffering
447 447
 		while (@ob_end_clean());
448 448
 
449
-		$file = fopen($tmpfname,'rb');
449
+		$file = fopen($tmpfname, 'rb');
450 450
 
451 451
 		// Get charset
452 452
 		$charset = Api\Cache::getSession('importexport', $tmpfname);
453 453
 
454 454
 		Api\Header\Content::type($nicefname.'.'.$_GET['_suffix'],
455
-			($_GET['_type'] ? $_GET['_type'] : 'application/text') . ($charset ? '; charset='.$charset : ''),
455
+			($_GET['_type'] ? $_GET['_type'] : 'application/text').($charset ? '; charset='.$charset : ''),
456 456
 			filesize($tmpfname));
457 457
 		fpassthru($file);
458 458
 
Please login to merge, or discard this 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.