Test Setup Failed
Push — master ( 12c298...4a14e0 )
by Ralf
22:03
created
calendar/inc/class.calendar_boupdate.inc.php 4 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1504,22 +1504,22 @@  discard block
 block discarded – undo
1504 1504
 		// check the old list against the new list
1505 1505
 		foreach ($old_event['participants'] as $userid => $status)
1506 1506
   		{
1507
-            if (!isset($new_event['participants'][$userid])){
1508
-            	// Attendee will be deleted this way
1509
-            	$new_event['participants'][$userid] = 'G';
1510
-            }
1511
-            elseif ($new_event['participants'][$userid] == $status)
1512
-            {
1513
-            	// Same status -- nothing to do.
1514
-            	unset($new_event['participants'][$userid]);
1515
-            }
1507
+			if (!isset($new_event['participants'][$userid])){
1508
+				// Attendee will be deleted this way
1509
+				$new_event['participants'][$userid] = 'G';
1510
+			}
1511
+			elseif ($new_event['participants'][$userid] == $status)
1512
+			{
1513
+				// Same status -- nothing to do.
1514
+				unset($new_event['participants'][$userid]);
1515
+			}
1516 1516
 		}
1517 1517
 		// write the changes
1518 1518
 		foreach ($new_event['participants'] as $userid => $status)
1519 1519
 		{
1520 1520
 			$this->set_status($old_event, $userid, $status, $recur_date, true, false,$skip_notification);
1521 1521
 		}
1522
-    }
1522
+	}
1523 1523
 
1524 1524
 	/**
1525 1525
 	 * deletes an event
@@ -2493,24 +2493,24 @@  discard block
 block discarded – undo
2493 2493
 	/**
2494 2494
 	 * classifies an incoming event from the eGW point-of-view
2495 2495
 	 *
2496
-     * exceptions: unlike other calendar apps eGW does not create an event exception
2497
-     * if just the participant state changes - therefore we have to distinguish between
2498
-     * real exceptions and status only exceptions
2499
-     *
2500
-     * @param array $event the event to check
2501
-     *
2502
-     * @return array
2503
-     * 	type =>
2504
-     * 		SINGLE a single event
2505
-     * 		SERIES-MASTER the series master
2506
-     * 		SERIES-EXCEPTION event is a real exception
2507
-	  * 		SERIES-PSEUDO-EXCEPTION event is a status only exception
2508
-	  * 		SERIES-EXCEPTION-PROPAGATE event was a status only exception in the past and is now a real exception
2509
-	  * 	stored_event => if event already exists in the database array with event data or false
2510
-	  * 	master_event => for event type SERIES-EXCEPTION, SERIES-PSEUDO-EXCEPTION or SERIES-EXCEPTION-PROPAGATE
2511
-	  * 		the corresponding series master event array
2512
-	  * 		NOTE: this param is false if event is of type SERIES-MASTER
2513
-     */
2496
+	 * exceptions: unlike other calendar apps eGW does not create an event exception
2497
+	 * if just the participant state changes - therefore we have to distinguish between
2498
+	 * real exceptions and status only exceptions
2499
+	 *
2500
+	 * @param array $event the event to check
2501
+	 *
2502
+	 * @return array
2503
+	 * 	type =>
2504
+	 * 		SINGLE a single event
2505
+	 * 		SERIES-MASTER the series master
2506
+	 * 		SERIES-EXCEPTION event is a real exception
2507
+	 * 		SERIES-PSEUDO-EXCEPTION event is a status only exception
2508
+	 * 		SERIES-EXCEPTION-PROPAGATE event was a status only exception in the past and is now a real exception
2509
+	 * 	stored_event => if event already exists in the database array with event data or false
2510
+	 * 	master_event => for event type SERIES-EXCEPTION, SERIES-PSEUDO-EXCEPTION or SERIES-EXCEPTION-PROPAGATE
2511
+	 * 		the corresponding series master event array
2512
+	 * 		NOTE: this param is false if event is of type SERIES-MASTER
2513
+	 */
2514 2514
 	function get_event_info($event)
2515 2515
 	{
2516 2516
 		$type = 'SINGLE'; // default
@@ -2681,16 +2681,16 @@  discard block
 block discarded – undo
2681 2681
 			'stored_event' => $stored_event,
2682 2682
 			'master_event' => $master_event,
2683 2683
 		);
2684
-    }
2685
-
2686
-    /**
2687
-     * Translates all timestamps for a given event from server-time to user-time.
2688
-     * The update() and save() methods expect timestamps in user-time.
2689
-     * @param &$event	the event we are working on
2690
-     *
2691
-     */
2692
-    function server2usertime (&$event)
2693
-    {
2684
+	}
2685
+
2686
+	/**
2687
+	 * Translates all timestamps for a given event from server-time to user-time.
2688
+	 * The update() and save() methods expect timestamps in user-time.
2689
+	 * @param &$event	the event we are working on
2690
+	 *
2691
+	 */
2692
+	function server2usertime (&$event)
2693
+	{
2694 2694
 		// we run all dates through date2usertime, to adjust to user-time
2695 2695
 		foreach(array('start','end','recur_enddate','recurrence') as $ts)
2696 2696
 		{
@@ -2713,7 +2713,7 @@  discard block
 block discarded – undo
2713 2713
 				$event['alarm'][$id]['time'] = $this->date2usertime($alarm['time']);
2714 2714
 			}
2715 2715
 		}
2716
-    }
2716
+	}
2717 2717
 	/**
2718 2718
 	 * Delete events that are more than $age years old
2719 2719
 	 *
Please login to merge, or discard this patch.
Upper-Lower-Casing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1878,12 +1878,12 @@  discard block
 block discarded – undo
1878 1878
 	 */
1879 1879
 	function event2array($event)
1880 1880
 	{
1881
-		$var['title'] = Array(
1881
+		$var['title'] = array(
1882 1882
 			'field'		=> lang('Title'),
1883 1883
 			'data'		=> $event['title']
1884 1884
 		);
1885 1885
 
1886
-		$var['description'] = Array(
1886
+		$var['description'] = array(
1887 1887
 			'field'	=> lang('Description'),
1888 1888
 			'data'	=> $event['description']
1889 1889
 		);
@@ -1892,48 +1892,48 @@  discard block
 block discarded – undo
1892 1892
 		{
1893 1893
 			$cat_string[] = stripslashes(Api\Categories::id2name($cat_id));
1894 1894
 		}
1895
-		$var['category'] = Array(
1895
+		$var['category'] = array(
1896 1896
 			'field'	=> lang('Category'),
1897 1897
 			'data'	=> implode(', ',$cat_string)
1898 1898
 		);
1899 1899
 
1900
-		$var['location'] = Array(
1900
+		$var['location'] = array(
1901 1901
 			'field'	=> lang('Location'),
1902 1902
 			'data'	=> $event['location']
1903 1903
 		);
1904 1904
 
1905
-		$var['startdate'] = Array(
1905
+		$var['startdate'] = array(
1906 1906
 			'field'	=> lang('Start Date/Time'),
1907 1907
 			'data'	=> $this->format_date($event['start']),
1908 1908
 		);
1909 1909
 
1910
-		$var['enddate'] = Array(
1910
+		$var['enddate'] = array(
1911 1911
 			'field'	=> lang('End Date/Time'),
1912 1912
 			'data'	=> $this->format_date($event['end']),
1913 1913
 		);
1914 1914
 
1915
-		$pri = Array(
1915
+		$pri = array(
1916 1916
 			0   => lang('None'),
1917 1917
 			1	=> lang('Low'),
1918 1918
 			2	=> lang('Normal'),
1919 1919
 			3	=> lang('High')
1920 1920
 		);
1921
-		$var['priority'] = Array(
1921
+		$var['priority'] = array(
1922 1922
 			'field'	=> lang('Priority'),
1923 1923
 			'data'	=> $pri[$event['priority']]
1924 1924
 		);
1925 1925
 
1926
-		$var['owner'] = Array(
1926
+		$var['owner'] = array(
1927 1927
 			'field'	=> lang('Owner'),
1928 1928
 			'data'	=> Api\Accounts::username($event['owner'])
1929 1929
 		);
1930 1930
 
1931
-		$var['updated'] = Array(
1931
+		$var['updated'] = array(
1932 1932
 			'field'	=> lang('Updated'),
1933 1933
 			'data'	=> $this->format_date($event['modtime']).', '.Api\Accounts::username($event['modifier'])
1934 1934
 		);
1935 1935
 
1936
-		$var['access'] = Array(
1936
+		$var['access'] = array(
1937 1937
 			'field'	=> lang('Access'),
1938 1938
 			'data'	=> $event['public'] ? lang('Public') : lang('Private')
1939 1939
 		);
@@ -1956,13 +1956,13 @@  discard block
 block discarded – undo
1956 1956
 			}
1957 1957
 		}
1958 1958
 
1959
-		$var['participants'] = Array(
1959
+		$var['participants'] = array(
1960 1960
 			'field'	=> lang('Participants'),
1961 1961
 			'data'	=> $participants
1962 1962
 		);
1963 1963
 
1964 1964
 		// Repeated Events
1965
-		$var['recur_type'] = Array(
1965
+		$var['recur_type'] = array(
1966 1966
 			'field'	=> lang('Repetition'),
1967 1967
 			'data'	=> ($event['recur_type'] != MCAL_RECUR_NONE) ? $this->recure2string($event) : '',
1968 1968
 		);
@@ -2012,7 +2012,7 @@  discard block
 block discarded – undo
2012 2012
 	 * @param Api\DateTime|int|null $instance_date For recurring events, this is the date we
2013 2013
 	 *	are dealing with
2014 2014
 	 */
2015
-	function check_move_alarms(Array &$event, Array $old_event = null, $instance_date = null)
2015
+	function check_move_alarms(array &$event, array $old_event = null, $instance_date = null)
2016 2016
 	{
2017 2017
 		if ($old_event !== null && $event['start'] == $old_event['start']) return;
2018 2018
 
Please login to merge, or discard this patch.
Spacing   +322 added lines, -324 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@  discard block
 block discarded – undo
16 16
 use EGroupware\Api\Acl;
17 17
 
18 18
 // types of messsages send by calendar_boupdate::send_update
19
-define('MSG_DELETED',0);
20
-define('MSG_MODIFIED',1);
21
-define('MSG_ADDED',2);
22
-define('MSG_REJECTED',3);
23
-define('MSG_TENTATIVE',4);
24
-define('MSG_ACCEPTED',5);
25
-define('MSG_ALARM',6);
26
-define('MSG_DISINVITE',7);
27
-define('MSG_DELEGATED',8);
19
+define('MSG_DELETED', 0);
20
+define('MSG_MODIFIED', 1);
21
+define('MSG_ADDED', 2);
22
+define('MSG_REJECTED', 3);
23
+define('MSG_TENTATIVE', 4);
24
+define('MSG_ACCEPTED', 5);
25
+define('MSG_ALARM', 6);
26
+define('MSG_DISINVITE', 7);
27
+define('MSG_DELEGATED', 8);
28 28
 
29 29
 /**
30 30
  * Class to access AND manipulate all calendar data (business object)
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	function __construct()
87 87
 	{
88
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started',True);
88
+		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started', True);
89 89
 
90
-		parent::__construct();	// calling the parent constructor
90
+		parent::__construct(); // calling the parent constructor
91 91
 
92
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished',True);
92
+		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished', True);
93 93
 	}
94 94
 
95 95
 	/**
@@ -116,16 +116,16 @@  discard block
 block discarded – undo
116 116
 	 * +      + +  C   +	which is clearly wrong for everything with a maximum quantity > 1
117 117
 	 * ++++++++ ++++++++
118 118
 	 */
119
-	function update(&$event,$ignore_conflicts=false,$touch_modified=true,$ignore_acl=false,$updateTS=true,&$messages=null, $skip_notification=false)
119
+	function update(&$event, $ignore_conflicts = false, $touch_modified = true, $ignore_acl = false, $updateTS = true, &$messages = null, $skip_notification = false)
120 120
 	{
121
-		unset($updateTS);	// ignored, as updating timestamps is required for sync!
121
+		unset($updateTS); // ignored, as updating timestamps is required for sync!
122 122
 		//error_log(__METHOD__."(".array2string($event).",$ignore_conflicts,$touch_modified,$ignore_acl)");
123 123
 		if (!is_array($messages)) $messages = $messages ? (array)$messages : array();
124 124
 
125 125
 		if ($this->debug > 1 || $this->debug == 'update')
126 126
 		{
127 127
 			$this->debug_message('calendar_boupdate::update(%1,ignore_conflict=%2,touch_modified=%3,ignore_acl=%4)',
128
-				false,$event,$ignore_conflicts,$touch_modified,$ignore_acl);
128
+				false, $event, $ignore_conflicts, $touch_modified, $ignore_acl);
129 129
 		}
130 130
 		// check some minimum requirements:
131 131
 		// - new events need start, end and title
@@ -153,11 +153,11 @@  discard block
 block discarded – undo
153 153
 		}
154 154
 
155 155
 		// check if user has the permission to update / create the event
156
-		if (!$ignore_acl && (!$new_event && !$this->check_perms(Acl::EDIT,$event['id']) ||
157
-			$new_event && !$this->check_perms(Acl::EDIT,0,$event['owner'])) &&
158
-			!$this->check_perms(Acl::ADD,0,$event['owner']))
156
+		if (!$ignore_acl && (!$new_event && !$this->check_perms(Acl::EDIT, $event['id']) ||
157
+			$new_event && !$this->check_perms(Acl::EDIT, 0, $event['owner'])) &&
158
+			!$this->check_perms(Acl::ADD, 0, $event['owner']))
159 159
 		{
160
-			$messages[] = lang('Access to calendar of %1 denied!',Api\Accounts::username($event['owner']));
160
+			$messages[] = lang('Access to calendar of %1 denied!', Api\Accounts::username($event['owner']));
161 161
 			return false;
162 162
 		}
163 163
 		if ($new_event)
@@ -166,24 +166,24 @@  discard block
 block discarded – undo
166 166
 		}
167 167
 		else
168 168
 		{
169
-			$old_event = $this->read((int)$event['id'],null,$ignore_acl);
169
+			$old_event = $this->read((int)$event['id'], null, $ignore_acl);
170 170
 		}
171 171
 
172 172
 		// do we need to check, if user is allowed to invite the invited participants
173
-		if ($this->require_acl_invite && ($removed = $this->remove_no_acl_invite($event,$old_event)))
173
+		if ($this->require_acl_invite && ($removed = $this->remove_no_acl_invite($event, $old_event)))
174 174
 		{
175 175
 			// report removed participants back to user
176
-			foreach($removed as $key => $account_id)
176
+			foreach ($removed as $key => $account_id)
177 177
 			{
178 178
 				$removed[$key] = $this->participant_name($account_id);
179 179
 			}
180
-			$messages[] = lang('%1 participants removed because of missing invite grants',count($removed)).
181
-				': '.implode(', ',$removed);
180
+			$messages[] = lang('%1 participants removed because of missing invite grants', count($removed)).
181
+				': '.implode(', ', $removed);
182 182
 		}
183 183
 		// check category based ACL
184 184
 		if ($event['category'])
185 185
 		{
186
-			if (!is_array($event['category'])) $event['category'] = explode(',',$event['category']);
186
+			if (!is_array($event['category'])) $event['category'] = explode(',', $event['category']);
187 187
 			if (!$old_event || !isset($old_event['category']))
188 188
 			{
189 189
 				$old_event['category'] = array();
@@ -192,38 +192,38 @@  discard block
 block discarded – undo
192 192
 			{
193 193
 				$old_event['category'] = explode(',', $old_event['category']);
194 194
 			}
195
-			foreach($event['category'] as $key => $cat_id)
195
+			foreach ($event['category'] as $key => $cat_id)
196 196
 			{
197 197
 				// check if user is allowed to update event categories
198
-				if ((!$old_event || !in_array($cat_id,$old_event['category'])) &&
199
-					self::has_cat_right(self::CAT_ACL_ADD,$cat_id,$this->user) === false)
198
+				if ((!$old_event || !in_array($cat_id, $old_event['category'])) &&
199
+					self::has_cat_right(self::CAT_ACL_ADD, $cat_id, $this->user) === false)
200 200
 				{
201 201
 					unset($event['category'][$key]);
202 202
 					// report removed category to user
203 203
 					$removed_cats[$cat_id] = $this->categories->id2name($cat_id);
204
-					continue;	// no further check, as cat was removed
204
+					continue; // no further check, as cat was removed
205 205
 				}
206 206
 				// for new or moved events check status of participants, if no category status right --> set all status to 'U' = unknown
207 207
 				if (!$status_reset_to_unknown &&
208
-					self::has_cat_right(self::CAT_ACL_STATUS,$cat_id,$this->user) === false &&
208
+					self::has_cat_right(self::CAT_ACL_STATUS, $cat_id, $this->user) === false &&
209 209
 					(!$old_event || $old_event['start'] != $event['start'] || $old_event['end'] != $event['end']))
210 210
 				{
211
-					foreach((array)$event['participants'] as $uid => $status)
211
+					foreach ((array)$event['participants'] as $uid => $status)
212 212
 					{
213 213
 						$q = $r = null;
214
-						calendar_so::split_status($status,$q,$r);
214
+						calendar_so::split_status($status, $q, $r);
215 215
 						if ($status != 'U')
216 216
 						{
217
-							$event['participants'][$uid] = calendar_so::combine_status('U',$q,$r);
217
+							$event['participants'][$uid] = calendar_so::combine_status('U', $q, $r);
218 218
 							// todo: report reset status to user
219 219
 						}
220 220
 					}
221
-					$status_reset_to_unknown = true;	// once is enough
221
+					$status_reset_to_unknown = true; // once is enough
222 222
 				}
223 223
 			}
224 224
 			if ($removed_cats)
225 225
 			{
226
-				$messages[] = lang('Category %1 removed because of missing rights',implode(', ',$removed_cats));
226
+				$messages[] = lang('Category %1 removed because of missing rights', implode(', ', $removed_cats));
227 227
 			}
228 228
 			if ($status_reset_to_unknown)
229 229
 			{
@@ -262,30 +262,30 @@  discard block
 block discarded – undo
262 262
 		$event = $this->read($cal_id, null, $ignore_acl, 'ts', $new_event && !$event['public'] ? $this->user : null);
263 263
 		//error_log("new $cal_id=". array2string($event));
264 264
 
265
-		if($old_event['deleted'] && $event['deleted'] == null)
265
+		if ($old_event['deleted'] && $event['deleted'] == null)
266 266
 		{
267 267
 			// Restored, bring back links
268 268
 			Link::restore('calendar', $cal_id);
269 269
 		}
270 270
 		if ($this->log_file)
271 271
 		{
272
-			$this->log2file($event2save,$event,$old_event);
272
+			$this->log2file($event2save, $event, $old_event);
273 273
 		}
274 274
 		// send notifications if the event is in the future
275
-		if(!$skip_notification && $event['end'] > $this->now_su)
275
+		if (!$skip_notification && $event['end'] > $this->now_su)
276 276
 		{
277 277
 			if ($new_event)
278 278
 			{
279
-				$this->send_update(MSG_ADDED,$event['participants'],'',$event);
279
+				$this->send_update(MSG_ADDED, $event['participants'], '', $event);
280 280
 			}
281 281
 			else // update existing event
282 282
 			{
283
-				$this->check4update($event,$old_event);
283
+				$this->check4update($event, $old_event);
284 284
 			}
285 285
 		}
286 286
 
287 287
 		// notify the link-class about the update, as other apps may be subscribt to it
288
-		Link::notify_update('calendar',$cal_id,$event);
288
+		Link::notify_update('calendar', $cal_id, $event);
289 289
 
290 290
 		return $cal_id;
291 291
 	}
@@ -303,27 +303,27 @@  discard block
 block discarded – undo
303 303
 	 * @param Api\DateTime& $checked_excluding =null time until which (excluding) recurrences have been checked
304 304
 	 * @return array or events
305 305
 	 */
306
-	function conflicts(array $event, &$checked_excluding=null)
306
+	function conflicts(array $event, &$checked_excluding = null)
307 307
 	{
308 308
 		$types_with_quantity = array();
309
-		foreach($this->resources as $type => $data)
309
+		foreach ($this->resources as $type => $data)
310 310
 		{
311 311
 			if ($data['max_quantity']) $types_with_quantity[] = $type;
312 312
 		}
313 313
 		// get all NOT rejected participants and evtl. their quantity
314 314
 		$quantity = $users = array();
315
-		foreach($event['participants'] as $uid => $status)
315
+		foreach ($event['participants'] as $uid => $status)
316 316
 		{
317 317
 			$q = $role = null;
318 318
 			calendar_so::split_status($status, $q, $role);
319
-			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue;	// ignore rejected or non-participants
319
+			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue; // ignore rejected or non-participants
320 320
 
321 321
 			if ($uid < 0)	// group, check it's members too
322 322
 			{
323
-				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid,true)));
323
+				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid, true)));
324 324
 			}
325 325
 			$users[] = $uid;
326
-			if (in_array($uid[0],$types_with_quantity))
326
+			if (in_array($uid[0], $types_with_quantity))
327 327
 			{
328 328
 				$quantity[$uid] = $q;
329 329
 			}
@@ -346,58 +346,58 @@  discard block
 block discarded – undo
346 346
 		}
347 347
 		$checked = 0;
348 348
 		$start = microtime(true);
349
-		$duration = $event['end']-$event['start'];
350
-		foreach($recurences as $date)
349
+		$duration = $event['end'] - $event['start'];
350
+		foreach ($recurences as $date)
351 351
 		{
352 352
 			$startts = $date->format('ts');
353 353
 
354 354
 			// skip past events or recurrences
355
-			if ($startts+$duration < $this->now_su) continue;
355
+			if ($startts + $duration < $this->now_su) continue;
356 356
 
357 357
 			// abort check if configured limits are exceeded
358 358
 			if ($event['recur_type'] &&
359 359
 				(++$checked > $max_checked && $max_checked > 0 || // maximum number of checked recurrences exceeded
360
-				microtime(true) > $start+$max_check_time ||	// max check time exceeded
360
+				microtime(true) > $start + $max_check_time || // max check time exceeded
361 361
 				$startts > $this->config['horizont']))	// we are behind horizon for which recurrences are rendered
362 362
 			{
363 363
 				if ($this->debug > 2 || $this->debug == 'conflicts')
364 364
 				{
365 365
 					$this->debug_message(__METHOD__.'() conflict check limited to %1 recurrences, %2 seconds, until (excluding) %3',
366
-						$checked, microtime(true)-$start, $date);
366
+						$checked, microtime(true) - $start, $date);
367 367
 				}
368 368
 				$checked_excluding = $date;
369 369
 				break;
370 370
 			}
371
-			$overlapping_events =& $this->search(array(
371
+			$overlapping_events = & $this->search(array(
372 372
 				'start' => $startts,
373
-				'end'   => $startts+$duration,
373
+				'end'   => $startts + $duration,
374 374
 				'users' => $users,
375
-				'ignore_acl' => true,	// otherwise we get only events readable by the user
376
-				'enum_groups' => true,	// otherwise group-events would not block time
375
+				'ignore_acl' => true, // otherwise we get only events readable by the user
376
+				'enum_groups' => true, // otherwise group-events would not block time
377 377
 				'query' => array(
378 378
 					'cal_non_blocking' => 0,
379 379
 				),
380
-				'no_integration' => true,	// do NOT use integration of other apps
380
+				'no_integration' => true, // do NOT use integration of other apps
381 381
 			));
382 382
 			if ($this->debug > 2 || $this->debug == 'conflicts')
383 383
 			{
384
-				$this->debug_message(__METHOD__.'() checking for potential overlapping events for users %1 from %2 to %3',false,$users,$startts,$startts+$duration);
384
+				$this->debug_message(__METHOD__.'() checking for potential overlapping events for users %1 from %2 to %3', false, $users, $startts, $startts + $duration);
385 385
 			}
386
-			foreach((array) $overlapping_events as $k => $overlap)
386
+			foreach ((array)$overlapping_events as $k => $overlap)
387 387
 			{
388
-				if ($overlap['id'] == $event['id'] ||	// that's the event itself
389
-					$overlap['id'] == $event['reference'] ||	// event is an exception of overlap
388
+				if ($overlap['id'] == $event['id'] || // that's the event itself
389
+					$overlap['id'] == $event['reference'] || // event is an exception of overlap
390 390
 					$overlap['non_blocking'])			// that's a non_blocking event
391 391
 				{
392 392
 					continue;
393 393
 				}
394 394
 				if ($this->debug > 3 || $this->debug == 'conflicts')
395 395
 				{
396
-					$this->debug_message(__METHOD__.'() checking overlapping event %1',false,$overlap);
396
+					$this->debug_message(__METHOD__.'() checking overlapping event %1', false, $overlap);
397 397
 				}
398 398
 				// check if the overlap is with a rejected participant or within the allowed quantity
399
-				$common_parts = array_intersect($users,array_keys($overlap['participants']));
400
-				foreach($common_parts as $n => $uid)
399
+				$common_parts = array_intersect($users, array_keys($overlap['participants']));
400
+				foreach ($common_parts as $n => $uid)
401 401
 				{
402 402
 					$status = $overlap['participants'][$uid];
403 403
 					calendar_so::split_status($status, $q, $role);
@@ -406,9 +406,9 @@  discard block
 block discarded – undo
406 406
 						unset($common_parts[$n]);
407 407
 						continue;
408 408
 					}
409
-					if (is_numeric($uid) || !in_array($uid[0],$types_with_quantity))
409
+					if (is_numeric($uid) || !in_array($uid[0], $types_with_quantity))
410 410
 					{
411
-						continue;	// no quantity check: quantity allways 1 ==> conflict
411
+						continue; // no quantity check: quantity allways 1 ==> conflict
412 412
 					}
413 413
 					if (!isset($max_quantity[$uid]))
414 414
 					{
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 					$quantity[$uid] += $q;
419 419
 					if ($quantity[$uid] <= $max_quantity[$uid])
420 420
 					{
421
-						$possible_quantity_conflicts[$uid][] =& $overlapping_events[$k];	// an other event can give the conflict
421
+						$possible_quantity_conflicts[$uid][] = & $overlapping_events[$k]; // an other event can give the conflict
422 422
 						unset($common_parts[$n]);
423 423
 						continue;
424 424
 					}
@@ -428,22 +428,22 @@  discard block
 block discarded – undo
428 428
 				{
429 429
 					if ($this->debug > 3 || $this->debug == 'conflicts')
430 430
 					{
431
-						$this->debug_message(__METHOD__.'() conflicts with the following participants found %1',false,$common_parts);
431
+						$this->debug_message(__METHOD__.'() conflicts with the following participants found %1', false, $common_parts);
432 432
 					}
433
-					$conflicts[$overlap['id'].'-'.$this->date2ts($overlap['start'])] =& $overlapping_events[$k];
433
+					$conflicts[$overlap['id'].'-'.$this->date2ts($overlap['start'])] = & $overlapping_events[$k];
434 434
 				}
435 435
 			}
436 436
 		}
437 437
 		//error_log(__METHOD__."() conflict check took ".number_format(microtime(true)-$start, 3).'s');
438 438
 		// check if we are withing the allowed quantity and if not add all events using that resource
439 439
 		// seems this function is doing very strange things, it gives empty conflicts
440
-		foreach($max_quantity as $uid => $max)
440
+		foreach ($max_quantity as $uid => $max)
441 441
 		{
442 442
 			if ($quantity[$uid] > $max)
443 443
 			{
444
-				foreach((array)$possible_quantity_conflicts[$uid] as $conflict)
444
+				foreach ((array)$possible_quantity_conflicts[$uid] as $conflict)
445 445
 				{
446
-					$conflicts[$conflict['id'].'-'.$this->date2ts($conflict['start'])] =& $possible_quantity_conflicts[$k];
446
+					$conflicts[$conflict['id'].'-'.$this->date2ts($conflict['start'])] = & $possible_quantity_conflicts[$k];
447 447
 				}
448 448
 			}
449 449
 		}
@@ -451,10 +451,10 @@  discard block
 block discarded – undo
451 451
 
452 452
 		if (count($conflicts))
453 453
 		{
454
-			foreach($conflicts as $key => $conflict)
454
+			foreach ($conflicts as $key => $conflict)
455 455
 			{
456
-					$conflict['participants'] = array_intersect_key((array)$conflict['participants'],$event['participants']);
457
-				if (!$this->check_perms(Acl::READ,$conflict))
456
+					$conflict['participants'] = array_intersect_key((array)$conflict['participants'], $event['participants']);
457
+				if (!$this->check_perms(Acl::READ, $conflict))
458 458
 				{
459 459
 					$conflicts[$key] = array(
460 460
 						'id'    => $conflict['id'],
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 			}
468 468
 			if ($this->debug > 2 || $this->debug == 'conflicts')
469 469
 			{
470
-				$this->debug_message(__METHOD__.'() %1 conflicts found %2',false,count($conflicts),$conflicts);
470
+				$this->debug_message(__METHOD__.'() %1 conflicts found %2', false, count($conflicts), $conflicts);
471 471
 			}
472 472
 		}
473 473
 		return $conflicts;
@@ -479,22 +479,22 @@  discard block
 block discarded – undo
479 479
 	 * @param array $old_event =null old event with already invited participants
480 480
 	 * @return array removed participants because of missing invite grants
481 481
 	 */
482
-	public function remove_no_acl_invite(array &$event,array $old_event=null)
482
+	public function remove_no_acl_invite(array &$event, array $old_event = null)
483 483
 	{
484 484
 		if (!$this->require_acl_invite)
485 485
 		{
486
-			return array();	// nothing to check, everyone can invite everyone else
486
+			return array(); // nothing to check, everyone can invite everyone else
487 487
 		}
488 488
 		if ($event['id'] && is_null($old_event))
489 489
 		{
490 490
 			$old_event = $this->read($event['id']);
491 491
 		}
492 492
 		$removed = array();
493
-		foreach(array_keys((array)$event['participants']) as $uid)
493
+		foreach (array_keys((array)$event['participants']) as $uid)
494 494
 		{
495 495
 			if ((is_null($old_event) || !isset($old_event['participants'][$uid])) && !$this->check_acl_invite($uid))
496 496
 			{
497
-				unset($event['participants'][$uid]);	// remove participant
497
+				unset($event['participants'][$uid]); // remove participant
498 498
 				$removed[] = $uid;
499 499
 			}
500 500
 		}
@@ -517,15 +517,15 @@  discard block
 block discarded – undo
517 517
 		}
518 518
 		elseif (!$this->require_acl_invite)
519 519
 		{
520
-			$ret = true;	// no grant required
520
+			$ret = true; // no grant required
521 521
 		}
522 522
 		elseif ($this->require_acl_invite == 'groups' && $GLOBALS['egw']->accounts->get_type($uid) != 'g')
523 523
 		{
524
-			$ret = true;	// grant only required for groups
524
+			$ret = true; // grant only required for groups
525 525
 		}
526 526
 		else
527 527
 		{
528
-			$ret = $this->check_perms(self::ACL_INVITE,0,$uid);
528
+			$ret = $this->check_perms(self::ACL_INVITE, 0, $uid);
529 529
 		}
530 530
 		//error_log(__METHOD__."($uid) = ".array2string($ret));
531 531
 		//echo "<p>".__METHOD__."($uid) require_acl_invite=$this->require_acl_invite returning ".array2string($ret)."</p>\n";
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 	 * @param array $old_event the event before the update
540 540
 	 * @todo check if there is a real change, not assume every save is a change
541 541
 	 */
542
-	function check4update($new_event,$old_event)
542
+	function check4update($new_event, $old_event)
543 543
 	{
544 544
 		//error_log(__METHOD__."($new_event[title])");
545 545
 		$modified = $added = $deleted = array();
@@ -547,9 +547,9 @@  discard block
 block discarded – undo
547 547
 		//echo "<p>calendar_boupdate::check4update() new participants = ".print_r($new_event['participants'],true).", old participants =".print_r($old_event['participants'],true)."</p>\n";
548 548
 
549 549
 		// Find modified and deleted participants ...
550
-		foreach($old_event['participants'] as $old_userid => $old_status)
550
+		foreach ($old_event['participants'] as $old_userid => $old_status)
551 551
 		{
552
-			if(isset($new_event['participants'][$old_userid]))
552
+			if (isset($new_event['participants'][$old_userid]))
553 553
 			{
554 554
 				$modified[$old_userid] = $new_event['participants'][$old_userid];
555 555
 			}
@@ -559,27 +559,27 @@  discard block
 block discarded – undo
559 559
 			}
560 560
 		}
561 561
 		// Find new participants ...
562
-		foreach(array_keys((array)$new_event['participants']) as $new_userid)
562
+		foreach (array_keys((array)$new_event['participants']) as $new_userid)
563 563
 		{
564
-			if(!isset($old_event['participants'][$new_userid]))
564
+			if (!isset($old_event['participants'][$new_userid]))
565 565
 			{
566 566
 				$added[$new_userid] = 'U';
567 567
 			}
568 568
 		}
569 569
 		//echo "<p>calendar_boupdate::check4update() added=".print_r($added,true).", modified=".print_r($modified,true).", deleted=".print_r($deleted,true)."</p>\n";
570
-		if(count($added) || count($modified) || count($deleted))
570
+		if (count($added) || count($modified) || count($deleted))
571 571
 		{
572
-			if(count($added))
572
+			if (count($added))
573 573
 			{
574
-				$this->send_update(MSG_ADDED,$added,$old_event,$new_event);
574
+				$this->send_update(MSG_ADDED, $added, $old_event, $new_event);
575 575
 			}
576
-			if(count($modified))
576
+			if (count($modified))
577 577
 			{
578
-				$this->send_update(MSG_MODIFIED,$modified,$old_event,$new_event);
578
+				$this->send_update(MSG_MODIFIED, $modified, $old_event, $new_event);
579 579
 			}
580
-			if(count($deleted))
580
+			if (count($deleted))
581 581
 			{
582
-				$this->send_update(MSG_DISINVITE,$deleted,$new_event);
582
+				$this->send_update(MSG_DISINVITE, $deleted, $new_event);
583 583
 			}
584 584
 		}
585 585
 	}
@@ -596,11 +596,11 @@  discard block
 block discarded – undo
596 596
 	 * @param string $status of current user
597 597
 	 * @return boolean true = update requested, false otherwise
598 598
 	 */
599
-	public static function update_requested($userid, $part_prefs, &$msg_type, $old_event ,$new_event, $role, $status=null)
599
+	public static function update_requested($userid, $part_prefs, &$msg_type, $old_event, $new_event, $role, $status = null)
600 600
 	{
601 601
 		if ($msg_type == MSG_ALARM)
602 602
 		{
603
-			return True;	// always True for now
603
+			return True; // always True for now
604 604
 		}
605 605
 		$want_update = 0;
606 606
 
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 		$msg_is_response = $msg_type == MSG_REJECTED || $msg_type == MSG_ACCEPTED || $msg_type == MSG_TENTATIVE || $msg_type == MSG_DELEGATED;
610 610
 
611 611
 		// Check if user is not participating, and does not want notifications
612
-		if($msg_is_response && !$part_prefs['calendar']['receive_not_participating'] && !array_key_exists($userid, $old_event['participants']))
612
+		if ($msg_is_response && !$part_prefs['calendar']['receive_not_participating'] && !array_key_exists($userid, $old_event['participants']))
613 613
 		{
614 614
 			return false;
615 615
 		}
@@ -619,13 +619,13 @@  discard block
 block discarded – undo
619 619
 		if (!is_numeric($userid) && $role == 'CHAIR' &&
620 620
 			($msg_is_response || in_array($msg_type, array(MSG_ADDED, MSG_DELETED))))
621 621
 		{
622
-			switch($msg_type)
622
+			switch ($msg_type)
623 623
 			{
624 624
 				case MSG_DELETED:	// treat deleting event as rejection to organizer
625 625
 					$msg_type = MSG_REJECTED;
626 626
 					break;
627 627
 				case MSG_ADDED:		// new events use added, but organizer needs status
628
-					switch($status[0])
628
+					switch ($status[0])
629 629
 					{
630 630
 						case 'A': $msg_type = MSG_ACCEPTED; break;
631 631
 						case 'R': $msg_type = MSG_REJECTED; break;
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 		}
639 639
 		else
640 640
 		{
641
-			switch($ru = $part_prefs['calendar']['receive_updates'])
641
+			switch ($ru = $part_prefs['calendar']['receive_updates'])
642 642
 			{
643 643
 				case 'responses':
644 644
 					++$want_update;
@@ -652,8 +652,8 @@  discard block
 block discarded – undo
652 652
 				default:
653 653
 					if (is_array($new_event) && is_array($old_event))
654 654
 					{
655
-						$diff = max(abs(self::date2ts($old_event['start'])-self::date2ts($new_event['start'])),
656
-							abs(self::date2ts($old_event['end'])-self::date2ts($new_event['end'])));
655
+						$diff = max(abs(self::date2ts($old_event['start']) - self::date2ts($new_event['start'])),
656
+							abs(self::date2ts($old_event['end']) - self::date2ts($new_event['end'])));
657 657
 						$check = $ru == 'time_change_4h' ? 4 * 60 * 60 - 1 : 0;
658 658
 						if ($msg_type == MSG_MODIFIED && $diff > $check)
659 659
 						{
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 	 * @param string $role ='REQ-PARTICIPANT'
684 684
 	 * @return boolean true if user requested to be notified, false if not
685 685
 	 */
686
-	static public function email_update_requested($user_or_email, $ical_method='REQUEST', $role='REQ-PARTICIPANT')
686
+	static public function email_update_requested($user_or_email, $ical_method = 'REQUEST', $role = 'REQ-PARTICIPANT')
687 687
 	{
688 688
 		// check if email is from a user
689 689
 		if (is_numeric($user_or_email))
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 				)
708 708
 			);
709 709
 		}
710
-		switch($ical_method)
710
+		switch ($ical_method)
711 711
 		{
712 712
 			default:
713 713
 			case 'REQUEST':
@@ -732,9 +732,9 @@  discard block
 block discarded – undo
732 732
 	 * @param string& $action=null on return verbose name
733 733
 	 * @param string& $msg=null on return notification message
734 734
 	 */
735
-	function msg_type2ical_method($msg_type, &$action=null, &$msg=null, $prefs=null)
735
+	function msg_type2ical_method($msg_type, &$action = null, &$msg = null, $prefs = null)
736 736
 	{
737
-		switch($msg_type)
737
+		switch ($msg_type)
738 738
 		{
739 739
 			case MSG_DELETED:
740 740
 				$action = 'Canceled';
@@ -783,14 +783,14 @@  discard block
 block discarded – undo
783 783
 			default:
784 784
 				$method = 'PUBLISH';
785 785
 		}
786
-		if(is_null($prefs))
786
+		if (is_null($prefs))
787 787
 		{
788 788
 			$prefs = $this->cal_prefs;
789 789
 		}
790 790
 		$msg = $prefs['notify'.$pref];
791 791
 		if (empty($msg))
792 792
 		{
793
-			$msg = $prefs['notifyAdded'];	// use a default
793
+			$msg = $prefs['notifyAdded']; // use a default
794 794
 		}
795 795
 		//error_log(__METHOD__."($msg_type) action='$action', $msg='$msg' returning '$method'");
796 796
 		return $method;
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 	 * @param int/string $user =0 User/participant who started the notify, default current user
807 807
 	 * @return bool true/false
808 808
 	 */
809
-	function send_update($msg_type,$to_notify,$old_event,$new_event=null,$user=0)
809
+	function send_update($msg_type, $to_notify, $old_event, $new_event = null, $user = 0)
810 810
 	{
811 811
 		//error_log(__METHOD__."($msg_type,".array2string($to_notify).",...) ".array2string($new_event));
812 812
 		if (!is_array($to_notify))
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
 		$owner = $old_event ? $old_event['owner'] : $new_event['owner'];
819 819
 		if ($owner && !isset($to_notify[$owner]) && $msg_type != MSG_ALARM)
820 820
 		{
821
-			$to_notify[$owner] = 'OCHAIR';	// always include the event-owner
821
+			$to_notify[$owner] = 'OCHAIR'; // always include the event-owner
822 822
 		}
823 823
 
824 824
 		// ignore events in the past (give a tolerance of 10 seconds for the script)
825
-		if($old_event && $this->date2ts($old_event['start']) < ($this->now_su - 10))
825
+		if ($old_event && $this->date2ts($old_event['start']) < ($this->now_su - 10))
826 826
 		{
827 827
 			return False;
828 828
 		}
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 			$restore_tz = $tz;
833 833
 			date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
834 834
 		}
835
-		$temp_user = $GLOBALS['egw_info']['user'];	// save user-date of the enviroment to restore it after
835
+		$temp_user = $GLOBALS['egw_info']['user']; // save user-date of the enviroment to restore it after
836 836
 
837 837
 		if (!$user)
838 838
 		{
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository();
847 847
 
848 848
 			// If target user/participant is not an account, try to get good notification message
849
-			if(!is_numeric($user))
849
+			if (!is_numeric($user))
850 850
 			{
851 851
 				$res_info = $this->resource_info($user);
852 852
 				$title = $res_info['name'] ?: Link::title($res_info['app'], $res_info['res_id']) ?: $res_info['res_id'] ?: $user;
@@ -863,16 +863,16 @@  discard block
 block discarded – undo
863 863
 		$event = $msg_type == MSG_ADDED || $msg_type == MSG_MODIFIED ? $new_event : $old_event;
864 864
 
865 865
 		// add all group-members to the notification, unless they are already participants
866
-		foreach($to_notify as $userid => $statusid)
866
+		foreach ($to_notify as $userid => $statusid)
867 867
 		{
868 868
 			if (is_numeric($userid) && $GLOBALS['egw']->accounts->get_type($userid) == 'g' &&
869 869
 				($members = $GLOBALS['egw']->accounts->members($userid, true)))
870 870
 			{
871
-				foreach($members as $member)
871
+				foreach ($members as $member)
872 872
 				{
873 873
 					if (!isset($to_notify[$member]))
874 874
 					{
875
-						$to_notify[$member] = 'G';	// Group-invitation
875
+						$to_notify[$member] = 'G'; // Group-invitation
876 876
 					}
877 877
 				}
878 878
 			}
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
 		{
884 884
 			// check if we have *only* an external chair
885 885
 			$chair = null;
886
-			foreach($to_notify as $userid => $statusid)
886
+			foreach ($to_notify as $userid => $statusid)
887 887
 			{
888 888
 				$res_info = $quantity = $role = null;
889 889
 				calendar_so::split_status($statusid, $quantity, $role);
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 			// *only* an external chair --> do not notify anyone, but the external chair and the current user
896 896
 			if (!empty($chair) && !is_numeric($chair))
897 897
 			{
898
-				$to_notify = array($chair => $to_notify[$chair])+
898
+				$to_notify = array($chair => $to_notify[$chair]) +
899 899
 					(isset($to_notify[$user]) ? array($user => $to_notify[$user]) : array());
900 900
 			}
901 901
 		}
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 		if ($old_event) $olddate = new Api\DateTime($old_event['start']);
907 907
 		//error_log(__METHOD__."() date_default_timezone_get()=".date_default_timezone_get().", user-timezone=".Api\DateTime::$user_timezone->getName().", startdate=".$startdate->format().", enddate=".$enddate->format().", updated=".$modified->format().", olddate=".($olddate ? $olddate->format() : ''));
908 908
 		$owner_prefs = $ics = null;
909
-		foreach($to_notify as $userid => $statusid)
909
+		foreach ($to_notify as $userid => $statusid)
910 910
 		{
911 911
 			$res_info = $quantity = $role = null;
912 912
 			calendar_so::split_status($statusid, $quantity, $role);
@@ -929,14 +929,14 @@  discard block
 block discarded – undo
929 929
 
930 930
 				if (!isset($userid))
931 931
 				{
932
-					if (empty($res_info['email'])) continue;	// no way to notify
932
+					if (empty($res_info['email'])) continue; // no way to notify
933 933
 					// check if event-owner wants non-EGroupware users notified
934 934
 					if (is_null($owner_prefs))
935 935
 					{
936 936
 						$preferences = new Api\Preferences($owner);
937 937
 						$owner_prefs = $preferences->read_repository();
938 938
 					}
939
-					if ($role != 'CHAIR' &&		// always notify externals CHAIRs
939
+					if ($role != 'CHAIR' && // always notify externals CHAIRs
940 940
 						(empty($owner_prefs['calendar']['notify_externals']) ||
941 941
 						$owner_prefs['calendar']['notify_externals'] == 'no'))
942 942
 					{
@@ -948,12 +948,12 @@  discard block
 block discarded – undo
948 948
 
949 949
 			if ($statusid == 'R' || $GLOBALS['egw']->accounts->get_type($userid) == 'g')
950 950
 			{
951
-				continue;	// dont notify rejected participants or groups
951
+				continue; // dont notify rejected participants or groups
952 952
 			}
953 953
 
954
-			if($userid != $GLOBALS['egw_info']['user']['account_id'] ||
954
+			if ($userid != $GLOBALS['egw_info']['user']['account_id'] ||
955 955
 				($userid == $GLOBALS['egw_info']['user']['account_id'] &&
956
-					$user_prefs['calendar']['receive_own_updates']==1) ||
956
+					$user_prefs['calendar']['receive_own_updates'] == 1) ||
957 957
 				$msg_type == MSG_ALARM)
958 958
 			{
959 959
 				$tfn = $tln = $lid = null; //cleanup of lastname and fullname (in case they are set in a previous loop)
@@ -962,8 +962,8 @@  discard block
 block discarded – undo
962 962
 					$preferences = new Api\Preferences($userid);
963 963
 					$GLOBALS['egw_info']['user']['preferences'] = $part_prefs = $preferences->read_repository();
964 964
 					$fullname = Api\Accounts::username($userid);
965
-					$tfn = Api\Accounts::id2name($userid,'account_firstname');
966
-					$tln = Api\Accounts::id2name($userid,'account_lastname');
965
+					$tfn = Api\Accounts::id2name($userid, 'account_firstname');
966
+					$tln = Api\Accounts::id2name($userid, 'account_lastname');
967 967
 				}
968 968
 				else	// external email address: use Api\Preferences of event-owner, plus some hardcoded settings (eg. ical notification)
969 969
 				{
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 					}
975 975
 					$part_prefs = $owner_prefs;
976 976
 					$part_prefs['calendar']['receive_updates'] = $owner_prefs['calendar']['notify_externals'];
977
-					$part_prefs['calendar']['update_format'] = 'ical';	// use ical format
977
+					$part_prefs['calendar']['update_format'] = 'ical'; // use ical format
978 978
 					$fullname = $res_info && !empty($res_info['name']) ? $res_info['name'] : $userid;
979 979
 				}
980 980
 				$m_type = $msg_type;
@@ -999,14 +999,14 @@  discard block
 block discarded – undo
999 999
 				$details = $this->_get_event_details(isset($cleared_event) ? $cleared_event : $event,
1000 1000
 					$action, $event_arr, $disinvited);
1001 1001
 				$details['to-fullname'] = $fullname;
1002
-				$details['to-firstname'] = isset($tfn)? $tfn: '';
1003
-				$details['to-lastname'] = isset($tln)? $tln: '';
1002
+				$details['to-firstname'] = isset($tfn) ? $tfn : '';
1003
+				$details['to-lastname'] = isset($tln) ? $tln : '';
1004 1004
 
1005 1005
 				// event is in user-time of current user, now we need to calculate the tz-difference to the notified user and take it into account
1006 1006
 				if (!isset($part_prefs['common']['tz'])) $part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
1007 1007
 				$timezone = new DateTimeZone($part_prefs['common']['tz']);
1008 1008
 				$timeformat = $part_prefs['common']['timeformat'];
1009
-				switch($timeformat)
1009
+				switch ($timeformat)
1010 1010
 				{
1011 1011
 			  		case '24':
1012 1012
 						$timeformat = 'H:i';
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 						$timeformat = 'h:i a';
1016 1016
 						break;
1017 1017
 				}
1018
-				$timeformat = $part_prefs['common']['dateformat'] . ', ' . $timeformat;
1018
+				$timeformat = $part_prefs['common']['dateformat'].', '.$timeformat;
1019 1019
 
1020 1020
 				$startdate->setTimezone($timezone);
1021 1021
 				$details['startdate'] = $startdate->format($timeformat);
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
 				$details['enddate'] = $enddate->format($timeformat);
1025 1025
 
1026 1026
 				$modified->setTimezone($timezone);
1027
-				$details['updated'] = $modified->format($timeformat) . ', ' . Api\Accounts::username($event['modifier']);
1027
+				$details['updated'] = $modified->format($timeformat).', '.Api\Accounts::username($event['modifier']);
1028 1028
 
1029 1029
 				if ($old_event != False)
1030 1030
 				{
@@ -1033,15 +1033,14 @@  discard block
 block discarded – undo
1033 1033
 				}
1034 1034
 				//error_log(__METHOD__."() userid=$userid, timezone=".$timezone->getName().", startdate=$details[startdate], enddate=$details[enddate], updated=$details[updated], olddate=$details[olddate]");
1035 1035
 
1036
-				list($subject,$notify_body) = explode("\n",$GLOBALS['egw']->preferences->parse_notify($notify_msg,$details),2);
1036
+				list($subject, $notify_body) = explode("\n", $GLOBALS['egw']->preferences->parse_notify($notify_msg, $details), 2);
1037 1037
 				// alarm is NOT an iCal method, therefore we have to use extened (no iCal)
1038
-				switch($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
1038
+				switch ($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
1039 1039
 				{
1040
-					case 'ical':
1041
-						if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
1040
+					case 'ical' : if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
1042 1041
 						{
1043 1042
 							$calendar_ical = new calendar_ical();
1044
-							$calendar_ical->setSupportedFields('full');	// full iCal fields+event TZ
1043
+							$calendar_ical->setSupportedFields('full'); // full iCal fields+event TZ
1045 1044
 							// we need to pass $event[id] so iCal class reads event again,
1046 1045
 							// as event is in user TZ, but iCal class expects server TZ!
1047 1046
 							$ics = $calendar_ical->exportVCal(array(isset($cleared_event) ? $cleared_event : $event['id']),
@@ -1062,11 +1061,11 @@  discard block
 block discarded – undo
1062 1061
 					case 'extended':
1063 1062
 
1064 1063
 						$details_body = lang('Event Details follow').":\n";
1065
-						foreach($event_arr as $key => $val)
1064
+						foreach ($event_arr as $key => $val)
1066 1065
 						{
1067
-							if(!empty($details[$key]))
1066
+							if (!empty($details[$key]))
1068 1067
 							{
1069
-								switch($key)
1068
+								switch ($key)
1070 1069
 								{
1071 1070
 							 		case 'access':
1072 1071
 									case 'priority':
@@ -1075,7 +1074,7 @@  discard block
 block discarded – undo
1075 1074
 									case 'title':
1076 1075
 										break;
1077 1076
 									default:
1078
-										$details_body .= sprintf("%-20s %s\n",$val['field'].':',$details[$key]);
1077
+										$details_body .= sprintf("%-20s %s\n", $val['field'].':', $details[$key]);
1079 1078
 										break;
1080 1079
 							 	}
1081 1080
 							}
@@ -1083,7 +1082,7 @@  discard block
 block discarded – undo
1083 1082
 						break;
1084 1083
 				}
1085 1084
 				// send via notification_app
1086
-				if($GLOBALS['egw_info']['apps']['notifications']['enabled'])
1085
+				if ($GLOBALS['egw_info']['apps']['notifications']['enabled'])
1087 1086
 				{
1088 1087
 					try {
1089 1088
 						//error_log(__METHOD__."() notifying $userid from $senderid: $subject");
@@ -1105,7 +1104,7 @@  discard block
 block discarded – undo
1105 1104
 						// popup notifiactions: set subject, different message (without separator) and (always) links
1106 1105
 						$notification->set_popupsubject($subject);
1107 1106
 
1108
-						if ($method =='REQUEST')
1107
+						if ($method == 'REQUEST')
1109 1108
 						{
1110 1109
 							// Add ACCEPT|REHECT|TENTATIVE actions
1111 1110
 							$notification->set_popupdata('calendar', array(
@@ -1118,11 +1117,11 @@  discard block
 block discarded – undo
1118 1117
 						}
1119 1118
 						if ($m_type === MSG_ALARM) $notification->set_popupdata('calendar', array('egw_pr_notify' => 1, 'type' => $m_type));
1120 1119
 						$notification->set_popupmessage($subject."\n\n".$notify_body."\n\n".$details['description']."\n\n".$details_body."\n\n");
1121
-						$notification->set_popuplinks(array($details['link_arr']+array('app'=>'calendar')));
1120
+						$notification->set_popuplinks(array($details['link_arr'] + array('app'=>'calendar')));
1122 1121
 
1123
-						if(is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1122
+						if (is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1124 1123
 						$notification->send();
1125
-						foreach(notifications::errors(true) as $error)
1124
+						foreach (notifications::errors(true) as $error)
1126 1125
 						{
1127 1126
 							error_log(__METHOD__."() Error notifying $userid from $senderid: $subject: $error");
1128 1127
 						}
@@ -1161,14 +1160,14 @@  discard block
 block discarded – undo
1161 1160
 		return true;
1162 1161
 	}
1163 1162
 
1164
-	function get_update_message($event,$added)
1163
+	function get_update_message($event, $added)
1165 1164
 	{
1166 1165
 		$nul = null;
1167
-		$details = $this->_get_event_details($event,$added ? lang('Added') : lang('Modified'),$nul);
1166
+		$details = $this->_get_event_details($event, $added ? lang('Added') : lang('Modified'), $nul);
1168 1167
 
1169 1168
 		$notify_msg = $this->cal_prefs[$added || empty($this->cal_prefs['notifyModified']) ? 'notifyAdded' : 'notifyModified'];
1170 1169
 
1171
-		return explode("\n",$GLOBALS['egw']->preferences->parse_notify($notify_msg,$details),2);
1170
+		return explode("\n", $GLOBALS['egw']->preferences->parse_notify($notify_msg, $details), 2);
1172 1171
 	}
1173 1172
 
1174 1173
 	/**
@@ -1182,38 +1181,38 @@  discard block
 block discarded – undo
1182 1181
 		//echo "<p>bocalendar::send_alarm("; print_r($alarm); echo ")</p>\n";
1183 1182
 		$GLOBALS['egw_info']['user']['account_id'] = $this->owner = $alarm['owner'];
1184 1183
 
1185
-		$event_time_user = Api\DateTime::server2user($alarm['time'] + $alarm['offset']);	// alarm[time] is in server-time, read requires user-time
1186
-		if (!$alarm['owner'] || !$alarm['cal_id'] || !($event = $this->read($alarm['cal_id'],$event_time_user)))
1184
+		$event_time_user = Api\DateTime::server2user($alarm['time'] + $alarm['offset']); // alarm[time] is in server-time, read requires user-time
1185
+		if (!$alarm['owner'] || !$alarm['cal_id'] || !($event = $this->read($alarm['cal_id'], $event_time_user)))
1187 1186
 		{
1188
-			return False;	// event not found
1187
+			return False; // event not found
1189 1188
 		}
1190 1189
 		if ($alarm['all'])
1191 1190
 		{
1192 1191
 			$to_notify = $event['participants'];
1193 1192
 		}
1194
-		elseif ($this->check_perms(Acl::READ,$event))	// checks agains $this->owner set to $alarm[owner]
1193
+		elseif ($this->check_perms(Acl::READ, $event))	// checks agains $this->owner set to $alarm[owner]
1195 1194
 		{
1196 1195
 			$to_notify[$alarm['owner']] = 'A';
1197 1196
 		}
1198 1197
 		else
1199 1198
 		{
1200
-			return False;	// no rights
1199
+			return False; // no rights
1201 1200
 		}
1202 1201
 		// need to load calendar translations and set currentapp, so calendar can reload a different lang
1203 1202
 		Api\Translation::add_app('calendar');
1204 1203
 		$GLOBALS['egw_info']['flags']['currentapp'] = 'calendar';
1205 1204
 
1206
-		$ret = $this->send_update(MSG_ALARM,$to_notify,$event,False,$alarm['owner']);
1205
+		$ret = $this->send_update(MSG_ALARM, $to_notify, $event, False, $alarm['owner']);
1207 1206
 
1208 1207
 		// create a new alarm for recuring events for the next event, if one exists
1209
-		if ($event['recur_type'] != MCAL_RECUR_NONE && ($event = $this->read($alarm['cal_id'],$event_time_user+1)))
1208
+		if ($event['recur_type'] != MCAL_RECUR_NONE && ($event = $this->read($alarm['cal_id'], $event_time_user + 1)))
1210 1209
 		{
1211 1210
 			$alarm['time'] = $this->date2ts($event['start']) - $alarm['offset'];
1212 1211
 			unset($alarm['times']);
1213 1212
 			unset($alarm['next']);
1214
-			unset($alarm['keep_time']);	// need to remove the keep_time, as otherwise the alarm would be deleted automatically
1213
+			unset($alarm['keep_time']); // need to remove the keep_time, as otherwise the alarm would be deleted automatically
1215 1214
 			//error_log(__METHOD__."() moving alarm to next recurrence ".array2string($alarm));
1216
-			$this->save_alarm($alarm['cal_id'], $alarm, false);	// false = do NOT update timestamp, as nothing changed for iCal clients
1215
+			$this->save_alarm($alarm['cal_id'], $alarm, false); // false = do NOT update timestamp, as nothing changed for iCal clients
1217 1216
 		}
1218 1217
 		return $ret;
1219 1218
 	}
@@ -1229,14 +1228,14 @@  discard block
 block discarded – undo
1229 1228
 	 * Please note: you should ALLWAYS update timestamps, as they are required for sync!
1230 1229
 	 * @return int|boolean $cal_id > 0 or false on error (eg. permission denied)
1231 1230
 	 */
1232
-	function save($event,$ignore_acl=false,$updateTS=true)
1231
+	function save($event, $ignore_acl = false, $updateTS = true)
1233 1232
 	{
1234 1233
 		//error_log(__METHOD__.'('.array2string($event).", $ignore_acl, $updateTS)");
1235 1234
 
1236 1235
 		// check if user has the permission to update / create the event
1237
-		if (!$ignore_acl && ($event['id'] && !$this->check_perms(Acl::EDIT,$event['id']) ||
1238
-			!$event['id'] && !$this->check_perms(Acl::EDIT,0,$event['owner']) &&
1239
-			!$this->check_perms(Acl::ADD,0,$event['owner'])))
1236
+		if (!$ignore_acl && ($event['id'] && !$this->check_perms(Acl::EDIT, $event['id']) ||
1237
+			!$event['id'] && !$this->check_perms(Acl::EDIT, 0, $event['owner']) &&
1238
+			!$this->check_perms(Acl::ADD, 0, $event['owner'])))
1240 1239
 		{
1241 1240
 			return false;
1242 1241
 		}
@@ -1257,7 +1256,7 @@  discard block
 block discarded – undo
1257 1256
 		if ($event['recur_type'] != MCAL_RECUR_NONE && $event['recur_enddate'] && $event['start'])
1258 1257
 		{
1259 1258
 			$event['recur_enddate'] = new Api\DateTime($event['recur_enddate'], calendar_timezones::DateTimeZone($event['tzid']));
1260
-			$event['recur_enddate']->setTime(23,59,59);
1259
+			$event['recur_enddate']->setTime(23, 59, 59);
1261 1260
 			$rrule = calendar_rrule::event2rrule($event, true, Api\DateTime::$user_timezone->getName());
1262 1261
 			$rrule->rewind();
1263 1262
 			$enddate = $rrule->current();
@@ -1316,19 +1315,19 @@  discard block
 block discarded – undo
1316 1315
 
1317 1316
 				$event['recur_enddate'] = $save_event['recur_enddate'] = $time;
1318 1317
 			}
1319
-			$timestamps = array('modified','created');
1318
+			$timestamps = array('modified', 'created');
1320 1319
 			// all-day events are handled in server time
1321 1320
 		//	$event['tzid'] = $save_event['tzid'] = Api\DateTime::$server_timezone->getName();
1322 1321
 		}
1323 1322
 		else
1324 1323
 		{
1325
-			$timestamps = array('start','end','modified','created','recur_enddate','recurrence');
1324
+			$timestamps = array('start', 'end', 'modified', 'created', 'recur_enddate', 'recurrence');
1326 1325
 		}
1327 1326
 		// we run all dates through date2ts, to adjust to server-time and the possible date-formats
1328
-		foreach($timestamps as $ts)
1327
+		foreach ($timestamps as $ts)
1329 1328
 		{
1330 1329
 			// we convert here from user-time to timestamps in server-time!
1331
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1330
+			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts], true) : 0;
1332 1331
 		}
1333 1332
 		// convert tzid name to integer tz_id, of set user default
1334 1333
 		if (empty($event['tzid']) || !($event['tz_id'] = calendar_timezones::tz2id($event['tzid'])))
@@ -1338,7 +1337,7 @@  discard block
 block discarded – undo
1338 1337
 		// same with the recur exceptions
1339 1338
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
1340 1339
 		{
1341
-			foreach($event['recur_exception'] as &$date)
1340
+			foreach ($event['recur_exception'] as &$date)
1342 1341
 			{
1343 1342
 				if ($event['whole_day'])
1344 1343
 				{
@@ -1347,7 +1346,7 @@  discard block
 block discarded – undo
1347 1346
 				}
1348 1347
 				else
1349 1348
 				{
1350
-					$date = $this->date2ts($date,true);
1349
+					$date = $this->date2ts($date, true);
1351 1350
 				}
1352 1351
 			}
1353 1352
 			unset($date);
@@ -1358,13 +1357,13 @@  discard block
 block discarded – undo
1358 1357
 			// Expand group invitations so we don't lose individual alarms
1359 1358
 			$expanded = $event;
1360 1359
 			$this->enum_groups($expanded);
1361
-			foreach($event['alarm'] as $id => &$alarm)
1360
+			foreach ($event['alarm'] as $id => &$alarm)
1362 1361
 			{
1363 1362
 				// remove alarms belonging to not longer existing or rejected participants
1364 1363
 				if ($alarm['owner'] && isset($expanded['participants']))
1365 1364
 				{
1366 1365
 					// Don't auto-delete alarm if for all users
1367
-					if($alarm['all']) continue;
1366
+					if ($alarm['all']) continue;
1368 1367
 
1369 1368
 					$status = $expanded['participants'][$alarm['owner']];
1370 1369
 					if (!isset($status) || calendar_so::split_status($status) === 'R')
@@ -1374,21 +1373,20 @@  discard block
 block discarded – undo
1374 1373
 						//error_log(__LINE__.': '.__METHOD__."(".array2string($event).") deleting alarm=".array2string($alarm).", $status=".array2string($alarm));
1375 1374
 					}
1376 1375
 				}
1377
-				$alarm['time'] = $this->date2ts($alarm['time'],true);	// user to server-time
1376
+				$alarm['time'] = $this->date2ts($alarm['time'], true); // user to server-time
1378 1377
 			}
1379 1378
 		}
1380 1379
 		// update all existing alarm times, in case alarm got moved and alarms are not include in $event
1381 1380
 		if ($old_event && is_array($old_event['alarm']) && isset($event['start']))
1382 1381
 		{
1383
-			foreach($old_event['alarm'] as $id => &$alarm)
1382
+			foreach ($old_event['alarm'] as $id => &$alarm)
1384 1383
 			{
1385 1384
 				if (!isset($event['alarm'][$id]))
1386 1385
 				{
1387 1386
 					$alarm['time'] = $event['start'] - $alarm['offset'];
1388 1387
 					if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
1389 1388
 						// remove (not store) alarms belonging to not longer existing or rejected participants
1390
-					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] :
1391
-						$old_event['participants'][$alarm['owner']];
1389
+					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] : $old_event['participants'][$alarm['owner']];
1392 1390
 					if (!$alarm['owner'] || isset($status) && calendar_so::split_status($status) !== 'R')
1393 1391
 					{
1394 1392
 						$this->so->save_alarm($event['id'], $alarm);
@@ -1417,7 +1415,7 @@  discard block
 block discarded – undo
1417 1415
 		}
1418 1416
 		$set_recurrences = $old_event ? abs($event['recur_enddate'] - $old_event['recur_enddate']) > 1 : false;
1419 1417
 		$set_recurrences_start = 0;
1420
-		if (($cal_id = $this->so->save($event,$set_recurrences,$set_recurrences_start,0,$event['etag'])) && $set_recurrences && $event['recur_type'] != MCAL_RECUR_NONE)
1418
+		if (($cal_id = $this->so->save($event, $set_recurrences, $set_recurrences_start, 0, $event['etag'])) && $set_recurrences && $event['recur_type'] != MCAL_RECUR_NONE)
1421 1419
 		{
1422 1420
 			$save_event['id'] = $cal_id;
1423 1421
 			// unset participants to enforce the default stati for all added recurrences
@@ -1428,7 +1426,7 @@  discard block
 block discarded – undo
1428 1426
 		// create links for new participants from addressbook, if configured
1429 1427
 		if ($cal_id && $GLOBALS['egw_info']['server']['link_contacts'] && $event['participants'])
1430 1428
 		{
1431
-			foreach($event['participants'] as $uid => $status)
1429
+			foreach ($event['participants'] as $uid => $status)
1432 1430
 			{
1433 1431
 				$user_type = $user_id = null;
1434 1432
 				calendar_so::split_user($uid, $user_type, $user_id);
@@ -1441,7 +1439,7 @@  discard block
 block discarded – undo
1441 1439
 
1442 1440
 		// Update history
1443 1441
 		$tracking = new calendar_tracking($this);
1444
-		if (empty($event['id']) && !empty($cal_id)) $event['id']=$cal_id;
1442
+		if (empty($event['id']) && !empty($cal_id)) $event['id'] = $cal_id;
1445 1443
 		$tracking->track($save_event, $old_event);
1446 1444
 
1447 1445
 		return $cal_id;
@@ -1456,16 +1454,16 @@  discard block
 block discarded – undo
1456 1454
 	 * @param array|int $event event array or id of the event
1457 1455
 	 * @return boolean
1458 1456
 	 */
1459
-	function check_status_perms($uid,$event)
1457
+	function check_status_perms($uid, $event)
1460 1458
 	{
1461 1459
 		if ($uid[0] == 'c' || $uid[0] == 'e')	// for contact we use the owner of the event
1462 1460
 		{
1463 1461
 			if (!is_array($event) && !($event = $this->read($event))) return false;
1464 1462
 
1465
-			return $this->check_perms(Acl::EDIT,0,$event['owner']);
1463
+			return $this->check_perms(Acl::EDIT, 0, $event['owner']);
1466 1464
 		}
1467 1465
 		// check if we have a category Acl for the event or not (null)
1468
-		$access = $this->check_cat_acl(self::CAT_ACL_STATUS,$event);
1466
+		$access = $this->check_cat_acl(self::CAT_ACL_STATUS, $event);
1469 1467
 		if (!is_null($access))
1470 1468
 		{
1471 1469
 			return $access;
@@ -1482,10 +1480,10 @@  discard block
 block discarded – undo
1482 1480
 		// regular user and groups (need to check memberships too)
1483 1481
 		if (!isset($event['participants'][$uid]))
1484 1482
 		{
1485
-			$memberships = $GLOBALS['egw']->accounts->memberships($uid,true);
1483
+			$memberships = $GLOBALS['egw']->accounts->memberships($uid, true);
1486 1484
 		}
1487 1485
 		$memberships[] = $uid;
1488
-		return array_intersect($memberships, array_keys($event['participants'])) && $this->check_perms(Acl::EDIT,0,$uid);
1486
+		return array_intersect($memberships, array_keys($event['participants'])) && $this->check_perms(Acl::EDIT, 0, $uid);
1489 1487
 	}
1490 1488
 
1491 1489
 	/**
@@ -1499,16 +1497,16 @@  discard block
 block discarded – undo
1499 1497
 	 * @return boolean false=access denied because of cat acl, true access granted because of cat acl,
1500 1498
 	 * 	null = cat has no acl
1501 1499
 	 */
1502
-	function check_cat_acl($right,$event)
1500
+	function check_cat_acl($right, $event)
1503 1501
 	{
1504 1502
 		if (!is_array($event)) $event = $this->read($event);
1505 1503
 
1506 1504
 		$ret = null;
1507 1505
 		if ($event['category'])
1508 1506
 		{
1509
-			foreach(is_array($event['category']) ? $event['category'] : explode(',',$event['category']) as $cat_id)
1507
+			foreach (is_array($event['category']) ? $event['category'] : explode(',', $event['category']) as $cat_id)
1510 1508
 			{
1511
-				$access = self::has_cat_right($right,$cat_id,$this->user);
1509
+				$access = self::has_cat_right($right, $cat_id, $this->user);
1512 1510
 				if ($access === true)
1513 1511
 				{
1514 1512
 					$ret = true;
@@ -1516,7 +1514,7 @@  discard block
 block discarded – undo
1516 1514
 				}
1517 1515
 				if ($access === false)
1518 1516
 				{
1519
-					$ret = false;	// cat denies access --> check further cats
1517
+					$ret = false; // cat denies access --> check further cats
1520 1518
 				}
1521 1519
 			}
1522 1520
 		}
@@ -1537,12 +1535,12 @@  discard block
 block discarded – undo
1537 1535
 	 * @param int $cat_id =null null to return array with all cats
1538 1536
 	 * @return array with account_id => right pairs
1539 1537
 	 */
1540
-	public static function get_cat_rights($cat_id=null)
1538
+	public static function get_cat_rights($cat_id = null)
1541 1539
 	{
1542 1540
 		if (!isset(self::$cat_rights_cache))
1543 1541
 		{
1544
-			self::$cat_rights_cache = Api\Cache::getSession('calendar','cat_rights',
1545
-				array($GLOBALS['egw']->acl,'get_location_grants'),array('L%','calendar'));
1542
+			self::$cat_rights_cache = Api\Cache::getSession('calendar', 'cat_rights',
1543
+				array($GLOBALS['egw']->acl, 'get_location_grants'), array('L%', 'calendar'));
1546 1544
 		}
1547 1545
 		//echo "<p>".__METHOD__."($cat_id) = ".array2string($cat_id ? self::$cat_rights_cache['L'.$cat_id] : self::$cat_rights_cache)."</p>\n";
1548 1546
 		return $cat_id ? self::$cat_rights_cache['L'.$cat_id] : self::$cat_rights_cache;
@@ -1555,7 +1553,7 @@  discard block
 block discarded – undo
1555 1553
 	 * @param int $user
1556 1554
 	 * @param int $rights self::CAT_ACL_{ADD|STATUS} or'ed together
1557 1555
 	 */
1558
-	public static function set_cat_rights($cat_id,$user,$rights)
1556
+	public static function set_cat_rights($cat_id, $user, $rights)
1559 1557
 	{
1560 1558
 		//echo "<p>".__METHOD__."($cat_id,$user,$rights)</p>\n";
1561 1559
 		if (!isset(self::$cat_rights_cache)) self::get_cat_rights($cat_id);
@@ -1565,15 +1563,15 @@  discard block
 block discarded – undo
1565 1563
 			if ($rights)
1566 1564
 			{
1567 1565
 				self::$cat_rights_cache['L'.$cat_id][$user] = $rights;
1568
-				$GLOBALS['egw']->acl->add_repository('calendar','L'.$cat_id,$user,$rights);
1566
+				$GLOBALS['egw']->acl->add_repository('calendar', 'L'.$cat_id, $user, $rights);
1569 1567
 			}
1570 1568
 			else
1571 1569
 			{
1572 1570
 				unset(self::$cat_rights_cache['L'.$cat_id][$user]);
1573 1571
 				if (!self::$cat_rights_cache['L'.$cat_id]) unset(self::$cat_rights_cache['L'.$cat_id]);
1574
-				$GLOBALS['egw']->acl->delete_repository('calendar','L'.$cat_id,$user);
1572
+				$GLOBALS['egw']->acl->delete_repository('calendar', 'L'.$cat_id, $user);
1575 1573
 			}
1576
-			Api\Cache::setSession('calendar','cat_rights',self::$cat_rights_cache);
1574
+			Api\Cache::setSession('calendar', 'cat_rights', self::$cat_rights_cache);
1577 1575
 		}
1578 1576
 	}
1579 1577
 
@@ -1584,9 +1582,9 @@  discard block
 block discarded – undo
1584 1582
 	 * @return boolean false=access denied because of cat acl, true access granted because of cat acl,
1585 1583
 	 * 	null = cat has no acl
1586 1584
 	 */
1587
-	public static function has_cat_right($right,$cat_id,$user)
1585
+	public static function has_cat_right($right, $cat_id, $user)
1588 1586
 	{
1589
-		static $cache=null;
1587
+		static $cache = null;
1590 1588
 
1591 1589
 		if (!isset($cache[$cat_id]))
1592 1590
 		{
@@ -1594,21 +1592,21 @@  discard block
 block discarded – undo
1594 1592
 			$cat_rights = self::get_cat_rights($cat_id);
1595 1593
 			if (!is_null($cat_rights))
1596 1594
 			{
1597
-				static $memberships=null;
1595
+				static $memberships = null;
1598 1596
 				if (is_null($memberships))
1599 1597
 				{
1600
-					$memberships = $GLOBALS['egw']->accounts->memberships($user,true);
1598
+					$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1601 1599
 					$memberships[] = $user;
1602 1600
 				}
1603
-				foreach($cat_rights as $uid => $value)
1601
+				foreach ($cat_rights as $uid => $value)
1604 1602
 				{
1605 1603
 					$all |= $value;
1606
-					if (in_array($uid,$memberships)) $own |= $value;
1604
+					if (in_array($uid, $memberships)) $own |= $value;
1607 1605
 				}
1608 1606
 			}
1609
-			foreach(array(self::CAT_ACL_ADD,self::CAT_ACL_STATUS) as $mask)
1607
+			foreach (array(self::CAT_ACL_ADD, self::CAT_ACL_STATUS) as $mask)
1610 1608
 			{
1611
-				$cache[$cat_id][$mask] = !($all & $mask) ? null : !!($own & $mask);
1609
+				$cache[$cat_id][$mask] = !($all&$mask) ? null : !!($own&$mask);
1612 1610
 			}
1613 1611
 		}
1614 1612
 		//echo "<p>".__METHOD__."($right,$cat_id) all=$all, own=$own returning ".array2string($cache[$cat_id][$right])."</p>\n";
@@ -1628,13 +1626,13 @@  discard block
 block discarded – undo
1628 1626
 	 * @param boolean $skip_notification =false true: do not send notification messages
1629 1627
 	 * @return int number of changed recurrences
1630 1628
 	 */
1631
-	function set_status($event,$uid,$status,$recur_date=0,$ignore_acl=false,$updateTS=true,$skip_notification=false)
1629
+	function set_status($event, $uid, $status, $recur_date = 0, $ignore_acl = false, $updateTS = true, $skip_notification = false)
1632 1630
 	{
1633 1631
 		unset($updateTS);
1634 1632
 
1635 1633
 		$cal_id = is_array($event) ? $event['id'] : $event;
1636 1634
 		//echo "<p>calendar_boupdate::set_status($cal_id,$uid,$status,$recur_date)</p>\n";
1637
-		if (!$cal_id || (!$ignore_acl && !$this->check_status_perms($uid,$event)))
1635
+		if (!$cal_id || (!$ignore_acl && !$this->check_status_perms($uid, $event)))
1638 1636
 		{
1639 1637
 			return false;
1640 1638
 		}
@@ -1643,16 +1641,16 @@  discard block
 block discarded – undo
1643 1641
 		if ($this->log)
1644 1642
 		{
1645 1643
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1646
-				"($cal_id, $uid, $status, $recur_date)\n",3,$this->logfile);
1644
+				"($cal_id, $uid, $status, $recur_date)\n", 3, $this->logfile);
1647 1645
 		}
1648 1646
 		$old_event = $this->read($cal_id, $recur_date, $ignore_acl, 'server');
1649
-		if (($Ok = $this->so->set_status($cal_id,is_numeric($uid)?'u':$uid[0],
1650
-				is_numeric($uid)?$uid:substr($uid,1),$status,
1651
-				$recur_date?$this->date2ts($recur_date,true):0,$role)))
1647
+		if (($Ok = $this->so->set_status($cal_id, is_numeric($uid) ? 'u' : $uid[0],
1648
+				is_numeric($uid) ? $uid : substr($uid, 1), $status,
1649
+				$recur_date ? $this->date2ts($recur_date, true) : 0, $role)))
1652 1650
 		{
1653 1651
 			if ($status == 'R')	// remove alarms belonging to rejected participants
1654 1652
 			{
1655
-				foreach(is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1653
+				foreach (is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1656 1654
 				{
1657 1655
 					if ((string)$alarm['owner'] === (string)$uid)
1658 1656
 					{
@@ -1674,9 +1672,9 @@  discard block
 block discarded – undo
1674 1672
 			if (isset($status2msg[$status]) && !$skip_notification)
1675 1673
 			{
1676 1674
 				if (!is_array($event)) $event = $this->read($cal_id);
1677
-				if (isset($recur_date)) $event = $this->read($event['id'],$recur_date); //re-read the actually edited recurring event
1675
+				if (isset($recur_date)) $event = $this->read($event['id'], $recur_date); //re-read the actually edited recurring event
1678 1676
 				$user_id = is_numeric($uid) ? (int)$uid : $uid;
1679
-				$this->send_update($status2msg[$status],$event['participants'],$event, null, $user_id);
1677
+				$this->send_update($status2msg[$status], $event['participants'], $event, null, $user_id);
1680 1678
 			}
1681 1679
 
1682 1680
 			// Update history
@@ -1696,14 +1694,14 @@  discard block
 block discarded – undo
1696 1694
 	 * @param int $recur_date =0 date to change, or 0 = all since now
1697 1695
 	 * @param boolean $skip_notification Do not send notifications.  Parameter passed on to set_status().
1698 1696
 	 */
1699
-	function update_status($new_event, $old_event , $recur_date=0, $skip_notification=false)
1697
+	function update_status($new_event, $old_event, $recur_date = 0, $skip_notification = false)
1700 1698
 	{
1701 1699
 		if (!isset($new_event['participants'])) return;
1702 1700
 
1703 1701
 		// check the old list against the new list
1704 1702
 		foreach ($old_event['participants'] as $userid => $status)
1705 1703
   		{
1706
-            if (!isset($new_event['participants'][$userid])){
1704
+            if (!isset($new_event['participants'][$userid])) {
1707 1705
             	// Attendee will be deleted this way
1708 1706
             	$new_event['participants'][$userid] = 'G';
1709 1707
             }
@@ -1716,7 +1714,7 @@  discard block
 block discarded – undo
1716 1714
 		// write the changes
1717 1715
 		foreach ($new_event['participants'] as $userid => $status)
1718 1716
 		{
1719
-			$this->set_status($old_event, $userid, $status, $recur_date, true, false,$skip_notification);
1717
+			$this->set_status($old_event, $userid, $status, $recur_date, true, false, $skip_notification);
1720 1718
 		}
1721 1719
     }
1722 1720
 
@@ -1731,43 +1729,43 @@  discard block
 block discarded – undo
1731 1729
 	 * @param int &$exceptions_kept=null on return number of kept exceptions
1732 1730
 	 * @return boolean true on success, false on error (usually permission denied)
1733 1731
 	 */
1734
-	function delete($cal_id, $recur_date=0, $ignore_acl=false, $skip_notification=false,
1735
-		$delete_exceptions=true, &$exceptions_kept=null)
1732
+	function delete($cal_id, $recur_date = 0, $ignore_acl = false, $skip_notification = false,
1733
+		$delete_exceptions = true, &$exceptions_kept = null)
1736 1734
 	{
1737 1735
 		//error_log(__METHOD__."(cal_id=$cal_id, recur_date=$recur_date, ignore_acl=$ignore_acl, skip_notifications=$skip_notification)");
1738
-		if (!($event = $this->read($cal_id,$recur_date)) ||
1739
-			!$ignore_acl && !$this->check_perms(Acl::DELETE,$event))
1736
+		if (!($event = $this->read($cal_id, $recur_date)) ||
1737
+			!$ignore_acl && !$this->check_perms(Acl::DELETE, $event))
1740 1738
 		{
1741 1739
 			return false;
1742 1740
 		}
1743 1741
 
1744 1742
 		// Don't send notification if the event has already been deleted
1745
-		if(!$event['deleted'] && !$skip_notification)
1743
+		if (!$event['deleted'] && !$skip_notification)
1746 1744
 		{
1747
-			$this->send_update(MSG_DELETED,$event['participants'],$event);
1745
+			$this->send_update(MSG_DELETED, $event['participants'], $event);
1748 1746
 		}
1749 1747
 
1750 1748
 		if (!$recur_date || $event['recur_type'] == MCAL_RECUR_NONE)
1751 1749
 		{
1752 1750
 			$config = Api\Config::read('phpgwapi');
1753
-			if(!$config['calendar_delete_history'] || $event['deleted'])
1751
+			if (!$config['calendar_delete_history'] || $event['deleted'])
1754 1752
 			{
1755 1753
 				$this->so->delete($cal_id);
1756 1754
 
1757 1755
 				// delete all links to the event
1758
-				Link::unlink(0,'calendar',$cal_id);
1756
+				Link::unlink(0, 'calendar', $cal_id);
1759 1757
 			}
1760 1758
 			elseif ($config['calendar_delete_history'])
1761 1759
 			{
1762 1760
 				// mark all links to the event as deleted, but keep them
1763
-				Link::unlink(0,'calendar',$cal_id,'','','',true);
1761
+				Link::unlink(0, 'calendar', $cal_id, '', '', '', true);
1764 1762
 
1765 1763
 				$event['deleted'] = $this->now;
1766 1764
 				$this->save($event, $ignore_acl);
1767 1765
 				// Actually delete alarms
1768 1766
 				if (isset($event['alarm']) && is_array($event['alarm']))
1769 1767
 				{
1770
-					foreach($event['alarm'] as $id => $alarm)
1768
+					foreach ($event['alarm'] as $id => $alarm)
1771 1769
 					{
1772 1770
 						$this->delete_alarm($id);
1773 1771
 					}
@@ -1789,7 +1787,7 @@  discard block
 block discarded – undo
1789 1787
 						if (!($exception = $this->read($id))) continue;
1790 1788
 						$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
1791 1789
 						$exception['reference'] = $exception['recurrence'] = 0;
1792
-						$this->update($exception, true, true, false, true, $msg=null, true);
1790
+						$this->update($exception, true, true, false, true, $msg = null, true);
1793 1791
 						++$exceptions_kept;
1794 1792
 					}
1795 1793
 				}
@@ -1801,9 +1799,9 @@  discard block
 block discarded – undo
1801 1799
 			if ($event['alarm'])
1802 1800
 			{
1803 1801
 				$next_recurrance = null;
1804
-				foreach($event['alarm'] as &$alarm)
1802
+				foreach ($event['alarm'] as &$alarm)
1805 1803
 				{
1806
-					if (($alarm['time'] == $recur_date) || ($alarm['time']+$alarm['offset'] == $recur_date))
1804
+					if (($alarm['time'] == $recur_date) || ($alarm['time'] + $alarm['offset'] == $recur_date))
1807 1805
 					{
1808 1806
 						//error_log(__METHOD__.__LINE__.'->'.array2string($recur_date));
1809 1807
 						//error_log(__METHOD__.__LINE__.array2string($event));
@@ -1811,12 +1809,12 @@  discard block
 block discarded – undo
1811 1809
 						{
1812 1810
 							$checkdate = $recur_date;
1813 1811
 							//if ($alarm['time']+$alarm['offset'] == $recur_date) $checkdate = $recur_date + $alarm['offset'];
1814
-							if (($e = $this->read($cal_id,$checkdate+1)))
1812
+							if (($e = $this->read($cal_id, $checkdate + 1)))
1815 1813
 							{
1816 1814
 								$next_recurrance = $this->date2ts($e['start']);
1817 1815
 							}
1818 1816
 						}
1819
-						$alarm['time'] = $this->date2ts($next_recurrance, true);	// user to server-time
1817
+						$alarm['time'] = $this->date2ts($next_recurrance, true); // user to server-time
1820 1818
 						$alarm['cal_id'] = $cal_id;
1821 1819
 						unset($alarm['times']);
1822 1820
 						unset($alarm['next']);
@@ -1830,7 +1828,7 @@  discard block
 block discarded – undo
1830 1828
 			$event = $this->read($cal_id);
1831 1829
 			//if (isset($alarmbuffer)) $event['alarm'] = $alarmbuffer;
1832 1830
 			$event['recur_exception'][] = $recur_date;
1833
-			$this->save($event);// updates the content-history
1831
+			$this->save($event); // updates the content-history
1834 1832
 		}
1835 1833
 		if ($event['reference'])
1836 1834
 		{
@@ -1848,19 +1846,19 @@  discard block
 block discarded – undo
1848 1846
 	 * @param array $disinvited
1849 1847
 	 * @return array
1850 1848
 	 */
1851
-	function _get_event_details($event,$action,&$event_arr,$disinvited=array())
1849
+	function _get_event_details($event, $action, &$event_arr, $disinvited = array())
1852 1850
 	{
1853 1851
 		$details = array(			// event-details for the notify-msg
1854 1852
 			'id'          => $event['id'],
1855 1853
 			'action'      => lang($action),
1856 1854
 		);
1857 1855
 		$event_arr = $this->event2array($event);
1858
-		foreach($event_arr as $key => $val)
1856
+		foreach ($event_arr as $key => $val)
1859 1857
 		{
1860 1858
 			if ($key == 'recur_type') $key = 'repetition';
1861 1859
 			$details[$key] = $val['data'];
1862 1860
 		}
1863
-		$details['participants'] = $details['participants'] ? implode("\n",$details['participants']) : '';
1861
+		$details['participants'] = $details['participants'] ? implode("\n", $details['participants']) : '';
1864 1862
 
1865 1863
 		$event_arr['link']['field'] = lang('URL');
1866 1864
 		$eventStart_arr = $this->date2array($event['start']); // give this as 'date' to the link to pick the right recurrence for the participants state
@@ -1876,7 +1874,7 @@  discard block
 block discarded – undo
1876 1874
 		 */
1877 1875
 		$link_arr = array();
1878 1876
 		$link_arr['text'] = $event['title'];
1879
-		$link_arr['view'] = array(	'menuaction' => 'calendar.calendar_uiforms.edit',
1877
+		$link_arr['view'] = array('menuaction' => 'calendar.calendar_uiforms.edit',
1880 1878
 									'cal_id' => $event['id'],
1881 1879
 									'date' => $eventStart_arr['full'],
1882 1880
 									'ajax' => true
@@ -1885,11 +1883,11 @@  discard block
 block discarded – undo
1885 1883
 		$details['link_arr'] = $link_arr;
1886 1884
 
1887 1885
 		$dis = array();
1888
-		foreach($disinvited as $uid)
1886
+		foreach ($disinvited as $uid)
1889 1887
 		{
1890 1888
 			$dis[] = $this->participant_name($uid);
1891 1889
 		}
1892
-		$details['disinvited'] = implode(', ',$dis);
1890
+		$details['disinvited'] = implode(', ', $dis);
1893 1891
 		return $details;
1894 1892
 	}
1895 1893
 
@@ -1913,13 +1911,13 @@  discard block
 block discarded – undo
1913 1911
 			'data'	=> $event['description']
1914 1912
 		);
1915 1913
 
1916
-		foreach(explode(',',$event['category']) as $cat_id)
1914
+		foreach (explode(',', $event['category']) as $cat_id)
1917 1915
 		{
1918 1916
 			$cat_string[] = stripslashes(Api\Categories::id2name($cat_id));
1919 1917
 		}
1920 1918
 		$var['category'] = Array(
1921 1919
 			'field'	=> lang('Category'),
1922
-			'data'	=> implode(', ',$cat_string)
1920
+			'data'	=> implode(', ', $cat_string)
1923 1921
 		);
1924 1922
 
1925 1923
 		$var['location'] = Array(
@@ -1965,10 +1963,10 @@  discard block
 block discarded – undo
1965 1963
 
1966 1964
 		if (isset($event['participants']) && is_array($event['participants']) && !empty($event['participants']))
1967 1965
 		{
1968
-			$participants = $this->participants($event,true);
1966
+			$participants = $this->participants($event, true);
1969 1967
 
1970 1968
 			// fix external organiser to not be included as participant and shown as organiser
1971
-			foreach($event['participants'] as $uid => $status)
1969
+			foreach ($event['participants'] as $uid => $status)
1972 1970
 			{
1973 1971
 				$role = $quantity = null;
1974 1972
 				calendar_so::split_status($status, $quantity, $role);
@@ -2002,26 +2000,26 @@  discard block
 block discarded – undo
2002 2000
 	 * @param array $old_event =null event-data in the DB before calling save
2003 2001
 	 * @param string $type ='update'
2004 2002
 	 */
2005
-	function log2file($event2save,$event_saved,$old_event=null,$type='update')
2003
+	function log2file($event2save, $event_saved, $old_event = null, $type = 'update')
2006 2004
 	{
2007
-		if (!($f = fopen($this->log_file,'a')))
2005
+		if (!($f = fopen($this->log_file, 'a')))
2008 2006
 		{
2009 2007
 			echo "<p>error opening '$this->log_file' !!!</p>\n";
2010 2008
 			return false;
2011 2009
 		}
2012
-		fwrite($f,$type.': '.Api\Accounts::username($this->user).': '.date('r')."\n");
2013
-		fwrite($f,"Time: time to save / saved time read back / old time before save\n");
2014
-		foreach(array('start','end') as $name)
2010
+		fwrite($f, $type.': '.Api\Accounts::username($this->user).': '.date('r')."\n");
2011
+		fwrite($f, "Time: time to save / saved time read back / old time before save\n");
2012
+		foreach (array('start', 'end') as $name)
2015 2013
 		{
2016
-			fwrite($f,$name.': '.(isset($event2save[$name]) ? $this->format_date($event2save[$name]) : 'not set').' / '.
2017
-				$this->format_date($event_saved[$name]) .' / '.
2014
+			fwrite($f, $name.': '.(isset($event2save[$name]) ? $this->format_date($event2save[$name]) : 'not set').' / '.
2015
+				$this->format_date($event_saved[$name]).' / '.
2018 2016
 				(is_null($old_event) ? 'no old event' : $this->format_date($old_event[$name]))."\n");
2019 2017
 		}
2020
-		foreach(array('event2save','event_saved','old_event') as $name)
2018
+		foreach (array('event2save', 'event_saved', 'old_event') as $name)
2021 2019
 		{
2022
-			fwrite($f,$name.' = '.print_r($$name,true));
2020
+			fwrite($f, $name.' = '.print_r($$name, true));
2023 2021
 		}
2024
-		fwrite($f,"\n");
2022
+		fwrite($f, "\n");
2025 2023
 		fclose($f);
2026 2024
 
2027 2025
 		return true;
@@ -2042,7 +2040,7 @@  discard block
 block discarded – undo
2042 2040
 		if ($old_event !== null && $event['start'] == $old_event['start']) return;
2043 2041
 
2044 2042
 		$time = new Api\DateTime($event['start']);
2045
-		if(!is_array($event['alarm']))
2043
+		if (!is_array($event['alarm']))
2046 2044
 		{
2047 2045
 			$event['alarm'] = $this->so->read_alarms($event['id']);
2048 2046
 		}
@@ -2056,9 +2054,9 @@  discard block
 block discarded – undo
2056 2054
 			$instance_date = $instance_date->format('ts');
2057 2055
 		}
2058 2056
 
2059
-		foreach($event['alarm'] as &$alarm)
2057
+		foreach ($event['alarm'] as &$alarm)
2060 2058
 		{
2061
-			if($event['recur_type'] != MCAL_RECUR_NONE && $instance_date)
2059
+			if ($event['recur_type'] != MCAL_RECUR_NONE && $instance_date)
2062 2060
 			{
2063 2061
 				calendar_so::shift_alarm($event, $alarm, $instance_date);
2064 2062
 			}
@@ -2078,14 +2076,14 @@  discard block
 block discarded – undo
2078 2076
 	 * @param boolean $update_modified =true call update modified, default true
2079 2077
 	 * @return string id of the alarm, or false on error (eg. no perms)
2080 2078
 	 */
2081
-	function save_alarm($cal_id, $alarm, $update_modified=true)
2079
+	function save_alarm($cal_id, $alarm, $update_modified = true)
2082 2080
 	{
2083
-		if (!$cal_id || !$this->check_perms(Acl::EDIT,$alarm['all'] ? $cal_id : 0,!$alarm['all'] ? $alarm['owner'] : 0))
2081
+		if (!$cal_id || !$this->check_perms(Acl::EDIT, $alarm['all'] ? $cal_id : 0, !$alarm['all'] ? $alarm['owner'] : 0))
2084 2082
 		{
2085 2083
 			//echo "<p>no rights to save the alarm=".print_r($alarm,true)." to event($cal_id)</p>";
2086
-			return false;	// no rights to add the alarm
2084
+			return false; // no rights to add the alarm
2087 2085
 		}
2088
-		$alarm['time'] = $this->date2ts($alarm['time'],true);	// user to server-time
2086
+		$alarm['time'] = $this->date2ts($alarm['time'], true); // user to server-time
2089 2087
 
2090 2088
 		return $this->so->save_alarm($cal_id, $alarm, $update_modified);
2091 2089
 	}
@@ -2098,11 +2096,11 @@  discard block
 block discarded – undo
2098 2096
 	 */
2099 2097
 	function delete_alarm($id)
2100 2098
 	{
2101
-		list(,$cal_id) = explode(':',$id);
2099
+		list(,$cal_id) = explode(':', $id);
2102 2100
 
2103
-		if (!($alarm = $this->so->read_alarm($id)) || !$cal_id || !$this->check_perms(Acl::EDIT,$alarm['all'] ? $cal_id : 0,!$alarm['all'] ? $alarm['owner'] : 0))
2101
+		if (!($alarm = $this->so->read_alarm($id)) || !$cal_id || !$this->check_perms(Acl::EDIT, $alarm['all'] ? $cal_id : 0, !$alarm['all'] ? $alarm['owner'] : 0))
2104 2102
 		{
2105
-			return false;	// no rights to delete the alarm
2103
+			return false; // no rights to delete the alarm
2106 2104
 		}
2107 2105
 
2108 2106
 		return $this->so->delete_alarm($id);
@@ -2117,13 +2115,13 @@  discard block
 block discarded – undo
2117 2115
 	 *  by the ones the user normally does not see due to category permissions - used to preserve categories
2118 2116
 	 * @return array category ids (found, added and preserved categories)
2119 2117
 	 */
2120
-	function find_or_add_categories($catname_list, $old_event=null)
2118
+	function find_or_add_categories($catname_list, $old_event = null)
2121 2119
 	{
2122 2120
 		if (is_array($old_event) || $old_event > 0)
2123 2121
 		{
2124 2122
 			// preserve categories without users read access
2125 2123
 			if (!is_array($old_event)) $old_event = $this->read($old_event);
2126
-			$old_categories = explode(',',$old_event['category']);
2124
+			$old_categories = explode(',', $old_event['category']);
2127 2125
 			$old_cats_preserve = array();
2128 2126
 			if (is_array($old_categories) && count($old_categories) > 0)
2129 2127
 			{
@@ -2177,7 +2175,7 @@  discard block
 block discarded – undo
2177 2175
 	{
2178 2176
 		if (!is_array($cat_id_list))
2179 2177
 		{
2180
-			$cat_id_list = explode(',',$cat_id_list);
2178
+			$cat_id_list = explode(',', $cat_id_list);
2181 2179
 		}
2182 2180
 		$cat_list = array();
2183 2181
 		foreach ($cat_id_list as $cat_id)
@@ -2202,7 +2200,7 @@  discard block
 block discarded – undo
2202 2200
 	 *                              master	-> try to find a releated series master
2203 2201
 	 * @return array calendar_ids of matching entries
2204 2202
 	 */
2205
-	function find_event($event, $filter='exact')
2203
+	function find_event($event, $filter = 'exact')
2206 2204
 	{
2207 2205
 		$matchingEvents = array();
2208 2206
 		$query = array();
@@ -2210,14 +2208,14 @@  discard block
 block discarded – undo
2210 2208
 		if ($this->log)
2211 2209
 		{
2212 2210
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2213
-				"($filter)[EVENT]:" . array2string($event)."\n",3,$this->logfile);
2211
+				"($filter)[EVENT]:".array2string($event)."\n", 3, $this->logfile);
2214 2212
 		}
2215 2213
 
2216 2214
 		if (!isset($event['recurrence'])) $event['recurrence'] = 0;
2217 2215
 
2218 2216
 		if ($filter == 'master')
2219 2217
 		{
2220
-			$query[] = 'recur_type!='. MCAL_RECUR_NONE;
2218
+			$query[] = 'recur_type!='.MCAL_RECUR_NONE;
2221 2219
 			$query['cal_recurrence'] = 0;
2222 2220
 		}
2223 2221
 		elseif ($filter == 'exact')
@@ -2238,14 +2236,14 @@  discard block
 block discarded – undo
2238 2236
 			if ($this->log)
2239 2237
 			{
2240 2238
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2241
-					'(' . $event['id'] . ")[EventID]\n",3,$this->logfile);
2239
+					'('.$event['id'].")[EventID]\n", 3, $this->logfile);
2242 2240
 			}
2243 2241
 			if (($egwEvent = $this->read($event['id'], 0, false, 'server')))
2244 2242
 			{
2245 2243
 				if ($this->log)
2246 2244
 				{
2247 2245
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2248
-						'()[FOUND]:' . array2string($egwEvent)."\n",3,$this->logfile);
2246
+						'()[FOUND]:'.array2string($egwEvent)."\n", 3, $this->logfile);
2249 2247
 				}
2250 2248
 				if ($egwEvent['recur_type'] != MCAL_RECUR_NONE &&
2251 2249
 					(empty($event['uid']) || $event['uid'] == $egwEvent['uid']))
@@ -2264,7 +2262,7 @@  discard block
 block discarded – undo
2264 2262
 						$exceptions = $this->so->get_recurrence_exceptions($egwEvent, $event['tzid']);
2265 2263
 						if (in_array($event['recurrence'], $exceptions))
2266 2264
 						{
2267
-							$matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['recurrence'];
2265
+							$matchingEvents[] = $egwEvent['id'].':'.(int)$event['recurrence'];
2268 2266
 						}
2269 2267
 					}
2270 2268
 				} elseif ($filter != 'master' && ($filter == 'exact' ||
@@ -2283,19 +2281,19 @@  discard block
 block discarded – undo
2283 2281
 
2284 2282
 		// only query calendars of users, we have READ-grants from
2285 2283
 		$users = array();
2286
-		foreach(array_keys($this->grants) as $user)
2284
+		foreach (array_keys($this->grants) as $user)
2287 2285
 		{
2288 2286
 			$user = trim($user);
2289
-			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY,0,$user))
2287
+			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY, 0, $user))
2290 2288
 			{
2291
-				if ($user && !in_array($user,$users))	// already added?
2289
+				if ($user && !in_array($user, $users))	// already added?
2292 2290
 				{
2293 2291
 					$users[] = $user;
2294 2292
 				}
2295 2293
 			}
2296 2294
 			elseif ($GLOBALS['egw']->accounts->get_type($user) != 'g')
2297 2295
 			{
2298
-				continue;	// for non-groups (eg. users), we stop here if we have no read-rights
2296
+				continue; // for non-groups (eg. users), we stop here if we have no read-rights
2299 2297
 			}
2300 2298
 			// the further code is only for real users
2301 2299
 			if (!is_numeric($user)) continue;
@@ -2306,7 +2304,7 @@  discard block
 block discarded – undo
2306 2304
 				$members = $GLOBALS['egw']->accounts->members($user, true);
2307 2305
 				if (is_array($members))
2308 2306
 				{
2309
-					foreach($members as $member)
2307
+					foreach ($members as $member)
2310 2308
 					{
2311 2309
 						// use only members which gave the user a read-grant
2312 2310
 						if (!in_array($member, $users) &&
@@ -2322,7 +2320,7 @@  discard block
 block discarded – undo
2322 2320
 				$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
2323 2321
 				if (is_array($memberships))
2324 2322
 				{
2325
-					foreach($memberships as $group)
2323
+					foreach ($memberships as $group)
2326 2324
 					{
2327 2325
 						if (!in_array($group, $users))
2328 2326
 						{
@@ -2348,24 +2346,24 @@  discard block
 block discarded – undo
2348 2346
 
2349 2347
 				// check length with some tolerance
2350 2348
 				$length = $event['end'] - $event['start'] - $delta;
2351
-				$query[] = ('(cal_end-cal_start)>' . $length);
2349
+				$query[] = ('(cal_end-cal_start)>'.$length);
2352 2350
 				$length += 2 * $delta;
2353
-				$query[] = ('(cal_end-cal_start)<' . $length);
2354
-				$query[] = ('cal_start>' . ($event['start'] - 86400));
2355
-				$query[] = ('cal_start<' . ($event['start'] + 86400));
2351
+				$query[] = ('(cal_end-cal_start)<'.$length);
2352
+				$query[] = ('cal_start>'.($event['start'] - 86400));
2353
+				$query[] = ('cal_start<'.($event['start'] + 86400));
2356 2354
 			}
2357 2355
 			elseif (isset($event['start']))
2358 2356
 			{
2359 2357
 				if ($filter == 'relax')
2360 2358
 				{
2361
-					$query[] = ('cal_start>' . ($event['start'] - 3600));
2362
-					$query[] = ('cal_start<' . ($event['start'] + 3600));
2359
+					$query[] = ('cal_start>'.($event['start'] - 3600));
2360
+					$query[] = ('cal_start<'.($event['start'] + 3600));
2363 2361
 				}
2364 2362
 				else
2365 2363
 				{
2366 2364
 					// we accept a tiny tolerance
2367
-					$query[] = ('cal_start>' . ($event['start'] - 2));
2368
-					$query[] = ('cal_start<' . ($event['start'] + 2));
2365
+					$query[] = ('cal_start>'.($event['start'] - 2));
2366
+					$query[] = ('cal_start<'.($event['start'] + 2));
2369 2367
 				}
2370 2368
 			}
2371 2369
 			if ($filter == 'relax')
@@ -2388,14 +2386,14 @@  discard block
 block discarded – undo
2388 2386
 			if ($this->log)
2389 2387
 			{
2390 2388
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2391
-					'(' . $event['uid'] . ")[EventUID]\n",3,$this->logfile);
2389
+					'('.$event['uid'].")[EventUID]\n", 3, $this->logfile);
2392 2390
 			}
2393 2391
 		}
2394 2392
 
2395 2393
 		if ($this->log)
2396 2394
 		{
2397 2395
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2398
-				'[QUERY]: ' . array2string($query)."\n",3,$this->logfile);
2396
+				'[QUERY]: '.array2string($query)."\n", 3, $this->logfile);
2399 2397
 		}
2400 2398
 		if (!count($users) || !($foundEvents =
2401 2399
 			$this->so->search(null, null, $users, 0, 'owner', false, 0, array('query' => $query))))
@@ -2403,19 +2401,19 @@  discard block
 block discarded – undo
2403 2401
 			if ($this->log)
2404 2402
 			{
2405 2403
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2406
-				"[NO MATCH]\n",3,$this->logfile);
2404
+				"[NO MATCH]\n", 3, $this->logfile);
2407 2405
 			}
2408 2406
 			return $matchingEvents;
2409 2407
 		}
2410 2408
 
2411 2409
 		$pseudos = array();
2412 2410
 
2413
-		foreach($foundEvents as $egwEvent)
2411
+		foreach ($foundEvents as $egwEvent)
2414 2412
 		{
2415 2413
 			if ($this->log)
2416 2414
 			{
2417 2415
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2418
-					'[FOUND]: ' . array2string($egwEvent)."\n",3,$this->logfile);
2416
+					'[FOUND]: '.array2string($egwEvent)."\n", 3, $this->logfile);
2419 2417
 			}
2420 2418
 
2421 2419
 			if (in_array($egwEvent['id'], $matchingEvents)) continue;
@@ -2489,7 +2487,7 @@  discard block
 block discarded – undo
2489 2487
 						if (in_array($event['recurrence'], $exceptions))
2490 2488
 						{
2491 2489
 							// We found a pseudo exception
2492
-							$matchingEvents = array($egwEvent['id'] . ':' . (int)$event['recurrence']);
2490
+							$matchingEvents = array($egwEvent['id'].':'.(int)$event['recurrence']);
2493 2491
 							break;
2494 2492
 						}
2495 2493
 					}
@@ -2507,7 +2505,7 @@  discard block
 block discarded – undo
2507 2505
 						if ($this->log)
2508 2506
 						{
2509 2507
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2510
-							"() egwEvent length does not match!\n",3,$this->logfile);
2508
+							"() egwEvent length does not match!\n", 3, $this->logfile);
2511 2509
 						}
2512 2510
 						continue;
2513 2511
 					}
@@ -2519,7 +2517,7 @@  discard block
 block discarded – undo
2519 2517
 						if ($this->log)
2520 2518
 						{
2521 2519
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2522
-							"() egwEvent is not a whole-day event!\n",3,$this->logfile);
2520
+							"() egwEvent is not a whole-day event!\n", 3, $this->logfile);
2523 2521
 						}
2524 2522
 						continue;
2525 2523
 					}
@@ -2540,8 +2538,8 @@  discard block
 block discarded – undo
2540 2538
 					if ($this->log)
2541 2539
 					{
2542 2540
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2543
-							"() event[$key] differ: '" . $event[$key] .
2544
-							"' <> '" . $egwEvent[$key] . "'\n",3,$this->logfile);
2541
+							"() event[$key] differ: '".$event[$key].
2542
+							"' <> '".$egwEvent[$key]."'\n", 3, $this->logfile);
2545 2543
 					}
2546 2544
 					continue 2; // next foundEvent
2547 2545
 				}
@@ -2559,7 +2557,7 @@  discard block
 block discarded – undo
2559 2557
 						if ($this->log)
2560 2558
 						{
2561 2559
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2562
-							"() egwEvent category $cat_id is missing!\n",3,$this->logfile);
2560
+							"() egwEvent category $cat_id is missing!\n", 3, $this->logfile);
2563 2561
 						}
2564 2562
 						continue 2;
2565 2563
 					}
@@ -2571,7 +2569,7 @@  discard block
 block discarded – undo
2571 2569
 					{
2572 2570
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2573 2571
 							'() event has additional categories:'
2574
-							. array2string($newCategories)."\n",3,$this->logfile);
2572
+							. array2string($newCategories)."\n", 3, $this->logfile);
2575 2573
 					}
2576 2574
 					continue;
2577 2575
 				}
@@ -2591,7 +2589,7 @@  discard block
 block discarded – undo
2591 2589
 							if ($this->log)
2592 2590
 							{
2593 2591
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2594
-								"() additional event['participants']: $attendee\n",3,$this->logfile);
2592
+								"() additional event['participants']: $attendee\n", 3, $this->logfile);
2595 2593
 							}
2596 2594
 							continue 2;
2597 2595
 						}
@@ -2614,8 +2612,8 @@  discard block
 block discarded – undo
2614 2612
 						if ($this->log)
2615 2613
 						{
2616 2614
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2617
-								'() missing event[participants]: ' .
2618
-								array2string($egwEvent['participants'])."\n",3,$this->logfile);
2615
+								'() missing event[participants]: '.
2616
+								array2string($egwEvent['participants'])."\n", 3, $this->logfile);
2619 2617
 						}
2620 2618
 						continue;
2621 2619
 					}
@@ -2627,7 +2625,7 @@  discard block
 block discarded – undo
2627 2625
 				if ($egwEvent['recur_type'] != MCAL_RECUR_NONE)
2628 2626
 				{
2629 2627
 					// We found a pseudo Exception
2630
-					$pseudos[] = $egwEvent['id'] . ':' . $event['start'];
2628
+					$pseudos[] = $egwEvent['id'].':'.$event['start'];
2631 2629
 					continue;
2632 2630
 				}
2633 2631
 			}
@@ -2649,7 +2647,7 @@  discard block
 block discarded – undo
2649 2647
 							if ($this->log)
2650 2648
 							{
2651 2649
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2652
-								"() additional event['recur_exception']: $day\n",3,$this->logfile);
2650
+								"() additional event['recur_exception']: $day\n", 3, $this->logfile);
2653 2651
 							}
2654 2652
 							continue 2;
2655 2653
 						}
@@ -2659,8 +2657,8 @@  discard block
 block discarded – undo
2659 2657
 						if ($this->log)
2660 2658
 						{
2661 2659
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2662
-								'() missing event[recur_exception]: ' .
2663
-								array2string($event['recur_exception'])."\n",3,$this->logfile);
2660
+								'() missing event[recur_exception]: '.
2661
+								array2string($event['recur_exception'])."\n", 3, $this->logfile);
2664 2662
 						}
2665 2663
 						continue;
2666 2664
 					}
@@ -2675,8 +2673,8 @@  discard block
 block discarded – undo
2675 2673
 						if ($this->log)
2676 2674
 						{
2677 2675
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2678
-								"() events[$key] differ: " . $event[$key] .
2679
-								' <> ' . $egwEvent[$key]."\n",3,$this->logfile);
2676
+								"() events[$key] differ: ".$event[$key].
2677
+								' <> '.$egwEvent[$key]."\n", 3, $this->logfile);
2680 2678
 						}
2681 2679
 						continue 2;
2682 2680
 					}
@@ -2692,7 +2690,7 @@  discard block
 block discarded – undo
2692 2690
 			if ($this->log)
2693 2691
 			{
2694 2692
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2695
-					"() new exception for series found.\n",3,$this->logfile);
2693
+					"() new exception for series found.\n", 3, $this->logfile);
2696 2694
 			}
2697 2695
 			$matchingEvents = array();
2698 2696
 		}
@@ -2703,7 +2701,7 @@  discard block
 block discarded – undo
2703 2701
 		if ($this->log)
2704 2702
 		{
2705 2703
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2706
-				'[MATCHES]:' . array2string($matches)."\n",3,$this->logfile);
2704
+				'[MATCHES]:'.array2string($matches)."\n", 3, $this->logfile);
2707 2705
 		}
2708 2706
 		return $matches;
2709 2707
 	}
@@ -2776,7 +2774,7 @@  discard block
 block discarded – undo
2776 2774
 				if ($this->log)
2777 2775
 				{
2778 2776
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2779
-					"()[MASTER]: $eventID\n",3,$this->logfile);
2777
+					"()[MASTER]: $eventID\n", 3, $this->logfile);
2780 2778
 				}
2781 2779
 				$type = 'SERIES-EXCEPTION';
2782 2780
 				if (($master_event = $this->read($eventID, 0, false, 'server')))
@@ -2797,7 +2795,7 @@  discard block
 block discarded – undo
2797 2795
 					}
2798 2796
 					elseif (in_array($event['start'], $master_event['recur_exception']))
2799 2797
 					{
2800
-						$type='SERIES-PSEUDO-EXCEPTION'; // new pseudo exception?
2798
+						$type = 'SERIES-PSEUDO-EXCEPTION'; // new pseudo exception?
2801 2799
 						$recurrence_event = $master_event;
2802 2800
 						$recurrence_event['start'] = $event['start'];
2803 2801
 						$recurrence_event['end'] -= $master_event['start'] - $event['start'];
@@ -2814,8 +2812,8 @@  discard block
 block discarded – undo
2814 2812
 							if ($this->log)
2815 2813
 							{
2816 2814
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2817
-									'() try occurrence ' . $egw_rrule->current()
2818
-									. " ($occurrence)\n",3,$this->logfile);
2815
+									'() try occurrence '.$egw_rrule->current()
2816
+									. " ($occurrence)\n", 3, $this->logfile);
2819 2817
 							}
2820 2818
 							if ($event['start'] == $occurrence)
2821 2819
 							{
@@ -2848,8 +2846,8 @@  discard block
 block discarded – undo
2848 2846
 			// default if we cannot find a proof for a fundamental change
2849 2847
 			// the recurrence_event is the master event with start and end adjusted to the recurrence
2850 2848
 			// check for changed data
2851
-			foreach (array('start','end','uid','title','location','description',
2852
-				'priority','public','special','non_blocking') as $key)
2849
+			foreach (array('start', 'end', 'uid', 'title', 'location', 'description',
2850
+				'priority', 'public', 'special', 'non_blocking') as $key)
2853 2851
 			{
2854 2852
 				if (!empty($event[$key]) && $recurrence_event[$key] != $event[$key])
2855 2853
 				{
@@ -2907,10 +2905,10 @@  discard block
 block discarded – undo
2907 2905
      * @param &$event	the event we are working on
2908 2906
      *
2909 2907
      */
2910
-    function server2usertime (&$event)
2908
+    function server2usertime(&$event)
2911 2909
     {
2912 2910
 		// we run all dates through date2usertime, to adjust to user-time
2913
-		foreach(array('start','end','recur_enddate','recurrence') as $ts)
2911
+		foreach (array('start', 'end', 'recur_enddate', 'recurrence') as $ts)
2914 2912
 		{
2915 2913
 			// we convert here from server-time to timestamps in user-time!
2916 2914
 			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
@@ -2918,7 +2916,7 @@  discard block
 block discarded – undo
2918 2916
 		// same with the recur exceptions
2919 2917
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
2920 2918
 		{
2921
-			foreach($event['recur_exception'] as $n => $date)
2919
+			foreach ($event['recur_exception'] as $n => $date)
2922 2920
 			{
2923 2921
 				$event['recur_exception'][$n] = $this->date2usertime($date);
2924 2922
 			}
@@ -2926,7 +2924,7 @@  discard block
 block discarded – undo
2926 2924
 		// same with the alarms
2927 2925
 		if (isset($event['alarm']) && is_array($event['alarm']))
2928 2926
 		{
2929
-			foreach($event['alarm'] as $id => $alarm)
2927
+			foreach ($event['alarm'] as $id => $alarm)
2930 2928
 			{
2931 2929
 				$event['alarm'][$id]['time'] = $this->date2usertime($alarm['time']);
2932 2930
 			}
@@ -2943,7 +2941,7 @@  discard block
 block discarded – undo
2943 2941
 	{
2944 2942
 		if (is_numeric($age) && $age > 0)	// just make sure bogus values dont delete everything
2945 2943
 		{
2946
-			$this->so->purge(time() - 365*24*3600*(float)$age);
2944
+			$this->so->purge(time() - 365 * 24 * 3600 * (float)$age);
2947 2945
 		}
2948 2946
 	}
2949 2947
 
@@ -2960,18 +2958,18 @@  discard block
 block discarded – undo
2960 2958
 	 */
2961 2959
 	protected function check_reset_stati(&$event, $old_event)
2962 2960
 	{
2963
-		if(!$old_event || !is_array($old_event) || $event['start'] == $old_event['start'])
2961
+		if (!$old_event || !is_array($old_event) || $event['start'] == $old_event['start'])
2964 2962
 		{
2965 2963
 			return false;
2966 2964
 		}
2967 2965
 
2968 2966
 		$status_reset = false;
2969 2967
 		$sameday = (date('Ymd', $old_event['start']) == date('Ymd', $event['start']));
2970
-		foreach((array)$event['participants'] as $uid => $status)
2968
+		foreach ((array)$event['participants'] as $uid => $status)
2971 2969
 		{
2972 2970
 			$q = $r = null;
2973
-			calendar_so::split_status($status,$q,$r);
2974
-			if($uid == $this->user || $status == 'U')
2971
+			calendar_so::split_status($status, $q, $r);
2972
+			if ($uid == $this->user || $status == 'U')
2975 2973
 			{
2976 2974
 				continue;
2977 2975
 			}
@@ -2989,14 +2987,14 @@  discard block
 block discarded – undo
2989 2987
 						if ($sameday) break;
2990 2988
 					default:
2991 2989
 						$status_reset = true;
2992
-						$event['participants'][$uid] = calendar_so::combine_status('U',$q,$r);
2990
+						$event['participants'][$uid] = calendar_so::combine_status('U', $q, $r);
2993 2991
 				}
2994 2992
 			}
2995 2993
 			// All other participant types
2996 2994
 			else
2997 2995
 			{
2998 2996
 				$status_reset = true;
2999
-				$event['participants'][$uid] = calendar_so::combine_status('U',$q,$r);
2997
+				$event['participants'][$uid] = calendar_so::combine_status('U', $q, $r);
3000 2998
 			}
3001 2999
 		}
3002 3000
 		return $status_reset;
Please login to merge, or discard this patch.
Braces   +227 added lines, -58 removed lines patch added patch discarded remove patch
@@ -85,11 +85,17 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	function __construct()
87 87
 	{
88
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started',True);
88
+		if ($this->debug > 0)
89
+		{
90
+			$this->debug_message('calendar_boupdate::__construct() started',True);
91
+		}
89 92
 
90 93
 		parent::__construct();	// calling the parent constructor
91 94
 
92
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished',True);
95
+		if ($this->debug > 0)
96
+		{
97
+			$this->debug_message('calendar_boupdate::__construct() finished',True);
98
+		}
93 99
 	}
94 100
 
95 101
 	/**
@@ -120,7 +126,10 @@  discard block
 block discarded – undo
120 126
 	{
121 127
 		unset($updateTS);	// ignored, as updating timestamps is required for sync!
122 128
 		//error_log(__METHOD__."(".array2string($event).",$ignore_conflicts,$touch_modified,$ignore_acl)");
123
-		if (!is_array($messages)) $messages = $messages ? (array)$messages : array();
129
+		if (!is_array($messages))
130
+		{
131
+			$messages = $messages ? (array)$messages : array();
132
+		}
124 133
 
125 134
 		if ($this->debug > 1 || $this->debug == 'update')
126 135
 		{
@@ -140,10 +149,13 @@  discard block
 block discarded – undo
140 149
 
141 150
 		$status_reset_to_unknown = false;
142 151
 
143
-		if (($new_event = !$event['id']))	// some defaults for new entries
152
+		if (($new_event = !$event['id']))
153
+		{
154
+			// some defaults for new entries
144 155
 		{
145 156
 			// if no owner given, set user to owner
146 157
 			if (!$event['owner']) $event['owner'] = $this->user;
158
+		}
147 159
 			// set owner as participant if none is given
148 160
 			if (!is_array($event['participants']) || !count($event['participants']))
149 161
 			{
@@ -183,7 +195,10 @@  discard block
 block discarded – undo
183 195
 		// check category based ACL
184 196
 		if ($event['category'])
185 197
 		{
186
-			if (!is_array($event['category'])) $event['category'] = explode(',',$event['category']);
198
+			if (!is_array($event['category']))
199
+			{
200
+				$event['category'] = explode(',',$event['category']);
201
+			}
187 202
 			if (!$old_event || !isset($old_event['category']))
188 203
 			{
189 204
 				$old_event['category'] = array();
@@ -235,13 +250,16 @@  discard block
 block discarded – undo
235 250
 		if (!$ignore_conflicts && !$event['non_blocking'] && isset($event['start']) && isset($event['end']) &&
236 251
 			(($conflicts = $this->conflicts($event, $checked_excluding)) || $checked_excluding))
237 252
 		{
238
-			if ($checked_excluding)	// warn user if not all recurrences have been checked
253
+			if ($checked_excluding)
254
+			{
255
+				// warn user if not all recurrences have been checked
239 256
 			{
240 257
 				$conflicts['warning'] = array(
241 258
 					'start' => $checked_excluding,
242 259
 					'title' => lang('Only recurrences until %1 (excluding) have been checked!', $checked_excluding->format(true)),
243 260
 				);
244 261
 			}
262
+			}
245 263
 			return $conflicts;
246 264
 		}
247 265
 
@@ -308,7 +326,10 @@  discard block
 block discarded – undo
308 326
 		$types_with_quantity = array();
309 327
 		foreach($this->resources as $type => $data)
310 328
 		{
311
-			if ($data['max_quantity']) $types_with_quantity[] = $type;
329
+			if ($data['max_quantity'])
330
+			{
331
+				$types_with_quantity[] = $type;
332
+			}
312 333
 		}
313 334
 		// get all NOT rejected participants and evtl. their quantity
314 335
 		$quantity = $users = array();
@@ -316,12 +337,19 @@  discard block
 block discarded – undo
316 337
 		{
317 338
 			$q = $role = null;
318 339
 			calendar_so::split_status($status, $q, $role);
319
-			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue;	// ignore rejected or non-participants
340
+			if ($status == 'R' || $role == 'NON-PARTICIPANT')
341
+			{
342
+				continue;
343
+			}
344
+			// ignore rejected or non-participants
320 345
 
321
-			if ($uid < 0)	// group, check it's members too
346
+			if ($uid < 0)
347
+			{
348
+				// group, check it's members too
322 349
 			{
323 350
 				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid,true)));
324 351
 			}
352
+			}
325 353
 			$users[] = $uid;
326 354
 			if (in_array($uid[0],$types_with_quantity))
327 355
 			{
@@ -352,18 +380,24 @@  discard block
 block discarded – undo
352 380
 			$startts = $date->format('ts');
353 381
 
354 382
 			// skip past events or recurrences
355
-			if ($startts+$duration < $this->now_su) continue;
383
+			if ($startts+$duration < $this->now_su)
384
+			{
385
+				continue;
386
+			}
356 387
 
357 388
 			// abort check if configured limits are exceeded
358 389
 			if ($event['recur_type'] &&
359 390
 				(++$checked > $max_checked && $max_checked > 0 || // maximum number of checked recurrences exceeded
360 391
 				microtime(true) > $start+$max_check_time ||	// max check time exceeded
361
-				$startts > $this->config['horizont']))	// we are behind horizon for which recurrences are rendered
392
+				$startts > $this->config['horizont']))
393
+			{
394
+				// we are behind horizon for which recurrences are rendered
362 395
 			{
363 396
 				if ($this->debug > 2 || $this->debug == 'conflicts')
364 397
 				{
365 398
 					$this->debug_message(__METHOD__.'() conflict check limited to %1 recurrences, %2 seconds, until (excluding) %3',
366 399
 						$checked, microtime(true)-$start, $date);
400
+			}
367 401
 				}
368 402
 				$checked_excluding = $date;
369 403
 				break;
@@ -387,10 +421,13 @@  discard block
 block discarded – undo
387 421
 			{
388 422
 				if ($overlap['id'] == $event['id'] ||	// that's the event itself
389 423
 					$overlap['id'] == $event['reference'] ||	// event is an exception of overlap
390
-					$overlap['non_blocking'])			// that's a non_blocking event
424
+					$overlap['non_blocking'])
425
+				{
426
+					// that's a non_blocking event
391 427
 				{
392 428
 					continue;
393 429
 				}
430
+				}
394 431
 				if ($this->debug > 3 || $this->debug == 'conflicts')
395 432
 				{
396 433
 					$this->debug_message(__METHOD__.'() checking overlapping event %1',false,$overlap);
@@ -903,14 +940,20 @@  discard block
 block discarded – undo
903 940
 		$startdate = new Api\DateTime($event['start']);
904 941
 		$enddate = new Api\DateTime($event['end']);
905 942
 		$modified = new Api\DateTime($event['modified']);
906
-		if ($old_event) $olddate = new Api\DateTime($old_event['start']);
943
+		if ($old_event)
944
+		{
945
+			$olddate = new Api\DateTime($old_event['start']);
946
+		}
907 947
 		//error_log(__METHOD__."() date_default_timezone_get()=".date_default_timezone_get().", user-timezone=".Api\DateTime::$user_timezone->getName().", startdate=".$startdate->format().", enddate=".$enddate->format().", updated=".$modified->format().", olddate=".($olddate ? $olddate->format() : ''));
908 948
 		$owner_prefs = $ics = null;
909 949
 		foreach($to_notify as $userid => $statusid)
910 950
 		{
911 951
 			$res_info = $quantity = $role = null;
912 952
 			calendar_so::split_status($statusid, $quantity, $role);
913
-			if ($this->debug > 0) error_log(__METHOD__." trying to notify $userid, with $statusid ($role)");
953
+			if ($this->debug > 0)
954
+			{
955
+				error_log(__METHOD__." trying to notify $userid, with $statusid ($role)");
956
+			}
914 957
 
915 958
 			if (!is_numeric($userid))
916 959
 			{
@@ -929,7 +972,11 @@  discard block
 block discarded – undo
929 972
 
930 973
 				if (!isset($userid))
931 974
 				{
932
-					if (empty($res_info['email'])) continue;	// no way to notify
975
+					if (empty($res_info['email']))
976
+					{
977
+						continue;
978
+					}
979
+					// no way to notify
933 980
 					// check if event-owner wants non-EGroupware users notified
934 981
 					if (is_null($owner_prefs))
935 982
 					{
@@ -1003,7 +1050,10 @@  discard block
 block discarded – undo
1003 1050
 				$details['to-lastname'] = isset($tln)? $tln: '';
1004 1051
 
1005 1052
 				// event is in user-time of current user, now we need to calculate the tz-difference to the notified user and take it into account
1006
-				if (!isset($part_prefs['common']['tz'])) $part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
1053
+				if (!isset($part_prefs['common']['tz']))
1054
+				{
1055
+					$part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
1056
+				}
1007 1057
 				$timezone = new DateTimeZone($part_prefs['common']['tz']);
1008 1058
 				$timeformat = $part_prefs['common']['timeformat'];
1009 1059
 				switch($timeformat)
@@ -1038,9 +1088,12 @@  discard block
 block discarded – undo
1038 1088
 				switch($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
1039 1089
 				{
1040 1090
 					case 'ical':
1041
-						if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
1091
+						if (is_null($ics) || $m_type != $msg_type)
1092
+						{
1093
+							// need different ical for organizer notification
1042 1094
 						{
1043 1095
 							$calendar_ical = new calendar_ical();
1096
+						}
1044 1097
 							$calendar_ical->setSupportedFields('full');	// full iCal fields+event TZ
1045 1098
 							// we need to pass $event[id] so iCal class reads event again,
1046 1099
 							// as event is in user TZ, but iCal class expects server TZ!
@@ -1056,7 +1109,10 @@  discard block
 block discarded – undo
1056 1109
 							'encoding' => '8bit',
1057 1110
 							'type' => 'text/calendar; method='.$method,
1058 1111
 						);
1059
-						if ($m_type != $msg_type) unset($ics);
1112
+						if ($m_type != $msg_type)
1113
+						{
1114
+							unset($ics);
1115
+						}
1060 1116
 						$subject = isset($cleared_event) ? $cleared_event['title'] : $event['title'];
1061 1117
 						// fall through
1062 1118
 					case 'extended':
@@ -1116,11 +1172,16 @@  discard block
 block discarded – undo
1116 1172
 								'app' => 'calendar'
1117 1173
 							));
1118 1174
 						}
1119
-						if ($m_type === MSG_ALARM) $notification->set_popupdata('calendar', array('egw_pr_notify' => 1, 'type' => $m_type));
1175
+						if ($m_type === MSG_ALARM)
1176
+						{
1177
+							$notification->set_popupdata('calendar', array('egw_pr_notify' => 1, 'type' => $m_type));
1178
+						}
1120 1179
 						$notification->set_popupmessage($subject."\n\n".$notify_body."\n\n".$details['description']."\n\n".$details_body."\n\n");
1121 1180
 						$notification->set_popuplinks(array($details['link_arr']+array('app'=>'calendar')));
1122 1181
 
1123
-						if(is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1182
+						if(is_array($attachment))
1183
+						{
1184
+$notification->set_attachments(array($attachment)); }
1124 1185
 						$notification->send();
1125 1186
 						foreach(notifications::errors(true) as $error)
1126 1187
 						{
@@ -1156,7 +1217,10 @@  discard block
 block discarded – undo
1156 1217
 			Api\Translation::init();
1157 1218
 		}
1158 1219
 		// restore timezone, in case we had to reset it to server-timezone
1159
-		if ($restore_tz) date_default_timezone_set($restore_tz);
1220
+		if ($restore_tz)
1221
+		{
1222
+			date_default_timezone_set($restore_tz);
1223
+		}
1160 1224
 
1161 1225
 		return true;
1162 1226
 	}
@@ -1191,10 +1255,13 @@  discard block
 block discarded – undo
1191 1255
 		{
1192 1256
 			$to_notify = $event['participants'];
1193 1257
 		}
1194
-		elseif ($this->check_perms(Acl::READ,$event))	// checks agains $this->owner set to $alarm[owner]
1258
+		elseif ($this->check_perms(Acl::READ,$event))
1259
+		{
1260
+			// checks agains $this->owner set to $alarm[owner]
1195 1261
 		{
1196 1262
 			$to_notify[$alarm['owner']] = 'A';
1197 1263
 		}
1264
+		}
1198 1265
 		else
1199 1266
 		{
1200 1267
 			return False;	// no rights
@@ -1244,14 +1311,20 @@  discard block
 block discarded – undo
1244 1311
 		if ($event['id'])
1245 1312
 		{
1246 1313
 			// invalidate the read-cache if it contains the event we store now
1247
-			if ($event['id'] == self::$cached_event['id']) self::$cached_event = array();
1314
+			if ($event['id'] == self::$cached_event['id'])
1315
+			{
1316
+				self::$cached_event = array();
1317
+			}
1248 1318
 			$old_event = $this->read($event['id'], $event['recurrence'], $ignore_acl, 'server');
1249 1319
 		}
1250 1320
 		else
1251 1321
 		{
1252 1322
 			$old_event = null;
1253 1323
 		}
1254
-		if (!isset($event['whole_day'])) $event['whole_day'] = $this->isWholeDay($event);
1324
+		if (!isset($event['whole_day']))
1325
+		{
1326
+			$event['whole_day'] = $this->isWholeDay($event);
1327
+		}
1255 1328
 
1256 1329
 		// set recur-enddate/range-end to real end-date of last recurrence
1257 1330
 		if ($event['recur_type'] != MCAL_RECUR_NONE && $event['recur_enddate'] && $event['start'])
@@ -1328,7 +1401,10 @@  discard block
 block discarded – undo
1328 1401
 		foreach($timestamps as $ts)
1329 1402
 		{
1330 1403
 			// we convert here from user-time to timestamps in server-time!
1331
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1404
+			if (isset($event[$ts]))
1405
+			{
1406
+				$event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1407
+			}
1332 1408
 		}
1333 1409
 		// convert tzid name to integer tz_id, of set user default
1334 1410
 		if (empty($event['tzid']) || !($event['tz_id'] = calendar_timezones::tz2id($event['tzid'])))
@@ -1364,7 +1440,10 @@  discard block
 block discarded – undo
1364 1440
 				if ($alarm['owner'] && isset($expanded['participants']))
1365 1441
 				{
1366 1442
 					// Don't auto-delete alarm if for all users
1367
-					if($alarm['all']) continue;
1443
+					if($alarm['all'])
1444
+					{
1445
+						continue;
1446
+					}
1368 1447
 
1369 1448
 					$status = $expanded['participants'][$alarm['owner']];
1370 1449
 					if (!isset($status) || calendar_so::split_status($status) === 'R')
@@ -1385,7 +1464,10 @@  discard block
 block discarded – undo
1385 1464
 				if (!isset($event['alarm'][$id]))
1386 1465
 				{
1387 1466
 					$alarm['time'] = $event['start'] - $alarm['offset'];
1388
-					if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
1467
+					if ($alarm['time'] < time())
1468
+					{
1469
+						calendar_so::shift_alarm($event, $alarm);
1470
+					}
1389 1471
 						// remove (not store) alarms belonging to not longer existing or rejected participants
1390 1472
 					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] :
1391 1473
 						$old_event['participants'][$alarm['owner']];
@@ -1441,7 +1523,10 @@  discard block
 block discarded – undo
1441 1523
 
1442 1524
 		// Update history
1443 1525
 		$tracking = new calendar_tracking($this);
1444
-		if (empty($event['id']) && !empty($cal_id)) $event['id']=$cal_id;
1526
+		if (empty($event['id']) && !empty($cal_id))
1527
+		{
1528
+			$event['id']=$cal_id;
1529
+		}
1445 1530
 		$tracking->track($save_event, $old_event);
1446 1531
 
1447 1532
 		return $cal_id;
@@ -1458,9 +1543,12 @@  discard block
 block discarded – undo
1458 1543
 	 */
1459 1544
 	function check_status_perms($uid,$event)
1460 1545
 	{
1461
-		if ($uid[0] == 'c' || $uid[0] == 'e')	// for contact we use the owner of the event
1546
+		if ($uid[0] == 'c' || $uid[0] == 'e')
1547
+		{
1548
+			// for contact we use the owner of the event
1462 1549
 		{
1463 1550
 			if (!is_array($event) && !($event = $this->read($event))) return false;
1551
+		}
1464 1552
 
1465 1553
 			return $this->check_perms(Acl::EDIT,0,$event['owner']);
1466 1554
 		}
@@ -1471,13 +1559,19 @@  discard block
 block discarded – undo
1471 1559
 			return $access;
1472 1560
 		}
1473 1561
 		// no access or denied access because of category acl --> regular check
1474
-		if (!is_numeric($uid))	// this is eg. for resources (r123)
1562
+		if (!is_numeric($uid))
1563
+		{
1564
+			// this is eg. for resources (r123)
1475 1565
 		{
1476 1566
 			$resource = $this->resource_info($uid);
1567
+		}
1477 1568
 
1478 1569
 			return Acl::EDIT & $resource['rights'];
1479 1570
 		}
1480
-		if (!is_array($event) && !($event = $this->read($event))) return false;
1571
+		if (!is_array($event) && !($event = $this->read($event)))
1572
+		{
1573
+			return false;
1574
+		}
1481 1575
 
1482 1576
 		// regular user and groups (need to check memberships too)
1483 1577
 		if (!isset($event['participants'][$uid]))
@@ -1501,7 +1595,10 @@  discard block
 block discarded – undo
1501 1595
 	 */
1502 1596
 	function check_cat_acl($right,$event)
1503 1597
 	{
1504
-		if (!is_array($event)) $event = $this->read($event);
1598
+		if (!is_array($event))
1599
+		{
1600
+			$event = $this->read($event);
1601
+		}
1505 1602
 
1506 1603
 		$ret = null;
1507 1604
 		if ($event['category'])
@@ -1558,7 +1655,10 @@  discard block
 block discarded – undo
1558 1655
 	public static function set_cat_rights($cat_id,$user,$rights)
1559 1656
 	{
1560 1657
 		//echo "<p>".__METHOD__."($cat_id,$user,$rights)</p>\n";
1561
-		if (!isset(self::$cat_rights_cache)) self::get_cat_rights($cat_id);
1658
+		if (!isset(self::$cat_rights_cache))
1659
+		{
1660
+			self::get_cat_rights($cat_id);
1661
+		}
1562 1662
 
1563 1663
 		if ((int)$rights != (int)self::$cat_rights_cache['L'.$cat_id][$user])
1564 1664
 		{
@@ -1570,7 +1670,10 @@  discard block
 block discarded – undo
1570 1670
 			else
1571 1671
 			{
1572 1672
 				unset(self::$cat_rights_cache['L'.$cat_id][$user]);
1573
-				if (!self::$cat_rights_cache['L'.$cat_id]) unset(self::$cat_rights_cache['L'.$cat_id]);
1673
+				if (!self::$cat_rights_cache['L'.$cat_id])
1674
+				{
1675
+					unset(self::$cat_rights_cache['L'.$cat_id]);
1676
+				}
1574 1677
 				$GLOBALS['egw']->acl->delete_repository('calendar','L'.$cat_id,$user);
1575 1678
 			}
1576 1679
 			Api\Cache::setSession('calendar','cat_rights',self::$cat_rights_cache);
@@ -1603,7 +1706,10 @@  discard block
 block discarded – undo
1603 1706
 				foreach($cat_rights as $uid => $value)
1604 1707
 				{
1605 1708
 					$all |= $value;
1606
-					if (in_array($uid,$memberships)) $own |= $value;
1709
+					if (in_array($uid,$memberships))
1710
+					{
1711
+						$own |= $value;
1712
+					}
1607 1713
 				}
1608 1714
 			}
1609 1715
 			foreach(array(self::CAT_ACL_ADD,self::CAT_ACL_STATUS) as $mask)
@@ -1650,13 +1756,16 @@  discard block
 block discarded – undo
1650 1756
 				is_numeric($uid)?$uid:substr($uid,1),$status,
1651 1757
 				$recur_date?$this->date2ts($recur_date,true):0,$role)))
1652 1758
 		{
1653
-			if ($status == 'R')	// remove alarms belonging to rejected participants
1759
+			if ($status == 'R')
1760
+			{
1761
+				// remove alarms belonging to rejected participants
1654 1762
 			{
1655 1763
 				foreach(is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1656 1764
 				{
1657 1765
 					if ((string)$alarm['owner'] === (string)$uid)
1658 1766
 					{
1659 1767
 						$this->so->delete_alarm($id);
1768
+			}
1660 1769
 						//error_log(__LINE__.': '.__METHOD__."(".array2string($event).", '$uid', '$status', ...) deleting alarm=".array2string($alarm).", $status=".array2string($alarm));
1661 1770
 					}
1662 1771
 				}
@@ -1673,8 +1782,15 @@  discard block
 block discarded – undo
1673 1782
 
1674 1783
 			if (isset($status2msg[$status]) && !$skip_notification)
1675 1784
 			{
1676
-				if (!is_array($event)) $event = $this->read($cal_id);
1677
-				if (isset($recur_date)) $event = $this->read($event['id'],$recur_date); //re-read the actually edited recurring event
1785
+				if (!is_array($event))
1786
+				{
1787
+					$event = $this->read($cal_id);
1788
+				}
1789
+				if (isset($recur_date))
1790
+				{
1791
+					$event = $this->read($event['id'],$recur_date);
1792
+				}
1793
+				//re-read the actually edited recurring event
1678 1794
 				$user_id = is_numeric($uid) ? (int)$uid : $uid;
1679 1795
 				$this->send_update($status2msg[$status],$event['participants'],$event, null, $user_id);
1680 1796
 			}
@@ -1698,12 +1814,16 @@  discard block
 block discarded – undo
1698 1814
 	 */
1699 1815
 	function update_status($new_event, $old_event , $recur_date=0, $skip_notification=false)
1700 1816
 	{
1701
-		if (!isset($new_event['participants'])) return;
1817
+		if (!isset($new_event['participants']))
1818
+		{
1819
+			return;
1820
+		}
1702 1821
 
1703 1822
 		// check the old list against the new list
1704 1823
 		foreach ($old_event['participants'] as $userid => $status)
1705
-  		{
1706
-            if (!isset($new_event['participants'][$userid])){
1824
+		{
1825
+            if (!isset($new_event['participants'][$userid]))
1826
+            {
1707 1827
             	// Attendee will be deleted this way
1708 1828
             	$new_event['participants'][$userid] = 'G';
1709 1829
             }
@@ -1786,7 +1906,10 @@  discard block
 block discarded – undo
1786 1906
 					}
1787 1907
 					else
1788 1908
 					{
1789
-						if (!($exception = $this->read($id))) continue;
1909
+						if (!($exception = $this->read($id)))
1910
+						{
1911
+							continue;
1912
+						}
1790 1913
 						$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
1791 1914
 						$exception['reference'] = $exception['recurrence'] = 0;
1792 1915
 						$this->update($exception, true, true, false, true, $msg=null, true);
@@ -1857,7 +1980,10 @@  discard block
 block discarded – undo
1857 1980
 		$event_arr = $this->event2array($event);
1858 1981
 		foreach($event_arr as $key => $val)
1859 1982
 		{
1860
-			if ($key == 'recur_type') $key = 'repetition';
1983
+			if ($key == 'recur_type')
1984
+			{
1985
+				$key = 'repetition';
1986
+			}
1861 1987
 			$details[$key] = $val['data'];
1862 1988
 		}
1863 1989
 		$details['participants'] = $details['participants'] ? implode("\n",$details['participants']) : '';
@@ -1866,7 +1992,10 @@  discard block
 block discarded – undo
1866 1992
 		$eventStart_arr = $this->date2array($event['start']); // give this as 'date' to the link to pick the right recurrence for the participants state
1867 1993
 		$link = $GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=calendar.calendar_uiforms.edit&cal_id='.$event['id'].'&date='.$eventStart_arr['full'].'&no_popup=1&ajax=true';
1868 1994
 		// if url is only a path, try guessing the rest ;-)
1869
-		if ($link[0] == '/') $link = Api\Framework::getUrl($link);
1995
+		if ($link[0] == '/')
1996
+		{
1997
+			$link = Api\Framework::getUrl($link);
1998
+		}
1870 1999
 		$event_arr['link']['data'] = $details['link'] = $link;
1871 2000
 
1872 2001
 		/* this is needed for notification-app
@@ -2039,7 +2168,10 @@  discard block
 block discarded – undo
2039 2168
 	 */
2040 2169
 	function check_move_alarms(Array &$event, Array $old_event = null, $instance_date = null)
2041 2170
 	{
2042
-		if ($old_event !== null && $event['start'] == $old_event['start']) return;
2171
+		if ($old_event !== null && $event['start'] == $old_event['start'])
2172
+		{
2173
+			return;
2174
+		}
2043 2175
 
2044 2176
 		$time = new Api\DateTime($event['start']);
2045 2177
 		if(!is_array($event['alarm']))
@@ -2122,7 +2254,10 @@  discard block
 block discarded – undo
2122 2254
 		if (is_array($old_event) || $old_event > 0)
2123 2255
 		{
2124 2256
 			// preserve categories without users read access
2125
-			if (!is_array($old_event)) $old_event = $this->read($old_event);
2257
+			if (!is_array($old_event))
2258
+			{
2259
+				$old_event = $this->read($old_event);
2260
+			}
2126 2261
 			$old_categories = explode(',',$old_event['category']);
2127 2262
 			$old_cats_preserve = array();
2128 2263
 			if (is_array($old_categories) && count($old_categories) > 0)
@@ -2213,7 +2348,10 @@  discard block
 block discarded – undo
2213 2348
 				"($filter)[EVENT]:" . array2string($event)."\n",3,$this->logfile);
2214 2349
 		}
2215 2350
 
2216
-		if (!isset($event['recurrence'])) $event['recurrence'] = 0;
2351
+		if (!isset($event['recurrence']))
2352
+		{
2353
+			$event['recurrence'] = 0;
2354
+		}
2217 2355
 
2218 2356
 		if ($filter == 'master')
2219 2357
 		{
@@ -2267,19 +2405,26 @@  discard block
 block discarded – undo
2267 2405
 							$matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['recurrence'];
2268 2406
 						}
2269 2407
 					}
2270
-				} elseif ($filter != 'master' && ($filter == 'exact' ||
2408
+				}
2409
+				elseif ($filter != 'master' && ($filter == 'exact' ||
2271 2410
 							$event['recur_type'] == $egwEvent['recur_type'] &&
2272 2411
 							strpos($egwEvent['title'], $event['title']) === 0))
2273 2412
 				{
2274 2413
 					$matchingEvents[] = $egwEvent['id']; // we found the event
2275 2414
 				}
2276 2415
 			}
2277
-			if (!empty($matchingEvents) || $filter == 'exact') return $matchingEvents;
2416
+			if (!empty($matchingEvents) || $filter == 'exact')
2417
+			{
2418
+				return $matchingEvents;
2419
+			}
2278 2420
 		}
2279 2421
 		unset($event['id']);
2280 2422
 
2281 2423
 		// No chance to find a master without [U]ID
2282
-		if ($filter == 'master' && empty($event['uid'])) return $matchingEvents;
2424
+		if ($filter == 'master' && empty($event['uid']))
2425
+		{
2426
+			return $matchingEvents;
2427
+		}
2283 2428
 
2284 2429
 		// only query calendars of users, we have READ-grants from
2285 2430
 		$users = array();
@@ -2288,17 +2433,23 @@  discard block
 block discarded – undo
2288 2433
 			$user = trim($user);
2289 2434
 			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY,0,$user))
2290 2435
 			{
2291
-				if ($user && !in_array($user,$users))	// already added?
2436
+				if ($user && !in_array($user,$users))
2437
+				{
2438
+					// already added?
2292 2439
 				{
2293 2440
 					$users[] = $user;
2294 2441
 				}
2442
+				}
2295 2443
 			}
2296 2444
 			elseif ($GLOBALS['egw']->accounts->get_type($user) != 'g')
2297 2445
 			{
2298 2446
 				continue;	// for non-groups (eg. users), we stop here if we have no read-rights
2299 2447
 			}
2300 2448
 			// the further code is only for real users
2301
-			if (!is_numeric($user)) continue;
2449
+			if (!is_numeric($user))
2450
+			{
2451
+				continue;
2452
+			}
2302 2453
 
2303 2454
 			// for groups we have to include the members
2304 2455
 			if ($GLOBALS['egw']->accounts->get_type($user) == 'g')
@@ -2378,7 +2529,10 @@  discard block
 block discarded – undo
2378 2529
 			}
2379 2530
 			foreach ($matchFields as $key)
2380 2531
 			{
2381
-				if (isset($event[$key])) $query['cal_'.$key] = $event[$key];
2532
+				if (isset($event[$key]))
2533
+				{
2534
+					$query['cal_'.$key] = $event[$key];
2535
+				}
2382 2536
 			}
2383 2537
 		}
2384 2538
 
@@ -2418,7 +2572,10 @@  discard block
 block discarded – undo
2418 2572
 					'[FOUND]: ' . array2string($egwEvent)."\n",3,$this->logfile);
2419 2573
 			}
2420 2574
 
2421
-			if (in_array($egwEvent['id'], $matchingEvents)) continue;
2575
+			if (in_array($egwEvent['id'], $matchingEvents))
2576
+			{
2577
+				continue;
2578
+			}
2422 2579
 
2423 2580
 			// convert timezone id of event to tzid (iCal id like 'Europe/Berlin')
2424 2581
 			if (!$egwEvent['tz_id'] || !($egwEvent['tzid'] = calendar_timezones::id2tz($egwEvent['tz_id'])))
@@ -2585,13 +2742,16 @@  discard block
 block discarded – undo
2585 2742
 					foreach ($event['participants'] as $attendee => $status)
2586 2743
 					{
2587 2744
 						if (!isset($egwEvent['participants'][$attendee]) &&
2588
-								$attendee != $egwEvent['owner']) // ||
2745
+								$attendee != $egwEvent['owner'])
2746
+						{
2747
+							// ||
2589 2748
 							//(!$relax && $egw_event['participants'][$attendee] != $status))
2590 2749
 						{
2591 2750
 							if ($this->log)
2592 2751
 							{
2593 2752
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2594 2753
 								"() additional event['participants']: $attendee\n",3,$this->logfile);
2754
+						}
2595 2755
 							}
2596 2756
 							continue 2;
2597 2757
 						}
@@ -2913,7 +3073,10 @@  discard block
 block discarded – undo
2913 3073
 		foreach(array('start','end','recur_enddate','recurrence') as $ts)
2914 3074
 		{
2915 3075
 			// we convert here from server-time to timestamps in user-time!
2916
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
3076
+			if (isset($event[$ts]))
3077
+			{
3078
+				$event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
3079
+			}
2917 3080
 		}
2918 3081
 		// same with the recur exceptions
2919 3082
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
@@ -2941,10 +3104,13 @@  discard block
 block discarded – undo
2941 3104
 	 */
2942 3105
 	function purge($age)
2943 3106
 	{
2944
-		if (is_numeric($age) && $age > 0)	// just make sure bogus values dont delete everything
3107
+		if (is_numeric($age) && $age > 0)
3108
+		{
3109
+			// just make sure bogus values dont delete everything
2945 3110
 		{
2946 3111
 			$this->so->purge(time() - 365*24*3600*(float)$age);
2947 3112
 		}
3113
+		}
2948 3114
 	}
2949 3115
 
2950 3116
 	/**
@@ -2986,7 +3152,10 @@  discard block
 block discarded – undo
2986 3152
 					case 'no':
2987 3153
 						break;
2988 3154
 					case 'startday':
2989
-						if ($sameday) break;
3155
+						if ($sameday)
3156
+						{
3157
+							break;
3158
+						}
2990 3159
 					default:
2991 3160
 						$status_reset = true;
2992 3161
 						$event['participants'][$uid] = calendar_so::combine_status('U',$q,$r);
Please login to merge, or discard this patch.
calendar/inc/class.calendar_timegrid_etemplate_widget.inc.php 3 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
-  * Egroupware
4
-  * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
5
-  * @link http://www.egroupware.org
6
-  * @author Nathan Gray
7
-  * @version $Id$
8
-  */
3
+ * Egroupware
4
+ * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
5
+ * @link http://www.egroupware.org
6
+ * @author Nathan Gray
7
+ * @version $Id$
8
+ */
9 9
 
10 10
 use EGroupware\Api;
11 11
 use EGroupware\Api\Etemplate;
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
  {
23 23
 
24 24
 	 /**
25
-	 * Set up what we know on the server side.
26
-	 *
27
-	 * Sending a first chunk of rows
28
-	 *
29
-	 * @param string $cname
30
-	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
31
-	 */
25
+	  * Set up what we know on the server side.
26
+	  *
27
+	  * Sending a first chunk of rows
28
+	  *
29
+	  * @param string $cname
30
+	  * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
31
+	  */
32 32
 	public function beforeSendToClient($cname, array $expand=null)
33 33
 	{
34 34
 		$form_name = self::form_name($cname, $this->id, $expand);
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,24 +29,24 @@
 block discarded – undo
29 29
 	 * @param string $cname
30 30
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
31 31
 	 */
32
-	public function beforeSendToClient($cname, array $expand=null)
32
+	public function beforeSendToClient($cname, array $expand = null)
33 33
 	{
34 34
 		$form_name = self::form_name($cname, $this->id, $expand);
35
-		$value =& self::get_array(self::$request->content, $form_name, true);
36
-		if(!is_array($value)) $value = array();
35
+		$value = & self::get_array(self::$request->content, $form_name, true);
36
+		if (!is_array($value)) $value = array();
37 37
 
38
-		foreach($value as &$events)
38
+		foreach ($value as &$events)
39 39
 		{
40
-			if(!is_array($events))
40
+			if (!is_array($events))
41 41
 			{
42 42
 				continue;
43 43
 			}
44
-			foreach($events as &$event)
44
+			foreach ($events as &$event)
45 45
 			{
46
-				if(!is_array($event)) continue;
47
-				foreach(array('start','end') as $date)
46
+				if (!is_array($event)) continue;
47
+				foreach (array('start', 'end') as $date)
48 48
 				{
49
-					$event[$date] = Api\DateTime::to($event[$date],'Y-m-d\TH:i:s\Z');
49
+					$event[$date] = Api\DateTime::to($event[$date], 'Y-m-d\TH:i:s\Z');
50 50
 				}
51 51
 			}
52 52
 		}
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,10 @@  discard block
 block discarded – undo
33 33
 	{
34 34
 		$form_name = self::form_name($cname, $this->id, $expand);
35 35
 		$value =& self::get_array(self::$request->content, $form_name, true);
36
-		if(!is_array($value)) $value = array();
36
+		if(!is_array($value))
37
+		{
38
+			$value = array();
39
+		}
37 40
 
38 41
 		foreach($value as &$events)
39 42
 		{
@@ -43,7 +46,10 @@  discard block
 block discarded – undo
43 46
 			}
44 47
 			foreach($events as &$event)
45 48
 			{
46
-				if(!is_array($event)) continue;
49
+				if(!is_array($event))
50
+				{
51
+					continue;
52
+				}
47 53
 				foreach(array('start','end') as $date)
48 54
 				{
49 55
 					$event[$date] = Api\DateTime::to($event[$date],'Y-m-d\TH:i:s\Z');
Please login to merge, or discard this patch.
calendar/inc/class.calendar_tracking.inc.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
 		}
133 133
 
134 134
 		/**
135
-		* Do some magic with the participants and recurrance.
136
-		* If this is one of a recurring event, append the recur_date to the participant field so we can
137
-		* filter by it later.
138
-		*/
135
+		 * Do some magic with the participants and recurrance.
136
+		 * If this is one of a recurring event, append the recur_date to the participant field so we can
137
+		 * filter by it later.
138
+		 */
139 139
 		if(is_array($data['participants']))
140 140
 		{
141 141
 			$participants = $data['participants'];
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
 	}
196 196
 
197 197
 	/**
198
-	* Do some magic with the participants and recurrance.
199
-	* If this is one of a recurring event, append the recur_date to the participant field so we can
200
-	* filter by it later.
201
-	*/
198
+	 * Do some magic with the participants and recurrance.
199
+	 * If this is one of a recurring event, append the recur_date to the participant field so we can
200
+	 * filter by it later.
201
+	 */
202 202
 	protected function alter_participants($participants)
203 203
 	{
204 204
 		$data = array();
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -114,18 +114,18 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	public function __construct()
116 116
 	{
117
-		parent::__construct('calendar');	// adds custom fields
117
+		parent::__construct('calendar'); // adds custom fields
118 118
 	}
119 119
 
120 120
 	/**
121 121
 	 * Tracks the changes in one entry $data, by comparing it with the last version in $old
122 122
 	 * Overrides parent to reformat participants into a format parent can handle
123 123
 	 */
124
-	public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null)
124
+	public function track(array $data, array $old = null, $user = null, $deleted = null, array $changed_fields = null)
125 125
 	{
126 126
 		// Don't try to track dates on recurring events.
127 127
 		// It won't change for the base event, and any change to the time creates an exception
128
-		if($data['recur_type'])
128
+		if ($data['recur_type'])
129 129
 		{
130 130
 			unset($data['start']); unset($data['end']);
131 131
 			unset($old['start']); unset($old['end']);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		* If this is one of a recurring event, append the recur_date to the participant field so we can
137 137
 		* filter by it later.
138 138
 		*/
139
-		if(is_array($data['participants']))
139
+		if (is_array($data['participants']))
140 140
 		{
141 141
 			$participants = $data['participants'];
142 142
 			$data['participants'] = array();
@@ -144,33 +144,33 @@  discard block
 block discarded – undo
144 144
 		}
145 145
 		// if clients eg. CalDAV do NOT set participants, they are left untouched
146 146
 		// therefore we should not track them, as all updates then show up as all participants removed
147
-		elseif(!isset($data['participants']))
147
+		elseif (!isset($data['participants']))
148 148
 		{
149 149
 			unset($old['participants']);
150 150
 		}
151
-		if(is_array($old['participants']))
151
+		if (is_array($old['participants']))
152 152
 		{
153 153
 			$participants = $old['participants'];
154 154
 			$old['participants'] = array();
155 155
 			$old = array_merge($old, $this->alter_participants($participants));
156 156
 		}
157 157
 		// Make sure dates are timestamps
158
-		foreach(array('start','end') as $date)
158
+		foreach (array('start', 'end') as $date)
159 159
 		{
160
-			if(is_object($data[$date]) && is_a($data[$date], 'DateTime'))
160
+			if (is_object($data[$date]) && is_a($data[$date], 'DateTime'))
161 161
 			{
162 162
 				$data[$date] = $data[$date]->format('ts');
163 163
 			}
164 164
 		}
165
-		parent::track($data,$old,$user,$deleted, $changed_fields);
165
+		parent::track($data, $old, $user, $deleted, $changed_fields);
166 166
 	}
167 167
 
168 168
 	/**
169 169
 	 * Overrides parent because calendar_boupdates handles the notifications
170 170
 	 */
171
-	public function do_notifications($data,$old,$deleted=null)
171
+	public function do_notifications($data, $old, $deleted = null)
172 172
 	{
173
-		unset($data, $old, $deleted);	// unused, but required by function signature
173
+		unset($data, $old, $deleted); // unused, but required by function signature
174 174
 		return true;
175 175
 	}
176 176
 
@@ -185,21 +185,21 @@  discard block
 block discarded – undo
185 185
 	 * @param array $old = null
186 186
 	 * @return array of keys with different values in $data and $old
187 187
 	 */
188
-	public function changed_fields(array $data,array $old=null)
188
+	public function changed_fields(array $data, array $old = null)
189 189
 	{
190
-		if(is_array($data['participants']))
190
+		if (is_array($data['participants']))
191 191
 		{
192 192
 			$participants = $data['participants'];
193 193
 			$data['participants'] = array();
194 194
 			$data = array_merge($data, $this->alter_participants($participants));
195 195
 		}
196
-		if(is_array($old['participants']))
196
+		if (is_array($old['participants']))
197 197
 		{
198 198
 			$participants = $old['participants'];
199 199
 			$old['participants'] = array();
200 200
 			$old = array_merge($old, $this->alter_participants($participants));
201 201
 		}
202
-		return parent::changed_fields($data,$old);
202
+		return parent::changed_fields($data, $old);
203 203
 	}
204 204
 
205 205
 	/**
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	protected function alter_participants($participants)
211 211
 	{
212 212
 		$data = array();
213
-		foreach($participants as $uid => $status)
213
+		foreach ($participants as $uid => $status)
214 214
 		{
215 215
 			$quantity = $role = $user_type = $user_id = null;
216 216
 			calendar_so::split_status($status, $quantity, $role);
Please login to merge, or discard this patch.
calendar/inc/class.calendar_so.inc.php 4 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1528,7 +1528,7 @@
 block discarded – undo
1528 1528
 			if (!$set_recurrences)
1529 1529
 			{
1530 1530
 				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int) $event['cal_start']) ||
1531
-				    $event['recur_type'] != $old_repeats['recur_type'] || $event['recur_data'] != $old_repeats['recur_data'] ||
1531
+					$event['recur_type'] != $old_repeats['recur_type'] || $event['recur_data'] != $old_repeats['recur_data'] ||
1532 1532
 					(int)$event['recur_interval'] != (int)$old_repeats['recur_interval'] || $event['tz_id'] != $old_tz_id;
1533 1533
 			}
1534 1534
 
Please login to merge, or discard this patch.
Upper-Lower-Casing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 			"	CASE WHEN recur_type IS NULL THEN egw_cal.range_start ELSE cal_start END AS cal_start,\n".
253 253
 			"	CASE WHEN recur_type IS NULL THEN egw_cal.range_end ELSE cal_end END AS cal_end\n".
254 254
 			// using time-limited range view, instead of complete table, give a big performance plus
255
-			"FROM $egw_cal\n".
255
+			"from $egw_cal\n".
256 256
 			"JOIN egw_cal_user ON egw_cal_user.cal_id=egw_cal.cal_id\n".
257 257
 			// need to left join dates, as egw_cal_user.recur_date is null for non-recuring event
258 258
 			"LEFT JOIN egw_cal_dates ON egw_cal_user.cal_id=egw_cal_dates.cal_id AND egw_cal_dates.cal_start=egw_cal_user.cal_recur_date\n".
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 			$where[] = 'cal_start >= '.(int)$recur_date;
346 346
 			$group_by = 'GROUP BY '.$cols;
347 347
 			$cols .= ',MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end';
348
-			$join = "JOIN $this->dates_table ON $this->cal_table.cal_id=$this->dates_table.cal_id $join";
348
+			$join = "join $this->dates_table ON $this->cal_table.cal_id=$this->dates_table.cal_id $join";
349 349
 		}
350 350
 		else
351 351
 		{
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 		$cal_table = $this->cal_range_view($start, $end, null, $filter == 'everything' ? null : $filter != 'deleted');
885 885
 		$cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table);
886 886
 
887
-		$u_join = "JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id ".
887
+		$u_join = "join $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id ".
888 888
 			"LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id ".
889 889
 			$rejected_by_user_join;
890 890
 		// dates table join only needed to enum recuring events, we use a time-range limited view here too
@@ -1415,7 +1415,7 @@  discard block
 block discarded – undo
1415 1415
 			{
1416 1416
 				$old_repeats = $this->db->select($this->repeats_table, "$this->repeats_table.*,range_end AS recur_enddate",
1417 1417
 					"$this->repeats_table.cal_id=".(int)$cal_id, __LINE__, __FILE__,
1418
-					false, '', 'calendar', 0, "JOIN $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id")->fetch();
1418
+					false, '', 'calendar', 0, "join $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id")->fetch();
1419 1419
 			}
1420 1420
 			$where = array('cal_id' => $cal_id);
1421 1421
 			// read only timezone id, to check if it is changed
@@ -1782,13 +1782,13 @@  discard block
 block discarded – undo
1782 1782
 		if ($move_start)
1783 1783
 		{
1784 1784
 			// move the recur-date of the participants
1785
-			$this->db->query("UPDATE $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ".
1785
+			$this->db->query("update $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ".
1786 1786
 				((int)$change_since ? '>= '.(int)$change_since : '!= 0'),__LINE__,__FILE__);
1787 1787
 		}
1788 1788
 		if ($move_start || $move_end)
1789 1789
 		{
1790 1790
 			// move the event and it's recurrences
1791
-			$this->db->query("UPDATE $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where".
1791
+			$this->db->query("update $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where".
1792 1792
 				((int) $change_since ? ' AND cal_start >= '.(int) $change_since : ''),__LINE__,__FILE__);
1793 1793
 		}
1794 1794
 		return $this->db->affected_rows();
@@ -2488,7 +2488,7 @@  discard block
 block discarded – undo
2488 2488
 			),__LINE__,__FILE__,'calendar');
2489 2489
 
2490 2490
 			// delete calendar entries without participants (can happen if the deleted user is the only participants, but not the owner)
2491
-			foreach($this->db->select($this->cal_table,"DISTINCT $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__,
2491
+			foreach($this->db->select($this->cal_table,"distinct $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__,
2492 2492
 				False,'','calendar',0,"LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2493 2493
 			{
2494 2494
 				$this->delete($row['cal_id']);
Please login to merge, or discard this patch.
Braces   +366 added lines, -96 removed lines patch added patch discarded remove patch
@@ -159,16 +159,32 @@  discard block
 block discarded – undo
159 159
 	 */
160 160
 	protected function cal_range_view($start, $end, array $_where=null, $deleted=false)
161 161
 	{
162
-		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start)	// using view without start-date is slower!
162
+		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start)
163 163
 		{
164
-			return $this->cal_table;	// no need / use for a view
164
+			// using view without start-date is slower!
165
+		{
166
+			return $this->cal_table;
167
+		}
168
+		// no need / use for a view
165 169
 		}
166 170
 
167 171
 		$where = array();
168
-		if (isset($deleted)) $where[] = "cal_deleted IS ".($deleted ? '' : 'NOT').' NULL';
169
-		if ($end) $where[] = "range_start<".(int)$end;
170
-		if ($start) $where[] = "(range_end IS NULL OR range_end>".(int)$start.")";
171
-		if ($_where) $where = array_merge($where, $_where);
172
+		if (isset($deleted))
173
+		{
174
+			$where[] = "cal_deleted IS ".($deleted ? '' : 'NOT').' NULL';
175
+		}
176
+		if ($end)
177
+		{
178
+			$where[] = "range_start<".(int)$end;
179
+		}
180
+		if ($start)
181
+		{
182
+			$where[] = "(range_end IS NULL OR range_end>".(int)$start.")";
183
+		}
184
+		if ($_where)
185
+		{
186
+			$where = array_merge($where, $_where);
187
+		}
172 188
 
173 189
 		$sql = "(SELECT * FROM $this->cal_table WHERE ".$this->db->expression($this->cal_table, $where).") $this->cal_table";
174 190
 
@@ -189,16 +205,32 @@  discard block
 block discarded – undo
189 205
 	 */
190 206
 	protected function dates_range_view($start, $end, array $_where=null, $deleted=false)
191 207
 	{
192
-		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end)	// using view without start- AND end-date is slower!
208
+		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end)
209
+		{
210
+			// using view without start- AND end-date is slower!
193 211
 		{
194
-			return $this->dates_table;	// no need / use for a view
212
+			return $this->dates_table;
213
+		}
214
+		// no need / use for a view
195 215
 		}
196 216
 
197 217
 		$where = array();
198
-		if (isset($deleted)) $where['recur_exception'] = $deleted;
199
-		if ($end) $where[] = "cal_start<".(int)$end;
200
-		if ($start) $where[] = "cal_end>".(int)$start;
201
-		if ($_where) $where = array_merge($where, $_where);
218
+		if (isset($deleted))
219
+		{
220
+			$where['recur_exception'] = $deleted;
221
+		}
222
+		if ($end)
223
+		{
224
+			$where[] = "cal_start<".(int)$end;
225
+		}
226
+		if ($start)
227
+		{
228
+			$where[] = "cal_end>".(int)$start;
229
+		}
230
+		if ($_where)
231
+		{
232
+			$where = array_merge($where, $_where);
233
+		}
202 234
 
203 235
 		// Api\Db::union uses Api\Db::select which check if join contains "WHERE"
204 236
 		// to support old join syntax like ", other_table WHERE ...",
@@ -248,7 +280,10 @@  discard block
 block discarded – undo
248 280
 			throw new Api\Exception\AssertionFailed("Unsupported value for parameters!");
249 281
 		}
250 282
 		$where = is_array($params['query']) ? $params['query'] : array();
251
-		if ($cat_id) $where[] = $this->cat_filter($cat_id);
283
+		if ($cat_id)
284
+		{
285
+			$where[] = $this->cat_filter($cat_id);
286
+		}
252 287
 		$egw_cal = $this->cal_range_view($start, $end, $where, $filter == 'everything' ? null : $filter != 'deleted');
253 288
 
254 289
 		$status_filter = $this->status_filter($filter, $params['enum_recuring']);
@@ -269,7 +304,10 @@  discard block
 block discarded – undo
269 304
 		if ($users)
270 305
 		{
271 306
 			// fix $users to also prefix system users and groups (with 'u')
272
-			if (!is_array($users)) $users = $users ? (array)$users : array();
307
+			if (!is_array($users))
308
+			{
309
+				$users = $users ? (array)$users : array();
310
+			}
273 311
 			foreach($users as &$uid)
274 312
 			{
275 313
 				$user_type = $user_id = null;
@@ -289,15 +327,22 @@  discard block
 block discarded – undo
289 327
 			$sql .= " AND\n	".$params['sql_filter'];
290 328
 		}
291 329
 
292
-		if ($params['order'])	// only order if requested
330
+		if ($params['order'])
293 331
 		{
294
-			if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
332
+			// only order if requested
333
+		{
334
+			if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';
335
+		}
336
+		// gard against SQL injection
295 337
 			$sql .= "\nORDER BY ".$params['order'];
296 338
 		}
297 339
 
298
-		if ($offset === false)	// return all rows --> Api\Db::query wants offset=0, num_rows=-1
340
+		if ($offset === false)
341
+		{
342
+			// return all rows --> Api\Db::query wants offset=0, num_rows=-1
299 343
 		{
300 344
 			$offset = 0;
345
+		}
301 346
 			$num_rows = -1;
302 347
 		}
303 348
 		$events =& $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows));
@@ -324,10 +369,13 @@  discard block
 block discarded – undo
324 369
 		$join = "LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id";
325 370
 
326 371
 		$where = array();
327
-		if (is_scalar($ids) && !is_numeric($ids))	// a single uid
372
+		if (is_scalar($ids) && !is_numeric($ids))
373
+		{
374
+			// a single uid
328 375
 		{
329 376
 			// We want only the parents to match
330 377
 			$where['cal_uid'] = $ids;
378
+		}
331 379
 			if ($read_recurrence)
332 380
 			{
333 381
 				$where['cal_recurrence'] = $recur_date;
@@ -337,20 +385,26 @@  discard block
 block discarded – undo
337 385
 				$where['cal_reference'] = 0;
338 386
 			}
339 387
 		}
340
-		elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids))	// one or more cal_id's
388
+		elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids))
389
+		{
390
+			// one or more cal_id's
341 391
 		{
342 392
 			$where['cal_id'] = $ids;
343 393
 		}
394
+		}
344 395
 		else	// array with column => value pairs
345 396
 		{
346 397
 			$where = $ids;
347 398
 			unset($ids);	// otherwise users get not read!
348 399
 		}
349
-		if (isset($where['cal_id']))	// prevent non-unique column-name cal_id
400
+		if (isset($where['cal_id']))
401
+		{
402
+			// prevent non-unique column-name cal_id
350 403
 		{
351 404
 			$where[] = $this->db->expression($this->cal_table, $this->cal_table.'.',array(
352 405
 				'cal_id' => $where['cal_id'],
353 406
 			));
407
+		}
354 408
 			unset($where['cal_id']);
355 409
 		}
356 410
 		if ((int) $recur_date && !$read_recurrence)
@@ -406,10 +460,16 @@  discard block
 block discarded – undo
406 460
 			$row['recur_exception'] = $row['alarm'] = array();
407 461
 			$events[$row['cal_id']] = Api\Db::strip_array_keys($row,'cal_');
408 462
 		}
409
-		if (!$events) return $events;
463
+		if (!$events)
464
+		{
465
+			return $events;
466
+		}
410 467
 
411 468
 		$ids = array_keys($events);
412
-		if (count($ids) == 1) $ids = $ids[0];
469
+		if (count($ids) == 1)
470
+		{
471
+			$ids = $ids[0];
472
+		}
413 473
 
414 474
 		foreach ($events as &$event)
415 475
 		{
@@ -483,10 +543,13 @@  discard block
 block discarded – undo
483 543
 			'cal_id'      => $ids,
484 544
 			'cal_recur_date' => $recur_date,
485 545
 			"cal_status NOT IN ('X','E')",
486
-		),__LINE__,__FILE__,false,'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT,'calendar') as $row)	// DESC puts users before resources and contacts
546
+		),__LINE__,__FILE__,false,'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT,'calendar') as $row)
547
+		{
548
+			// DESC puts users before resources and contacts
487 549
 		{
488 550
 			// combine all participant data in uid and status values
489 551
 			$uid    = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
552
+		}
490 553
 			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
491 554
 
492 555
 			$events[$row['cal_id']]['participants'][$uid] = $status;
@@ -543,7 +606,10 @@  discard block
 block discarded – undo
543 606
 			$last_request = time();
544 607
 		}
545 608
 		$signature = serialize(func_get_args());
546
-		if (isset($ctags[$signature])) return $ctags[$signature];
609
+		if (isset($ctags[$signature]))
610
+		{
611
+			return $ctags[$signature];
612
+		}
547 613
 
548 614
 		$types = array();
549 615
 		foreach((array)$users as $uid)
@@ -576,7 +642,10 @@  discard block
 block discarded – undo
576 642
 			// owner can only by users, no groups or resources
577 643
 			foreach($users as $key => $user)
578 644
 			{
579
-				if (!($user > 0)) unset($users[$key]);
645
+				if (!($user > 0))
646
+				{
647
+					unset($users[$key]);
648
+				}
580 649
 			}
581 650
 			$where = $this->db->expression($this->user_table, '(', $where, ' OR ').
582 651
 				$this->db->expression($this->cal_table, array(
@@ -598,7 +667,10 @@  discard block
 block discarded – undo
598 667
 	 */
599 668
 	function get_cal_data(array $query, $cols='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified')
600 669
 	{
601
-		if (!is_array($cols)) $cols = explode(',', $cols);
670
+		if (!is_array($cols))
671
+		{
672
+			$cols = explode(',', $cols);
673
+		}
602 674
 
603 675
 		// special handling of cal_user_modified "pseudo" column
604 676
 		if (($key = array_search('cal_user_modified', $cols)) !== false)
@@ -627,7 +699,10 @@  discard block
 block discarded – undo
627 699
 				unset($key);	// not used, but required by function signature
628 700
 				$val = (int) $val;
629 701
 			});
630
-			if (is_array($cat_id) && count($cat_id)==1) $cat_id = $cat_id[0];
702
+			if (is_array($cat_id) && count($cat_id)==1)
703
+			{
704
+				$cat_id = $cat_id[0];
705
+			}
631 706
 			$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '='.$this->db->quote((int)$cat_id));
632 707
 			foreach($cats as $cat)
633 708
 			{
@@ -686,10 +761,13 @@  discard block
 block discarded – undo
686 761
 				$where[] = "$this->user_table.cal_status NOT IN ('X','E')";
687 762
 				break;
688 763
 			default:
689
-				if ($enum_recuring)	// regular UI
764
+				if ($enum_recuring)
765
+				{
766
+					// regular UI
690 767
 				{
691 768
 					$where[] = "$this->user_table.cal_status NOT IN ('R','X','E')";
692 769
 				}
770
+				}
693 771
 				else	// CalDAV / eSync / iCal need to include 'E' = exceptions
694 772
 				{
695 773
 					$where[] = "$this->user_table.cal_status NOT IN ('R','X')";
@@ -831,7 +909,10 @@  discard block
 block discarded – undo
831 909
 						$user_ids = array();
832 910
 						foreach($ids as $user_id)
833 911
 						{
834
-							if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u') $user_ids[] = $user_id;
912
+							if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u')
913
+							{
914
+								$user_ids[] = $user_id;
915
+							}
835 916
 						}
836 917
 						$owner_or = $this->db->expression($cal_table_def,array('cal_owner' => $user_ids));
837 918
 					}
@@ -851,7 +932,10 @@  discard block
 block discarded – undo
851 932
 				}
852 933
 			}
853 934
 			// this is only used, when we cannot use UNIONS
854
-			if (!$useUnionQuery) $where[] = '('.implode(' OR ',$to_or).')';
935
+			if (!$useUnionQuery)
936
+			{
937
+				$where[] = '('.implode(' OR ',$to_or).')';
938
+			}
855 939
 
856 940
 			$where = $this->status_filter($filter, $params['enum_recuring'], $where);
857 941
 		}
@@ -870,7 +954,11 @@  discard block
 block discarded – undo
870 954
 				$where[] = '('.((int)$start).' < range_end OR range_end IS NULL)';
871 955
 			}
872 956
 		}
873
-		if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
957
+		if (!preg_match('/^[a-z_ ,c]+$/i',$params['order']))
958
+		{
959
+			$params['order'] = 'cal_start';
960
+		}
961
+		// gard against SQL injection
874 962
 
875 963
 		// if not enum recuring events, we have to use minimum start- AND end-dates, otherwise we get more then one event per cal_id!
876 964
 		if (!$params['enum_recuring'])
@@ -880,9 +968,15 @@  discard block
 block discarded – undo
880 968
 			// in case cal_start is used in a query, eg. calendar_ical::find_event
881 969
 			$where = str_replace(array('cal_start','cal_end'), array('range_start','(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id)'), $where);
882 970
 			$params['order'] = str_replace('cal_start', 'range_start', $params['order']);
883
-			if ($end) $where[] = (int)$end.' > range_start';
971
+			if ($end)
972
+			{
973
+				$where[] = (int)$end.' > range_start';
974
+			}
884 975
   		}
885
-		elseif ($end) $where[] = (int)$end.' > cal_start';
976
+  		elseif ($end)
977
+		{
978
+			$where[] = (int)$end.' > cal_start';
979
+		}
886 980
 
887 981
 		if ($remove_rejected_by_user && $filter != 'everything')
888 982
 		{
@@ -896,7 +990,10 @@  discard block
 block discarded – undo
896 990
 				'rejected_by_user.cal_status IS NULL',
897 991
 				"rejected_by_user.cal_status NOT IN ('R','X')",
898 992
 			);
899
-			if ($filter == 'owner') $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user;
993
+			if ($filter == 'owner')
994
+			{
995
+				$or_required[] = 'cal_owner='.(int)$remove_rejected_by_user;
996
+			}
900 997
 			$where[] = '('.implode(' OR ',$or_required).')';
901 998
 		}
902 999
 		// using a time-range and deleted attribute limited view instead of full table
@@ -939,7 +1036,10 @@  discard block
 block discarded – undo
939 1036
 		if ($useUnionQuery)
940 1037
 		{
941 1038
 			// allow apps to supply participants and/or icons
942
-			if (!isset($params['cols'])) $cols .= ',NULL AS participants,NULL AS icons';
1039
+			if (!isset($params['cols']))
1040
+			{
1041
+				$cols .= ',NULL AS participants,NULL AS icons';
1042
+			}
943 1043
 
944 1044
 			// changed the original OR in the query into a union, to speed up the query execution under MySQL 5
945 1045
 			// with time-range views benefit is now at best slim for huge tables or none at all!
@@ -994,9 +1094,12 @@  discard block
 block discarded – undo
994 1094
 					$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
995 1095
 				}
996 1096
 			}
997
-			if (is_numeric($offset) && !$params['no_total'])	// get the total too
1097
+			if (is_numeric($offset) && !$params['no_total'])
1098
+			{
1099
+				// get the total too
998 1100
 			{
999 1101
 				$save_selects = $selects;
1102
+			}
1000 1103
 				// we only select cal_table.cal_id (and not cal_table.*) to be able to use DISTINCT (eg. MsSQL does not allow it for text-columns)
1001 1104
 				foreach(array_keys($selects) as $key)
1002 1105
 				{
@@ -1007,14 +1110,20 @@  discard block
 block discarded – undo
1007 1110
 							array('range_start AS cal_start','range_end AS cal_end'), $selects[$key]['cols']);
1008 1111
 					}
1009 1112
 				}
1010
-				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1113
+				if (!isset($params['cols']) && !$params['no_integration'])
1114
+				{
1115
+					self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1116
+				}
1011 1117
 
1012 1118
 				$this->total = $this->db->union($selects,__LINE__,__FILE__)->NumRows();
1013 1119
 
1014 1120
 				// restore original cols / selects
1015 1121
 				$selects = $save_selects; unset($save_selects);
1016 1122
 			}
1017
-			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1123
+			if (!isset($params['cols']) && !$params['no_integration'])
1124
+			{
1125
+				self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1126
+			}
1018 1127
 
1019 1128
 			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
1020 1129
 		}
@@ -1032,9 +1141,12 @@  discard block
 block discarded – undo
1032 1141
 				'table_def' => $cal_table_def,
1033 1142
 			));
1034 1143
 
1035
-			if (is_numeric($offset) && !$params['no_total'])	// get the total too
1144
+			if (is_numeric($offset) && !$params['no_total'])
1145
+			{
1146
+				// get the total too
1036 1147
 			{
1037 1148
 				$save_selects = $selects;
1149
+			}
1038 1150
 				// we only select cal_table.cal_id (and not cal_table.*) to be able to use DISTINCT (eg. MsSQL does not allow it for text-columns)
1039 1151
 				$selects[0]['cols'] = "$this->cal_table.cal_id,cal_start";
1040 1152
 				if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
@@ -1062,7 +1174,10 @@  discard block
 block discarded – undo
1062 1174
 		foreach($rs as $row)
1063 1175
 		{
1064 1176
 			$id = $row['cal_id'];
1065
-			if (is_numeric($id)) $ids[] = $id;
1177
+			if (is_numeric($id))
1178
+			{
1179
+				$ids[] = $id;
1180
+			}
1066 1181
 
1067 1182
 			if ($row['cal_recur_date'])
1068 1183
 			{
@@ -1082,7 +1197,10 @@  discard block
 block discarded – undo
1082 1197
 			$row['recur_exception'] = $row['alarm'] = array();
1083 1198
 
1084 1199
 			// compile a list of recurrences per cal_id
1085
-			if (!in_array($id,(array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1200
+			if (!in_array($id,(array)$recur_ids[$row['cal_id']]))
1201
+			{
1202
+				$recur_ids[$row['cal_id']][] = $id;
1203
+			}
1086 1204
 
1087 1205
 			$events[$id] = Api\Db::strip_array_keys($row,'cal_');
1088 1206
 		}
@@ -1101,10 +1219,16 @@  discard block
 block discarded – undo
1101 1219
 					//'cal_id' => array_unique($ids),
1102 1220
 					'cal_recur_date' => $recur_dates,
1103 1221
 				),__LINE__,__FILE__,false,'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT,'calendar',-1,$join='',
1104
-				$this->db->get_table_definitions('calendar',$this->user_table)) as $row)	// DESC puts users before resources and contacts
1222
+				$this->db->get_table_definitions('calendar',$this->user_table)) as $row)
1223
+			{
1224
+				// DESC puts users before resources and contacts
1105 1225
 			{
1106 1226
 				$id = $row['cal_id'];
1107
-				if ($row['cal_recur_date']) $id .= '-'.$row['cal_recur_date'];
1227
+			}
1228
+				if ($row['cal_recur_date'])
1229
+				{
1230
+					$id .= '-'.$row['cal_recur_date'];
1231
+				}
1108 1232
 
1109 1233
 				// combine all participant data in uid and status values
1110 1234
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
@@ -1123,7 +1247,10 @@  discard block
 block discarded – undo
1123 1247
 				}
1124 1248
 
1125 1249
 				// set data, if recurrence is requested
1126
-				if (isset($events[$id])) $events[$id]['participants'][$uid] = $status;
1250
+				if (isset($events[$id]))
1251
+				{
1252
+					$events[$id]['participants'][$uid] = $status;
1253
+				}
1127 1254
 			}
1128 1255
 			// query recurrance exceptions, if needed: enum_recuring && !daywise is used in calendar_groupdav::get_series($uid,...)
1129 1256
 			if (!$params['enum_recuring'] || !$params['daywise'])
@@ -1139,7 +1266,10 @@  discard block
 block discarded – undo
1139 1266
 					{
1140 1267
 						foreach($events as $id => $event)
1141 1268
 						{
1142
-							if ($event['id'] == $row['cal_id']) break;
1269
+							if ($event['id'] == $row['cal_id'])
1270
+							{
1271
+								break;
1272
+							}
1143 1273
 						}
1144 1274
 					}
1145 1275
 					$events[$id]['recur_exception'][] = $row['cal_start'];
@@ -1149,7 +1279,10 @@  discard block
 block discarded – undo
1149 1279
 			if (!is_null($params['cfs']))
1150 1280
 			{
1151 1281
 				$where = array('cal_id' => $ids);
1152
-				if ($params['cfs']) $where['cal_extra_name'] = $params['cfs'];
1282
+				if ($params['cfs'])
1283
+				{
1284
+					$where['cal_extra_name'] = $params['cfs'];
1285
+				}
1153 1286
 				foreach($this->db->select($this->extra_table,'*',$where,
1154 1287
 					__LINE__,__FILE__,false,'','calendar') as $row)
1155 1288
 				{
@@ -1169,14 +1302,20 @@  discard block
 block discarded – undo
1169 1302
 				{
1170 1303
 					$event_start = $alarm['time'] + $alarm['offset'];
1171 1304
 
1172
-					if (isset($events[$cal_id]))	// none recuring event
1305
+					if (isset($events[$cal_id]))
1306
+					{
1307
+						// none recuring event
1173 1308
 					{
1174 1309
 						$events[$cal_id]['alarm'][$id] = $alarm;
1175 1310
 					}
1176
-					elseif (isset($events[$cal_id.'-'.$event_start]))	// recuring event
1311
+					}
1312
+					elseif (isset($events[$cal_id.'-'.$event_start]))
1313
+					{
1314
+						// recuring event
1177 1315
 					{
1178 1316
 						$events[$cal_id.'-'.$event_start]['alarm'][$id] = $alarm;
1179 1317
 					}
1318
+					}
1180 1319
 				}
1181 1320
 			}
1182 1321
 		}
@@ -1276,10 +1415,13 @@  discard block
 block discarded – undo
1276 1415
 			}
1277 1416
 			foreach((array)$cols as $col)
1278 1417
 			{
1279
-				if (substr($col,0,7) == 'egw_cal')	// remove table name
1418
+				if (substr($col,0,7) == 'egw_cal')
1419
+				{
1420
+					// remove table name
1280 1421
 				{
1281 1422
 					$col = preg_replace('/^egw_cal[a-z_]*\./','',$col);
1282 1423
 				}
1424
+				}
1283 1425
 				if (isset($app_cols[$col]))
1284 1426
 				{
1285 1427
 					$return_cols[] = $app_cols[$col];
@@ -1373,7 +1515,11 @@  discard block
 block discarded – undo
1373 1515
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
1374 1516
 		{
1375 1517
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
1376
-			if (empty($minimum_uid_length) || $minimum_uid_length<=1) $minimum_uid_length = 8; // we just do not accept no uid, or uid way to short!
1518
+			if (empty($minimum_uid_length) || $minimum_uid_length<=1)
1519
+			{
1520
+				$minimum_uid_length = 8;
1521
+			}
1522
+			// we just do not accept no uid, or uid way to short!
1377 1523
 		}
1378 1524
 		else
1379 1525
 		{
@@ -1404,7 +1550,10 @@  discard block
 block discarded – undo
1404 1550
 			}
1405 1551
 		}
1406 1552
 		// set range_start/_end, but only if we have cal_start/_end, as otherwise we destroy present values!
1407
-		if (isset($event['cal_start'])) $event['range_start'] = $event['cal_start'];
1553
+		if (isset($event['cal_start']))
1554
+		{
1555
+			$event['range_start'] = $event['cal_start'];
1556
+		}
1408 1557
 		if (isset($event['cal_end']))
1409 1558
 		{
1410 1559
 			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] :
@@ -1425,7 +1574,10 @@  discard block
 block discarded – undo
1425 1574
 		$event['cal_category'] = implode(',',$categories);
1426 1575
 
1427 1576
 		// make sure recurring events never reference to an other recurrent event
1428
-		if ($event['recur_type'] != MCAL_RECUR_NONE) $event['cal_reference'] = 0;
1577
+		if ($event['recur_type'] != MCAL_RECUR_NONE)
1578
+		{
1579
+			$event['cal_reference'] = 0;
1580
+		}
1429 1581
 
1430 1582
 		if ($cal_id)
1431 1583
 		{
@@ -1442,7 +1594,10 @@  discard block
 block discarded – undo
1442 1594
 			{
1443 1595
 				$old_tz_id = $this->db->select($this->cal_table,'tz_id',$where,__LINE__,__FILE__,'calendar')->fetchColumn();
1444 1596
 			}
1445
-			if (!is_null($etag)) $where['cal_etag'] = $etag;
1597
+			if (!is_null($etag))
1598
+			{
1599
+				$where['cal_etag'] = $etag;
1600
+			}
1446 1601
 
1447 1602
 			unset($event['cal_etag']);
1448 1603
 			$event[] = 'cal_etag=COALESCE(cal_etag,0)+1';	// always update the etag, even if none given to check
@@ -1453,14 +1608,24 @@  discard block
 block discarded – undo
1453 1608
 			{
1454 1609
 				return 0;	// wrong etag, someone else updated the entry
1455 1610
 			}
1456
-			if (!is_null($etag)) ++$etag;
1611
+			if (!is_null($etag))
1612
+			{
1613
+				++$etag;
1614
+			}
1457 1615
 		}
1458 1616
 		else
1459 1617
 		{
1460 1618
 			// new event
1461
-			if (!$event['cal_owner']) $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id'];
1619
+			if (!$event['cal_owner'])
1620
+			{
1621
+				$event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id'];
1622
+			}
1462 1623
 
1463
-			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = '';	// uid is NOT NULL!
1624
+			if (!$event['cal_id'] && !isset($event['cal_uid']))
1625
+			{
1626
+				$event['cal_uid'] = '';
1627
+			}
1628
+			// uid is NOT NULL!
1464 1629
 
1465 1630
 			$event['cal_etag'] = $etag = 0;
1466 1631
 			$this->db->insert($this->cal_table,$event,false,__LINE__,__FILE__,'calendar');
@@ -1612,8 +1777,7 @@  discard block
 block discarded – undo
1612 1777
 					// recurrences need to be truncated
1613 1778
 					if((int)$event['recur_enddate'] > 0 &&
1614 1779
 						((int)$old_repeats['recur_enddate'] == 0 || (int)$old_repeats['recur_enddate'] > (int)$event['recur_enddate'])
1615
-					)
1616
-					{
1780
+					) {
1617 1781
 						$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1618 1782
 						$this->db->delete($this->dates_table,array('cal_id' => $cal_id,'cal_start >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1619 1783
 					}
@@ -1621,8 +1785,7 @@  discard block
 block discarded – undo
1621 1785
 					// recurrences need to be expanded
1622 1786
 					if(((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1623 1787
 						|| ((int)$event['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] < (int)$event['recur_enddate'])
1624
-					)
1625
-					{
1788
+					) {
1626 1789
 						$set_recurrences = true;
1627 1790
 						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1*DAY_s);
1628 1791
 					}
@@ -1771,12 +1934,18 @@  discard block
 block discarded – undo
1771 1934
 	{
1772 1935
 		//echo "<p>socal::move($cal_id,$start,$end,$change_since,$old_start,$old_end)</p>\n";
1773 1936
 
1774
-		if (!(int) $cal_id) return false;
1937
+		if (!(int) $cal_id)
1938
+		{
1939
+			return false;
1940
+		}
1775 1941
 
1776 1942
 		if (!$old_start)
1777 1943
 		{
1778
-			if ($change_since !== false) $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1944
+			if ($change_since !== false)
1945
+			{
1946
+				$row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1779 1947
 				array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetch();
1948
+			}
1780 1949
 			// if no recurrence found, create one with the new dates
1781 1950
 			if ($change_since === false || !$row || !$row['cal_start'] || !$row['cal_end'])
1782 1951
 			{
@@ -1878,7 +2047,10 @@  discard block
 block discarded – undo
1878 2047
 			$user_type = $uid[0];
1879 2048
 			$email = substr($uid, 1);
1880 2049
 			$matches = null;
1881
-			if (preg_match('/<([^<>]+)>$/', $email, $matches)) $email = $matches[1];
2050
+			if (preg_match('/<([^<>]+)>$/', $email, $matches))
2051
+			{
2052
+				$email = $matches[1];
2053
+			}
1882 2054
 			$user_id = md5(trim(strtolower($email)));
1883 2055
 		}
1884 2056
 		else
@@ -1898,8 +2070,14 @@  discard block
 block discarded – undo
1898 2070
 	 */
1899 2071
 	static function combine_status($status,$quantity=1,$role='REQ-PARTICIPANT')
1900 2072
 	{
1901
-		if ((int)$quantity > 1) $status .= (int)$quantity;
1902
-		if ($role != 'REQ-PARTICIPANT') $status .= $role;
2073
+		if ((int)$quantity > 1)
2074
+		{
2075
+			$status .= (int)$quantity;
2076
+		}
2077
+		if ($role != 'REQ-PARTICIPANT')
2078
+		{
2079
+			$status .= $role;
2080
+		}
1903 2081
 
1904 2082
 		return $status;
1905 2083
 	}
@@ -1920,8 +2098,14 @@  discard block
 block discarded – undo
1920 2098
 		$matches = null;
1921 2099
 		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/',$status,$matches))
1922 2100
 		{
1923
-			if ((int)$matches[1] > 0) $quantity = (int)$matches[1];
1924
-			if ($matches[2]) $role = $matches[2];
2101
+			if ((int)$matches[1] > 0)
2102
+			{
2103
+				$quantity = (int)$matches[1];
2104
+			}
2105
+			if ($matches[2])
2106
+			{
2107
+				$role = $matches[2];
2108
+			}
1925 2109
 			$status = $status[0];
1926 2110
 		}
1927 2111
 		elseif ($status === true)
@@ -2032,9 +2216,13 @@  discard block
 block discarded – undo
2032 2216
 			}
2033 2217
 		}
2034 2218
 
2035
-		if (count($participants))	// participants which need to be added
2219
+		if (count($participants))
2220
+		{
2221
+			// participants which need to be added
2036 2222
 		{
2037
-			if (!count($recurrences)) $recurrences[] = 0;   // insert the default recurrence
2223
+			if (!count($recurrences)) $recurrences[] = 0;
2224
+		}
2225
+		// insert the default recurrence
2038 2226
 
2039 2227
 			$delete_deleted = array();
2040 2228
 
@@ -2106,7 +2294,10 @@  discard block
 block discarded – undo
2106 2294
 			return false;
2107 2295
 		}
2108 2296
 
2109
-		if (is_numeric($status)) $status = $status_code_short[$status];
2297
+		if (is_numeric($status))
2298
+		{
2299
+			$status = $status_code_short[$status];
2300
+		}
2110 2301
 
2111 2302
 		$uid = self::combine_user($user_type, $user_id);
2112 2303
 		$user_id_md5 = null;
@@ -2126,16 +2317,25 @@  discard block
 block discarded – undo
2126 2317
 			$where[] = '(cal_recur_date=0 OR cal_recur_date >= '.time().')';
2127 2318
 		}
2128 2319
 
2129
-		if ($status == 'G')		// remove group invitations, as we dont store them in the db
2320
+		if ($status == 'G')
2321
+		{
2322
+			// remove group invitations, as we dont store them in the db
2130 2323
 		{
2131 2324
 			$this->db->delete($this->user_table,$where,__LINE__,__FILE__,'calendar');
2325
+		}
2132 2326
 			$ret = $this->db->affected_rows();
2133 2327
 		}
2134 2328
 		else
2135 2329
 		{
2136 2330
 			$set = array('cal_status' => $status);
2137
-			if ($user_type == 'e' || $attendee) $set['cal_user_attendee'] = $attendee ? $attendee : $user_id;
2138
-			if (!is_null($role) && $role != 'REQ-PARTICIPANT') $set['cal_role'] = $role;
2331
+			if ($user_type == 'e' || $attendee)
2332
+			{
2333
+				$set['cal_user_attendee'] = $attendee ? $attendee : $user_id;
2334
+			}
2335
+			if (!is_null($role) && $role != 'REQ-PARTICIPANT')
2336
+			{
2337
+				$set['cal_role'] = $role;
2338
+			}
2139 2339
 			$this->db->insert($this->user_table,$set,$where,__LINE__,__FILE__,'calendar');
2140 2340
 			// for new or changed group-invitations, remove previously deleted members, so they show up again
2141 2341
 			if (($ret = $this->db->affected_rows()) && $user_type == 'u' && $user_id < 0)
@@ -2168,7 +2368,10 @@  discard block
 block discarded – undo
2168 2368
 	{
2169 2369
 		//error_log(__METHOD__."($cal_id, $start, $end, ".array2string($participants).", ".array2string($exception));
2170 2370
 		$update = array('cal_end' => $end);
2171
-		if (isset($exception)) $update['recur_exception'] = $exception;
2371
+		if (isset($exception))
2372
+		{
2373
+			$update['recur_exception'] = $exception;
2374
+		}
2172 2375
 
2173 2376
 		$this->db->insert($this->dates_table, $update, array(
2174 2377
 			'cal_id' => $cal_id,
@@ -2183,7 +2386,11 @@  discard block
 block discarded – undo
2183 2386
 		{
2184 2387
 			foreach($participants as $uid => $status)
2185 2388
 			{
2186
-				if ($status == 'G') continue;	// dont save group-invitations
2389
+				if ($status == 'G')
2390
+				{
2391
+					continue;
2392
+				}
2393
+				// dont save group-invitations
2187 2394
 
2188 2395
 				$type = '';
2189 2396
 				$id = null;
@@ -2412,7 +2619,10 @@  discard block
 block discarded – undo
2412 2619
 			$alarm['time'] = $alarm['keep_time'] = time()+self::ALARM_KEEP_TIME;
2413 2620
 		}
2414 2621
 		// add an alarm uid, if none is given
2415
-		if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) $alarm['uid'] = (string)new Horde_Support_Uuid;
2622
+		if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid'))
2623
+		{
2624
+			$alarm['uid'] = (string)new Horde_Support_Uuid;
2625
+		}
2416 2626
 		//error_log(__METHOD__.__LINE__.' Save Alarm for CalID:'.$cal_id.'->'.array2string($alarm).'-->'.$id.'#'.function_backtrace());
2417 2627
 		// allways store job with the alarm owner as job-owner to get eg. the correct from address
2418 2628
 		if (!$this->async->set_timer($alarm['time'], $id, 'calendar.calendar_boupdate.send_alarm', $alarm, $alarm['owner'], false, true))
@@ -2421,10 +2631,16 @@  discard block
 block discarded – undo
2421 2631
 		}
2422 2632
 
2423 2633
 		// update the modification information of the related event
2424
-		if ($update_modified) $this->updateModified($cal_id, true);
2634
+		if ($update_modified)
2635
+		{
2636
+			$this->updateModified($cal_id, true);
2637
+		}
2425 2638
 
2426 2639
 		// update cache, if used
2427
-		if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, true);
2640
+		if (isset(self::$alarm_cache))
2641
+		{
2642
+			$this->read_alarms($cal_id, true);
2643
+		}
2428 2644
 
2429 2645
 		return $id;
2430 2646
 	}
@@ -2447,7 +2663,10 @@  discard block
 block discarded – undo
2447 2663
 				$this->async->cancel_timer($id);
2448 2664
 			}
2449 2665
 			// update cache, if used
2450
-			if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, false);
2666
+			if (isset(self::$alarm_cache))
2667
+			{
2668
+				$this->read_alarms($cal_id, false);
2669
+			}
2451 2670
 		}
2452 2671
 		return count($alarms);
2453 2672
 	}
@@ -2470,7 +2689,10 @@  discard block
 block discarded – undo
2470 2689
 		$ret = $this->async->cancel_timer($id);
2471 2690
 
2472 2691
 		// update cache, if used
2473
-		if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, true);
2692
+		if (isset(self::$alarm_cache))
2693
+		{
2694
+			$this->read_alarms($cal_id, true);
2695
+		}
2474 2696
 
2475 2697
 		return $ret;
2476 2698
 	}
@@ -2494,11 +2716,14 @@  discard block
 block discarded – undo
2494 2716
 			$user_id = null;
2495 2717
 			self::split_user($old_user,$user_type,$user_id);
2496 2718
 
2497
-			if ($user_type == 'u')	// only accounts can be owners of events
2719
+			if ($user_type == 'u')
2720
+			{
2721
+				// only accounts can be owners of events
2498 2722
 			{
2499 2723
 				foreach($this->db->select($this->cal_table,'cal_id',array('cal_owner' => $old_user),__LINE__,__FILE__,false,'','calendar') as $row)
2500 2724
 				{
2501 2725
 					$this->delete($row['cal_id']);
2726
+			}
2502 2727
 				}
2503 2728
 			}
2504 2729
 			$this->db->delete($this->user_table,array(
@@ -2526,11 +2751,14 @@  discard block
 block discarded – undo
2526 2751
 			{
2527 2752
 				$ids[] = $row['cal_id'];
2528 2753
 			}
2529
-			if ($ids) $this->db->delete($this->user_table,array(
2754
+			if ($ids)
2755
+			{
2756
+				$this->db->delete($this->user_table,array(
2530 2757
 				'cal_user_type' => 'u',
2531 2758
 				'cal_user_id' => $old_user,
2532 2759
 				'cal_id' => $ids,
2533 2760
 			),__LINE__,__FILE__,'calendar');
2761
+			}
2534 2762
 			// now change participant in the rest to contain new user instead of old user
2535 2763
 			$this->db->update($this->user_table,array(
2536 2764
 				'cal_user_id' => $new_user,
@@ -2555,8 +2783,14 @@  discard block
 block discarded – undo
2555 2783
 	{
2556 2784
 		$participant_status = array();
2557 2785
 		$where = array('cal_id' => $cal_id);
2558
-		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2559
-		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2786
+		if ($start != 0 && $end == 0)
2787
+		{
2788
+			$where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2789
+		}
2790
+		if ($start == 0 && $end != 0)
2791
+		{
2792
+			$where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2793
+		}
2560 2794
 		if ($start != 0 && $end != 0)
2561 2795
 		{
2562 2796
 			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
@@ -2567,7 +2801,10 @@  discard block
 block discarded – undo
2567 2801
 			// inititalize the array
2568 2802
 			$participant_status[$row['cal_recur_date']] = null;
2569 2803
 		}
2570
-		if (is_null($uid)) return $participant_status;
2804
+		if (is_null($uid))
2805
+		{
2806
+			return $participant_status;
2807
+		}
2571 2808
 		$user_type = $user_id = null;
2572 2809
 		self::split_user($uid, $user_type, $user_id, true);
2573 2810
 
@@ -2576,8 +2813,14 @@  discard block
 block discarded – undo
2576 2813
 			'cal_user_type'	=> $user_type ? $user_type : 'u',
2577 2814
 			'cal_user_id'   => $user_id,
2578 2815
 		);
2579
-		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2580
-		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2816
+		if ($start != 0 && $end == 0)
2817
+		{
2818
+			$where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2819
+		}
2820
+		if ($start == 0 && $end != 0)
2821
+		{
2822
+			$where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2823
+		}
2581 2824
 		if ($start != 0 && $end != 0)
2582 2825
 		{
2583 2826
 			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
@@ -2667,17 +2910,26 @@  discard block
 block discarded – undo
2667 2910
 	 */
2668 2911
 	function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all')
2669 2912
 	{
2670
-		if (!is_array($event)) return false;
2913
+		if (!is_array($event))
2914
+		{
2915
+			return false;
2916
+		}
2671 2917
 		$cal_id = (int) $event['id'];
2672 2918
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2673 2919
 		//		"($cal_id, $tz_id, $filter): " . $event['tzid']);
2674
-		if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false;
2920
+		if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE)
2921
+		{
2922
+			return false;
2923
+		}
2675 2924
 
2676 2925
 		$days = array();
2677 2926
 
2678 2927
 		$expand_all = (!$this->isWholeDay($event) && $tz_id && $tz_id != $event['tzid']);
2679 2928
 
2680
-		if ($filter == 'tz_only' && !$expand_all) return $days;
2929
+		if ($filter == 'tz_only' && !$expand_all)
2930
+		{
2931
+			return $days;
2932
+		}
2681 2933
 
2682 2934
 		$remote = in_array($filter, array('tz_rrule', 'rrule'));
2683 2935
 
@@ -2720,7 +2972,10 @@  discard block
 block discarded – undo
2720 2972
 					$remote_rrule->next_no_exception();
2721 2973
 				}
2722 2974
 				$egw_rrule->next_no_exception();
2723
-				if (!$egw_rrule->valid()) return $days;
2975
+				if (!$egw_rrule->valid())
2976
+				{
2977
+					return $days;
2978
+				}
2724 2979
 			}
2725 2980
 			$day = $egw_rrule->current();
2726 2981
 			$locts = (int)Api\DateTime::to($day,'server');
@@ -2874,7 +3129,11 @@  discard block
 block discarded – undo
2874 3129
 			}
2875 3130
 		}
2876 3131
 
2877
-		if (empty($participants)) return false; // occurrence does not exist at all yet
3132
+		if (empty($participants))
3133
+		{
3134
+			return false;
3135
+		}
3136
+		// occurrence does not exist at all yet
2878 3137
 
2879 3138
 		foreach ($recurrence_zero as $uid => $status)
2880 3139
 		{
@@ -2931,7 +3190,9 @@  discard block
 block discarded – undo
2931 3190
 			}
2932 3191
 			if (!isset($participants[$uid])
2933 3192
 				|| $participants[$uid] != $status)
2934
-				return true;
3193
+			{
3194
+							return true;
3195
+			}
2935 3196
 			unset($participants[$uid]);
2936 3197
 		}
2937 3198
 		return (!empty($participants));
@@ -2945,7 +3206,10 @@  discard block
 block discarded – undo
2945 3206
 	 */
2946 3207
 	function isWholeDay($event)
2947 3208
 	{
2948
-		if (!isset($event['start']) || !isset($event['end'])) return false;
3209
+		if (!isset($event['start']) || !isset($event['end']))
3210
+		{
3211
+			return false;
3212
+		}
2949 3213
 
2950 3214
 		if (empty($event['tzid']))
2951 3215
 		{
@@ -3007,8 +3271,14 @@  discard block
 block discarded – undo
3007 3271
 	 */
3008 3272
 	function updateModified($id, $update_master=false, $time=null, $modifier=null)
3009 3273
 	{
3010
-		if (is_null($time) || !$time) $time = time();
3011
-		if (is_null($modifier)) $modifier = $GLOBALS['egw_info']['user']['account_id'];
3274
+		if (is_null($time) || !$time)
3275
+		{
3276
+			$time = time();
3277
+		}
3278
+		if (is_null($modifier))
3279
+		{
3280
+			$modifier = $GLOBALS['egw_info']['user']['account_id'];
3281
+		}
3012 3282
 
3013 3283
 		$this->db->update($this->cal_table,
3014 3284
 			array('cal_modified' => $time, 'cal_modifier' => $modifier),
Please login to merge, or discard this patch.
Spacing   +392 added lines, -395 removed lines patch added patch discarded remove patch
@@ -19,40 +19,40 @@  discard block
 block discarded – undo
19 19
 /**
20 20
  * some necessary defines used by the calendar
21 21
  */
22
-if(!extension_loaded('mcal'))
22
+if (!extension_loaded('mcal'))
23 23
 {
24
-	define('MCAL_RECUR_NONE',0);
25
-	define('MCAL_RECUR_DAILY',1);
26
-	define('MCAL_RECUR_WEEKLY',2);
27
-	define('MCAL_RECUR_MONTHLY_MDAY',3);
28
-	define('MCAL_RECUR_MONTHLY_WDAY',4);
29
-	define('MCAL_RECUR_YEARLY',5);
30
-	define('MCAL_RECUR_SECONDLY',6);
31
-	define('MCAL_RECUR_MINUTELY',7);
32
-	define('MCAL_RECUR_HOURLY',8);
33
-
34
-	define('MCAL_M_SUNDAY',1);
35
-	define('MCAL_M_MONDAY',2);
36
-	define('MCAL_M_TUESDAY',4);
37
-	define('MCAL_M_WEDNESDAY',8);
38
-	define('MCAL_M_THURSDAY',16);
39
-	define('MCAL_M_FRIDAY',32);
40
-	define('MCAL_M_SATURDAY',64);
41
-
42
-	define('MCAL_M_WEEKDAYS',62);
43
-	define('MCAL_M_WEEKEND',65);
44
-	define('MCAL_M_ALLDAYS',127);
24
+	define('MCAL_RECUR_NONE', 0);
25
+	define('MCAL_RECUR_DAILY', 1);
26
+	define('MCAL_RECUR_WEEKLY', 2);
27
+	define('MCAL_RECUR_MONTHLY_MDAY', 3);
28
+	define('MCAL_RECUR_MONTHLY_WDAY', 4);
29
+	define('MCAL_RECUR_YEARLY', 5);
30
+	define('MCAL_RECUR_SECONDLY', 6);
31
+	define('MCAL_RECUR_MINUTELY', 7);
32
+	define('MCAL_RECUR_HOURLY', 8);
33
+
34
+	define('MCAL_M_SUNDAY', 1);
35
+	define('MCAL_M_MONDAY', 2);
36
+	define('MCAL_M_TUESDAY', 4);
37
+	define('MCAL_M_WEDNESDAY', 8);
38
+	define('MCAL_M_THURSDAY', 16);
39
+	define('MCAL_M_FRIDAY', 32);
40
+	define('MCAL_M_SATURDAY', 64);
41
+
42
+	define('MCAL_M_WEEKDAYS', 62);
43
+	define('MCAL_M_WEEKEND', 65);
44
+	define('MCAL_M_ALLDAYS', 127);
45 45
 }
46 46
 
47
-define('REJECTED',0);
48
-define('NO_RESPONSE',1);
49
-define('TENTATIVE',2);
50
-define('ACCEPTED',3);
51
-define('DELEGATED',4);
47
+define('REJECTED', 0);
48
+define('NO_RESPONSE', 1);
49
+define('TENTATIVE', 2);
50
+define('ACCEPTED', 3);
51
+define('DELEGATED', 4);
52 52
 
53
-define('HOUR_s',60*60);
54
-define('DAY_s',24*HOUR_s);
55
-define('WEEK_s',7*DAY_s);
53
+define('HOUR_s', 60 * 60);
54
+define('DAY_s', 24 * HOUR_s);
55
+define('WEEK_s', 7 * DAY_s);
56 56
 
57 57
 /**
58 58
  * Class to store all calendar data (storage object)
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * name of the main calendar table and prefix for all other calendar tables
101 101
 	 */
102 102
 	var $cal_table = 'egw_cal';
103
-	var $extra_table,$repeats_table,$user_table,$dates_table,$all_tables;
103
+	var $extra_table, $repeats_table, $user_table, $dates_table, $all_tables;
104 104
 
105 105
 	/**
106 106
 	 * reference to global db-object
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 		$this->db = $GLOBALS['egw']->db;
142 142
 
143 143
 		$this->all_tables = array($this->cal_table);
144
-		foreach(array('extra','repeats','user','dates') as $name)
144
+		foreach (array('extra', 'repeats', 'user', 'dates') as $name)
145 145
 		{
146 146
 			$vname = $name.'_table';
147 147
 			$this->all_tables[] = $this->$vname = $this->cal_table.'_'.$name;
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
 	 * @param boolean $deleted =false
158 158
 	 * @return string
159 159
 	 */
160
-	protected function cal_range_view($start, $end, array $_where=null, $deleted=false)
160
+	protected function cal_range_view($start, $end, array $_where = null, $deleted = false)
161 161
 	{
162 162
 		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start)	// using view without start-date is slower!
163 163
 		{
164
-			return $this->cal_table;	// no need / use for a view
164
+			return $this->cal_table; // no need / use for a view
165 165
 		}
166 166
 
167 167
 		$where = array();
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
 	 * @param boolean $deleted =false
188 188
 	 * @return string
189 189
 	 */
190
-	protected function dates_range_view($start, $end, array $_where=null, $deleted=false)
190
+	protected function dates_range_view($start, $end, array $_where = null, $deleted = false)
191 191
 	{
192 192
 		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end)	// using view without start- AND end-date is slower!
193 193
 		{
194
-			return $this->dates_table;	// no need / use for a view
194
+			return $this->dates_table; // no need / use for a view
195 195
 		}
196 196
 
197 197
 		$where = array();
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
 	 * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it
237 237
 	 * @return array of events
238 238
 	 */
239
-	function &events($start,$end,$users,$cat_id=0,$filter='all',$offset=False,$num_rows=0,array $params=array(),$remove_rejected_by_user=null)
239
+	function &events($start, $end, $users, $cat_id = 0, $filter = 'all', $offset = False, $num_rows = 0, array $params = array(), $remove_rejected_by_user = null)
240 240
 	{
241
-		error_log(__METHOD__.'('.($start ? date('Y-m-d H:i',$start) : '').','.($end ? date('Y-m-d H:i',$end) : '').','.array2string($users).','.array2string($cat_id).",'$filter',".array2string($offset).",$num_rows,".array2string($params).') '.function_backtrace());
241
+		error_log(__METHOD__.'('.($start ? date('Y-m-d H:i', $start) : '').','.($end ? date('Y-m-d H:i', $end) : '').','.array2string($users).','.array2string($cat_id).",'$filter',".array2string($offset).",$num_rows,".array2string($params).') '.function_backtrace());
242 242
 		$start_time = microtime(true);
243 243
 		// not everything is supported by now
244 244
 		if (!$start || !$end || is_string($params['query']) ||
245 245
 			//in_array($filter,array('owner','deleted')) ||
246
-			$params['enum_recuring']===false)
246
+			$params['enum_recuring'] === false)
247 247
 		{
248 248
 			throw new Api\Exception\AssertionFailed("Unsupported value for parameters!");
249 249
 		}
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 		{
271 271
 			// fix $users to also prefix system users and groups (with 'u')
272 272
 			if (!is_array($users)) $users = $users ? (array)$users : array();
273
-			foreach($users as &$uid)
273
+			foreach ($users as &$uid)
274 274
 			{
275 275
 				$user_type = $user_id = null;
276 276
 				self::split_user($uid, $user_type, $user_id, true);
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 
292 292
 		if ($params['order'])	// only order if requested
293 293
 		{
294
-			if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
294
+			if (!preg_match('/^[a-z_ ,c]+$/i', $params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection
295 295
 			$sql .= "\nORDER BY ".$params['order'];
296 296
 		}
297 297
 
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 			$offset = 0;
301 301
 			$num_rows = -1;
302 302
 		}
303
-		$events =& $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows));
304
-		error_log(__METHOD__."(...) $sql --> ".number_format(microtime(true)-$start_time, 3));
303
+		$events = & $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows));
304
+		error_log(__METHOD__."(...) $sql --> ".number_format(microtime(true) - $start_time, 3));
305 305
 		return $events;
306 306
 	}
307 307
 
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 	 * @param boolean $read_recurrence =false true: read the exception, not the series master (only for recur_date && $ids='<uid>'!)
316 316
 	 * @return array|boolean array with cal_id => event array pairs or false if entry not found
317 317
 	 */
318
-	function read($ids, $recur_date=0, $read_recurrence=false)
318
+	function read($ids, $recur_date = 0, $read_recurrence = false)
319 319
 	{
320 320
 		//error_log(__METHOD__.'('.array2string($ids).",$recur_date) ".function_backtrace());
321 321
 		$cols = self::get_columns('calendar', $this->cal_table);
322 322
 		$cols[0] = $this->db->to_varchar($this->cal_table.'.cal_id');
323
-		$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".implode(',',$cols);
323
+		$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".implode(',', $cols);
324 324
 		$join = "LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id";
325 325
 
326 326
 		$where = array();
@@ -337,23 +337,23 @@  discard block
 block discarded – undo
337 337
 				$where['cal_reference'] = 0;
338 338
 			}
339 339
 		}
340
-		elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids))	// one or more cal_id's
340
+		elseif (is_array($ids) && isset($ids[count($ids) - 1]) || is_scalar($ids))	// one or more cal_id's
341 341
 		{
342 342
 			$where['cal_id'] = $ids;
343 343
 		}
344 344
 		else	// array with column => value pairs
345 345
 		{
346 346
 			$where = $ids;
347
-			unset($ids);	// otherwise users get not read!
347
+			unset($ids); // otherwise users get not read!
348 348
 		}
349 349
 		if (isset($where['cal_id']))	// prevent non-unique column-name cal_id
350 350
 		{
351
-			$where[] = $this->db->expression($this->cal_table, $this->cal_table.'.',array(
351
+			$where[] = $this->db->expression($this->cal_table, $this->cal_table.'.', array(
352 352
 				'cal_id' => $where['cal_id'],
353 353
 			));
354 354
 			unset($where['cal_id']);
355 355
 		}
356
-		if ((int) $recur_date && !$read_recurrence)
356
+		if ((int)$recur_date && !$read_recurrence)
357 357
 		{
358 358
 			$where[] = 'cal_start >= '.(int)$recur_date;
359 359
 			$group_by = 'GROUP BY '.$cols;
@@ -367,9 +367,9 @@  discard block
 block discarded – undo
367 367
 		$cols .= ',range_end-1 AS recur_enddate';
368 368
 
369 369
 		// sort deleted to the end, to prefer non-deleted events over deleted ones when querying by uid
370
-		$group_by .= ' ORDER BY cal_deleted IS NOT NULL,' . $this->db->to_varchar($this->cal_table.'.cal_id') . ' DESC';
370
+		$group_by .= ' ORDER BY cal_deleted IS NOT NULL,'.$this->db->to_varchar($this->cal_table.'.cal_id').' DESC';
371 371
 
372
-		$events =& $this->get_events($this->db->select($this->cal_table, $cols, $where, __LINE__, __FILE__, false, $group_by, 'calendar', 0, $join), $recur_date);
372
+		$events = & $this->get_events($this->db->select($this->cal_table, $cols, $where, __LINE__, __FILE__, false, $group_by, 'calendar', 0, $join), $recur_date);
373 373
 
374 374
 		// if we wanted to read the real recurrence, but we have eg. only a virtual one, we need to try again without $read_recurrence
375 375
 		if ((!$events || ($e = current($events)) && $e['deleted']) && $recur_date && $read_recurrence)
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 	 * @param int $recur_date =0
388 388
 	 * @return array
389 389
 	 */
390
-	protected function &get_events($rs, $recur_date=0)
390
+	protected function &get_events($rs, $recur_date = 0)
391 391
 	{
392 392
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
393 393
 		{
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 		}
400 400
 
401 401
 		$events = array();
402
-		foreach($rs as $row)
402
+		foreach ($rs as $row)
403 403
 		{
404 404
 			if (!$row['recur_type'])
405 405
 			{
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 				unset($row['recur_enddate']);
408 408
 			}
409 409
 			$row['recur_exception'] = $row['alarm'] = array();
410
-			$events[$row['cal_id']] = Api\Db::strip_array_keys($row,'cal_');
410
+			$events[$row['cal_id']] = Api\Db::strip_array_keys($row, 'cal_');
411 411
 		}
412 412
 		if (!$events) return $events;
413 413
 
@@ -419,26 +419,26 @@  discard block
 block discarded – undo
419 419
 			if (!isset($event['uid']) || strlen($event['uid']) < $minimum_uid_length)
420 420
 			{
421 421
 				// event (without uid), not strong enough uid => create new uid
422
-				$event['uid'] = Api\CalDAV::generate_uid('calendar',$event['id']);
422
+				$event['uid'] = Api\CalDAV::generate_uid('calendar', $event['id']);
423 423
 				$this->db->update($this->cal_table, array('cal_uid' => $event['uid']),
424
-					array('cal_id' => $event['id']),__LINE__,__FILE__,'calendar');
424
+					array('cal_id' => $event['id']), __LINE__, __FILE__, 'calendar');
425 425
 			}
426 426
 			if (!(int)$recur_date && $event['recur_type'] != MCAL_RECUR_NONE)
427 427
 			{
428
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
428
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
429 429
 					'cal_id' => $ids,
430 430
 					'recur_exception' => true,
431 431
 				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row)
432 432
 				{
433 433
 					$events[$row['cal_id']]['recur_exception'][] = $row['cal_start'];
434 434
 				}
435
-				break;	// as above select read all exceptions (and I dont think too short uid problem still exists)
435
+				break; // as above select read all exceptions (and I dont think too short uid problem still exists)
436 436
 			}
437 437
 			// make sure we fetch only real exceptions (deleted occurrences of a series should not show up)
438
-			if (($recur_date &&	$event['recur_type'] != MCAL_RECUR_NONE))
438
+			if (($recur_date && $event['recur_type'] != MCAL_RECUR_NONE))
439 439
 			{
440 440
 				//_debug_array(__METHOD__.__LINE__.' recur_date:'.$recur_date.' check cal_start:'.$event['start']);
441
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
441
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
442 442
 					'cal_id' => $event['id'],
443 443
 					'cal_start' => $event['start'],
444 444
 					'recur_exception' => true,
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 						'cal_deleted' => NULL
455 455
 					), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn())
456 456
 					{
457
-						$e = $this->read($event['id'],$event['start']+1);
457
+						$e = $this->read($event['id'], $event['start'] + 1);
458 458
 						$event = $e[$event['id']];
459 459
 						break;
460 460
 					}
@@ -476,21 +476,21 @@  discard block
 block discarded – undo
476 476
 			if ($recur_date)
477 477
 			{
478 478
 				// also remember recur_date, maybe we need it later, duno now
479
-				$recur_date = array(0,$events[$ids]['recur_date'] = $events[$ids]['start']);
479
+				$recur_date = array(0, $events[$ids]['recur_date'] = $events[$ids]['start']);
480 480
 			}
481 481
 		}
482 482
 
483 483
 		// participants, if a recur_date give, we read that recurance, plus the one users from the default entry with recur_date=0
484 484
 		// sorting by cal_recur_date ASC makes sure recurence status always overwrites series status
485
-		foreach($this->db->select($this->user_table,'*',array(
485
+		foreach ($this->db->select($this->user_table, '*', array(
486 486
 			'cal_id'      => $ids,
487 487
 			'cal_recur_date' => $recur_date,
488 488
 			"cal_status NOT IN ('X','E')",
489
-		),__LINE__,__FILE__,false,'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT,'calendar') as $row)	// DESC puts users before resources and contacts
489
+		), __LINE__, __FILE__, false, 'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT, 'calendar') as $row)	// DESC puts users before resources and contacts
490 490
 		{
491 491
 			// combine all participant data in uid and status values
492 492
 			$uid    = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
493
-			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
493
+			$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
494 494
 
495 495
 			$events[$row['cal_id']]['participants'][$uid] = $status;
496 496
 			$events[$row['cal_id']]['participant_types'][$row['cal_user_type']][is_numeric($uid) ? $uid : substr($uid, 1)] = $status;
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 		}
500 500
 
501 501
 		// custom fields
502
-		foreach($this->db->select($this->extra_table,'*',array('cal_id'=>$ids),__LINE__,__FILE__,false,'','calendar') as $row)
502
+		foreach ($this->db->select($this->extra_table, '*', array('cal_id'=>$ids), __LINE__, __FILE__, false, '', 'calendar') as $row)
503 503
 		{
504 504
 			$events[$row['cal_id']]['#'.$row['cal_extra_name']] = $row['cal_extra_value'];
505 505
 		}
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 		// alarms
508 508
 		if (is_array($ids))
509 509
 		{
510
-			foreach($this->read_alarms((array)$ids) as $cal_id => $alarms)
510
+			foreach ($this->read_alarms((array)$ids) as $cal_id => $alarms)
511 511
 			{
512 512
 				$events[$cal_id]['alarm'] = $alarms;
513 513
 			}
@@ -536,11 +536,11 @@  discard block
 block discarded – undo
536 536
 	 * @param boolean $master_only =false only check recurance master (egw_cal_user.recur_date=0)
537 537
 	 * @return int maximum modification timestamp
538 538
 	 */
539
-	function get_ctag($users, $owner_too=false,$master_only=false)
539
+	function get_ctag($users, $owner_too = false, $master_only = false)
540 540
 	{
541
-		static $ctags = array();	// some per-request caching
541
+		static $ctags = array(); // some per-request caching
542 542
 		static $last_request = null;
543
-		if (!isset($last_request) || time()-$last_request > self::MAX_CTAG_CACHE_TIME)
543
+		if (!isset($last_request) || time() - $last_request > self::MAX_CTAG_CACHE_TIME)
544 544
 		{
545 545
 			$ctags = array();
546 546
 			$last_request = time();
@@ -549,13 +549,13 @@  discard block
 block discarded – undo
549 549
 		if (isset($ctags[$signature])) return $ctags[$signature];
550 550
 
551 551
 		$types = array();
552
-		foreach((array)$users as $uid)
552
+		foreach ((array)$users as $uid)
553 553
 		{
554 554
 			$type = $id = null;
555 555
 			self::split_user($uid, $type, $id, true);
556 556
 			$types[$type][] = $id;
557 557
 		}
558
-		foreach($types as $type => $ids)
558
+		foreach ($types as $type => $ids)
559 559
 		{
560 560
 			$where = array(
561 561
 				'cal_user_type' => $type,
@@ -577,17 +577,17 @@  discard block
 block discarded – undo
577 577
 		if ($owner_too)
578 578
 		{
579 579
 			// owner can only by users, no groups or resources
580
-			foreach($users as $key => $user)
580
+			foreach ($users as $key => $user)
581 581
 			{
582 582
 				if (!($user > 0)) unset($users[$key]);
583 583
 			}
584 584
 			$where = $this->db->expression($this->user_table, '(', $where, ' OR ').
585 585
 				$this->db->expression($this->cal_table, array(
586 586
 					'cal_owner' => $users,
587
-				),')');
587
+				), ')');
588 588
 		}
589
-		return $ctags[$signature] = $this->db->select($this->user_table,'MAX(cal_modified)',
590
-			$where,__LINE__,__FILE__,false,'','calendar',0,'JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id')->fetchColumn();
589
+		return $ctags[$signature] = $this->db->select($this->user_table, 'MAX(cal_modified)',
590
+			$where, __LINE__, __FILE__, false, '', 'calendar', 0, 'JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id')->fetchColumn();
591 591
 	}
592 592
 
593 593
 	/**
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 	 * @param string|array $cols ='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified' cols to query
600 600
 	 * @return Iterator as Api\Db::select
601 601
 	 */
602
-	function get_cal_data(array $query, $cols='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified')
602
+	function get_cal_data(array $query, $cols = 'cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified')
603 603
 	{
604 604
 		if (!is_array($cols)) $cols = explode(',', $cols);
605 605
 
@@ -627,14 +627,14 @@  discard block
 block discarded – undo
627 627
 			$cats = $GLOBALS['egw']->categories->return_all_children($cat_id);
628 628
 			array_walk($cats, function(&$val, $key)
629 629
 			{
630
-				unset($key);	// not used, but required by function signature
631
-				$val = (int) $val;
630
+				unset($key); // not used, but required by function signature
631
+				$val = (int)$val;
632 632
 			});
633
-			if (is_array($cat_id) && count($cat_id)==1) $cat_id = $cat_id[0];
634
-			$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '='.$this->db->quote((int)$cat_id));
635
-			foreach($cats as $cat)
633
+			if (is_array($cat_id) && count($cat_id) == 1) $cat_id = $cat_id[0];
634
+			$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','", $cats)."')" : '='.$this->db->quote((int)$cat_id));
635
+			foreach ($cats as $cat)
636 636
 			{
637
-				$sql .= ' OR '.$this->db->concat("','",'cal_category',"','").' LIKE '.$this->db->quote('%,'.$cat.',%');
637
+				$sql .= ' OR '.$this->db->concat("','", 'cal_category', "','").' LIKE '.$this->db->quote('%,'.$cat.',%');
638 638
 			}
639 639
 			$sql .= ') ';
640 640
 		}
@@ -649,13 +649,13 @@  discard block
 block discarded – undo
649 649
 	 * @param array $where =array() array to add filters too
650 650
 	 * @return array
651 651
 	 */
652
-	protected function status_filter($filter, $enum_recuring=true, array $where=array())
652
+	protected function status_filter($filter, $enum_recuring = true, array $where = array())
653 653
 	{
654
-		if($filter != 'deleted' && $filter != 'everything')
654
+		if ($filter != 'deleted' && $filter != 'everything')
655 655
 		{
656 656
 			$where[] = 'cal_deleted IS NULL';
657 657
 		}
658
-		switch($filter)
658
+		switch ($filter)
659 659
 		{
660 660
 			case 'everything':	// no filter at all
661 661
 				break;
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 	 * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it
730 730
 	 * @return Iterator|array of events
731 731
 	 */
732
-	function &search($start,$end,$users,$cat_id=0,$filter='all',$offset=False,$num_rows=0,array $params=array(),$remove_rejected_by_user=null)
732
+	function &search($start, $end, $users, $cat_id = 0, $filter = 'all', $offset = False, $num_rows = 0, array $params = array(), $remove_rejected_by_user = null)
733 733
 	{
734 734
 		//error_log(__METHOD__.'('.($start ? date('Y-m-d H:i',$start) : '').','.($end ? date('Y-m-d H:i',$end) : '').','.array2string($users).','.array2string($cat_id).",'$filter',".array2string($offset).",$num_rows,".array2string($params).') '.function_backtrace());
735 735
 
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 		{
753 753
 			$all_cols = self::get_columns('calendar', $this->cal_table);
754 754
 			$all_cols[0] = $this->db->to_varchar($this->cal_table.'.cal_id');
755
-			$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,range_end - 1 AS recur_enddate,".implode(',',$all_cols).",cal_start,cal_end,$this->user_table.cal_recur_date";
755
+			$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,range_end - 1 AS recur_enddate,".implode(',', $all_cols).",cal_start,cal_end,$this->user_table.cal_recur_date";
756 756
 		}
757 757
 		$where = array();
758 758
 		$join = '';
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 		}
763 763
 		elseif ($params['query'])
764 764
 		{
765
-			$columns = array('cal_title','cal_description','cal_location');
765
+			$columns = array('cal_title', 'cal_description', 'cal_location');
766 766
 
767 767
 			$wildcard = '%'; $op = null;
768 768
 			$so_sql = new Api\Storage('calendar', $this->cal_table, $this->extra_table, '', 'cal_extra_name', 'cal_extra_value', 'cal_id', $this->db);
@@ -772,9 +772,9 @@  discard block
 block discarded – undo
772 772
 			if (!isset($params['private_grants']))
773 773
 			{
774 774
 				$params['private_grants'] = $GLOBALS['egw']->acl->get_ids_for_location($GLOBALS['egw_info']['user']['account_id'], Acl::PRIVAT, 'calendar');
775
-				$params['private_grants'][] = $GLOBALS['egw_info']['user']['account_id'];	// db query does NOT return current user
775
+				$params['private_grants'][] = $GLOBALS['egw_info']['user']['account_id']; // db query does NOT return current user
776 776
 			}
777
-			$private_filter = '(cal_public=1 OR cal_public=0 AND '.$this->db->expression($this->cal_table, array('cal_owner' => $params['private_grants'])) . ')';
777
+			$private_filter = '(cal_public=1 OR cal_public=0 AND '.$this->db->expression($this->cal_table, array('cal_owner' => $params['private_grants'])).')';
778 778
 			$where[] = $private_filter;
779 779
 		}
780 780
 		if (!empty($params['sql_filter']))
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
 			{
784 784
 				$where[] = $params['sql_filter'];
785 785
 			}
786
-			elseif(is_array($params['sql_filter']))
786
+			elseif (is_array($params['sql_filter']))
787 787
 			{
788 788
 				$where = array_merge($where, $params['sql_filter']);
789 789
 			}
@@ -792,11 +792,11 @@  discard block
 block discarded – undo
792 792
 		if ($users)
793 793
 		{
794 794
 			$users_by_type = array();
795
-			foreach((array)$users as $user)
795
+			foreach ((array)$users as $user)
796 796
 			{
797 797
 				if (is_numeric($user))
798 798
 				{
799
-					$users_by_type['u'][] = (int) $user;
799
+					$users_by_type['u'][] = (int)$user;
800 800
 				}
801 801
 				else
802 802
 				{
@@ -807,45 +807,45 @@  discard block
 block discarded – undo
807 807
 			}
808 808
 			$to_or = $user_or = array();
809 809
 			$owner_or = null;
810
-			$table_def = $this->db->get_table_definitions('calendar',$this->user_table);
811
-			foreach($users_by_type as $type => $ids)
810
+			$table_def = $this->db->get_table_definitions('calendar', $this->user_table);
811
+			foreach ($users_by_type as $type => $ids)
812 812
 			{
813 813
 				// when we are able to use Union Querys, we do not OR our query, we save the needed parts for later construction of the union
814 814
 				if ($useUnionQuery)
815 815
 				{
816
-					$user_or[] = $this->db->expression($table_def,$this->user_table.'.',array(
816
+					$user_or[] = $this->db->expression($table_def, $this->user_table.'.', array(
817 817
 						'cal_user_type' => $type,
818
-					),' AND '.$this->user_table.'.',array(
818
+					), ' AND '.$this->user_table.'.', array(
819 819
 						'cal_user_id'   => $ids,
820 820
 					));
821 821
 					if ($type == 'u' && $filter == 'owner')
822 822
 					{
823
-						$cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table);
823
+						$cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table);
824 824
 						// only users can be owners, no need to add groups
825 825
 						$user_ids = array();
826
-						foreach($ids as $user_id)
826
+						foreach ($ids as $user_id)
827 827
 						{
828 828
 							if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u') $user_ids[] = $user_id;
829 829
 						}
830
-						$owner_or = $this->db->expression($cal_table_def,array('cal_owner' => $user_ids));
830
+						$owner_or = $this->db->expression($cal_table_def, array('cal_owner' => $user_ids));
831 831
 					}
832 832
 				}
833 833
 				else
834 834
 				{
835
-					$to_or[] = $this->db->expression($table_def,$this->user_table.'.',array(
835
+					$to_or[] = $this->db->expression($table_def, $this->user_table.'.', array(
836 836
 						'cal_user_type' => $type,
837
-					),' AND '.$this->user_table.'.',array(
837
+					), ' AND '.$this->user_table.'.', array(
838 838
 						'cal_user_id'   => $ids,
839 839
 					));
840 840
 					if ($type == 'u' && $filter == 'owner')
841 841
 					{
842
-						$cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table);
843
-						$to_or[] = $this->db->expression($cal_table_def,array('cal_owner' => $ids));
842
+						$cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table);
843
+						$to_or[] = $this->db->expression($cal_table_def, array('cal_owner' => $ids));
844 844
 					}
845 845
 				}
846 846
 			}
847 847
 			// this is only used, when we cannot use UNIONS
848
-			if (!$useUnionQuery) $where[] = '('.implode(' OR ',$to_or).')';
848
+			if (!$useUnionQuery) $where[] = '('.implode(' OR ', $to_or).')';
849 849
 
850 850
 			$where = $this->status_filter($filter, $params['enum_recuring'], $where);
851 851
 		}
@@ -864,15 +864,15 @@  discard block
 block discarded – undo
864 864
 				$where[] = '('.((int)$start).' < range_end OR range_end IS NULL)';
865 865
 			}
866 866
 		}
867
-		if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
867
+		if (!preg_match('/^[a-z_ ,c]+$/i', $params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection
868 868
 
869 869
 		// if not enum recuring events, we have to use minimum start- AND end-dates, otherwise we get more then one event per cal_id!
870 870
 		if (!$params['enum_recuring'])
871 871
 		{
872 872
 			$where[] = "$this->user_table.cal_recur_date=0";
873
-			$cols = str_replace(array('cal_start','cal_end'),array('range_start AS cal_start','(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id) AS cal_end'),$cols);
873
+			$cols = str_replace(array('cal_start', 'cal_end'), array('range_start AS cal_start', '(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id) AS cal_end'), $cols);
874 874
 			// in case cal_start is used in a query, eg. calendar_ical::find_event
875
-			$where = str_replace(array('cal_start','cal_end'), array('range_start','(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id)'), $where);
875
+			$where = str_replace(array('cal_start', 'cal_end'), array('range_start', '(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id)'), $where);
876 876
 			$params['order'] = str_replace('cal_start', 'range_start', $params['order']);
877 877
 			if ($end) $where[] = (int)$end.' > range_start';
878 878
   		}
@@ -884,14 +884,13 @@  discard block
 block discarded – undo
884 884
 				" ON $this->cal_table.cal_id=rejected_by_user.cal_id".
885 885
 				" AND rejected_by_user.cal_user_type='u'".
886 886
 				" AND rejected_by_user.cal_user_id=".$this->db->quote($remove_rejected_by_user).
887
-				" AND ".(!$params['enum_recuring'] ? 'rejected_by_user.cal_recur_date=0' :
888
-					'(recur_type IS NULL AND rejected_by_user.cal_recur_date=0 OR cal_start=rejected_by_user.cal_recur_date)');
887
+				" AND ".(!$params['enum_recuring'] ? 'rejected_by_user.cal_recur_date=0' : '(recur_type IS NULL AND rejected_by_user.cal_recur_date=0 OR cal_start=rejected_by_user.cal_recur_date)');
889 888
 			$or_required = array(
890 889
 				'rejected_by_user.cal_status IS NULL',
891 890
 				"rejected_by_user.cal_status NOT IN ('R','X')",
892 891
 			);
893 892
 			if ($filter == 'owner') $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user;
894
-			$where[] = '('.implode(' OR ',$or_required).')';
893
+			$where[] = '('.implode(' OR ', $or_required).')';
895 894
 		}
896 895
 		// using a time-range and deleted attribute limited view instead of full table
897 896
 		$cal_table = $this->cal_range_view($start, $end, null, $filter == 'everything' ? null : $filter != 'deleted');
@@ -903,7 +902,7 @@  discard block
 block discarded – undo
903 902
 		// dates table join only needed to enum recuring events, we use a time-range limited view here too
904 903
 		if ($params['enum_recuring'])
905 904
 		{
906
-			$join .= "JOIN ".$this->dates_table.	// using dates_table direct seems quicker then an other view
905
+			$join .= "JOIN ".$this->dates_table.// using dates_table direct seems quicker then an other view
907 906
 				//$this->dates_range_view($start, $end, null, $filter == 'everything' ? null : $filter == 'deleted').
908 907
 				" ON $this->cal_table.cal_id=$this->dates_table.cal_id ".$u_join;
909 908
 		}
@@ -913,12 +912,12 @@  discard block
 block discarded – undo
913 912
 		}
914 913
 
915 914
 		// Check for some special sorting, used by planner views
916
-		if($params['order'] == 'participants , cal_non_blocking DESC')
915
+		if ($params['order'] == 'participants , cal_non_blocking DESC')
917 916
 		{
918 917
 			$order = ($GLOBALS['egw_info']['user']['preferences']['common']['account_display'] == 'lastname' ? 'n_family' : 'n_fileas');
919 918
 			$cols .= ",egw_addressbook.{$order}";
920 919
 			$join .= "LEFT JOIN egw_addressbook ON ".
921
-					($this->db->Type == 'pgsql'? "egw_addressbook.account_id::varchar = ":"egw_addressbook.account_id = ").
920
+					($this->db->Type == 'pgsql' ? "egw_addressbook.account_id::varchar = " : "egw_addressbook.account_id = ").
922 921
 					"{$this->user_table}.cal_user_id";
923 922
 			$params['order'] = "$order, cal_non_blocking DESC";
924 923
 		}
@@ -951,29 +950,29 @@  discard block
 block discarded – undo
951 950
 			// as replace the OR by construction of a suitable UNION for performance reasons
952 951
 			if ($owner_or || $user_or)
953 952
 			{
954
-				foreach($user_or as $user_sql)
953
+				foreach ($user_or as $user_sql)
955 954
 				{
956 955
 					$selects[] = $select;
957
-					$selects[count($selects)-1]['where'][] = $user_sql;
956
+					$selects[count($selects) - 1]['where'][] = $user_sql;
958 957
 					if ($params['enum_recuring'])
959 958
 					{
960
-						$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
959
+						$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
961 960
 						$selects[] = $select;
962
-						$selects[count($selects)-1]['where'][] = $user_sql;
963
-						$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
961
+						$selects[count($selects) - 1]['where'][] = $user_sql;
962
+						$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
964 963
 					}
965 964
 				}
966 965
 				// if the query is to be filtered by owner we need to add more selects for the union
967 966
 				if ($owner_or)
968 967
 				{
969 968
 					$selects[] = $select;
970
-					$selects[count($selects)-1]['where'][] = $owner_or;
969
+					$selects[count($selects) - 1]['where'][] = $owner_or;
971 970
 					if ($params['enum_recuring'])
972 971
 					{
973
-						$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
972
+						$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
974 973
 						$selects[] = $select;
975
-						$selects[count($selects)-1]['where'][] = $owner_or;
976
-						$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
974
+						$selects[count($selects) - 1]['where'][] = $owner_or;
975
+						$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
977 976
 					}
978 977
 				}
979 978
 			}
@@ -983,34 +982,34 @@  discard block
 block discarded – undo
983 982
 				$selects[] = $select;
984 983
 				if ($params['enum_recuring'])
985 984
 				{
986
-					$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
985
+					$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
987 986
 					$selects[] = $select;
988
-					$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
987
+					$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
989 988
 				}
990 989
 			}
991 990
 			if (is_numeric($offset) && !$params['no_total'])	// get the total too
992 991
 			{
993 992
 				$save_selects = $selects;
994 993
 				// we only select cal_table.cal_id (and not cal_table.*) to be able to use DISTINCT (eg. MsSQL does not allow it for text-columns)
995
-				foreach(array_keys($selects) as $key)
994
+				foreach (array_keys($selects) as $key)
996 995
 				{
997 996
 					$selects[$key]['cols'] = "$this->repeats_table.recur_type,range_end AS recur_enddate,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".$this->db->to_varchar($this->cal_table.'.cal_id').",cal_start,cal_end,$this->user_table.cal_recur_date";
998 997
 					if (!$params['enum_recuring'])
999 998
 					{
1000
-						$selects[$key]['cols'] = str_replace(array('cal_start','cal_end'),
1001
-							array('range_start AS cal_start','range_end AS cal_end'), $selects[$key]['cols']);
999
+						$selects[$key]['cols'] = str_replace(array('cal_start', 'cal_end'),
1000
+							array('range_start AS cal_start', 'range_end AS cal_end'), $selects[$key]['cols']);
1002 1001
 					}
1003 1002
 				}
1004
-				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1003
+				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1005 1004
 
1006
-				$this->total = $this->db->union($selects,__LINE__,__FILE__)->NumRows();
1005
+				$this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows();
1007 1006
 
1008 1007
 				// restore original cols / selects
1009 1008
 				$selects = $save_selects; unset($save_selects);
1010 1009
 			}
1011
-			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1010
+			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1012 1011
 
1013
-			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
1012
+			$rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows);
1014 1013
 		}
1015 1014
 		else	// MsSQL oder MySQL 3.23
1016 1015
 		{
@@ -1033,27 +1032,27 @@  discard block
 block discarded – undo
1033 1032
 				$selects[0]['cols'] = "$this->cal_table.cal_id,cal_start";
1034 1033
 				if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
1035 1034
 				{
1036
-					self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1035
+					self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1037 1036
 				}
1038 1037
 				$this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows();
1039 1038
 				$selects = $save_selects;
1040 1039
 			}
1041 1040
 			if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
1042 1041
 			{
1043
-				self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1042
+				self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1044 1043
 			}
1045
-			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
1044
+			$rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows);
1046 1045
 		}
1047 1046
 		//error_log(__METHOD__."() useUnionQuery=$useUnionQuery --> query took ".(microtime(true)-$starttime).'s '.$rs->sql);
1048 1047
 
1049 1048
 		if (isset($params['cols']))
1050 1049
 		{
1051
-			return $rs;	// if colums are specified we return the recordset / iterator
1050
+			return $rs; // if colums are specified we return the recordset / iterator
1052 1051
 		}
1053 1052
 		// Todo: return $this->get_events($rs);
1054 1053
 
1055 1054
 		$events = $ids = $recur_dates = $recur_ids = array();
1056
-		foreach($rs as $row)
1055
+		foreach ($rs as $row)
1057 1056
 		{
1058 1057
 			$id = $row['cal_id'];
1059 1058
 			if (is_numeric($id)) $ids[] = $id;
@@ -1065,9 +1064,9 @@  discard block
 block discarded – undo
1065 1064
 			}
1066 1065
 			if ($row['participants'])
1067 1066
 			{
1068
-				$row['participants'] = explode(',',$row['participants']);
1067
+				$row['participants'] = explode(',', $row['participants']);
1069 1068
 				$row['participants'] = array_combine($row['participants'],
1070
-					array_fill(0,count($row['participants']),''));
1069
+					array_fill(0, count($row['participants']), ''));
1071 1070
 			}
1072 1071
 			else
1073 1072
 			{
@@ -1076,9 +1075,9 @@  discard block
 block discarded – undo
1076 1075
 			$row['recur_exception'] = $row['alarm'] = array();
1077 1076
 
1078 1077
 			// compile a list of recurrences per cal_id
1079
-			if (!in_array($id,(array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1078
+			if (!in_array($id, (array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1080 1079
 
1081
-			$events[$id] = Api\Db::strip_array_keys($row,'cal_');
1080
+			$events[$id] = Api\Db::strip_array_keys($row, 'cal_');
1082 1081
 		}
1083 1082
 		//_debug_array($events);
1084 1083
 		if (count($ids))
@@ -1088,26 +1087,26 @@  discard block
 block discarded – undo
1088 1087
 			// now ready all users with the given cal_id AND (cal_recur_date=0 or the fitting recur-date)
1089 1088
 			// This will always read the first entry of each recuring event too, we eliminate it later
1090 1089
 			$recur_dates[] = 0;
1091
-			$utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',',$ids).")".
1090
+			$utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',', $ids).")".
1092 1091
 				($filter != 'everything' ? " AND cal_status NOT IN ('X','E')" : '').") utcalid ";
1093 1092
 			//$utrecurdate_view = " (select * from ".$this->user_table." where cal_recur_date in (".implode(',',array_unique($recur_dates)).")) utrecurdates ";
1094
-			foreach($this->db->select($utcal_id_view,'*',array(
1093
+			foreach ($this->db->select($utcal_id_view, '*', array(
1095 1094
 					//'cal_id' => array_unique($ids),
1096 1095
 					'cal_recur_date' => $recur_dates,
1097
-				),__LINE__,__FILE__,false,'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT,'calendar',-1,$join='',
1098
-				$this->db->get_table_definitions('calendar',$this->user_table)) as $row)	// DESC puts users before resources and contacts
1096
+				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT, 'calendar', -1, $join = '',
1097
+				$this->db->get_table_definitions('calendar', $this->user_table)) as $row)	// DESC puts users before resources and contacts
1099 1098
 			{
1100 1099
 				$id = $row['cal_id'];
1101 1100
 				if ($row['cal_recur_date']) $id .= '-'.$row['cal_recur_date'];
1102 1101
 
1103 1102
 				// combine all participant data in uid and status values
1104 1103
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1105
-				$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
1104
+				$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
1106 1105
 
1107 1106
 				// set accept/reject/tentative of series for all recurrences
1108 1107
 				if (!$row['cal_recur_date'])
1109 1108
 				{
1110
-					foreach((array)$recur_ids[$row['cal_id']] as $i)
1109
+					foreach ((array)$recur_ids[$row['cal_id']] as $i)
1111 1110
 					{
1112 1111
 						if (isset($events[$i]) && !isset($events[$i]['participants'][$uid]))
1113 1112
 						{
@@ -1122,16 +1121,16 @@  discard block
 block discarded – undo
1122 1121
 			// query recurrance exceptions, if needed: enum_recuring && !daywise is used in calendar_groupdav::get_series($uid,...)
1123 1122
 			if (!$params['enum_recuring'] || !$params['daywise'])
1124 1123
 			{
1125
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
1124
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
1126 1125
 					'cal_id' => $ids,
1127 1126
 					'recur_exception' => true,
1128 1127
 				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row)
1129 1128
 				{
1130 1129
 					// for enum_recurring events are not indexed by cal_id, but $cal_id.'-'.$cal_start
1131 1130
 					// find master, which is first recurrence
1132
-					if (!isset($events[$id=$row['cal_id']]))
1131
+					if (!isset($events[$id = $row['cal_id']]))
1133 1132
 					{
1134
-						foreach($events as $id => $event)
1133
+						foreach ($events as $id => $event)
1135 1134
 						{
1136 1135
 							if ($event['id'] == $row['cal_id']) break;
1137 1136
 						}
@@ -1144,10 +1143,10 @@  discard block
 block discarded – undo
1144 1143
 			{
1145 1144
 				$where = array('cal_id' => $ids);
1146 1145
 				if ($params['cfs']) $where['cal_extra_name'] = $params['cfs'];
1147
-				foreach($this->db->select($this->extra_table,'*',$where,
1148
-					__LINE__,__FILE__,false,'','calendar') as $row)
1146
+				foreach ($this->db->select($this->extra_table, '*', $where,
1147
+					__LINE__, __FILE__, false, '', 'calendar') as $row)
1149 1148
 				{
1150
-					foreach((array)$recur_ids[$row['cal_id']] as $id)
1149
+					foreach ((array)$recur_ids[$row['cal_id']] as $id)
1151 1150
 					{
1152 1151
 						if (isset($events[$id]))
1153 1152
 						{
@@ -1157,9 +1156,9 @@  discard block
 block discarded – undo
1157 1156
 				}
1158 1157
 			}
1159 1158
 			// alarms
1160
-			foreach($this->read_alarms($ids) as $cal_id => $alarms)
1159
+			foreach ($this->read_alarms($ids) as $cal_id => $alarms)
1161 1160
 			{
1162
-				foreach($alarms as $id => $alarm)
1161
+				foreach ($alarms as $id => $alarm)
1163 1162
 				{
1164 1163
 					$event_start = $alarm['time'] + $alarm['offset'];
1165 1164
 
@@ -1196,16 +1195,16 @@  discard block
 block discarded – undo
1196 1195
 	 * @param $query
1197 1196
 	 * @param $users_raw as passed to calendar_bo::search (no members and memberships added)
1198 1197
 	 */
1199
-	private static function get_union_selects(array &$selects,$start,$end,$users,$cat_id,$filter,$query,$users_raw)
1198
+	private static function get_union_selects(array &$selects, $start, $end, $users, $cat_id, $filter, $query, $users_raw)
1200 1199
 	{
1201
-		if (in_array(basename($_SERVER['SCRIPT_FILENAME']),array('groupdav.php','rpc.php','xmlrpc.php','/activesync/index.php')) ||
1202
-			!in_array($GLOBALS['egw_info']['flags']['currentapp'],array('calendar','home')))
1200
+		if (in_array(basename($_SERVER['SCRIPT_FILENAME']), array('groupdav.php', 'rpc.php', 'xmlrpc.php', '/activesync/index.php')) ||
1201
+			!in_array($GLOBALS['egw_info']['flags']['currentapp'], array('calendar', 'home')))
1203 1202
 		{
1204
-			return;    // disable integration for GroupDAV, SyncML, ...
1203
+			return; // disable integration for GroupDAV, SyncML, ...
1205 1204
 		}
1206 1205
 		self::$integration_data = Api\Hooks::process(array(
1207 1206
 			'location' => 'calendar_search_union',
1208
-			'cols'  => $selects[0]['cols'],    // cols to return
1207
+			'cols'  => $selects[0]['cols'], // cols to return
1209 1208
 			'start' => $start,
1210 1209
 			'end'   => $end,
1211 1210
 			'users' => $users,
@@ -1214,12 +1213,12 @@  discard block
 block discarded – undo
1214 1213
 			'filter'=> $filter,
1215 1214
 			'query' => $query,
1216 1215
 		));
1217
-		foreach(self::$integration_data as $data)
1216
+		foreach (self::$integration_data as $data)
1218 1217
 		{
1219 1218
 			if (is_array($data['selects']))
1220 1219
 			{
1221 1220
 				//echo $app; _debug_array($data);
1222
-				$selects = array_merge($selects,$data['selects']);
1221
+				$selects = array_merge($selects, $data['selects']);
1223 1222
 			}
1224 1223
 		}
1225 1224
 	}
@@ -1244,35 +1243,35 @@  discard block
 block discarded – undo
1244 1243
 	 * @param string $required_app ='calendar'
1245 1244
 	 * @return string cols for union query to match ones supplied in $required
1246 1245
 	 */
1247
-	public static function union_cols(array $app_cols,$required,$required_app='calendar')
1246
+	public static function union_cols(array $app_cols, $required, $required_app = 'calendar')
1248 1247
 	{
1249 1248
 		// remove evtl. used DISTINCT, we currently dont need it
1250
-		if (($distinct = substr($required,0,9) == 'DISTINCT '))
1249
+		if (($distinct = substr($required, 0, 9) == 'DISTINCT '))
1251 1250
 		{
1252
-			$required = substr($required,9);
1251
+			$required = substr($required, 9);
1253 1252
 		}
1254 1253
 		$return_cols = array();
1255
-		foreach(is_array($required) ? $required : explode(',',$required) as $cols)
1254
+		foreach (is_array($required) ? $required : explode(',', $required) as $cols)
1256 1255
 		{
1257 1256
 			$matches = null;
1258
-			if (substr($cols,-2) == '.*')
1257
+			if (substr($cols, -2) == '.*')
1259 1258
 			{
1260
-				$cols = self::get_columns($required_app,substr($cols,0,-2));
1259
+				$cols = self::get_columns($required_app, substr($cols, 0, -2));
1261 1260
 			}
1262 1261
 			// remove CAST added for PostgreSQL from eg. "CAST(egw_cal.cal_id AS varchar)"
1263 1262
 			elseif (preg_match('/CAST\(([a-z0-9_.]+) AS [a-z0-9_]+\)/i', $cols, $matches))
1264 1263
 			{
1265 1264
 				$cols = $matches[1];
1266 1265
 			}
1267
-			elseif (strpos($cols,' AS ') !== false)
1266
+			elseif (strpos($cols, ' AS ') !== false)
1268 1267
 			{
1269
-				list(,$cols) = explode(' AS ',$cols);
1268
+				list(,$cols) = explode(' AS ', $cols);
1270 1269
 			}
1271
-			foreach((array)$cols as $col)
1270
+			foreach ((array)$cols as $col)
1272 1271
 			{
1273
-				if (substr($col,0,7) == 'egw_cal')	// remove table name
1272
+				if (substr($col, 0, 7) == 'egw_cal')	// remove table name
1274 1273
 				{
1275
-					$col = preg_replace('/^egw_cal[a-z_]*\./','',$col);
1274
+					$col = preg_replace('/^egw_cal[a-z_]*\./', '', $col);
1276 1275
 				}
1277 1276
 				if (isset($app_cols[$col]))
1278 1277
 				{
@@ -1285,7 +1284,7 @@  discard block
 block discarded – undo
1285 1284
 			}
1286 1285
 		}
1287 1286
 		//error_log(__METHOD__."(".array2string($app_cols).", ".array2string($required).", '$required_app') returning ".array2string(implode(',',$return_cols)));
1288
-		return implode(',',$return_cols);
1287
+		return implode(',', $return_cols);
1289 1288
 	}
1290 1289
 
1291 1290
 	/**
@@ -1295,21 +1294,21 @@  discard block
 block discarded – undo
1295 1294
 	 * @param string $table
1296 1295
 	 * @return array of column names
1297 1296
 	 */
1298
-	static private function get_columns($app,$table)
1297
+	static private function get_columns($app, $table)
1299 1298
 	{
1300 1299
 		if ($table != 'egw_cal')
1301 1300
 		{
1302
-			$table_def = $GLOBALS['egw']->db->get_table_definitions($app,$table);
1301
+			$table_def = $GLOBALS['egw']->db->get_table_definitions($app, $table);
1303 1302
 			$cols = array_keys($table_def['fd']);
1304 1303
 		}
1305 1304
 		else
1306 1305
 		{
1307 1306
 			// special handling for egw_cal, as old databases have a different column order!!!
1308
-			$cols =& Api\Cache::getSession(__CLASS__,$table);
1307
+			$cols = & Api\Cache::getSession(__CLASS__, $table);
1309 1308
 
1310 1309
 			if (is_null($cols))
1311 1310
 			{
1312
-				$meta = $GLOBALS['egw']->db->metadata($table,true);
1311
+				$meta = $GLOBALS['egw']->db->metadata($table, true);
1313 1312
 				$cols = array_keys($meta['meta']);
1314 1313
 			}
1315 1314
 		}
@@ -1362,12 +1361,12 @@  discard block
 block discarded – undo
1362 1361
 	 * @param int &$etag etag=null etag to check or null, on return new etag
1363 1362
 	 * @return boolean|int false on error, 0 if etag does not match, cal_id otherwise
1364 1363
 	 */
1365
-	function save(&$event,&$set_recurrences,&$set_recurrences_start=0,$change_since=0,&$etag=null)
1364
+	function save(&$event, &$set_recurrences, &$set_recurrences_start = 0, $change_since = 0, &$etag = null)
1366 1365
 	{
1367 1366
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
1368 1367
 		{
1369 1368
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
1370
-			if (empty($minimum_uid_length) || $minimum_uid_length<=1) $minimum_uid_length = 8; // we just do not accept no uid, or uid way to short!
1369
+			if (empty($minimum_uid_length) || $minimum_uid_length <= 1) $minimum_uid_length = 8; // we just do not accept no uid, or uid way to short!
1371 1370
 		}
1372 1371
 		else
1373 1372
 		{
@@ -1378,7 +1377,7 @@  discard block
 block discarded – undo
1378 1377
 
1379 1378
 		//error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag) ".function_backtrace());
1380 1379
 
1381
-		$cal_id = (int) $event['id'];
1380
+		$cal_id = (int)$event['id'];
1382 1381
 		unset($event['id']);
1383 1382
 		$set_recurrences = $set_recurrences || !$cal_id && $event['recur_type'] != MCAL_RECUR_NONE;
1384 1383
 
@@ -1389,9 +1388,9 @@  discard block
 block discarded – undo
1389 1388
 		}
1390 1389
 
1391 1390
 		// add colum prefix 'cal_' if there's not already a 'recur_' prefix
1392
-		foreach(array_keys($event) as $col)
1391
+		foreach (array_keys($event) as $col)
1393 1392
 		{
1394
-			if ($col[0] != '#' && substr($col,0,6) != 'recur_' && substr($col,0,6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name')
1393
+			if ($col[0] != '#' && substr($col, 0, 6) != 'recur_' && substr($col, 0, 6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name')
1395 1394
 			{
1396 1395
 				$event['cal_'.$col] = $event[$col];
1397 1396
 				unset($event[$col]);
@@ -1401,13 +1400,12 @@  discard block
 block discarded – undo
1401 1400
 		if (isset($event['cal_start'])) $event['range_start'] = $event['cal_start'];
1402 1401
 		if (isset($event['cal_end']))
1403 1402
 		{
1404
-			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] :
1405
-				($event['recur_enddate'] ? $event['recur_enddate'] : null);
1403
+			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] : ($event['recur_enddate'] ? $event['recur_enddate'] : null);
1406 1404
 		}
1407 1405
 		// ensure that we find mathing entries later on
1408 1406
 		if (!is_array($event['cal_category']))
1409 1407
 		{
1410
-			$categories = array_unique(explode(',',$event['cal_category']));
1408
+			$categories = array_unique(explode(',', $event['cal_category']));
1411 1409
 			sort($categories);
1412 1410
 		}
1413 1411
 		else
@@ -1416,7 +1414,7 @@  discard block
 block discarded – undo
1416 1414
 		}
1417 1415
 		sort($categories, SORT_NUMERIC);
1418 1416
 
1419
-		$event['cal_category'] = implode(',',$categories);
1417
+		$event['cal_category'] = implode(',', $categories);
1420 1418
 
1421 1419
 		// make sure recurring events never reference to an other recurrent event
1422 1420
 		if ($event['recur_type'] != MCAL_RECUR_NONE) $event['cal_reference'] = 0;
@@ -1434,18 +1432,18 @@  discard block
 block discarded – undo
1434 1432
 			// read only timezone id, to check if it is changed
1435 1433
 			if ($event['recur_type'] != MCAL_RECUR_NONE)
1436 1434
 			{
1437
-				$old_tz_id = $this->db->select($this->cal_table,'tz_id',$where,__LINE__,__FILE__,'calendar')->fetchColumn();
1435
+				$old_tz_id = $this->db->select($this->cal_table, 'tz_id', $where, __LINE__, __FILE__, 'calendar')->fetchColumn();
1438 1436
 			}
1439 1437
 			if (!is_null($etag)) $where['cal_etag'] = $etag;
1440 1438
 
1441 1439
 			unset($event['cal_etag']);
1442
-			$event[] = 'cal_etag=COALESCE(cal_etag,0)+1';	// always update the etag, even if none given to check
1440
+			$event[] = 'cal_etag=COALESCE(cal_etag,0)+1'; // always update the etag, even if none given to check
1443 1441
 
1444
-			$this->db->update($this->cal_table,$event,$where,__LINE__,__FILE__,'calendar');
1442
+			$this->db->update($this->cal_table, $event, $where, __LINE__, __FILE__, 'calendar');
1445 1443
 
1446 1444
 			if (!is_null($etag) && $this->db->affected_rows() < 1)
1447 1445
 			{
1448
-				return 0;	// wrong etag, someone else updated the entry
1446
+				return 0; // wrong etag, someone else updated the entry
1449 1447
 			}
1450 1448
 			if (!is_null($etag)) ++$etag;
1451 1449
 		}
@@ -1454,11 +1452,11 @@  discard block
 block discarded – undo
1454 1452
 			// new event
1455 1453
 			if (!$event['cal_owner']) $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id'];
1456 1454
 
1457
-			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = '';	// uid is NOT NULL!
1455
+			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = ''; // uid is NOT NULL!
1458 1456
 
1459 1457
 			$event['cal_etag'] = $etag = 0;
1460
-			$this->db->insert($this->cal_table,$event,false,__LINE__,__FILE__,'calendar');
1461
-			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table,'cal_id')))
1458
+			$this->db->insert($this->cal_table, $event, false, __LINE__, __FILE__, 'calendar');
1459
+			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table, 'cal_id')))
1462 1460
 			{
1463 1461
 				return false;
1464 1462
 			}
@@ -1467,7 +1465,7 @@  discard block
 block discarded – undo
1467 1465
 		// event without uid or not strong enough uid
1468 1466
 		if (!isset($event['cal_uid']) || strlen($event['cal_uid']) < $minimum_uid_length)
1469 1467
 		{
1470
-			$update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar',$cal_id);
1468
+			$update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar', $cal_id);
1471 1469
 		}
1472 1470
 		// set caldav_name, if not given by caller
1473 1471
 		if (empty($event['caldav_name']) && version_compare($GLOBALS['egw_info']['apps']['calendar']['version'], '1.9.003', '>='))
@@ -1476,37 +1474,37 @@  discard block
 block discarded – undo
1476 1474
 		}
1477 1475
 		if ($update)
1478 1476
 		{
1479
-			$this->db->update($this->cal_table, $update, array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
1477
+			$this->db->update($this->cal_table, $update, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar');
1480 1478
 		}
1481 1479
 
1482 1480
 		if ($event['recur_type'] == MCAL_RECUR_NONE)
1483 1481
 		{
1484
-			$this->db->delete($this->dates_table,array(
1482
+			$this->db->delete($this->dates_table, array(
1485 1483
 				'cal_id' => $cal_id),
1486
-				__LINE__,__FILE__,'calendar');
1484
+				__LINE__, __FILE__, 'calendar');
1487 1485
 
1488 1486
 			// delete all user-records, with recur-date != 0
1489
-			$this->db->delete($this->user_table,array(
1487
+			$this->db->delete($this->user_table, array(
1490 1488
 				'cal_id' => $cal_id, 'cal_recur_date != 0'),
1491
-				__LINE__,__FILE__,'calendar');
1489
+				__LINE__, __FILE__, 'calendar');
1492 1490
 
1493
-			$this->db->delete($this->repeats_table,array(
1491
+			$this->db->delete($this->repeats_table, array(
1494 1492
 				'cal_id' => $cal_id),
1495
-				__LINE__,__FILE__,'calendar');
1493
+				__LINE__, __FILE__, 'calendar');
1496 1494
 
1497 1495
 			// add exception marker to master, so participants added to exceptions *only* get found
1498 1496
 			if ($event['cal_reference'])
1499 1497
 			{
1500 1498
 				$master_participants = array();
1501
-				foreach($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array(
1499
+				foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array(
1502 1500
 					'cal_id' => $event['cal_reference'],
1503 1501
 					'cal_recur_date' => 0,
1504
-					"cal_status != 'X'",	// deleted need to be replaced with exception marker too
1502
+					"cal_status != 'X'", // deleted need to be replaced with exception marker too
1505 1503
 				), __LINE__, __FILE__, 'calendar') as $row)
1506 1504
 				{
1507 1505
 					$master_participants[] = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1508 1506
 				}
1509
-				foreach(array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid)
1507
+				foreach (array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid)
1510 1508
 				{
1511 1509
 					$user_type = $user_id = null;
1512 1510
 					self::split_user($uid, $user_type, $user_id, true);
@@ -1525,10 +1523,10 @@  discard block
 block discarded – undo
1525 1523
 		else // write information about recuring event, if recur_type is present in the array
1526 1524
 		{
1527 1525
 			// fetch information about the currently saved (old) event
1528
-			$old_min = (int) $this->db->select($this->dates_table,'MIN(cal_start)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn();
1529
-			$old_duration = (int) $this->db->select($this->dates_table,'MIN(cal_end)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn() - $old_min;
1526
+			$old_min = (int)$this->db->select($this->dates_table, 'MIN(cal_start)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn();
1527
+			$old_duration = (int)$this->db->select($this->dates_table, 'MIN(cal_end)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn() - $old_min;
1530 1528
 			$old_exceptions = array();
1531
-			foreach($this->db->select($this->dates_table, 'cal_start', array(
1529
+			foreach ($this->db->select($this->dates_table, 'cal_start', array(
1532 1530
 				'cal_id' => $cal_id,
1533 1531
 				'recur_exception' => true
1534 1532
 			), __LINE__, __FILE__, false, 'ORDER BY cal_start', 'calendar') as $row)
@@ -1547,8 +1545,8 @@  discard block
 block discarded – undo
1547 1545
 				'cal_recur_date' => 0,
1548 1546
 			);
1549 1547
 			$old_participants = array();
1550
-			foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where,
1551
-				__LINE__,__FILE__,false,'','calendar') as $row)
1548
+			foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where,
1549
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
1552 1550
 			{
1553 1551
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1554 1552
 				$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
@@ -1558,7 +1556,7 @@  discard block
 block discarded – undo
1558 1556
 			// re-check: did so much recurrence data change that we have to rebuild it from scratch?
1559 1557
 			if (!$set_recurrences)
1560 1558
 			{
1561
-				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int) $event['cal_start']) ||
1559
+				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int)$event['cal_start']) ||
1562 1560
 				    $event['recur_type'] != $old_repeats['recur_type'] || $event['recur_data'] != $old_repeats['recur_data'] ||
1563 1561
 					(int)$event['recur_interval'] != (int)$old_repeats['recur_interval'] || $event['tz_id'] != $old_tz_id;
1564 1562
 			}
@@ -1567,22 +1565,22 @@  discard block
 block discarded – undo
1567 1565
 			{
1568 1566
 				// too much recurrence data has changed, we have to do a rebuild from scratch
1569 1567
 				// delete all, but the lowest dates record
1570
-				$this->db->delete($this->dates_table,array(
1568
+				$this->db->delete($this->dates_table, array(
1571 1569
 					'cal_id' => $cal_id,
1572 1570
 					'cal_start > '.(int)$old_min,
1573
-				),__LINE__,__FILE__,'calendar');
1571
+				), __LINE__, __FILE__, 'calendar');
1574 1572
 
1575 1573
 				// delete all user-records, with recur-date != 0
1576
-				$this->db->delete($this->user_table,array(
1574
+				$this->db->delete($this->user_table, array(
1577 1575
 					'cal_id' => $cal_id,
1578 1576
 					'cal_recur_date != 0',
1579
-				),__LINE__,__FILE__,'calendar');
1577
+				), __LINE__, __FILE__, 'calendar');
1580 1578
 			}
1581 1579
 			else
1582 1580
 			{
1583 1581
 				// we adjust some possibly changed recurrences manually
1584 1582
 				// deleted exceptions: re-insert recurrences into the user and dates table
1585
-				if (count($deleted_exceptions = array_diff($old_exceptions,$event['recur_exception'])))
1583
+				if (count($deleted_exceptions = array_diff($old_exceptions, $event['recur_exception'])))
1586 1584
 				{
1587 1585
 					if (isset($event['cal_participants']))
1588 1586
 					{
@@ -1593,7 +1591,7 @@  discard block
 block discarded – undo
1593 1591
 						// use old default
1594 1592
 						$participants = $old_participants;
1595 1593
 					}
1596
-					foreach($deleted_exceptions as $id => $deleted_exception)
1594
+					foreach ($deleted_exceptions as $id => $deleted_exception)
1597 1595
 					{
1598 1596
 						// rebuild participants for the re-inserted recurrence
1599 1597
 						$this->recurrence($cal_id, $deleted_exception, $deleted_exception + $old_duration, $participants);
@@ -1601,24 +1599,24 @@  discard block
 block discarded – undo
1601 1599
 				}
1602 1600
 
1603 1601
 				// check if recurrence enddate was adjusted
1604
-				if(isset($event['recur_enddate']))
1602
+				if (isset($event['recur_enddate']))
1605 1603
 				{
1606 1604
 					// recurrences need to be truncated
1607
-					if((int)$event['recur_enddate'] > 0 &&
1605
+					if ((int)$event['recur_enddate'] > 0 &&
1608 1606
 						((int)$old_repeats['recur_enddate'] == 0 || (int)$old_repeats['recur_enddate'] > (int)$event['recur_enddate'])
1609 1607
 					)
1610 1608
 					{
1611
-						$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1612
-						$this->db->delete($this->dates_table,array('cal_id' => $cal_id,'cal_start >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1609
+						$this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar');
1610
+						$this->db->delete($this->dates_table, array('cal_id' => $cal_id, 'cal_start >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar');
1613 1611
 					}
1614 1612
 
1615 1613
 					// recurrences need to be expanded
1616
-					if(((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1614
+					if (((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1617 1615
 						|| ((int)$event['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] < (int)$event['recur_enddate'])
1618 1616
 					)
1619 1617
 					{
1620 1618
 						$set_recurrences = true;
1621
-						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1*DAY_s);
1619
+						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1 * DAY_s);
1622 1620
 					}
1623 1621
 					//error_log(__METHOD__."() event[recur_enddate]=$event[recur_enddate], old_repeats[recur_enddate]=$old_repeats[recur_enddate] --> set_recurrences=".array2string($set_recurrences).", set_recurrences_start=$set_recurrences_start");
1624 1622
 				}
@@ -1627,9 +1625,9 @@  discard block
 block discarded – undo
1627 1625
 				if (count($event['recur_exception']))
1628 1626
 				{
1629 1627
 					// added and existing exceptions: delete the execeptions from the user table, it could be the first time
1630
-					$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date' => $event['recur_exception']),__LINE__,__FILE__,'calendar');
1628
+					$this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date' => $event['recur_exception']), __LINE__, __FILE__, 'calendar');
1631 1629
 					// update recur_exception flag based on current exceptions
1632
-					$this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table,array(
1630
+					$this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table, array(
1633 1631
 						'cal_start' => $event['recur_exception'],
1634 1632
 					)), array(
1635 1633
 						'cal_id' => $cal_id,
@@ -1638,27 +1636,27 @@  discard block
 block discarded – undo
1638 1636
 			}
1639 1637
 
1640 1638
 			// write the repeats table
1641
-			unset($event[0]);	// unset the 'etag=etag+1', as it's not in the repeats table
1642
-			$this->db->insert($this->repeats_table,$event,array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
1639
+			unset($event[0]); // unset the 'etag=etag+1', as it's not in the repeats table
1640
+			$this->db->insert($this->repeats_table, $event, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar');
1643 1641
 		}
1644 1642
 		// update start- and endtime if present in the event-array, evtl. we need to move all recurrences
1645 1643
 		if (isset($event['cal_start']) && isset($event['cal_end']))
1646 1644
 		{
1647
-			$this->move($cal_id,$event['cal_start'],$event['cal_end'],!$cal_id ? false : $change_since, $old_min, $old_min +  $old_duration);
1645
+			$this->move($cal_id, $event['cal_start'], $event['cal_end'], !$cal_id ? false : $change_since, $old_min, $old_min + $old_duration);
1648 1646
 		}
1649 1647
 		// update participants if present in the event-array
1650 1648
 		if (isset($event['cal_participants']))
1651 1649
 		{
1652
-			$this->participants($cal_id,$event['cal_participants'],!$cal_id ? false : $change_since);
1650
+			$this->participants($cal_id, $event['cal_participants'], !$cal_id ? false : $change_since);
1653 1651
 		}
1654 1652
 		// Custom fields
1655 1653
 		Api\Storage\Customfields::handle_files('calendar', $cal_id, $event);
1656 1654
 
1657
-		foreach($event as $name => $value)
1655
+		foreach ($event as $name => $value)
1658 1656
 		{
1659 1657
 			if ($name[0] == '#')
1660 1658
 			{
1661
-				if (is_array($value) && array_key_exists('id',$value))
1659
+				if (is_array($value) && array_key_exists('id', $value))
1662 1660
 				{
1663 1661
 					//error_log(__METHOD__.__LINE__."$name => ".array2string($value).function_backtrace());
1664 1662
 					$value = $value['id'];
@@ -1666,19 +1664,19 @@  discard block
 block discarded – undo
1666 1664
 				}
1667 1665
 				if ($value)
1668 1666
 				{
1669
-					$this->db->insert($this->extra_table,array(
1670
-						'cal_extra_value'	=> is_array($value) ? implode(',',$value) : $value,
1671
-					),array(
1667
+					$this->db->insert($this->extra_table, array(
1668
+						'cal_extra_value'	=> is_array($value) ? implode(',', $value) : $value,
1669
+					), array(
1672 1670
 						'cal_id'			=> $cal_id,
1673
-						'cal_extra_name'	=> substr($name,1),
1674
-					),__LINE__,__FILE__,'calendar');
1671
+						'cal_extra_name'	=> substr($name, 1),
1672
+					), __LINE__, __FILE__, 'calendar');
1675 1673
 				}
1676 1674
 				else
1677 1675
 				{
1678
-					$this->db->delete($this->extra_table,array(
1676
+					$this->db->delete($this->extra_table, array(
1679 1677
 						'cal_id'			=> $cal_id,
1680
-						'cal_extra_name'	=> substr($name,1),
1681
-					),__LINE__,__FILE__,'calendar');
1678
+						'cal_extra_name'	=> substr($name, 1),
1679
+					), __LINE__, __FILE__, 'calendar');
1682 1680
 				}
1683 1681
 			}
1684 1682
 		}
@@ -1689,9 +1687,9 @@  discard block
 block discarded – undo
1689 1687
 			{
1690 1688
 				if ($alarm['id'] && strpos($alarm['id'], 'cal:'.$cal_id.':') !== 0)
1691 1689
 				{
1692
-					unset($alarm['id']);	// unset the temporary id to add the alarm
1690
+					unset($alarm['id']); // unset the temporary id to add the alarm
1693 1691
 				}
1694
-				if(!isset($alarm['offset']))
1692
+				if (!isset($alarm['offset']))
1695 1693
 				{
1696 1694
 					$alarm['offset'] = $event['cal_start'] - $alarm['time'];
1697 1695
 				}
@@ -1702,14 +1700,14 @@  discard block
 block discarded – undo
1702 1700
 
1703 1701
 				if ($alarm['time'] < time() && !self::shift_alarm($event, $alarm))
1704 1702
 				{
1705
-					continue;	// pgoerzen: don't add alarm in the past
1703
+					continue; // pgoerzen: don't add alarm in the past
1706 1704
 				}
1707
-				$this->save_alarm($cal_id, $alarm, false);	// false: not update modified, we do it anyway
1705
+				$this->save_alarm($cal_id, $alarm, false); // false: not update modified, we do it anyway
1708 1706
 			}
1709 1707
 		}
1710 1708
 		if (is_null($etag))
1711 1709
 		{
1712
-			$etag = $this->db->select($this->cal_table,'cal_etag',array('cal_id' => $cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn();
1710
+			$etag = $this->db->select($this->cal_table, 'cal_etag', array('cal_id' => $cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn();
1713 1711
 		}
1714 1712
 
1715 1713
 		// if event is an exception: update modified of master, to force etag, ctag and sync-token change
@@ -1729,7 +1727,7 @@  discard block
 block discarded – undo
1729 1727
 	 *	are dealing with, default is now.
1730 1728
 	 * @return boolean true if alarm could be shifted, false if not
1731 1729
 	 */
1732
-	public static function shift_alarm(array $_event, array &$alarm, $timestamp=null)
1730
+	public static function shift_alarm(array $_event, array &$alarm, $timestamp = null)
1733 1731
 	{
1734 1732
 		if ($_event['recur_type'] == MCAL_RECUR_NONE)
1735 1733
 		{
@@ -1740,7 +1738,7 @@  discard block
 block discarded – undo
1740 1738
 		$rrule = calendar_rrule::event2rrule($event, false);
1741 1739
 		foreach ($rrule as $time)
1742 1740
 		{
1743
-			if ($start < ($ts = Api\DateTime::to($time,'server')))
1741
+			if ($start < ($ts = Api\DateTime::to($time, 'server')))
1744 1742
 			{
1745 1743
 				$alarm['time'] = $ts - $alarm['offset'];
1746 1744
 				return true;
@@ -1761,34 +1759,34 @@  discard block
 block discarded – undo
1761 1759
 	 * @todo Recalculate recurrences, if timezone changes
1762 1760
 	 * @return int|boolean number of moved recurrences or false on error
1763 1761
 	 */
1764
-	function move($cal_id,$start,$end,$change_since=0,$old_start=0,$old_end=0)
1762
+	function move($cal_id, $start, $end, $change_since = 0, $old_start = 0, $old_end = 0)
1765 1763
 	{
1766 1764
 		//echo "<p>socal::move($cal_id,$start,$end,$change_since,$old_start,$old_end)</p>\n";
1767 1765
 
1768
-		if (!(int) $cal_id) return false;
1766
+		if (!(int)$cal_id) return false;
1769 1767
 
1770 1768
 		if (!$old_start)
1771 1769
 		{
1772
-			if ($change_since !== false) $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1773
-				array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetch();
1770
+			if ($change_since !== false) $row = $this->db->select($this->dates_table, 'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1771
+				array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetch();
1774 1772
 			// if no recurrence found, create one with the new dates
1775 1773
 			if ($change_since === false || !$row || !$row['cal_start'] || !$row['cal_end'])
1776 1774
 			{
1777
-				$this->db->insert($this->dates_table,array(
1775
+				$this->db->insert($this->dates_table, array(
1778 1776
 					'cal_id'    => $cal_id,
1779 1777
 					'cal_start' => $start,
1780 1778
 					'cal_end'   => $end,
1781
-				),false,__LINE__,__FILE__,'calendar');
1779
+				), false, __LINE__, __FILE__, 'calendar');
1782 1780
 
1783 1781
 				return 1;
1784 1782
 			}
1785
-			$move_start = (int) ($start-$row['cal_start']);
1786
-			$move_end   = (int) ($end-$row['cal_end']);
1783
+			$move_start = (int)($start - $row['cal_start']);
1784
+			$move_end   = (int)($end - $row['cal_end']);
1787 1785
 		}
1788 1786
 		else
1789 1787
 		{
1790
-			$move_start = (int) ($start-$old_start);
1791
-			$move_end   = (int) ($end-$old_end);
1788
+			$move_start = (int)($start - $old_start);
1789
+			$move_end   = (int)($end - $old_end);
1792 1790
 		}
1793 1791
 		$where = 'cal_id='.(int)$cal_id;
1794 1792
 
@@ -1796,13 +1794,13 @@  discard block
 block discarded – undo
1796 1794
 		{
1797 1795
 			// move the recur-date of the participants
1798 1796
 			$this->db->query("UPDATE $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ".
1799
-				((int)$change_since ? '>= '.(int)$change_since : '!= 0'),__LINE__,__FILE__);
1797
+				((int)$change_since ? '>= '.(int)$change_since : '!= 0'), __LINE__, __FILE__);
1800 1798
 		}
1801 1799
 		if ($move_start || $move_end)
1802 1800
 		{
1803 1801
 			// move the event and it's recurrences
1804 1802
 			$this->db->query("UPDATE $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where".
1805
-				((int) $change_since ? ' AND cal_start >= '.(int) $change_since : ''),__LINE__,__FILE__);
1803
+				((int)$change_since ? ' AND cal_start >= '.(int)$change_since : ''), __LINE__, __FILE__);
1806 1804
 		}
1807 1805
 		return $this->db->affected_rows();
1808 1806
 	}
@@ -1821,8 +1819,7 @@  discard block
 block discarded – undo
1821 1819
 		}
1822 1820
 		if (is_array($attendee))
1823 1821
 		{
1824
-			$email = !empty($attendee['email']) ? $user_attendee['email'] :
1825
-				(strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']);
1822
+			$email = !empty($attendee['email']) ? $user_attendee['email'] : (strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']);
1826 1823
 			$attendee = !empty($attendee['cn']) ? $attendee['cn'].' <'.$email.'>' : $email;
1827 1824
 		}
1828 1825
 		return $attendee;
@@ -1835,11 +1832,11 @@  discard block
 block discarded – undo
1835 1832
 	 * @param string|array $attendee attendee information: email, json or array with attr cn and url
1836 1833
 	 * @return string|int combined id
1837 1834
 	 */
1838
-	static function combine_user($user_type, $user_id, $attendee=null)
1835
+	static function combine_user($user_type, $user_id, $attendee = null)
1839 1836
 	{
1840 1837
 		if (!$user_type || $user_type == 'u')
1841 1838
 		{
1842
-			return (int) $user_id;
1839
+			return (int)$user_id;
1843 1840
 		}
1844 1841
 		if ($user_type == 'e' && $attendee)
1845 1842
 		{
@@ -1859,12 +1856,12 @@  discard block
 block discarded – undo
1859 1856
 	 * @param string|int &$user_id id
1860 1857
 	 * @param boolean $md5_email =false md5 hash user_id for email / user_type=="e"
1861 1858
 	 */
1862
-	static function split_user($uid, &$user_type, &$user_id, $md5_email=false)
1859
+	static function split_user($uid, &$user_type, &$user_id, $md5_email = false)
1863 1860
 	{
1864 1861
 		if (is_numeric($uid))
1865 1862
 		{
1866 1863
 			$user_type = 'u';
1867
-			$user_id = (int) $uid;
1864
+			$user_id = (int)$uid;
1868 1865
 		}
1869 1866
 		// create md5 hash from lowercased and trimed raw email ("[email protected]", not "Ralf Becker <[email protected]>")
1870 1867
 		elseif ($md5_email && $uid[0] == 'e')
@@ -1878,7 +1875,7 @@  discard block
 block discarded – undo
1878 1875
 		else
1879 1876
 		{
1880 1877
 			$user_type = $uid[0];
1881
-			$user_id = substr($uid,1);
1878
+			$user_id = substr($uid, 1);
1882 1879
 		}
1883 1880
 	}
1884 1881
 
@@ -1890,7 +1887,7 @@  discard block
 block discarded – undo
1890 1887
 	 * @param string $role ='REQ-PARTICIPANT'
1891 1888
 	 * @return string
1892 1889
 	 */
1893
-	static function combine_status($status,$quantity=1,$role='REQ-PARTICIPANT')
1890
+	static function combine_status($status, $quantity = 1, $role = 'REQ-PARTICIPANT')
1894 1891
 	{
1895 1892
 		if ((int)$quantity > 1) $status .= (int)$quantity;
1896 1893
 		if ($role != 'REQ-PARTICIPANT') $status .= $role;
@@ -1906,13 +1903,13 @@  discard block
 block discarded – undo
1906 1903
 	 * @param string &$role=null only O: role
1907 1904
 	 * @return string status U, T, A or R, same as $status parameter on return
1908 1905
 	 */
1909
-	static function split_status(&$status,&$quantity=null,&$role=null)
1906
+	static function split_status(&$status, &$quantity = null, &$role = null)
1910 1907
 	{
1911 1908
 		$quantity = 1;
1912 1909
 		$role = 'REQ-PARTICIPANT';
1913 1910
 		//error_log(__METHOD__.__LINE__.array2string($status));
1914 1911
 		$matches = null;
1915
-		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/',$status,$matches))
1912
+		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/', $status, $matches))
1916 1913
 		{
1917 1914
 			if ((int)$matches[1] > 0) $quantity = (int)$matches[1];
1918 1915
 			if ($matches[2]) $role = $matches[2];
@@ -1939,14 +1936,14 @@  discard block
 block discarded – undo
1939 1936
 	 *		true = only add participants if needed, no participant will be deleted (participants to check/add required in $participants)
1940 1937
 	 * @return int|boolean number of updated recurrences or false on error
1941 1938
 	 */
1942
-	function participants($cal_id,$participants,$change_since=0,$add_only=false)
1939
+	function participants($cal_id, $participants, $change_since = 0, $add_only = false)
1943 1940
 	{
1944 1941
 		//error_log(__METHOD__."($cal_id,".array2string($participants).",$change_since,$add_only");
1945 1942
 
1946 1943
 		$recurrences = array();
1947 1944
 
1948 1945
 		// remove group-invitations, they are NOT stored in the db
1949
-		foreach($participants as $uid => $status)
1946
+		foreach ($participants as $uid => $status)
1950 1947
 		{
1951 1948
 			if ($status[0] == 'G')
1952 1949
 			{
@@ -1955,7 +1952,7 @@  discard block
 block discarded – undo
1955 1952
 		}
1956 1953
 		$where = array('cal_id' => $cal_id);
1957 1954
 
1958
-		if ((int) $change_since)
1955
+		if ((int)$change_since)
1959 1956
 		{
1960 1957
 			$where[] = '(cal_recur_date=0 OR cal_recur_date >= '.(int)$change_since.')';
1961 1958
 		}
@@ -1963,31 +1960,31 @@  discard block
 block discarded – undo
1963 1960
 		if ($change_since !== false)
1964 1961
 		{
1965 1962
 			// find all existing recurrences
1966
-			foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row)
1963
+			foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row)
1967 1964
 			{
1968 1965
 				$recurrences[] = $row['cal_recur_date'];
1969 1966
 			}
1970 1967
 
1971 1968
 			// update existing entries
1972
-			$existing_entries = $this->db->select($this->user_table,'*',$where,__LINE__,__FILE__,false,'ORDER BY cal_recur_date DESC','calendar');
1969
+			$existing_entries = $this->db->select($this->user_table, '*', $where, __LINE__, __FILE__, false, 'ORDER BY cal_recur_date DESC', 'calendar');
1973 1970
 
1974 1971
 			// create a full list of participants which already exist in the db
1975 1972
 			// with status, quantity and role of the earliest recurence
1976 1973
 			$old_participants = array();
1977
-			foreach($existing_entries as $row)
1974
+			foreach ($existing_entries as $row)
1978 1975
 			{
1979 1976
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1980 1977
 				if ($row['cal_recur_date'] || !isset($old_participants[$uid]))
1981 1978
 				{
1982
-					$old_participants[$uid] = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
1979
+					$old_participants[$uid] = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
1983 1980
 				}
1984 1981
 			}
1985 1982
 
1986 1983
 			// tag participants which should be deleted
1987
-			if($add_only === false)
1984
+			if ($add_only === false)
1988 1985
 			{
1989 1986
 				$deleted = array();
1990
-				foreach($existing_entries as $row)
1987
+				foreach ($existing_entries as $row)
1991 1988
 				{
1992 1989
 					$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1993 1990
 					// delete not longer set participants
@@ -2000,7 +1997,7 @@  discard block
 block discarded – undo
2000 1997
 
2001 1998
 			// only keep added OR status (incl. quantity!) changed participants for further steps
2002 1999
 			// we do not touch unchanged (!) existing ones
2003
-			foreach($participants as $uid => $status)
2000
+			foreach ($participants as $uid => $status)
2004 2001
 			{
2005 2002
 				if ($old_participants[$uid] === $status)
2006 2003
 				{
@@ -2012,46 +2009,46 @@  discard block
 block discarded – undo
2012 2009
 			if ($add_only === false && count($deleted))
2013 2010
 			{
2014 2011
 				$to_or = array();
2015
-				$table_def = $this->db->get_table_definitions('calendar',$this->user_table);
2016
-				foreach($deleted as $type => $ids)
2012
+				$table_def = $this->db->get_table_definitions('calendar', $this->user_table);
2013
+				foreach ($deleted as $type => $ids)
2017 2014
 				{
2018
-					$to_or[] = $this->db->expression($table_def,array(
2015
+					$to_or[] = $this->db->expression($table_def, array(
2019 2016
 						'cal_user_type' => $type,
2020 2017
 						'cal_user_id'   => $ids,
2021 2018
 					));
2022 2019
 				}
2023
-				$where[] = '('.implode(' OR ',$to_or).')';
2024
-				$where[] = "cal_status!='E'";	// do NOT delete exception marker
2025
-				$this->db->update($this->user_table,array('cal_status'=>'X'),$where,__LINE__,__FILE__,'calendar');
2020
+				$where[] = '('.implode(' OR ', $to_or).')';
2021
+				$where[] = "cal_status!='E'"; // do NOT delete exception marker
2022
+				$this->db->update($this->user_table, array('cal_status'=>'X'), $where, __LINE__, __FILE__, 'calendar');
2026 2023
 			}
2027 2024
 		}
2028 2025
 
2029 2026
 		if (count($participants))	// participants which need to be added
2030 2027
 		{
2031
-			if (!count($recurrences)) $recurrences[] = 0;   // insert the default recurrence
2028
+			if (!count($recurrences)) $recurrences[] = 0; // insert the default recurrence
2032 2029
 
2033 2030
 			$delete_deleted = array();
2034 2031
 
2035 2032
 			// update participants
2036
-			foreach($participants as $uid => $status)
2033
+			foreach ($participants as $uid => $status)
2037 2034
 			{
2038 2035
 				$type = $id = $quantity = $role = null;
2039 2036
 				self::split_user($uid, $type, $id, true);
2040
-				self::split_status($status,$quantity,$role);
2037
+				self::split_status($status, $quantity, $role);
2041 2038
 				$set = array(
2042 2039
 					'cal_status'	  => $status,
2043 2040
 					'cal_quantity'	  => $quantity,
2044 2041
 					'cal_role'        => $role,
2045 2042
 					'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null,
2046 2043
 				);
2047
-				foreach($recurrences as $recur_date)
2044
+				foreach ($recurrences as $recur_date)
2048 2045
 				{
2049
-					$this->db->insert($this->user_table,$set,array(
2046
+					$this->db->insert($this->user_table, $set, array(
2050 2047
 						'cal_id'	      => $cal_id,
2051 2048
 						'cal_recur_date'  => $recur_date,
2052 2049
 						'cal_user_type'   => $type,
2053 2050
 						'cal_user_id' 	  => $id,
2054
-					),__LINE__,__FILE__,'calendar');
2051
+					), __LINE__, __FILE__, 'calendar');
2055 2052
 				}
2056 2053
 				// for new or changed group-invitations, remove previously deleted members, so they show up again
2057 2054
 				if ($uid < 0)
@@ -2061,13 +2058,13 @@  discard block
 block discarded – undo
2061 2058
 			}
2062 2059
 			if ($delete_deleted)
2063 2060
 			{
2064
-				$this->db->delete($this->user_table, $where=array(
2061
+				$this->db->delete($this->user_table, $where = array(
2065 2062
 					'cal_id' => $cal_id,
2066 2063
 					'cal_recur_date' => $recurrences,
2067 2064
 					'cal_user_type' => 'u',
2068 2065
 					'cal_user_id' => array_unique($delete_deleted),
2069 2066
 					'cal_status' => 'X',
2070
-				),__LINE__,__FILE__,'calendar');
2067
+				), __LINE__, __FILE__, 'calendar');
2071 2068
 				//error_log(__METHOD__."($cal_id, ".array2string($participants).", since=$change_since, add_only=$add_only) db->delete('$this->user_table', ".array2string($where).") affected ".$this->db->affected_rows().' rows');
2072 2069
 			}
2073 2070
 		}
@@ -2086,7 +2083,7 @@  discard block
 block discarded – undo
2086 2083
 	 * @param string $attendee =null extra attendee information to set for all types (incl. accounts!)
2087 2084
 	 * @return int number of changed recurrences
2088 2085
 	 */
2089
-	function set_status($cal_id,$user_type,$user_id,$status,$recur_date=0,$role=null,$attendee=null)
2086
+	function set_status($cal_id, $user_type, $user_id, $status, $recur_date = 0, $role = null, $attendee = null)
2090 2087
 	{
2091 2088
 		static $status_code_short = array(
2092 2089
 			REJECTED 	=> 'R',
@@ -2111,7 +2108,7 @@  discard block
 block discarded – undo
2111 2108
 			'cal_user_type'	=> $user_type,
2112 2109
 			'cal_user_id'   => $user_id_md5,
2113 2110
 		);
2114
-		if ((int) $recur_date)
2111
+		if ((int)$recur_date)
2115 2112
 		{
2116 2113
 			$where['cal_recur_date'] = $recur_date;
2117 2114
 		}
@@ -2122,7 +2119,7 @@  discard block
 block discarded – undo
2122 2119
 
2123 2120
 		if ($status == 'G')		// remove group invitations, as we dont store them in the db
2124 2121
 		{
2125
-			$this->db->delete($this->user_table,$where,__LINE__,__FILE__,'calendar');
2122
+			$this->db->delete($this->user_table, $where, __LINE__, __FILE__, 'calendar');
2126 2123
 			$ret = $this->db->affected_rows();
2127 2124
 		}
2128 2125
 		else
@@ -2130,7 +2127,7 @@  discard block
 block discarded – undo
2130 2127
 			$set = array('cal_status' => $status);
2131 2128
 			if ($user_type == 'e' || $attendee) $set['cal_user_attendee'] = $attendee ? $attendee : $user_id;
2132 2129
 			if (!is_null($role) && $role != 'REQ-PARTICIPANT') $set['cal_role'] = $role;
2133
-			$this->db->insert($this->user_table,$set,$where,__LINE__,__FILE__,'calendar');
2130
+			$this->db->insert($this->user_table, $set, $where, __LINE__, __FILE__, 'calendar');
2134 2131
 			// for new or changed group-invitations, remove previously deleted members, so they show up again
2135 2132
 			if (($ret = $this->db->affected_rows()) && $user_type == 'u' && $user_id < 0)
2136 2133
 			{
@@ -2143,7 +2140,7 @@  discard block
 block discarded – undo
2143 2140
 		// update modified and modifier in main table
2144 2141
 		if ($ret)
2145 2142
 		{
2146
-			$this->updateModified($cal_id, true);	// true = update series master too
2143
+			$this->updateModified($cal_id, true); // true = update series master too
2147 2144
 		}
2148 2145
 		//error_log(__METHOD__."($cal_id,$user_type,$user_id,$status,$recur_date) = $ret");
2149 2146
 		return $ret;
@@ -2158,7 +2155,7 @@  discard block
 block discarded – undo
2158 2155
 	 * @param array $participants uid => status pairs
2159 2156
 	 * @param boolean $exception =null true or false to set recure_exception flag, null leave it unchanged (new are by default no exception)
2160 2157
 	 */
2161
-	function recurrence($cal_id,$start,$end,$participants,$exception=null)
2158
+	function recurrence($cal_id, $start, $end, $participants, $exception = null)
2162 2159
 	{
2163 2160
 		//error_log(__METHOD__."($cal_id, $start, $end, ".array2string($participants).", ".array2string($exception));
2164 2161
 		$update = array('cal_end' => $end);
@@ -2167,7 +2164,7 @@  discard block
 block discarded – undo
2167 2164
 		$this->db->insert($this->dates_table, $update, array(
2168 2165
 			'cal_id' => $cal_id,
2169 2166
 			'cal_start'  => $start,
2170
-		),__LINE__,__FILE__,'calendar');
2167
+		), __LINE__, __FILE__, 'calendar');
2171 2168
 
2172 2169
 		if (!is_array($participants))
2173 2170
 		{
@@ -2175,26 +2172,26 @@  discard block
 block discarded – undo
2175 2172
 		}
2176 2173
 		if ($exception !== true)
2177 2174
 		{
2178
-			foreach($participants as $uid => $status)
2175
+			foreach ($participants as $uid => $status)
2179 2176
 			{
2180
-				if ($status == 'G') continue;	// dont save group-invitations
2177
+				if ($status == 'G') continue; // dont save group-invitations
2181 2178
 
2182 2179
 				$type = '';
2183 2180
 				$id = null;
2184 2181
 				self::split_user($uid, $type, $id, true);
2185 2182
 				$quantity = $role = null;
2186
-				self::split_status($status,$quantity,$role);
2187
-				$this->db->insert($this->user_table,array(
2183
+				self::split_status($status, $quantity, $role);
2184
+				$this->db->insert($this->user_table, array(
2188 2185
 					'cal_status'	=> $status,
2189 2186
 					'cal_quantity'	=> $quantity,
2190 2187
 					'cal_role'		=> $role,
2191 2188
 					'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null,
2192
-				),array(
2189
+				), array(
2193 2190
 					'cal_id'		 => $cal_id,
2194 2191
 					'cal_recur_date' => $start,
2195 2192
 					'cal_user_type'  => $type,
2196 2193
 					'cal_user_id' 	 => $id,
2197
-				),__LINE__,__FILE__,'calendar');
2194
+				), __LINE__, __FILE__, 'calendar');
2198 2195
 			}
2199 2196
 		}
2200 2197
 	}
@@ -2208,7 +2205,7 @@  discard block
 block discarded – undo
2208 2205
 	function unfinished_recuring($time)
2209 2206
 	{
2210 2207
 		$ids = array();
2211
-		foreach($rs=$this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start",
2208
+		foreach ($rs = $this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start",
2212 2209
 			'(range_end IS NULL OR range_end > '.(int)$time.')',
2213 2210
 			__LINE__, __FILE__, false, "GROUP BY $this->repeats_table.cal_id,range_end", 'calendar', 0,
2214 2211
 			" JOIN $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id".
@@ -2234,9 +2231,9 @@  discard block
 block discarded – undo
2234 2231
 		// update timestamp of series master, updates own timestamp too, which does not hurt ;-)
2235 2232
 		$this->updateModified($cal_id, true);
2236 2233
 
2237
-		foreach($this->all_tables as $table)
2234
+		foreach ($this->all_tables as $table)
2238 2235
 		{
2239
-			$this->db->delete($table,array('cal_id'=>$cal_id),__LINE__,__FILE__,'calendar');
2236
+			$this->db->delete($table, array('cal_id'=>$cal_id), __LINE__, __FILE__, 'calendar');
2240 2237
 		}
2241 2238
 	}
2242 2239
 
@@ -2252,10 +2249,10 @@  discard block
 block discarded – undo
2252 2249
 	function purge($date)
2253 2250
 	{
2254 2251
 		// with new range_end we simple delete all with range_end < $date (range_end NULL is never returned)
2255
-		foreach($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row)
2252
+		foreach ($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row)
2256 2253
 		{
2257 2254
 			//echo __METHOD__." About to delete".$row['cal_id']."\r\n";
2258
-			foreach($this->all_tables as $table)
2255
+			foreach ($this->all_tables as $table)
2259 2256
 			{
2260 2257
 				$this->db->delete($table, array('cal_id'=>$row['cal_id']), __LINE__, __FILE__, 'calendar');
2261 2258
 			}
@@ -2280,23 +2277,23 @@  discard block
 block discarded – undo
2280 2277
 	 * @param boolean $update_cache =null true: re-read given $cal_id, false: delete given $cal_id
2281 2278
 	 * @return array of (cal_id => array of) alarms with alarm-id as key
2282 2279
 	 */
2283
-	function read_alarms($cal_id, $update_cache=null)
2280
+	function read_alarms($cal_id, $update_cache = null)
2284 2281
 	{
2285 2282
 		if (!isset(self::$alarm_cache) && is_array($cal_id))
2286 2283
 		{
2287 2284
 			self::$alarm_cache = array();
2288 2285
 			if (($jobs = $this->async->read('cal:%')))
2289 2286
 			{
2290
-				foreach($jobs as $id => $job)
2287
+				foreach ($jobs as $id => $job)
2291 2288
 				{
2292
-					$alarm         = $job['data'];	// text, enabled
2289
+					$alarm         = $job['data']; // text, enabled
2293 2290
 					$alarm['id']   = $id;
2294 2291
 					$alarm['time'] = $job['next'];
2295 2292
 
2296 2293
 					self::$alarm_cache[$alarm['cal_id']][$id] = $alarm;
2297 2294
 				}
2298 2295
 			}
2299
-			unset($update_cache);	// just done
2296
+			unset($update_cache); // just done
2300 2297
 		}
2301 2298
 		$alarms = array();
2302 2299
 
@@ -2304,13 +2301,13 @@  discard block
 block discarded – undo
2304 2301
 		{
2305 2302
 			if (isset($update_cache))
2306 2303
 			{
2307
-				foreach((array)$cal_id as $id)
2304
+				foreach ((array)$cal_id as $id)
2308 2305
 				{
2309 2306
 					if ($update_cache === false)
2310 2307
 					{
2311 2308
 						unset(self::$alarm_cache[$cal_id]);
2312 2309
 					}
2313
-					elseif($update_cache === true)
2310
+					elseif ($update_cache === true)
2314 2311
 					{
2315 2312
 						self::$alarm_cache[$cal_id] = $this->read_alarms_nocache($cal_id);
2316 2313
 					}
@@ -2322,7 +2319,7 @@  discard block
 block discarded – undo
2322 2319
 			}
2323 2320
 			else
2324 2321
 			{
2325
-				foreach($cal_id as $id)
2322
+				foreach ($cal_id as $id)
2326 2323
 				{
2327 2324
 					$alarms[$id] = (array)self::$alarm_cache[$id];
2328 2325
 				}
@@ -2337,9 +2334,9 @@  discard block
 block discarded – undo
2337 2334
 	{
2338 2335
 		if (($jobs = $this->async->read('cal:'.(int)$cal_id.':%')))
2339 2336
 		{
2340
-			foreach($jobs as $id => $job)
2337
+			foreach ($jobs as $id => $job)
2341 2338
 			{
2342
-				$alarm         = $job['data'];	// text, enabled
2339
+				$alarm         = $job['data']; // text, enabled
2343 2340
 				$alarm['id']   = $id;
2344 2341
 				$alarm['time'] = $job['next'];
2345 2342
 
@@ -2364,7 +2361,7 @@  discard block
 block discarded – undo
2364 2361
 		}
2365 2362
 		$alarm_id = key($jobs);
2366 2363
 		$job = current($jobs);
2367
-		$alarm         = $job['data'];	// text, enabled
2364
+		$alarm         = $job['data']; // text, enabled
2368 2365
 		$alarm['id']   = $alarm_id;
2369 2366
 		$alarm['time'] = $job['next'];
2370 2367
 
@@ -2380,12 +2377,12 @@  discard block
 block discarded – undo
2380 2377
 	 * @param boolean $update_modified =true call update modified, default true
2381 2378
 	 * @return string id of the alarm
2382 2379
 	 */
2383
-	function save_alarm($cal_id, $alarm, $update_modified=true)
2380
+	function save_alarm($cal_id, $alarm, $update_modified = true)
2384 2381
 	{
2385 2382
 		//error_log(__METHOD__."($cal_id, ".array2string($alarm).', '.array2string($update_modified).') '.function_backtrace());
2386 2383
 		if (!($id = $alarm['id']))
2387 2384
 		{
2388
-			$alarms = $this->read_alarms($cal_id);	// find a free alarm#
2385
+			$alarms = $this->read_alarms($cal_id); // find a free alarm#
2389 2386
 			$n = count($alarms);
2390 2387
 			do
2391 2388
 			{
@@ -2398,13 +2395,13 @@  discard block
 block discarded – undo
2398 2395
 		{
2399 2396
 			$this->async->cancel_timer($id);
2400 2397
 		}
2401
-		$alarm['cal_id'] = $cal_id;		// we need the back-reference
2398
+		$alarm['cal_id'] = $cal_id; // we need the back-reference
2402 2399
 		// do not deleted async-job, as we need it for alarm snozzing
2403 2400
 		$alarm['keep'] = self::ALARM_KEEP_TIME;
2404 2401
 		// past alarms need NOT to be triggered, but kept around for a while to allow alarm snozzing
2405 2402
 		if ($alarm['time'] < time())
2406 2403
 		{
2407
-			$alarm['time'] = $alarm['keep_time'] = time()+self::ALARM_KEEP_TIME;
2404
+			$alarm['time'] = $alarm['keep_time'] = time() + self::ALARM_KEEP_TIME;
2408 2405
 		}
2409 2406
 		// add an alarm uid, if none is given
2410 2407
 		if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) $alarm['uid'] = (string)new Horde_Support_Uuid;
@@ -2437,7 +2434,7 @@  discard block
 block discarded – undo
2437 2434
 		//error_log(__METHOD__."($cal_id) ".function_backtrace());
2438 2435
 		if (($alarms = $this->read_alarms($cal_id)))
2439 2436
 		{
2440
-			foreach(array_keys($alarms) as $id)
2437
+			foreach (array_keys($alarms) as $id)
2441 2438
 			{
2442 2439
 				$this->async->cancel_timer($id);
2443 2440
 			}
@@ -2457,7 +2454,7 @@  discard block
 block discarded – undo
2457 2454
 	{
2458 2455
 		//error_log(__METHOD__."('$id') ".function_backtrace());
2459 2456
 		// update the modification information of the related event
2460
-		list(,$cal_id) = explode(':',$id);
2457
+		list(,$cal_id) = explode(':', $id);
2461 2458
 		if ($cal_id)
2462 2459
 		{
2463 2460
 			$this->updateModified($cal_id, true);
@@ -2476,7 +2473,7 @@  discard block
 block discarded – undo
2476 2473
 	 * @param array|int $old_user integer old user or array with keys 'account_id' and 'new_owner' as the deleteaccount hook uses it
2477 2474
 	 * @param int $new_user =null
2478 2475
 	 */
2479
-	function deleteaccount($old_user, $new_user=null)
2476
+	function deleteaccount($old_user, $new_user = null)
2480 2477
 	{
2481 2478
 		if (is_array($old_user))
2482 2479
 		{
@@ -2487,52 +2484,52 @@  discard block
 block discarded – undo
2487 2484
 		{
2488 2485
 			$user_type = '';
2489 2486
 			$user_id = null;
2490
-			self::split_user($old_user,$user_type,$user_id);
2487
+			self::split_user($old_user, $user_type, $user_id);
2491 2488
 
2492 2489
 			if ($user_type == 'u')	// only accounts can be owners of events
2493 2490
 			{
2494
-				foreach($this->db->select($this->cal_table,'cal_id',array('cal_owner' => $old_user),__LINE__,__FILE__,false,'','calendar') as $row)
2491
+				foreach ($this->db->select($this->cal_table, 'cal_id', array('cal_owner' => $old_user), __LINE__, __FILE__, false, '', 'calendar') as $row)
2495 2492
 				{
2496 2493
 					$this->delete($row['cal_id']);
2497 2494
 				}
2498 2495
 			}
2499
-			$this->db->delete($this->user_table,array(
2496
+			$this->db->delete($this->user_table, array(
2500 2497
 				'cal_user_type' => $user_type,
2501 2498
 				'cal_user_id'   => $user_id,
2502
-			),__LINE__,__FILE__,'calendar');
2499
+			), __LINE__, __FILE__, 'calendar');
2503 2500
 
2504 2501
 			// delete calendar entries without participants (can happen if the deleted user is the only participants, but not the owner)
2505
-			foreach($this->db->select($this->cal_table,"DISTINCT $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__,
2506
-				False,'','calendar',0,"LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2502
+			foreach ($this->db->select($this->cal_table, "DISTINCT $this->cal_table.cal_id", 'cal_user_id IS NULL', __LINE__, __FILE__,
2503
+				False, '', 'calendar', 0, "LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2507 2504
 			{
2508 2505
 				$this->delete($row['cal_id']);
2509 2506
 			}
2510 2507
 		}
2511 2508
 		else
2512 2509
 		{
2513
-			$this->db->update($this->cal_table,array('cal_owner' => $new_user),array('cal_owner' => $old_user),__LINE__,__FILE__,'calendar');
2510
+			$this->db->update($this->cal_table, array('cal_owner' => $new_user), array('cal_owner' => $old_user), __LINE__, __FILE__, 'calendar');
2514 2511
 			// delete participation of old user, if new user is already a participant
2515 2512
 			$ids = array();
2516
-			foreach($this->db->select($this->user_table,'cal_id',array(		// MySQL does NOT allow to run this as delete!
2513
+			foreach ($this->db->select($this->user_table, 'cal_id', array(		// MySQL does NOT allow to run this as delete!
2517 2514
 				'cal_user_type' => 'u',
2518 2515
 				'cal_user_id' => $old_user,
2519 2516
 				"cal_id IN (SELECT cal_id FROM $this->user_table other WHERE other.cal_id=cal_id AND other.cal_user_id=".$this->db->quote($new_user)." AND cal_user_type='u')",
2520
-			),__LINE__,__FILE__,false,'','calendar') as $row)
2517
+			), __LINE__, __FILE__, false, '', 'calendar') as $row)
2521 2518
 			{
2522 2519
 				$ids[] = $row['cal_id'];
2523 2520
 			}
2524
-			if ($ids) $this->db->delete($this->user_table,array(
2521
+			if ($ids) $this->db->delete($this->user_table, array(
2525 2522
 				'cal_user_type' => 'u',
2526 2523
 				'cal_user_id' => $old_user,
2527 2524
 				'cal_id' => $ids,
2528
-			),__LINE__,__FILE__,'calendar');
2525
+			), __LINE__, __FILE__, 'calendar');
2529 2526
 			// now change participant in the rest to contain new user instead of old user
2530
-			$this->db->update($this->user_table,array(
2527
+			$this->db->update($this->user_table, array(
2531 2528
 				'cal_user_id' => $new_user,
2532
-			),array(
2529
+			), array(
2533 2530
 				'cal_user_type' => 'u',
2534 2531
 				'cal_user_id' => $old_user,
2535
-			),__LINE__,__FILE__,'calendar');
2532
+			), __LINE__, __FILE__, 'calendar');
2536 2533
 		}
2537 2534
 	}
2538 2535
 
@@ -2546,18 +2543,18 @@  discard block
 block discarded – undo
2546 2543
 	 *
2547 2544
 	 * @return array recur_date => status pairs (index 0 => main status)
2548 2545
 	 */
2549
-	function get_recurrences($cal_id, $uid=null, $start=0, $end=0)
2546
+	function get_recurrences($cal_id, $uid = null, $start = 0, $end = 0)
2550 2547
 	{
2551 2548
 		$participant_status = array();
2552 2549
 		$where = array('cal_id' => $cal_id);
2553
-		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2554
-		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2550
+		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')';
2551
+		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')';
2555 2552
 		if ($start != 0 && $end != 0)
2556 2553
 		{
2557
-			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
2558
-						' AND cal_recur_date <= ' . (int)$end . '))';
2554
+			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start.
2555
+						' AND cal_recur_date <= '.(int)$end.'))';
2559 2556
 		}
2560
-		foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row)
2557
+		foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row)
2561 2558
 		{
2562 2559
 			// inititalize the array
2563 2560
 			$participant_status[$row['cal_recur_date']] = null;
@@ -2571,17 +2568,17 @@  discard block
 block discarded – undo
2571 2568
 			'cal_user_type'	=> $user_type ? $user_type : 'u',
2572 2569
 			'cal_user_id'   => $user_id,
2573 2570
 		);
2574
-		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2575
-		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2571
+		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')';
2572
+		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')';
2576 2573
 		if ($start != 0 && $end != 0)
2577 2574
 		{
2578
-			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
2579
-						' AND cal_recur_date <= ' . (int)$end . '))';
2575
+			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start.
2576
+						' AND cal_recur_date <= '.(int)$end.'))';
2580 2577
 		}
2581
-		foreach ($this->db->select($this->user_table,'cal_recur_date,cal_status,cal_quantity,cal_role',$where2,
2582
-				__LINE__,__FILE__,false,'','calendar') as $row)
2578
+		foreach ($this->db->select($this->user_table, 'cal_recur_date,cal_status,cal_quantity,cal_role', $where2,
2579
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2583 2580
 		{
2584
-			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
2581
+			$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
2585 2582
 			$participant_status[$row['cal_recur_date']] = $status;
2586 2583
 		}
2587 2584
 		return $participant_status;
@@ -2630,8 +2627,8 @@  discard block
 block discarded – undo
2630 2627
 			'cal_uid'		=> $uid,
2631 2628
 		);
2632 2629
 		$related = array();
2633
-		foreach ($this->db->select($this->cal_table,'cal_id,cal_reference',$where,
2634
-				__LINE__,__FILE__,false,'','calendar') as $row)
2630
+		foreach ($this->db->select($this->cal_table, 'cal_id,cal_reference', $where,
2631
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2635 2632
 		{
2636 2633
 			if ($row['cal_reference'] != 0)
2637 2634
 			{
@@ -2660,10 +2657,10 @@  discard block
 block discarded – undo
2660 2657
 	 *
2661 2658
 	 * @return array		Array of exception days (false for non-recurring events).
2662 2659
 	 */
2663
-	function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all')
2660
+	function get_recurrence_exceptions($event, $tz_id = null, $start = 0, $end = 0, $filter = 'all')
2664 2661
 	{
2665 2662
 		if (!is_array($event)) return false;
2666
-		$cal_id = (int) $event['id'];
2663
+		$cal_id = (int)$event['id'];
2667 2664
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2668 2665
 		//		"($cal_id, $tz_id, $filter): " . $event['tzid']);
2669 2666
 		if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false;
@@ -2687,27 +2684,27 @@  discard block
 block discarded – undo
2687 2684
 		while ($egw_rrule->valid())
2688 2685
 		{
2689 2686
 			while ($egw_rrule->exceptions &&
2690
-				in_array($egw_rrule->current->format('Ymd'),$egw_rrule->exceptions))
2687
+				in_array($egw_rrule->current->format('Ymd'), $egw_rrule->exceptions))
2691 2688
 			{
2692
-				if (in_array($filter, array('map','tz_map','rrule','tz_rrule')))
2689
+				if (in_array($filter, array('map', 'tz_map', 'rrule', 'tz_rrule')))
2693 2690
 				{
2694 2691
 					 // real exception
2695
-					$locts = (int)Api\DateTime::to($egw_rrule->current(),'server');
2692
+					$locts = (int)Api\DateTime::to($egw_rrule->current(), 'server');
2696 2693
 					if ($expand_all)
2697 2694
 					{
2698
-						$remts = (int)Api\DateTime::to($remote_rrule->current(),'server');
2695
+						$remts = (int)Api\DateTime::to($remote_rrule->current(), 'server');
2699 2696
 						if ($remote)
2700 2697
 						{
2701
-							$days[$locts]= $remts;
2698
+							$days[$locts] = $remts;
2702 2699
 						}
2703 2700
 						else
2704 2701
 						{
2705
-							$days[$remts]= $locts;
2702
+							$days[$remts] = $locts;
2706 2703
 						}
2707 2704
 					}
2708 2705
 					else
2709 2706
 					{
2710
-						$days[$locts]= $locts;
2707
+						$days[$locts] = $locts;
2711 2708
 					}
2712 2709
 				}
2713 2710
 				if ($expand_all)
@@ -2718,14 +2715,14 @@  discard block
 block discarded – undo
2718 2715
 				if (!$egw_rrule->valid()) return $days;
2719 2716
 			}
2720 2717
 			$day = $egw_rrule->current();
2721
-			$locts = (int)Api\DateTime::to($day,'server');
2718
+			$locts = (int)Api\DateTime::to($day, 'server');
2722 2719
 			$tz_exception = ($filter == 'tz_rrule');
2723 2720
 			//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2724 2721
 			//	'()[EVENT Server]: ' . $day->format('Ymd\THis') . " ($locts)");
2725 2722
 			if ($expand_all)
2726 2723
 			{
2727 2724
 				$remote_day = $remote_rrule->current();
2728
-				$remts = (int)Api\DateTime::to($remote_day,'server');
2725
+				$remts = (int)Api\DateTime::to($remote_day, 'server');
2729 2726
 			//	error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2730 2727
 			//	'()[EVENT Device]: ' . $remote_day->format('Ymd\THis') . " ($remts)");
2731 2728
 			}
@@ -2744,11 +2741,11 @@  discard block
 block discarded – undo
2744 2741
 						//	'() tz exception: ' . $day->format('Ymd\THis'));
2745 2742
 						if ($remote)
2746 2743
 						{
2747
-							$days[$locts]= $remts;
2744
+							$days[$locts] = $remts;
2748 2745
 						}
2749 2746
 						else
2750 2747
 						{
2751
-							$days[$remts]= $locts;
2748
+							$days[$remts] = $locts;
2752 2749
 						}
2753 2750
 					}
2754 2751
 				}
@@ -2770,18 +2767,18 @@  discard block
 block discarded – undo
2770 2767
 							{
2771 2768
 								if ($remote)
2772 2769
 								{
2773
-									$days[$locts]= $remts;
2770
+									$days[$locts] = $remts;
2774 2771
 								}
2775 2772
 								else
2776 2773
 								{
2777
-									$days[$remts]= $locts;
2774
+									$days[$remts] = $locts;
2778 2775
 								}
2779 2776
 							}
2780 2777
 						}
2781 2778
 					}
2782 2779
 					elseif ($filter != 'map')
2783 2780
 					{
2784
-						$days[$locts]= $locts;
2781
+						$days[$locts] = $locts;
2785 2782
 					}
2786 2783
 				}
2787 2784
 				elseif (($filter == 'map' || filter == 'tz_map') &&
@@ -2791,11 +2788,11 @@  discard block
 block discarded – undo
2791 2788
 					if ($expand_all)
2792 2789
 					{
2793 2790
 
2794
-						$days[$remts]= $locts;
2791
+						$days[$remts] = $locts;
2795 2792
 					}
2796 2793
 					else
2797 2794
 					{
2798
-						$days[$locts]= $locts;
2795
+						$days[$locts] = $locts;
2799 2796
 					}
2800 2797
 				}
2801 2798
 			}
@@ -2819,9 +2816,9 @@  discard block
 block discarded – undo
2819 2816
 	 */
2820 2817
 	function status_pseudo_exception($cal_id, $recur_date, $filter)
2821 2818
 	{
2822
-		static $recurrence_zero=null;
2823
-		static $cached_id=null;
2824
-		static $user=null;
2819
+		static $recurrence_zero = null;
2820
+		static $cached_id = null;
2821
+		static $user = null;
2825 2822
 
2826 2823
 		if (!isset($cached_id) || $cached_id != $cal_id)
2827 2824
 		{
@@ -2832,8 +2829,8 @@  discard block
 block discarded – undo
2832 2829
 				'cal_id' => $cal_id,
2833 2830
 				'cal_recur_date' => 0,
2834 2831
 			);
2835
-			foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where,
2836
-				__LINE__,__FILE__,false,'','calendar') as $row)
2832
+			foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where,
2833
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2837 2834
 			{
2838 2835
 				switch ($row['cal_user_type'])
2839 2836
 				{
@@ -2856,8 +2853,8 @@  discard block
 block discarded – undo
2856 2853
 			'cal_id' => $cal_id,
2857 2854
 			'cal_recur_date' => $recur_date,
2858 2855
 		);
2859
-		foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where,
2860
-			__LINE__,__FILE__,false,'','calendar') as $row)
2856
+		foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where,
2857
+			__LINE__, __FILE__, false, '', 'calendar') as $row)
2861 2858
 		{
2862 2859
 			switch ($row['cal_user_type'])
2863 2860
 			{
@@ -2882,42 +2879,42 @@  discard block
 block discarded – undo
2882 2879
 						if ($status != 'U')
2883 2880
 						{
2884 2881
 							unset($participants[$uid]);
2885
-							continue 2;	// +1 for switch
2882
+							continue 2; // +1 for switch
2886 2883
 						}
2887 2884
 						break;
2888 2885
 					case 'accepted':
2889 2886
 						if ($status != 'A')
2890 2887
 						{
2891 2888
 							unset($participants[$uid]);
2892
-							continue 2;	// +1 for switch
2889
+							continue 2; // +1 for switch
2893 2890
 						}
2894 2891
 						break;
2895 2892
 					case 'tentative':
2896 2893
 						if ($status != 'T')
2897 2894
 						{
2898 2895
 							unset($participants[$uid]);
2899
-							continue 2;	// +1 for switch
2896
+							continue 2; // +1 for switch
2900 2897
 						}
2901 2898
 						break;
2902 2899
 					case 'rejected':
2903 2900
 						if ($status != 'R')
2904 2901
 						{
2905 2902
 							unset($participants[$uid]);
2906
-							continue 2;	// +1 for switch
2903
+							continue 2; // +1 for switch
2907 2904
 						}
2908 2905
 						break;
2909 2906
 					case 'delegated':
2910 2907
 						if ($status != 'D')
2911 2908
 						{
2912 2909
 							unset($participants[$uid]);
2913
-							continue 2;	// +1 for switch
2910
+							continue 2; // +1 for switch
2914 2911
 						}
2915 2912
 						break;
2916 2913
 					case 'default':
2917 2914
 						if ($status == 'R')
2918 2915
 						{
2919 2916
 							unset($participants[$uid]);
2920
-							continue 2;	// +1 for switch
2917
+							continue 2; // +1 for switch
2921 2918
 						}
2922 2919
 						break;
2923 2920
 					default:
@@ -2954,14 +2951,14 @@  discard block
 block discarded – undo
2954 2951
 			}
2955 2952
 			$timezone = self::$tz_cache[$event['tzid']];
2956 2953
 		}
2957
-		$start_time = new Api\DateTime($event['start'],Api\DateTime::$server_timezone);
2954
+		$start_time = new Api\DateTime($event['start'], Api\DateTime::$server_timezone);
2958 2955
 		$start_time->setTimezone($timezone);
2959
-		$end_time = new Api\DateTime($event['end'],Api\DateTime::$server_timezone);
2956
+		$end_time = new Api\DateTime($event['end'], Api\DateTime::$server_timezone);
2960 2957
 		$end_time->setTimezone($timezone);
2961 2958
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2962 2959
 		//	'(): ' . $start . '-' . $end);
2963
-		$start = Api\DateTime::to($start_time,'array');
2964
-		$end = Api\DateTime::to($end_time,'array');
2960
+		$start = Api\DateTime::to($start_time, 'array');
2961
+		$end = Api\DateTime::to($end_time, 'array');
2965 2962
 
2966 2963
 
2967 2964
 		return !$start['hour'] && !$start['minute'] && $end['hour'] == 23 && $end['minute'] == 59;
@@ -2975,7 +2972,7 @@  discard block
 block discarded – undo
2975 2972
 	 *
2976 2973
 	 * @return DateTime
2977 2974
 	 */
2978
-	function &startOfDay(Api\DateTime $time, $tz_id=null)
2975
+	function &startOfDay(Api\DateTime $time, $tz_id = null)
2979 2976
 	{
2980 2977
 		if (empty($tz_id))
2981 2978
 		{
@@ -3000,14 +2997,14 @@  discard block
 block discarded – undo
3000 2997
 	 * @param int $time =null new timestamp, default current (server-)time
3001 2998
 	 * @param int $modifier =null uid of the modifier, default current user
3002 2999
 	 */
3003
-	function updateModified($id, $update_master=false, $time=null, $modifier=null)
3000
+	function updateModified($id, $update_master = false, $time = null, $modifier = null)
3004 3001
 	{
3005 3002
 		if (is_null($time) || !$time) $time = time();
3006 3003
 		if (is_null($modifier)) $modifier = $GLOBALS['egw_info']['user']['account_id'];
3007 3004
 
3008 3005
 		$this->db->update($this->cal_table,
3009 3006
 			array('cal_modified' => $time, 'cal_modifier' => $modifier),
3010
-			array('cal_id' => $id), __LINE__,__FILE__, 'calendar');
3007
+			array('cal_id' => $id), __LINE__, __FILE__, 'calendar');
3011 3008
 
3012 3009
 		// if event is an exception: update modified of master, to force etag, ctag and sync-token change
3013 3010
 		if ($update_master)
Please login to merge, or discard this patch.
calendar/importexport/class.import_events_csv.inc.php 3 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 	private $user = null;
83 83
 
84 84
 	/**
85
-         * List of import errors
86
-         */
87
-        protected $errors = array();
85
+	 * List of import errors
86
+	 */
87
+		protected $errors = array();
88 88
 
89 89
 	/**
90 90
 	 * List of actions, and how many times that action was taken
@@ -305,26 +305,26 @@  discard block
 block discarded – undo
305 305
 	}
306 306
 
307 307
 	/**
308
-        * Returns errors that were encountered during importing
309
-        * Maximum of one error message per record, but you can append if you need to
310
-        *
311
-        * @return Array (
312
-        *       record_# => error message
313
-        *       )
314
-        */
315
-        public function get_errors() {
308
+	 * Returns errors that were encountered during importing
309
+	 * Maximum of one error message per record, but you can append if you need to
310
+	 *
311
+	 * @return Array (
312
+	 *       record_# => error message
313
+	 *       )
314
+	 */
315
+		public function get_errors() {
316 316
 		return $this->errors;
317 317
 	}
318 318
 
319 319
 	/**
320
-        * Returns a list of actions taken, and the number of records for that action.
321
-        * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
322
-        *
323
-        * @return Array (
324
-        *       action => record count
325
-        * )
326
-        */
327
-        public function get_results() {
320
+	 * Returns a list of actions taken, and the number of records for that action.
321
+	 * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
322
+	 *
323
+	 * @return Array (
324
+	 *       action => record count
325
+	 * )
326
+	 */
327
+		public function get_results() {
328 328
 		return $this->results;
329 329
 	}
330 330
 } // end of iface_export_plugin
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -10,28 +10,28 @@  discard block
 block discarded – undo
10 10
  * @version $Id: $
11 11
  */
12 12
 
13
-require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.iface_import_plugin.inc.php');
13
+require_once(EGW_INCLUDE_ROOT.'/importexport/inc/class.iface_import_plugin.inc.php');
14 14
 require_once(EGW_INCLUDE_ROOT.'/importexport/inc/class.import_csv.inc.php');
15 15
 
16 16
 
17 17
 /**
18 18
  * class import_csv for addressbook
19 19
  */
20
-class import_events_csv implements iface_import_plugin  {
20
+class import_events_csv implements iface_import_plugin {
21 21
 
22 22
 	private static $plugin_options = array(
23
-		'fieldsep', 			// char
24
-		'charset', 				// string
25
-		'event_owner', 			// int account_id or -1 for leave untuched
26
-		'owner_joins_event',	// bool
27
-		'update_cats', 			// string {override|add} overides record
23
+		'fieldsep', // char
24
+		'charset', // string
25
+		'event_owner', // int account_id or -1 for leave untuched
26
+		'owner_joins_event', // bool
27
+		'update_cats', // string {override|add} overides record
28 28
 								// with cat(s) from csv OR add the cat from
29 29
 								// csv file to exeisting cat(s) of record
30
-		'num_header_lines',		// int number of header lines
31
-		'trash_users_records',	// trashes all events of events owner before import
32
-		'field_conversion', 	// array( $csv_col_num => conversion)
33
-		'field_mapping',		// array( $csv_col_num => adb_filed)
34
-		'conditions',			/* => array containing condition arrays:
30
+		'num_header_lines', // int number of header lines
31
+		'trash_users_records', // trashes all events of events owner before import
32
+		'field_conversion', // array( $csv_col_num => conversion)
33
+		'field_mapping', // array( $csv_col_num => adb_filed)
34
+		'conditions', /* => array containing condition arrays:
35 35
 				'type' => exists, // record['uid'] exists
36 36
 				'true' => array(
37 37
 					'action' => update,
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 	/**
48 48
 	 * actions wich could be done to data entries
49 49
 	 */
50
-	private static $actions = array( 'none', 'update', 'insert', 'delete', );
50
+	private static $actions = array('none', 'update', 'insert', 'delete',);
51 51
 
52 52
 	/**
53 53
 	 * conditions for actions
54 54
 	 *
55 55
 	 * @var array
56 56
 	 */
57
-	private static $conditions = array( 'exists', 'empty', );
57
+	private static $conditions = array('exists', 'empty',);
58 58
 
59 59
 	/**
60 60
 	 * @var definition
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 	 * @param string $_charset
98 98
 	 * @param definition $_definition
99 99
 	 */
100
-	public function import( $_stream, definition $_definition ) {
101
-		$import_csv = new import_csv( $_stream, array(
100
+	public function import($_stream, definition $_definition) {
101
+		$import_csv = new import_csv($_stream, array(
102 102
 			'fieldsep' => $_definition->plugin_options['fieldsep'],
103 103
 			'charset' => $_definition->plugin_options['charset'],
104 104
 		));
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 		$this->definition = $_definition;
107 107
 
108 108
 		// user, is admin ?
109
-		$this->is_admin = isset( $GLOBALS['egw_info']['user']['apps']['admin'] ) && $GLOBALS['egw_info']['user']['apps']['admin'];
109
+		$this->is_admin = isset($GLOBALS['egw_info']['user']['apps']['admin']) && $GLOBALS['egw_info']['user']['apps']['admin'];
110 110
 		$this->user = $GLOBALS['egw_info']['user']['account_id'];
111 111
 
112 112
 		// dry run?
113
-		$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] :  false;
113
+		$this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false;
114 114
 
115 115
 		// fetch the calendar bo
116 116
 		$this->bocalupdate = new calendar_boupdate();
@@ -122,24 +122,24 @@  discard block
 block discarded – undo
122 122
 		$import_csv->conversion = $_definition->plugin_options['field_conversion'];
123 123
 
124 124
 		//check if file has a header lines
125
-		if ( isset( $_definition->plugin_options['num_header_lines'] ) ) {
126
-			$import_csv->skip_records( $_definition->plugin_options['num_header_lines'] );
125
+		if (isset($_definition->plugin_options['num_header_lines'])) {
126
+			$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
127 127
 		}
128 128
 
129 129
 		// set eventOwner
130 130
 		$plugin_options = $_definition->plugin_options;
131
-		$plugin_options['events_owner'] = isset( $_definition->plugin_options['events_owner'] ) ?
131
+		$plugin_options['events_owner'] = isset($_definition->plugin_options['events_owner']) ?
132 132
 			$_definition->plugin_options['events_owner'] : $this->user;
133 133
 		$_definition->plugin_options = $plugin_options;
134 134
 
135 135
 		// trash_users_records ?
136
-		if ( $_definition->plugin_options['trash_users_records'] === true ) {
137
-			if ( !$_definition->plugin_options['dry_run'] ) {
136
+		if ($_definition->plugin_options['trash_users_records'] === true) {
137
+			if (!$_definition->plugin_options['dry_run']) {
138 138
 				$socal = new calendar_socal();
139
-				$this->bocalupdate->so->deleteaccount( $_definition->plugin_options['events_owner']);
140
-				unset( $socal );
139
+				$this->bocalupdate->so->deleteaccount($_definition->plugin_options['events_owner']);
140
+				unset($socal);
141 141
 			} else {
142
-				$lid = $GLOBALS['egw']->accounts->id2name( $_definition->plugin_options['events_owner'] );
142
+				$lid = $GLOBALS['egw']->accounts->id2name($_definition->plugin_options['events_owner']);
143 143
 				echo "Attension: All Events of '$lid' would be deleted!\n";
144 144
 			}
145 145
 		}
@@ -147,44 +147,44 @@  discard block
 block discarded – undo
147 147
 		$this->errors = array();
148 148
 		$this->results = array();
149 149
 
150
-		while ( $record = $import_csv->get_record() ) {
150
+		while ($record = $import_csv->get_record()) {
151 151
 
152 152
 			// don't import empty events
153
-			if( count( array_unique( $record ) ) < 2 ) continue;
153
+			if (count(array_unique($record)) < 2) continue;
154 154
 
155
-			if ( $_definition->plugin_options['events_owner'] != -1 ) {
155
+			if ($_definition->plugin_options['events_owner'] != -1) {
156 156
 				$record['owner'] = $_definition->plugin_options['events_owner'];
157
-			} else unset( $record['owner'] );
157
+			} else unset($record['owner']);
158 158
 
159
-			if ( $_definition->plugin_options['conditions'] ) {
160
-				foreach ( $_definition->plugin_options['conditions'] as $condition ) {
161
-					switch ( $condition['type'] ) {
159
+			if ($_definition->plugin_options['conditions']) {
160
+				foreach ($_definition->plugin_options['conditions'] as $condition) {
161
+					switch ($condition['type']) {
162 162
 						// exists
163 163
 						case 'exists' :
164 164
 
165
-							if ( is_array( $event = $this->bocalupdate->read( $record['uid'], null, $this->is_admin ) ) ) {
165
+							if (is_array($event = $this->bocalupdate->read($record['uid'], null, $this->is_admin))) {
166 166
 								// apply action to event matching this exists condition
167 167
 								$record['id'] = $event['id'];
168 168
 
169
-								if ( $_definition->plugin_options['update_cats'] == 'add' ) {
170
-									if ( !is_array( $event['cat_id'] ) ) $event['cat_id'] = explode( ',', $event['cat_id'] );
171
-									if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] );
172
-									$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $event['cat_id'] ) ) );
169
+								if ($_definition->plugin_options['update_cats'] == 'add') {
170
+									if (!is_array($event['cat_id'])) $event['cat_id'] = explode(',', $event['cat_id']);
171
+									if (!is_array($record['cat_id'])) $record['cat_id'] = explode(',', $record['cat_id']);
172
+									$record['cat_id'] = implode(',', array_unique(array_merge($record['cat_id'], $event['cat_id'])));
173 173
 								}
174 174
 
175 175
 								// check if entry is modiefied
176
-								$event = array_intersect_key( $event, $record );
177
-								$diff = array_diff( $event, $record );
178
-								if( !empty( $diff ) ) $record['modified'] = time();
176
+								$event = array_intersect_key($event, $record);
177
+								$diff = array_diff($event, $record);
178
+								if (!empty($diff)) $record['modified'] = time();
179 179
 
180 180
 								$action = $condition['true'];
181 181
 							} else $action = $condition['false'];
182 182
 
183
-							$this->action( $action['action'], $record );
183
+							$this->action($action['action'], $record);
184 184
 							break;
185 185
 						case 'empty' :
186
-							$action = empty( $record[$condition['string']] ) ? $condition['true'] : $condition['false'];
187
-							$this->action( $action['action'], $record );
186
+							$action = empty($record[$condition['string']]) ? $condition['true'] : $condition['false'];
187
+							$this->action($action['action'], $record);
188 188
 							break;
189 189
 
190 190
 						// not supported action
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 				}
197 197
 			} else {
198 198
 				// unconditional insert
199
-				$this->action( 'insert', $record );
199
+				$this->action('insert', $record);
200 200
 			}
201 201
 		}
202 202
 	}
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 * @param array $_data event data for the action
209 209
 	 * @return bool success or not
210 210
 	 */
211
-	private function action ( $_action, $_data ) {
212
-		switch ( $_action ) {
211
+	private function action($_action, $_data) {
212
+		switch ($_action) {
213 213
 			case 'none' :
214 214
 				return true;
215 215
 
@@ -217,32 +217,32 @@  discard block
 block discarded – undo
217 217
 			case 'insert' :
218 218
 
219 219
 				// paticipants handling
220
-				$participants = $_data['participants'] ? split( '[,;]', $_data['participants'] ) : array();
220
+				$participants = $_data['participants'] ? split('[,;]', $_data['participants']) : array();
221 221
 				$_data['participants'] = array();
222
-				if ( $this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0 ) {
222
+				if ($this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0) {
223 223
 					$_data['participants'][$this->definition->plugin_options['events_owner']] = 'A';
224 224
 				}
225
-				foreach( $participants as $participant ) {
226
-					list( $participant, $status ) = explode( '=', $participant );
227
-					$valid_staties = array('U'=>'U','u'=>'U','A'=>'A','a'=>'A','R'=>'R','r'=>'R','T'=>'T','t'=>'T');
228
-					$status = isset( $valid_staties[$status] ) ? $valid_staties[$status] : 'U';
229
-					if ( $participant && is_numeric($participant ) ) {
225
+				foreach ($participants as $participant) {
226
+					list($participant, $status) = explode('=', $participant);
227
+					$valid_staties = array('U'=>'U', 'u'=>'U', 'A'=>'A', 'a'=>'A', 'R'=>'R', 'r'=>'R', 'T'=>'T', 't'=>'T');
228
+					$status = isset($valid_staties[$status]) ? $valid_staties[$status] : 'U';
229
+					if ($participant && is_numeric($participant)) {
230 230
 						$_data['participants'][$participant] = $status;
231 231
 					}
232 232
 				}
233 233
 				// no valid participants so far --> add the importing user/owner
234
-				if ( empty( $_data['participants'] ) ) {
234
+				if (empty($_data['participants'])) {
235 235
 					$_data['participants'][$this->user] = 'A';
236 236
 				}
237 237
 
238 238
 				// are we serious?
239
-				if ( $this->dry_run ) {
239
+				if ($this->dry_run) {
240 240
 					print_r($_data);
241 241
 					$this->results[$_action]++;
242 242
 				} else {
243 243
 					$messages = array();
244
-					$result = $this->bocalupdate->update( $_data, true, !$_data['modified'], $this->is_admin, true, $messages);
245
-					if(!$result) {
244
+					$result = $this->bocalupdate->update($_data, true, !$_data['modified'], $this->is_admin, true, $messages);
245
+					if (!$result) {
246 246
 						$this->errors = implode(',', $messages);
247 247
 					} else {
248 248
 						$this->results[$_action]++;
Please login to merge, or discard this patch.
Braces   +94 added lines, -38 removed lines patch added patch discarded remove patch
@@ -17,7 +17,8 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * class import_csv for addressbook
19 19
  */
20
-class import_events_csv implements iface_import_plugin  {
20
+class import_events_csv implements iface_import_plugin
21
+{
21 22
 
22 23
 	private static $plugin_options = array(
23 24
 		'fieldsep', 			// char
@@ -97,7 +98,8 @@  discard block
 block discarded – undo
97 98
 	 * @param string $_charset
98 99
 	 * @param definition $_definition
99 100
 	 */
100
-	public function import( $_stream, definition $_definition ) {
101
+	public function import( $_stream, definition $_definition )
102
+	{
101 103
 		$import_csv = new import_csv( $_stream, array(
102 104
 			'fieldsep' => $_definition->plugin_options['fieldsep'],
103 105
 			'charset' => $_definition->plugin_options['charset'],
@@ -122,7 +124,8 @@  discard block
 block discarded – undo
122 124
 		$import_csv->conversion = $_definition->plugin_options['field_conversion'];
123 125
 
124 126
 		//check if file has a header lines
125
-		if ( isset( $_definition->plugin_options['num_header_lines'] ) ) {
127
+		if ( isset( $_definition->plugin_options['num_header_lines'] ) )
128
+		{
126 129
 			$import_csv->skip_records( $_definition->plugin_options['num_header_lines'] );
127 130
 		}
128 131
 
@@ -133,12 +136,16 @@  discard block
 block discarded – undo
133 136
 		$_definition->plugin_options = $plugin_options;
134 137
 
135 138
 		// trash_users_records ?
136
-		if ( $_definition->plugin_options['trash_users_records'] === true ) {
137
-			if ( !$_definition->plugin_options['dry_run'] ) {
139
+		if ( $_definition->plugin_options['trash_users_records'] === true )
140
+		{
141
+			if ( !$_definition->plugin_options['dry_run'] )
142
+			{
138 143
 				$socal = new calendar_socal();
139 144
 				$this->bocalupdate->so->deleteaccount( $_definition->plugin_options['events_owner']);
140 145
 				unset( $socal );
141
-			} else {
146
+			}
147
+			else
148
+			{
142 149
 				$lid = $GLOBALS['egw']->accounts->id2name( $_definition->plugin_options['events_owner'] );
143 150
 				echo "Attension: All Events of '$lid' would be deleted!\n";
144 151
 			}
@@ -147,38 +154,63 @@  discard block
 block discarded – undo
147 154
 		$this->errors = array();
148 155
 		$this->results = array();
149 156
 
150
-		while ( $record = $import_csv->get_record() ) {
157
+		while ( $record = $import_csv->get_record() )
158
+		{
151 159
 
152 160
 			// don't import empty events
153
-			if( count( array_unique( $record ) ) < 2 ) continue;
161
+			if( count( array_unique( $record ) ) < 2 )
162
+			{
163
+				continue;
164
+			}
154 165
 
155
-			if ( $_definition->plugin_options['events_owner'] != -1 ) {
166
+			if ( $_definition->plugin_options['events_owner'] != -1 )
167
+			{
156 168
 				$record['owner'] = $_definition->plugin_options['events_owner'];
157
-			} else unset( $record['owner'] );
169
+			}
170
+			else {
171
+				unset( $record['owner'] );
172
+			}
158 173
 
159
-			if ( $_definition->plugin_options['conditions'] ) {
160
-				foreach ( $_definition->plugin_options['conditions'] as $condition ) {
161
-					switch ( $condition['type'] ) {
174
+			if ( $_definition->plugin_options['conditions'] )
175
+			{
176
+				foreach ( $_definition->plugin_options['conditions'] as $condition )
177
+				{
178
+					switch ( $condition['type'] )
179
+					{
162 180
 						// exists
163 181
 						case 'exists' :
164 182
 
165
-							if ( is_array( $event = $this->bocalupdate->read( $record['uid'], null, $this->is_admin ) ) ) {
183
+							if ( is_array( $event = $this->bocalupdate->read( $record['uid'], null, $this->is_admin ) ) )
184
+							{
166 185
 								// apply action to event matching this exists condition
167 186
 								$record['id'] = $event['id'];
168 187
 
169
-								if ( $_definition->plugin_options['update_cats'] == 'add' ) {
170
-									if ( !is_array( $event['cat_id'] ) ) $event['cat_id'] = explode( ',', $event['cat_id'] );
171
-									if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] );
188
+								if ( $_definition->plugin_options['update_cats'] == 'add' )
189
+								{
190
+									if ( !is_array( $event['cat_id'] ) )
191
+									{
192
+										$event['cat_id'] = explode( ',', $event['cat_id'] );
193
+									}
194
+									if ( !is_array( $record['cat_id'] ) )
195
+									{
196
+										$record['cat_id'] = explode( ',', $record['cat_id'] );
197
+									}
172 198
 									$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $event['cat_id'] ) ) );
173 199
 								}
174 200
 
175 201
 								// check if entry is modiefied
176 202
 								$event = array_intersect_key( $event, $record );
177 203
 								$diff = array_diff( $event, $record );
178
-								if( !empty( $diff ) ) $record['modified'] = time();
204
+								if( !empty( $diff ) )
205
+								{
206
+									$record['modified'] = time();
207
+								}
179 208
 
180 209
 								$action = $condition['true'];
181
-							} else $action = $condition['false'];
210
+							}
211
+							else {
212
+								$action = $condition['false'];
213
+							}
182 214
 
183 215
 							$this->action( $action['action'], $record );
184 216
 							break;
@@ -192,9 +224,14 @@  discard block
 block discarded – undo
192 224
 							throw new Exception('condition not supported!!!');
193 225
 							break;
194 226
 					}
195
-					if ($action['last']) break;
227
+					if ($action['last'])
228
+					{
229
+						break;
230
+					}
196 231
 				}
197
-			} else {
232
+			}
233
+			else
234
+			{
198 235
 				// unconditional insert
199 236
 				$this->action( 'insert', $record );
200 237
 			}
@@ -208,8 +245,10 @@  discard block
 block discarded – undo
208 245
 	 * @param array $_data event data for the action
209 246
 	 * @return bool success or not
210 247
 	 */
211
-	private function action ( $_action, $_data ) {
212
-		switch ( $_action ) {
248
+	private function action ( $_action, $_data )
249
+	{
250
+		switch ( $_action )
251
+		{
213 252
 			case 'none' :
214 253
 				return true;
215 254
 
@@ -219,32 +258,42 @@  discard block
 block discarded – undo
219 258
 				// paticipants handling
220 259
 				$participants = $_data['participants'] ? split( '[,;]', $_data['participants'] ) : array();
221 260
 				$_data['participants'] = array();
222
-				if ( $this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0 ) {
261
+				if ( $this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0 )
262
+				{
223 263
 					$_data['participants'][$this->definition->plugin_options['events_owner']] = 'A';
224 264
 				}
225
-				foreach( $participants as $participant ) {
265
+				foreach( $participants as $participant )
266
+				{
226 267
 					list( $participant, $status ) = explode( '=', $participant );
227 268
 					$valid_staties = array('U'=>'U','u'=>'U','A'=>'A','a'=>'A','R'=>'R','r'=>'R','T'=>'T','t'=>'T');
228 269
 					$status = isset( $valid_staties[$status] ) ? $valid_staties[$status] : 'U';
229
-					if ( $participant && is_numeric($participant ) ) {
270
+					if ( $participant && is_numeric($participant ) )
271
+					{
230 272
 						$_data['participants'][$participant] = $status;
231 273
 					}
232 274
 				}
233 275
 				// no valid participants so far --> add the importing user/owner
234
-				if ( empty( $_data['participants'] ) ) {
276
+				if ( empty( $_data['participants'] ) )
277
+				{
235 278
 					$_data['participants'][$this->user] = 'A';
236 279
 				}
237 280
 
238 281
 				// are we serious?
239
-				if ( $this->dry_run ) {
282
+				if ( $this->dry_run )
283
+				{
240 284
 					print_r($_data);
241 285
 					$this->results[$_action]++;
242
-				} else {
286
+				}
287
+				else
288
+				{
243 289
 					$messages = array();
244 290
 					$result = $this->bocalupdate->update( $_data, true, !$_data['modified'], $this->is_admin, true, $messages);
245
-					if(!$result) {
291
+					if(!$result)
292
+					{
246 293
 						$this->errors = implode(',', $messages);
247
-					} else {
294
+					}
295
+					else
296
+					{
248 297
 						$this->results[$_action]++;
249 298
 					}
250 299
 					return $result;
@@ -259,7 +308,8 @@  discard block
 block discarded – undo
259 308
 	 *
260 309
 	 * @return string name
261 310
 	 */
262
-	public static function get_name() {
311
+	public static function get_name()
312
+	{
263 313
 		return lang('Calendar CSV export');
264 314
 	}
265 315
 
@@ -268,7 +318,8 @@  discard block
 block discarded – undo
268 318
 	 *
269 319
 	 * @return string descriprion
270 320
 	 */
271
-	public static function get_description() {
321
+	public static function get_description()
322
+	{
272 323
 		return lang("Imports events into your Calendar from a CSV File. CSV means 'Comma Separated Values'. However in the options Tab you can also choose other seperators.");
273 324
 	}
274 325
 
@@ -277,7 +328,8 @@  discard block
 block discarded – undo
277 328
 	 *
278 329
 	 * @return string suffix (comma seperated)
279 330
 	 */
280
-	public static function get_filesuffix() {
331
+	public static function get_filesuffix()
332
+	{
281 333
 		return 'csv';
282 334
 	}
283 335
 
@@ -293,7 +345,8 @@  discard block
 block discarded – undo
293 345
 	 * 		preserv		=> array,
294 346
 	 * )
295 347
 	 */
296
-	public function get_options_etpl() {
348
+	public function get_options_etpl()
349
+	{
297 350
 		// lets do it!
298 351
 	}
299 352
 
@@ -302,7 +355,8 @@  discard block
 block discarded – undo
302 355
 	 *
303 356
 	 * @return string etemplate name
304 357
 	 */
305
-	public function get_selectors_etpl() {
358
+	public function get_selectors_etpl()
359
+	{
306 360
 		// lets do it!
307 361
 	}
308 362
 
@@ -314,7 +368,8 @@  discard block
 block discarded – undo
314 368
         *       record_# => error message
315 369
         *       )
316 370
         */
317
-        public function get_errors() {
371
+        public function get_errors()
372
+        {
318 373
 		return $this->errors;
319 374
 	}
320 375
 
@@ -326,7 +381,8 @@  discard block
 block discarded – undo
326 381
         *       action => record count
327 382
         * )
328 383
         */
329
-        public function get_results() {
384
+        public function get_results()
385
+        {
330 386
 		return $this->results;
331 387
 	}
332 388
 } // end of iface_export_plugin
Please login to merge, or discard this patch.
api/asyncservices.php 2 patches
Spacing   +10 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 use EGroupware\Api\Asyncservice;
16 16
 
17 17
 if (!isset($_REQUEST['domain'])) $_REQUEST['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'default';
18
-$path_to_egroupware = realpath(__DIR__.'/..');	//  need to be adapted if this script is moved somewhere else
18
+$path_to_egroupware = realpath(__DIR__.'/..'); //  need to be adapted if this script is moved somewhere else
19 19
 
20 20
 // remove the comment from one of the following lines to enable loging
21 21
 // define('ASYNC_LOG','C:\\async.log');		// Windows
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 if (defined('ASYNC_LOG'))
26 26
 {
27 27
 	$msg = date('Y/m/d H:i:s ').$_REQUEST['domain'].": asyncservice started\n";
28
-	$f = fopen(ASYNC_LOG,'a+');
29
-	fwrite($f,$msg);
28
+	$f = fopen(ASYNC_LOG, 'a+');
29
+	fwrite($f, $msg);
30 30
 	fclose($f);
31 31
 }
32 32
 $GLOBALS['egw_info']['flags'] = array(
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	}
44 44
 	if (defined('ASYNC_LOG'))
45 45
 	{
46
-		$f = fopen(ASYNC_LOG,'a+');
47
-		fwrite($f,$msg);
46
+		$f = fopen(ASYNC_LOG, 'a+');
47
+		fwrite($f, $msg);
48 48
 		fclose($f);
49 49
 	}
50 50
 	die($msg);
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	}
64 64
 	if (defined('ASYNC_LOG'))
65 65
 	{
66
-		$f = fopen(ASYNC_LOG,'a+');
67
-		fwrite($f,$msg);
66
+		$f = fopen(ASYNC_LOG, 'a+');
67
+		fwrite($f, $msg);
68 68
 		fclose($f);
69 69
 	}
70 70
 	die($msg);
@@ -75,8 +75,7 @@  discard block
 block discarded – undo
75 75
 $async = new Asyncservice();
76 76
 $num = $async->check_run(isset($_REQUEST['run_by']) ? $_REQUEST['run_by'] : 'crontab');
77 77
 
78
-$msg = date('Y/m/d H:i:s ').$_REQUEST['domain'].': '.($num === false ? 'An error occured: can not obtain semaphore!' :
79
-	($num ? "$num job(s) executed" : 'Nothing to execute'))."\n\n";
78
+$msg = date('Y/m/d H:i:s ').$_REQUEST['domain'].': '.($num === false ? 'An error occured: can not obtain semaphore!' : ($num ? "$num job(s) executed" : 'Nothing to execute'))."\n\n";
80 79
 
81 80
 if (isset($_SERVER['HTTP_HOST']))
82 81
 {
@@ -87,7 +86,7 @@  discard block
 block discarded – undo
87 86
 
88 87
 if (defined('ASYNC_LOG'))
89 88
 {
90
-	$f = fopen(ASYNC_LOG,'a+');
91
-	fwrite($f,$msg);
89
+	$f = fopen(ASYNC_LOG, 'a+');
90
+	fwrite($f, $msg);
92 91
 	fclose($f);
93 92
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,10 @@
 block discarded – undo
14 14
 
15 15
 use EGroupware\Api\Asyncservice;
16 16
 
17
-if (!isset($_REQUEST['domain'])) $_REQUEST['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'default';
17
+if (!isset($_REQUEST['domain']))
18
+{
19
+	$_REQUEST['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'default';
20
+}
18 21
 $path_to_egroupware = realpath(__DIR__.'/..');	//  need to be adapted if this script is moved somewhere else
19 22
 
20 23
 // remove the comment from one of the following lines to enable loging
Please login to merge, or discard this patch.
api/src/Framework/Template.php 2 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *	- function-name like set_var to get eg. all assignments or
33 33
 	 *	- handle- / variable-names - if you are only interested in some variables ;-)
34 34
 	 */
35
-	var $debug = False;	// array('cat_list','cat_list_t');
35
+	var $debug = False; // array('cat_list','cat_list_t');
36 36
 
37 37
 	/**
38 38
 	 * $file[handle] = 'filename';
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	function set_file($handle, $filename = '')
130 130
 	{
131
-		if ($this->debug && $this->check_debug('set_file',$handle,$filename))
131
+		if ($this->debug && $this->check_debug('set_file', $handle, $filename))
132 132
 		{
133
-			echo "<p>Template::set_file('".print_r($handle,true)."','$filename')</p>\n";
133
+			echo "<p>Template::set_file('".print_r($handle, true)."','$filename')</p>\n";
134 134
 		}
135 135
 		if (!is_array($handle))
136 136
 		{
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		}
144 144
 		else
145 145
 		{
146
-			foreach($handle as $h => $f)
146
+			foreach ($handle as $h => $f)
147 147
 			{
148 148
 				$this->file[$h] = $this->filename($f);
149 149
 			}
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	function set_block($parent, $handle, $name = '')
162 162
 	{
163
-		if ($this->debug && $this->check_debug('set_block',$parent,$handle,$name))
163
+		if ($this->debug && $this->check_debug('set_block', $parent, $handle, $name))
164 164
 		{
165 165
 			echo "<p>Template::set_block('$parent','$handle','$name')</p>\n";
166 166
 		}
@@ -177,14 +177,14 @@  discard block
 block discarded – undo
177 177
 		$qhandle = preg_quote($handle);
178 178
 		$reg = "/<!--\\s+BEGIN $qhandle\\s+-->(.*)\n\\s*<!--\\s+END $qhandle\\s+-->/s";
179 179
 		$match = null;
180
-		if (!preg_match($reg,$str,$match))
180
+		if (!preg_match($reg, $str, $match))
181 181
 		{
182 182
 			// unfortunaly some apps set non-existing blocks, therefor I have to disable this diagnostics again for now
183 183
 			$this->halt("set_block: unable to find block '$handle' in '$parent'=<pre>".htmlspecialchars($str)."</pre> this->root=$this->root");
184 184
 			// return False;
185 185
 		}
186
-		$this->set_var($handle,$match[1]);
187
-		$this->set_var($parent,preg_replace($reg, '{' . "$name}",$str));
186
+		$this->set_var($handle, $match[1]);
187
+		$this->set_var($parent, preg_replace($reg, '{'."$name}", $str));
188 188
 	}
189 189
 
190 190
 	/* public: set_var(array $values)
@@ -205,18 +205,18 @@  discard block
 block discarded – undo
205 205
 				$varname => $value
206 206
 			);
207 207
 		}
208
-		foreach($varname as $k => $v)
208
+		foreach ($varname as $k => $v)
209 209
 		{
210 210
 			if (!empty($k))
211 211
 			{
212
-				if ($this->debug && $this->check_debug('set_var',$k))
212
+				if ($this->debug && $this->check_debug('set_var', $k))
213 213
 				{
214 214
 					echo "<p>Template::set_var('$k','$v')</p>\n";
215 215
 				}
216 216
 				$this->varkeys[$k] = $this->varname($k);
217 217
 				$this->varvals[$k] = $this->egroupware_hack ? str_replace(
218
-					array('phpGroupWare','www.phpgroupware.org'),
219
-					array('eGroupWare','www.eGroupWare.org'),$v
218
+					array('phpGroupWare', 'www.phpgroupware.org'),
219
+					array('eGroupWare', 'www.eGroupWare.org'), $v
220 220
 				) : $v;
221 221
 			}
222 222
 		}
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 */
231 231
 	function subst($handle)
232 232
 	{
233
-		if ($this->debug && $this->check_debug('subst',$handle))
233
+		if ($this->debug && $this->check_debug('subst', $handle))
234 234
 		{
235 235
 			echo "<p>Template::subst('$handle')</p>\n";
236 236
 		}
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		}
242 242
 
243 243
 		$str = $this->get_var($handle);
244
-		foreach($this->varkeys as $k => $v)
244
+		foreach ($this->varkeys as $k => $v)
245 245
 		{
246 246
 			$str = str_replace($v, $this->varvals[$k], $str);
247 247
 		}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 			$str = $this->subst($handle);
277 277
 			if ($append)
278 278
 			{
279
-				$this->set_var($target, $this->get_var($target) . $str);
279
+				$this->set_var($target, $this->get_var($target).$str);
280 280
 			}
281 281
 			else
282 282
 			{
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		}
286 286
 		else
287 287
 		{
288
-			foreach($handle as $h)
288
+			foreach ($handle as $h)
289 289
 			{
290 290
 				$str = $this->subst($h);
291 291
 				$this->set_var($target, $str);
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 */
333 333
 	function get_vars()
334 334
 	{
335
-		foreach(array_keys($this->varkeys) as $k)
335
+		foreach (array_keys($this->varkeys) as $k)
336 336
 		{
337 337
 			$result[$k] = $this->varvals[$k];
338 338
 		}
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		}
354 354
 		else
355 355
 		{
356
-			foreach(array_keys($varname) as $k)
356
+			foreach (array_keys($varname) as $k)
357 357
 			{
358 358
 				$result[$k] = $this->varvals[$k];
359 359
 			}
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 		{
383 383
 			return false;
384 384
 		}
385
-		foreach($m as $v)
385
+		foreach ($m as $v)
386 386
 		{
387 387
 			if (!isset($this->varkeys[$v]))
388 388
 			{
@@ -448,15 +448,15 @@  discard block
 block discarded – undo
448 448
 	 * @param string $root ='' default $this->root
449 449
 	 * @param int $time =1
450 450
 	 */
451
-	protected function filename($filename,$root='',$time=1)
451
+	protected function filename($filename, $root = '', $time = 1)
452 452
 	{
453
-		if($root == '')
453
+		if ($root == '')
454 454
 		{
455 455
 			$root = $this->root;
456 456
 		}
457
-		if(substr($filename, 0, 1) != '/')
457
+		if (substr($filename, 0, 1) != '/')
458 458
 		{
459
-			$new_filename = $root . '/' . $filename;
459
+			$new_filename = $root.'/'.$filename;
460 460
 		}
461 461
 		else
462 462
 		{
@@ -465,14 +465,14 @@  discard block
 block discarded – undo
465 465
 
466 466
 		if (!file_exists($new_filename))
467 467
 		{
468
-			if($time==2)
468
+			if ($time == 2)
469 469
 			{
470 470
 				$this->halt("filename: file $new_filename does not exist.");
471 471
 			}
472 472
 			else
473 473
 			{
474
-				$new_root = dirname($root) . DIRECTORY_SEPARATOR . 'default';
475
-				$new_filename = $this->filename(str_replace($root.'/','',$new_filename),$new_root,2);
474
+				$new_root = dirname($root).DIRECTORY_SEPARATOR.'default';
475
+				$new_filename = $this->filename(str_replace($root.'/', '', $new_filename), $new_root, 2);
476 476
 			}
477 477
 		}
478 478
 		return $new_filename;
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 	 */
492 492
 	function loadfile($handle)
493 493
 	{
494
-		if ($this->debug && $this->check_debug('loadfile',$handle))
494
+		if ($this->debug && $this->check_debug('loadfile', $handle))
495 495
 		{
496
-			echo "<p>Template::loadfile('$handle') file=<pre>\n".print_r($this->file,True)."</pre>\n";
496
+			echo "<p>Template::loadfile('$handle') file=<pre>\n".print_r($this->file, True)."</pre>\n";
497 497
 			echo "<p>backtrace: ".function_backtrace()."</p>\n";
498 498
 		}
499 499
 		if (isset($this->varkeys[$handle]) && !empty($this->varvals[$handle]))
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 		}
503 503
 		if (!isset($this->file[$handle]))
504 504
 		{
505
-			if ($this->debug && $this->check_debug('loadfile',$handle))
505
+			if ($this->debug && $this->check_debug('loadfile', $handle))
506 506
 			{
507
-				echo "varkeys =<pre>".print_r($this->varkeys,True)."</pre>varvals =<pre>".print_r($this->varvals,True)."</pre>\n";
507
+				echo "varkeys =<pre>".print_r($this->varkeys, True)."</pre>varvals =<pre>".print_r($this->varvals, True)."</pre>\n";
508 508
 			}
509 509
 			$this->halt("loadfile: $handle is not a valid handle.");
510 510
 			return false;
@@ -549,10 +549,10 @@  discard block
 block discarded – undo
549 549
 	{
550 550
 		if (!$this->debug) return False;
551 551
 
552
-		foreach(func_get_args() as $arg)
552
+		foreach (func_get_args() as $arg)
553 553
 		{
554 554
 			if (!is_array($this->debug) && $this->debug === $arg ||
555
-				(is_array($this->debug) && (@$this->debug[$arg] || in_array($arg,$this->debug,True))))
555
+				(is_array($this->debug) && (@$this->debug[$arg] || in_array($arg, $this->debug, True))))
556 556
 			{
557 557
 				return True;
558 558
 			}
@@ -601,8 +601,8 @@  discard block
 block discarded – undo
601 601
 		{
602 602
 			$GLOBALS['egw_info']['server']['template_set'] = 'idots';
603 603
 		}
604
-		$tpldir         = EGW_SERVER_ROOT . '/' . $appname . '/templates/' . $GLOBALS['egw_info']['server']['template_set'];
605
-		$tpldir_default = EGW_SERVER_ROOT . '/' . $appname . '/templates/default';
604
+		$tpldir         = EGW_SERVER_ROOT.'/'.$appname.'/templates/'.$GLOBALS['egw_info']['server']['template_set'];
605
+		$tpldir_default = EGW_SERVER_ROOT.'/'.$appname.'/templates/default';
606 606
 
607 607
 		if (@is_dir($tpldir))
608 608
 		{
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -547,7 +547,10 @@
 block discarded – undo
547 547
 
548 548
 	function check_debug()
549 549
 	{
550
-		if (!$this->debug) return False;
550
+		if (!$this->debug)
551
+		{
552
+			return False;
553
+		}
551 554
 
552 555
 		foreach(func_get_args() as $arg)
553 556
 		{
Please login to merge, or discard this patch.
api/src/Framework/Extra.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -54,12 +54,12 @@  discard block
 block discarded – undo
54 54
 	 * @param string $with =null
55 55
 	 * @param string $msg_type =null 'error', 'warning' or 'success' (default)
56 56
 	 */
57
-	public static function refresh_opener($msg, $app, $id=null, $type=null, $targetapp=null, $replace=null, $with=null, $msg_type=null)
57
+	public static function refresh_opener($msg, $app, $id = null, $type = null, $targetapp = null, $replace = null, $with = null, $msg_type = null)
58 58
 	{
59 59
 		//error_log(__METHOD__.'('.array2string(func_get_args()).')');
60 60
 		self::$extra['refresh-opener'] = func_get_args();
61 61
 
62
-		unset($msg, $app, $id, $type, $targetapp, $replace, $with, $msg_type);	// used only via func_get_args();
62
+		unset($msg, $app, $id, $type, $targetapp, $replace, $with, $msg_type); // used only via func_get_args();
63 63
 	}
64 64
 
65 65
 	/**
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 	 * @param string $msg message to show
71 71
 	 * @param string $type ='success' 'error', 'warning' or 'success' (default)
72 72
 	 */
73
-	public static function message($msg, $type='success')
73
+	public static function message($msg, $type = 'success')
74 74
 	{
75 75
 		self::$extra['message'] = func_get_args();
76 76
 
77
-		unset($msg, $type);	// used only via func_get_args();
77
+		unset($msg, $type); // used only via func_get_args();
78 78
 	}
79 79
 
80 80
 	/**
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
 	 * @param string $target
85 85
 	 * @param string $popup
86 86
 	 */
87
-	public static function popup($link, $target='_blank', $popup='640x480')
87
+	public static function popup($link, $target = '_blank', $popup = '640x480')
88 88
 	{
89 89
 		// default params are not returned by func_get_args!
90
-		$args = func_get_args()+array(null, '_blank', '640x480');
90
+		$args = func_get_args() + array(null, '_blank', '640x480');
91 91
 
92
-		unset($link, $target, $popup);	// used only via func_get_args()
92
+		unset($link, $target, $popup); // used only via func_get_args()
93 93
 
94 94
 		if (Json\Request::isJSONRequest())
95 95
 		{
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 *
107 107
 	 * @param string $alert_msg ='' optional message to display as alert, before closing the window
108 108
 	 */
109
-	public static function window_close($alert_msg='')
109
+	public static function window_close($alert_msg = '')
110 110
 	{
111 111
 		//error_log(__METHOD__."()");
112 112
 		self::$extra['window-close'] = $alert_msg ? $alert_msg : true;
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
 	public static function get_extra()
164 164
 	{
165 165
 		// adding links of refreshed entry, to give others apps more information about necessity to refresh
166
-		if (isset(self::$extra['refresh-opener']) && count(self::$extra['refresh-opener']) <= 8 &&	// do not run twice
166
+		if (isset(self::$extra['refresh-opener']) && count(self::$extra['refresh-opener']) <= 8 && // do not run twice
167 167
 			!empty(self::$extra['refresh-opener'][1]) && !empty(self::$extra['refresh-opener'][2]))	// app/id given
168 168
 		{
169 169
 			$links = Link::get_links(self::$extra['refresh-opener'][1], self::$extra['refresh-opener'][2]);
170 170
 			$apps = array();
171
-			foreach($links as $link)
171
+			foreach ($links as $link)
172 172
 			{
173 173
 				$apps[$link['app']][] = $link['id'];
174 174
 			}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -164,9 +164,12 @@
 block discarded – undo
164 164
 	{
165 165
 		// adding links of refreshed entry, to give others apps more information about necessity to refresh
166 166
 		if (isset(self::$extra['refresh-opener']) && count(self::$extra['refresh-opener']) <= 8 &&	// do not run twice
167
-			!empty(self::$extra['refresh-opener'][1]) && !empty(self::$extra['refresh-opener'][2]))	// app/id given
167
+			!empty(self::$extra['refresh-opener'][1]) && !empty(self::$extra['refresh-opener'][2]))
168
+		{
169
+			// app/id given
168 170
 		{
169 171
 			$links = Link::get_links(self::$extra['refresh-opener'][1], self::$extra['refresh-opener'][2]);
172
+		}
170 173
 			$apps = array();
171 174
 			foreach($links as $link)
172 175
 			{
Please login to merge, or discard this patch.
api/src/Framework/Ajax.php 3 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -337,16 +337,16 @@  discard block
 block discarded – undo
337 337
 	}
338 338
 
339 339
 	/**
340
-	* called by hooks to add an icon in the topmenu info location
341
-	*
342
-	* @param string $id unique element id
343
-	* @param string $icon_src src of the icon image. Make sure this nog height then 18pixels
344
-	* @param string $iconlink where the icon links to
345
-	* @param booleon $blink set true to make the icon blink
346
-	* @param mixed $tooltip string containing the tooltip Api\Html, or null of no tooltip
347
-	* @todo implement in a reasonable way for jdots
348
-	* @return void
349
-	*/
340
+	 * called by hooks to add an icon in the topmenu info location
341
+	 *
342
+	 * @param string $id unique element id
343
+	 * @param string $icon_src src of the icon image. Make sure this nog height then 18pixels
344
+	 * @param string $iconlink where the icon links to
345
+	 * @param booleon $blink set true to make the icon blink
346
+	 * @param mixed $tooltip string containing the tooltip Api\Html, or null of no tooltip
347
+	 * @todo implement in a reasonable way for jdots
348
+	 * @return void
349
+	 */
350 350
 	function topmenu_info_icon($id,$icon_src,$iconlink,$blink=false,$tooltip=null)
351 351
 	{
352 352
 		unset($id,$icon_src,$iconlink,$blink,$tooltip);	// not used
@@ -354,14 +354,14 @@  discard block
 block discarded – undo
354 354
 	}
355 355
 
356 356
 	/**
357
-	* Add menu items to the topmenu template class to be displayed
358
-	*
359
-	* @param array $app application data
360
-	* @param mixed $alt_label string with alternative menu item label default value = null
361
-	* @param string $urlextra string with alternate additional code inside <a>-tag
362
-	* @access protected
363
-	* @return void
364
-	*/
357
+	 * Add menu items to the topmenu template class to be displayed
358
+	 *
359
+	 * @param array $app application data
360
+	 * @param mixed $alt_label string with alternative menu item label default value = null
361
+	 * @param string $urlextra string with alternate additional code inside <a>-tag
362
+	 * @access protected
363
+	 * @return void
364
+	 */
365 365
 	function _add_topmenu_item(array $app_data,$alt_label=null)
366 366
 	{
367 367
 		switch($app_data['name'])
Please login to merge, or discard this patch.
Braces   +52 added lines, -13 removed lines patch added patch discarded remove patch
@@ -104,7 +104,9 @@  discard block
 block discarded – undo
104 104
 
105 105
 		//Width may not be smaller than MIN_SIDEBAR_WIDTH
106 106
 		if ($width < self::MIN_SIDEBAR_WIDTH)
107
-			$width = self::MIN_SIDEBAR_WIDTH;
107
+		{
108
+					$width = self::MIN_SIDEBAR_WIDTH;
109
+		}
108 110
 
109 111
 		return $width;
110 112
 	}
@@ -156,7 +158,10 @@  discard block
 block discarded – undo
156 158
 	 */
157 159
 	static function link($url = '', $extravars = '', $link_app=null)
158 160
 	{
159
-		if (is_null($link_app)) $link_app = self::$link_app;
161
+		if (is_null($link_app))
162
+		{
163
+			$link_app = self::$link_app;
164
+		}
160 165
 		$link = parent::link($url, $extravars);
161 166
 
162 167
 		// $link_app === true --> detect application, otherwise use given application
@@ -182,7 +187,10 @@  discard block
 block discarded – undo
182 187
 	function header(array $extra=array())
183 188
 	{
184 189
 		// make sure header is output only once
185
-		if (self::$header_done) return '';
190
+		if (self::$header_done)
191
+		{
192
+			return '';
193
+		}
186 194
 		self::$header_done = true;
187 195
 
188 196
 		$this->send_headers();
@@ -249,7 +257,10 @@  discard block
 block discarded – undo
249 257
 			// for remote manual never check/create framework
250 258
 			if (!in_array($GLOBALS['egw_info']['flags']['currentapp'], array('manual', 'login', 'logout', 'sitemgr')))
251 259
 			{
252
-				if (empty($GLOBALS['egw_info']['flags']['java_script'])) $GLOBALS['egw_info']['flags']['java_script']='';
260
+				if (empty($GLOBALS['egw_info']['flags']['java_script']))
261
+				{
262
+					$GLOBALS['egw_info']['flags']['java_script']='';
263
+				}
253 264
 				$extra['check-framework'] = $_GET['cd'] !== 'no';
254 265
 			}
255 266
 		}
@@ -522,7 +533,10 @@  discard block
 block discarded – undo
522 533
 	 */
523 534
 	public function sidebox($appname,$menu_title,$file,$type=null)
524 535
 	{
525
-		if (!isset($file['menuOpened'])) $file['menuOpened'] = (boolean)$this->sidebox_menu_opened;
536
+		if (!isset($file['menuOpened']))
537
+		{
538
+			$file['menuOpened'] = (boolean)$this->sidebox_menu_opened;
539
+		}
526 540
 		//error_log(__METHOD__."('$appname', '$menu_title', file[menuOpened]=$file[menuOpened], ...) this->sidebox_menu_opened=$this->sidebox_menu_opened");
527 541
 		$this->sidebox_menu_opened = false;
528 542
 
@@ -663,7 +677,10 @@  discard block
 block discarded – undo
663 677
 		foreach($tablist as $data)
664 678
 		{
665 679
 			$tabs[] = $data['appName'];
666
-			if ($data['active']) $active = $data['appName'];
680
+			if ($data['active'])
681
+			{
682
+				$active = $data['appName'];
683
+			}
667 684
 		}
668 685
 		// send app a notification, that it's tab got closed
669 686
 		// used eg. in phpFreeChat to leave the chat
@@ -790,10 +807,22 @@  discard block
 block discarded – undo
790 807
 		}
791 808
 
792 809
 		unset($apps['logout']);	// never display it
793
-		if (isset($apps['about'])) $apps['about']['noNavbar'] = true;
794
-		if (isset($apps['preferences'])) $apps['preferences']['noNavbar'] = true;
795
-		if (isset($apps['manual'])) $apps['manual']['noNavbar'] = true;
796
-		if (isset($apps['home'])) $apps['home']['noNavbar'] = true;
810
+		if (isset($apps['about']))
811
+		{
812
+			$apps['about']['noNavbar'] = true;
813
+		}
814
+		if (isset($apps['preferences']))
815
+		{
816
+			$apps['preferences']['noNavbar'] = true;
817
+		}
818
+		if (isset($apps['manual']))
819
+		{
820
+			$apps['manual']['noNavbar'] = true;
821
+		}
822
+		if (isset($apps['home']))
823
+		{
824
+			$apps['home']['noNavbar'] = true;
825
+		}
797 826
 
798 827
 		// no need for website icon, if we have sitemgr
799 828
 		if (isset($apps['sitemgr']) && isset($apps['sitemgr-link']))
@@ -855,7 +884,10 @@  discard block
 block discarded – undo
855 884
 		else
856 885
 		{
857 886
 			$active_tab = $GLOBALS['egw_info']['user']['preferences']['common']['active_tab'];
858
-			if (!$active_tab) $active_tab = $default_app;
887
+			if (!$active_tab)
888
+			{
889
+				$active_tab = $default_app;
890
+			}
859 891
 		}
860 892
 
861 893
 		//self::app_from_url might return an application the user has no rights
@@ -898,9 +930,12 @@  discard block
 block discarded – undo
898 930
 		// Restore Tabs
899 931
 		foreach($open_tabs as $n => $app)
900 932
 		{
901
-			if (isset($apps[$app]))		// user might no longer have app rights
933
+			if (isset($apps[$app]))
934
+			{
935
+				// user might no longer have app rights
902 936
 			{
903 937
 				$apps[$app]['opened'] = $n;
938
+			}
904 939
 				if ($app == $active_tab)
905 940
 				{
906 941
 					$apps[$app]['active'] = true;
@@ -926,7 +961,11 @@  discard block
 block discarded – undo
926 961
 	function footer($no_framework=true)
927 962
 	{
928 963
 		//error_log(__METHOD__."($no_framework) footer_done=".array2string(self::$footer_done).' '.function_backtrace());
929
-		if (self::$footer_done) return;	// prevent (multiple) footers
964
+		if (self::$footer_done)
965
+		{
966
+			return;
967
+		}
968
+		// prevent (multiple) footers
930 969
 		self::$footer_done = true;
931 970
 
932 971
 		if (!isset($GLOBALS['egw_info']['flags']['nofooter']) || !$GLOBALS['egw_info']['flags']['nofooter'])
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @param string $template = '' name of the template
57 57
 	 */
58
-	function __construct($template=self::APP)
58
+	function __construct($template = self::APP)
59 59
 	{
60
-		parent::__construct($template);		// call the constructor of the extended class
60
+		parent::__construct($template); // call the constructor of the extended class
61 61
 
62
-		$this->template_dir = '/'.$template;		// we are packaged as an application
62
+		$this->template_dir = '/'.$template; // we are packaged as an application
63 63
 	}
64 64
 
65 65
 	/**
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 	public static function app_from_url($url)
128 128
 	{
129 129
 		$matches = null;
130
-		if (preg_match('/menuaction=([a-z0-9_-]+)\./i',$url,$matches))
130
+		if (preg_match('/menuaction=([a-z0-9_-]+)\./i', $url, $matches))
131 131
 		{
132 132
 			return $matches[1];
133 133
 		}
134 134
 		if ($GLOBALS['egw_info']['server']['webserver_url'] &&
135
-			($webserver_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH)))
135
+			($webserver_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH)))
136 136
 		{
137
-			list(,$url) = explode($webserver_path, parse_url($url,PHP_URL_PATH),2);
137
+			list(,$url) = explode($webserver_path, parse_url($url, PHP_URL_PATH), 2);
138 138
 		}
139
-		if (preg_match('/\/([^\/]+)\/([^\/]+\.php)?(\?|\/|$)/',$url,$matches))
139
+		if (preg_match('/\/([^\/]+)\/([^\/]+\.php)?(\?|\/|$)/', $url, $matches))
140 140
 		{
141 141
 			return $matches[1];
142 142
 		}
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 * @param string $link_app = null if appname or true, some templates generate a special link-handler url
153 153
 	 * @return string	The full url after processing
154 154
 	 */
155
-	static function link($url = '', $extravars = '', $link_app=null)
155
+	static function link($url = '', $extravars = '', $link_app = null)
156 156
 	{
157 157
 		if (is_null($link_app)) $link_app = self::$link_app;
158 158
 		$link = parent::link($url, $extravars);
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 			// Link gets handled in JS, so quotes need slashes as well as url-encoded
164 164
 			// encoded ampersands in get parameters (%26) need to be encoded twise,
165 165
 			// so they are still encoded when assigned to window.location
166
-			$link_with_slashes = str_replace(array('%27','%26'), array('\%27','%2526'), $link);
166
+			$link_with_slashes = str_replace(array('%27', '%26'), array('\%27', '%2526'), $link);
167 167
 
168 168
 			//$link = "javascript:window.egw_link_handler?egw_link_handler('$link','$link_app'):parent.egw_link_handler('$link','$link_app');";
169 169
 			$link = "javascript:egw_link_handler('$link_with_slashes','$link_app')";
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 * @param array $extra = array() extra attributes passed as data-attribute to egw.js
178 178
 	 * @return string with Api\Html
179 179
 	 */
180
-	function header(array $extra=array())
180
+	function header(array $extra = array())
181 181
 	{
182 182
 		// make sure header is output only once
183 183
 		if (self::$header_done) return '';
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 		{
203 203
 			$this->tpl->set_file(array('_head' => 'head.tpl'));
204 204
 		}
205
-		$this->tpl->set_block('_head','head');
206
-		$this->tpl->set_block('_head','framework');
205
+		$this->tpl->set_block('_head', 'head');
206
+		$this->tpl->set_block('_head', 'framework');
207 207
 
208 208
 		// should we draw the framework, or just a header
209 209
 		$do_framework = isset($_GET['cd']) && $_GET['cd'] === 'yes';
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 			{
229 229
 				self::includeJS('.', 'fw_'.static::APP, static::JS_INCLUDE_APP);
230 230
 			}
231
-			Api\Cache::unsetSession(__CLASS__,'sidebox_md5');	// sideboxes need to be send again
231
+			Api\Cache::unsetSession(__CLASS__, 'sidebox_md5'); // sideboxes need to be send again
232 232
 
233 233
 			$extra['navbar-apps'] = $this->get_navbar_apps($_SERVER['REQUEST_URI']);
234 234
 		}
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		// - if not we need to check if we have an opener (are a popup window)
238 238
 		// - as popups can open further popups, we need to decend all the way down until we find a framework
239 239
 		// - only if we cant find a framework in all openers, we redirect to create a new framework
240
-		if(!$do_framework)
240
+		if (!$do_framework)
241 241
 		{
242 242
 			// fetch sidebox from application and set it in extra data, if we are no popup
243 243
 			if (!$GLOBALS['egw_info']['flags']['nonavbar'])
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 			// for remote manual never check/create framework
248 248
 			if (!in_array($GLOBALS['egw_info']['flags']['currentapp'], array('manual', 'login', 'logout', 'sitemgr')))
249 249
 			{
250
-				if (empty($GLOBALS['egw_info']['flags']['java_script'])) $GLOBALS['egw_info']['flags']['java_script']='';
250
+				if (empty($GLOBALS['egw_info']['flags']['java_script'])) $GLOBALS['egw_info']['flags']['java_script'] = '';
251 251
 				$extra['check-framework'] = $_GET['cd'] !== 'no';
252 252
 			}
253 253
 		}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		), [], true);
260 260
 
261 261
 		$this->tpl->set_var($this->_get_header($extra));
262
-		$content = $this->tpl->fp('out','head').$content;
262
+		$content = $this->tpl->fp('out', 'head').$content;
263 263
 
264 264
 		if (!$do_framework)
265 265
 		{
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 
269 269
 		// topmenu
270 270
 		$vars = $this->_get_navbar($apps = $this->_get_navbar_apps());
271
-		$this->tpl->set_var($this->topmenu($vars,$apps));
271
+		$this->tpl->set_var($this->topmenu($vars, $apps));
272 272
 
273 273
 		// hook after_navbar (eg. notifications)
274
-		$this->tpl->set_var('hook_after_navbar',$this->_get_after_navbar());
274
+		$this->tpl->set_var('hook_after_navbar', $this->_get_after_navbar());
275 275
 
276 276
 		//Global sidebar width
277 277
 		$this->tpl->set_var('sidebox_width', self::get_global_sidebar_width());
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 
280 280
 		// add framework div's
281 281
 		$this->tpl->set_var($this->_get_footer());
282
-		$content .= $this->tpl->fp('out','framework');
282
+		$content .= $this->tpl->fp('out', 'framework');
283 283
 		$content .= self::footer(false);
284 284
 
285 285
 		echo $content;
@@ -298,14 +298,14 @@  discard block
 block discarded – undo
298 298
 	 * @param array $apps
299 299
 	 * @return array
300 300
 	 */
301
-	function topmenu(array $vars,array $apps)
301
+	function topmenu(array $vars, array $apps)
302 302
 	{
303 303
 		$this->topmenu_items = $this->topmenu_info_items = array();
304 304
 
305
-		parent::topmenu($vars,$apps);
306
-		$vars['topmenu_items'] = "<ul>\n<li>".implode("</li>\n<li>",$this->topmenu_items)."</li>\n</ul>";
305
+		parent::topmenu($vars, $apps);
306
+		$vars['topmenu_items'] = "<ul>\n<li>".implode("</li>\n<li>", $this->topmenu_items)."</li>\n</ul>";
307 307
 		$vars['topmenu_info_items'] = '';
308
-		foreach($this->topmenu_info_items as $id => $item)
308
+		foreach ($this->topmenu_info_items as $id => $item)
309 309
 		{
310 310
 			$vars['topmenu_info_items'] .= '<div class="topmenu_info_item"'.
311 311
 				(is_numeric($id) ? '' : ' id="topmenu_info_'.$id.'"').'>'.$item."</div>\n";
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
 	* @todo implement in a reasonable way for jdots
327 327
 	* @return void
328 328
 	*/
329
-	function topmenu_info_icon($id,$icon_src,$iconlink,$blink=false,$tooltip=null)
329
+	function topmenu_info_icon($id, $icon_src, $iconlink, $blink = false, $tooltip = null)
330 330
 	{
331
-		unset($id,$icon_src,$iconlink,$blink,$tooltip);	// not used
331
+		unset($id, $icon_src, $iconlink, $blink, $tooltip); // not used
332 332
 		// not yet implemented, only used in admin/inc/hook_topmenu_info.inc.php to notify about pending updates
333 333
 	}
334 334
 
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
 	* @access protected
342 342
 	* @return void
343 343
 	*/
344
-	function _add_topmenu_item(array $app_data,$alt_label=null)
344
+	function _add_topmenu_item(array $app_data, $alt_label = null)
345 345
 	{
346
-		switch($app_data['name'])
346
+		switch ($app_data['name'])
347 347
 		{
348 348
 			case 'manual':
349 349
 				$app_data['url'] = "javascript:callManual();";
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 				{
355 355
 					break;
356 356
 				}
357
-				if (strpos($app_data['url'],'logout.php') === false && substr($app_data['url'], 0, 11) != 'javascript:')
357
+				if (strpos($app_data['url'], 'logout.php') === false && substr($app_data['url'], 0, 11) != 'javascript:')
358 358
 				{
359 359
 					$app_data['url'] = "javascript:egw_link_handler('".$app_data['url']."','".
360 360
 						(isset($GLOBALS['egw_info']['user']['apps'][$app_data['name']]) ?
@@ -362,8 +362,8 @@  discard block
 block discarded – undo
362 362
 				}
363 363
 		}
364 364
 		$id = $app_data['id'] ? $app_data['id'] : ($app_data['name'] ? $app_data['name'] : $app_data['title']);
365
-		$title =  htmlspecialchars($alt_label ? $alt_label : $app_data['title']);
366
-		$this->topmenu_items[] = '<a id="topmenu_' . $id . '" href="'.htmlspecialchars($app_data['url']).'" title="'.$app_data['title'].'">'.$title.'</a>';
365
+		$title = htmlspecialchars($alt_label ? $alt_label : $app_data['title']);
366
+		$this->topmenu_items[] = '<a id="topmenu_'.$id.'" href="'.htmlspecialchars($app_data['url']).'" title="'.$app_data['title'].'">'.$title.'</a>';
367 367
 	}
368 368
 
369 369
 	/**
@@ -374,11 +374,11 @@  discard block
 block discarded – undo
374 374
 	 * @access protected
375 375
 	 * @return void
376 376
 	 */
377
-	function _add_topmenu_info_item($content, $id=null)
377
+	function _add_topmenu_info_item($content, $id = null)
378 378
 	{
379
-		if(strpos($content,'menuaction=admin.admin_accesslog.sessions') !== false)
379
+		if (strpos($content, 'menuaction=admin.admin_accesslog.sessions') !== false)
380 380
 		{
381
-			$content = preg_replace('/href="([^"]+)"/',"href=\"javascript:egw_link_handler('\\1','admin')\"",$content);
381
+			$content = preg_replace('/href="([^"]+)"/', "href=\"javascript:egw_link_handler('\\1','admin')\"", $content);
382 382
 		}
383 383
 		if ($id)
384 384
 		{
@@ -397,10 +397,10 @@  discard block
 block discarded – undo
397 397
 	 */
398 398
 	static function ajax_tz_selection($tz)
399 399
 	{
400
-		Api\DateTime::setUserPrefs($tz);	// throws exception, if tz is invalid
400
+		Api\DateTime::setUserPrefs($tz); // throws exception, if tz is invalid
401 401
 
402 402
 		$GLOBALS['egw']->preferences->read_repository();
403
-		$GLOBALS['egw']->preferences->add('common','tz',$tz);
403
+		$GLOBALS['egw']->preferences->add('common', 'tz', $tz);
404 404
 		$GLOBALS['egw']->preferences->save_repository();
405 405
 	}
406 406
 
@@ -452,13 +452,13 @@  discard block
 block discarded – undo
452 452
 		// only send admin sidebox, for admin index url (when clicked on admin),
453 453
 		// not for other admin pages, called eg. from sidebox menu of other apps
454 454
 		// --> that way we always stay in the app, and NOT open admin sidebox for an app tab!!!
455
-		if ($app == 'admin' && substr($_SERVER['PHP_SELF'],-16) != '/admin/index.php' &&
455
+		if ($app == 'admin' && substr($_SERVER['PHP_SELF'], -16) != '/admin/index.php' &&
456 456
 			$_GET['menuaction'] != 'admin.admin_ui.index')
457 457
 		{
458 458
 			//error_log(__METHOD__."() app=$app, menuaction=$_GET[menuaction], PHP_SELF=$_SERVER[PHP_SELF] --> sidebox request ignored");
459 459
 			return;
460 460
 		}
461
-		$md5_session =& Api\Cache::getSession(__CLASS__,'sidebox_md5');
461
+		$md5_session = & Api\Cache::getSession(__CLASS__, 'sidebox_md5');
462 462
 
463 463
 		//Set the sidebox content
464 464
 		$sidebox = $this->get_sidebox($app);
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 		if ($md5_session[$app] !== $md5)
468 468
 		{
469 469
 			//error_log(__METHOD__."() header changed md5_session[$app]!=='$md5' --> setting it on self::\$extra[setSidebox]");
470
-			$md5_session[$app] = $md5;	// update md5 in session
470
+			$md5_session[$app] = $md5; // update md5 in session
471 471
 			self::$extra['setSidebox'] = array($app, $sidebox, $md5);
472 472
 		}
473 473
 		//else error_log(__METHOD__."() md5_session[$app]==='$md5' --> nothing to do");
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
 	 * @return boolean $consider_navbar_not_yet_called_as_true=true ignored by jdots, we only care for cd=yes GET param
482 482
 	 * @return boolean
483 483
 	 */
484
-	public function isTop($consider_navbar_not_yet_called_as_true=true)
484
+	public function isTop($consider_navbar_not_yet_called_as_true = true)
485 485
 	{
486
-		unset($consider_navbar_not_yet_called_as_true);	// not used
486
+		unset($consider_navbar_not_yet_called_as_true); // not used
487 487
 		return isset($_GET['cd']) && $_GET['cd'] === 'yes';
488 488
 	}
489 489
 
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 	 * @param array $file
510 510
 	 * @param string $type = null 'admin', 'preferences', 'favorites', ...
511 511
 	 */
512
-	public function sidebox($appname,$menu_title,$file,$type=null)
512
+	public function sidebox($appname, $menu_title, $file, $type = null)
513 513
 	{
514 514
 		if (!isset($file['menuOpened'])) $file['menuOpened'] = (boolean)$this->sidebox_menu_opened;
515 515
 		//error_log(__METHOD__."('$appname', '$menu_title', file[menuOpened]=$file[menuOpened], ...) this->sidebox_menu_opened=$this->sidebox_menu_opened");
@@ -518,12 +518,12 @@  discard block
 block discarded – undo
518 518
 		// fix app admin menus to use admin.admin_ui.index loader
519 519
 		if (($type == 'admin' || $menu_title == lang('Admin')) && $appname != 'admin')
520 520
 		{
521
-			foreach($file as &$link)
521
+			foreach ($file as &$link)
522 522
 			{
523 523
 				$ajax = null;
524 524
 				preg_match('/ajax=(true|false)/', $link, $ajax);
525 525
 				$link = preg_replace("/^(javascript:egw_link_handler\(')(.*)menuaction=([^&]+)(.*)(','[^']+'\))$/",
526
-					'$1$2menuaction=admin.admin_ui.index&load=$3$4&ajax=' . ($ajax[1] ? $ajax[1] : 'true') .'\',\'admin\')', $link);
526
+					'$1$2menuaction=admin.admin_ui.index&load=$3$4&ajax='.($ajax[1] ? $ajax[1] : 'true').'\',\'admin\')', $link);
527 527
 			}
528 528
 		}
529 529
 
@@ -559,15 +559,15 @@  discard block
 block discarded – undo
559 559
 			self::$link_app = $appname;
560 560
 			// allow other apps to hook into sidebox menu of an app, hook-name: sidebox_$appname
561 561
 			$this->sidebox_menu_opened = true;
562
-			Api\Hooks::process('sidebox_'.$appname,array($appname),true);	// true = call independent of app-permissions
562
+			Api\Hooks::process('sidebox_'.$appname, array($appname), true); // true = call independent of app-permissions
563 563
 
564 564
 			// calling the old hook
565 565
 			$this->sidebox_menu_opened = true;
566
-			Api\Hooks::single('sidebox_menu',$appname);
566
+			Api\Hooks::single('sidebox_menu', $appname);
567 567
 			self::$link_app = null;
568 568
 
569 569
 			// allow other apps to hook into sidebox menu of every app: sidebox_all
570
-			Api\Hooks::process('sidebox_all',array($GLOBALS['egw_info']['flags']['currentapp']),true);
570
+			Api\Hooks::process('sidebox_all', array($GLOBALS['egw_info']['flags']['currentapp']), true);
571 571
 		}
572 572
 		//If there still is no sidebox content, return null here
573 573
 		if (!isset($this->sideboxes[$appname]))
@@ -577,17 +577,17 @@  discard block
 block discarded – undo
577 577
 
578 578
 		$data = array();
579 579
 		$sendToBottom = array();
580
-		foreach($this->sideboxes[$appname] as $menu_name => &$file)
580
+		foreach ($this->sideboxes[$appname] as $menu_name => &$file)
581 581
 		{
582 582
 			$current_menu = array(
583
-				'menu_name' => md5($menu_name),	// can contain Api\Html tags and javascript!
583
+				'menu_name' => md5($menu_name), // can contain Api\Html tags and javascript!
584 584
 				'title' => $menu_name,
585 585
 				'entries' => array(),
586 586
 				'opened' => (boolean)$file['menuOpened'],
587 587
 			);
588
-			foreach($file as $item_text => $item_link)
588
+			foreach ($file as $item_text => $item_link)
589 589
 			{
590
-				if ($item_text === 'menuOpened' || $item_text === 'sendToBottom' ||// flag, not menu entry
590
+				if ($item_text === 'menuOpened' || $item_text === 'sendToBottom' || // flag, not menu entry
591 591
 					$item_text === '_NewLine_' || $item_link === '_NewLine_')
592 592
 				{
593 593
 					continue;
@@ -598,14 +598,14 @@  discard block
 block discarded – undo
598 598
 				}
599 599
 
600 600
 				$var = array();
601
-				$var['icon_or_star'] = $GLOBALS['egw_info']['server']['webserver_url'] . $this->template_dir.'/images/bullet.png';
601
+				$var['icon_or_star'] = $GLOBALS['egw_info']['server']['webserver_url'].$this->template_dir.'/images/bullet.png';
602 602
 				$var['target'] = '';
603
-				if(is_array($item_link))
603
+				if (is_array($item_link))
604 604
 				{
605
-					if(isset($item_link['icon']))
605
+					if (isset($item_link['icon']))
606 606
 					{
607 607
 						$app = isset($item_link['app']) ? $item_link['app'] : $appname;
608
-						$var['icon_or_star'] = $item_link['icon'] ? Api\Image::find($app,$item_link['icon']) : False;
608
+						$var['icon_or_star'] = $item_link['icon'] ? Api\Image::find($app, $item_link['icon']) : False;
609 609
 					}
610 610
 					$var['lang_item'] = isset($item_link['no_lang']) && $item_link['no_lang'] ? $item_link['text'] : lang($item_link['text']);
611 611
 					$var['item_link'] = $item_link['link'];
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 	public static function ajax_tab_changed_state($tablist)
654 654
 	{
655 655
 		$tabs = array();
656
-		foreach($tablist as $data)
656
+		foreach ($tablist as $data)
657 657
 		{
658 658
 			$tabs[] = $data['appName'];
659 659
 			if ($data['active']) $active = $data['appName'];
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
 		// used eg. in phpFreeChat to leave the chat
663 663
 		if (($old_tabs = Api\Cache::getSession(__CLASS__, 'open_tabs')))
664 664
 		{
665
-			foreach(array_diff(explode(',',$old_tabs),$tabs) as $app)
665
+			foreach (array_diff(explode(',', $old_tabs), $tabs) as $app)
666 666
 			{
667 667
 				//error_log("Tab '$app' closed, old_tabs=$old_tabs");
668 668
 				Api\Hooks::single(array(
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
 				), $app);
672 672
 			}
673 673
 		}
674
-		$open = implode(',',$tabs);
674
+		$open = implode(',', $tabs);
675 675
 
676 676
 		if ($open != $GLOBALS['egw_info']['user']['preferences']['common']['open_tabs'] ||
677 677
 			$active != $GLOBALS['egw_info']['user']['preferences']['common']['active_tab'])
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 		$i = 0;
742 742
 
743 743
 		//Parse the "$apps" array for valid content (security)
744
-		foreach($apps as $app)
744
+		foreach ($apps as $app)
745 745
 		{
746 746
 			//Check whether the app really exists and add it to the $app_arr var
747 747
 			if ($GLOBALS['egw_info']['user']['apps'][$app])
@@ -779,10 +779,10 @@  discard block
 block discarded – undo
779 779
 		{
780 780
 			$data['sideboxwidth'] = self::get_sidebar_width($app);
781 781
 			// overwrite icon with svg, if supported by browser
782
-			unset($data['icon_hover']);	// not used in jdots
782
+			unset($data['icon_hover']); // not used in jdots
783 783
 		}
784 784
 
785
-		unset($apps['logout']);	// never display it
785
+		unset($apps['logout']); // never display it
786 786
 		if (isset($apps['about'])) $apps['about']['noNavbar'] = true;
787 787
 		if (isset($apps['preferences'])) $apps['preferences']['noNavbar'] = true;
788 788
 		if (isset($apps['manual'])) $apps['manual']['noNavbar'] = true;
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 		}
833 833
 
834 834
 		// check if user called a specific url --> open it as active tab
835
-		$last_direct_url =& Api\Cache::getSession(__CLASS__, 'last_direct_url');
835
+		$last_direct_url = & Api\Cache::getSession(__CLASS__, 'last_direct_url');
836 836
 		if ($last_direct_url)
837 837
 		{
838 838
 			$url = $last_direct_url;
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 		{
843 843
 			// Coming in with a specific URL, save it and redirect to index.php
844 844
 			// so reloads work nicely, but strip cd=yes or we'll get the framework again
845
-			$last_direct_url = preg_replace('/[&?]cd=yes/','',$url);
845
+			$last_direct_url = preg_replace('/[&?]cd=yes/', '', $url);
846 846
 			Api\Framework::redirect_link('/index.php?cd=yes');
847 847
 		}
848 848
 		else
@@ -857,11 +857,11 @@  discard block
 block discarded – undo
857 857
 		if ($active_tab && array_key_exists($active_tab, $apps))
858 858
 		{
859 859
 			// Do not remove cd=yes if it's an ajax=true app
860
-			if (strpos( $apps[$active_tab]['url'],'ajax=true') !== False)
860
+			if (strpos($apps[$active_tab]['url'], 'ajax=true') !== False)
861 861
 			{
862
-				$url = preg_replace('/[&?]cd=yes/','',$url);
862
+				$url = preg_replace('/[&?]cd=yes/', '', $url);
863 863
 			}
864
-			if($last_direct_url)
864
+			if ($last_direct_url)
865 865
 			{
866 866
 				$apps[$active_tab]['openOnce'] = $url;
867 867
 			}
@@ -873,8 +873,8 @@  discard block
 block discarded – undo
873 873
 		{
874 874
 			$open_tabs = $GLOBALS['egw_info']['user']['preferences']['common']['open_tabs'];
875 875
 		}
876
-		$open_tabs = $open_tabs ? explode(',',$open_tabs) : array();
877
-		if ($active_tab && !in_array($active_tab,$open_tabs))
876
+		$open_tabs = $open_tabs ? explode(',', $open_tabs) : array();
877
+		if ($active_tab && !in_array($active_tab, $open_tabs))
878 878
 		{
879 879
 			$open_tabs[] = $active_tab;
880 880
 			$store_prefs = true;
@@ -882,14 +882,14 @@  discard block
 block discarded – undo
882 882
 		if ($store_prefs)
883 883
 		{
884 884
 			$GLOBALS['egw']->preferences->read_repository();
885
-			$GLOBALS['egw']->preferences->add('common', 'open_tabs', implode(',',$open_tabs));
885
+			$GLOBALS['egw']->preferences->add('common', 'open_tabs', implode(',', $open_tabs));
886 886
 			$GLOBALS['egw']->preferences->add('common', 'active_tab', $active_tab);
887 887
 			$GLOBALS['egw']->preferences->save_repository(true);
888 888
 		}
889 889
 
890 890
 		//error_log(__METHOD__."('$url') url_tab='$url_tab', active_tab=$active_tab, open_tabs=".array2string($open_tabs));
891 891
 		// Restore Tabs
892
-		foreach($open_tabs as $n => $app)
892
+		foreach ($open_tabs as $n => $app)
893 893
 		{
894 894
 			if (isset($apps[$app]))		// user might no longer have app rights
895 895
 			{
@@ -916,10 +916,10 @@  discard block
 block discarded – undo
916 916
 	 * @param boolean $no_framework = true
917 917
 	 * @return string
918 918
 	 */
919
-	function footer($no_framework=true)
919
+	function footer($no_framework = true)
920 920
 	{
921 921
 		//error_log(__METHOD__."($no_framework) footer_done=".array2string(self::$footer_done).' '.function_backtrace());
922
-		if (self::$footer_done) return;	// prevent (multiple) footers
922
+		if (self::$footer_done) return; // prevent (multiple) footers
923 923
 		self::$footer_done = true;
924 924
 
925 925
 		if (!isset($GLOBALS['egw_info']['flags']['nofooter']) || !$GLOBALS['egw_info']['flags']['nofooter'])
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
 			}
932 932
 		}
933 933
 		return $footer.
934
-			$GLOBALS['egw_info']['flags']['need_footer']."\n".	// eg. javascript, which need to be at the end of the page
934
+			$GLOBALS['egw_info']['flags']['need_footer']."\n".// eg. javascript, which need to be at the end of the page
935 935
 			"</body>\n</html>\n";
936 936
 	}
937 937
 
@@ -969,8 +969,8 @@  discard block
 block discarded – undo
969 969
 		if ($parts['query'])
970 970
 		{
971 971
 			$_SERVER['REQUEST_URI'] = '?'.$parts['query'];
972
-			parse_str($parts['query'],$_GET);
973
-			$_REQUEST = $_GET;	// some apps use $_REQUEST to check $_GET or $_POST
972
+			parse_str($parts['query'], $_GET);
973
+			$_REQUEST = $_GET; // some apps use $_REQUEST to check $_GET or $_POST
974 974
 		}
975 975
 
976 976
 		if (!isset($_GET['menuaction']))
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
 		// set session action
981 981
 		$GLOBALS['egw']->session->set_action('Ajax: '.$_GET['menuaction']);
982 982
 
983
-		list($app,$class,$method) = explode('.',$_GET['menuaction']);
983
+		list($app, $class, $method) = explode('.', $_GET['menuaction']);
984 984
 
985 985
 		if (!isset($GLOBALS['egw_info']['user']['apps'][$app]))
986 986
 		{
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 
993 993
 		$GLOBALS[$class] = $obj = CreateObject($app.'.'.$class);
994 994
 
995
-		if(!is_array($obj->public_functions) || !$obj->public_functions[$method])
995
+		if (!is_array($obj->public_functions) || !$obj->public_functions[$method])
996 996
 		{
997 997
 			throw new Api\Exception\NoPermission("Bad menuaction {$_GET['menuaction']}, not listed in public_functions!");
998 998
 		}
Please login to merge, or discard this patch.