Completed
Push — master ( 047af4...8edb92 )
by Nathan
20:35
created
api/src/Storage/Tracking.php 1 patch
Spacing   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -207,22 +207,22 @@  discard block
 block discarded – undo
207 207
 	 * @param string $cf_app = null if set, custom field names get added to $field2history
208 208
 	 * @return bo_tracking
209 209
 	 */
210
-	function __construct($cf_app = null, $notification_class=false)
210
+	function __construct($cf_app = null, $notification_class = false)
211 211
 	{
212 212
 		if ($cf_app)
213 213
 		{
214
-			$linkable_cf_types = array('link-entry')+array_keys(Api\Link::app_list());
215
-			foreach(Customfields::get($cf_app, true) as $cf_name => $cf_data)
214
+			$linkable_cf_types = array('link-entry') + array_keys(Api\Link::app_list());
215
+			foreach (Customfields::get($cf_app, true) as $cf_name => $cf_data)
216 216
 			{
217 217
 				$this->field2history['#'.$cf_name] = '#'.$cf_name;
218 218
 
219
-				if (in_array($cf_data['type'],$linkable_cf_types))
219
+				if (in_array($cf_data['type'], $linkable_cf_types))
220 220
 				{
221 221
 					$this->cf_link_fields['#'.$cf_name] = $cf_data['type'] == 'link-entry' ? '' : $cf_data['type'];
222 222
 				}
223 223
 			}
224 224
 		}
225
-		if($notification_class)
225
+		if ($notification_class)
226 226
 		{
227 227
 			$this->notification_class = $notification_class;
228 228
 		}
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
 	 * @param int|string $receiver nummeric account_id or email address
238 238
 	 * @return array of details as array with values for keys 'label','value','type'
239 239
 	 */
240
-	function get_details($data,$receiver=null)
240
+	function get_details($data, $receiver = null)
241 241
 	{
242
-		unset($data, $receiver);	// not uses as just a stub
242
+		unset($data, $receiver); // not uses as just a stub
243 243
 
244 244
 		return array();
245 245
 	}
@@ -254,10 +254,10 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @return array of details as array with values for keys 'label','value','type'
256 256
 	 */
257
-	function get_customfields($data, $only_type2=null, $user = false)
257
+	function get_customfields($data, $only_type2 = null, $user = false)
258 258
 	{
259 259
 		$details = array();
260
-		if(!is_numeric($user))
260
+		if (!is_numeric($user))
261 261
 		{
262 262
 			$user = false;
263 263
 		}
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 		if (($cfs = Customfields::get($this->app, $user, $only_type2)))
266 266
 		{
267 267
 			$header_done = false;
268
-			foreach($cfs as $name => $field)
268
+			foreach ($cfs as $name => $field)
269 269
 			{
270 270
 				if (in_array($field['type'], Customfields::$non_printable_fields)) continue;
271 271
 
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
 	 * @param array $old = null old/last state of the entry or null for a new entry
312 312
 	 * @return mixed
313 313
 	 */
314
-	protected function get_config($name,$data,$old=null)
314
+	protected function get_config($name, $data, $old = null)
315 315
 	{
316
-		unset($name, $data, $old);	// not used as just a stub
316
+		unset($name, $data, $old); // not used as just a stub
317 317
 
318 318
 		return null;
319 319
 	}
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 	 * @param boolean $skip_notification = false do NOT send any notification
330 330
 	 * @return int|boolean false on error, integer number of changes logged or true for new entries ($old == null)
331 331
 	 */
332
-	public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null,$skip_notification=false)
332
+	public function track(array $data, array $old = null, $user = null, $deleted = null, array $changed_fields = null, $skip_notification = false)
333 333
 	{
334 334
 		$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
335 335
 
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 		if ($old && $this->field2history)
339 339
 		{
340 340
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true));
341
-			$changes = $this->save_history($data,$old,$deleted,$changed_fields);
341
+			$changes = $this->save_history($data, $old, $deleted, $changed_fields);
342 342
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true));
343 343
 			//error_log(__METHOD__.__LINE__.' Changes:'.print_r($changes,true));
344 344
 		}
@@ -346,10 +346,10 @@  discard block
 block discarded – undo
346 346
 		//error_log(__METHOD__.__LINE__.' LinkFields:'.array2string($this->cf_link_fields));
347 347
 		if ($changes && $this->cf_link_fields)
348 348
 		{
349
-			$this->update_links($data,(array)$old);
349
+			$this->update_links($data, (array)$old);
350 350
 		}
351 351
 		// do not run do_notifications if we have no changes
352
-		if ($changes && !$skip_notification && !$this->do_notifications($data,$old,$deleted))
352
+		if ($changes && !$skip_notification && !$this->do_notifications($data, $old, $deleted))
353 353
 		{
354 354
 			$changes = false;
355 355
 		}
@@ -366,45 +366,45 @@  discard block
 block discarded – undo
366 366
 	{
367 367
 		//error_log(__METHOD__.__LINE__.array2string($data).function_backtrace());
368 368
 		//error_log(__METHOD__.__LINE__.array2string($this->cf_link_fields));
369
-		foreach(array_keys((array)$this->cf_link_fields) as $name)
369
+		foreach (array_keys((array)$this->cf_link_fields) as $name)
370 370
 		{
371 371
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name]));
372 372
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name]));
373
-			if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id'];
374
-			if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id'];
373
+			if (is_array($data[$name]) && array_key_exists('id', $data[$name])) $data[$name] = $data[$name]['id'];
374
+			if (is_array($old[$name]) && array_key_exists('id', $old[$name])) $old[$name] = $old[$name]['id'];
375 375
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name]));
376 376
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name]));
377 377
 		}
