Completed
Push — master ( df263c...059178 )
by Ralf
91:04 queued 68:58
created
timesheet/inc/class.timesheet_wizard_export_csv.inc.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 		// Custom fields
25 25
 		unset($this->export_fields['customfields']);
26 26
 		$custom = Api\Storage\Customfields::get('timesheet', true);
27
-		foreach($custom as $name => $data) {
27
+		foreach ($custom as $name => $data) {
28 28
 			$this->export_fields['#'.$name] = $data['label'];
29 29
 		}
30 30
 	}
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,8 @@  discard block
 block discarded – undo
14 14
 
15 15
 class timesheet_wizard_export_csv extends importexport_wizard_basic_export_csv
16 16
 {
17
-	public function __construct() {
17
+	public function __construct()
18
+	{
18 19
 		parent::__construct();
19 20
 
20 21
 		// Field mapping
@@ -24,7 +25,8 @@  discard block
 block discarded – undo
24 25
 		// Custom fields
25 26
 		unset($this->export_fields['customfields']);
26 27
 		$custom = Api\Storage\Customfields::get('timesheet', true);
27
-		foreach($custom as $name => $data) {
28
+		foreach($custom as $name => $data)
29
+		{
28 30
 			$this->export_fields['#'.$name] = $data['label'];
29 31
 		}
30 32
 	}
Please login to merge, or discard this patch.
timesheet/inc/class.timesheet_bo.inc.php 4 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -152,8 +152,8 @@
 block discarded – undo
152 152
 	const EXTRA_TABLE = 'egw_timesheet_extra';
153 153
 
154 154
 	/**
155
-	* Columns to search when user does a text search
156
-	*/
155
+	 * Columns to search when user does a text search
156
+	 */
157 157
 	var $columns_to_search = array('egw_timesheet.ts_id', 'ts_project', 'ts_title', 'ts_description', 'ts_duration', 'ts_quantity', 'ts_unitprice');
158 158
 
159 159
 	/**
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -792,7 +792,7 @@
 block discarded – undo
792 792
 	 * @param array $options Array of options for the search
793 793
 	 * @return array with ts_id - title pairs of the matching entries
794 794
 	 */
795
-	function link_query( $pattern, Array &$options = array() )
795
+	function link_query( $pattern, array &$options = array() )
796 796
 	{
797 797
 		$limit = false;
798 798
 		$need_count = false;
Please login to merge, or discard this patch.
Braces   +78 added lines, -20 removed lines patch added patch discarded remove patch
@@ -171,7 +171,10 @@  discard block
 block discarded – undo
171 171
 		$this->quantity_sum = $this->config_data['quantity_sum'] == 'true';
172 172
 
173 173
 		// Load & process statuses
174
-		if($this->config_data['status_labels']) $this->load_statuses();
174
+		if($this->config_data['status_labels'])
175
+		{
176
+			$this->load_statuses();
177
+		}
175 178
 
176 179
 		$this->today = mktime(0,0,0,date('m',$this->now),date('d',$this->now),date('Y',$this->now));
177 180
 
@@ -189,12 +192,16 @@  discard block
 block discarded – undo
189 192
 	protected function load_statuses()
190 193
 	{
191 194
 		$this->status_labels =&  $this->config_data['status_labels'];
192
-		if (!is_array($this->status_labels)) $this->status_labels= array($this->status_labels);
195
+		if (!is_array($this->status_labels))
196
+		{
197
+			$this->status_labels= array($this->status_labels);
198
+		}
193 199
 
194 200
 		foreach ($this->status_labels as $status_id => $label)
195 201
 		{
196 202
 			if (!is_array($label))
197
-			{	//old values, before parent status
203
+			{
204
+//old values, before parent status
198 205
 				$name = $label;
199 206
 				$label=array();
200 207
 				$label['name'] = $name;
@@ -242,7 +249,10 @@  discard block
 block discarded – undo
242 249
 	 */
243 250
 	function get_sub_status($status)
244 251
 	{
245
-		if (!isset($this->status_labels_config)) $this->load_statuses();
252
+		if (!isset($this->status_labels_config))
253
+		{
254
+			$this->load_statuses();
255
+		}
246 256
 		$stati = array($status);
247 257
 		foreach($this->status_labels_config as $stat)
248 258
 		{
@@ -309,7 +319,10 @@  discard block
 block discarded – undo
309 319
 	 */
310 320
 	function grant_list($required=Acl::READ, $hide_deactive=null)
311 321
 	{
312
-		if (!isset($hide_deactive)) $hide_deactive = $required == Acl::EDIT;
322
+		if (!isset($hide_deactive))
323
+		{
324
+			$hide_deactive = $required == Acl::EDIT;
325
+		}
313 326
 
314 327
 		$result = array();
315 328
 		foreach($this->grants as $uid => $grant)
@@ -345,9 +358,16 @@  discard block
 block discarded – undo
345 358
 			$data = $this->read($data,true);
346 359
 			$this->data = $save_data;
347 360
 
348
-			if (!$data) return null; 	// entry not found
361
+			if (!$data)
362
+			{
363
+				return null;
364
+			}
365
+			// entry not found
366
+		}
367
+		if (!$user)
368
+		{
369
+			$user = $this->user;
349 370
 		}
350
-		if (!$user) $user = $this->user;
351 371
 		if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) && $data['ts_status'])
352 372
 		{
353 373
 			if ($this->status_labels_config[$data['ts_status']]['admin'])
@@ -380,9 +400,16 @@  discard block
 block discarded – undo
380 400
 			$data = $this->read($data,true);
381 401
 			$this->data = $save_data;
382 402
 
383
-			if (!$data) return null; 	// entry not found
403
+			if (!$data)
404
+			{
405
+				return null;
406
+			}
407
+			// entry not found
408
+		}
409
+		if (!$user)
410
+		{
411
+			$user = $this->user;
384 412
 		}
385
-		if (!$user) $user = $this->user;
386 413
 		if ($user == $this->user)
387 414
 		{
388 415
 			$grants = $this->grants;
@@ -462,7 +489,10 @@  discard block
 block discarded – undo
462 489
 		}
463 490
 		else
464 491
 		{
465
-			if (!is_array($filter['ts_owner'])) $filter['ts_owner'] = array($filter['ts_owner']);
492
+			if (!is_array($filter['ts_owner']))
493
+			{
494
+				$filter['ts_owner'] = array($filter['ts_owner']);
495
+			}
466 496
 
467 497
 			foreach($filter['ts_owner'] as $key => $owner)
468 498
 			{
@@ -517,7 +547,10 @@  discard block
 block discarded – undo
517 547
 		$this->summary = $this->summary[0];
518 548
 		$this->summary['max_modified'] = Api\DateTime::server2user($this->summary['max_modified']);
519 549
 
520
-		if ($only_summary) return $this->summary;
550
+		if ($only_summary)
551
+		{
552
+			return $this->summary;
553
+		}
521 554
 
522 555
 		if ($this->show_sums && strpos($order_by,'ts_start') !== false && 	// sums only make sense if ordered by ts_start
523 556
 			$this->db->capabilities['union'] && ($from_unixtime_ts_start = $this->db->from_unixtime('ts_start')))
@@ -593,7 +626,10 @@  discard block
 block discarded – undo
593 626
 	 */
594 627
 	function save($keys=null,$touch_modified=true,$ignore_acl=false)
595 628
 	{
596
-		if ($keys) $this->data_merge($keys);
629
+		if ($keys)
630
+		{
631
+			$this->data_merge($keys);
632
+		}
597 633
 
598 634
 		if (!$ignore_acl && $this->data['ts_id'] && !$this->check_acl(Acl::EDIT))
599 635
 		{
@@ -615,10 +651,13 @@  discard block
 block discarded – undo
615 651
 			$old =& $this->data;
616 652
 			$this->data =& $new;
617 653
 			$changed = array();
618
-			if (isset($old)) foreach($old as $name => $value)
654
+			if (isset($old))
655
+			{
656
+				foreach($old as $name => $value)
619 657
 			{
620 658
 				if (isset($new[$name]) && $new[$name] != $value) $changed[] = $name;
621 659
 			}
660
+			}
622 661
 		}
623 662
 		if (!$this->data['ts_created'])
624 663
 		{
@@ -750,7 +789,10 @@  discard block
 block discarded – undo
750 789
 		}
751 790
 
752 791
 		$this->data['ts_status'] = $status;
753
-		if ($this->save($ts_id)!=0) $ret = false;
792
+		if ($this->save($ts_id)!=0)
793
+		{
794
+			$ret = false;
795
+		}
754 796
 
755 797
 		return $ret;
756 798
 	}
@@ -794,10 +836,13 @@  discard block
 block discarded – undo
794 836
 			return $entry;
795 837
 		}
796 838
 		$format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
797
-		if (date('H:i',$entry['ts_start']) != '00:00')	// dont show 00:00 time, as it means date only
839
+		if (date('H:i',$entry['ts_start']) != '00:00')
840
+		{
841
+			// dont show 00:00 time, as it means date only
798 842
 		{
799 843
 			$format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i');
800 844
 		}
845
+		}
801 846
 		return date($format,$entry['ts_start']).': '.$entry['ts_title'];
802 847
 	}
803 848
 
@@ -843,14 +888,18 @@  discard block
 block discarded – undo
843 888
 	{
844 889
 		$limit = false;
845 890
 		$need_count = false;
846
-		if($options['start'] || $options['num_rows']) {
891
+		if($options['start'] || $options['num_rows'])
892
+		{
847 893
 			$limit = array($options['start'], $options['num_rows']);
848 894
 			$need_count = true;
849 895
 		}
850 896
 		$result = array();
851 897
 		foreach((array) $this->search($pattern,false,'','','%',false,'OR', $limit, null, '', $need_count) as $ts )
852 898
 		{
853
-			if ($ts) $result[$ts['ts_id']] = $this->link_title($ts);
899
+			if ($ts)
900
+			{
901
+				$result[$ts['ts_id']] = $this->link_title($ts);
902
+			}
854 903
 		}
855 904
 		$options['total'] = $need_count ? $this->total : count($result);
856 905
 		return $result;
@@ -969,7 +1018,10 @@  discard block
 block discarded – undo
969 1018
 				//error_log(__METHOD__."() setting pm_id=$pm_id --> ".array2string($update));
970 1019
 			}
971 1020
 		}
972
-		if ($backup) $this->data = $backup;
1021
+		if ($backup)
1022
+		{
1023
+			$this->data = $backup;
1024
+		}
973 1025
 	}
974 1026
 
975 1027
 
@@ -994,7 +1046,10 @@  discard block
 block discarded – undo
994 1046
 			$first_pm_id = null;
995 1047
 			foreach(Link::get_links('timesheet', $data['ts_id'], 'projectmanager') as $pm_id)
996 1048
 			{
997
-				if (!isset($first_pm_id)) $first_pm_id = $pm_id;
1049
+				if (!isset($first_pm_id))
1050
+				{
1051
+					$first_pm_id = $pm_id;
1052
+				}
998 1053
 				if ($data['ts_project'] == Link::title('projectmanager', $pm_id))
999 1054
 				{
1000 1055
 					$data['pm_id'] = $pm_id;
@@ -1003,7 +1058,10 @@  discard block
 block discarded – undo
1003 1058
 					break;
1004 1059
 				}
1005 1060
 			}
1006
-			if (!isset($data['pm_id']) && isset($first_pm_id)) $data['pm_id'] = $first_pm_id;
1061
+			if (!isset($data['pm_id']) && isset($first_pm_id))
1062
+			{
1063
+				$data['pm_id'] = $first_pm_id;
1064
+			}
1007 1065
 		}
1008 1066
 		elseif ($data['ts_id'] && $data['pm_id'] && Link::title('projectmanager', $data['pm_id']) == $data['ts_project'])
1009 1067
 		{
Please login to merge, or discard this patch.
Spacing   +138 added lines, -139 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 if (!defined('TIMESHEET_APP'))
18 18
 {
19
-	define('TIMESHEET_APP','timesheet');
19
+	define('TIMESHEET_APP', 'timesheet');
20 20
 }
21 21
 
22 22
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @var boolean
45 45
 	 */
46
-	var $quantity_sum=false;
46
+	var $quantity_sum = false;
47 47
 	/**
48 48
 	 * current user
49 49
 	 *
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 * @var array
57 57
 	 */
58 58
 	var $timestamps = array(
59
-		'ts_start','ts_created', 'ts_modified'
59
+		'ts_start', 'ts_created', 'ts_modified'
60 60
 	);
61 61
 	/**
62 62
 	 * Start of today in user-time
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
 	 * @var array
71 71
 	 */
72 72
 	var $date_filters = array(	// Start: year,month,day,week, End: year,month,day,week
73
-		'Today'       => array(0,0,0,0,  0,0,1,0),
74
-		'Yesterday'   => array(0,0,-1,0, 0,0,0,0),
75
-		'This week'   => array(0,0,0,0,  0,0,0,1),
76
-		'Last week'   => array(0,0,0,-1, 0,0,0,0),
77
-		'This month'  => array(0,0,0,0,  0,1,0,0),
78
-		'Last month'  => array(0,-1,0,0, 0,0,0,0),
79
-		'2 month ago' => array(0,-2,0,0, 0,-1,0,0),
80
-		'This year'   => array(0,0,0,0,  1,0,0,0),
81
-		'Last year'   => array(-1,0,0,0, 0,0,0,0),
82
-		'2 years ago' => array(-2,0,0,0, -1,0,0,0),
83
-		'3 years ago' => array(-3,0,0,0, -2,0,0,0),
73
+		'Today'       => array(0, 0, 0, 0, 0, 0, 1, 0),
74
+		'Yesterday'   => array(0, 0, -1, 0, 0, 0, 0, 0),
75
+		'This week'   => array(0, 0, 0, 0, 0, 0, 0, 1),
76
+		'Last week'   => array(0, 0, 0, -1, 0, 0, 0, 0),
77
+		'This month'  => array(0, 0, 0, 0, 0, 1, 0, 0),
78
+		'Last month'  => array(0, -1, 0, 0, 0, 0, 0, 0),
79
+		'2 month ago' => array(0, -2, 0, 0, 0, -1, 0, 0),
80
+		'This year'   => array(0, 0, 0, 0, 1, 0, 0, 0),
81
+		'Last year'   => array(-1, 0, 0, 0, 0, 0, 0, 0),
82
+		'2 years ago' => array(-2, 0, 0, 0, -1, 0, 0, 0),
83
+		'3 years ago' => array(-3, 0, 0, 0, -2, 0, 0, 0),
84 84
 	);
85 85
 	/**
86 86
 	 * Grants: $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @var array
107 107
 	 */
108
-	var $customfields=array();
108
+	var $customfields = array();
109 109
 	/**
110 110
 	 * Array with status label
111 111
 	 *
@@ -165,20 +165,20 @@  discard block
 block discarded – undo
165 165
 
166 166
 	function __construct()
167 167
 	{
168
-		parent::__construct(TIMESHEET_APP,'egw_timesheet',self::EXTRA_TABLE,'','ts_extra_name','ts_extra_value','ts_id');
168
+		parent::__construct(TIMESHEET_APP, 'egw_timesheet', self::EXTRA_TABLE, '', 'ts_extra_name', 'ts_extra_value', 'ts_id');
169 169
 
170 170
 		$this->config_data = Api\Config::read(TIMESHEET_APP);
171 171
 		$this->quantity_sum = $this->config_data['quantity_sum'] == 'true';
172 172
 
173 173
 		// Load & process statuses
174
-		if($this->config_data['status_labels']) $this->load_statuses();
174
+		if ($this->config_data['status_labels']) $this->load_statuses();
175 175
 
176
-		$this->today = mktime(0,0,0,date('m',$this->now),date('d',$this->now),date('Y',$this->now));
176
+		$this->today = mktime(0, 0, 0, date('m', $this->now), date('d', $this->now), date('Y', $this->now));
177 177
 
178 178
 		// save us in $GLOBALS['timesheet_bo'] for ExecMethod used in hooks
179 179
 		if (!is_object($GLOBALS['timesheet_bo']))
180 180
 		{
181
-			$GLOBALS['timesheet_bo'] =& $this;
181
+			$GLOBALS['timesheet_bo'] = & $this;
182 182
 		}
183 183
 		$this->grants = $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP);
184 184
 	}
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
 	 */
189 189
 	protected function load_statuses()
190 190
 	{
191
-		$this->status_labels =&  $this->config_data['status_labels'];
192
-		if (!is_array($this->status_labels)) $this->status_labels= array($this->status_labels);
191
+		$this->status_labels = &  $this->config_data['status_labels'];
192
+		if (!is_array($this->status_labels)) $this->status_labels = array($this->status_labels);
193 193
 
194 194
 		foreach ($this->status_labels as $status_id => $label)
195 195
 		{
196 196
 			if (!is_array($label))
197 197
 			{	//old values, before parent status
198 198
 				$name = $label;
199
-				$label=array();
199
+				$label = array();
200 200
 				$label['name'] = $name;
201 201
 				$label['parent'] = '';
202 202
 			}
@@ -208,12 +208,12 @@  discard block
 block discarded – undo
208 208
 		$map = array(
209 209
 			'' => array('substatus' => array())
210 210
 		);
211
-		foreach($this->status_labels_config as $id => &$status)
211
+		foreach ($this->status_labels_config as $id => &$status)
212 212
 		{
213 213
 			$status['substatus'] = array();
214 214
 			$map[$id] = &$status;
215 215
 		}
216
-		foreach($this->status_labels_config as &$status)
216
+		foreach ($this->status_labels_config as &$status)
217 217
 		{
218 218
 			$map[$status['parent']]['substatus'][] = &$status;
219 219
 		}
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 
226 226
 		// Sort Api\Config based on tree
227 227
 		$sorted = array();
228
-		foreach($this->status_labels as $status_id => $label)
228
+		foreach ($this->status_labels as $status_id => $label)
229 229
 		{
230 230
 			$sorted[$status_id] = $this->status_labels_config[$status_id];
231 231
 			//$sorted[$status_id]['name'] = $label;
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	{
245 245
 		if (!isset($this->status_labels_config)) $this->load_statuses();
246 246
 		$stati = array($status);
247
-		foreach($this->status_labels_config as $stat)
247
+		foreach ($this->status_labels_config as $stat)
248 248
 		{
249 249
 			if ($stat['parent'] && in_array($stat['parent'], $stati))
250 250
 			{
@@ -264,14 +264,14 @@  discard block
 block discarded – undo
264 264
 	 *
265 265
 	 * @return None, labels are built in labels parameter
266 266
 	 */
267
-	protected function make_status_labels($statuses, &$labels, $depth=0)
267
+	protected function make_status_labels($statuses, &$labels, $depth = 0)
268 268
 	{
269
-		foreach($statuses as $status)
269
+		foreach ($statuses as $status)
270 270
 		{
271
-			$labels[$status['id']] = str_pad('',$depth*12, " ",STR_PAD_LEFT).trim(str_replace(' ','',$status['name']));
272
-			if(count($status['substatus']) > 0)
271
+			$labels[$status['id']] = str_pad('', $depth * 12, " ", STR_PAD_LEFT).trim(str_replace(' ', '', $status['name']));
272
+			if (count($status['substatus']) > 0)
273 273
 			{
274
-				$this->make_status_labels($status['substatus'], $labels, $depth+1);
274
+				$this->make_status_labels($status['substatus'], $labels, $depth + 1);
275 275
 			}
276 276
 		}
277 277
 	}
@@ -285,14 +285,14 @@  discard block
 block discarded – undo
285 285
 	 */
286 286
 	protected function get_status_labels($admin = null)
287 287
 	{
288
-		if(is_null($admin))
288
+		if (is_null($admin))
289 289
 		{
290 290
 			$admin = isset($GLOBALS['egw_info']['user']['apps']['admin']);
291 291
 		}
292 292
 		$labels = array();
293
-		foreach($this->status_labels as $status_id => $label)
293
+		foreach ($this->status_labels as $status_id => $label)
294 294
 		{
295
-			if($admin || !$admin && !$this->status_labels_config[$status_id]['admin'])
295
+			if ($admin || !$admin && !$this->status_labels_config[$status_id]['admin'])
296 296
 			{
297 297
 				$labels[$status_id] = $label;
298 298
 			}
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
 	 * @param boolean $hide_deactive =null default only Acl::EDIT hides deactivates users
308 308
 	 * @return array with uid => Username pairs
309 309
 	 */
310
-	function grant_list($required=Acl::READ, $hide_deactive=null)
310
+	function grant_list($required = Acl::READ, $hide_deactive = null)
311 311
 	{
312 312
 		if (!isset($hide_deactive)) $hide_deactive = $required == Acl::EDIT;
313 313
 
314 314
 		$result = array();
315
-		foreach($this->grants as $uid => $grant)
315
+		foreach ($this->grants as $uid => $grant)
316 316
 		{
317
-			if ($grant & $required && (!$hide_deactive || Api\Accounts::getInstance()->is_active($uid)))
317
+			if ($grant&$required && (!$hide_deactive || Api\Accounts::getInstance()->is_active($uid)))
318 318
 			{
319 319
 				$result[$uid] = Api\Accounts::username($uid);
320 320
 			}
@@ -333,19 +333,19 @@  discard block
 block discarded – undo
333 333
 	 * @param int $user =null for which user to check, default current user
334 334
 	 * @return boolean true if the rights are ok, false if no rights
335 335
 	 */
336
-	function check_statusForEditRights($data=null,$user=null)
336
+	function check_statusForEditRights($data = null, $user = null)
337 337
 	{
338 338
 		if (is_null($data) || (int)$data == $this->data['ts_id'])
339 339
 		{
340
-			$data =& $this->data;
340
+			$data = & $this->data;
341 341
 		}
342 342
 		if (!is_array($data))
343 343
 		{
344 344
 			$save_data = $this->data;
345
-			$data = $this->read($data,true);
345
+			$data = $this->read($data, true);
346 346
 			$this->data = $save_data;
347 347
 
348
-			if (!$data) return null; 	// entry not found
348
+			if (!$data) return null; // entry not found
349 349
 		}
350 350
 		if (!$user) $user = $this->user;
351 351
 		if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) && $data['ts_status'])
@@ -368,19 +368,19 @@  discard block
 block discarded – undo
368 368
 	 * @param int $user =null for which user to check, default current user
369 369
 	 * @return boolean true if the rights are ok, null if not found, false if no rights
370 370
 	 */
371
-	function check_acl($required,$data=null,$user=null)
371
+	function check_acl($required, $data = null, $user = null)
372 372
 	{
373 373
 		if (is_null($data) || (int)$data == $this->data['ts_id'])
374 374
 		{
375
-			$data =& $this->data;
375
+			$data = & $this->data;
376 376
 		}
377 377
 		if (!is_array($data))
378 378
 		{
379 379
 			$save_data = $this->data;
380
-			$data = $this->read($data,true);
380
+			$data = $this->read($data, true);
381 381
 			$this->data = $save_data;
382 382
 
383
-			if (!$data) return null; 	// entry not found
383
+			if (!$data) return null; // entry not found
384 384
 		}
385 385
 		if (!$user) $user = $this->user;
386 386
 		if ($user == $this->user)
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
 		}
390 390
 		else
391 391
 		{
392
-			$grants = $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP,true,$user);
392
+			$grants = $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP, true, $user);
393 393
 		}
394
-		$ret = $data && !!($grants[$data['ts_owner']] & $required);
394
+		$ret = $data && !!($grants[$data['ts_owner']]&$required);
395 395
 
396
-		if(($required & Acl::DELETE) && $this->config_data['history'] == 'history' &&
396
+		if (($required&Acl::DELETE) && $this->config_data['history'] == 'history' &&
397 397
 			$data['ts_status'] == self::DELETED_STATUS)
398 398
 		{
399 399
 			$ret = !!($GLOBALS['egw_info']['user']['apps']['admin']);
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 	 * @param int &$end
411 411
 	 * @return string
412 412
 	 */
413
-	function date_filter($name,&$start,&$end)
413
+	function date_filter($name, &$start, &$end)
414 414
 	{
415 415
 		return Api\DateTime::sql_filter($name, $start, $end, 'ts_start', $this->date_filters);
416 416
 	}
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 	 * @param boolean $only_summary =false If true only return the sums as array with keys duration and price, default false
437 437
 	 * @return array of matching rows (the row is an array of the cols) or False
438 438
 	 */
439
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false,$only_summary=false)
439
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false, $only_summary = false)
440 440
 	{
441 441
 		//error_log(__METHOD__."(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')");
442 442
 		//echo "<p>".__METHOD__."(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
@@ -445,9 +445,9 @@  discard block
 block discarded – undo
445 445
 
446 446
 		if (!is_array($extra_cols))
447 447
 		{
448
-			$extra_cols = $extra_cols ? explode(',',$extra_cols) : array();
448
+			$extra_cols = $extra_cols ? explode(',', $extra_cols) : array();
449 449
 		}
450
-		if ($only_keys === false || $this->show_sums && strpos($order_by,'ts_start') !== false)
450
+		if ($only_keys === false || $this->show_sums && strpos($order_by, 'ts_start') !== false)
451 451
 		{
452 452
 			$extra_cols[] = $total_sql.' AS ts_total';
453 453
 		}
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 		{
465 465
 			if (!is_array($filter['ts_owner'])) $filter['ts_owner'] = array($filter['ts_owner']);
466 466
 
467
-			foreach($filter['ts_owner'] as $key => $owner)
467
+			foreach ($filter['ts_owner'] as $key => $owner)
468 468
 			{
469 469
 				if (!isset($this->grants[$owner]))
470 470
 				{
@@ -478,8 +478,8 @@  discard block
 block discarded – undo
478 478
 		}
479 479
 		else
480 480
 		{
481
-			$filter[] = '(ts_status ' . ($filter['ts_status'] == self::DELETED_STATUS ? '=':'!= ') . self::DELETED_STATUS .
482
-				($filter['ts_status'] == self::DELETED_STATUS ? '':' OR ts_status IS NULL') . ')';
481
+			$filter[] = '(ts_status '.($filter['ts_status'] == self::DELETED_STATUS ? '=' : '!= ').self::DELETED_STATUS.
482
+				($filter['ts_status'] == self::DELETED_STATUS ? '' : ' OR ts_status IS NULL').')';
483 483
 		}
484 484
 		if (!count($filter['ts_owner']))
485 485
 		{
@@ -487,15 +487,15 @@  discard block
 block discarded – undo
487 487
 			$this->summary = array();
488 488
 			return array();
489 489
 		}
490
-		if ($only_summary==false && $criteria && $this->show_sums)
490
+		if ($only_summary == false && $criteria && $this->show_sums)
491 491
 		{
492 492
 			// if we have a criteria AND intend to show the sums we first query the affected ids,
493 493
 			// then we throw away criteria and filter, and replace the filter with the list of ids
494
-			$ids = parent::search($criteria,'egw_timesheet.ts_id as id','','',$wildcard,$empty,$op,false,$filter,$join);
494
+			$ids = parent::search($criteria, 'egw_timesheet.ts_id as id', '', '', $wildcard, $empty, $op, false, $filter, $join);
495 495
 			//_debug_array($ids);
496 496
 			if (empty($ids))
497 497
 			{
498
-				$this->summary = array('duration'=>0,'price'=>null,'quantity'=>0);
498
+				$this->summary = array('duration'=>0, 'price'=>null, 'quantity'=>0);
499 499
 				return array();
500 500
 			}
501 501
 			unset($criteria);
@@ -519,45 +519,45 @@  discard block
 block discarded – undo
519 519
 
520 520
 		if ($only_summary) return $this->summary;
521 521
 
522
-		if ($this->show_sums && strpos($order_by,'ts_start') !== false && 	// sums only make sense if ordered by ts_start
522
+		if ($this->show_sums && strpos($order_by, 'ts_start') !== false && // sums only make sense if ordered by ts_start
523 523
 			$this->db->capabilities['union'] && ($from_unixtime_ts_start = $this->db->from_unixtime('ts_start')))
524 524
 		{
525 525
 			$sum_sql = array(
526
-				'year'  => $this->db->date_format($from_unixtime_ts_start,'%Y'),
527
-				'month' => $this->db->date_format($from_unixtime_ts_start,'%Y%m'),
528
-				'week'  => $this->db->date_format($from_unixtime_ts_start,$GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'] == 'Sunday' ? '%X%V' : '%x%v'),
529
-				'day'   => $this->db->date_format($from_unixtime_ts_start,'%Y-%m-%d'),
526
+				'year'  => $this->db->date_format($from_unixtime_ts_start, '%Y'),
527
+				'month' => $this->db->date_format($from_unixtime_ts_start, '%Y%m'),
528
+				'week'  => $this->db->date_format($from_unixtime_ts_start, $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'] == 'Sunday' ? '%X%V' : '%x%v'),
529
+				'day'   => $this->db->date_format($from_unixtime_ts_start, '%Y-%m-%d'),
530 530
 			);
531
-			foreach($this->show_sums as $type)
531
+			foreach ($this->show_sums as $type)
532 532
 			{
533 533
 				$extra_cols[] = $sum_sql[$type].' AS ts_'.$type;
534 534
 				$extra_cols[] = '0 AS is_sum_'.$type;
535
-				$sum_extra_cols[] = str_replace('ts_start','MIN(ts_start)',$sum_sql[$type]);	// as we dont group by ts_start
535
+				$sum_extra_cols[] = str_replace('ts_start', 'MIN(ts_start)', $sum_sql[$type]); // as we dont group by ts_start
536 536
 				$sum_extra_cols[$type] = '0 AS is_sum_'.$type;
537 537
 			}
538 538
 			// regular entries
539
-			parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,'UNION',$filter,$join,$need_full_no_count);
539
+			parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, 'UNION', $filter, $join, $need_full_no_count);
540 540
 
541
-			$sort = substr($order_by,8);
541
+			$sort = substr($order_by, 8);
542 542
 			$union_order = array();
543
-			$sum_ts_id = array('year' => -3,'month' => -2,'week' => -1,'day' => 0);
544
-			foreach($this->show_sums as $type)
543
+			$sum_ts_id = array('year' => -3, 'month' => -2, 'week' => -1, 'day' => 0);
544
+			foreach ($this->show_sums as $type)
545 545
 			{
546
-				$union_order[] = 'ts_'.$type . ' ' . $sort;
546
+				$union_order[] = 'ts_'.$type.' '.$sort;
547 547
 				$union_order[] = 'is_sum_'.$type;
548 548
 				$sum_extra_cols[$type]{0} = '1';
549 549
 				// the $type sum
550
-				parent::search($criteria,array(
551
-					(string)$sum_ts_id[$type],"''","''","''",'MIN(ts_start)','SUM(ts_duration) AS ts_duration',
550
+				parent::search($criteria, array(
551
+					(string)$sum_ts_id[$type], "''", "''", "''", 'MIN(ts_start)', 'SUM(ts_duration) AS ts_duration',
552 552
 					($this->quantity_sum ? "SUM(ts_quantity) AS ts_quantity" : '0'),
553
-					'0','NULL','0','0','0','0','0','0',"SUM($total_sql) AS ts_total"
554
-				),'GROUP BY '.$sum_sql[$type],$sum_extra_cols,$wildcard,$empty,$op,'UNION',$filter,$join,$need_full_no_count);
553
+					'0', 'NULL', '0', '0', '0', '0', '0', '0', "SUM($total_sql) AS ts_total"
554
+				), 'GROUP BY '.$sum_sql[$type], $sum_extra_cols, $wildcard, $empty, $op, 'UNION', $filter, $join, $need_full_no_count);
555 555
 				$sum_extra_cols[$type]{0} = '0';
556 556
 			}
557 557
 			$union_order[] = 'ts_start '.$sort;
558
-			return parent::search('','',implode(',',$union_order),'','',false,'',$start);
558
+			return parent::search('', '', implode(',', $union_order), '', '', false, '', $start);
559 559
 		}
560
-		return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
560
+		return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
561 561
 	}
562 562
 
563 563
 	/**
@@ -567,16 +567,16 @@  discard block
 block discarded – undo
567 567
 	 * @param boolean $ignore_acl =false should the Acl be checked
568 568
 	 * @return array|boolean array with timesheet entry, null if timesheet not found or false if no rights
569 569
 	 */
570
-	function read($ts_id,$ignore_acl=false)
570
+	function read($ts_id, $ignore_acl = false)
571 571
 	{
572 572
 		//error_log(__METHOD__."($ts_id,$ignore_acl) ".function_backtrace());
573 573
 		if (!(int)$ts_id || (int)$ts_id != $this->data['ts_id'] && !parent::read($ts_id))
574 574
 		{
575
-			return null;	// entry not found
575
+			return null; // entry not found
576 576
 		}
577 577
 		if (!$ignore_acl && !($ret = $this->check_acl(Acl::READ)))
578 578
 		{
579
-			return false;	// no read rights
579
+			return false; // no read rights
580 580
 		}
581 581
 		return $this->data;
582 582
 	}
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 	 * @param boolean $ignore_acl =false should the Acl be checked, returns true if no edit-rigts
592 592
 	 * @return int 0 on success and errno != 0 else
593 593
 	 */
594
-	function save($keys=null,$touch_modified=true,$ignore_acl=false)
594
+	function save($keys = null, $touch_modified = true, $ignore_acl = false)
595 595
 	{
596 596
 		if ($keys) $this->data_merge($keys);
597 597
 
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
 		// check if we have a real modification of an existing record
610 610
 		if ($this->data['ts_id'])
611 611
 		{
612
-			$new =& $this->data;
612
+			$new = & $this->data;
613 613
 			unset($this->data);
614 614
 			$this->read($new['ts_id']);
615
-			$old =& $this->data;
616
-			$this->data =& $new;
615
+			$old = & $this->data;
616
+			$this->data = & $new;
617 617
 			$changed = array();
618
-			if (isset($old)) foreach($old as $name => $value)
618
+			if (isset($old)) foreach ($old as $name => $value)
619 619
 			{
620 620
 				if (isset($new[$name]) && $new[$name] != $value) $changed[] = $name;
621 621
 			}
@@ -634,17 +634,16 @@  discard block
 block discarded – undo
634 634
 		))
635 635
 		{
636 636
 			$this->data['ts_project'] = $this->data['pm_id'] ? Link::title('projectmanager', $this->data['pm_id']) : '';
637
-			if($this->data['ts_title'] == Link::title('projectmanager', $old['pm_id']))
637
+			if ($this->data['ts_title'] == Link::title('projectmanager', $old['pm_id']))
638 638
 			{
639 639
 				$this->data['ts_title'] = $this->data['ts_project'];
640 640
 			}
641 641
 		}
642 642
 
643
-		$type = !isset($old) ? 'add' :
644
-			($new['ts_status'] == self::DELETED_STATUS ? 'delete' : 'update');
643
+		$type = !isset($old) ? 'add' : ($new['ts_status'] == self::DELETED_STATUS ? 'delete' : 'update');
645 644
 
646 645
 		// Check for restore of deleted contact, restore held links
647
-		if($old && $old['ts_status'] == self::DELETED_STATUS && $new['ts_status'] != self::DELETED_STATUS)
646
+		if ($old && $old['ts_status'] == self::DELETED_STATUS && $new['ts_status'] != self::DELETED_STATUS)
648 647
 		{
649 648
 			Link::restore(TIMESHEET_APP, $new['ts_id']);
650 649
 			$type = 'add';
@@ -658,9 +657,9 @@  discard block
 block discarded – undo
658 657
 
659 658
 				$this->tracking->html_content_allow = true;
660 659
 			}
661
-			if ($this->tracking->track($this->data,$old,$this->user) === false)
660
+			if ($this->tracking->track($this->data, $old, $this->user) === false)
662 661
 			{
663
-				return implode(', ',$this->tracking->errors);
662
+				return implode(', ', $this->tracking->errors);
664 663
 			}
665 664
 			// notify the link-class about the update, as other apps may be subscribt to it
666 665
 			Link::notify_update(TIMESHEET_APP, $this->data['ts_id'], $this->data, $type);
@@ -676,15 +675,15 @@  discard block
 block discarded – undo
676 675
 	 * @param boolean $ignore_acl =false should the Acl be checked, returns false if no delete-rigts
677 676
 	 * @return int affected rows, should be 1 if ok, 0 if an error
678 677
 	 */
679
-	function delete($keys=null,$ignore_acl=false)
678
+	function delete($keys = null, $ignore_acl = false)
680 679
 	{
681
-		if (!is_array($keys) && (int) $keys)
680
+		if (!is_array($keys) && (int)$keys)
682 681
 		{
683
-			$keys = array('ts_id' => (int) $keys);
682
+			$keys = array('ts_id' => (int)$keys);
684 683
 		}
685 684
 		$ts_id = is_null($keys) ? $this->data['ts_id'] : $keys['ts_id'];
686 685
 
687
-		if (!$ignore_acl && !$this->check_acl(Acl::DELETE,$ts_id) || !($old = $this->read($ts_id)))
686
+		if (!$ignore_acl && !$this->check_acl(Acl::DELETE, $ts_id) || !($old = $this->read($ts_id)))
688 687
 		{
689 688
 			return false;
690 689
 		}
@@ -695,12 +694,12 @@  discard block
 block discarded – undo
695 694
 			$delete = $old;
696 695
 			$delete['ts_status'] = self::DELETED_STATUS;
697 696
 			$ret = !($this->save($delete));
698
-			Link::unlink(0,TIMESHEET_APP,$ts_id,'','','',true);
697
+			Link::unlink(0, TIMESHEET_APP, $ts_id, '', '', '', true);
699 698
 		}
700 699
 		elseif (($ret = parent::delete($keys)) && $ts_id)
701 700
 		{
702 701
 			// delete all links to timesheet entry $ts_id
703
-			Link::unlink(0,TIMESHEET_APP,$ts_id);
702
+			Link::unlink(0, TIMESHEET_APP, $ts_id);
704 703
 		}
705 704
 		return $ret;
706 705
 	}
@@ -715,7 +714,7 @@  discard block
 block discarded – undo
715 714
 	function deleteaccount($data)
716 715
 	{
717 716
 		$account_id = $data['account_id'];
718
-		$new_owner =  $data['new_owner'];
717
+		$new_owner = $data['new_owner'];
719 718
 
720 719
 		if (!$new_owner)
721 720
 		{
@@ -739,22 +738,22 @@  discard block
 block discarded – undo
739 738
 	 * @param int $status =0
740 739
 	 * @return int affected rows, should be 1 if ok, 0 if an error
741 740
 	 */
742
-	function set_status($keys=null, $status=0)
741
+	function set_status($keys = null, $status = 0)
743 742
 	{
744 743
 		$ret = true;
745
-		if (!is_array($keys) && (int) $keys)
744
+		if (!is_array($keys) && (int)$keys)
746 745
 		{
747
-			$keys = array('ts_id' => (int) $keys);
746
+			$keys = array('ts_id' => (int)$keys);
748 747
 		}
749 748
 		$ts_id = is_null($keys) ? $this->data['ts_id'] : $keys['ts_id'];
750 749
 
751
-		if (!$this->check_acl(Acl::EDIT,$ts_id) || !$this->read($ts_id,true))
750
+		if (!$this->check_acl(Acl::EDIT, $ts_id) || !$this->read($ts_id, true))
752 751
 		{
753 752
 			return false;
754 753
 		}
755 754
 
756 755
 		$this->data['ts_status'] = $status;
757
-		if ($this->save($ts_id)!=0) $ret = false;
756
+		if ($this->save($ts_id) != 0) $ret = false;
758 757
 
759 758
 		return $ret;
760 759
 	}
@@ -771,7 +770,7 @@  discard block
 block discarded – undo
771 770
 		{
772 771
 			return array('duration' => 0, 'quantity' => 0, 'price' => 0, 'max_modified' => null);
773 772
 		}
774
-		return $this->search(array('ts_id'=>$ids),true,'','','',false,'AND',false,null,'',false,true);
773
+		return $this->search(array('ts_id'=>$ids), true, '', '', '', false, 'AND', false, null, '', false, true);
775 774
 	}
776 775
 
777 776
 	/**
@@ -782,27 +781,27 @@  discard block
 block discarded – undo
782 781
 	 * @param int|array $entry int ts_id or array with timesheet entry
783 782
 	 * @return string/boolean string with title, null if timesheet not found, false if no perms to view it
784 783
 	 */
785
-	function link_title( $entry )
784
+	function link_title($entry)
786 785
 	{
787 786
 		if (!is_array($entry))
788 787
 		{
789 788
 			// need to preserve the $this->data
790
-			$backup =& $this->data;
789
+			$backup = & $this->data;
791 790
 			unset($this->data);
792
-			$entry = $this->read( $entry,false,false);
791
+			$entry = $this->read($entry, false, false);
793 792
 			// restore the data again
794
-			$this->data =& $backup;
793
+			$this->data = & $backup;
795 794
 		}
796 795
 		if (!$entry)
797 796
 		{
798 797
 			return $entry;
799 798
 		}
800 799
 		$format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
801
-		if (date('H:i',$entry['ts_start']) != '00:00')	// dont show 00:00 time, as it means date only
800
+		if (date('H:i', $entry['ts_start']) != '00:00')	// dont show 00:00 time, as it means date only
802 801
 		{
803 802
 			$format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i');
804 803
 		}
805
-		return date($format,$entry['ts_start']).': '.$entry['ts_title'];
804
+		return date($format, $entry['ts_start']).': '.$entry['ts_title'];
806 805
 	}
807 806
 
808 807
 	/**
@@ -813,18 +812,18 @@  discard block
 block discarded – undo
813 812
 	 * @param array $ids array with ts_id's
814 813
 	 * @return array with titles, see link_title
815 814
 	 */
816
-	function link_titles( array $ids )
815
+	function link_titles(array $ids)
817 816
 	{
818 817
 		$titles = array();
819
-		if (($entries = $this->search(array('ts_id' => $ids),'ts_id,ts_title,ts_start')))
818
+		if (($entries = $this->search(array('ts_id' => $ids), 'ts_id,ts_title,ts_start')))
820 819
 		{
821
-			foreach($entries as $entry)
820
+			foreach ($entries as $entry)
822 821
 			{
823 822
 				$titles[$entry['ts_id']] = $this->link_title($entry);
824 823
 			}
825 824
 		}
826 825
 		// we assume all not returned entries are not readable by the user, as we notify Link about all deletes
827
-		foreach($ids as $id)
826
+		foreach ($ids as $id)
828 827
 		{
829 828
 			if (!isset($titles[$id]))
830 829
 			{
@@ -843,16 +842,16 @@  discard block
 block discarded – undo
843 842
 	 * @param array $options Array of options for the search
844 843
 	 * @return array with ts_id - title pairs of the matching entries
845 844
 	 */
846
-	function link_query( $pattern, Array &$options = array() )
845
+	function link_query($pattern, Array &$options = array())
847 846
 	{
848 847
 		$limit = false;
849 848
 		$need_count = false;
850
-		if($options['start'] || $options['num_rows']) {
849
+		if ($options['start'] || $options['num_rows']) {
851 850
 			$limit = array($options['start'], $options['num_rows']);
852 851
 			$need_count = true;
853 852
 		}
854 853
 		$result = array();
855
-		foreach((array) $this->search($pattern,false,'','','%',false,'OR', $limit, null, '', $need_count) as $ts )
854
+		foreach ((array)$this->search($pattern, false, '', '', '%', false, 'OR', $limit, null, '', $need_count) as $ts)
856 855
 		{
857 856
 			if ($ts) $result[$ts['ts_id']] = $this->link_title($ts);
858 857
 		}
@@ -869,11 +868,11 @@  discard block
 block discarded – undo
869 868
 	 * @param int $user =null for which user to check, default current user
870 869
 	 * @return boolean true if access is granted or false otherwise
871 870
 	 */
872
-	function file_access($id,$check,$rel_path=null,$user=null)
871
+	function file_access($id, $check, $rel_path = null, $user = null)
873 872
 	{
874
-		unset($rel_path);	// not used, but required by function signature
873
+		unset($rel_path); // not used, but required by function signature
875 874
 
876
-		return $this->check_acl($check,$id,$user);
875
+		return $this->check_acl($check, $id, $user);
877 876
 	}
878 877
 
879 878
 	/**
@@ -885,16 +884,16 @@  discard block
 block discarded – undo
885 884
 	 * @param string $newtitle => the new title of the project
886 885
 	 * @return boolean true for success, false for invalid parameters
887 886
 	 */
888
-	 function update_ts_project($oldtitle='', $newtitle='')
887
+	 function update_ts_project($oldtitle = '', $newtitle = '')
889 888
 	 {
890
-		if(strlen($oldtitle) > 0 && strlen($newtitle) > 0)
889
+		if (strlen($oldtitle) > 0 && strlen($newtitle) > 0)
891 890
 		{
892
-			$this->db->update('egw_timesheet',array(
891
+			$this->db->update('egw_timesheet', array(
893 892
 				'ts_project' => $newtitle,
894 893
 				'ts_title' => $newtitle,
895
-			),array(
894
+			), array(
896 895
 				'ts_project' => $oldtitle,
897
-			),__LINE__,__FILE__,TIMESHEET_APP);
896
+			), __LINE__, __FILE__, TIMESHEET_APP);
898 897
 
899 898
 			return true;
900 899
 		}
@@ -907,16 +906,16 @@  discard block
 block discarded – undo
907 906
 	 * @param int $pm_id ID of selected project
908 907
 	 * @return array containing link_id and ts_id
909 908
 	 */
910
-	function get_ts_links($pm_id=0)
909
+	function get_ts_links($pm_id = 0)
911 910
 	{
912
-		if($pm_id && isset($GLOBALS['egw_info']['user']['apps']['projectmanager']))
911
+		if ($pm_id && isset($GLOBALS['egw_info']['user']['apps']['projectmanager']))
913 912
 		{
914
-			$pm_ids = ExecMethod('projectmanager.projectmanager_bo.children',$pm_id);
913
+			$pm_ids = ExecMethod('projectmanager.projectmanager_bo.children', $pm_id);
915 914
 			$pm_ids[] = $pm_id;
916
-			$links = Link\Storage::get_links('projectmanager',$pm_ids,'timesheet');	// Link\Storage::get_links not egw_links::get_links!
915
+			$links = Link\Storage::get_links('projectmanager', $pm_ids, 'timesheet'); // Link\Storage::get_links not egw_links::get_links!
917 916
 			if ($links)
918 917
 			{
919
-				$links = array_unique(call_user_func_array('array_merge',$links));
918
+				$links = array_unique(call_user_func_array('array_merge', $links));
920 919
 			}
921 920
 			return $links;
922 921
 		}
@@ -934,17 +933,17 @@  discard block
 block discarded – undo
934 933
 	function notify($data)
935 934
 	{
936 935
 		//error_log(__METHOD__.'('.array2string($data).')');
937
-		$backup =& $this->data;	// backup internal data in case class got re-used by ExecMethod
936
+		$backup = & $this->data; // backup internal data in case class got re-used by ExecMethod
938 937
 		unset($this->data);
939 938
 
940 939
 		if ($data['target_app'] == 'projectmanager' && $this->read($data['id']))
941 940
 		{
942 941
 			$old_title = isset($data['data']) ? $data['data'][Link::OLD_LINK_TITLE] : null;
943
-			switch($data['type'])
942
+			switch ($data['type'])
944 943
 			{
945 944
 				case 'link':
946 945
 				case 'update':
947
-					if (empty($this->data['ts_project']) ||	// timesheet has not yet project set --> set just linked one
946
+					if (empty($this->data['ts_project']) || // timesheet has not yet project set --> set just linked one
948 947
 						isset($old_title) && $this->data['ts_project'] === $old_title)
949 948
 					{
950 949
 						$pm_id = $data['target_id'];
@@ -986,17 +985,17 @@  discard block
 block discarded – undo
986 985
 	 * @param array $data =null if given works on that array and returns result, else works on internal data-array
987 986
 	 * @return array
988 987
 	 */
989
-	function db2data($data=null)
988
+	function db2data($data = null)
990 989
 	{
991 990
 		if (($intern = !is_array($data)))
992 991
 		{
993
-			$data =& $this->data;
992
+			$data = & $this->data;
994 993
 		}
995 994
 		// get pm_id from links and ts_project: either project matching ts_project or first found project
996 995
 		if (!isset($data['pm_id']) && $data['ts_id'])
997 996
 		{
998 997
 			$first_pm_id = null;
999
-			foreach(Link::get_links('timesheet', $data['ts_id'], 'projectmanager') as $pm_id)
998
+			foreach (Link::get_links('timesheet', $data['ts_id'], 'projectmanager') as $pm_id)
1000 999
 			{
1001 1000
 				if (!isset($first_pm_id)) $first_pm_id = $pm_id;
1002 1001
 				if ($data['ts_project'] == Link::title('projectmanager', $pm_id))
@@ -1014,7 +1013,7 @@  discard block
 block discarded – undo
1014 1013
 			$data['ts_project_blur'] = $data['ts_project'];
1015 1014
 			$data['ts_project'] = '';
1016 1015
 		}
1017
-		return parent::db2data($intern ? null : $data);	// important to use null, if $intern!
1016
+		return parent::db2data($intern ? null : $data); // important to use null, if $intern!
1018 1017
 	}
1019 1018
 
1020 1019
 	/**
@@ -1026,17 +1025,17 @@  discard block
 block discarded – undo
1026 1025
 	 * @param array $data =null if given works on that array and returns result, else works on internal data-array
1027 1026
 	 * @return array
1028 1027
 	 */
1029
-	function data2db($data=null)
1028
+	function data2db($data = null)
1030 1029
 	{
1031 1030
 		if (($intern = !is_array($data)))
1032 1031
 		{
1033
-			$data =& $this->data;
1032
+			$data = & $this->data;
1034 1033
 		}
1035 1034
 		// allways store ts_project to be able to search for it, even if no custom project is set
1036 1035
 		if (empty($data['ts_project']) && !is_null($data['ts_project']))
1037 1036
 		{
1038 1037
 			$data['ts_project'] = $data['pm_id'] ? Link::title('projectmanager', $data['pm_id']) : '';
1039 1038
 		}
1040
-		return parent::data2db($intern ? null : $data);	// important to use null, if $intern!
1039
+		return parent::data2db($intern ? null : $data); // important to use null, if $intern!
1041 1040
 	}
1042 1041
 }
Please login to merge, or discard this patch.
timesheet/inc/class.timesheet_tracking.inc.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 
74 74
 		//set fields for tracking
75 75
 		$this->field2history = array_keys($this->bo->db_cols);
76
-		$this->field2history = array_diff(array_combine($this->field2history,$this->field2history),array('ts_modified'));
77
-		$this->field2history += array('customfields'   => '#c');	// to display old customfield data in history
76
+		$this->field2history = array_diff(array_combine($this->field2history, $this->field2history), array('ts_modified'));
77
+		$this->field2history += array('customfields'   => '#c'); // to display old customfield data in history
78 78
 
79 79
 		// custom fields are now handled by parent::__construct('tracker')
80 80
 		parent::__construct('timesheet');
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @param array $old =null old/last state of the entry or null for a new entry
92 92
 	 * @return mixed
93 93
 	 */
94
-	function get_config($name,$data,$old=null)
94
+	function get_config($name, $data, $old = null)
95 95
 	{
96 96
 		$timesheet = $data['ts_id'];
97 97
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @param array $old
110 110
 	 * @return string
111 111
 	 */
112
-	function get_subject($data,$old)
112
+	function get_subject($data, $old)
113 113
 	{
114 114
 		return '#'.$data['ts_id'].' - '.$data['ts_title'];
115 115
 	}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @param array $old
122 122
 	 * @return string
123 123
 	 */
124
-	function get_message($data,$old)
124
+	function get_message($data, $old)
125 125
 	{
126 126
 		if (!$data['ts_modified'] || !$old)
127 127
 		{
Please login to merge, or discard this patch.
timesheet/index.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@
 block discarded – undo
28 28
 {
29 29
 	Framework::render('<p style="text-align: center; color:red; font-weight: bold;">'.
30 30
 		lang('Your database is NOT up to date (%1 vs. %2), please run %3setup%4 to update your database.',
31
-		$ts_version,$GLOBALS['egw_info']['apps'][TIMESHEET_APP]['version'],
32
-		'<a href="../setup/">','</a>')."</p>\n", null, true);
31
+		$ts_version, $GLOBALS['egw_info']['apps'][TIMESHEET_APP]['version'],
32
+		'<a href="../setup/">', '</a>')."</p>\n", null, true);
33 33
 	exit();
34 34
 }
35 35
 
36
-Framework::redirect_link('/index.php',array('menuaction'=>TIMESHEET_APP.'.timesheet_ui.index'));
36
+Framework::redirect_link('/index.php', array('menuaction'=>TIMESHEET_APP.'.timesheet_ui.index'));
Please login to merge, or discard this patch.
notifications/inc/class.notifications_push.inc.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
 	public static function get()
41 41
 	{
42
-		$already_send =& Api\Cache::getSession(__CLASS__, 'already_send');
42
+		$already_send = & Api\Cache::getSession(__CLASS__, 'already_send');
43 43
 		$max_id = Api\Cache::getInstance(__CLASS__, 'max_id');
44 44
 
45 45
 		if (!isset($already_send))
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		{
58 58
 			$response = Json\Response::get();
59 59
 
60
-			foreach(self::$db->select(self::TABLE, '*', array(
60
+			foreach (self::$db->select(self::TABLE, '*', array(
61 61
 				'account_id' => array(0, $GLOBALS['egw_info']['user']['account_id']),
62 62
 				'notify_type' => self::TYPE,
63 63
 				'notify_id > '.(int)$already_send,
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public static function init_static()
123 123
 	{
124
-		self::$db =& $GLOBALS['egw']->db;
124
+		self::$db = & $GLOBALS['egw']->db;
125 125
 	}
126 126
 }
127 127
 notifications_push::init_static();
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,10 @@
 block discarded – undo
89 89
 	 */
90 90
 	public function addGeneric($account_id, $key, $data)
91 91
 	{
92
-		if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
92
+		if (!isset($account_id))
93
+		{
94
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
95
+		}
93 96
 
94 97
 		self::$db->insert(self::TABLE, array(
95 98
 			'account_id'  => $account_id,
Please login to merge, or discard this patch.
notifications/inc/class.notifications_jdesk_ajax.inc.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
 	{
134 134
 		if ($notify_id)
135 135
 		{
136
-			$this->db->delete(self::_notification_table,array(
136
+			$this->db->delete(self::_notification_table, array(
137 137
 				'notify_id' => $notify_id,
138 138
 				'account_id' => $this->recipient->account_id,
139 139
 				'notify_type' => self::_type
140
-			),__LINE__,__FILE__,self::_appname);
140
+			), __LINE__, __FILE__, self::_appname);
141 141
 		}
142 142
 	}
143 143
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 */
149 149
 	private function get_egwpopup($browserNotify = false)
150 150
 	{
151
-		unset($browserNotify);	// not used
151
+		unset($browserNotify); // not used
152 152
 
153 153
 		$message = '';
154 154
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 				'account_id' => $this->recipient->account_id,
157 157
 				'notify_type' => self::_type
158 158
 			),
159
-			__LINE__,__FILE__,false,'',self::_appname);
159
+			__LINE__, __FILE__, false, '', self::_appname);
160 160
 
161
-		if( $rs->NumRows() > 0 )
161
+		if ($rs->NumRows() > 0)
162 162
 		{
163 163
 			foreach ($rs as $notification)
164 164
 			{
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 				$this->response->data($jmessage);
171 171
 			}
172 172
 
173
-			switch( $this->preferences[self::_appname]['egwpopup_verbosity'] )
173
+			switch ($this->preferences[self::_appname]['egwpopup_verbosity'])
174 174
 			{
175 175
 				case 'low':
176 176
 
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,8 @@  discard block
 block discarded – undo
14 14
 /**
15 15
  * jdesk Json methods for notifications
16 16
  */
17
-class notifications_jdesk_ajax {
17
+class notifications_jdesk_ajax
18
+{
18 19
 
19 20
 	public $public_functions = array(
20 21
 		'get_notification'	=> true
@@ -92,7 +93,9 @@  discard block
 block discarded – undo
92 93
 	 * destructor
93 94
 	 *
94 95
 	 */
95
-	public function __destruct() {}
96
+	public function __destruct()
97
+	{
98
+}
96 99
 
97 100
 	/**
98 101
 	 * public AJAX trigger function to be called by the JavaScript client
Please login to merge, or discard this patch.
notifications/inc/hook_admin.inc.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@
 block discarded – undo
11 11
 
12 12
 use EGroupware\Api\Egw;
13 13
 
14
-$file = Array(	'Site Configuration' => Egw::link('/index.php', array(
14
+$file = Array('Site Configuration' => Egw::link('/index.php', array(
15 15
 	'menuaction'	=> 'admin.admin_config.index',
16 16
 	'appname'		=> $appname,
17 17
 	'ajax'          => 'true',
18 18
 )));
19
-display_section($appname,$file);
19
+display_section($appname, $file);
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 
12 12
 use EGroupware\Api\Egw;
13 13
 
14
-$file = Array(	'Site Configuration' => Egw::link('/index.php', array(
14
+$file = array(	'Site Configuration' => Egw::link('/index.php', array(
15 15
 	'menuaction'	=> 'admin.admin_config.index',
16 16
 	'appname'		=> $appname,
17 17
 	'ajax'          => 'true',
Please login to merge, or discard this patch.
notifications/inc/class.notifications.inc.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -660,14 +660,14 @@
 block discarded – undo
660 660
 	 }
661 661
 
662 662
 	 /**
663
-	 * returns notification chains based on admin prefs
664
-	 * @abstract the available chains can be retrieved in two different output formats:
665
-	 * routing: array with common and enabled chains, chain-name as key and the chain-array as value (used for message-routing)
666
-	 * human: array with common, enabled and disabled chains, chain-name as key and a human-readable description as value (used for config)
667
-	 *
668
-	 * @param string $_output one of: 'routing' or 'human', defaults to 'routing'
669
-	 * @return array containing notification chains, output like given in $_output
670
-	 */
663
+	  * returns notification chains based on admin prefs
664
+	  * @abstract the available chains can be retrieved in two different output formats:
665
+	  * routing: array with common and enabled chains, chain-name as key and the chain-array as value (used for message-routing)
666
+	  * human: array with common, enabled and disabled chains, chain-name as key and a human-readable description as value (used for config)
667
+	  *
668
+	  * @param string $_output one of: 'routing' or 'human', defaults to 'routing'
669
+	  * @return array containing notification chains, output like given in $_output
670
+	  */
671 671
 	public function get_available_chains($_output = 'routing') {
672 672
 		// determine enabled backends from Api\Config
673 673
 		$enabled_backends = array();
Please login to merge, or discard this patch.
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 *
192 192
 	 */
193 193
 	public function __construct() {
194
-		$this->config = (object) Api\Config::read(self::_appname);
194
+		$this->config = (object)Api\Config::read(self::_appname);
195 195
 	}
196 196
 
197 197
 	/**
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @param boolean $reset =false true: reset all errors
201 201
 	 * @return array
202 202
 	 */
203
-	public static function errors($reset=false)
203
+	public static function errors($reset = false)
204 204
 	{
205 205
 		$ret = self::$errors;
206 206
 		if ($reset) self::$errors = array();
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
 	 * it's an int with the account id or the e-mail address of a non-eGW user
216 216
 	 */
217 217
 	public function set_sender($_sender) {
218
-		if(is_object($_sender)) {
218
+		if (is_object($_sender)) {
219 219
 			$this->sender = $_sender;
220 220
 			return true;
221 221
 		} else {
222 222
 			// no object atm, we have to handle this and make a pseudo-object
223
-			if(is_numeric($_sender)) {
224
-				$this->sender = (object) $GLOBALS['egw']->accounts->read($_sender);
223
+			if (is_numeric($_sender)) {
224
+				$this->sender = (object)$GLOBALS['egw']->accounts->read($_sender);
225 225
 				return true;
226 226
 			}
227
-			if(is_string($_sender) && strpos($_sender,'@')) {
228
-				$this->sender = (object) array (
229
-									'account_email' => $this->get_addresspart($_sender,'email'),
230
-									'account_fullname' => $this->get_addresspart($_sender,'fullname'),
227
+			if (is_string($_sender) && strpos($_sender, '@')) {
228
+				$this->sender = (object)array(
229
+									'account_email' => $this->get_addresspart($_sender, 'email'),
230
+									'account_fullname' => $this->get_addresspart($_sender, 'fullname'),
231 231
 									);
232 232
 				return true;
233 233
 			}
@@ -267,19 +267,19 @@  discard block
 block discarded – undo
267 267
 	 * it's an int with the account id or the e-mail address of a non-eGW user
268 268
 	 */
269 269
 	public function add_receiver($_receiver) {
270
-		if(is_object($_receiver)) {
270
+		if (is_object($_receiver)) {
271 271
 			$this->receivers[] = $_receiver;
272 272
 			return true;
273 273
 		} else {
274 274
 			// no object atm, we have to handle this and make a pseudo-object
275
-			if(is_numeric($_receiver)) {
276
-				$this->receivers[] = (object) $GLOBALS['egw']->accounts->read($_receiver);
275
+			if (is_numeric($_receiver)) {
276
+				$this->receivers[] = (object)$GLOBALS['egw']->accounts->read($_receiver);
277 277
 				return true;
278 278
 			}
279
-			if(is_string($_receiver) && strpos($_receiver,'@')) {
280
-				$this->receivers[] = (object) array (
281
-									'account_email' => $this->get_addresspart($_receiver,'email'),
282
-									'account_fullname' => $this->get_addresspart($_receiver,'fullname'),
279
+			if (is_string($_receiver) && strpos($_receiver, '@')) {
280
+				$this->receivers[] = (object)array(
281
+									'account_email' => $this->get_addresspart($_receiver, 'email'),
282
+									'account_fullname' => $this->get_addresspart($_receiver, 'fullname'),
283 283
 									);
284 284
 				return true;
285 285
 			}
@@ -320,11 +320,11 @@  discard block
 block discarded – undo
320 320
 	 * @param string $_type Type of message, 'plain' or 'html'
321 321
 	 */
322 322
 	public function set_message($_message, $_type = false) {
323
-		if(!$_type)
323
+		if (!$_type)
324 324
 		{
325 325
 			$_type = strlen($_message) == strlen(strip_tags($_message)) ? 'plain' : 'html';
326 326
 		}
327
-		if($_type == 'plain') {
327
+		if ($_type == 'plain') {
328 328
 			$this->message_plain = $_message;
329 329
 		} else {
330 330
 			$this->message_html = $_message;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 	 */
343 343
 	public function set_popupmessage($_message) {
344 344
 		//popup requires html
345
-		if(strlen($_message) == strlen(strip_tags($_message))) $_message = self::plain2html($_message);
345
+		if (strlen($_message) == strlen(strip_tags($_message))) $_message = self::plain2html($_message);
346 346
 		$this->message_popup = $_message;
347 347
 		return true;
348 348
 	}
@@ -354,9 +354,9 @@  discard block
 block discarded – undo
354 354
 	 */
355 355
 	public function set_links(array $_links) {
356 356
 		$this->links = array(); // clear array if set
357
-		foreach($_links as $link) {
358
-			if(is_array($link)) {
359
-				$this->add_link($link['text'], $link['view'], $link['popup'], $link['app'],$link['id']);
357
+		foreach ($_links as $link) {
358
+			if (is_array($link)) {
359
+				$this->add_link($link['text'], $link['view'], $link['popup'], $link['app'], $link['id']);
360 360
 			}
361 361
 		}
362 362
 		return true;
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
 	 */
370 370
 	public function set_popuplinks(array $_links) {
371 371
 		$this->popup_links = array(); // clear array if set
372
-		foreach($_links as $link) {
373
-			if(is_array($link)) {
372
+		foreach ($_links as $link) {
373
+			if (is_array($link)) {
374 374
 				$this->add_popuplink($link['text'], $link['view'], $link['popup'], $link['app']);
375 375
 			}
376 376
 		}
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 	 * @param string $_id Application ID, to use link registry (popup & view ignored)
388 388
 	 */
389 389
 	public function add_link($_text, $_view, $_popup = false, $_app = false, $_id = false) {
390
-		if(!$_view || !$_text) { return false; }
390
+		if (!$_view || !$_text) { return false; }
391 391
 		$this->links[] = (object)array(
392 392
 			'text'	=> $_text,
393 393
 			'view'	=> $_view,
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	 * @param string $_app application name
408 408
 	 */
409 409
 	public function add_popuplink($_text, $_view, $_popup = false, $_app = '') {
410
-		if(!$_view || !$_text) { return false; }
410
+		if (!$_view || !$_text) { return false; }
411 411
 		$this->popup_links[] = (object)array(
412 412
 										'text'	=> $_text,
413 413
 										'view'	=> $_view,
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
 	 */
425 425
 	public function set_attachments(array $_attachments) {
426 426
 		$this->attachments = array(); // clear array if set
427
-		foreach($_attachments as $attachment) {
428
-			if(is_array($attachment)) {
427
+		foreach ($_attachments as $attachment) {
428
+			if (is_array($attachment)) {
429 429
 				$this->add_attachment(
430 430
 					$attachment['string'],
431 431
 					$attachment['filename'],
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	 * @param string $_type File extension (MIME) type.
450 450
 	 * @param string $_path optional path to attachment, if !$_string
451 451
 	 */
452
-	public function add_attachment($_string, $_filename, $_encoding = "base64", $_type = "application/octet-stream", $_path=null) {
453
-		if(!$_string && (!$_path || !file_exists($_path)) || !$_filename) return false;
452
+	public function add_attachment($_string, $_filename, $_encoding = "base64", $_type = "application/octet-stream", $_path = null) {
453
+		if (!$_string && (!$_path || !file_exists($_path)) || !$_filename) return false;
454 454
 		$this->attachments[] = (object)array(
455 455
 			'string' => $_string,
456 456
 			'filename' => $_filename,
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 		if (!is_array($this->receivers) || count($this->receivers) == 0) {
483 483
 			throw new Exception('Error: cannot send notifications. No receivers supplied');
484 484
 		}
485
-		if(!$messages = $this->create_messages($this->message_plain, $this->message_html, $this->message_popup)) {
485
+		if (!$messages = $this->create_messages($this->message_plain, $this->message_html, $this->message_popup)) {
486 486
 			throw new Exception('Error: cannot send notifications. No valid messages supplied');
487 487
 		}
488 488
 
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 			$backend_errors = array();
497 497
 			try {
498 498
 				// system or non-system user
499
-				if($receiver->account_id && is_numeric($receiver->account_id)) {
499
+				if ($receiver->account_id && is_numeric($receiver->account_id)) {
500 500
 					// system user, collect data and check for Status and expire state, skip notification if expired or not active
501 501
 					$userData = $GLOBALS['egw']->accounts->read($receiver->account_id);
502 502
 					//error_log(__METHOD__.__LINE__." fetched data for User:".array2string($userData['account_lid']).'#'.$userData['account_type'].'#'.$userData['account_status'].'#'.$GLOBALS['egw']->accounts->is_expired($userData).'#');
@@ -509,17 +509,17 @@  discard block
 block discarded – undo
509 509
 					}
510 510
 					$receiver->handle = $receiver->account_lid;
511 511
 					// check if the receiver has rights to run the notifcation app
512
-					$ids = $GLOBALS['egw']->accounts->memberships($receiver->account_id,true);
512
+					$ids = $GLOBALS['egw']->accounts->memberships($receiver->account_id, true);
513 513
 					$ids[] = $receiver->account_id;
514
-					if ($GLOBALS['egw']->acl->get_specific_rights_for_account($ids,'run','notifications')) {
514
+					if ($GLOBALS['egw']->acl->get_specific_rights_for_account($ids, 'run', 'notifications')) {
515 515
 						// read the users notification chain
516 516
 						$prefs = new Api\Preferences($receiver->account_id);
517 517
 						$preferences_all = $prefs->read();
518 518
 						$preferences = (object)$preferences_all[self::_appname];
519
-						if($preferences->notification_chain) {
519
+						if ($preferences->notification_chain) {
520 520
 							// fallback: admin disabled user-chosen chain
521
-							if(!$notification_chain = $available_chains[$preferences->notification_chain]) {
522
-								$prepend_message .= lang(	'This eGroupWare notification has been sent to you by mail because your'
521
+							if (!$notification_chain = $available_chains[$preferences->notification_chain]) {
522
+								$prepend_message .= lang('This eGroupWare notification has been sent to you by mail because your'
523 523
 															.' chosen notification-chain has been disabled by the administrator.'
524 524
 															.' Please choose another notification-chain in your preferences!');
525 525
 								$notification_chain = $available_chains[self::_fallback];
@@ -536,28 +536,28 @@  discard block
 block discarded – undo
536 536
 					$notification_chain = $available_chains[self::_fallback]; // fallback: non-system user
537 537
 				}
538 538
 
539
-				if($notification_chain == 'disable') {
539
+				if ($notification_chain == 'disable') {
540 540
 					continue; //user disabled notifications
541 541
 				}
542 542
 
543
-				foreach($notification_chain as $backend => $action) {
543
+				foreach ($notification_chain as $backend => $action) {
544 544
 					$notification_backend = null;
545 545
 					try {
546 546
 						// check if backend should be skipped
547
-						if( in_array($backend, $this->skip_backends) ) {
547
+						if (in_array($backend, $this->skip_backends)) {
548 548
 							// log as error just for the case too much skipping prevents user from being notified
549 549
 							$backend_errors[] = $backend.' will be skipped (as defined by calling application)';
550 550
 							continue;
551 551
 						}
552 552
 
553 553
 						$notification_backend = self::_appname.'_'.$backend;
554
-						if(!file_exists(EGW_INCLUDE_ROOT.'/'. self::_appname.'/inc/class.'. $notification_backend. '.inc.php')) {
555
-							throw new Exception('file for '.$notification_backend. ' does not exist');
554
+						if (!file_exists(EGW_INCLUDE_ROOT.'/'.self::_appname.'/inc/class.'.$notification_backend.'.inc.php')) {
555
+							throw new Exception('file for '.$notification_backend.' does not exist');
556 556
 						}
557
-						$obj = new $notification_backend( $this->sender, $receiver, $this->config, $preferences );
558
-						if ( !($obj instanceof notifications_iface) ) {
559
-							unset ( $obj );
560
-					 		throw new Exception($notification_backend. ' is no implementation of notifications_iface');
557
+						$obj = new $notification_backend($this->sender, $receiver, $this->config, $preferences);
558
+						if (!($obj instanceof notifications_iface)) {
559
+							unset ($obj);
560
+					 		throw new Exception($notification_backend.' is no implementation of notifications_iface');
561 561
 						}
562 562
 						$lsubject = $this->subject;
563 563
 						$llinks = $this->links;
@@ -567,14 +567,14 @@  discard block
 block discarded – undo
567 567
 							if ($this->popup_links) $llinks = $this->popup_links;
568 568
 							if (is_array($this->popup_data)) $popup_data = $this->popup_data;
569 569
 						} elseif ($backend == 'email') {
570
-							if (!empty($this->reply_to)) $popup_data = array( 'reply_to' => $this->reply_to );
570
+							if (!empty($this->reply_to)) $popup_data = array('reply_to' => $this->reply_to);
571 571
 						}
572 572
 						$obj->send($this->prepend_message($messages, $prepend_message), $lsubject, $llinks, $this->attachments, $popup_data);
573 573
 
574 574
 						// This is to make popup_or_email option sensfull since
575 575
 						// we save popup notifications in database anyway, email
576 576
 						// notifications should be based on user availability.
577
-						if ($backend == 'popup' && $action== 'fail' && !Api\Session::notifications_active($receiver->account_id))
577
+						if ($backend == 'popup' && $action == 'fail' && !Api\Session::notifications_active($receiver->account_id))
578 578
 						{
579 579
 							throw new Exception();
580 580
 						}
@@ -582,17 +582,17 @@  discard block
 block discarded – undo
582 582
 					catch (Exception $exception) {
583 583
 						$backend_errors[] = $notification_backend.' failed: '.$exception->getMessage();
584 584
 						// try next backend
585
-						if($action == 'fail' || $action == 'continue') {
585
+						if ($action == 'fail' || $action == 'continue') {
586 586
 							continue;
587 587
 						}
588 588
 						break; // stop running through chain
589 589
 					}
590 590
 					// backend sucseeded
591 591
 					$user_notified = true;
592
-					if($action == 'stop' || $action == 'fail') { break; } // stop running through chain
592
+					if ($action == 'stop' || $action == 'fail') { break; } // stop running through chain
593 593
 				}
594 594
 				// check if the user has been notified at all
595
-				if(!$user_notified) {
595
+				if (!$user_notified) {
596 596
 					/*error_log('Error: notification of receiver '.$receiver->handle.' failed for the following reasons:');
597 597
 					foreach($backend_errors as $id=>$backend_error) {
598 598
 						error_log($backend_error);
@@ -619,22 +619,22 @@  discard block
 block discarded – undo
619 619
 	 * @return plain and html message in one array, $messages['plain'] and $messages['html'] and, if exists $messages['popup']
620 620
 	 */
621 621
 	private function create_messages($_message_plain = '', $_message_html = '', $_message_popup = '') {
622
-		if(empty($_message_plain) && empty($_message_html) && empty($_message_popup)) { return false; } // no message set
622
+		if (empty($_message_plain) && empty($_message_html) && empty($_message_popup)) { return false; } // no message set
623 623
 		$messages = array();
624 624
 
625 625
 		// create the messages
626
-		if(!empty($_message_plain)) {
626
+		if (!empty($_message_plain)) {
627 627
 			$messages['plain'] = $_message_plain;
628 628
 		} else {
629 629
 			$messages['plain'] = Api\Mail\Html::convertHTMLToText($_message_html, false, true);
630 630
 		}
631 631
 
632
-		if(!empty($_message_html)) {
632
+		if (!empty($_message_html)) {
633 633
 			$messages['html'] = $_message_html;
634 634
 		} else {
635 635
 			$messages['html'] = self::plain2html($_message_plain);
636 636
 		}
637
-		if (!empty($_message_popup)) $messages['popup']=$_message_popup;
637
+		if (!empty($_message_popup)) $messages['popup'] = $_message_popup;
638 638
 		return $messages;
639 639
 	}
640 640
 
@@ -657,9 +657,9 @@  discard block
 block discarded – undo
657 657
 	 * @return plain and html message in one array including the prepended message, $messages['plain'] and $messages['html']
658 658
 	 */
659 659
 	 private function prepend_message(array $_messages, $_prepend = null) {
660
-		if(strlen($_prepend) > 0) {
661
-			foreach($_messages as $key => $value) {
662
-				switch($key) {
660
+		if (strlen($_prepend) > 0) {
661
+			foreach ($_messages as $key => $value) {
662
+				switch ($key) {
663 663
 					case 'plain':
664 664
 						$_messages[$key] = $_prepend."\n\n".$value;
665 665
 						break;
@@ -683,17 +683,17 @@  discard block
 block discarded – undo
683 683
 	 * @param string $_part
684 684
 	 * @return string chosen part of the address
685 685
 	 */
686
-	private function get_addresspart($_address, $_part='email')
686
+	private function get_addresspart($_address, $_part = 'email')
687 687
 	{
688 688
 		$parts = null;
689
-	 	if(strpos($_address,'<') && preg_match('/^(.*)\S?\<(.*)\>/',$_address, $parts)) { // _address contains a fullname part
690
-	 		$fullname = trim(trim($parts[1]),'\"');
689
+	 	if (strpos($_address, '<') && preg_match('/^(.*)\S?\<(.*)\>/', $_address, $parts)) { // _address contains a fullname part
690
+	 		$fullname = trim(trim($parts[1]), '\"');
691 691
 	 		$email = $parts[2];
692 692
 	 	} else {
693 693
 	 		$fullname = false;
694 694
 	 		$email = $_address;
695 695
 	 	}
696
-	 	switch($_part) {
696
+	 	switch ($_part) {
697 697
 	 		case 'fullname':
698 698
 	 			return $fullname;
699 699
 	 		case 'email':
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
 	public function get_available_chains($_output = 'routing') {
716 716
 		// determine enabled backends from Api\Config
717 717
 		$enabled_backends = array();
718
-		foreach($this->backends as $backend) {
719
-			switch($backend) {
718
+		foreach ($this->backends as $backend) {
719
+			switch ($backend) {
720 720
 				case 'email':
721 721
 				case 'popup':
722 722
 				case 'jpopup':
@@ -731,15 +731,15 @@  discard block
 block discarded – undo
731 731
 
732 732
 		$enabled_chains = array();
733 733
 		$disabled_chains = array();
734
-		foreach($this->notification_chains as $key => $chain) {
734
+		foreach ($this->notification_chains as $key => $chain) {
735 735
 			$allow_chain = true;
736
-			if(is_array($chain)) {
737
-				foreach(array_keys($chain) as $name) {
738
-					if(!$enabled_backends[$name]) {
736
+			if (is_array($chain)) {
737
+				foreach (array_keys($chain) as $name) {
738
+					if (!$enabled_backends[$name]) {
739 739
 						$allow_chain = false; // disable whole chain if one backend is disabled
740 740
 					}
741 741
 				}
742
-				if($allow_chain) {
742
+				if ($allow_chain) {
743 743
 					$enabled_chains[$key] = $chain;
744 744
 				} else {
745 745
 					$disabled_chains[$key] = $chain;
@@ -754,15 +754,15 @@  discard block
 block discarded – undo
754 754
 		// create the 'all' chain from the enabled backends
755 755
 		$chain_all = array();
756 756
 		$backend_count = 1;
757
-		foreach($enabled_backends as $backend => $enabled) {
758
-			if($enabled) {
757
+		foreach ($enabled_backends as $backend => $enabled) {
758
+			if ($enabled) {
759 759
 				$chain_all[$backend] = count($enabled_backends) == $backend_count ? 'stop' : 'continue';
760 760
 			}
761 761
 			$backend_count++;
762 762
 		}
763 763
 		$common_chains['all'] = $chain_all;
764 764
 
765
-		switch($_output) {
765
+		switch ($_output) {
766 766
 			case 'human':
767 767
 				$chain_groups = array(
768 768
 					lang('Common chains')	=> 'common_chains',
@@ -771,10 +771,10 @@  discard block
 block discarded – undo
771 771
 					);
772 772
 				$suffix = '_human';
773 773
 				// create descriptions for each chain key in each group
774
-				foreach($chain_groups as $name => $arr_name) {
774
+				foreach ($chain_groups as $name => $arr_name) {
775 775
 					${$arr_name.$suffix} = array();
776
-					foreach(array_keys(${$arr_name}) as $key) {
777
-						if($arr_name == 'disabled_chains') {
776
+					foreach (array_keys(${$arr_name}) as $key) {
777
+						if ($arr_name == 'disabled_chains') {
778 778
 							${$arr_name.$suffix}[$key] = '('.lang('Disabled').') '.lang($this->chains_descriptions[$key]);
779 779
 						} else {
780 780
 							${$arr_name.$suffix}[$key] = lang($this->chains_descriptions[$key]);
@@ -783,8 +783,8 @@  discard block
 block discarded – undo
783 783
 				}
784 784
 				// summarize all groups with minimum one chain to the final array
785 785
 				$chains_final = array();
786
-				foreach($chain_groups as $name => $arr_name) {
787
-					if(is_array(${$arr_name.$suffix}) && count(${$arr_name.$suffix}) > 0) {
786
+				foreach ($chain_groups as $name => $arr_name) {
787
+					if (is_array(${$arr_name.$suffix}) && count(${$arr_name.$suffix}) > 0) {
788 788
 						$chains_final[$name] = ${$arr_name.$suffix};
789 789
 					}
790 790
 				}
@@ -804,10 +804,10 @@  discard block
 block discarded – undo
804 804
 	 * @param settings array with keys account_id and new_owner (new_owner is optional)
805 805
 	 */
806 806
 	public function deleteaccount($settings) {
807
-		foreach($this->backends as $backend) {
808
-			$backend_hook = array(self::_appname.'_'.$backend,'deleteaccount');
807
+		foreach ($this->backends as $backend) {
808
+			$backend_hook = array(self::_appname.'_'.$backend, 'deleteaccount');
809 809
 			if (is_callable($backend_hook)) {
810
-				call_user_func($backend_hook,$settings);
810
+				call_user_func($backend_hook, $settings);
811 811
 			}
812 812
 		}
813 813
 	}
Please login to merge, or discard this patch.
Braces   +237 added lines, -101 removed lines patch added patch discarded remove patch
@@ -24,7 +24,8 @@  discard block
 block discarded – undo
24 24
  * called from this class. The backend's job is to deliver ONE message to ONE recipient.
25 25
  *
26 26
  */
27
-class notifications {
27
+class notifications
28
+{
28 29
 
29 30
 	/**
30 31
 	 * Appname
@@ -190,7 +191,8 @@  discard block
 block discarded – undo
190 191
 	 * constructor of notifications
191 192
 	 *
192 193
 	 */
193
-	public function __construct() {
194
+	public function __construct()
195
+	{
194 196
 		$this->config = (object) Api\Config::read(self::_appname);
195 197
 	}
196 198
 
@@ -203,7 +205,10 @@  discard block
 block discarded – undo
203 205
 	public static function errors($reset=false)
204 206
 	{
205 207
 		$ret = self::$errors;
206
-		if ($reset) self::$errors = array();
208
+		if ($reset)
209
+		{
210
+			self::$errors = array();
211
+		}
207 212
 		return $ret;
208 213
 	}
209 214
 
@@ -214,17 +219,23 @@  discard block
 block discarded – undo
214 219
 	 * as long as the accounts class isn't a nice object,
215 220
 	 * it's an int with the account id or the e-mail address of a non-eGW user
216 221
 	 */
217
-	public function set_sender($_sender) {
218
-		if(is_object($_sender)) {
222
+	public function set_sender($_sender)
223
+	{
224
+		if(is_object($_sender))
225
+		{
219 226
 			$this->sender = $_sender;
220 227
 			return true;
221
-		} else {
228
+		}
229
+		else
230
+		{
222 231
 			// no object atm, we have to handle this and make a pseudo-object
223
-			if(is_numeric($_sender)) {
232
+			if(is_numeric($_sender))
233
+			{
224 234
 				$this->sender = (object) $GLOBALS['egw']->accounts->read($_sender);
225 235
 				return true;
226 236
 			}
227
-			if(is_string($_sender) && strpos($_sender,'@')) {
237
+			if(is_string($_sender) && strpos($_sender,'@'))
238
+			{
228 239
 				$this->sender = (object) array (
229 240
 									'account_email' => $this->get_addresspart($_sender,'email'),
230 241
 									'account_fullname' => $this->get_addresspart($_sender,'fullname'),
@@ -240,7 +251,8 @@  discard block
 block discarded – undo
240 251
 	 *
241 252
 	 * @param $_reply_to string for email address to reply to
242 253
 	 */
243
-	public function set_reply_to($_reply_to) {
254
+	public function set_reply_to($_reply_to)
255
+	{
244 256
 		$this->reply_to = $_reply_to;
245 257
 		return true;
246 258
 	}
@@ -252,9 +264,11 @@  discard block
 block discarded – undo
252 264
 	 * as long as the accounts class isn't a nice object,
253 265
 	 * it's an array with the int of the account id or the e-mail address of a non-eGW user
254 266
 	 */
255
-	public function set_receivers(array $_receivers) {
267
+	public function set_receivers(array $_receivers)
268
+	{
256 269
 		$this->receivers = array();
257
-		foreach ($_receivers as $receiver) {
270
+		foreach ($_receivers as $receiver)
271
+		{
258 272
 			$this->add_receiver($receiver);
259 273
 		}
260 274
 	}
@@ -266,17 +280,23 @@  discard block
 block discarded – undo
266 280
 	 * as long as the accounts class isn't a nice object,
267 281
 	 * it's an int with the account id or the e-mail address of a non-eGW user
268 282
 	 */
269
-	public function add_receiver($_receiver) {
270
-		if(is_object($_receiver)) {
283
+	public function add_receiver($_receiver)
284
+	{
285
+		if(is_object($_receiver))
286
+		{
271 287
 			$this->receivers[] = $_receiver;
272 288
 			return true;
273
-		} else {
289
+		}
290
+		else
291
+		{
274 292
 			// no object atm, we have to handle this and make a pseudo-object
275
-			if(is_numeric($_receiver)) {
293
+			if(is_numeric($_receiver))
294
+			{
276 295
 				$this->receivers[] = (object) $GLOBALS['egw']->accounts->read($_receiver);
277 296
 				return true;
278 297
 			}
279
-			if(is_string($_receiver) && strpos($_receiver,'@')) {
298
+			if(is_string($_receiver) && strpos($_receiver,'@'))
299
+			{
280 300
 				$this->receivers[] = (object) array (
281 301
 									'account_email' => $this->get_addresspart($_receiver,'email'),
282 302
 									'account_fullname' => $this->get_addresspart($_receiver,'fullname'),
@@ -292,7 +312,8 @@  discard block
 block discarded – undo
292 312
 	 *
293 313
 	 * @param string $_subject
294 314
 	 */
295
-	public function set_subject($_subject) {
315
+	public function set_subject($_subject)
316
+	{
296 317
 		$this->subject = $_subject;
297 318
 		return true;
298 319
 	}
@@ -302,7 +323,8 @@  discard block
 block discarded – undo
302 323
 	 *
303 324
 	 * @param string $_subject
304 325
 	 */
305
-	public function set_popupsubject($_subject) {
326
+	public function set_popupsubject($_subject)
327
+	{
306 328
 		$this->popupsubject = $_subject;
307 329
 		return true;
308 330
 	}
@@ -319,14 +341,18 @@  discard block
 block discarded – undo
319 341
 	 * @param string $_message
320 342
 	 * @param string $_type Type of message, 'plain' or 'html'
321 343
 	 */
322
-	public function set_message($_message, $_type = false) {
344
+	public function set_message($_message, $_type = false)
345
+	{
323 346
 		if(!$_type)
324 347
 		{
325 348
 			$_type = strlen($_message) == strlen(strip_tags($_message)) ? 'plain' : 'html';
326 349
 		}
327
-		if($_type == 'plain') {
350
+		if($_type == 'plain')
351
+		{
328 352
 			$this->message_plain = $_message;
329
-		} else {
353
+		}
354
+		else
355
+		{
330 356
 			$this->message_html = $_message;
331 357
 		}
332 358
 		return true;
@@ -340,9 +366,13 @@  discard block
 block discarded – undo
340 366
 	 *
341 367
 	 * @param string $_message
342 368
 	 */
343
-	public function set_popupmessage($_message) {
369
+	public function set_popupmessage($_message)
370
+	{
344 371
 		//popup requires html
345
-		if(strlen($_message) == strlen(strip_tags($_message))) $_message = self::plain2html($_message);
372
+		if(strlen($_message) == strlen(strip_tags($_message)))
373
+		{
374
+			$_message = self::plain2html($_message);
375
+		}
346 376
 		$this->message_popup = $_message;
347 377
 		return true;
348 378
 	}
@@ -352,10 +382,13 @@  discard block
 block discarded – undo
352 382
 	 *
353 383
 	 * @param array $_links link array (like defined in $this->add_link)
354 384
 	 */
355
-	public function set_links(array $_links) {
385
+	public function set_links(array $_links)
386
+	{
356 387
 		$this->links = array(); // clear array if set
357
-		foreach($_links as $link) {
358
-			if(is_array($link)) {
388
+		foreach($_links as $link)
389
+		{
390
+			if(is_array($link))
391
+			{
359 392
 				$this->add_link($link['text'], $link['view'], $link['popup'], $link['app'],$link['id']);
360 393
 			}
361 394
 		}
@@ -367,10 +400,13 @@  discard block
 block discarded – undo
367 400
 	 *
368 401
 	 * @param array $_links link array (like defined in $this->add_link)
369 402
 	 */
370
-	public function set_popuplinks(array $_links) {
403
+	public function set_popuplinks(array $_links)
404
+	{
371 405
 		$this->popup_links = array(); // clear array if set
372
-		foreach($_links as $link) {
373
-			if(is_array($link)) {
406
+		foreach($_links as $link)
407
+		{
408
+			if(is_array($link))
409
+			{
374 410
 				$this->add_popuplink($link['text'], $link['view'], $link['popup'], $link['app']);
375 411
 			}
376 412
 		}
@@ -386,8 +422,11 @@  discard block
 block discarded – undo
386 422
 	 * @param string $_app Application name, to use link registry (popup & view ignored)
387 423
 	 * @param string $_id Application ID, to use link registry (popup & view ignored)
388 424
 	 */
389
-	public function add_link($_text, $_view, $_popup = false, $_app = false, $_id = false) {
390
-		if(!$_view || !$_text) { return false; }
425
+	public function add_link($_text, $_view, $_popup = false, $_app = false, $_id = false)
426
+	{
427
+		if(!$_view || !$_text)
428
+		{
429
+return false; }
391 430
 		$this->links[] = (object)array(
392 431
 			'text'	=> $_text,
393 432
 			'view'	=> $_view,
@@ -406,8 +445,11 @@  discard block
 block discarded – undo
406 445
 	 * @param string $_popup if link can be viewed in a popup something like '300x200' otherwise false
407 446
 	 * @param string $_app application name
408 447
 	 */
409
-	public function add_popuplink($_text, $_view, $_popup = false, $_app = '') {
410
-		if(!$_view || !$_text) { return false; }
448
+	public function add_popuplink($_text, $_view, $_popup = false, $_app = '')
449
+	{
450
+		if(!$_view || !$_text)
451
+		{
452
+return false; }
411 453
 		$this->popup_links[] = (object)array(
412 454
 										'text'	=> $_text,
413 455
 										'view'	=> $_view,
@@ -422,10 +464,13 @@  discard block
 block discarded – undo
422 464
 	 *
423 465
 	 * @param array $_attachments attachment array (like defined in $this->add_attachment)
424 466
 	 */
425
-	public function set_attachments(array $_attachments) {
467
+	public function set_attachments(array $_attachments)
468
+	{
426 469
 		$this->attachments = array(); // clear array if set
427
-		foreach($_attachments as $attachment) {
428
-			if(is_array($attachment)) {
470
+		foreach($_attachments as $attachment)
471
+		{
472
+			if(is_array($attachment))
473
+			{
429 474
 				$this->add_attachment(
430 475
 					$attachment['string'],
431 476
 					$attachment['filename'],
@@ -449,8 +494,12 @@  discard block
 block discarded – undo
449 494
 	 * @param string $_type File extension (MIME) type.
450 495
 	 * @param string $_path optional path to attachment, if !$_string
451 496
 	 */
452
-	public function add_attachment($_string, $_filename, $_encoding = "base64", $_type = "application/octet-stream", $_path=null) {
453
-		if(!$_string && (!$_path || !file_exists($_path)) || !$_filename) return false;
497
+	public function add_attachment($_string, $_filename, $_encoding = "base64", $_type = "application/octet-stream", $_path=null)
498
+	{
499
+		if(!$_string && (!$_path || !file_exists($_path)) || !$_filename)
500
+		{
501
+			return false;
502
+		}
454 503
 		$this->attachments[] = (object)array(
455 504
 			'string' => $_string,
456 505
 			'filename' => $_filename,
@@ -468,21 +517,26 @@  discard block
 block discarded – undo
468 517
 	 * @param array $_skip_backends array with names of the backends to be skipped
469 518
 	 * e.g. array('popup', 'winpopup')
470 519
 	 */
471
-	public function set_skip_backends(array $_skip_backends) {
520
+	public function set_skip_backends(array $_skip_backends)
521
+	{
472 522
 		$this->skip_backends = $_skip_backends;
473 523
 	}
474 524
 
475 525
 	/**
476 526
 	 * sends notifications
477 527
 	 */
478
-	public function send() {
479
-		if (!is_object($this->sender)) {
528
+	public function send()
529
+	{
530
+		if (!is_object($this->sender))
531
+		{
480 532
 			throw new Exception('Error: cannot send notifications. No sender supplied');
481 533
 		}
482
-		if (!is_array($this->receivers) || count($this->receivers) == 0) {
534
+		if (!is_array($this->receivers) || count($this->receivers) == 0)
535
+		{
483 536
 			throw new Exception('Error: cannot send notifications. No receivers supplied');
484 537
 		}
485
-		if(!$messages = $this->create_messages($this->message_plain, $this->message_html, $this->message_popup)) {
538
+		if(!$messages = $this->create_messages($this->message_plain, $this->message_html, $this->message_popup))
539
+		{
486 540
 			throw new Exception('Error: cannot send notifications. No valid messages supplied');
487 541
 		}
488 542
 
@@ -490,13 +544,15 @@  discard block
 block discarded – undo
490 544
 
491 545
 		$available_chains = $this->get_available_chains('routing');
492 546
 
493
-		foreach ($this->receivers as $receiver) {
547
+		foreach ($this->receivers as $receiver)
548
+		{
494 549
 			$user_notified = false;
495 550
 			$prepend_message = '';
496 551
 			$backend_errors = array();
497 552
 			try {
498 553
 				// system or non-system user
499
-				if($receiver->account_id && is_numeric($receiver->account_id)) {
554
+				if($receiver->account_id && is_numeric($receiver->account_id))
555
+				{
500 556
 					// system user, collect data and check for Status and expire state, skip notification if expired or not active
501 557
 					$userData = $GLOBALS['egw']->accounts->read($receiver->account_id);
502 558
 					//error_log(__METHOD__.__LINE__." fetched data for User:".array2string($userData['account_lid']).'#'.$userData['account_type'].'#'.$userData['account_status'].'#'.$GLOBALS['egw']->accounts->is_expired($userData).'#');
@@ -511,51 +567,65 @@  discard block
 block discarded – undo
511 567
 					// check if the receiver has rights to run the notifcation app
512 568
 					$ids = $GLOBALS['egw']->accounts->memberships($receiver->account_id,true);
513 569
 					$ids[] = $receiver->account_id;
514
-					if ($GLOBALS['egw']->acl->get_specific_rights_for_account($ids,'run','notifications')) {
570
+					if ($GLOBALS['egw']->acl->get_specific_rights_for_account($ids,'run','notifications'))
571
+					{
515 572
 						// read the users notification chain
516 573
 						$prefs = new Api\Preferences($receiver->account_id);
517 574
 						$preferences_all = $prefs->read();
518 575
 						$preferences = (object)$preferences_all[self::_appname];
519
-						if($preferences->notification_chain) {
576
+						if($preferences->notification_chain)
577
+						{
520 578
 							// fallback: admin disabled user-chosen chain
521
-							if(!$notification_chain = $available_chains[$preferences->notification_chain]) {
579
+							if(!$notification_chain = $available_chains[$preferences->notification_chain])
580
+							{
522 581
 								$prepend_message .= lang(	'This eGroupWare notification has been sent to you by mail because your'
523 582
 															.' chosen notification-chain has been disabled by the administrator.'
524 583
 															.' Please choose another notification-chain in your preferences!');
525 584
 								$notification_chain = $available_chains[self::_fallback];
526 585
 							}
527
-						} else {
586
+						}
587
+						else
588
+						{
528 589
 							$notification_chain = $available_chains[self::user_fallback]; // fallback: no prefs
529 590
 						}
530
-					} else {
591
+					}
592
+					else
593
+					{
531 594
 						$notification_chain = $available_chains[self::_fallback]; // fallback: no rights to app
532 595
 					}
533
-				} else {
596
+				}
597
+				else
598
+				{
534 599
 					// non-system user
535 600
 					$receiver->handle = $receiver->account_email;
536 601
 					$notification_chain = $available_chains[self::_fallback]; // fallback: non-system user
537 602
 				}
538 603
 
539
-				if($notification_chain == 'disable') {
604
+				if($notification_chain == 'disable')
605
+				{
540 606
 					continue; //user disabled notifications
541 607
 				}
542 608
 
543
-				foreach($notification_chain as $backend => $action) {
609
+				foreach($notification_chain as $backend => $action)
610
+				{
544 611
 					$notification_backend = null;
545 612
 					try {
546 613
 						// check if backend should be skipped
547
-						if( in_array($backend, $this->skip_backends) ) {
614
+						if( in_array($backend, $this->skip_backends) )
615
+						{
548 616
 							// log as error just for the case too much skipping prevents user from being notified
549 617
 							$backend_errors[] = $backend.' will be skipped (as defined by calling application)';
550 618
 							continue;
551 619
 						}
552 620
 
553 621
 						$notification_backend = self::_appname.'_'.$backend;
554
-						if(!file_exists(EGW_INCLUDE_ROOT.'/'. self::_appname.'/inc/class.'. $notification_backend. '.inc.php')) {
622
+						if(!file_exists(EGW_INCLUDE_ROOT.'/'. self::_appname.'/inc/class.'. $notification_backend. '.inc.php'))
623
+						{
555 624
 							throw new Exception('file for '.$notification_backend. ' does not exist');
556 625
 						}
557 626
 						$obj = new $notification_backend( $this->sender, $receiver, $this->config, $preferences );
558
-						if ( !($obj instanceof notifications_iface) ) {
627
+						if ( !($obj instanceof notifications_iface) )
628
+						{
559 629
 							unset ( $obj );
560 630
 					 		throw new Exception($notification_backend. ' is no implementation of notifications_iface');
561 631
 						}
@@ -563,11 +633,25 @@  discard block
 block discarded – undo
563 633
 						$llinks = $this->links;
564 634
 						if ($backend == 'popup')
565 635
 						{
566
-							if (!empty($this->popupsubject)) $lsubject = $this->popupsubject;
567
-							if ($this->popup_links) $llinks = $this->popup_links;
568
-							if (is_array($this->popup_data)) $popup_data = $this->popup_data;
569
-						} elseif ($backend == 'email') {
570
-							if (!empty($this->reply_to)) $popup_data = array( 'reply_to' => $this->reply_to );
636
+							if (!empty($this->popupsubject))
637
+							{
638
+								$lsubject = $this->popupsubject;
639
+							}
640
+							if ($this->popup_links)
641
+							{
642
+								$llinks = $this->popup_links;
643
+							}
644
+							if (is_array($this->popup_data))
645
+							{
646
+								$popup_data = $this->popup_data;
647
+							}
648
+						}
649
+						elseif ($backend == 'email')
650
+						{
651
+							if (!empty($this->reply_to))
652
+							{
653
+								$popup_data = array( 'reply_to' => $this->reply_to );
654
+							}
571 655
 						}
572 656
 						$obj->send($this->prepend_message($messages, $prepend_message), $lsubject, $llinks, $this->attachments, $popup_data);
573 657
 
@@ -582,23 +666,30 @@  discard block
 block discarded – undo
582 666
 					catch (Exception $exception) {
583 667
 						$backend_errors[] = $notification_backend.' failed: '.$exception->getMessage();
584 668
 						// try next backend
585
-						if($action == 'fail' || $action == 'continue') {
669
+						if($action == 'fail' || $action == 'continue')
670
+						{
586 671
 							continue;
587 672
 						}
588 673
 						break; // stop running through chain
589 674
 					}
590 675
 					// backend sucseeded
591 676
 					$user_notified = true;
592
-					if($action == 'stop' || $action == 'fail') { break; } // stop running through chain
677
+					if($action == 'stop' || $action == 'fail')
678
+					{
679
+break; } // stop running through chain
593 680
 				}
594 681
 				// check if the user has been notified at all
595
-				if(!$user_notified) {
682
+				if(!$user_notified)
683
+				{
596 684
 					/*error_log('Error: notification of receiver '.$receiver->handle.' failed for the following reasons:');
597 685
 					foreach($backend_errors as $id=>$backend_error) {
598 686
 						error_log($backend_error);
599 687
 					}*/
600 688
 					$error = implode(', ', $backend_errors);
601
-					if (stripos($error, (string)$receiver->handle) !== false) $error = $receiver->handle.': '.$error;
689
+					if (stripos($error, (string)$receiver->handle) !== false)
690
+					{
691
+						$error = $receiver->handle.': '.$error;
692
+					}
602 693
 					self::$errors[] = $error;
603 694
 				}
604 695
 			}
@@ -618,23 +709,35 @@  discard block
 block discarded – undo
618 709
 	 * @param string $_message_popup
619 710
 	 * @return plain and html message in one array, $messages['plain'] and $messages['html'] and, if exists $messages['popup']
620 711
 	 */
621
-	private function create_messages($_message_plain = '', $_message_html = '', $_message_popup = '') {
622
-		if(empty($_message_plain) && empty($_message_html) && empty($_message_popup)) { return false; } // no message set
712
+	private function create_messages($_message_plain = '', $_message_html = '', $_message_popup = '')
713
+	{
714
+		if(empty($_message_plain) && empty($_message_html) && empty($_message_popup))
715
+		{
716
+return false; } // no message set
623 717
 		$messages = array();
624 718
 
625 719
 		// create the messages
626
-		if(!empty($_message_plain)) {
720
+		if(!empty($_message_plain))
721
+		{
627 722
 			$messages['plain'] = $_message_plain;
628
-		} else {
723
+		}
724
+		else
725
+		{
629 726
 			$messages['plain'] = Api\Mail\Html::convertHTMLToText($_message_html, false, true);
630 727
 		}
631 728
 
632
-		if(!empty($_message_html)) {
729
+		if(!empty($_message_html))
730
+		{
633 731
 			$messages['html'] = $_message_html;
634
-		} else {
732
+		}
733
+		else
734
+		{
635 735
 			$messages['html'] = self::plain2html($_message_plain);
636 736
 		}
637
-		if (!empty($_message_popup)) $messages['popup']=$_message_popup;
737
+		if (!empty($_message_popup))
738
+		{
739
+			$messages['popup']=$_message_popup;
740
+		}
638 741
 		return $messages;
639 742
 	}
640 743
 
@@ -656,10 +759,14 @@  discard block
 block discarded – undo
656 759
 	 * @param string $_prepend just a plain message to prepend, no html!
657 760
 	 * @return plain and html message in one array including the prepended message, $messages['plain'] and $messages['html']
658 761
 	 */
659
-	 private function prepend_message(array $_messages, $_prepend = null) {
660
-		if(strlen($_prepend) > 0) {
661
-			foreach($_messages as $key => $value) {
662
-				switch($key) {
762
+	 private function prepend_message(array $_messages, $_prepend = null)
763
+	 {
764
+		if(strlen($_prepend) > 0)
765
+		{
766
+			foreach($_messages as $key => $value)
767
+			{
768
+				switch($key)
769
+				{
663 770
 					case 'plain':
664 771
 						$_messages[$key] = $_prepend."\n\n".$value;
665 772
 						break;
@@ -686,14 +793,19 @@  discard block
 block discarded – undo
686 793
 	private function get_addresspart($_address, $_part='email')
687 794
 	{
688 795
 		$parts = null;
689
-	 	if(strpos($_address,'<') && preg_match('/^(.*)\S?\<(.*)\>/',$_address, $parts)) { // _address contains a fullname part
796
+	 	if(strpos($_address,'<') && preg_match('/^(.*)\S?\<(.*)\>/',$_address, $parts))
797
+	 	{
798
+// _address contains a fullname part
690 799
 	 		$fullname = trim(trim($parts[1]),'\"');
691 800
 	 		$email = $parts[2];
692
-	 	} else {
801
+	 	}
802
+	 	else
803
+	 	{
693 804
 	 		$fullname = false;
694 805
 	 		$email = $_address;
695 806
 	 	}
696
-	 	switch($_part) {
807
+	 	switch($_part)
808
+	 	{
697 809
 	 		case 'fullname':
698 810
 	 			return $fullname;
699 811
 	 		case 'email':
@@ -712,11 +824,14 @@  discard block
 block discarded – undo
712 824
 	 * @param string $_output one of: 'routing' or 'human', defaults to 'routing'
713 825
 	 * @return array containing notification chains, output like given in $_output
714 826
 	 */
715
-	public function get_available_chains($_output = 'routing') {
827
+	public function get_available_chains($_output = 'routing')
828
+	{
716 829
 		// determine enabled backends from Api\Config
717 830
 		$enabled_backends = array();
718
-		foreach($this->backends as $backend) {
719
-			switch($backend) {
831
+		foreach($this->backends as $backend)
832
+		{
833
+			switch($backend)
834
+			{
720 835
 				case 'email':
721 836
 				case 'popup':
722 837
 				case 'jpopup':
@@ -731,17 +846,24 @@  discard block
 block discarded – undo
731 846
 
732 847
 		$enabled_chains = array();
733 848
 		$disabled_chains = array();
734
-		foreach($this->notification_chains as $key => $chain) {
849
+		foreach($this->notification_chains as $key => $chain)
850
+		{
735 851
 			$allow_chain = true;
736
-			if(is_array($chain)) {
737
-				foreach(array_keys($chain) as $name) {
738
-					if(!$enabled_backends[$name]) {
852
+			if(is_array($chain))
853
+			{
854
+				foreach(array_keys($chain) as $name)
855
+				{
856
+					if(!$enabled_backends[$name])
857
+					{
739 858
 						$allow_chain = false; // disable whole chain if one backend is disabled
740 859
 					}
741 860
 				}
742
-				if($allow_chain) {
861
+				if($allow_chain)
862
+				{
743 863
 					$enabled_chains[$key] = $chain;
744
-				} else {
864
+				}
865
+				else
866
+				{
745 867
 					$disabled_chains[$key] = $chain;
746 868
 				}
747 869
 			}
@@ -754,15 +876,18 @@  discard block
 block discarded – undo
754 876
 		// create the 'all' chain from the enabled backends
755 877
 		$chain_all = array();
756 878
 		$backend_count = 1;
757
-		foreach($enabled_backends as $backend => $enabled) {
758
-			if($enabled) {
879
+		foreach($enabled_backends as $backend => $enabled)
880
+		{
881
+			if($enabled)
882
+			{
759 883
 				$chain_all[$backend] = count($enabled_backends) == $backend_count ? 'stop' : 'continue';
760 884
 			}
761 885
 			$backend_count++;
762 886
 		}
763 887
 		$common_chains['all'] = $chain_all;
764 888
 
765
-		switch($_output) {
889
+		switch($_output)
890
+		{
766 891
 			case 'human':
767 892
 				$chain_groups = array(
768 893
 					lang('Common chains')	=> 'common_chains',
@@ -771,20 +896,27 @@  discard block
 block discarded – undo
771 896
 					);
772 897
 				$suffix = '_human';
773 898
 				// create descriptions for each chain key in each group
774
-				foreach($chain_groups as $name => $arr_name) {
899
+				foreach($chain_groups as $name => $arr_name)
900
+				{
775 901
 					${$arr_name.$suffix} = array();
776
-					foreach(array_keys(${$arr_name}) as $key) {
777
-						if($arr_name == 'disabled_chains') {
902
+					foreach(array_keys(${$arr_name}) as $key)
903
+					{
904
+						if($arr_name == 'disabled_chains')
905
+						{
778 906
 							${$arr_name.$suffix}[$key] = '('.lang('Disabled').') '.lang($this->chains_descriptions[$key]);
779
-						} else {
907
+						}
908
+						else
909
+						{
780 910
 							${$arr_name.$suffix}[$key] = lang($this->chains_descriptions[$key]);
781 911
 						}
782 912
 					}
783 913
 				}
784 914
 				// summarize all groups with minimum one chain to the final array
785 915
 				$chains_final = array();
786
-				foreach($chain_groups as $name => $arr_name) {
787
-					if(is_array(${$arr_name.$suffix}) && count(${$arr_name.$suffix}) > 0) {
916
+				foreach($chain_groups as $name => $arr_name)
917
+				{
918
+					if(is_array(${$arr_name.$suffix}) && count(${$arr_name.$suffix}) > 0)
919
+					{
788 920
 						$chains_final[$name] = ${$arr_name.$suffix};
789 921
 					}
790 922
 				}
@@ -803,10 +935,13 @@  discard block
 block discarded – undo
803 935
 	 *
804 936
 	 * @param settings array with keys account_id and new_owner (new_owner is optional)
805 937
 	 */
806
-	public function deleteaccount($settings) {
807
-		foreach($this->backends as $backend) {
938
+	public function deleteaccount($settings)
939
+	{
940
+		foreach($this->backends as $backend)
941
+		{
808 942
 			$backend_hook = array(self::_appname.'_'.$backend,'deleteaccount');
809
-			if (is_callable($backend_hook)) {
943
+			if (is_callable($backend_hook))
944
+			{
810 945
 				call_user_func($backend_hook,$settings);
811 946
 			}
812 947
 		}
@@ -820,7 +955,8 @@  discard block
 block discarded – undo
820 955
 	 * @param array $_data
821 956
 	 * @return boolean
822 957
 	 */
823
-	public function set_popupdata($_appname, $_data) {
958
+	public function set_popupdata($_appname, $_data)
959
+	{
824 960
 		$this->popup_data = array(
825 961
 			'appname' => $_appname,
826 962
 			'data' => $_data
Please login to merge, or discard this patch.
status.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
  * @version $Id$
15 15
  */
16 16
 // forward for not existing or empty header to setup
17
-if(!file_exists('header.inc.php') || !filesize('header.inc.php'))
17
+if (!file_exists('header.inc.php') || !filesize('header.inc.php'))
18 18
 {
19 19
 	Header('Location: setup/index.php');
20 20
 	exit;
Please login to merge, or discard this patch.