378
-		$current_ids = array_unique(array_diff(array_intersect_key($data,$this->cf_link_fields),array('',0,NULL)));
379
-		$old_ids = $old ? array_unique(array_diff(array_intersect_key($old,$this->cf_link_fields),array('',0,NULL))) : array();
378
+		$current_ids = array_unique(array_diff(array_intersect_key($data, $this->cf_link_fields), array('', 0, NULL)));
379
+		$old_ids = $old ? array_unique(array_diff(array_intersect_key($old, $this->cf_link_fields), array('', 0, NULL))) : array();
380 380
 		//error_log(__METHOD__.__LINE__.array2string($current_ids));
381 381
 		//error_log(__METHOD__.__LINE__.array2string($old_ids));
382 382
 		// create links for added application entry
383
-		foreach(array_diff($current_ids,$old_ids) as $name => $id)
383
+		foreach (array_diff($current_ids, $old_ids) as $name => $id)
384 384
 		{
385 385
 			if (!($app = $this->cf_link_fields[$name]))
386 386
 			{
387
-				list($app,$id) = explode(':',$id);
388
-				if (!$id) continue;	// can be eg. 'addressbook:', if no contact selected
387
+				list($app, $id) = explode(':', $id);
388
+				if (!$id) continue; // can be eg. 'addressbook:', if no contact selected
389 389
 			}
390 390
 			$source_id = $data[$this->id_field];
391 391
 			//error_log(__METHOD__.__LINE__.array2string($source_id));
392
-			if ($source_id) Api\Link::link($this->app,$source_id,$app,$id);
392
+			if ($source_id) Api\Link::link($this->app, $source_id, $app, $id);
393 393
 			//error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);");
394 394
 			//echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n";
395 395
 		}
396 396
 
397 397
 		// unlink removed application entries
398
-		foreach(array_diff($old_ids,$current_ids) as $name => $id)
398
+		foreach (array_diff($old_ids, $current_ids) as $name => $id)
399 399
 		{
400
-			if (!isset($data[$name])) continue;	// ignore not set link cf's, eg. from sync clients
400
+			if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients
401 401
 			if (!($app = $this->cf_link_fields[$name]))
402 402
 			{
403
-				list($app,$id) = explode(':',$id);
403
+				list($app, $id) = explode(':', $id);
404 404
 				if (!$id) continue;
405 405
 			}
406 406
 			$source_id = $data[$this->id_field];
407
-			if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
407
+			if ($source_id) Api\Link::unlink(null, $this->app, $source_id, 0, $app, $id);
408 408
 			//echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n";
409 409
 		}
410 410
 	}
@@ -419,14 +419,14 @@  discard block
 block discarded – undo
419 419
 	 * @param array $changed_fields = null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again
420 420
 	 * @return int number of log-entries made
421 421
 	 */
422
-	protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null)
422
+	protected function save_history(array $data, array $old = null, $deleted = null, array $changed_fields = null)
423 423
 	{
424
-		unset($deleted);	// not used, but required by function signature
424
+		unset($deleted); // not used, but required by function signature
425 425
 
426 426
 		//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
427 427
 		if (is_null($changed_fields))
428 428
 		{
429
-			$changed_fields = self::changed_fields($data,$old);
429
+			$changed_fields = self::changed_fields($data, $old);
430 430
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
431 431
 		}
432 432
 		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0;
@@ -441,26 +441,26 @@  discard block
 block discarded – undo
441 441
 			$this->historylog->add('user_agent_action', $data[$this->id_field],
442 442
 				$_SERVER['HTTP_USER_AGENT'], $_SESSION[Api\Session::EGW_SESSION_VAR]['session_action']);
443 443
 		}
444
-		foreach($changed_fields as $name)
444
+		foreach ($changed_fields as $name)
445 445
 		{
446 446
 			$status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name;
447 447
 			//error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status));
448 448
 			if (is_array($status))	// 1:N relation --> remove common rows
449 449
 			{
450 450
 				//error_log(__METHOD__.__LINE__.' is Array');
451
-				self::compact_1_N_relation($data[$name],$status);
452
-				self::compact_1_N_relation($old[$name],$status);
453
-				$added = array_values(array_diff($data[$name],$old[$name]));
454
-				$removed = array_values(array_diff($old[$name],$data[$name]));
455
-				$n = max(array(count($added),count($removed)));
456
-				for($i = 0; $i < $n; ++$i)
451
+				self::compact_1_N_relation($data[$name], $status);
452
+				self::compact_1_N_relation($old[$name], $status);
453
+				$added = array_values(array_diff($data[$name], $old[$name]));
454
+				$removed = array_values(array_diff($old[$name], $data[$name]));
455
+				$n = max(array(count($added), count($removed)));
456
+				for ($i = 0; $i < $n; ++$i)
457 457
 				{
458 458
 					//error_log(__METHOD__."() $i: historylog->add('$name',data['$this->id_field']={$data[$this->id_field]},".array2string($added[$i]).','.array2string($removed[$i]));
459
-					$this->historylog->add($name,$data[$this->id_field],$added[$i],$removed[$i]);
459
+					$this->historylog->add($name, $data[$this->id_field], $added[$i], $removed[$i]);
460 460
 				}
461 461
 			}
462 462
 			else if (is_string($data[$name]) && is_string($old[$name]) && (
463
-					$this->historylog->needs_diff ($name, $data[$name]) || $this->historylog->needs_diff ($name, $old[$name])))
463
+					$this->historylog->needs_diff($name, $data[$name]) || $this->historylog->needs_diff($name, $old[$name])))
464 464
 			{
465 465
 				// Multiline string, just store diff
466 466
 				// Strip HTML first though
@@ -468,13 +468,13 @@  discard block
 block discarded – undo
468 468
 				$new_text = Api\Mail\Html::convertHTMLToText($data[$name]);
469 469
 
470 470
 				// If only change was something in HTML, show the HTML
471
-				if(trim($old_text) === trim($new_text))
471
+				if (trim($old_text) === trim($new_text))
472 472
 				{
473 473
 					$old_text = $old[$name];
474 474
 					$new_text = $data[$name];
475 475
 				}
476 476
 
477
-				$diff = new \Horde_Text_Diff('auto', array(explode("\n",$old_text), explode("\n",$new_text)));
477
+				$diff = new \Horde_Text_Diff('auto', array(explode("\n", $old_text), explode("\n", $new_text)));
478 478
 				$renderer = new \Horde_Text_Diff_Renderer_Unified();
479 479
 				$this->historylog->add(
480 480
 					$status,
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
 			else
487 487
 			{
488 488
 				//error_log(__METHOD__.__LINE__.' IDField:'.array2string($this->id_field).' ->'.$data[$this->id_field].' New:'.$data[$name].' Old:'.$old[$name]);
489
-				$this->historylog->add($status,$data[$this->id_field],
490
-					is_array($data[$name]) ? implode(',',$data[$name]) : $data[$name],
491
-					is_array($old[$name]) ? implode(',',$old[$name]) : $old[$name]);
489
+				$this->historylog->add($status, $data[$this->id_field],
490
+					is_array($data[$name]) ? implode(',', $data[$name]) : $data[$name],
491
+					is_array($old[$name]) ? implode(',', $old[$name]) : $old[$name]);
492 492
 			}
493 493
 		}
494 494
 		//error_log(__METHOD__.__LINE__.' return:'.count($changed_fields));
@@ -504,28 +504,28 @@  discard block
 block discarded – undo
504 504
 	 * @param array $old = null
505 505
 	 * @return array of keys with different values in $data and $old
506 506
 	 */
507
-	public function changed_fields(array $data,array $old=null)
507
+	public function changed_fields(array $data, array $old = null)
508 508
 	{
509 509
 		if (is_null($old)) return array_keys($data);
510 510
 		$changed_fields = array();
511
-		foreach($this->field2history as $name => $status)
511
+		foreach ($this->field2history as $name => $status)
512 512
 		{
513
-			if (!$old[$name] && !$data[$name]) continue;	// treat all sorts of empty equally
513
+			if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally
514 514
 
515
-			if ($name[0] == '#' && !isset($data[$name])) continue;	// no set customfields are not stored, therefore not changed
515
+			if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed
516 516
 
517 517
 			if (is_array($status))	// 1:N relation
518 518
 			{
519
-				self::compact_1_N_relation($data[$name],$status);
520
-				self::compact_1_N_relation($old[$name],$status);
519
+				self::compact_1_N_relation($data[$name], $status);
520
+				self::compact_1_N_relation($old[$name], $status);
521 521
 			}
522 522
 			if ($old[$name] != $data[$name])
523 523
 			{
524 524
 				// normalize arrays, we do NOT care for the order of multiselections
525 525
 				if (is_array($data[$name]) || is_array($old[$name]))
526 526
 				{
527
-					if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]);
528
-					if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]);
527
+					if (!is_array($data[$name])) $data[$name] = explode(',', $data[$name]);
528
+					if (!is_array($old[$name])) $old[$name] = explode(',', $old[$name]);
529 529
 					if (count($data[$name]) == count($old[$name]))
530 530
 					{
531 531
 						sort($data[$name]);
@@ -535,13 +535,13 @@  discard block
 block discarded – undo
535 535
 				}
536 536
 				elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name]))
537 537
 				{
538
-					continue;	// change only in CR (eg. different OS) --> ignore
538
+					continue; // change only in CR (eg. different OS) --> ignore
539 539
 				}
540 540
 				$changed_fields[] = $name;
541 541
 				//echo "<p>$name: ".array2string($data[$name]).' != '.array2string($old[$name])."</p>\n";
542 542
 			}
543 543
 		}
544
-		foreach($data as $name => $value)
544
+		foreach ($data as $name => $value)
545 545
 		{
546 546
 			if ($name[0] == '#' && $name[1] == '#' && $value !== $old[$name])
547 547
 			{
@@ -558,18 +558,18 @@  discard block
 block discarded – undo
558 558
 	 * @param array &$rows rows of the 1:N relation
559 559
 	 * @param array $cols field names as values
560 560
 	 */
561
-	private static function compact_1_N_relation(&$rows,array $cols)
561
+	private static function compact_1_N_relation(&$rows, array $cols)
562 562
 	{
563 563
 		if (is_array($rows))
564 564
 		{
565
-			foreach($rows as &$row)
565
+			foreach ($rows as &$row)
566 566
 			{
567 567
 				$values = array();
568
-				foreach($cols as $col)
568
+				foreach ($cols as $col)
569 569
 				{
570 570
 					$values[] = $row[$col];
571 571
 				}
572
-				$row = implode(self::ONE2N_SEPERATOR,$values);
572
+				$row = implode(self::ONE2N_SEPERATOR, $values);
573 573
 			}
574 574
 		}
575 575
 		else
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 	 * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified
589 589
 	 * @return boolean true on success, false on error (error messages are in $this->errors)
590 590
 	 */
591
-	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
591
+	public function do_notifications($data, $old, $deleted = null, &$email_notified = null)
592 592
 	{
593 593
 		$this->errors = $email_sent = array();
594 594
 		if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified;
@@ -596,19 +596,19 @@  discard block
 block discarded – undo
596 596
 		if (!$this->notify_current_user && $this->user)		// do we have a current user and should we notify the current user about his own changes
597 597
 		{
598 598
 			//error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him");
599
-			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email');
599
+			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email');
600 600
 		}
601
-		$skip_notify = $this->get_config('skip_notify',$data,$old);
602
-		if($skip_notify && is_array($skip_notify))
601
+		$skip_notify = $this->get_config('skip_notify', $data, $old);
602
+		if ($skip_notify && is_array($skip_notify))
603 603
 		{
604 604
 			$email_sent = array_merge($email_sent, $skip_notify);
605 605
 		}
606 606
 
607 607
 		// entry creator
608
-		if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field],'account_email')) &&
608
+		if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field], 'account_email')) &&
609 609
 			!in_array($email, $email_sent))
610 610
 		{
611
-			if ($this->send_notification($data,$old,$email,$data[$this->creator_field],'notify_creator'))
611
+			if ($this->send_notification($data, $old, $email, $data[$this->creator_field], 'notify_creator'))
612 612
 			{
613 613
 				$email_sent[] = $email;
614 614
 			}
@@ -617,12 +617,12 @@  discard block
 block discarded – undo
617 617
 		// members of group when entry owned by group
618 618
 		if ($this->creator_field && $GLOBALS['egw']->accounts->get_type($data[$this->creator_field]) == 'g')
619 619
 		{
620
-			foreach($GLOBALS['egw']->accounts->members($data[$this->creator_field],true) as $u)
620
+			foreach ($GLOBALS['egw']->accounts->members($data[$this->creator_field], true) as $u)
621 621
 			{
622
-				if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) &&
622
+				if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) &&
623 623
 					!in_array($email, $email_sent))
624 624
 				{
625
-					if ($this->send_notification($data,$old,$email,$u,'notify_owner_group_member'))
625
+					if ($this->send_notification($data, $old, $email, $u, 'notify_owner_group_member'))
626 626
 					{
627 627
 						$email_sent[] = $email;
628 628
 					}
@@ -639,14 +639,14 @@  discard block
 block discarded – undo
639 639
 			if ($data[$this->assigned_field])	// current assignments
640 640
 			{
641 641
 				$assignees = is_array($data[$this->assigned_field]) ?
642
-					$data[$this->assigned_field] : explode(',',$data[$this->assigned_field]);
642
+					$data[$this->assigned_field] : explode(',', $data[$this->assigned_field]);
643 643
 			}
644 644
 			if ($old && $old[$this->assigned_field])
645 645
 			{
646 646
 				$old_assignees = is_array($old[$this->assigned_field]) ?
647
-					$old[$this->assigned_field] : explode(',',$old[$this->assigned_field]);
647
+					$old[$this->assigned_field] : explode(',', $old[$this->assigned_field]);
648 648
 			}
649
-			foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee)
649
+			foreach (array_unique(array_merge($assignees, $old_assignees)) as $assignee)
650 650
 			{
651 651
 				//error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email'));
652 652
 				if (!$assignee) continue;
@@ -654,10 +654,10 @@  discard block
 block discarded – undo
654 654
 				// item assignee is a user
655 655
 				if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u')
656 656
 				{
657
-					if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent))
657
+					if (($email = $GLOBALS['egw']->accounts->id2name($assignee, 'account_email')) && !in_array($email, $email_sent))
658 658
 					{
659
-						if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned',
660
-							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))	// assignment changed
659
+						if ($this->send_notification($data, $old, $email, $assignee, 'notify_assigned',
660
+							in_array($assignee, $assignees) !== in_array($assignee, $old_assignees) || $deleted))	// assignment changed
661 661
 						{
662 662
 							$email_sent[] = $email;
663 663
 						}
@@ -665,12 +665,12 @@  discard block
 block discarded – undo
665 665
 				}
666 666
 				else	// item assignee is a group
667 667
 				{
668
-					foreach($GLOBALS['egw']->accounts->members($assignee,true) as $u)
668
+					foreach ($GLOBALS['egw']->accounts->members($assignee, true) as $u)
669 669
 					{
670
-						if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent))
670
+						if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) && !in_array($email, $email_sent))
671 671
 						{
672
-							if ($this->send_notification($data,$old,$email,$u,'notify_assigned',
673
-								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))	// assignment changed
672
+							if ($this->send_notification($data, $old, $email, $u, 'notify_assigned',
673
+								in_array($u, $assignees) !== in_array($u, $old_assignees) || $deleted))	// assignment changed
674 674
 							{
675 675
 								$email_sent[] = $email;
676 676
 							}
@@ -681,14 +681,14 @@  discard block
 block discarded – undo
681 681
 		}
682 682
 
683 683
 		// notification copies
684
-		if (($copies = $this->get_config('copy',$data,$old)))
684
+		if (($copies = $this->get_config('copy', $data, $old)))
685 685
 		{
686
-			$lang = $this->get_config('lang',$data,$old);
687
-			foreach($copies as $email)
686
+			$lang = $this->get_config('lang', $data, $old);
687
+			foreach ($copies as $email)
688 688
 			{
689
-				if (strchr($email,'@') !== false && !in_array($email, $email_sent))
689
+				if (strchr($email, '@') !== false && !in_array($email, $email_sent))
690 690
 				{
691
-					if ($this->send_notification($data,$old,$email,$lang,'notify_copy'))
691
+					if ($this->send_notification($data, $old, $email, $lang, 'notify_copy'))
692 692
 					{
693 693
 						$email_sent[] = $email;
694 694
 					}
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 	 * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted
734 734
 	 * @return boolean true on success or false if notification not requested or error (error-message is in $this->errors)
735 735
 	 */
736
-	public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null)
736
+	public function send_notification($data, $old, $email, $user_or_lang, $check = null, $assignment_changed = true, $deleted = null)
737 737
 	{
738 738
 		//error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)");
739 739
 		if (!$email) return false;
@@ -746,16 +746,16 @@  discard block
 block discarded – undo
746 746
 		{
747 747
 			$GLOBALS['egw_info']['user']['account_id'] = $user_or_lang;
748 748
 			$GLOBALS['egw']->preferences->__construct($user_or_lang);
749
-			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
749
+			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
750 750
 
751 751
 			if ($check && $this->check2pref) $check = $this->check2pref[$check];
752 752
 
753
-			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] ||	// no notification requested
753
+			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested
754 754
 				// only notification about changed assignment requested
755 755
 				$check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed ||
756 756
 				$this->user == $user_or_lang && !$this->notify_current_user)  // no popup for own actions
757 757
 			{
758
-				$do_notify = false;	// no notification requested / necessary
758
+				$do_notify = false; // no notification requested / necessary
759 759
 			}
760 760
 			$can_cache = (Customfields::get($this->app, true) == Customfields::get($this->app, $user_or_lang));
761 761
 		}
@@ -779,37 +779,37 @@  discard block
 block discarded – undo
779 779
 
780 780
 			// Cache message body to not have to re-generate it every time
781 781
 			$lang = Api\Translation::$userlang;
782
-			$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] .
782
+			$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].
783 783
 				$GLOBALS['egw_info']['user']['preferences']['common']['timeformat'];
784 784
 
785 785
 			// Cache text body, if there's no private custom fields we might reveal
786
-			if($can_cache)
786
+			if ($can_cache)
787 787
 			{
788
-				$body_cache =& $this->body_cache[$data[$this->id_field]][$lang][$date_format];
788
+				$body_cache = & $this->body_cache[$data[$this->id_field]][$lang][$date_format];
789 789
 			}
790
-			if(empty($data[$this->id_field]) || !isset($body_cache['text']))
790
+			if (empty($data[$this->id_field]) || !isset($body_cache['text']))
791 791
 			{
792
-				$body_cache['text'] = $this->get_body(false,$data,$old,false,$receiver);
792
+				$body_cache['text'] = $this->get_body(false, $data, $old, false, $receiver);
793 793
 			}
794 794
 			// Cache HTML body
795
-			if(empty($data[$this->id_field]) || !isset($body_cache['html']))
795
+			if (empty($data[$this->id_field]) || !isset($body_cache['html']))
796 796
 			{
797
-				$body_cache['html'] = $this->get_body(true,$data,$old,false,$receiver);
797
+				$body_cache['html'] = $this->get_body(true, $data, $old, false, $receiver);
798 798
 			}
799 799
 
800 800
 			// get rest of notification message
801
-			$sender = $this->get_sender($data,$old,true,$receiver);
802
-			$reply_to = $this->get_reply_to($data,$old);
803
-			$subject = $this->get_subject($data,$old,$deleted,$receiver);
804
-			$link = $this->get_notification_link($data,$old,$receiver);
805
-			$attachments = $this->get_attachments($data,$old,$receiver);
801
+			$sender = $this->get_sender($data, $old, true, $receiver);
802
+			$reply_to = $this->get_reply_to($data, $old);
803
+			$subject = $this->get_subject($data, $old, $deleted, $receiver);
804
+			$link = $this->get_notification_link($data, $old, $receiver);
805
+			$attachments = $this->get_attachments($data, $old, $receiver);
806 806
 		}
807 807
 
808 808
 		// restore user enviroment BEFORE calling notification class or returning
809 809
 		$GLOBALS['egw_info']['user'] = $save_user;
810 810
 		// need to call preferences constructor and read_repository, to set user timezone again
811 811
 		$GLOBALS['egw']->preferences->__construct($GLOBALS['egw_info']['user']['account_id']);
812
-		$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
812
+		$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
813 813
 
814 814
 		// Re-load date/time preferences
815 815
 		Api\DateTime::init();
@@ -873,11 +873,11 @@  discard block
 block discarded – undo
873 873
 	 *
874 874
 	 * @return string
875 875
 	 */
876
-	public function datetime($timestamp,$do_time=true)
876
+	public function datetime($timestamp, $do_time = true)
877 877
 	{
878
-		if (!is_a($timestamp,'DateTime'))
878
+		if (!is_a($timestamp, 'DateTime'))
879 879
 		{
880
-			$timestamp = new Api\DateTime($timestamp,Api\DateTime::$server_timezone);
880
+			$timestamp = new Api\DateTime($timestamp, Api\DateTime::$server_timezone);
881 881
 		}
882 882
 		$timestamp->setTimezone(Api\DateTime::$user_timezone);
883 883
 		if (is_null($do_time))
@@ -903,25 +903,25 @@  discard block
 block discarded – undo
903 903
 	 * @param int|string $receiver nummeric account_id or email address
904 904
 	 * @return string or userid
905 905
 	 */
906
-	protected function get_sender($data,$old,$prefer_id=false,$receiver=null)
906
+	protected function get_sender($data, $old, $prefer_id = false, $receiver = null)
907 907
 	{
908
-		unset($receiver);	// not used, but required by function signature
908
+		unset($receiver); // not used, but required by function signature
909 909
 
910
-		$sender = $this->get_config('sender',$data,$old);
910
+		$sender = $this->get_config('sender', $data, $old);
911 911
 		//echo "<p>".__METHOD__."() get_config('sender',...)='".htmlspecialchars($sender)."'</p>\n";
912 912
 
913 913
 		if (($this->prefer_user_as_sender || !$sender) && $this->user &&
914
-			($email = $GLOBALS['egw']->accounts->id2name($this->user,'account_email')))
914
+			($email = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email')))
915 915
 		{
916
-			$name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname');
916
+			$name = $GLOBALS['egw']->accounts->id2name($this->user, 'account_fullname');
917 917
 
918
-			if($prefer_id) {
918
+			if ($prefer_id) {
919 919
 				$sender = $this->user;
920 920
 			} else {
921 921
 				$sender = $name ? $name.' <'.$email.'>' : $email;
922 922
 			}
923 923
 		}
924
-		elseif(!$sender)
924
+		elseif (!$sender)
925 925
 		{
926 926
 			$sender = 'EGroupware '.lang($this->app).' <noreply@'.$GLOBALS['egw_info']['server']['mail_suffix'].'>';
927 927
 		}
@@ -939,9 +939,9 @@  discard block
 block discarded – undo
939 939
 	 * @param array $old
940 940
 	 * @return string or null
941 941
 	 */
942
-	protected function get_reply_to($data,$old)
942
+	protected function get_reply_to($data, $old)
943 943
 	{
944
-		$reply_to = $this->get_config('reply_to',$data,$old);
944
+		$reply_to = $this->get_config('reply_to', $data, $old);
945 945
 
946 946
 		return $reply_to;
947 947
 	}
@@ -953,11 +953,11 @@  discard block
 block discarded – undo
953 953
 	 * @param array $old
954 954
 	 * @return string
955 955
 	 */
956
-	protected function get_title($data,$old)
956
+	protected function get_title($data, $old)
957 957
 	{
958
-		unset($old);	// not used, but required by function signature
958
+		unset($old); // not used, but required by function signature
959 959
 
960
-		return Api\Link::title($this->app,$data[$this->id_field]);
960
+		return Api\Link::title($this->app, $data[$this->id_field]);
961 961
 	}
962 962
 
963 963
 	/**
@@ -971,11 +971,11 @@  discard block
 block discarded – undo
971 971
 	 * @param int|string $receiver nummeric account_id or email address
972 972
 	 * @return string
973 973
 	 */
974
-	protected function get_subject($data,$old,$deleted=null,$receiver=null)
974
+	protected function get_subject($data, $old, $deleted = null, $receiver = null)
975 975
 	{
976
-		unset($old, $deleted, $receiver);	// not used, but required by function signature
976
+		unset($old, $deleted, $receiver); // not used, but required by function signature
977 977
 
978
-		return Api\Link::title($this->app,$data[$this->id_field]);
978
+		return Api\Link::title($this->app, $data[$this->id_field]);
979 979
 	}
980 980
 
981 981
 	/**
@@ -988,9 +988,9 @@  discard block
 block discarded – undo
988 988
 	 * @param int|string $receiver nummeric account_id or email address
989 989
 	 * @return string
990 990
 	 */
991
-	protected function get_message($data,$old,$receiver=null)
991
+	protected function get_message($data, $old, $receiver = null)
992 992
 	{
993
-		unset($data, $old, $receiver);	// not used, but required by function signature
993
+		unset($data, $old, $receiver); // not used, but required by function signature
994 994
 
995 995
 		return '';
996 996
 	}
@@ -1006,24 +1006,24 @@  discard block
 block discarded – undo
1006 1006
 	 * @param int|string $receiver nummeric account_id or email address
1007 1007
 	 * @return string|array string with link (!$allow_popup) or array(link,popup-size), popup size is something like '640x480'
1008 1008
 	 */
1009
-	protected function get_link($data,$old,$allow_popup=false,$receiver=null)
1009
+	protected function get_link($data, $old, $allow_popup = false, $receiver = null)
1010 1010
 	{
1011
-		unset($receiver);	// not used, but required by function signature
1011
+		unset($receiver); // not used, but required by function signature
1012 1012
 
1013
-		if (($link = $this->get_config('link',$data,$old)))
1013
+		if (($link = $this->get_config('link', $data, $old)))
1014 1014
 		{
1015
-			if (!$this->get_config('link_no_id', $data) && strpos($link,$this->id_field.'=') === false && isset($data[$this->id_field]))
1015
+			if (!$this->get_config('link_no_id', $data) && strpos($link, $this->id_field.'=') === false && isset($data[$this->id_field]))
1016 1016
 			{
1017
-				$link .= strpos($link,'?') === false ? '?' : '&';
1017
+				$link .= strpos($link, '?') === false ? '?' : '&';
1018 1018
 				$link .= $this->id_field.'='.$data[$this->id_field];
1019 1019
 			}
1020 1020
 		}
1021 1021
 		else
1022 1022
 		{
1023
-			if (($view = Api\Link::view($this->app,$data[$this->id_field])))
1023
+			if (($view = Api\Link::view($this->app, $data[$this->id_field])))
1024 1024
 			{
1025
-				$link = Api\Framework::link('/index.php',$view);
1026
-				$popup = Api\Link::is_popup($this->app,'view');
1025
+				$link = Api\Framework::link('/index.php', $view);
1026
+				$popup = Api\Link::is_popup($this->app, 'view');
1027 1027
 			}
1028 1028
 		}
1029 1029
 		if ($link[0] == '/') Api\Framework::getUrl($link);
@@ -1031,12 +1031,12 @@  discard block
 block discarded – undo
1031 1031
 		if (!$allow_popup)
1032 1032
 		{
1033 1033
 			// remove the session-id in the notification mail!
1034
-			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link);
1034
+			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/', '', $link);
1035 1035
 
1036 1036
 			if ($popup) $link .= '&nopopup=1';
1037 1037
 		}
1038 1038
 		//error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link));
1039
-		return $allow_popup ? array($link,$popup) : $link;
1039
+		return $allow_popup ? array($link, $popup) : $link;
1040 1040
 	}
1041 1041
 
1042 1042
 	/**
@@ -1047,18 +1047,18 @@  discard block
 block discarded – undo
1047 1047
 	 * @param int|string $receiver nummeric account_id or email address
1048 1048
 	 * @return array with link
1049 1049
 	 */
1050
-	protected function get_notification_link($data,$old,$receiver=null)
1050
+	protected function get_notification_link($data, $old, $receiver = null)
1051 1051
 	{
1052
-		unset($receiver);	// not used, but required by function signature
1052
+		unset($receiver); // not used, but required by function signature
1053 1053
 
1054
-		if (($view = Api\Link::view($this->app,$data[$this->id_field])))
1054
+		if (($view = Api\Link::view($this->app, $data[$this->id_field])))
1055 1055
 		{
1056 1056
 			return array(
1057
-				'text' 	=> $this->get_title($data,$old),
1057
+				'text' 	=> $this->get_title($data, $old),
1058 1058
 				'app'	=> $this->app,
1059 1059
 				'id'	=> $data[$this->id_field],
1060 1060
 				'view' 	=> $view,
1061
-				'popup'	=> Api\Link::is_popup($this->app,'view'),
1061
+				'popup'	=> Api\Link::is_popup($this->app, 'view'),
1062 1062
 			);
1063 1063
 		}
1064 1064
 		return false;
@@ -1074,15 +1074,15 @@  discard block
 block discarded – undo
1074 1074
 	 * @param int|string $receiver nummeric account_id or email address
1075 1075
 	 * @return string
1076 1076
 	 */
1077
-	public function get_body($html_email,$data,$old,$integrate_link = true,$receiver=null)
1077
+	public function get_body($html_email, $data, $old, $integrate_link = true, $receiver = null)
1078 1078
 	{
1079 1079
 		$body = '';
1080
-		if($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old))
1080
+		if ($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old))
1081 1081
 		{
1082
-			$body = $this->get_custom_message($data,$old,null,$receiver);
1083
-			if(($sig = $this->get_signature($data,$old,$receiver)))
1082
+			$body = $this->get_custom_message($data, $old, null, $receiver);
1083
+			if (($sig = $this->get_signature($data, $old, $receiver)))
1084 1084
 			{
1085
-				$body .= ($html_email ? '<br />':'') . "\n$sig";
1085
+				$body .= ($html_email ? '<br />' : '')."\n$sig";
1086 1086
 			}
1087 1087
 			return $body;
1088 1088
 		}
@@ -1091,35 +1091,35 @@  discard block
 block discarded – undo
1091 1091
 			$body = '<table cellspacing="2" cellpadding="0" border="0" width="100%">'."\n";
1092 1092
 		}
1093 1093
 		// new or modified message
1094
-		if (($message = $this->get_message($data,$old,$receiver)))
1094
+		if (($message = $this->get_message($data, $old, $receiver)))
1095 1095
 		{
1096 1096
 			foreach ((array)$message as $_message)
1097 1097
 			{
1098
-				$body .= $this->format_line($html_email,'message',false,($_message=='---'?($html_email?'<hr/>':$_message):$_message));
1098
+				$body .= $this->format_line($html_email, 'message', false, ($_message == '---' ? ($html_email ? '<hr/>' : $_message) : $_message));
1099 1099
 			}
1100 1100
 		}
1101
-		if ($integrate_link && ($link = $this->get_link($data,$old,false,$receiver)))
1101
+		if ($integrate_link && ($link = $this->get_link($data, $old, false, $receiver)))
1102 1102
 		{
1103
-			$body .= $this->format_line($html_email,'link',false,$integrate_link === true ? lang('You can respond by visiting:') : $integrate_link,$link);
1103
+			$body .= $this->format_line($html_email, 'link', false, $integrate_link === true ? lang('You can respond by visiting:') : $integrate_link, $link);
1104 1104
 		}
1105
-		foreach($this->get_details($data,$receiver) as $name => $detail)
1105
+		foreach ($this->get_details($data, $receiver) as $name => $detail)
1106 1106
 		{
1107 1107
 			// if there's no old entry, the entry is not modified by definition
1108 1108
 			// if both values are '', 0 or null, we count them as equal too
1109 1109
 			$modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]);
1110 1110
 			//if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified);
1111
-			if (empty($detail['value']) && !$modified) continue;	// skip unchanged, empty values
1111
+			if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values
1112 1112
 
1113
-			$body .= $this->format_line($html_email,$detail['type'],$modified,
1113
+			$body .= $this->format_line($html_email, $detail['type'], $modified,
1114 1114
 				$detail['label'] ? $detail['label'] : '', $detail['value']);
1115 1115
 		}
1116 1116
 		if ($html_email)
1117 1117
 		{
1118 1118
 			$body .= "</table>\n";
1119 1119
 		}
1120
-		if(($sig = $this->get_signature($data,$old,$receiver)))
1120
+		if (($sig = $this->get_signature($data, $old, $receiver)))
1121 1121
 		{
1122
-			$body .= ($html_email ? '<br />':'') . "\n$sig";
1122
+			$body .= ($html_email ? '<br />' : '')."\n$sig";
1123 1123
 		}
1124 1124
 		if (!$html_email && $data['tr_edit_mode'] == 'html')
1125 1125
 		{
@@ -1139,20 +1139,20 @@  discard block
 block discarded – undo
1139 1139
 	 * @param string $data = null data or null to display just $line over 2 columns
1140 1140
 	 * @return string
1141 1141
 	 */
1142
-	protected function format_line($html_mail,$type,$modified,$line,$data=null)
1142
+	protected function format_line($html_mail, $type, $modified, $line, $data = null)
1143 1143
 	{
1144 1144
 		//error_log(__METHOD__.'('.array2string($html_mail).",'$type',".array2string($modified).",'$line',".array2string($data).')');
1145 1145
 		$content = '';
1146 1146
 
1147 1147
 		if ($html_mail)
1148 1148
 		{
1149
-			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line);	// XSS
1149
+			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS
1150 1150
 
1151 1151
 			$color = $modified ? 'red' : false;
1152 1152
 			$size  = '110%';
1153 1153
 			$bold = false;
1154 1154
 			$background = '#FFFFF1';
1155
-			switch($type)
1155
+			switch ($type)
1156 1156
 			{
1157 1157
 				case 'message':
1158 1158
 					$background = '#D3DCE3;';
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
 					if (strpos($data, '<br') === false)
1171 1171
 					{
1172 1172
 						$data = nl2br($this->html_content_allow ? $data : Api\Html::htmlspecialchars($data));
1173
-						$this->html_content_allow = true;	// to NOT do htmlspecialchars again
1173
+						$this->html_content_allow = true; // to NOT do htmlspecialchars again
1174 1174
 					}
1175 1175
 					break;
1176 1176
 				case 'reply':
@@ -1179,13 +1179,13 @@  discard block
 block discarded – undo
1179 1179
 				default:
1180 1180
 					$size = false;
1181 1181
 			}
1182
-			$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color?'color:'.$color:'');
1182
+			$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color ? 'color:'.$color : '');
1183 1183
 
1184
-			$content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data?'" width="20%':'" colspan="2').'">';
1184
+			$content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data ? '" width="20%' : '" colspan="2').'">';
1185 1185
 		}
1186 1186
 		else	// text-mail
1187 1187
 		{
1188
-			if ($type == 'reply') $content = str_repeat('-',64)."\n";
1188
+			if ($type == 'reply') $content = str_repeat('-', 64)."\n";
1189 1189
 
1190 1190
 			if ($modified) $content .= '> ';
1191 1191
 		}
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
 			if ($type == 'link')
1198 1198
 			{
1199 1199
 				// the link is often too long for html boxes chunk-split allows to break lines if needed
1200
-				$content .= Api\Html::a_href(chunk_split(rawurldecode($data),40,'&#8203;'),$data,'','target="_blank"');
1200
+				$content .= Api\Html::a_href(chunk_split(rawurldecode($data), 40, '&#8203;'), $data, '', 'target="_blank"');
1201 1201
 			}
1202 1202
 			elseif ($this->html_content_allow)
1203 1203
 			{
@@ -1210,7 +1210,7 @@  discard block
 block discarded – undo
1210 1210
 		}
1211 1211
 		else
1212 1212
 		{
1213
-			$content .= ($content&&$data?': ':'').$data;
1213
+			$content .= ($content && $data ? ': ' : '').$data;
1214 1214
 		}
1215 1215
 		if ($html_mail) $content .= '</td></tr>';
1216 1216
 
@@ -1227,9 +1227,9 @@  discard block
 block discarded – undo
1227 1227
 	 * @param int|string $receiver nummeric account_id or email address
1228 1228
 	 * @return array or array with values for either 'string' or 'path' and optionally (mime-)'type', 'filename' and 'encoding'
1229 1229
 	 */
1230
-	protected function get_attachments($data,$old,$receiver=null)
1230
+	protected function get_attachments($data, $old, $receiver = null)
1231 1231
 	{
1232
-		unset($data, $old, $receiver);	// not used, but required by function signature
1232
+		unset($data, $old, $receiver); // not used, but required by function signature
1233 1233
 
1234 1234
 	 	return array();
1235 1235
 	}
@@ -1242,20 +1242,20 @@  discard block
 block discarded – undo
1242 1242
 	 */
1243 1243
 	protected function get_signature($data, $old, $receiver)
1244 1244
 	{
1245
-		unset($old, $receiver);	// not used, but required by function signature
1245
+		unset($old, $receiver); // not used, but required by function signature
1246 1246
 
1247 1247
 		$config = Api\Config::read('notifications');
1248
-		if(!isset($data[$this->id_field]))
1248
+		if (!isset($data[$this->id_field]))
1249 1249
 		{
1250
-			error_log($this->app . ' did not properly implement bo_tracking->id_field.  Merge skipped.');
1250
+			error_log($this->app.' did not properly implement bo_tracking->id_field.  Merge skipped.');
1251 1251
 		}
1252
-		elseif(class_exists($this->app. '_merge'))
1252
+		elseif (class_exists($this->app.'_merge'))
1253 1253
 		{
1254 1254
 			$merge_class = $this->app.'_merge';
1255 1255
 			$merge = new $merge_class();
1256 1256
 			$error = null;
1257 1257
 			$sig = $merge->merge_string($config['signature'], array($data[$this->id_field]), $error, 'text/html');
1258
-			if($error)
1258
+			if ($error)
1259 1259
 			{
1260 1260
 				error_log($error);
1261 1261
 				return $config['signature'];
@@ -1272,7 +1272,7 @@  discard block
 block discarded – undo
1272 1272
 	protected function get_custom_message($data, $old, $merge_class = null, $receiver = false)
1273 1273
 	{
1274 1274
 		$message = $this->get_config(self::CUSTOM_NOTIFICATION, $data, $old);
1275
-		if(!$message)
1275
+		if (!$message)
1276 1276
 		{
1277 1277
 			return '';
1278 1278
 		}
@@ -1281,21 +1281,21 @@  discard block
 block discarded – undo
1281 1281
 		$message = $this->sanitize_custom_message($message, $receiver);
1282 1282
 
1283 1283
 		// Automatically set merge class from naming conventions
1284
-		if($merge_class == null)
1284
+		if ($merge_class == null)
1285 1285
 		{
1286 1286
 			$merge_class = $this->app.'_merge';
1287 1287
 		}
1288
-		if(!isset($data[$this->id_field]))
1288
+		if (!isset($data[$this->id_field]))
1289 1289
 		{
1290
-			error_log($this->app . ' did not properly implement bo_tracking->id_field.  Merge skipped.');
1290
+			error_log($this->app.' did not properly implement bo_tracking->id_field.  Merge skipped.');
1291 1291
 			return $message;
1292 1292
 		}
1293
-		elseif(class_exists($merge_class))
1293
+		elseif (class_exists($merge_class))
1294 1294
 		{
1295 1295
 			$merge = new $merge_class();
1296 1296
 			$error = null;
1297 1297
 			$merged_message = $merge->merge_string($message, array($data[$this->id_field]), $error, 'text/html');
1298
-			if($error)
1298
+			if ($error)
1299 1299
 			{
1300 1300
 				error_log($error);
1301 1301
 				return $message;
@@ -1317,7 +1317,7 @@  discard block
 block discarded – undo
1317 1317
 	 */
1318 1318
 	protected function sanitize_custom_message($message, $receiver)
1319 1319
 	{
1320
-		if(!is_numeric($receiver))
1320
+		if (!is_numeric($receiver))
1321 1321
 		{
1322 1322
 			$receiver = false;
1323 1323
 		}
@@ -1327,14 +1327,14 @@  discard block
 block discarded – undo
1327 1327
 
1328 1328
 		// If we have a specific user and they're the same then there are
1329 1329
 		// no private fields so nothing needs to be done
1330
-		if($receiver && $all_cfs == $cfs)
1330
+		if ($receiver && $all_cfs == $cfs)
1331 1331
 		{
1332 1332
 			return $message;
1333 1333
 		}
1334 1334
 
1335 1335
 		// Replace any placeholders that use the private field, or any sub-keys
1336 1336
 		// of the field
1337
-		foreach($all_cfs as $name => $field)
1337
+		foreach ($all_cfs as $name => $field)
1338 1338
 		{
1339 1339
 			if ($receiver === false && $field['private'] || !$cfs[$name])
1340 1340
 			{
Please login to merge, or discard this patch.