Completed
Push — 16.1 ( b39e15...d98aac )
by Klaus
18:52
created
calendar/inc/class.calendar_merge.inc.php 3 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -326,20 +326,20 @@  discard block
 block discarded – undo
326 326
 	}
327 327
 
328 328
 	/**
329
-	* Table plugin for event
330
-	* Lists events for a certain day of the week.  Only works for one week at a time, so for multiple weeks,
331
-	* use multiple date ranges.
332
-	*
333
-	* Use:
334
-	* $$table/Monday$$ $$starttime$$ $$title$$ $$endtable$$
335
-	* The day of the week may be language specific (date('l')).
336
-	*
337
-	* @param string $plugin (Monday-Sunday)
338
-	* @param int/array date or date range
339
-	* @param int $n Row number
340
-	* @param string $repeat Text being repeated for each entry
341
-	* @return array
342
-	*/
329
+	 * Table plugin for event
330
+	 * Lists events for a certain day of the week.  Only works for one week at a time, so for multiple weeks,
331
+	 * use multiple date ranges.
332
+	 *
333
+	 * Use:
334
+	 * $$table/Monday$$ $$starttime$$ $$title$$ $$endtable$$
335
+	 * The day of the week may be language specific (date('l')).
336
+	 *
337
+	 * @param string $plugin (Monday-Sunday)
338
+	 * @param int/array date or date range
339
+	 * @param int $n Row number
340
+	 * @param string $repeat Text being repeated for each entry
341
+	 * @return array
342
+	 */
343 343
 	public function day_plugin($plugin,$date,$n,$repeat)
344 344
 	{
345 345
 		static $days = null;
@@ -414,16 +414,16 @@  discard block
 block discarded – undo
414 414
 	}
415 415
 
416 416
 	/**
417
-	* Table plugin for a certain date
418
-	*
419
-	* Can be either a particular date (2011-02-15) or a day of the month (15)
420
-	*
421
-	* @param string $plugin
422
-	* @param int $id ID for this record
423
-	* @param int $n Repeated row number
424
-	* @param string $repeat Text being repeated for each entry
425
-	* @return array
426
-	*/
417
+	 * Table plugin for a certain date
418
+	 *
419
+	 * Can be either a particular date (2011-02-15) or a day of the month (15)
420
+	 *
421
+	 * @param string $plugin
422
+	 * @param int $id ID for this record
423
+	 * @param int $n Repeated row number
424
+	 * @param string $repeat Text being repeated for each entry
425
+	 * @return array
426
+	 */
427 427
 	public function day($plugin,$id,$n,$repeat)
428 428
 	{
429 429
 		static $days = null;
@@ -515,15 +515,15 @@  discard block
 block discarded – undo
515 515
 	}
516 516
 
517 517
 	/**
518
-	* Table plugin for participants
519
-	*
520
-	* Copied from eventmgr resources
521
-	*
522
-	* @param string $plugin
523
-	* @param int $id
524
-	* @param int $n
525
-	* @return array
526
-	*/
518
+	 * Table plugin for participants
519
+	 *
520
+	 * Copied from eventmgr resources
521
+	 *
522
+	 * @param string $plugin
523
+	 * @param int $id
524
+	 * @param int $n
525
+	 * @return array
526
+	 */
527 527
 	public function participant($plugin,$id,$n)
528 528
 	{
529 529
 		unset($plugin);	// not used, but required by function signature
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 				{
583 583
 					foreach($resource as $name => $value)
584 584
 					{
585
-					    $replacements['$$'.$name.'$$'] = $value;
585
+						$replacements['$$'.$name.'$$'] = $value;
586 586
 					}
587 587
 				}
588 588
 				break;
Please login to merge, or discard this patch.
Spacing   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -84,14 +84,14 @@  discard block
 block discarded – undo
84 84
 
85 85
 		// Register table plugins
86 86
 		$this->table_plugins['participant'] = 'participant';
87
-		for($i = 0; $i < 7; $i++)
87
+		for ($i = 0; $i < 7; $i++)
88 88
 		{
89 89
 			$this->table_plugins[date('l', strtotime("+$i days"))] = 'day_plugin';
90 90
 		}
91
-		for($i = 1; $i <= 31; $i++) {
91
+		for ($i = 1; $i <= 31; $i++) {
92 92
 			$this->table_plugins['day_'.$i] = 'day'; // Numerically by day number (1-31)
93 93
 		}
94
-		foreach(self::$relative as $day) {
94
+		foreach (self::$relative as $day) {
95 95
 			$this->table_plugins[$day] = 'day'; // Current day
96 96
 		}
97 97
 		$this->query = is_array($this->bo->cal_prefs['saved_states']) ?
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 	 * @param string $charset=null charset to override default set by mimetype or export charset
118 118
 	 * @return string|boolean merged document or false on error
119 119
 	 */
120
-	function merge_string($content,$ids,$err,$mimetype,$fix)
120
+	function merge_string($content, $ids, $err, $mimetype, $fix)
121 121
 	{
122 122
 		//error_log(__METHOD__ . ' IDs: ' . array2string($ids));
123 123
 		// Handle merging a list of events into a document with range instead of pagerepeat
124
-		if((strpos($content, '$$range') !== false || strpos($content, '{{range') !== false) && is_array($ids))
124
+		if ((strpos($content, '$$range') !== false || strpos($content, '{{range') !== false) && is_array($ids))
125 125
 		{
126 126
 			//error_log(__METHOD__ . ' Got list of events(?), no pagerepeat tag');
127 127
 			// Merging more than one something will fail without pagerepeat
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 				$events = $ids;
132 132
 				$ids = array('start' => PHP_INT_MAX, 'end' => 0);
133 133
 				$this->ids = array();
134
-				foreach($events as $event) {
135
-					if($event['start'] && Api\DateTime::to($event['start'],'ts') < $ids['start']) $ids['start'] = Api\DateTime::to($event['start'],'ts');
136
-					if($event['end'] && Api\DateTime::to($event['end'],'ts') > $ids['end']) $ids['end'] = Api\DateTime::to($event['end'],'ts');
134
+				foreach ($events as $event) {
135
+					if ($event['start'] && Api\DateTime::to($event['start'], 'ts') < $ids['start']) $ids['start'] = Api\DateTime::to($event['start'], 'ts');
136
+					if ($event['end'] && Api\DateTime::to($event['end'], 'ts') > $ids['end']) $ids['end'] = Api\DateTime::to($event['end'], 'ts');
137 137
 					// Keep ids for future use
138 138
 					$this->ids[] = $event['id'];
139 139
 				}
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 				'cfs' => strpos($content, '#') !== false ? array_keys(Api\Storage\Customfields::get('calendar')) : null
155 155
 			));
156 156
 			$ids = array();
157
-			foreach($events as $event) {
157
+			foreach ($events as $event) {
158 158
 				$ids[] = $event;
159 159
 			}
160 160
 		}
161 161
 
162
-		return parent::merge_string($content, $ids, $err, $mimetype,$fix);
162
+		return parent::merge_string($content, $ids, $err, $mimetype, $fix);
163 163
 	}
164 164
 
165 165
 	/**
@@ -169,20 +169,20 @@  discard block
 block discarded – undo
169 169
 	 * @param string &$content=null content to create some replacements only if they are used
170 170
 	 * @return array|boolean
171 171
 	 */
172
-	protected function get_replacements($id,&$content=null)
172
+	protected function get_replacements($id, &$content = null)
173 173
 	{
174 174
 		$prefix = '';
175 175
 		// List events ?
176
-		if(is_array($id) && !$id['id'] && !$id[0]['id'])
176
+		if (is_array($id) && !$id['id'] && !$id[0]['id'])
177 177
 		{
178 178
 			$events = $this->bo->search($this->query + $id + array(
179 179
 				'offset' => 0,
180 180
 				'order' => 'cal_start',
181 181
 				'cfs' => strpos($content, '#') !== false ? array_keys(Api\Storage\Customfields::get('calendar')) : null
182 182
 			));
183
-			if(strpos($content,'$$calendar/') !== false || strpos($content, '$$table/day') !== false)
183
+			if (strpos($content, '$$calendar/') !== false || strpos($content, '$$table/day') !== false)
184 184
 			{
185
-				array_unshift($events,false); unset($events[0]);	// renumber the array to start with key 1, instead of 0
185
+				array_unshift($events, false); unset($events[0]); // renumber the array to start with key 1, instead of 0
186 186
 				$prefix = 'calendar/%d';
187 187
 			}
188 188
 		}
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 			$events = $id;
193 193
 			$id = array('start' => PHP_INT_MAX, 'end' => 0);
194 194
 			$this->ids = array();
195
-			foreach($events as $event) {
196
-				if($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
197
-				if($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
195
+			foreach ($events as $event) {
196
+				if ($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
197
+				if ($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
198 198
 				// Keep ids for future use
199
-				$this->ids[]  = $event['id'];
199
+				$this->ids[] = $event['id'];
200 200
 			}
201 201
 			$id = array($id);
202 202
 		}
@@ -208,20 +208,20 @@  discard block
 block discarded – undo
208 208
 		// as this function allows to pass query- parameters, we need to check the result of the query against export_limit restrictions
209 209
 		if (Api\Storage\Merge::hasExportLimit($this->export_limit) && !Api\Storage\Merge::is_export_limit_excepted() && count($events) > (int)$this->export_limit)
210 210
 		{
211
-			$err = lang('No rights to export more than %1 entries!',(int)$this->export_limit);
211
+			$err = lang('No rights to export more than %1 entries!', (int)$this->export_limit);
212 212
 			throw new Api\Exception\WrongUserinput($err);
213 213
 		}
214 214
 		$replacements = array();
215 215
 		$n = 0;
216
-		foreach($events as $event)
216
+		foreach ($events as $event)
217 217
 		{
218
-			$values = $this->calendar_replacements($event,sprintf($prefix,++$n), $content);
219
-			if(is_array($id) && $id['start'])
218
+			$values = $this->calendar_replacements($event, sprintf($prefix, ++$n), $content);
219
+			if (is_array($id) && $id['start'])
220 220
 			{
221
-				foreach(self::$range_tags as $key => $format)
221
+				foreach (self::$range_tags as $key => $format)
222 222
 				{
223 223
 					$value = date($format, $key == 'end' ? $id['end'] : $id['start']);
224
-					if($key == 'month') $value = lang($value);
224
+					if ($key == 'month') $value = lang($value);
225 225
 					$values["$\$range/$key$$"] = $value;
226 226
 				}
227 227
 			}
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 	 * @param boolean $last_event_too=false also include information about the last event
238 238
 	 * @return array
239 239
 	 */
240
-	public function calendar_replacements($id,$prefix = '', &$content = '')
240
+	public function calendar_replacements($id, $prefix = '', &$content = '')
241 241
 	{
242 242
 		$replacements = array();
243
-		if(!is_array($id) || !$id['start']) {
243
+		if (!is_array($id) || !$id['start']) {
244 244
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
245 245
 		} else {
246 246
 			$event = $id;
@@ -253,68 +253,68 @@  discard block
 block discarded – undo
253 253
 		importexport_export_csv::convert($record, $types, 'calendar');
254 254
 
255 255
 		$array = $record->get_record_array();
256
-		foreach($array as $key => $value)
256
+		foreach ($array as $key => $value)
257 257
 		{
258
-			$replacements['$$'.($prefix?$prefix.'/':'').$key.'$$'] = $value;
258
+			$replacements['$$'.($prefix ? $prefix.'/' : '').$key.'$$'] = $value;
259 259
 		}
260 260
 
261
-		$replacements['$$' . ($prefix ? $prefix . '/' : '') . 'calendar_id'. '$$'] = $event['id'];
262
-		foreach($this->bo->event2array($event) as $name => $data)
261
+		$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_id'.'$$'] = $event['id'];
262
+		foreach ($this->bo->event2array($event) as $name => $data)
263 263
 		{
264
-			if (substr($name,-4) == 'date') $name = substr($name,0,-4);
265
-			$replacements['$$' . ($prefix ? $prefix . '/' : '') . 'calendar_'.$name . '$$'] = is_array($data['data']) ? implode(', ',$data['data']) : $data['data'];
264
+			if (substr($name, -4) == 'date') $name = substr($name, 0, -4);
265
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_'.$name.'$$'] = is_array($data['data']) ? implode(', ', $data['data']) : $data['data'];
266 266
 		}
267 267
 		// Add seperate lists of participants by type
268
-		if(strpos($content, 'calendar_participants/')!== false)
268
+		if (strpos($content, 'calendar_participants/') !== false)
269 269
 		{
270 270
 			$types = array();
271
-			foreach($this->bo->resources as $resource)
271
+			foreach ($this->bo->resources as $resource)
272 272
 			{
273 273
 				$types[$resource['app']] = array();
274 274
 			}
275
-			foreach($event['participants'] as $uid => $status)
275
+			foreach ($event['participants'] as $uid => $status)
276 276
 			{
277 277
 				$type = $this->bo->resources[$uid[0]]['app'];
278
-				if($type == 'api-accounts')
278
+				if ($type == 'api-accounts')
279 279
 				{
280 280
 					$type = ($GLOBALS['egw']->accounts->get_type($uid) == 'g' ? 'group' : 'account');
281 281
 				}
282 282
 				$types[$type][] = $this->bo->participant_name($uid);
283 283
 			}
284
-			foreach($types as $t_id => $type)
284
+			foreach ($types as $t_id => $type)
285 285
 			{
286
-				$replacements['$$'.($prefix ? $prefix . '/' : '') . "calendar_participants/{$t_id}$$"] = implode(', ',$type);
286
+				$replacements['$$'.($prefix ? $prefix.'/' : '')."calendar_participants/{$t_id}$$"] = implode(', ', $type);
287 287
 			}
288 288
 		}
289
-		if(!$replacements['$$'.($prefix ? $prefix . '/' : '') . 'calendar_recur_type$$'])
289
+		if (!$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_recur_type$$'])
290 290
 		{
291 291
 			// Need to set it to '' if not set or previous record may be used
292
-			$replacements['$$'.($prefix ? $prefix . '/' : '') . 'calendar_recur_type$$'] = '';
292
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_recur_type$$'] = '';
293 293
 		}
294
-		foreach(array('start','end') as $what)
294
+		foreach (array('start', 'end') as $what)
295 295
 		{
296
-			foreach(array(
296
+			foreach (array(
297 297
 				'date' => $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],
298 298
 				'day'  => 'l',
299
-				'time' => (date('Ymd',$event['start']) != date('Ymd',$event['end']) ? $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' ' : '') . ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'),
299
+				'time' => (date('Ymd', $event['start']) != date('Ymd', $event['end']) ? $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' ' : '').($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'),
300 300
 			) as $name => $format)
301 301
 			{
302
-				$value = Api\DateTime::to($event[$what],$format);
302
+				$value = Api\DateTime::to($event[$what], $format);
303 303
 				if ($format == 'l') $value = lang($value);
304
-				$replacements['$$' .($prefix ? $prefix.'/':'').'calendar_'.$what.$name.'$$'] = $value;
304
+				$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_'.$what.$name.'$$'] = $value;
305 305
 			}
306 306
 		}
307
-		$duration = ($event['end'] - $event['start'])/60;
308
-		$replacements['$$'.($prefix?$prefix.'/':'').'calendar_duration$$'] = floor($duration/60).lang('h').($duration%60 ? $duration%60 : '');
307
+		$duration = ($event['end'] - $event['start']) / 60;
308
+		$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_duration$$'] = floor($duration / 60).lang('h').($duration % 60 ? $duration % 60 : '');
309 309
 
310 310
 		// Add in contact stuff for owner
311
-		if (strpos($content,'$$calendar_owner/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($event['owner'],'person_id')))
311
+		if (strpos($content, '$$calendar_owner/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($event['owner'], 'person_id')))
312 312
 		{
313
-			$replacements += $this->contact_replacements($user,($prefix ? $prefix.'/':'').'calendar_owner');
314
-			$replacements['$$'.($prefix?$prefix.'/':'').'calendar_owner/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($event['owner'],'account_primary_group'));
313
+			$replacements += $this->contact_replacements($user, ($prefix ? $prefix.'/' : '').'calendar_owner');
314
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'calendar_owner/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($event['owner'], 'account_primary_group'));
315 315
 		}
316 316
 
317
-		if($content && strpos($content, '$$#') !== FALSE)
317
+		if ($content && strpos($content, '$$#') !== FALSE)
318 318
 		{
319 319
 			$this->cf_link_to_expand($event, $content, $replacements);
320 320
 		}
@@ -340,77 +340,77 @@  discard block
 block discarded – undo
340 340
 	* @param string $repeat Text being repeated for each entry
341 341
 	* @return array
342 342
 	*/
343
-	public function day_plugin($plugin,$date,$n,$repeat)
343
+	public function day_plugin($plugin, $date, $n, $repeat)
344 344
 	{
345 345
 		static $days = null;
346
-		if(is_array($date) && !$date['start']) {
346
+		if (is_array($date) && !$date['start']) {
347 347
 			// List of IDs
348
-			if($date[0]['start']) {
348
+			if ($date[0]['start']) {
349 349
 				$id = array('start' => PHP_INT_MAX, 'end' => 0);
350
-				foreach($date as $event) {
351
-					if($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
352
-					if($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
350
+				foreach ($date as $event) {
351
+					if ($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
352
+					if ($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
353 353
 				}
354 354
 				$date = $id;
355 355
 			} else {
356 356
 				$event = $this->bo->read(is_array($date) ? $date['id'] : $date, is_array($date) ? $date['recur_date'] : null);
357
-				if(date('l',$event['start']) != $plugin) return array();
357
+				if (date('l', $event['start']) != $plugin) return array();
358 358
 				$date = $event['start'];
359 359
 			}
360 360
 		}
361 361
 
362 362
 		$_date = $date['start'] ? $date['start'] : $date;
363
-		if($days[date('Ymd',$_date)][$plugin]) return $days[date('Ymd',$_date)][$plugin][$n];
363
+		if ($days[date('Ymd', $_date)][$plugin]) return $days[date('Ymd', $_date)][$plugin][$n];
364 364
 
365 365
 		$events = $this->bo->search($this->query + array(
366
-			'start' => $date['end'] ? $date['start'] : mktime(0,0,0,date('m',$_date),date('d',$_date),date('Y',$_date)),
367
-			'end' => $date['end'] ? $date['end'] : mktime(23,59,59,date('m',$_date),date('d',$_date),date('Y',$_date)),
366
+			'start' => $date['end'] ? $date['start'] : mktime(0, 0, 0, date('m', $_date), date('d', $_date), date('Y', $_date)),
367
+			'end' => $date['end'] ? $date['end'] : mktime(23, 59, 59, date('m', $_date), date('d', $_date), date('Y', $_date)),
368 368
 			'offset' => 0,
369 369
 			'num_rows' => 20,
370 370
 			'order' => 'cal_start',
371 371
 			'daywise' => true,
372
-			'cfs' => array(),	// read all custom-fields
372
+			'cfs' => array(), // read all custom-fields
373 373
 		));
374 374
 
375 375
 		if (true) $days = array();
376 376
 		$replacements = array();
377 377
 		$time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i';
378
-		foreach($events as $day => $list)
378
+		foreach ($events as $day => $list)
379 379
 		{
380
-			foreach($list as $event)
380
+			foreach ($list as $event)
381 381
 			{
382
-				if($this->ids && !in_array($event['id'], $this->ids)) continue;
382
+				if ($this->ids && !in_array($event['id'], $this->ids)) continue;
383 383
 				$start = Api\DateTime::to($event['start'], 'array');
384 384
 				$end = Api\DateTime::to($event['end'], 'array');
385 385
 				$replacements = $this->calendar_replacements($event);
386
-				if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
387
-					$dow = date('l',$event['start']);
386
+				if ($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
387
+					$dow = date('l', $event['start']);
388 388
 				} else {
389 389
 					$dow = date('l', strtotime($day));
390 390
 					// Fancy date+time formatting for multi-day events
391
-					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0,0,0,0,0,1));
392
-					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23,59,59,0,0,0));
391
+					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0, 0, 0, 0, 0, 1));
392
+					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23, 59, 59, 0, 0, 0));
393 393
 				}
394 394
 
395
-				$days[date('Ymd',$_date)][$dow][] = $replacements;
395
+				$days[date('Ymd', $_date)][$dow][] = $replacements;
396 396
 			}
397
-			if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
397
+			if (strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
398 398
 				$date_marker = array(
399 399
 					'$$day/date$$' => date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], strtotime($day)),
400 400
 					'$$day/name$$' => lang(date('l', strtotime($day)))
401 401
 				);
402
-				if(!is_array($days[date('Ymd',$_date)][date('l',strtotime($day))])) {
402
+				if (!is_array($days[date('Ymd', $_date)][date('l', strtotime($day))])) {
403 403
 					$blank = $this->calendar_replacements(array());
404
-					foreach($blank as &$value)
404
+					foreach ($blank as &$value)
405 405
 					{
406 406
 						$value = '';
407 407
 					}
408
-					$days[date('Ymd',$_date)][date('l',strtotime($day))][] = $blank;
408
+					$days[date('Ymd', $_date)][date('l', strtotime($day))][] = $blank;
409 409
 				}
410
-				$days[date('Ymd',$_date)][date('l',strtotime($day))][0] += $date_marker;
410
+				$days[date('Ymd', $_date)][date('l', strtotime($day))][0] += $date_marker;
411 411
 			}
412 412
 		}
413
-		return $days[date('Ymd',$_date)][$plugin][0];
413
+		return $days[date('Ymd', $_date)][$plugin][0];
414 414
 	}
415 415
 
416 416
 	/**
@@ -424,27 +424,27 @@  discard block
 block discarded – undo
424 424
 	* @param string $repeat Text being repeated for each entry
425 425
 	* @return array
426 426
 	*/
427
-	public function day($plugin,$id,$n,$repeat)
427
+	public function day($plugin, $id, $n, $repeat)
428 428
 	{
429 429
 		static $days = null;
430 430
 
431 431
 		// Figure out which day
432
-		list($type, $which) = explode('_',$plugin);
433
-		if($type == 'day' && $which)
432
+		list($type, $which) = explode('_', $plugin);
433
+		if ($type == 'day' && $which)
434 434
 		{
435
-			if($id[0]['start'])
435
+			if ($id[0]['start'])
436 436
 			{
437 437
 				$dates = array('start' => PHP_INT_MAX, 'end' => 0);
438
-				foreach($id as $event) {
439
-					if($event['start'] && $event['start'] < $dates['start']) $dates['start'] = $event['start'];
440
-					if($event['end'] && $event['end'] > $dates['end']) $dates['end'] = $event['end'];
438
+				foreach ($id as $event) {
439
+					if ($event['start'] && $event['start'] < $dates['start']) $dates['start'] = $event['start'];
440
+					if ($event['end'] && $event['end'] > $dates['end']) $dates['end'] = $event['end'];
441 441
 				}
442 442
 				$id = $dates;
443 443
 			}
444 444
 			$arr = $this->bo->date2array($id['start']);
445 445
 			$arr['day'] = $which;
446 446
 			$date = $this->bo->date2ts($arr);
447
-			if(is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end'])) return array();
447
+			if (is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end'])) return array();
448 448
 		}
449 449
 		elseif ($plugin == 'selected')
450 450
 		{
@@ -454,64 +454,64 @@  discard block
 block discarded – undo
454 454
 		{
455 455
 			$date = strtotime($plugin);
456 456
 		}
457
-		if($type == 'day' && is_array($id) && !$id['start']) {
457
+		if ($type == 'day' && is_array($id) && !$id['start']) {
458 458
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
459
-			if($which && date('d',$event['start']) != $which) return array();
460
-			if(date('Ymd',$date) != date('Ymd', $event['start'])) return array();
459
+			if ($which && date('d', $event['start']) != $which) return array();
460
+			if (date('Ymd', $date) != date('Ymd', $event['start'])) return array();
461 461
 			return $n == 0 ? $this->calendar_replacements($event) : array();
462 462
 		}
463 463
 
464 464
 		// Use start for cache, in case of multiple months
465 465
 		$_date = $id['start'] ? $id['start'] : $date;
466
-		if($days[date('Ymd',$_date)][$plugin]) return $days[date('Ymd',$_date)][$plugin][$n];
466
+		if ($days[date('Ymd', $_date)][$plugin]) return $days[date('Ymd', $_date)][$plugin][$n];
467 467
 
468 468
 		$events = $this->bo->search($this->query + array(
469 469
 			'start' => $date,
470
-			'end' => mktime(23,59,59,date('m',$date),date('d',$date),date('Y',$date)),
470
+			'end' => mktime(23, 59, 59, date('m', $date), date('d', $date), date('Y', $date)),
471 471
 			'offset' => 0,
472 472
 			'num_rows' => 20,
473 473
 			'order' => 'cal_start',
474 474
 			'daywise' => true,
475
-			'cfs' => array(),	// read all custom-fields
475
+			'cfs' => array(), // read all custom-fields
476 476
 		));
477 477
 
478 478
 		$replacements = array();
479 479
 		if (true) $days = array();
480 480
 		$time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i';
481
-		foreach($events as $day => $list)
481
+		foreach ($events as $day => $list)
482 482
 		{
483
-			foreach($list as $event)
483
+			foreach ($list as $event)
484 484
 			{
485
-				if($this->ids && !in_array($event['id'], $this->ids)) continue;
485
+				if ($this->ids && !in_array($event['id'], $this->ids)) continue;
486 486
 				$start = Api\DateTime::to($event['start'], 'array');
487 487
 				$end = Api\DateTime::to($event['end'], 'array');
488 488
 				$replacements = $this->calendar_replacements($event);
489
-				if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
489
+				if ($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
490 490
 					//$dow = date('l',$event['start']);
491 491
 				} else {
492 492
 					// Fancy date+time formatting for multi-day events
493
-					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0,0,0,0,0,1));
494
-					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23,59,59,0,0,0));
493
+					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0, 0, 0, 0, 0, 1));
494
+					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23, 59, 59, 0, 0, 0));
495 495
 				}
496
-				$days[date('Ymd',$_date)][$plugin][] = $replacements;
496
+				$days[date('Ymd', $_date)][$plugin][] = $replacements;
497 497
 			}
498
-			if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
498
+			if (strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
499 499
 				$date_marker = array(
500 500
 					'$$day/date$$' => date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], strtotime($day)),
501 501
 					'$$day/name$$' => lang(date('l', strtotime($day)))
502 502
 				);
503
-				if(!is_array($days[date('Ymd',$_date)][$plugin])) {
503
+				if (!is_array($days[date('Ymd', $_date)][$plugin])) {
504 504
 					$blank = $this->calendar_replacements(array());
505
-					foreach($blank as &$value)
505
+					foreach ($blank as &$value)
506 506
 					{
507 507
 						$value = '';
508 508
 					}
509
-					$days[date('Ymd',$_date)][$plugin][] = $blank;
509
+					$days[date('Ymd', $_date)][$plugin][] = $blank;
510 510
 				}
511
-				$days[date('Ymd',$_date)][$plugin][0] += $date_marker;
511
+				$days[date('Ymd', $_date)][$plugin][0] += $date_marker;
512 512
 			}
513 513
 		}
514
-		return $days[date('Ymd',$_date)][$plugin][0];
514
+		return $days[date('Ymd', $_date)][$plugin][0];
515 515
 	}
516 516
 
517 517
 	/**
@@ -524,30 +524,30 @@  discard block
 block discarded – undo
524 524
 	* @param int $n
525 525
 	* @return array
526 526
 	*/
527
-	public function participant($plugin,$id,$n)
527
+	public function participant($plugin, $id, $n)
528 528
 	{
529
-		unset($plugin);	// not used, but required by function signature
529
+		unset($plugin); // not used, but required by function signature
530 530
 
531
-		if(!is_array($id) || !$id['start']) {
531
+		if (!is_array($id) || !$id['start']) {
532 532
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
533 533
 		} else {
534 534
 			$event = $id;
535 535
 		}
536 536
 
537
-		if(!is_array($event['participants']) || $n >= count($event['participants'])) return array();
537
+		if (!is_array($event['participants']) || $n >= count($event['participants'])) return array();
538 538
 
539 539
 		$participant = null;
540 540
 		$status = null;
541 541
 		$i = -1;
542
-		foreach($event['participants'] as $participant => $status) {
543
-			if(++$i == $n) break;
542
+		foreach ($event['participants'] as $participant => $status) {
543
+			if (++$i == $n) break;
544 544
 		}
545 545
 
546
-		if(!$participant) return array();
546
+		if (!$participant) return array();
547 547
 
548 548
 		// Add some common information
549 549
 		$quantity = $role = null;
550
-		calendar_so::split_status($status,$quantity,$role);
550
+		calendar_so::split_status($status, $quantity, $role);
551 551
 		if ($role != 'REQ-PARTICIPANT')
552 552
 		{
553 553
 			if (isset($this->bo->roles[$role]))
@@ -555,13 +555,13 @@  discard block
 block discarded – undo
555 555
 				$role = lang($this->bo->roles[$role]);
556 556
 			}
557 557
 			// allow to use cats as roles (beside regular iCal ones)
558
-			elseif (substr($role,0,6) == 'X-CAT-' && ($cat_id = (int)substr($role,6)) > 0)
558
+			elseif (substr($role, 0, 6) == 'X-CAT-' && ($cat_id = (int)substr($role, 6)) > 0)
559 559
 			{
560 560
 				$role = $GLOBALS['egw']->categories->id2name($cat_id);
561 561
 			}
562 562
 			else
563 563
 			{
564
-				$role = lang(str_replace('X-','',$role));
564
+				$role = lang(str_replace('X-', '', $role));
565 565
 			}
566 566
 		}
567 567
 		$info = array(
@@ -574,26 +574,26 @@  discard block
 block discarded – undo
574 574
 		switch ($participant[0])
575 575
 		{
576 576
 			case 'c':
577
-				$replacements = $this->contact_replacements(substr($participant,1),'');
577
+				$replacements = $this->contact_replacements(substr($participant, 1), '');
578 578
 				break;
579 579
 			case 'r':
580 580
 				if (is_null(self::$resources)) self::$resources = CreateObject('resources.resources_bo');
581
-				if (($resource = self::$resources->read(substr($participant,1))))
581
+				if (($resource = self::$resources->read(substr($participant, 1))))
582 582
 				{
583
-					foreach($resource as $name => $value)
583
+					foreach ($resource as $name => $value)
584 584
 					{
585 585
 					    $replacements['$$'.$name.'$$'] = $value;
586 586
 					}
587 587
 				}
588 588
 				break;
589 589
 			default:
590
-				if (is_numeric($participant) && ($contact = $GLOBALS['egw']->accounts->id2name($participant,'person_id')))
590
+				if (is_numeric($participant) && ($contact = $GLOBALS['egw']->accounts->id2name($participant, 'person_id')))
591 591
 				{
592
-					$replacements = $this->contact_replacements($contact,'');
592
+					$replacements = $this->contact_replacements($contact, '');
593 593
 				}
594 594
 				break;
595 595
 		}
596
-		foreach($info as $name => $value)
596
+		foreach ($info as $name => $value)
597 597
 		{
598 598
 			$replacements['$$'.$name.'$$'] = $value;
599 599
 		}
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 		echo '<tr><td colspan="4"><h3>'.lang('Calendar fields:')."</h3></td></tr>";
616 616
 
617 617
 		$n = 0;
618
-		foreach(array(
618
+		foreach (array(
619 619
 			'calendar_id' => lang('Calendar ID'),
620 620
 			'calendar_title' => lang('Title'),
621 621
 			'calendar_description' => lang('Description'),
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 			'calendar_owner'    => lang('Owner'),
639 639
 		) as $name => $label)
640 640
 		{
641
-			if (in_array($name,array('start','end')) && $n&1)		// main values, which should be in the first column
641
+			if (in_array($name, array('start', 'end')) && $n&1)		// main values, which should be in the first column
642 642
 			{
643 643
 				echo "</tr>\n";
644 644
 				$n++;
@@ -651,13 +651,13 @@  discard block
 block discarded – undo
651 651
 
652 652
 		echo '<tr><td colspan="4"><h3>'.lang('Range fields').":</h3></td></tr>";
653 653
 		echo '<tr><td colspan="4">'.lang('If you select a range (month, week, etc) instead of a list of entries, these extra fields are available').'</td></tr>';
654
-		foreach(array_keys(self::$range_tags) as $name)
654
+		foreach (array_keys(self::$range_tags) as $name)
655 655
 		{
656 656
 			echo '<tr><td>{{range/'.$name.'}}</td><td>'.lang($name)."</td></tr>\n";
657 657
 		}
658 658
 		echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
659 659
 		$custom = Api\Storage\Customfields::get('calendar');
660
-		foreach($custom as $name => $field)
660
+		foreach ($custom as $name => $field)
661 661
 		{
662 662
 			echo '<tr><td>{{#'.$name.'}}</td><td colspan="3">'.$field['label']."</td></tr>\n";
663 663
 		}
@@ -666,9 +666,9 @@  discard block
 block discarded – undo
666 666
 		echo '<tr><td colspan="4"><h3>'.lang('Participants').":</h3></td></tr>";
667 667
 		echo '<tr><td>{{calendar_participants/account}}</td><td colspan="3">'.lang('Accounts')."</td></tr>\n";
668 668
 		echo '<tr><td>{{calendar_participants/group}}</td><td colspan="3">'.lang('Groups')."</td></tr>\n";
669
-		foreach($this->bo->resources as $resource)
669
+		foreach ($this->bo->resources as $resource)
670 670
 		{
671
-			if($resource['type'])
671
+			if ($resource['type'])
672 672
 			{
673 673
 				echo '<tr><td>{{calendar_participants/'.$resource['app'].'}}</td><td colspan="3">'.lang($resource['app'])."</td></tr>\n";
674 674
 			}
@@ -685,19 +685,19 @@  discard block
 block discarded – undo
685 685
 		echo '<tr style="vertical-align:top"><td colspan="2"><table >';
686 686
 		echo '<tr><td><h3>'.lang('Day of week tables').":</h3></td></tr>";
687 687
 		$days = array();
688
-		for($i = 0; $i < 7; $i++)
688
+		for ($i = 0; $i < 7; $i++)
689 689
 		{
690
-			$days[date('N',strtotime("+$i days"))] = date('l',strtotime("+$i days"));
690
+			$days[date('N', strtotime("+$i days"))] = date('l', strtotime("+$i days"));
691 691
 		}
692 692
 		ksort($days);
693
-		foreach($days as $day)
693
+		foreach ($days as $day)
694 694
 		{
695
-			echo '<tr><td>{{table/'.$day. '}} ... {{endtable}}</td></tr>';
695
+			echo '<tr><td>{{table/'.$day.'}} ... {{endtable}}</td></tr>';
696 696
 		}
697 697
 		echo '</table></td><td colspan="2"><table >';
698 698
 		echo '<tr><td><h3>'.lang('Daily tables').":</h3></td></tr>";
699
-		foreach(self::$relative as $value) {
700
-			echo '<tr><td>{{table/'.$value. '}} ... {{endtable}}</td></tr>';
699
+		foreach (self::$relative as $value) {
700
+			echo '<tr><td>{{table/'.$value.'}} ... {{endtable}}</td></tr>';
701 701
 		}
702 702
 		echo '<tr><td>{{table/day_n}} ... {{endtable}}</td><td>1 <= n <= 31</td></tr>';
703 703
 		echo '</table></td></tr>';
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 		echo '<tr><td>{{day/name}}</td><td colspan="3">'.lang('Name of the week (ex: Monday), available for the first entry inside each day of week or daily table inside the selected range.').'</td></tr>';
706 706
 
707 707
 		echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";
708
-		foreach(array(
708
+		foreach (array(
709 709
 			'link' => lang('HTML link to the current record'),
710 710
 			'links' => lang('Titles of any entries linked to the current record, excluding attached files'),
711 711
 			'attachments' => lang('List of files linked to the current record'),
Please login to merge, or discard this patch.
Braces   +167 added lines, -53 removed lines patch added patch discarded remove patch
@@ -88,10 +88,12 @@  discard block
 block discarded – undo
88 88
 		{
89 89
 			$this->table_plugins[date('l', strtotime("+$i days"))] = 'day_plugin';
90 90
 		}
91
-		for($i = 1; $i <= 31; $i++) {
91
+		for($i = 1; $i <= 31; $i++)
92
+		{
92 93
 			$this->table_plugins['day_'.$i] = 'day'; // Numerically by day number (1-31)
93 94
 		}
94
-		foreach(self::$relative as $day) {
95
+		foreach(self::$relative as $day)
96
+		{
95 97
 			$this->table_plugins[$day] = 'day'; // Current day
96 98
 		}
97 99
 		$this->query = is_array($this->bo->cal_prefs['saved_states']) ?
@@ -131,9 +133,16 @@  discard block
 block discarded – undo
131 133
 				$events = $ids;
132 134
 				$ids = array('start' => PHP_INT_MAX, 'end' => 0);
133 135
 				$this->ids = array();
134
-				foreach($events as $event) {
135
-					if($event['start'] && Api\DateTime::to($event['start'],'ts') < $ids['start']) $ids['start'] = Api\DateTime::to($event['start'],'ts');
136
-					if($event['end'] && Api\DateTime::to($event['end'],'ts') > $ids['end']) $ids['end'] = Api\DateTime::to($event['end'],'ts');
136
+				foreach($events as $event)
137
+				{
138
+					if($event['start'] && Api\DateTime::to($event['start'],'ts') < $ids['start'])
139
+					{
140
+						$ids['start'] = Api\DateTime::to($event['start'],'ts');
141
+					}
142
+					if($event['end'] && Api\DateTime::to($event['end'],'ts') > $ids['end'])
143
+					{
144
+						$ids['end'] = Api\DateTime::to($event['end'],'ts');
145
+					}
137 146
 					// Keep ids for future use
138 147
 					$this->ids[] = $event['id'];
139 148
 				}
@@ -154,7 +163,8 @@  discard block
 block discarded – undo
154 163
 				'cfs' => strpos($content, '#') !== false ? array_keys(Api\Storage\Customfields::get('calendar')) : null
155 164
 			));
156 165
 			$ids = array();
157
-			foreach($events as $event) {
166
+			foreach($events as $event)
167
+			{
158 168
 				$ids[] = $event;
159 169
 			}
160 170
 		}
@@ -192,9 +202,16 @@  discard block
 block discarded – undo
192 202
 			$events = $id;
193 203
 			$id = array('start' => PHP_INT_MAX, 'end' => 0);
194 204
 			$this->ids = array();
195
-			foreach($events as $event) {
196
-				if($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
197
-				if($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
205
+			foreach($events as $event)
206
+			{
207
+				if($event['start'] && $event['start'] < $id['start'])
208
+				{
209
+					$id['start'] = $event['start'];
210
+				}
211
+				if($event['end'] && $event['end'] > $id['end'])
212
+				{
213
+					$id['end'] = $event['end'];
214
+				}
198 215
 				// Keep ids for future use
199 216
 				$this->ids[]  = $event['id'];
200 217
 			}
@@ -221,7 +238,10 @@  discard block
 block discarded – undo
221 238
 				foreach(self::$range_tags as $key => $format)
222 239
 				{
223 240
 					$value = date($format, $key == 'end' ? $id['end'] : $id['start']);
224
-					if($key == 'month') $value = lang($value);
241
+					if($key == 'month')
242
+					{
243
+						$value = lang($value);
244
+					}
225 245
 					$values["$\$range/$key$$"] = $value;
226 246
 				}
227 247
 			}
@@ -240,9 +260,12 @@  discard block
 block discarded – undo
240 260
 	public function calendar_replacements($id,$prefix = '', &$content = '')
241 261
 	{
242 262
 		$replacements = array();
243
-		if(!is_array($id) || !$id['start']) {
263
+		if(!is_array($id) || !$id['start'])
264
+		{
244 265
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
245
-		} else {
266
+		}
267
+		else
268
+		{
246 269
 			$event = $id;
247 270
 		}
248 271
 
@@ -261,7 +284,10 @@  discard block
 block discarded – undo
261 284
 		$replacements['$$' . ($prefix ? $prefix . '/' : '') . 'calendar_id'. '$$'] = $event['id'];
262 285
 		foreach($this->bo->event2array($event) as $name => $data)
263 286
 		{
264
-			if (substr($name,-4) == 'date') $name = substr($name,0,-4);
287
+			if (substr($name,-4) == 'date')
288
+			{
289
+				$name = substr($name,0,-4);
290
+			}
265 291
 			$replacements['$$' . ($prefix ? $prefix . '/' : '') . 'calendar_'.$name . '$$'] = is_array($data['data']) ? implode(', ',$data['data']) : $data['data'];
266 292
 		}
267 293
 		// Add seperate lists of participants by type
@@ -300,7 +326,10 @@  discard block
 block discarded – undo
300 326
 			) as $name => $format)
301 327
 			{
302 328
 				$value = Api\DateTime::to($event[$what],$format);
303
-				if ($format == 'l') $value = lang($value);
329
+				if ($format == 'l')
330
+				{
331
+					$value = lang($value);
332
+				}
304 333
 				$replacements['$$' .($prefix ? $prefix.'/':'').'calendar_'.$what.$name.'$$'] = $value;
305 334
 			}
306 335
 		}
@@ -343,24 +372,41 @@  discard block
 block discarded – undo
343 372
 	public function day_plugin($plugin,$date,$n,$repeat)
344 373
 	{
345 374
 		static $days = null;
346
-		if(is_array($date) && !$date['start']) {
375
+		if(is_array($date) && !$date['start'])
376
+		{
347 377
 			// List of IDs
348
-			if($date[0]['start']) {
378
+			if($date[0]['start'])
379
+			{
349 380
 				$id = array('start' => PHP_INT_MAX, 'end' => 0);
350
-				foreach($date as $event) {
351
-					if($event['start'] && $event['start'] < $id['start']) $id['start'] = $event['start'];
352
-					if($event['end'] && $event['end'] > $id['end']) $id['end'] = $event['end'];
381
+				foreach($date as $event)
382
+				{
383
+					if($event['start'] && $event['start'] < $id['start'])
384
+					{
385
+						$id['start'] = $event['start'];
386
+					}
387
+					if($event['end'] && $event['end'] > $id['end'])
388
+					{
389
+						$id['end'] = $event['end'];
390
+					}
353 391
 				}
354 392
 				$date = $id;
355
-			} else {
393
+			}
394
+			else
395
+			{
356 396
 				$event = $this->bo->read(is_array($date) ? $date['id'] : $date, is_array($date) ? $date['recur_date'] : null);
357
-				if(date('l',$event['start']) != $plugin) return array();
397
+				if(date('l',$event['start']) != $plugin)
398
+				{
399
+					return array();
400
+				}
358 401
 				$date = $event['start'];
359 402
 			}
360 403
 		}
361 404
 
362 405
 		$_date = $date['start'] ? $date['start'] : $date;
363
-		if($days[date('Ymd',$_date)][$plugin]) return $days[date('Ymd',$_date)][$plugin][$n];
406
+		if($days[date('Ymd',$_date)][$plugin])
407
+		{
408
+			return $days[date('Ymd',$_date)][$plugin][$n];
409
+		}
364 410
 
365 411
 		$events = $this->bo->search($this->query + array(
366 412
 			'start' => $date['end'] ? $date['start'] : mktime(0,0,0,date('m',$_date),date('d',$_date),date('Y',$_date)),
@@ -372,20 +418,29 @@  discard block
 block discarded – undo
372 418
 			'cfs' => array(),	// read all custom-fields
373 419
 		));
374 420
 
375
-		if (true) $days = array();
421
+		if (true)
422
+		{
423
+			$days = array();
424
+		}
376 425
 		$replacements = array();
377 426
 		$time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i';
378 427
 		foreach($events as $day => $list)
379 428
 		{
380 429
 			foreach($list as $event)
381 430
 			{
382
-				if($this->ids && !in_array($event['id'], $this->ids)) continue;
431
+				if($this->ids && !in_array($event['id'], $this->ids))
432
+				{
433
+					continue;
434
+				}
383 435
 				$start = Api\DateTime::to($event['start'], 'array');
384 436
 				$end = Api\DateTime::to($event['end'], 'array');
385 437
 				$replacements = $this->calendar_replacements($event);
386
-				if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
438
+				if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day'])
439
+				{
387 440
 					$dow = date('l',$event['start']);
388
-				} else {
441
+				}
442
+				else
443
+				{
389 444
 					$dow = date('l', strtotime($day));
390 445
 					// Fancy date+time formatting for multi-day events
391 446
 					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0,0,0,0,0,1));
@@ -394,12 +449,14 @@  discard block
 block discarded – undo
394 449
 
395 450
 				$days[date('Ymd',$_date)][$dow][] = $replacements;
396 451
 			}
397
-			if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
452
+			if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false)
453
+			{
398 454
 				$date_marker = array(
399 455
 					'$$day/date$$' => date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], strtotime($day)),
400 456
 					'$$day/name$$' => lang(date('l', strtotime($day)))
401 457
 				);
402
-				if(!is_array($days[date('Ymd',$_date)][date('l',strtotime($day))])) {
458
+				if(!is_array($days[date('Ymd',$_date)][date('l',strtotime($day))]))
459
+				{
403 460
 					$blank = $this->calendar_replacements(array());
404 461
 					foreach($blank as &$value)
405 462
 					{
@@ -435,16 +492,26 @@  discard block
 block discarded – undo
435 492
 			if($id[0]['start'])
436 493
 			{
437 494
 				$dates = array('start' => PHP_INT_MAX, 'end' => 0);
438
-				foreach($id as $event) {
439
-					if($event['start'] && $event['start'] < $dates['start']) $dates['start'] = $event['start'];
440
-					if($event['end'] && $event['end'] > $dates['end']) $dates['end'] = $event['end'];
495
+				foreach($id as $event)
496
+				{
497
+					if($event['start'] && $event['start'] < $dates['start'])
498
+					{
499
+						$dates['start'] = $event['start'];
500
+					}
501
+					if($event['end'] && $event['end'] > $dates['end'])
502
+					{
503
+						$dates['end'] = $event['end'];
504
+					}
441 505
 				}
442 506
 				$id = $dates;
443 507
 			}
444 508
 			$arr = $this->bo->date2array($id['start']);
445 509
 			$arr['day'] = $which;
446 510
 			$date = $this->bo->date2ts($arr);
447
-			if(is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end'])) return array();
511
+			if(is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end']))
512
+			{
513
+				return array();
514
+			}
448 515
 		}
449 516
 		elseif ($plugin == 'selected')
450 517
 		{
@@ -454,16 +521,26 @@  discard block
 block discarded – undo
454 521
 		{
455 522
 			$date = strtotime($plugin);
456 523
 		}
457
-		if($type == 'day' && is_array($id) && !$id['start']) {
524
+		if($type == 'day' && is_array($id) && !$id['start'])
525
+		{
458 526
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
459
-			if($which && date('d',$event['start']) != $which) return array();
460
-			if(date('Ymd',$date) != date('Ymd', $event['start'])) return array();
527
+			if($which && date('d',$event['start']) != $which)
528
+			{
529
+				return array();
530
+			}
531
+			if(date('Ymd',$date) != date('Ymd', $event['start']))
532
+			{
533
+				return array();
534
+			}
461 535
 			return $n == 0 ? $this->calendar_replacements($event) : array();
462 536
 		}
463 537
 
464 538
 		// Use start for cache, in case of multiple months
465 539
 		$_date = $id['start'] ? $id['start'] : $date;
466
-		if($days[date('Ymd',$_date)][$plugin]) return $days[date('Ymd',$_date)][$plugin][$n];
540
+		if($days[date('Ymd',$_date)][$plugin])
541
+		{
542
+			return $days[date('Ymd',$_date)][$plugin][$n];
543
+		}
467 544
 
468 545
 		$events = $this->bo->search($this->query + array(
469 546
 			'start' => $date,
@@ -476,31 +553,42 @@  discard block
 block discarded – undo
476 553
 		));
477 554
 
478 555
 		$replacements = array();
479
-		if (true) $days = array();
556
+		if (true)
557
+		{
558
+			$days = array();
559
+		}
480 560
 		$time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i';
481 561
 		foreach($events as $day => $list)
482 562
 		{
483 563
 			foreach($list as $event)
484 564
 			{
485
-				if($this->ids && !in_array($event['id'], $this->ids)) continue;
565
+				if($this->ids && !in_array($event['id'], $this->ids))
566
+				{
567
+					continue;
568
+				}
486 569
 				$start = Api\DateTime::to($event['start'], 'array');
487 570
 				$end = Api\DateTime::to($event['end'], 'array');
488 571
 				$replacements = $this->calendar_replacements($event);
489
-				if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
572
+				if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day'])
573
+				{
490 574
 					//$dow = date('l',$event['start']);
491
-				} else {
575
+				}
576
+				else
577
+				{
492 578
 					// Fancy date+time formatting for multi-day events
493 579
 					$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0,0,0,0,0,1));
494 580
 					$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23,59,59,0,0,0));
495 581
 				}
496 582
 				$days[date('Ymd',$_date)][$plugin][] = $replacements;
497 583
 			}
498
-			if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false) {
584
+			if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false)
585
+			{
499 586
 				$date_marker = array(
500 587
 					'$$day/date$$' => date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], strtotime($day)),
501 588
 					'$$day/name$$' => lang(date('l', strtotime($day)))
502 589
 				);
503
-				if(!is_array($days[date('Ymd',$_date)][$plugin])) {
590
+				if(!is_array($days[date('Ymd',$_date)][$plugin]))
591
+				{
504 592
 					$blank = $this->calendar_replacements(array());
505 593
 					foreach($blank as &$value)
506 594
 					{
@@ -528,22 +616,35 @@  discard block
 block discarded – undo
528 616
 	{
529 617
 		unset($plugin);	// not used, but required by function signature
530 618
 
531
-		if(!is_array($id) || !$id['start']) {
619
+		if(!is_array($id) || !$id['start'])
620
+		{
532 621
 			$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
533
-		} else {
622
+		}
623
+		else
624
+		{
534 625
 			$event = $id;
535 626
 		}
536 627
 
537
-		if(!is_array($event['participants']) || $n >= count($event['participants'])) return array();
628
+		if(!is_array($event['participants']) || $n >= count($event['participants']))
629
+		{
630
+			return array();
631
+		}
538 632
 
539 633
 		$participant = null;
540 634
 		$status = null;
541 635
 		$i = -1;
542
-		foreach($event['participants'] as $participant => $status) {
543
-			if(++$i == $n) break;
636
+		foreach($event['participants'] as $participant => $status)
637
+		{
638
+			if(++$i == $n)
639
+			{
640
+				break;
641
+			}
544 642
 		}
545 643
 
546
-		if(!$participant) return array();
644
+		if(!$participant)
645
+		{
646
+			return array();
647
+		}
547 648
 
548 649
 		// Add some common information
549 650
 		$quantity = $role = null;
@@ -577,7 +678,10 @@  discard block
 block discarded – undo
577 678
 				$replacements = $this->contact_replacements(substr($participant,1),'');
578 679
 				break;
579 680
 			case 'r':
580
-				if (is_null(self::$resources)) self::$resources = new resources_bo();
681
+				if (is_null(self::$resources))
682
+				{
683
+					self::$resources = new resources_bo();
684
+				}
581 685
 				if (($resource = self::$resources->read(substr($participant,1))))
582 686
 				{
583 687
 					foreach($resource as $name => $value)
@@ -638,14 +742,23 @@  discard block
 block discarded – undo
638 742
 			'calendar_owner'    => lang('Owner'),
639 743
 		) as $name => $label)
640 744
 		{
641
-			if (in_array($name,array('start','end')) && $n&1)		// main values, which should be in the first column
745
+			if (in_array($name,array('start','end')) && $n&1)
746
+			{
747
+				// main values, which should be in the first column
642 748
 			{
643 749
 				echo "</tr>\n";
750
+			}
644 751
 				$n++;
645 752
 			}
646
-			if (!($n&1)) echo '<tr>';
753
+			if (!($n&1))
754
+			{
755
+				echo '<tr>';
756
+			}
647 757
 			echo '<td>{{'.$name.'}}</td><td>'.$label.'</td>';
648
-			if ($n&1) echo "</tr>\n";
758
+			if ($n&1)
759
+			{
760
+				echo "</tr>\n";
761
+			}
649 762
 			$n++;
650 763
 		}
651 764
 
@@ -696,7 +809,8 @@  discard block
 block discarded – undo
696 809
 		}
697 810
 		echo '</table></td><td colspan="2"><table >';
698 811
 		echo '<tr><td><h3>'.lang('Daily tables').":</h3></td></tr>";
699
-		foreach(self::$relative as $value) {
812
+		foreach(self::$relative as $value)
813
+		{
700 814
 			echo '<tr><td>{{table/'.$value. '}} ... {{endtable}}</td></tr>';
701 815
 		}
702 816
 		echo '<tr><td>{{table/day_n}} ... {{endtable}}</td><td>1 <= n <= 31</td></tr>';
Please login to merge, or discard this patch.
calendar/inc/class.calendar_favorite_portlet.inc.php 3 patches
Spacing   +41 added lines, -42 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
 		$reload = !is_null($need_reload);
33 33
 
34 34
 		// Let parent handle the basic stuff
35
-		parent::__construct($context,$need_reload);
35
+		parent::__construct($context, $need_reload);
36 36
 
37
-		if($this->favorite['state']['view'] == 'listview')
37
+		if ($this->favorite['state']['view'] == 'listview')
38 38
 		{
39 39
 			$this->context['template'] = 'calendar.list.rows';
40 40
 			$this->context['sel_options'] = array();
41 41
 			$this->nm_settings += array(
42 42
 				'csv_export'      => True,
43
-				'filter_no_lang'  => True,	// I  set no_lang for filter (=dont translate the options)
44
-				'no_filter2'      => True,	// I  disable the 2. filter (params are the same as for filter)
45
-				'no_cat'          => True,	// I  disable the cat-selectbox
43
+				'filter_no_lang'  => True, // I  set no_lang for filter (=dont translate the options)
44
+				'no_filter2'      => True, // I  disable the 2. filter (params are the same as for filter)
45
+				'no_cat'          => True, // I  disable the cat-selectbox
46 46
 				'filter'          => 'after',
47
-				'row_id'          => 'row_id',	// set in get rows "$event[id]:$event[recur_date]"
47
+				'row_id'          => 'row_id', // set in get rows "$event[id]:$event[recur_date]"
48 48
 				'row_modified'    => 'modified',
49 49
 				'get_rows'	=> 'calendar_favorite_portlet::get_rows',
50 50
 				// Use a different template so it can be accessed from client side
@@ -58,17 +58,17 @@  discard block
 block discarded – undo
58 58
 		$need_reload = $reload && $need_reload;
59 59
 	}
60 60
 
61
-	public function exec($id = null, Etemplate &$etemplate = null)
61
+	public function exec($id = null, Etemplate&$etemplate = null)
62 62
 	{
63 63
 
64 64
 		// Always load app's javascript, so most actions have a chance of working
65
-		Framework::includeJS('.','app',$this->context['appname']);
65
+		Framework::includeJS('.', 'app', $this->context['appname']);
66 66
 
67 67
 		// Always load app's css
68 68
 		Framework::includeCSS('calendar', 'app-'.$GLOBALS['egw_info']['user']['preferences']['common']['theme']) ||
69
-			Framework::includeCSS('calendar','app');
69
+			Framework::includeCSS('calendar', 'app');
70 70
 
71
-		if($this->favorite['state']['view'] == 'listview' || is_array($this->favorite) && !$this->favorite['state']['view'])
71
+		if ($this->favorite['state']['view'] == 'listview' || is_array($this->favorite) && !$this->favorite['state']['view'])
72 72
 		{
73 73
 			$ui = new calendar_uilist();
74 74
 		}
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
 			$ui = new calendar_uiviews();
78 78
 			if ($this->favorite)
79 79
 			{
80
-				if($this->favorite['state']['start']) $ui->search_params['start'] = $this->favorite['state']['start'];
81
-				if($this->favorite['state']['cat_id']) $ui->search_params['cat_id'] = $this->favorite['state']['cat_id'];
80
+				if ($this->favorite['state']['start']) $ui->search_params['start'] = $this->favorite['state']['start'];
81
+				if ($this->favorite['state']['cat_id']) $ui->search_params['cat_id'] = $this->favorite['state']['cat_id'];
82 82
 				// Owner can be 0 for current user
83
-				if(array_key_exists('owner',$this->favorite['state'])) $ui->search_params['users'] = $this->favorite['state']['owner'];
84
-				if($ui->search_params['users'] && !is_array($ui->search_params['users']))
83
+				if (array_key_exists('owner', $this->favorite['state'])) $ui->search_params['users'] = $this->favorite['state']['owner'];
84
+				if ($ui->search_params['users'] && !is_array($ui->search_params['users']))
85 85
 				{
86
-					$ui->search_params['users'] = explode(',',$ui->search_params['users']);
86
+					$ui->search_params['users'] = explode(',', $ui->search_params['users']);
87 87
 				}
88
-				if($this->favorite['state']['filter']) $ui->search_params['filter'] = $this->favorite['state']['filter'];
89
-				if($this->favorite['state']['sortby']) $ui->search_params['sortby'] = $this->favorite['state']['sortby'];
88
+				if ($this->favorite['state']['filter']) $ui->search_params['filter'] = $this->favorite['state']['filter'];
89
+				if ($this->favorite['state']['sortby']) $ui->search_params['sortby'] = $this->favorite['state']['sortby'];
90 90
 				$ui->search_params['weekend'] = $this->favorite['state']['weekend'];
91 91
 			}
92 92
 			$etemplate->read('home.legacy');
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 
97 97
 		$content = array('legacy' => '');
98 98
 
99
-		switch($this->favorite['state']['view'])
99
+		switch ($this->favorite['state']['view'])
100 100
 		{
101 101
 			case 'listview':
102 102
 				$this->context['sel_options']['filter'] = &$ui->date_filters;
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
 				$content = array();
111 111
 				$etemplate->read('calendar.planner');
112 112
 				$etemplate->set_dom_id($id);
113
-				$this->actions =& $etemplate->getElementAttribute('planner', 'actions');
113
+				$this->actions = & $etemplate->getElementAttribute('planner', 'actions');
114 114
 				// Don't notify the calendar app of date changes
115
-				$etemplate->setElementAttribute('planner','onchange',false);
115
+				$etemplate->setElementAttribute('planner', 'onchange', false);
116 116
 				$ui->planner_view = $this->favorite['state']['planner_view'];
117 117
 				$ui->planner(array(), $etemplate);
118 118
 				return;
@@ -120,20 +120,19 @@  discard block
 block discarded – undo
120 120
 			case 'weekN':
121 121
 				$etemplate->read('calendar.view');
122 122
 				$etemplate->set_dom_id($id);
123
-				$this->actions =& $etemplate->getElementAttribute('view', 'actions');
123
+				$this->actions = & $etemplate->getElementAttribute('view', 'actions');
124 124
 
125 125
 				$ui->month($this->favorite['state']['view'] == 'month' ?
126
-					0 :
127
-					(int)$ui->cal_prefs['multiple_weeks'],
126
+					0 : (int)$ui->cal_prefs['multiple_weeks'],
128 127
 					$etemplate
129 128
 				);
130 129
 				return;
131 130
 			case 'week':
132 131
 				$etemplate->read('calendar.view');
133 132
 				$etemplate->set_dom_id($id);
134
-				$this->actions =& $etemplate->getElementAttribute('view', 'actions');
133
+				$this->actions = & $etemplate->getElementAttribute('view', 'actions');
135 134
 				// Don't notify the calendar app of date changes
136
-				$etemplate->setElementAttribute('view[0]','onchange',false);
135
+				$etemplate->setElementAttribute('view[0]', 'onchange', false);
137 136
 				$ui->week(array(), $etemplate);
138 137
 				return;
139 138
 			case 'day':
@@ -143,7 +142,7 @@  discard block
 block discarded – undo
143 142
 				$days = $this->favorite['state']['days'] ? $this->favorite['state']['days'] : (
144 143
 					$this->favorite['state']['view'] == 'day' ? 1 : 4
145 144
 				);
146
-				$this->actions =& $etemplate->getElementAttribute('view', 'actions');
145
+				$this->actions = & $etemplate->getElementAttribute('view', 'actions');
147 146
 				$ui->week($days, $etemplate);
148 147
 				return;
149 148
 		}
@@ -156,7 +155,7 @@  discard block
 block discarded – undo
156 155
 		$old_app = $GLOBALS['egw_info']['flags']['currentapp'];
157 156
 		$GLOBALS['egw_info']['flags']['currentapp'] = 'calendar';
158 157
 
159
-		$etemplate->exec(get_called_class() .'::process',$content);
158
+		$etemplate->exec(get_called_class().'::process', $content);
160 159
 		$GLOBALS['egw_info']['flags']['currentapp'] = $old_app;
161 160
 	}
162 161
 
@@ -199,27 +198,27 @@  discard block
 block discarded – undo
199 198
 			else
200 199
 			{
201 200
 				$success = $failed = $action_msg = $msg = null;
202
-				if ($ui->action($values['nm']['action'],$values['nm']['selected'],$values['nm']['select_all'],
203
-						$success,$failed,$action_msg,'calendar_list',$msg, $values['nm']['checkboxes']['no_notifications']))
201
+				if ($ui->action($values['nm']['action'], $values['nm']['selected'], $values['nm']['select_all'],
202
+						$success, $failed, $action_msg, 'calendar_list', $msg, $values['nm']['checkboxes']['no_notifications']))
204 203
 				{
205
-					$msg .= lang('%1 event(s) %2',$success,$action_msg);
206
-					Api\Json\Response::get()->apply('egw.message',array($msg,'success'));
207
-					foreach($values['nm']['selected'] as &$id)
204
+					$msg .= lang('%1 event(s) %2', $success, $action_msg);
205
+					Api\Json\Response::get()->apply('egw.message', array($msg, 'success'));
206
+					foreach ($values['nm']['selected'] as &$id)
208 207
 					{
209 208
 						$id = 'calendar::'.$id;
210 209
 					}
211 210
 					// Directly request an update - this will get addressbook tab too
212
-					Api\Json\Response::get()->apply('egw.dataRefreshUIDs',array($values['nm']['selected']));
211
+					Api\Json\Response::get()->apply('egw.dataRefreshUIDs', array($values['nm']['selected']));
213 212
 				}
214
-				elseif(is_null($msg))
213
+				elseif (is_null($msg))
215 214
 				{
216
-					$msg .= lang('%1 entries %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
217
-					Api\Json\Response::get()->apply('egw.message',array($msg,'error'));
215
+					$msg .= lang('%1 entries %2, %3 failed because of insufficent rights !!!', $success, $action_msg, $failed);
216
+					Api\Json\Response::get()->apply('egw.message', array($msg, 'error'));
218 217
 				}
219
-				elseif($msg)
218
+				elseif ($msg)
220 219
 				{
221
-					$msg .= "\n".lang('%1 entries %2, %3 failed.',$success,$action_msg,$failed);
222
-					Api\Json\Response::get()->apply('egw.message',array($msg,'error'));
220
+					$msg .= "\n".lang('%1 entries %2, %3 failed.', $success, $action_msg, $failed);
221
+					Api\Json\Response::get()->apply('egw.message', array($msg, 'error'));
223 222
 				}
224 223
 				unset($values['nm']['action']);
225 224
 				unset($values['nm']['select_all']);
@@ -235,9 +234,9 @@  discard block
 block discarded – undo
235 234
 	public function get_properties()
236 235
 	{
237 236
 		$properties = parent::get_properties();
238
-		foreach($properties as &$property)
237
+		foreach ($properties as &$property)
239 238
 		{
240
-			if($property['name'] == 'favorite')
239
+			if ($property['name'] == 'favorite')
241 240
 			{
242 241
 				unset($property['select_options']['blank']);
243 242
 				break;
@@ -247,7 +246,7 @@  discard block
 block discarded – undo
247 246
 	}
248 247
 
249 248
 	public function get_actions() {
250
-		if($this->favorite['state']['view'] == 'listview' || !$this->actions)
249
+		if ($this->favorite['state']['view'] == 'listview' || !$this->actions)
251 250
 		{
252 251
 			return array();
253 252
 		}
Please login to merge, or discard this patch.
Braces   +22 added lines, -6 removed lines patch added patch discarded remove patch
@@ -77,16 +77,31 @@  discard block
 block discarded – undo
77 77
 			$ui = new calendar_uiviews();
78 78
 			if ($this->favorite)
79 79
 			{
80
-				if($this->favorite['state']['start']) $ui->search_params['start'] = $this->favorite['state']['start'];
81
-				if($this->favorite['state']['cat_id']) $ui->search_params['cat_id'] = $this->favorite['state']['cat_id'];
80
+				if($this->favorite['state']['start'])
81
+				{
82
+					$ui->search_params['start'] = $this->favorite['state']['start'];
83
+				}
84
+				if($this->favorite['state']['cat_id'])
85
+				{
86
+					$ui->search_params['cat_id'] = $this->favorite['state']['cat_id'];
87
+				}
82 88
 				// Owner can be 0 for current user
83
-				if(array_key_exists('owner',$this->favorite['state'])) $ui->search_params['users'] = $this->favorite['state']['owner'];
89
+				if(array_key_exists('owner',$this->favorite['state']))
90
+				{
91
+					$ui->search_params['users'] = $this->favorite['state']['owner'];
92
+				}
84 93
 				if($ui->search_params['users'] && !is_array($ui->search_params['users']))
85 94
 				{
86 95
 					$ui->search_params['users'] = explode(',',$ui->search_params['users']);
87 96
 				}
88
-				if($this->favorite['state']['filter']) $ui->search_params['filter'] = $this->favorite['state']['filter'];
89
-				if($this->favorite['state']['sortby']) $ui->search_params['sortby'] = $this->favorite['state']['sortby'];
97
+				if($this->favorite['state']['filter'])
98
+				{
99
+					$ui->search_params['filter'] = $this->favorite['state']['filter'];
100
+				}
101
+				if($this->favorite['state']['sortby'])
102
+				{
103
+					$ui->search_params['sortby'] = $this->favorite['state']['sortby'];
104
+				}
90 105
 				$ui->search_params['weekend'] = $this->favorite['state']['weekend'];
91 106
 			}
92 107
 			$etemplate->read('home.legacy');
@@ -246,7 +261,8 @@  discard block
 block discarded – undo
246 261
 		return $properties;
247 262
 	}
248 263
 
249
-	public function get_actions() {
264
+	public function get_actions()
265
+	{
250 266
 		if($this->favorite['state']['view'] == 'listview' || !$this->actions)
251 267
 		{
252 268
 			return array();
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
 	 *
50 50
 	 * @param boolean $need_reload Flag to indicate that the portlet needs to be reloaded (exec will be called)
51 51
 	 */
52
-	public function __construct(Array &$context = array(), &$need_reload = false)
52
+	public function __construct(array &$context = array(), &$need_reload = false)
53 53
 	{
54 54
 		if (false) parent::__construct();
55 55
 
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   +14 added lines, -14 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,25 +144,25 @@  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
-		parent::track($data,$old,$user,$deleted, $changed_fields);
157
+		parent::track($data, $old, $user, $deleted, $changed_fields);
158 158
 	}
159 159
 
160 160
 	/**
161 161
 	 * Overrides parent because calendar_boupdates handles the notifications
162 162
 	 */
163
-	public function do_notifications($data,$old,$deleted=null)
163
+	public function do_notifications($data, $old, $deleted = null)
164 164
 	{
165
-		unset($data, $old, $deleted);	// unused, but required by function signature
165
+		unset($data, $old, $deleted); // unused, but required by function signature
166 166
 		return true;
167 167
 	}
168 168
 
@@ -177,21 +177,21 @@  discard block
 block discarded – undo
177 177
 	 * @param array $old = null
178 178
 	 * @return array of keys with different values in $data and $old
179 179
 	 */
180
-	public function changed_fields(array $data,array $old=null)
180
+	public function changed_fields(array $data, array $old = null)
181 181
 	{
182
-		if(is_array($data['participants']))
182
+		if (is_array($data['participants']))
183 183
 		{
184 184
 			$participants = $data['participants'];
185 185
 			$data['participants'] = array();
186 186
 			$data = array_merge($data, $this->alter_participants($participants));
187 187
 		}
188
-		if(is_array($old['participants']))
188
+		if (is_array($old['participants']))
189 189
 		{
190 190
 			$participants = $old['participants'];
191 191
 			$old['participants'] = array();
192 192
 			$old = array_merge($old, $this->alter_participants($participants));
193 193
 		}
194
-		return parent::changed_fields($data,$old);
194
+		return parent::changed_fields($data, $old);
195 195
 	}
196 196
 
197 197
 	/**
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	protected function alter_participants($participants)
203 203
 	{
204 204
 		$data = array();
205
-		foreach($participants as $uid => $status)
205
+		foreach ($participants as $uid => $status)
206 206
 		{
207 207
 			$quantity = $role = $user_type = $user_id = null;
208 208
 			calendar_so::split_status($status, $quantity, $role);
Please login to merge, or discard this patch.
calendar/inc/class.calendar_so.inc.php 5 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.
Braces   +366 added lines, -96 removed lines patch added patch discarded remove patch
@@ -154,16 +154,32 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	protected function cal_range_view($start, $end, array $_where=null, $deleted=false)
156 156
 	{
157
-		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start)	// using view without start-date is slower!
157
+		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start)
158 158
 		{
159
-			return $this->cal_table;	// no need / use for a view
159
+			// using view without start-date is slower!
160
+		{
161
+			return $this->cal_table;
162
+		}
163
+		// no need / use for a view
160 164
 		}
161 165
 
162 166
 		$where = array();
163
-		if (isset($deleted)) $where[] = "cal_deleted IS ".($deleted ? '' : 'NOT').' NULL';
164
-		if ($end) $where[] = "range_start<".(int)$end;
165
-		if ($start) $where[] = "(range_end IS NULL OR range_end>".(int)$start.")";
166
-		if ($_where) $where = array_merge($where, $_where);
167
+		if (isset($deleted))
168
+		{
169
+			$where[] = "cal_deleted IS ".($deleted ? '' : 'NOT').' NULL';
170
+		}
171
+		if ($end)
172
+		{
173
+			$where[] = "range_start<".(int)$end;
174
+		}
175
+		if ($start)
176
+		{
177
+			$where[] = "(range_end IS NULL OR range_end>".(int)$start.")";
178
+		}
179
+		if ($_where)
180
+		{
181
+			$where = array_merge($where, $_where);
182
+		}
167 183
 
168 184
 		$sql = "(SELECT * FROM $this->cal_table WHERE ".$this->db->expression($this->cal_table, $where).") $this->cal_table";
169 185
 
@@ -184,16 +200,32 @@  discard block
 block discarded – undo
184 200
 	 */
185 201
 	protected function dates_range_view($start, $end, array $_where=null, $deleted=false)
186 202
 	{
187
-		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end)	// using view without start- AND end-date is slower!
203
+		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end)
204
+		{
205
+			// using view without start- AND end-date is slower!
188 206
 		{
189
-			return $this->dates_table;	// no need / use for a view
207
+			return $this->dates_table;
208
+		}
209
+		// no need / use for a view
190 210
 		}
191 211
 
192 212
 		$where = array();
193
-		if (isset($deleted)) $where['recur_exception'] = $deleted;
194
-		if ($end) $where[] = "cal_start<".(int)$end;
195
-		if ($start) $where[] = "cal_end>".(int)$start;
196
-		if ($_where) $where = array_merge($where, $_where);
213
+		if (isset($deleted))
214
+		{
215
+			$where['recur_exception'] = $deleted;
216
+		}
217
+		if ($end)
218
+		{
219
+			$where[] = "cal_start<".(int)$end;
220
+		}
221
+		if ($start)
222
+		{
223
+			$where[] = "cal_end>".(int)$start;
224
+		}
225
+		if ($_where)
226
+		{
227
+			$where = array_merge($where, $_where);
228
+		}
197 229
 
198 230
 		// Api\Db::union uses Api\Db::select which check if join contains "WHERE"
199 231
 		// to support old join syntax like ", other_table WHERE ...",
@@ -243,7 +275,10 @@  discard block
 block discarded – undo
243 275
 			throw new Api\Exception\AssertionFailed("Unsupported value for parameters!");
244 276
 		}
245 277
 		$where = is_array($params['query']) ? $params['query'] : array();
246
-		if ($cat_id) $where[] = $this->cat_filter($cat_id);
278
+		if ($cat_id)
279
+		{
280
+			$where[] = $this->cat_filter($cat_id);
281
+		}
247 282
 		$egw_cal = $this->cal_range_view($start, $end, $where, $filter == 'everything' ? null : $filter != 'deleted');
248 283
 
249 284
 		$status_filter = $this->status_filter($filter, $params['enum_recuring']);
@@ -264,7 +299,10 @@  discard block
 block discarded – undo
264 299
 		if ($users)
265 300
 		{
266 301
 			// fix $users to also prefix system users and groups (with 'u')
267
-			if (!is_array($users)) $users = $users ? (array)$users : array();
302
+			if (!is_array($users))
303
+			{
304
+				$users = $users ? (array)$users : array();
305
+			}
268 306
 			foreach($users as &$uid)
269 307
 			{
270 308
 				$user_type = $user_id = null;
@@ -284,15 +322,22 @@  discard block
 block discarded – undo
284 322
 			$sql .= " AND\n	".$params['sql_filter'];
285 323
 		}
286 324
 
287
-		if ($params['order'])	// only order if requested
325
+		if ($params['order'])
288 326
 		{
289
-			if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
327
+			// only order if requested
328
+		{
329
+			if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';
330
+		}
331
+		// gard against SQL injection
290 332
 			$sql .= "\nORDER BY ".$params['order'];
291 333
 		}
292 334
 
293
-		if ($offset === false)	// return all rows --> Api\Db::query wants offset=0, num_rows=-1
335
+		if ($offset === false)
336
+		{
337
+			// return all rows --> Api\Db::query wants offset=0, num_rows=-1
294 338
 		{
295 339
 			$offset = 0;
340
+		}
296 341
 			$num_rows = -1;
297 342
 		}
298 343
 		$events =& $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows));
@@ -318,26 +363,35 @@  discard block
 block discarded – undo
318 363
 		$join = "LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id";
319 364
 
320 365
 		$where = array();
321
-		if (is_scalar($ids) && !is_numeric($ids))	// a single uid
366
+		if (is_scalar($ids) && !is_numeric($ids))
367
+		{
368
+			// a single uid
322 369
 		{
323 370
 			// We want only the parents to match
324 371
 			$where['cal_uid'] = $ids;
372
+		}
325 373
 			$where['cal_reference'] = 0;
326 374
 		}
327
-		elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids))	// one or more cal_id's
375
+		elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids))
376
+		{
377
+			// one or more cal_id's
328 378
 		{
329 379
 			$where['cal_id'] = $ids;
330 380
 		}
381
+		}
331 382
 		else	// array with column => value pairs
332 383
 		{
333 384
 			$where = $ids;
334 385
 			unset($ids);	// otherwise users get not read!
335 386
 		}
336
-		if (isset($where['cal_id']))	// prevent non-unique column-name cal_id
387
+		if (isset($where['cal_id']))
388
+		{
389
+			// prevent non-unique column-name cal_id
337 390
 		{
338 391
 			$where[] = $this->db->expression($this->cal_table, $this->cal_table.'.',array(
339 392
 				'cal_id' => $where['cal_id'],
340 393
 			));
394
+		}
341 395
 			unset($where['cal_id']);
342 396
 		}
343 397
 		if ((int) $recur_date)
@@ -387,10 +441,16 @@  discard block
 block discarded – undo
387 441
 			$row['recur_exception'] = $row['alarm'] = array();
388 442
 			$events[$row['cal_id']] = Api\Db::strip_array_keys($row,'cal_');
389 443
 		}
390
-		if (!$events) return $events;
444
+		if (!$events)
445
+		{
446
+			return $events;
447
+		}
391 448
 
392 449
 		$ids = array_keys($events);
393
-		if (count($ids) == 1) $ids = $ids[0];
450
+		if (count($ids) == 1)
451
+		{
452
+			$ids = $ids[0];
453
+		}
394 454
 
395 455
 		foreach ($events as &$event)
396 456
 		{
@@ -464,10 +524,13 @@  discard block
 block discarded – undo
464 524
 			'cal_id'      => $ids,
465 525
 			'cal_recur_date' => $recur_date,
466 526
 			"cal_status NOT IN ('X','E')",
467
-		),__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
527
+		),__LINE__,__FILE__,false,'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT,'calendar') as $row)
528
+		{
529
+			// DESC puts users before resources and contacts
468 530
 		{
469 531
 			// combine all participant data in uid and status values
470 532
 			$uid    = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
533
+		}
471 534
 			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
472 535
 
473 536
 			$events[$row['cal_id']]['participants'][$uid] = $status;
@@ -524,7 +587,10 @@  discard block
 block discarded – undo
524 587
 			$last_request = time();
525 588
 		}
526 589
 		$signature = serialize(func_get_args());
527
-		if (isset($ctags[$signature])) return $ctags[$signature];
590
+		if (isset($ctags[$signature]))
591
+		{
592
+			return $ctags[$signature];
593
+		}
528 594
 
529 595
 		$types = array();
530 596
 		foreach((array)$users as $uid)
@@ -557,7 +623,10 @@  discard block
 block discarded – undo
557 623
 			// owner can only by users, no groups or resources
558 624
 			foreach($users as $key => $user)
559 625
 			{
560
-				if (!($user > 0)) unset($users[$key]);
626
+				if (!($user > 0))
627
+				{
628
+					unset($users[$key]);
629
+				}
561 630
 			}
562 631
 			$where = $this->db->expression($this->user_table, '(', $where, ' OR ').
563 632
 				$this->db->expression($this->cal_table, array(
@@ -579,7 +648,10 @@  discard block
 block discarded – undo
579 648
 	 */
580 649
 	function get_cal_data(array $query, $cols='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified')
581 650
 	{
582
-		if (!is_array($cols)) $cols = explode(',', $cols);
651
+		if (!is_array($cols))
652
+		{
653
+			$cols = explode(',', $cols);
654
+		}
583 655
 
584 656
 		// special handling of cal_user_modified "pseudo" column
585 657
 		if (($key = array_search('cal_user_modified', $cols)) !== false)
@@ -604,7 +676,10 @@  discard block
 block discarded – undo
604 676
 		{
605 677
 			$cats = $GLOBALS['egw']->categories->return_all_children($cat_id);
606 678
 			array_walk($cats,create_function('&$val,$key','$val = (int) $val;'));
607
-			if (is_array($cat_id) && count($cat_id)==1) $cat_id = $cat_id[0];
679
+			if (is_array($cat_id) && count($cat_id)==1)
680
+			{
681
+				$cat_id = $cat_id[0];
682
+			}
608 683
 			$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '='.$this->db->quote((int)$cat_id));
609 684
 			foreach($cats as $cat)
610 685
 			{
@@ -663,10 +738,13 @@  discard block
 block discarded – undo
663 738
 				$where[] = "$this->user_table.cal_status NOT IN ('X','E')";
664 739
 				break;
665 740
 			default:
666
-				if ($enum_recuring)	// regular UI
741
+				if ($enum_recuring)
742
+				{
743
+					// regular UI
667 744
 				{
668 745
 					$where[] = "$this->user_table.cal_status NOT IN ('R','X','E')";
669 746
 				}
747
+				}
670 748
 				else	// CalDAV / eSync / iCal need to include 'E' = exceptions
671 749
 				{
672 750
 					$where[] = "$this->user_table.cal_status NOT IN ('R','X')";
@@ -798,7 +876,10 @@  discard block
 block discarded – undo
798 876
 						$user_ids = array();
799 877
 						foreach($ids as $user_id)
800 878
 						{
801
-							if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u') $user_ids[] = $user_id;
879
+							if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u')
880
+							{
881
+								$user_ids[] = $user_id;
882
+							}
802 883
 						}
803 884
 						$owner_or = $this->db->expression($cal_table_def,array('cal_owner' => $user_ids));
804 885
 					}
@@ -818,7 +899,10 @@  discard block
 block discarded – undo
818 899
 				}
819 900
 			}
820 901
 			// this is only used, when we cannot use UNIONS
821
-			if (!$useUnionQuery) $where[] = '('.implode(' OR ',$to_or).')';
902
+			if (!$useUnionQuery)
903
+			{
904
+				$where[] = '('.implode(' OR ',$to_or).')';
905
+			}
822 906
 
823 907
 			$where = $this->status_filter($filter, $params['enum_recuring'], $where);
824 908
 		}
@@ -837,7 +921,11 @@  discard block
 block discarded – undo
837 921
 				$where[] = '('.((int)$start).' < range_end OR range_end IS NULL)';
838 922
 			}
839 923
 		}
840
-		if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
924
+		if (!preg_match('/^[a-z_ ,c]+$/i',$params['order']))
925
+		{
926
+			$params['order'] = 'cal_start';
927
+		}
928
+		// gard against SQL injection
841 929
 
842 930
 		// if not enum recuring events, we have to use minimum start- AND end-dates, otherwise we get more then one event per cal_id!
843 931
 		if (!$params['enum_recuring'])
@@ -847,9 +935,15 @@  discard block
 block discarded – undo
847 935
 			// in case cal_start is used in a query, eg. calendar_ical::find_event
848 936
 			$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);
849 937
 			$params['order'] = str_replace('cal_start', 'range_start', $params['order']);
850
-			if ($end) $where[] = (int)$end.' > range_start';
938
+			if ($end)
939
+			{
940
+				$where[] = (int)$end.' > range_start';
941
+			}
851 942
   		}
852
-		elseif ($end) $where[] = (int)$end.' > cal_start';
943
+  		elseif ($end)
944
+		{
945
+			$where[] = (int)$end.' > cal_start';
946
+		}
853 947
 
854 948
 		if ($remove_rejected_by_user && $filter != 'everything')
855 949
 		{
@@ -863,7 +957,10 @@  discard block
 block discarded – undo
863 957
 				'rejected_by_user.cal_status IS NULL',
864 958
 				"rejected_by_user.cal_status NOT IN ('R','X')",
865 959
 			);
866
-			if ($filter == 'owner') $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user;
960
+			if ($filter == 'owner')
961
+			{
962
+				$or_required[] = 'cal_owner='.(int)$remove_rejected_by_user;
963
+			}
867 964
 			$where[] = '('.implode(' OR ',$or_required).')';
868 965
 		}
869 966
 		// using a time-range and deleted attribute limited view instead of full table
@@ -885,7 +982,10 @@  discard block
 block discarded – undo
885 982
 		if ($useUnionQuery)
886 983
 		{
887 984
 			// allow apps to supply participants and/or icons
888
-			if (!isset($params['cols'])) $cols .= ',NULL AS participants,NULL AS icons';
985
+			if (!isset($params['cols']))
986
+			{
987
+				$cols .= ',NULL AS participants,NULL AS icons';
988
+			}
889 989
 
890 990
 			// changed the original OR in the query into a union, to speed up the query execution under MySQL 5
891 991
 			// with time-range views benefit is now at best slim for huge tables or none at all!
@@ -940,9 +1040,12 @@  discard block
 block discarded – undo
940 1040
 					$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
941 1041
 				}
942 1042
 			}
943
-			if (is_numeric($offset) && !$params['no_total'])	// get the total too
1043
+			if (is_numeric($offset) && !$params['no_total'])
1044
+			{
1045
+				// get the total too
944 1046
 			{
945 1047
 				$save_selects = $selects;
1048
+			}
946 1049
 				// 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)
947 1050
 				foreach(array_keys($selects) as $key)
948 1051
 				{
@@ -953,14 +1056,20 @@  discard block
 block discarded – undo
953 1056
 							array('range_start AS cal_start','range_end AS cal_end'), $selects[$key]['cols']);
954 1057
 					}
955 1058
 				}
956
-				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1059
+				if (!isset($params['cols']) && !$params['no_integration'])
1060
+				{
1061
+					self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1062
+				}
957 1063
 
958 1064
 				$this->total = $this->db->union($selects,__LINE__,__FILE__)->NumRows();
959 1065
 
960 1066
 				// restore original cols / selects
961 1067
 				$selects = $save_selects; unset($save_selects);
962 1068
 			}
963
-			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1069
+			if (!isset($params['cols']) && !$params['no_integration'])
1070
+			{
1071
+				self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1072
+			}
964 1073
 
965 1074
 			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
966 1075
 		}
@@ -978,9 +1087,12 @@  discard block
 block discarded – undo
978 1087
 				'table_def' => $cal_table_def,
979 1088
 			));
980 1089
 
981
-			if (is_numeric($offset) && !$params['no_total'])	// get the total too
1090
+			if (is_numeric($offset) && !$params['no_total'])
1091
+			{
1092
+				// get the total too
982 1093
 			{
983 1094
 				$save_selects = $selects;
1095
+			}
984 1096
 				// 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)
985 1097
 				$selects[0]['cols'] = "$this->cal_table.cal_id,cal_start";
986 1098
 				if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
@@ -1008,7 +1120,10 @@  discard block
 block discarded – undo
1008 1120
 		foreach($rs as $row)
1009 1121
 		{
1010 1122
 			$id = $row['cal_id'];
1011
-			if (is_numeric($id)) $ids[] = $id;
1123
+			if (is_numeric($id))
1124
+			{
1125
+				$ids[] = $id;
1126
+			}
1012 1127
 
1013 1128
 			if ($row['cal_recur_date'])
1014 1129
 			{
@@ -1028,7 +1143,10 @@  discard block
 block discarded – undo
1028 1143
 			$row['recur_exception'] = $row['alarm'] = array();
1029 1144
 
1030 1145
 			// compile a list of recurrences per cal_id
1031
-			if (!in_array($id,(array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1146
+			if (!in_array($id,(array)$recur_ids[$row['cal_id']]))
1147
+			{
1148
+				$recur_ids[$row['cal_id']][] = $id;
1149
+			}
1032 1150
 
1033 1151
 			$events[$id] = Api\Db::strip_array_keys($row,'cal_');
1034 1152
 		}
@@ -1047,10 +1165,16 @@  discard block
 block discarded – undo
1047 1165
 					//'cal_id' => array_unique($ids),
1048 1166
 					'cal_recur_date' => $recur_dates,
1049 1167
 				),__LINE__,__FILE__,false,'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT,'calendar',$num_rows,$join='',
1050
-				$this->db->get_table_definitions('calendar',$this->user_table)) as $row)	// DESC puts users before resources and contacts
1168
+				$this->db->get_table_definitions('calendar',$this->user_table)) as $row)
1169
+			{
1170
+				// DESC puts users before resources and contacts
1051 1171
 			{
1052 1172
 				$id = $row['cal_id'];
1053
-				if ($row['cal_recur_date']) $id .= '-'.$row['cal_recur_date'];
1173
+			}
1174
+				if ($row['cal_recur_date'])
1175
+				{
1176
+					$id .= '-'.$row['cal_recur_date'];
1177
+				}
1054 1178
 
1055 1179
 				// combine all participant data in uid and status values
1056 1180
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
@@ -1069,7 +1193,10 @@  discard block
 block discarded – undo
1069 1193
 				}
1070 1194
 
1071 1195
 				// set data, if recurrence is requested
1072
-				if (isset($events[$id])) $events[$id]['participants'][$uid] = $status;
1196
+				if (isset($events[$id]))
1197
+				{
1198
+					$events[$id]['participants'][$uid] = $status;
1199
+				}
1073 1200
 			}
1074 1201
 			// query recurrance exceptions, if needed: enum_recuring && !daywise is used in calendar_groupdav::get_series($uid,...)
1075 1202
 			if (!$params['enum_recuring'] || !$params['daywise'])
@@ -1085,7 +1212,10 @@  discard block
 block discarded – undo
1085 1212
 					{
1086 1213
 						foreach($events as $id => $event)
1087 1214
 						{
1088
-							if ($event['id'] == $row['cal_id']) break;
1215
+							if ($event['id'] == $row['cal_id'])
1216
+							{
1217
+								break;
1218
+							}
1089 1219
 						}
1090 1220
 					}
1091 1221
 					$events[$id]['recur_exception'][] = $row['cal_start'];
@@ -1095,7 +1225,10 @@  discard block
 block discarded – undo
1095 1225
 			if (!is_null($params['cfs']))
1096 1226
 			{
1097 1227
 				$where = array('cal_id' => $ids);
1098
-				if ($params['cfs']) $where['cal_extra_name'] = $params['cfs'];
1228
+				if ($params['cfs'])
1229
+				{
1230
+					$where['cal_extra_name'] = $params['cfs'];
1231
+				}
1099 1232
 				foreach($this->db->select($this->extra_table,'*',$where,
1100 1233
 					__LINE__,__FILE__,false,'','calendar') as $row)
1101 1234
 				{
@@ -1115,14 +1248,20 @@  discard block
 block discarded – undo
1115 1248
 				{
1116 1249
 					$event_start = $alarm['time'] + $alarm['offset'];
1117 1250
 
1118
-					if (isset($events[$cal_id]))	// none recuring event
1251
+					if (isset($events[$cal_id]))
1252
+					{
1253
+						// none recuring event
1119 1254
 					{
1120 1255
 						$events[$cal_id]['alarm'][$id] = $alarm;
1121 1256
 					}
1122
-					elseif (isset($events[$cal_id.'-'.$event_start]))	// recuring event
1257
+					}
1258
+					elseif (isset($events[$cal_id.'-'.$event_start]))
1259
+					{
1260
+						// recuring event
1123 1261
 					{
1124 1262
 						$events[$cal_id.'-'.$event_start]['alarm'][$id] = $alarm;
1125 1263
 					}
1264
+					}
1126 1265
 				}
1127 1266
 			}
1128 1267
 		}
@@ -1222,10 +1361,13 @@  discard block
 block discarded – undo
1222 1361
 			}
1223 1362
 			foreach((array)$cols as $col)
1224 1363
 			{
1225
-				if (substr($col,0,7) == 'egw_cal')	// remove table name
1364
+				if (substr($col,0,7) == 'egw_cal')
1365
+				{
1366
+					// remove table name
1226 1367
 				{
1227 1368
 					$col = preg_replace('/^egw_cal[a-z_]*\./','',$col);
1228 1369
 				}
1370
+				}
1229 1371
 				if (isset($app_cols[$col]))
1230 1372
 				{
1231 1373
 					$return_cols[] = $app_cols[$col];
@@ -1319,7 +1461,11 @@  discard block
 block discarded – undo
1319 1461
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
1320 1462
 		{
1321 1463
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
1322
-			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!
1464
+			if (empty($minimum_uid_length) || $minimum_uid_length<=1)
1465
+			{
1466
+				$minimum_uid_length = 8;
1467
+			}
1468
+			// we just do not accept no uid, or uid way to short!
1323 1469
 		}
1324 1470
 		else
1325 1471
 		{
@@ -1367,7 +1513,10 @@  discard block
 block discarded – undo
1367 1513
 			}
1368 1514
 		}
1369 1515
 		// set range_start/_end, but only if we have cal_start/_end, as otherwise we destroy present values!
1370
-		if (isset($event['cal_start'])) $event['range_start'] = $event['cal_start'];
1516
+		if (isset($event['cal_start']))
1517
+		{
1518
+			$event['range_start'] = $event['cal_start'];
1519
+		}
1371 1520
 		if (isset($event['cal_end']))
1372 1521
 		{
1373 1522
 			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] :
@@ -1388,7 +1537,10 @@  discard block
 block discarded – undo
1388 1537
 		$event['cal_category'] = implode(',',$categories);
1389 1538
 
1390 1539
 		// make sure recurring events never reference to an other recurrent event
1391
-		if ($event['recur_type'] != MCAL_RECUR_NONE) $event['cal_reference'] = 0;
1540
+		if ($event['recur_type'] != MCAL_RECUR_NONE)
1541
+		{
1542
+			$event['cal_reference'] = 0;
1543
+		}
1392 1544
 
1393 1545
 		if ($cal_id)
1394 1546
 		{
@@ -1405,7 +1557,10 @@  discard block
 block discarded – undo
1405 1557
 			{
1406 1558
 				$old_tz_id = $this->db->select($this->cal_table,'tz_id',$where,__LINE__,__FILE__,'calendar')->fetchColumn();
1407 1559
 			}
1408
-			if (!is_null($etag)) $where['cal_etag'] = $etag;
1560
+			if (!is_null($etag))
1561
+			{
1562
+				$where['cal_etag'] = $etag;
1563
+			}
1409 1564
 
1410 1565
 			unset($event['cal_etag']);
1411 1566
 			$event[] = 'cal_etag=cal_etag+1';	// always update the etag, even if none given to check
@@ -1416,14 +1571,24 @@  discard block
 block discarded – undo
1416 1571
 			{
1417 1572
 				return 0;	// wrong etag, someone else updated the entry
1418 1573
 			}
1419
-			if (!is_null($etag)) ++$etag;
1574
+			if (!is_null($etag))
1575
+			{
1576
+				++$etag;
1577
+			}
1420 1578
 		}
1421 1579
 		else
1422 1580
 		{
1423 1581
 			// new event
1424
-			if (!$event['cal_owner']) $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id'];
1582
+			if (!$event['cal_owner'])
1583
+			{
1584
+				$event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id'];
1585
+			}
1425 1586
 
1426
-			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = '';	// uid is NOT NULL!
1587
+			if (!$event['cal_id'] && !isset($event['cal_uid']))
1588
+			{
1589
+				$event['cal_uid'] = '';
1590
+			}
1591
+			// uid is NOT NULL!
1427 1592
 
1428 1593
 			$this->db->insert($this->cal_table,$event,false,__LINE__,__FILE__,'calendar');
1429 1594
 			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table,'cal_id')))
@@ -1575,8 +1740,7 @@  discard block
 block discarded – undo
1575 1740
 					// recurrences need to be truncated
1576 1741
 					if((int)$event['recur_enddate'] > 0 &&
1577 1742
 						((int)$old_repeats['recur_enddate'] == 0 || (int)$old_repeats['recur_enddate'] > (int)$event['recur_enddate'])
1578
-					)
1579
-					{
1743
+					) {
1580 1744
 						$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1581 1745
 						$this->db->delete($this->dates_table,array('cal_id' => $cal_id,'cal_start >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1582 1746
 					}
@@ -1584,8 +1748,7 @@  discard block
 block discarded – undo
1584 1748
 					// recurrences need to be expanded
1585 1749
 					if(((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1586 1750
 						|| ((int)$event['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] < (int)$event['recur_enddate'])
1587
-					)
1588
-					{
1751
+					) {
1589 1752
 						$set_recurrences = true;
1590 1753
 						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1*DAY_s);
1591 1754
 					}
@@ -1732,12 +1895,18 @@  discard block
 block discarded – undo
1732 1895
 	{
1733 1896
 		//echo "<p>socal::move($cal_id,$start,$end,$change_since,$old_start,$old_end)</p>\n";
1734 1897
 
1735
-		if (!(int) $cal_id) return false;
1898
+		if (!(int) $cal_id)
1899
+		{
1900
+			return false;
1901
+		}
1736 1902
 
1737 1903
 		if (!$old_start)
1738 1904
 		{
1739
-			if ($change_since !== false) $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1905
+			if ($change_since !== false)
1906
+			{
1907
+				$row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1740 1908
 				array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetch();
1909
+			}
1741 1910
 			// if no recurrence found, create one with the new dates
1742 1911
 			if ($change_since === false || !$row || !$row['cal_start'] || !$row['cal_end'])
1743 1912
 			{
@@ -1839,7 +2008,10 @@  discard block
 block discarded – undo
1839 2008
 			$user_type = $uid[0];
1840 2009
 			$email = substr($uid, 1);
1841 2010
 			$matches = null;
1842
-			if (preg_match('/<([^<>]+)>$/', $email, $matches)) $email = $matches[1];
2011
+			if (preg_match('/<([^<>]+)>$/', $email, $matches))
2012
+			{
2013
+				$email = $matches[1];
2014
+			}
1843 2015
 			$user_id = md5(trim(strtolower($email)));
1844 2016
 		}
1845 2017
 		else
@@ -1859,8 +2031,14 @@  discard block
 block discarded – undo
1859 2031
 	 */
1860 2032
 	static function combine_status($status,$quantity=1,$role='REQ-PARTICIPANT')
1861 2033
 	{
1862
-		if ((int)$quantity > 1) $status .= (int)$quantity;
1863
-		if ($role != 'REQ-PARTICIPANT') $status .= $role;
2034
+		if ((int)$quantity > 1)
2035
+		{
2036
+			$status .= (int)$quantity;
2037
+		}
2038
+		if ($role != 'REQ-PARTICIPANT')
2039
+		{
2040
+			$status .= $role;
2041
+		}
1864 2042
 
1865 2043
 		return $status;
1866 2044
 	}
@@ -1881,8 +2059,14 @@  discard block
 block discarded – undo
1881 2059
 		$matches = null;
1882 2060
 		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/',$status,$matches))
1883 2061
 		{
1884
-			if ((int)$matches[1] > 0) $quantity = (int)$matches[1];
1885
-			if ($matches[2]) $role = $matches[2];
2062
+			if ((int)$matches[1] > 0)
2063
+			{
2064
+				$quantity = (int)$matches[1];
2065
+			}
2066
+			if ($matches[2])
2067
+			{
2068
+				$role = $matches[2];
2069
+			}
1886 2070
 			$status = $status[0];
1887 2071
 		}
1888 2072
 		elseif ($status === true)
@@ -1993,9 +2177,13 @@  discard block
 block discarded – undo
1993 2177
 			}
1994 2178
 		}
1995 2179
 
1996
-		if (count($participants))	// participants which need to be added
2180
+		if (count($participants))
2181
+		{
2182
+			// participants which need to be added
1997 2183
 		{
1998
-			if (!count($recurrences)) $recurrences[] = 0;   // insert the default recurrence
2184
+			if (!count($recurrences)) $recurrences[] = 0;
2185
+		}
2186
+		// insert the default recurrence
1999 2187
 
2000 2188
 			$delete_deleted = array();
2001 2189
 
@@ -2067,7 +2255,10 @@  discard block
 block discarded – undo
2067 2255
 			return false;
2068 2256
 		}
2069 2257
 
2070
-		if (is_numeric($status)) $status = $status_code_short[$status];
2258
+		if (is_numeric($status))
2259
+		{
2260
+			$status = $status_code_short[$status];
2261
+		}
2071 2262
 
2072 2263
 		$uid = self::combine_user($user_type, $user_id);
2073 2264
 		$user_id_md5 = null;
@@ -2087,16 +2278,25 @@  discard block
 block discarded – undo
2087 2278
 			$where[] = '(cal_recur_date=0 OR cal_recur_date >= '.time().')';
2088 2279
 		}
2089 2280
 
2090
-		if ($status == 'G')		// remove group invitations, as we dont store them in the db
2281
+		if ($status == 'G')
2282
+		{
2283
+			// remove group invitations, as we dont store them in the db
2091 2284
 		{
2092 2285
 			$this->db->delete($this->user_table,$where,__LINE__,__FILE__,'calendar');
2286
+		}
2093 2287
 			$ret = $this->db->affected_rows();
2094 2288
 		}
2095 2289
 		else
2096 2290
 		{
2097 2291
 			$set = array('cal_status' => $status);
2098
-			if ($user_type == 'e' || $attendee) $set['cal_user_attendee'] = $attendee ? $attendee : $user_id;
2099
-			if (!is_null($role) && $role != 'REQ-PARTICIPANT') $set['cal_role'] = $role;
2292
+			if ($user_type == 'e' || $attendee)
2293
+			{
2294
+				$set['cal_user_attendee'] = $attendee ? $attendee : $user_id;
2295
+			}
2296
+			if (!is_null($role) && $role != 'REQ-PARTICIPANT')
2297
+			{
2298
+				$set['cal_role'] = $role;
2299
+			}
2100 2300
 			$this->db->insert($this->user_table,$set,$where,__LINE__,__FILE__,'calendar');
2101 2301
 			// for new or changed group-invitations, remove previously deleted members, so they show up again
2102 2302
 			if (($ret = $this->db->affected_rows()) && $user_type == 'u' && $user_id < 0)
@@ -2129,7 +2329,10 @@  discard block
 block discarded – undo
2129 2329
 	{
2130 2330
 		//error_log(__METHOD__."($cal_id, $start, $end, ".array2string($participants).", ".array2string($exception));
2131 2331
 		$update = array('cal_end' => $end);
2132
-		if (isset($exception)) $update['recur_exception'] = $exception;
2332
+		if (isset($exception))
2333
+		{
2334
+			$update['recur_exception'] = $exception;
2335
+		}
2133 2336
 
2134 2337
 		$this->db->insert($this->dates_table, $update, array(
2135 2338
 			'cal_id' => $cal_id,
@@ -2144,7 +2347,11 @@  discard block
 block discarded – undo
2144 2347
 		{
2145 2348
 			foreach($participants as $uid => $status)
2146 2349
 			{
2147
-				if ($status == 'G') continue;	// dont save group-invitations
2350
+				if ($status == 'G')
2351
+				{
2352
+					continue;
2353
+				}
2354
+				// dont save group-invitations
2148 2355
 
2149 2356
 				$type = '';
2150 2357
 				$id = null;
@@ -2373,7 +2580,10 @@  discard block
 block discarded – undo
2373 2580
 		}
2374 2581
 		$alarm['cal_id'] = $cal_id;		// we need the back-reference
2375 2582
 		// add an alarm uid, if none is given
2376
-		if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) $alarm['uid'] = (string)new Horde_Support_Uuid;
2583
+		if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid'))
2584
+		{
2585
+			$alarm['uid'] = (string)new Horde_Support_Uuid;
2586
+		}
2377 2587
 		//error_log(__METHOD__.__LINE__.' Save Alarm for CalID:'.$cal_id.'->'.array2string($alarm).'-->'.$id.'#'.function_backtrace());
2378 2588
 		// allways store job with the alarm owner as job-owner to get eg. the correct from address
2379 2589
 		if (!$this->async->set_timer($alarm['time'],$id,'calendar.calendar_boupdate.send_alarm',$alarm,$alarm['owner']))
@@ -2382,10 +2592,16 @@  discard block
 block discarded – undo
2382 2592
 		}
2383 2593
 
2384 2594
 		// update the modification information of the related event
2385
-		if ($update_modified) $this->updateModified($cal_id, true);
2595
+		if ($update_modified)
2596
+		{
2597
+			$this->updateModified($cal_id, true);
2598
+		}
2386 2599
 
2387 2600
 		// update cache, if used
2388
-		if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, true);
2601
+		if (isset(self::$alarm_cache))
2602
+		{
2603
+			$this->read_alarms($cal_id, true);
2604
+		}
2389 2605
 
2390 2606
 		return $id;
2391 2607
 	}
@@ -2408,7 +2624,10 @@  discard block
 block discarded – undo
2408 2624
 				$this->async->cancel_timer($id);
2409 2625
 			}
2410 2626
 			// update cache, if used
2411
-			if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, false);
2627
+			if (isset(self::$alarm_cache))
2628
+			{
2629
+				$this->read_alarms($cal_id, false);
2630
+			}
2412 2631
 		}
2413 2632
 		return count($alarms);
2414 2633
 	}
@@ -2431,7 +2650,10 @@  discard block
 block discarded – undo
2431 2650
 		$ret = $this->async->cancel_timer($id);
2432 2651
 
2433 2652
 		// update cache, if used
2434
-		if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, true);
2653
+		if (isset(self::$alarm_cache))
2654
+		{
2655
+			$this->read_alarms($cal_id, true);
2656
+		}
2435 2657
 
2436 2658
 		return $ret;
2437 2659
 	}
@@ -2455,11 +2677,14 @@  discard block
 block discarded – undo
2455 2677
 			$user_id = null;
2456 2678
 			self::split_user($old_user,$user_type,$user_id);
2457 2679
 
2458
-			if ($user_type == 'u')	// only accounts can be owners of events
2680
+			if ($user_type == 'u')
2681
+			{
2682
+				// only accounts can be owners of events
2459 2683
 			{
2460 2684
 				foreach($this->db->select($this->cal_table,'cal_id',array('cal_owner' => $old_user),__LINE__,__FILE__,false,'','calendar') as $row)
2461 2685
 				{
2462 2686
 					$this->delete($row['cal_id']);
2687
+			}
2463 2688
 				}
2464 2689
 			}
2465 2690
 			$this->db->delete($this->user_table,array(
@@ -2487,11 +2712,14 @@  discard block
 block discarded – undo
2487 2712
 			{
2488 2713
 				$ids[] = $row['cal_id'];
2489 2714
 			}
2490
-			if ($ids) $this->db->delete($this->user_table,array(
2715
+			if ($ids)
2716
+			{
2717
+				$this->db->delete($this->user_table,array(
2491 2718
 				'cal_user_type' => 'u',
2492 2719
 				'cal_user_id' => $old_user,
2493 2720
 				'cal_id' => $ids,
2494 2721
 			),__LINE__,__FILE__,'calendar');
2722
+			}
2495 2723
 			// now change participant in the rest to contain new user instead of old user
2496 2724
 			$this->db->update($this->user_table,array(
2497 2725
 				'cal_user_id' => $new_user,
@@ -2516,8 +2744,14 @@  discard block
 block discarded – undo
2516 2744
 	{
2517 2745
 		$participant_status = array();
2518 2746
 		$where = array('cal_id' => $cal_id);
2519
-		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2520
-		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2747
+		if ($start != 0 && $end == 0)
2748
+		{
2749
+			$where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2750
+		}
2751
+		if ($start == 0 && $end != 0)
2752
+		{
2753
+			$where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2754
+		}
2521 2755
 		if ($start != 0 && $end != 0)
2522 2756
 		{
2523 2757
 			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
@@ -2528,7 +2762,10 @@  discard block
 block discarded – undo
2528 2762
 			// inititalize the array
2529 2763
 			$participant_status[$row['cal_recur_date']] = null;
2530 2764
 		}
2531
-		if (is_null($uid)) return $participant_status;
2765
+		if (is_null($uid))
2766
+		{
2767
+			return $participant_status;
2768
+		}
2532 2769
 		$user_type = $user_id = null;
2533 2770
 		self::split_user($uid, $user_type, $user_id, true);
2534 2771
 
@@ -2537,8 +2774,14 @@  discard block
 block discarded – undo
2537 2774
 			'cal_user_type'	=> $user_type ? $user_type : 'u',
2538 2775
 			'cal_user_id'   => $user_id,
2539 2776
 		);
2540
-		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2541
-		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2777
+		if ($start != 0 && $end == 0)
2778
+		{
2779
+			$where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2780
+		}
2781
+		if ($start == 0 && $end != 0)
2782
+		{
2783
+			$where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2784
+		}
2542 2785
 		if ($start != 0 && $end != 0)
2543 2786
 		{
2544 2787
 			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
@@ -2628,17 +2871,26 @@  discard block
 block discarded – undo
2628 2871
 	 */
2629 2872
 	function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all')
2630 2873
 	{
2631
-		if (!is_array($event)) return false;
2874
+		if (!is_array($event))
2875
+		{
2876
+			return false;
2877
+		}
2632 2878
 		$cal_id = (int) $event['id'];
2633 2879
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2634 2880
 		//		"($cal_id, $tz_id, $filter): " . $event['tzid']);
2635
-		if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false;
2881
+		if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE)
2882
+		{
2883
+			return false;
2884
+		}
2636 2885
 
2637 2886
 		$days = array();
2638 2887
 
2639 2888
 		$expand_all = (!$this->isWholeDay($event) && $tz_id && $tz_id != $event['tzid']);
2640 2889
 
2641
-		if ($filter == 'tz_only' && !$expand_all) return $days;
2890
+		if ($filter == 'tz_only' && !$expand_all)
2891
+		{
2892
+			return $days;
2893
+		}
2642 2894
 
2643 2895
 		$remote = in_array($filter, array('tz_rrule', 'rrule'));
2644 2896
 
@@ -2681,7 +2933,10 @@  discard block
 block discarded – undo
2681 2933
 					$remote_rrule->next_no_exception();
2682 2934
 				}
2683 2935
 				$egw_rrule->next_no_exception();
2684
-				if (!$egw_rrule->valid()) return $days;
2936
+				if (!$egw_rrule->valid())
2937
+				{
2938
+					return $days;
2939
+				}
2685 2940
 			}
2686 2941
 			$day = $egw_rrule->current();
2687 2942
 			$locts = (int)Api\DateTime::to($day,'server');
@@ -2835,7 +3090,11 @@  discard block
 block discarded – undo
2835 3090
 			}
2836 3091
 		}
2837 3092
 
2838
-		if (empty($participants)) return false; // occurrence does not exist at all yet
3093
+		if (empty($participants))
3094
+		{
3095
+			return false;
3096
+		}
3097
+		// occurrence does not exist at all yet
2839 3098
 
2840 3099
 		foreach ($recurrence_zero as $uid => $status)
2841 3100
 		{
@@ -2892,7 +3151,9 @@  discard block
 block discarded – undo
2892 3151
 			}
2893 3152
 			if (!isset($participants[$uid])
2894 3153
 				|| $participants[$uid] != $status)
2895
-				return true;
3154
+			{
3155
+							return true;
3156
+			}
2896 3157
 			unset($participants[$uid]);
2897 3158
 		}
2898 3159
 		return (!empty($participants));
@@ -2906,7 +3167,10 @@  discard block
 block discarded – undo
2906 3167
 	 */
2907 3168
 	function isWholeDay($event)
2908 3169
 	{
2909
-		if (!isset($event['start']) || !isset($event['end'])) return false;
3170
+		if (!isset($event['start']) || !isset($event['end']))
3171
+		{
3172
+			return false;
3173
+		}
2910 3174
 
2911 3175
 		if (empty($event['tzid']))
2912 3176
 		{
@@ -2968,8 +3232,14 @@  discard block
 block discarded – undo
2968 3232
 	 */
2969 3233
 	function updateModified($id, $update_master=false, $time=null, $modifier=null)
2970 3234
 	{
2971
-		if (is_null($time) || !$time) $time = time();
2972
-		if (is_null($modifier)) $modifier = $GLOBALS['egw_info']['user']['account_id'];
3235
+		if (is_null($time) || !$time)
3236
+		{
3237
+			$time = time();
3238
+		}
3239
+		if (is_null($modifier))
3240
+		{
3241
+			$modifier = $GLOBALS['egw_info']['user']['account_id'];
3242
+		}
2973 3243
 
2974 3244
 		$this->db->update($this->cal_table,
2975 3245
 			array('cal_modified' => $time, 'cal_modifier' => $modifier),
Please login to merge, or discard this patch.
Doc Comments   +12 added lines, -36 removed lines patch added patch discarded remove patch
@@ -211,23 +211,11 @@  discard block
 block discarded – undo
211 211
 	 * @param int $start startdate of the search/list (servertime)
212 212
 	 * @param int $end enddate of the search/list (servertime)
213 213
 	 * @param int|array $users user-id or array of user-id's, !$users means all entries regardless of users
214
-	 * @param int|array $cat_id =0 mixed category-id or array of cat-id's (incl. all sub-categories), default 0 = all
214
+	 * @param integer $cat_id =0 mixed category-id or array of cat-id's (incl. all sub-categories), default 0 = all
215 215
 	 * @param string $filter ='default' string filter-name: all (not rejected), accepted, unknown, tentative, rejected or everything (incl. rejected, deleted)
216 216
 	 * @param int|boolean $offset =False offset for a limited query or False (default)
217 217
 	 * @param int $num_rows =0 number of rows to return if offset set, default 0 = use default in user prefs
218 218
 	 * @param array $params =array()
219
-	 * @param string|array $params['query'] string: pattern so search for, if unset or empty all matching entries are returned (no search)
220
-	 *		Please Note: a search never returns repeating events more then once AND does not honor start+end date !!!
221
-	 *      array: everything is directly used as $where
222
-	 * @param string $params['order'] ='cal_start' column-names plus optional DESC|ASC separted by comma
223
-	 * @param string $params['sql_filter'] sql to be and'ed into query (fully quoted)
224
-	 * @param string|array $params['cols'] what to select, default "$this->repeats_table.*,$this->cal_table.*,cal_start,cal_end,cal_recur_date",
225
-	 * 						if specified and not false an iterator for the rows is returned
226
-	 * @param string $params['append'] SQL to append to the query before $order, eg. for a GROUP BY clause
227
-	 * @param array $params['cfs'] custom fields to query, null = none, array() = all, or array with cfs names
228
-	 * @param array $params['users'] raw parameter as passed to calendar_bo::search() no memberships resolved!
229
-	 * @param boolean $params['master_only'] =false, true only take into account participants/status from master (for AS)
230
-	 * @param boolean $params['enum_recuring'] =true enumerate recuring events
231 219
 	 * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it
232 220
 	 * @return array of events
233 221
 	 */
@@ -594,7 +582,7 @@  discard block
 block discarded – undo
594 582
 	/**
595 583
 	 * generate SQL to filter after a given category (incl. subcategories)
596 584
 	 *
597
-	 * @param array|int $cat_id cat-id or array of cat-ids, or !$cat_id for none
585
+	 * @param integer $cat_id cat-id or array of cat-ids, or !$cat_id for none
598 586
 	 * @return string SQL to include in the query
599 587
 	 */
600 588
 	function cat_filter($cat_id)
@@ -682,24 +670,11 @@  discard block
 block discarded – undo
682 670
 	 * @param int $start startdate of the search/list (servertime)
683 671
 	 * @param int $end enddate of the search/list (servertime)
684 672
 	 * @param int|array $users user-id or array of user-id's, !$users means all entries regardless of users
685
-	 * @param int|array $cat_id =0 mixed category-id or array of cat-id's (incl. all sub-categories), default 0 = all
673
+	 * @param integer $cat_id =0 mixed category-id or array of cat-id's (incl. all sub-categories), default 0 = all
686 674
 	 * @param string $filter ='all' string filter-name: all (not rejected), accepted, unknown, tentative, rejected or everything (incl. rejected, deleted)
687 675
 	 * @param int|boolean $offset =False offset for a limited query or False (default)
688 676
 	 * @param int $num_rows =0 number of rows to return if offset set, default 0 = use default in user prefs
689 677
 	 * @param array $params =array()
690
-	 * @param string|array $params['query'] string: pattern so search for, if unset or empty all matching entries are returned (no search)
691
-	 *		Please Note: a search never returns repeating events more then once AND does not honor start+end date !!!
692
-	 *      array: everything is directly used as $where
693
-	 * @param string $params['order'] ='cal_start' column-names plus optional DESC|ASC separted by comma
694
-	 * @param string|array $params['sql_filter'] sql to be and'ed into query (fully quoted), or usual filter array
695
-	 * @param string|array $params['cols'] what to select, default "$this->repeats_table.*,$this->cal_table.*,cal_start,cal_end,cal_recur_date",
696
-	 * 						if specified and not false an iterator for the rows is returned
697
-	 * @param string $params['append'] SQL to append to the query before $order, eg. for a GROUP BY clause
698
-	 * @param array $params['cfs'] custom fields to query, null = none, array() = all, or array with cfs names
699
-	 * @param array $params['users'] raw parameter as passed to calendar_bo::search() no memberships resolved!
700
-	 * @param boolean $params['master_only'] =false, true only take into account participants/status from master (for AS)
701
-	 * @param boolean $params['enum_recuring'] =true enumerate recuring events
702
-	 * @param boolean $params['use_so_events'] =false, true return result of new $this->events()
703 678
 	 * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it
704 679
 	 * @return Iterator|array of events
705 680
 	 */
@@ -1140,11 +1115,11 @@  discard block
 block discarded – undo
1140 1115
 	 * Ask other apps if they want to participate in calendar search / display
1141 1116
 	 *
1142 1117
 	 * @param &$selects parts of union query
1143
-	 * @param $start see search()
1144
-	 * @param $end
1118
+	 * @param integer $start see search()
1119
+	 * @param integer $end
1145 1120
 	 * @param $users as used in calendar_so ($users_raw plus all members and memberships added by calendar_bo)
1146
-	 * @param $cat_id
1147
-	 * @param $filter
1121
+	 * @param integer $cat_id
1122
+	 * @param string $filter
1148 1123
 	 * @param $query
1149 1124
 	 * @param $users_raw as passed to calendar_bo::search (no members and memberships added)
1150 1125
 	 */
@@ -1312,6 +1287,7 @@  discard block
 block discarded – undo
1312 1287
 	 * @param int &$set_recurrences_start=0 on return: time from which on the recurrences should be rebuilt, default 0=all
1313 1288
 	 * @param int $change_since =0 time from which on the repetitions should be changed, default 0=all
1314 1289
 	 * @param int &$etag etag=null etag to check or null, on return new etag
1290
+	 * @param boolean $set_recurrences
1315 1291
 	 * @return boolean|int false on error, 0 if etag does not match, cal_id otherwise
1316 1292
 	 */
1317 1293
 	function save($event,&$set_recurrences,&$set_recurrences_start=0,$change_since=0,&$etag=null)
@@ -1722,7 +1698,7 @@  discard block
 block discarded – undo
1722 1698
 	 * @param int $cal_id
1723 1699
 	 * @param int $start new starttime
1724 1700
 	 * @param int $end new endtime
1725
-	 * @param int|boolean $change_since =0 false=new entry, > 0 time from which on the repetitions should be changed, default 0=all
1701
+	 * @param integer $change_since =0 false=new entry, > 0 time from which on the repetitions should be changed, default 0=all
1726 1702
 	 * @param int $old_start =0 old starttime or (default) 0, to query it from the db
1727 1703
 	 * @param int $old_end =0 old starttime or (default) 0
1728 1704
 	 * @todo Recalculate recurrences, if timezone changes
@@ -1899,7 +1875,7 @@  discard block
 block discarded – undo
1899 1875
 	 *
1900 1876
 	 * @param int $cal_id
1901 1877
 	 * @param array $participants uid => status pairs
1902
-	 * @param int|boolean $change_since =0, false=new event,
1878
+	 * @param integer $change_since =0, false=new event,
1903 1879
 	 * 		0=all, > 0 time from which on the repetitions should be changed
1904 1880
 	 * @param boolean $add_only =false
1905 1881
 	 *		false = add AND delete participants if needed (full list of participants required in $participants)
@@ -2045,7 +2021,7 @@  discard block
 block discarded – undo
2045 2021
 	 * set the status of one participant for a given recurrence or for all recurrences since now (includes recur_date=0)
2046 2022
 	 *
2047 2023
 	 * @param int $cal_id
2048
-	 * @param char $user_type 'u' regular user, 'r' resource, 'c' contact
2024
+	 * @param string $user_type 'u' regular user, 'r' resource, 'c' contact
2049 2025
 	 * @param int|string $user_id
2050 2026
 	 * @param int|char $status numeric status (defines) or 1-char code: 'R', 'U', 'T' or 'A'
2051 2027
 	 * @param int $recur_date =0 date to change, or 0 = all since now
@@ -2962,7 +2938,7 @@  discard block
 block discarded – undo
2962 2938
 	 * Updates the modification timestamp to force an etag, ctag and sync-token change
2963 2939
 	 *
2964 2940
 	 * @param int $id event id
2965
-	 * @param int|boolean $update_master =false id of series master or true, to update series master too
2941
+	 * @param boolean $update_master =false id of series master or true, to update series master too
2966 2942
 	 * @param int $time =null new timestamp, default current (server-)time
2967 2943
 	 * @param int $modifier =null uid of the modifier, default current user
2968 2944
 	 */
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
 		{
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 		$cal_table = $this->cal_range_view($start, $end, null, $filter == 'everything' ? null : $filter != 'deleted');
875 875
 		$cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table);
876 876
 
877
-		$join = "JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id ".
877
+		$join = "join $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id ".
878 878
 			"LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id ".
879 879
 			$rejected_by_user_join;
880 880
 		// dates table join only needed to enum recuring events, we use a time-range limited view here too
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
 			{
1402 1402
 				$old_repeats = $this->db->select($this->repeats_table, "$this->repeats_table.*,range_end AS recur_enddate",
1403 1403
 					"$this->repeats_table.cal_id=".(int)$cal_id, __LINE__, __FILE__,
1404
-					false, '', 'calendar', 0, "JOIN $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id")->fetch();
1404
+					false, '', 'calendar', 0, "join $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id")->fetch();
1405 1405
 			}
1406 1406
 			$where = array('cal_id' => $cal_id);
1407 1407
 			// read only timezone id, to check if it is changed
@@ -1766,13 +1766,13 @@  discard block
 block discarded – undo
1766 1766
 		if ($move_start)
1767 1767
 		{
1768 1768
 			// move the recur-date of the participants
1769
-			$this->db->query("UPDATE $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ".
1769
+			$this->db->query("update $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ".
1770 1770
 				((int)$change_since ? '>= '.(int)$change_since : '!= 0'),__LINE__,__FILE__);
1771 1771
 		}
1772 1772
 		if ($move_start || $move_end)
1773 1773
 		{
1774 1774
 			// move the event and it's recurrences
1775
-			$this->db->query("UPDATE $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where".
1775
+			$this->db->query("update $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where".
1776 1776
 				((int) $change_since ? ' AND cal_start >= '.(int) $change_since : ''),__LINE__,__FILE__);
1777 1777
 		}
1778 1778
 		return $this->db->affected_rows();
@@ -2472,7 +2472,7 @@  discard block
 block discarded – undo
2472 2472
 			),__LINE__,__FILE__,'calendar');
2473 2473
 
2474 2474
 			// delete calendar entries without participants (can happen if the deleted user is the only participants, but not the owner)
2475
-			foreach($this->db->select($this->cal_table,"DISTINCT $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__,
2475
+			foreach($this->db->select($this->cal_table,"distinct $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__,
2476 2476
 				False,'','calendar',0,"LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2477 2477
 			{
2478 2478
 				$this->delete($row['cal_id']);
Please login to merge, or discard this patch.
Spacing   +389 added lines, -392 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
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		$this->db = $GLOBALS['egw']->db;
137 137
 
138 138
 		$this->all_tables = array($this->cal_table);
139
-		foreach(array('extra','repeats','user','dates') as $name)
139
+		foreach (array('extra', 'repeats', 'user', 'dates') as $name)
140 140
 		{
141 141
 			$vname = $name.'_table';
142 142
 			$this->all_tables[] = $this->$vname = $this->cal_table.'_'.$name;
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 * @param boolean $deleted =false
153 153
 	 * @return string
154 154
 	 */
155
-	protected function cal_range_view($start, $end, array $_where=null, $deleted=false)
155
+	protected function cal_range_view($start, $end, array $_where = null, $deleted = false)
156 156
 	{
157 157
 		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start)	// using view without start-date is slower!
158 158
 		{
159
-			return $this->cal_table;	// no need / use for a view
159
+			return $this->cal_table; // no need / use for a view
160 160
 		}
161 161
 
162 162
 		$where = array();
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
 	 * @param boolean $deleted =false
183 183
 	 * @return string
184 184
 	 */
185
-	protected function dates_range_view($start, $end, array $_where=null, $deleted=false)
185
+	protected function dates_range_view($start, $end, array $_where = null, $deleted = false)
186 186
 	{
187 187
 		if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end)	// using view without start- AND end-date is slower!
188 188
 		{
189
-			return $this->dates_table;	// no need / use for a view
189
+			return $this->dates_table; // no need / use for a view
190 190
 		}
191 191
 
192 192
 		$where = array();
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
 	 * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it
232 232
 	 * @return array of events
233 233
 	 */
234
-	function &events($start,$end,$users,$cat_id=0,$filter='all',$offset=False,$num_rows=0,array $params=array(),$remove_rejected_by_user=null)
234
+	function &events($start, $end, $users, $cat_id = 0, $filter = 'all', $offset = False, $num_rows = 0, array $params = array(), $remove_rejected_by_user = null)
235 235
 	{
236
-		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());
236
+		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());
237 237
 		$start_time = microtime(true);
238 238
 		// not everything is supported by now
239 239
 		if (!$start || !$end || is_string($params['query']) ||
240 240
 			//in_array($filter,array('owner','deleted')) ||
241
-			$params['enum_recuring']===false)
241
+			$params['enum_recuring'] === false)
242 242
 		{
243 243
 			throw new Api\Exception\AssertionFailed("Unsupported value for parameters!");
244 244
 		}
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 		{
266 266
 			// fix $users to also prefix system users and groups (with 'u')
267 267
 			if (!is_array($users)) $users = $users ? (array)$users : array();
268
-			foreach($users as &$uid)
268
+			foreach ($users as &$uid)
269 269
 			{
270 270
 				$user_type = $user_id = null;
271 271
 				self::split_user($uid, $user_type, $user_id, true);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 
287 287
 		if ($params['order'])	// only order if requested
288 288
 		{
289
-			if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
289
+			if (!preg_match('/^[a-z_ ,c]+$/i', $params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection
290 290
 			$sql .= "\nORDER BY ".$params['order'];
291 291
 		}
292 292
 
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 			$offset = 0;
296 296
 			$num_rows = -1;
297 297
 		}
298
-		$events =& $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows));
299
-		error_log(__METHOD__."(...) $sql --> ".number_format(microtime(true)-$start_time, 3));
298
+		$events = & $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows));
299
+		error_log(__METHOD__."(...) $sql --> ".number_format(microtime(true) - $start_time, 3));
300 300
 		return $events;
301 301
 	}
302 302
 
@@ -309,12 +309,12 @@  discard block
 block discarded – undo
309 309
 	 * @param int $recur_date =0 if set read the next recurrence at or after the timestamp, default 0 = read the initital one
310 310
 	 * @return array|boolean array with cal_id => event array pairs or false if entry not found
311 311
 	 */
312
-	function read($ids,$recur_date=0)
312
+	function read($ids, $recur_date = 0)
313 313
 	{
314 314
 		//error_log(__METHOD__.'('.array2string($ids).",$recur_date) ".function_backtrace());
315 315
 		$cols = self::get_columns('calendar', $this->cal_table);
316 316
 		$cols[0] = $this->db->to_varchar($this->cal_table.'.cal_id');
317
-		$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".implode(',',$cols);
317
+		$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,".implode(',', $cols);
318 318
 		$join = "LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id";
319 319
 
320 320
 		$where = array();
@@ -324,23 +324,23 @@  discard block
 block discarded – undo
324 324
 			$where['cal_uid'] = $ids;
325 325
 			$where['cal_reference'] = 0;
326 326
 		}
327
-		elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids))	// one or more cal_id's
327
+		elseif (is_array($ids) && isset($ids[count($ids) - 1]) || is_scalar($ids))	// one or more cal_id's
328 328
 		{
329 329
 			$where['cal_id'] = $ids;
330 330
 		}
331 331
 		else	// array with column => value pairs
332 332
 		{
333 333
 			$where = $ids;
334
-			unset($ids);	// otherwise users get not read!
334
+			unset($ids); // otherwise users get not read!
335 335
 		}
336 336
 		if (isset($where['cal_id']))	// prevent non-unique column-name cal_id
337 337
 		{
338
-			$where[] = $this->db->expression($this->cal_table, $this->cal_table.'.',array(
338
+			$where[] = $this->db->expression($this->cal_table, $this->cal_table.'.', array(
339 339
 				'cal_id' => $where['cal_id'],
340 340
 			));
341 341
 			unset($where['cal_id']);
342 342
 		}
343
-		if ((int) $recur_date)
343
+		if ((int)$recur_date)
344 344
 		{
345 345
 			$where[] = 'cal_start >= '.(int)$recur_date;
346 346
 			$group_by = 'GROUP BY '.$cols;
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		}
354 354
 		$cols .= ',range_end AS recur_enddate';
355 355
 
356
-		$events =& $this->get_events($this->db->select($this->cal_table, $cols, $where, __LINE__, __FILE__, false, $group_by, 'calendar', 0, $join), $recur_date);
356
+		$events = & $this->get_events($this->db->select($this->cal_table, $cols, $where, __LINE__, __FILE__, false, $group_by, 'calendar', 0, $join), $recur_date);
357 357
 
358 358
 		return $events ? $events : false;
359 359
 	}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * @param int $recur_date =0
366 366
 	 * @return array
367 367
 	 */
368
-	protected function &get_events($rs, $recur_date=0)
368
+	protected function &get_events($rs, $recur_date = 0)
369 369
 	{
370 370
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
371 371
 		{
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 		}
378 378
 
379 379
 		$events = array();
380
-		foreach($rs as $row)
380
+		foreach ($rs as $row)
381 381
 		{
382 382
 			if (!$row['recur_type'])
383 383
 			{
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 				unset($row['recur_enddate']);
386 386
 			}
387 387
 			$row['recur_exception'] = $row['alarm'] = array();
388
-			$events[$row['cal_id']] = Api\Db::strip_array_keys($row,'cal_');
388
+			$events[$row['cal_id']] = Api\Db::strip_array_keys($row, 'cal_');
389 389
 		}
390 390
 		if (!$events) return $events;
391 391
 
@@ -397,26 +397,26 @@  discard block
 block discarded – undo
397 397
 			if (!isset($event['uid']) || strlen($event['uid']) < $minimum_uid_length)
398 398
 			{
399 399
 				// event (without uid), not strong enough uid => create new uid
400
-				$event['uid'] = Api\CalDAV::generate_uid('calendar',$event['id']);
400
+				$event['uid'] = Api\CalDAV::generate_uid('calendar', $event['id']);
401 401
 				$this->db->update($this->cal_table, array('cal_uid' => $event['uid']),
402
-					array('cal_id' => $event['id']),__LINE__,__FILE__,'calendar');
402
+					array('cal_id' => $event['id']), __LINE__, __FILE__, 'calendar');
403 403
 			}
404 404
 			if (!(int)$recur_date && $event['recur_type'] != MCAL_RECUR_NONE)
405 405
 			{
406
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
406
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
407 407
 					'cal_id' => $ids,
408 408
 					'recur_exception' => true,
409 409
 				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row)
410 410
 				{
411 411
 					$events[$row['cal_id']]['recur_exception'][] = $row['cal_start'];
412 412
 				}
413
-				break;	// as above select read all exceptions (and I dont think too short uid problem still exists)
413
+				break; // as above select read all exceptions (and I dont think too short uid problem still exists)
414 414
 			}
415 415
 			// make sure we fetch only real exceptions (deleted occurrences of a series should not show up)
416
-			if (($recur_date &&	$event['recur_type'] != MCAL_RECUR_NONE))
416
+			if (($recur_date && $event['recur_type'] != MCAL_RECUR_NONE))
417 417
 			{
418 418
 				//_debug_array(__METHOD__.__LINE__.' recur_date:'.$recur_date.' check cal_start:'.$event['start']);
419
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
419
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
420 420
 					'cal_id' => $event['id'],
421 421
 					'cal_start' => $event['start'],
422 422
 					'recur_exception' => true,
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 						'cal_deleted' => NULL
433 433
 					), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn())
434 434
 					{
435
-						$e = $this->read($event['id'],$event['start']+1);
435
+						$e = $this->read($event['id'], $event['start'] + 1);
436 436
 						$event = $e[$event['id']];
437 437
 						break;
438 438
 					}
@@ -454,21 +454,21 @@  discard block
 block discarded – undo
454 454
 			if ($recur_date)
455 455
 			{
456 456
 				// also remember recur_date, maybe we need it later, duno now
457
-				$recur_date = array(0,$events[$ids]['recur_date'] = $events[$ids]['start']);
457
+				$recur_date = array(0, $events[$ids]['recur_date'] = $events[$ids]['start']);
458 458
 			}
459 459
 		}
460 460
 
461 461
 		// participants, if a recur_date give, we read that recurance, plus the one users from the default entry with recur_date=0
462 462
 		// sorting by cal_recur_date ASC makes sure recurence status always overwrites series status
463
-		foreach($this->db->select($this->user_table,'*',array(
463
+		foreach ($this->db->select($this->user_table, '*', array(
464 464
 			'cal_id'      => $ids,
465 465
 			'cal_recur_date' => $recur_date,
466 466
 			"cal_status NOT IN ('X','E')",
467
-		),__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
467
+		), __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
468 468
 		{
469 469
 			// combine all participant data in uid and status values
470 470
 			$uid    = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
471
-			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
471
+			$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
472 472
 
473 473
 			$events[$row['cal_id']]['participants'][$uid] = $status;
474 474
 			$events[$row['cal_id']]['participant_types'][$row['cal_user_type']][is_numeric($uid) ? $uid : substr($uid, 1)] = $status;
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 		}
478 478
 
479 479
 		// custom fields
480
-		foreach($this->db->select($this->extra_table,'*',array('cal_id'=>$ids),__LINE__,__FILE__,false,'','calendar') as $row)
480
+		foreach ($this->db->select($this->extra_table, '*', array('cal_id'=>$ids), __LINE__, __FILE__, false, '', 'calendar') as $row)
481 481
 		{
482 482
 			$events[$row['cal_id']]['#'.$row['cal_extra_name']] = $row['cal_extra_value'];
483 483
 		}
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 		// alarms
486 486
 		if (is_array($ids))
487 487
 		{
488
-			foreach($this->read_alarms((array)$ids) as $cal_id => $alarms)
488
+			foreach ($this->read_alarms((array)$ids) as $cal_id => $alarms)
489 489
 			{
490 490
 				$events[$cal_id]['alarm'] = $alarms;
491 491
 			}
@@ -514,11 +514,11 @@  discard block
 block discarded – undo
514 514
 	 * @param boolean $master_only =false only check recurance master (egw_cal_user.recur_date=0)
515 515
 	 * @return int maximum modification timestamp
516 516
 	 */
517
-	function get_ctag($users, $owner_too=false,$master_only=false)
517
+	function get_ctag($users, $owner_too = false, $master_only = false)
518 518
 	{
519
-		static $ctags = array();	// some per-request caching
519
+		static $ctags = array(); // some per-request caching
520 520
 		static $last_request = null;
521
-		if (!isset($last_request) || time()-$last_request > self::MAX_CTAG_CACHE_TIME)
521
+		if (!isset($last_request) || time() - $last_request > self::MAX_CTAG_CACHE_TIME)
522 522
 		{
523 523
 			$ctags = array();
524 524
 			$last_request = time();
@@ -527,13 +527,13 @@  discard block
 block discarded – undo
527 527
 		if (isset($ctags[$signature])) return $ctags[$signature];
528 528
 
529 529
 		$types = array();
530
-		foreach((array)$users as $uid)
530
+		foreach ((array)$users as $uid)
531 531
 		{
532 532
 			$type = $id = null;
533 533
 			self::split_user($uid, $type, $id, true);
534 534
 			$types[$type][] = $id;
535 535
 		}
536
-		foreach($types as $type => $ids)
536
+		foreach ($types as $type => $ids)
537 537
 		{
538 538
 			$where = array(
539 539
 				'cal_user_type' => $type,
@@ -555,17 +555,17 @@  discard block
 block discarded – undo
555 555
 		if ($owner_too)
556 556
 		{
557 557
 			// owner can only by users, no groups or resources
558
-			foreach($users as $key => $user)
558
+			foreach ($users as $key => $user)
559 559
 			{
560 560
 				if (!($user > 0)) unset($users[$key]);
561 561
 			}
562 562
 			$where = $this->db->expression($this->user_table, '(', $where, ' OR ').
563 563
 				$this->db->expression($this->cal_table, array(
564 564
 					'cal_owner' => $users,
565
-				),')');
565
+				), ')');
566 566
 		}
567
-		return $ctags[$signature] = $this->db->select($this->user_table,'MAX(cal_modified)',
568
-			$where,__LINE__,__FILE__,false,'','calendar',0,'JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id')->fetchColumn();
567
+		return $ctags[$signature] = $this->db->select($this->user_table, 'MAX(cal_modified)',
568
+			$where, __LINE__, __FILE__, false, '', 'calendar', 0, 'JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id')->fetchColumn();
569 569
 	}
570 570
 
571 571
 	/**
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 	 * @param string|array $cols ='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified' cols to query
578 578
 	 * @return Iterator as Api\Db::select
579 579
 	 */
580
-	function get_cal_data(array $query, $cols='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified')
580
+	function get_cal_data(array $query, $cols = 'cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified')
581 581
 	{
582 582
 		if (!is_array($cols)) $cols = explode(',', $cols);
583 583
 
@@ -603,12 +603,12 @@  discard block
 block discarded – undo
603 603
 		if ($cat_id)
604 604
 		{
605 605
 			$cats = $GLOBALS['egw']->categories->return_all_children($cat_id);
606
-			array_walk($cats,create_function('&$val,$key','$val = (int) $val;'));
607
-			if (is_array($cat_id) && count($cat_id)==1) $cat_id = $cat_id[0];
608
-			$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '='.$this->db->quote((int)$cat_id));
609
-			foreach($cats as $cat)
606
+			array_walk($cats, create_function('&$val,$key', '$val = (int) $val;'));
607
+			if (is_array($cat_id) && count($cat_id) == 1) $cat_id = $cat_id[0];
608
+			$sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','", $cats)."')" : '='.$this->db->quote((int)$cat_id));
609
+			foreach ($cats as $cat)
610 610
 			{
611
-				$sql .= ' OR '.$this->db->concat("','",'cal_category',"','").' LIKE '.$this->db->quote('%,'.$cat.',%');
611
+				$sql .= ' OR '.$this->db->concat("','", 'cal_category', "','").' LIKE '.$this->db->quote('%,'.$cat.',%');
612 612
 			}
613 613
 			$sql .= ') ';
614 614
 		}
@@ -623,13 +623,13 @@  discard block
 block discarded – undo
623 623
 	 * @param array $where =array() array to add filters too
624 624
 	 * @return array
625 625
 	 */
626
-	protected function status_filter($filter, $enum_recuring=true, array $where=array())
626
+	protected function status_filter($filter, $enum_recuring = true, array $where = array())
627 627
 	{
628
-		if($filter != 'deleted' && $filter != 'everything')
628
+		if ($filter != 'deleted' && $filter != 'everything')
629 629
 		{
630 630
 			$where[] = 'cal_deleted IS NULL';
631 631
 		}
632
-		switch($filter)
632
+		switch ($filter)
633 633
 		{
634 634
 			case 'everything':	// no filter at all
635 635
 				break;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 	 * @param int $remove_rejected_by_user =null add join to remove entry, if given user has rejected it
704 704
 	 * @return Iterator|array of events
705 705
 	 */
706
-	function &search($start,$end,$users,$cat_id=0,$filter='all',$offset=False,$num_rows=0,array $params=array(),$remove_rejected_by_user=null)
706
+	function &search($start, $end, $users, $cat_id = 0, $filter = 'all', $offset = False, $num_rows = 0, array $params = array(), $remove_rejected_by_user = null)
707 707
 	{
708 708
 		//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());
709 709
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 		{
727 727
 			$all_cols = self::get_columns('calendar', $this->cal_table);
728 728
 			$all_cols[0] = $this->db->to_varchar($this->cal_table.'.cal_id');
729
-			$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,range_end AS recur_enddate,".implode(',',$all_cols).",cal_start,cal_end,$this->user_table.cal_recur_date";
729
+			$cols = "$this->repeats_table.recur_type,$this->repeats_table.recur_interval,$this->repeats_table.recur_data,range_end AS recur_enddate,".implode(',', $all_cols).",cal_start,cal_end,$this->user_table.cal_recur_date";
730 730
 		}
731 731
 		$where = array();
732 732
 		if (is_array($params['query']))
@@ -735,26 +735,26 @@  discard block
 block discarded – undo
735 735
 		}
736 736
 		elseif ($params['query'])
737 737
 		{
738
-			if(is_numeric($params['query']))
738
+			if (is_numeric($params['query']))
739 739
 			{
740
-				$where[] = $this->cal_table.'.cal_id = ' . (int)$params['query'];
740
+				$where[] = $this->cal_table.'.cal_id = '.(int)$params['query'];
741 741
 			}
742 742
 			else
743 743
 			{
744
-				foreach(array('cal_title','cal_description','cal_location') as $col)
744
+				foreach (array('cal_title', 'cal_description', 'cal_location') as $col)
745 745
 				{
746 746
 					$to_or[] = $col.' '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%'.$params['query'].'%');
747 747
 				}
748
-				$where[] = '('.implode(' OR ',$to_or).')';
748
+				$where[] = '('.implode(' OR ', $to_or).')';
749 749
 			}
750 750
 
751 751
 			// Searching - restrict private to own or private grant
752 752
 			if (!isset($params['private_grants']))
753 753
 			{
754 754
 				$params['private_grants'] = $GLOBALS['egw']->acl->get_ids_for_location($GLOBALS['egw_info']['user']['account_id'], Acl::PRIVAT, 'calendar');
755
-				$params['private_grants'][] = $GLOBALS['egw_info']['user']['account_id'];	// db query does NOT return current user
755
+				$params['private_grants'][] = $GLOBALS['egw_info']['user']['account_id']; // db query does NOT return current user
756 756
 			}
757
-			$private_filter = '(cal_public=1 OR cal_public=0 AND '.$this->db->expression($this->cal_table, array('cal_owner' => $params['private_grants'])) . ')';
757
+			$private_filter = '(cal_public=1 OR cal_public=0 AND '.$this->db->expression($this->cal_table, array('cal_owner' => $params['private_grants'])).')';
758 758
 			$where[] = $private_filter;
759 759
 		}
760 760
 		if (!empty($params['sql_filter']))
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 			{
764 764
 				$where[] = $params['sql_filter'];
765 765
 			}
766
-			elseif(is_array($params['sql_filter']))
766
+			elseif (is_array($params['sql_filter']))
767 767
 			{
768 768
 				$where = array_merge($where, $params['sql_filter']);
769 769
 			}
@@ -771,11 +771,11 @@  discard block
 block discarded – undo
771 771
 		if ($users)
772 772
 		{
773 773
 			$users_by_type = array();
774
-			foreach((array)$users as $user)
774
+			foreach ((array)$users as $user)
775 775
 			{
776 776
 				if (is_numeric($user))
777 777
 				{
778
-					$users_by_type['u'][] = (int) $user;
778
+					$users_by_type['u'][] = (int)$user;
779 779
 				}
780 780
 				else
781 781
 				{
@@ -787,45 +787,45 @@  discard block
 block discarded – undo
787 787
 			$to_or = $user_or = array();
788 788
 			$owner_or = null;
789 789
 			$useUnionQuery = $this->db->capabilities['distinct_on_text'] && $this->db->capabilities['union'];
790
-			$table_def = $this->db->get_table_definitions('calendar',$this->user_table);
791
-			foreach($users_by_type as $type => $ids)
790
+			$table_def = $this->db->get_table_definitions('calendar', $this->user_table);
791
+			foreach ($users_by_type as $type => $ids)
792 792
 			{
793 793
 				// 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
794 794
 				if ($useUnionQuery)
795 795
 				{
796
-					$user_or[] = $this->db->expression($table_def,$this->user_table.'.',array(
796
+					$user_or[] = $this->db->expression($table_def, $this->user_table.'.', array(
797 797
 						'cal_user_type' => $type,
798
-					),' AND '.$this->user_table.'.',array(
798
+					), ' AND '.$this->user_table.'.', array(
799 799
 						'cal_user_id'   => $ids,
800 800
 					));
801 801
 					if ($type == 'u' && $filter == 'owner')
802 802
 					{
803
-						$cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table);
803
+						$cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table);
804 804
 						// only users can be owners, no need to add groups
805 805
 						$user_ids = array();
806
-						foreach($ids as $user_id)
806
+						foreach ($ids as $user_id)
807 807
 						{
808 808
 							if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u') $user_ids[] = $user_id;
809 809
 						}
810
-						$owner_or = $this->db->expression($cal_table_def,array('cal_owner' => $user_ids));
810
+						$owner_or = $this->db->expression($cal_table_def, array('cal_owner' => $user_ids));
811 811
 					}
812 812
 				}
813 813
 				else
814 814
 				{
815
-					$to_or[] = $this->db->expression($table_def,$this->user_table.'.',array(
815
+					$to_or[] = $this->db->expression($table_def, $this->user_table.'.', array(
816 816
 						'cal_user_type' => $type,
817
-					),' AND '.$this->user_table.'.',array(
817
+					), ' AND '.$this->user_table.'.', array(
818 818
 						'cal_user_id'   => $ids,
819 819
 					));
820 820
 					if ($type == 'u' && $filter == 'owner')
821 821
 					{
822
-						$cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table);
823
-						$to_or[] = $this->db->expression($cal_table_def,array('cal_owner' => $ids));
822
+						$cal_table_def = $this->db->get_table_definitions('calendar', $this->cal_table);
823
+						$to_or[] = $this->db->expression($cal_table_def, array('cal_owner' => $ids));
824 824
 					}
825 825
 				}
826 826
 			}
827 827
 			// this is only used, when we cannot use UNIONS
828
-			if (!$useUnionQuery) $where[] = '('.implode(' OR ',$to_or).')';
828
+			if (!$useUnionQuery) $where[] = '('.implode(' OR ', $to_or).')';
829 829
 
830 830
 			$where = $this->status_filter($filter, $params['enum_recuring'], $where);
831 831
 		}
@@ -844,15 +844,15 @@  discard block
 block discarded – undo
844 844
 				$where[] = '('.((int)$start).' < range_end OR range_end IS NULL)';
845 845
 			}
846 846
 		}
847
-		if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start';		// gard against SQL injection
847
+		if (!preg_match('/^[a-z_ ,c]+$/i', $params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection
848 848
 
849 849
 		// if not enum recuring events, we have to use minimum start- AND end-dates, otherwise we get more then one event per cal_id!
850 850
 		if (!$params['enum_recuring'])
851 851
 		{
852 852
 			$where[] = "$this->user_table.cal_recur_date=0";
853
-			$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);
853
+			$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);
854 854
 			// in case cal_start is used in a query, eg. calendar_ical::find_event
855
-			$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);
855
+			$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);
856 856
 			$params['order'] = str_replace('cal_start', 'range_start', $params['order']);
857 857
 			if ($end) $where[] = (int)$end.' > range_start';
858 858
   		}
@@ -864,14 +864,13 @@  discard block
 block discarded – undo
864 864
 				" ON $this->cal_table.cal_id=rejected_by_user.cal_id".
865 865
 				" AND rejected_by_user.cal_user_type='u'".
866 866
 				" AND rejected_by_user.cal_user_id=".$this->db->quote($remove_rejected_by_user).
867
-				" AND ".(!$params['enum_recuring'] ? 'rejected_by_user.cal_recur_date=0' :
868
-					'(recur_type IS NULL AND rejected_by_user.cal_recur_date=0 OR cal_start=rejected_by_user.cal_recur_date)');
867
+				" 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)');
869 868
 			$or_required = array(
870 869
 				'rejected_by_user.cal_status IS NULL',
871 870
 				"rejected_by_user.cal_status NOT IN ('R','X')",
872 871
 			);
873 872
 			if ($filter == 'owner') $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user;
874
-			$where[] = '('.implode(' OR ',$or_required).')';
873
+			$where[] = '('.implode(' OR ', $or_required).')';
875 874
 		}
876 875
 		// using a time-range and deleted attribute limited view instead of full table
877 876
 		$cal_table = $this->cal_range_view($start, $end, null, $filter == 'everything' ? null : $filter != 'deleted');
@@ -883,7 +882,7 @@  discard block
 block discarded – undo
883 882
 		// dates table join only needed to enum recuring events, we use a time-range limited view here too
884 883
 		if ($params['enum_recuring'])
885 884
 		{
886
-			$join = "JOIN ".$this->dates_table.	// using dates_table direct seems quicker then an other view
885
+			$join = "JOIN ".$this->dates_table.// using dates_table direct seems quicker then an other view
887 886
 				//$this->dates_range_view($start, $end, null, $filter == 'everything' ? null : $filter == 'deleted').
888 887
 				" ON $this->cal_table.cal_id=$this->dates_table.cal_id ".$join;
889 888
 		}
@@ -910,29 +909,29 @@  discard block
 block discarded – undo
910 909
 			// as replace the OR by construction of a suitable UNION for performance reasons
911 910
 			if ($owner_or || $user_or)
912 911
 			{
913
-				foreach($user_or as $user_sql)
912
+				foreach ($user_or as $user_sql)
914 913
 				{
915 914
 					$selects[] = $select;
916
-					$selects[count($selects)-1]['where'][] = $user_sql;
915
+					$selects[count($selects) - 1]['where'][] = $user_sql;
917 916
 					if ($params['enum_recuring'])
918 917
 					{
919
-						$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
918
+						$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
920 919
 						$selects[] = $select;
921
-						$selects[count($selects)-1]['where'][] = $user_sql;
922
-						$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
920
+						$selects[count($selects) - 1]['where'][] = $user_sql;
921
+						$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
923 922
 					}
924 923
 				}
925 924
 				// if the query is to be filtered by owner we need to add more selects for the union
926 925
 				if ($owner_or)
927 926
 				{
928 927
 					$selects[] = $select;
929
-					$selects[count($selects)-1]['where'][] = $owner_or;
928
+					$selects[count($selects) - 1]['where'][] = $owner_or;
930 929
 					if ($params['enum_recuring'])
931 930
 					{
932
-						$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
931
+						$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
933 932
 						$selects[] = $select;
934
-						$selects[count($selects)-1]['where'][] = $owner_or;
935
-						$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
933
+						$selects[count($selects) - 1]['where'][] = $owner_or;
934
+						$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
936 935
 					}
937 936
 				}
938 937
 			}
@@ -942,34 +941,34 @@  discard block
 block discarded – undo
942 941
 				$selects[] = $select;
943 942
 				if ($params['enum_recuring'])
944 943
 				{
945
-					$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
944
+					$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
946 945
 					$selects[] = $select;
947
-					$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
946
+					$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
948 947
 				}
949 948
 			}
950 949
 			if (is_numeric($offset) && !$params['no_total'])	// get the total too
951 950
 			{
952 951
 				$save_selects = $selects;
953 952
 				// 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)
954
-				foreach(array_keys($selects) as $key)
953
+				foreach (array_keys($selects) as $key)
955 954
 				{
956 955
 					$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";
957 956
 					if (!$params['enum_recuring'])
958 957
 					{
959
-						$selects[$key]['cols'] = str_replace(array('cal_start','cal_end'),
960
-							array('range_start AS cal_start','range_end AS cal_end'), $selects[$key]['cols']);
958
+						$selects[$key]['cols'] = str_replace(array('cal_start', 'cal_end'),
959
+							array('range_start AS cal_start', 'range_end AS cal_end'), $selects[$key]['cols']);
961 960
 					}
962 961
 				}
963
-				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
962
+				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
964 963
 
965
-				$this->total = $this->db->union($selects,__LINE__,__FILE__)->NumRows();
964
+				$this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows();
966 965
 
967 966
 				// restore original cols / selects
968 967
 				$selects = $save_selects; unset($save_selects);
969 968
 			}
970
-			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
969
+			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
971 970
 
972
-			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
971
+			$rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows);
973 972
 		}
974 973
 		else	// MsSQL oder MySQL 3.23
975 974
 		{
@@ -992,27 +991,27 @@  discard block
 block discarded – undo
992 991
 				$selects[0]['cols'] = "$this->cal_table.cal_id,cal_start";
993 992
 				if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
994 993
 				{
995
-					self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
994
+					self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
996 995
 				}
997 996
 				$this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows();
998 997
 				$selects = $save_selects;
999 998
 			}
1000 999
 			if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
1001 1000
 			{
1002
-				self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1001
+				self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1003 1002
 			}
1004
-			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
1003
+			$rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows);
1005 1004
 		}
1006 1005
 		//error_log(__METHOD__."() useUnionQuery=$useUnionQuery --> query took ".(microtime(true)-$starttime).'s '.$rs->sql);
1007 1006
 
1008 1007
 		if (isset($params['cols']))
1009 1008
 		{
1010
-			return $rs;	// if colums are specified we return the recordset / iterator
1009
+			return $rs; // if colums are specified we return the recordset / iterator
1011 1010
 		}
1012 1011
 		// Todo: return $this->get_events($rs);
1013 1012
 
1014 1013
 		$events = $ids = $recur_dates = $recur_ids = array();
1015
-		foreach($rs as $row)
1014
+		foreach ($rs as $row)
1016 1015
 		{
1017 1016
 			$id = $row['cal_id'];
1018 1017
 			if (is_numeric($id)) $ids[] = $id;
@@ -1024,9 +1023,9 @@  discard block
 block discarded – undo
1024 1023
 			}
1025 1024
 			if ($row['participants'])
1026 1025
 			{
1027
-				$row['participants'] = explode(',',$row['participants']);
1026
+				$row['participants'] = explode(',', $row['participants']);
1028 1027
 				$row['participants'] = array_combine($row['participants'],
1029
-					array_fill(0,count($row['participants']),''));
1028
+					array_fill(0, count($row['participants']), ''));
1030 1029
 			}
1031 1030
 			else
1032 1031
 			{
@@ -1035,9 +1034,9 @@  discard block
 block discarded – undo
1035 1034
 			$row['recur_exception'] = $row['alarm'] = array();
1036 1035
 
1037 1036
 			// compile a list of recurrences per cal_id
1038
-			if (!in_array($id,(array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1037
+			if (!in_array($id, (array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1039 1038
 
1040
-			$events[$id] = Api\Db::strip_array_keys($row,'cal_');
1039
+			$events[$id] = Api\Db::strip_array_keys($row, 'cal_');
1041 1040
 		}
1042 1041
 		//_debug_array($events);
1043 1042
 		if (count($ids))
@@ -1047,26 +1046,26 @@  discard block
 block discarded – undo
1047 1046
 			// now ready all users with the given cal_id AND (cal_recur_date=0 or the fitting recur-date)
1048 1047
 			// This will always read the first entry of each recuring event too, we eliminate it later
1049 1048
 			$recur_dates[] = 0;
1050
-			$utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',',$ids).")".
1049
+			$utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',', $ids).")".
1051 1050
 				($filter != 'everything' ? " AND cal_status NOT IN ('X','E')" : '').") utcalid ";
1052 1051
 			//$utrecurdate_view = " (select * from ".$this->user_table." where cal_recur_date in (".implode(',',array_unique($recur_dates)).")) utrecurdates ";
1053
-			foreach($this->db->select($utcal_id_view,'*',array(
1052
+			foreach ($this->db->select($utcal_id_view, '*', array(
1054 1053
 					//'cal_id' => array_unique($ids),
1055 1054
 					'cal_recur_date' => $recur_dates,
1056
-				),__LINE__,__FILE__,false,'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT,'calendar',$num_rows,$join='',
1057
-				$this->db->get_table_definitions('calendar',$this->user_table)) as $row)	// DESC puts users before resources and contacts
1055
+				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT, 'calendar', $num_rows, $join = '',
1056
+				$this->db->get_table_definitions('calendar', $this->user_table)) as $row)	// DESC puts users before resources and contacts
1058 1057
 			{
1059 1058
 				$id = $row['cal_id'];
1060 1059
 				if ($row['cal_recur_date']) $id .= '-'.$row['cal_recur_date'];
1061 1060
 
1062 1061
 				// combine all participant data in uid and status values
1063 1062
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1064
-				$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
1063
+				$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
1065 1064
 
1066 1065
 				// set accept/reject/tentative of series for all recurrences
1067 1066
 				if (!$row['cal_recur_date'])
1068 1067
 				{
1069
-					foreach((array)$recur_ids[$row['cal_id']] as $i)
1068
+					foreach ((array)$recur_ids[$row['cal_id']] as $i)
1070 1069
 					{
1071 1070
 						if (isset($events[$i]) && !isset($events[$i]['participants'][$uid]))
1072 1071
 						{
@@ -1081,16 +1080,16 @@  discard block
 block discarded – undo
1081 1080
 			// query recurrance exceptions, if needed: enum_recuring && !daywise is used in calendar_groupdav::get_series($uid,...)
1082 1081
 			if (!$params['enum_recuring'] || !$params['daywise'])
1083 1082
 			{
1084
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
1083
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
1085 1084
 					'cal_id' => $ids,
1086 1085
 					'recur_exception' => true,
1087 1086
 				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row)
1088 1087
 				{
1089 1088
 					// for enum_recurring events are not indexed by cal_id, but $cal_id.'-'.$cal_start
1090 1089
 					// find master, which is first recurrence
1091
-					if (!isset($events[$id=$row['cal_id']]))
1090
+					if (!isset($events[$id = $row['cal_id']]))
1092 1091
 					{
1093
-						foreach($events as $id => $event)
1092
+						foreach ($events as $id => $event)
1094 1093
 						{
1095 1094
 							if ($event['id'] == $row['cal_id']) break;
1096 1095
 						}
@@ -1103,10 +1102,10 @@  discard block
 block discarded – undo
1103 1102
 			{
1104 1103
 				$where = array('cal_id' => $ids);
1105 1104
 				if ($params['cfs']) $where['cal_extra_name'] = $params['cfs'];
1106
-				foreach($this->db->select($this->extra_table,'*',$where,
1107
-					__LINE__,__FILE__,false,'','calendar') as $row)
1105
+				foreach ($this->db->select($this->extra_table, '*', $where,
1106
+					__LINE__, __FILE__, false, '', 'calendar') as $row)
1108 1107
 				{
1109
-					foreach((array)$recur_ids[$row['cal_id']] as $id)
1108
+					foreach ((array)$recur_ids[$row['cal_id']] as $id)
1110 1109
 					{
1111 1110
 						if (isset($events[$id]))
1112 1111
 						{
@@ -1116,9 +1115,9 @@  discard block
 block discarded – undo
1116 1115
 				}
1117 1116
 			}
1118 1117
 			// alarms
1119
-			foreach($this->read_alarms($ids) as $cal_id => $alarms)
1118
+			foreach ($this->read_alarms($ids) as $cal_id => $alarms)
1120 1119
 			{
1121
-				foreach($alarms as $id => $alarm)
1120
+				foreach ($alarms as $id => $alarm)
1122 1121
 				{
1123 1122
 					$event_start = $alarm['time'] + $alarm['offset'];
1124 1123
 
@@ -1155,16 +1154,16 @@  discard block
 block discarded – undo
1155 1154
 	 * @param $query
1156 1155
 	 * @param $users_raw as passed to calendar_bo::search (no members and memberships added)
1157 1156
 	 */
1158
-	private static function get_union_selects(array &$selects,$start,$end,$users,$cat_id,$filter,$query,$users_raw)
1157
+	private static function get_union_selects(array &$selects, $start, $end, $users, $cat_id, $filter, $query, $users_raw)
1159 1158
 	{
1160
-		if (in_array(basename($_SERVER['SCRIPT_FILENAME']),array('groupdav.php','rpc.php','xmlrpc.php','/activesync/index.php')) ||
1161
-			!in_array($GLOBALS['egw_info']['flags']['currentapp'],array('calendar','home')))
1159
+		if (in_array(basename($_SERVER['SCRIPT_FILENAME']), array('groupdav.php', 'rpc.php', 'xmlrpc.php', '/activesync/index.php')) ||
1160
+			!in_array($GLOBALS['egw_info']['flags']['currentapp'], array('calendar', 'home')))
1162 1161
 		{
1163
-			return;    // disable integration for GroupDAV, SyncML, ...
1162
+			return; // disable integration for GroupDAV, SyncML, ...
1164 1163
 		}
1165 1164
 		self::$integration_data = Api\Hooks::process(array(
1166 1165
 			'location' => 'calendar_search_union',
1167
-			'cols'  => $selects[0]['cols'],    // cols to return
1166
+			'cols'  => $selects[0]['cols'], // cols to return
1168 1167
 			'start' => $start,
1169 1168
 			'end'   => $end,
1170 1169
 			'users' => $users,
@@ -1173,12 +1172,12 @@  discard block
 block discarded – undo
1173 1172
 			'filter'=> $filter,
1174 1173
 			'query' => $query,
1175 1174
 		));
1176
-		foreach(self::$integration_data as $data)
1175
+		foreach (self::$integration_data as $data)
1177 1176
 		{
1178 1177
 			if (is_array($data['selects']))
1179 1178
 			{
1180 1179
 				//echo $app; _debug_array($data);
1181
-				$selects = array_merge($selects,$data['selects']);
1180
+				$selects = array_merge($selects, $data['selects']);
1182 1181
 			}
1183 1182
 		}
1184 1183
 	}
@@ -1203,35 +1202,35 @@  discard block
 block discarded – undo
1203 1202
 	 * @param string $required_app ='calendar'
1204 1203
 	 * @return string cols for union query to match ones supplied in $required
1205 1204
 	 */
1206
-	public static function union_cols(array $app_cols,$required,$required_app='calendar')
1205
+	public static function union_cols(array $app_cols, $required, $required_app = 'calendar')
1207 1206
 	{
1208 1207
 		// remove evtl. used DISTINCT, we currently dont need it
1209
-		if (($distinct = substr($required,0,9) == 'DISTINCT '))
1208
+		if (($distinct = substr($required, 0, 9) == 'DISTINCT '))
1210 1209
 		{
1211
-			$required = substr($required,9);
1210
+			$required = substr($required, 9);
1212 1211
 		}
1213 1212
 		$return_cols = array();
1214
-		foreach(is_array($required) ? $required : explode(',',$required) as $cols)
1213
+		foreach (is_array($required) ? $required : explode(',', $required) as $cols)
1215 1214
 		{
1216 1215
 			$matches = null;
1217
-			if (substr($cols,-2) == '.*')
1216
+			if (substr($cols, -2) == '.*')
1218 1217
 			{
1219
-				$cols = self::get_columns($required_app,substr($cols,0,-2));
1218
+				$cols = self::get_columns($required_app, substr($cols, 0, -2));
1220 1219
 			}
1221 1220
 			// remove CAST added for PostgreSQL from eg. "CAST(egw_cal.cal_id AS varchar)"
1222 1221
 			elseif (preg_match('/CAST\(([a-z0-9_.]+) AS [a-z0-9_]+\)/i', $cols, $matches))
1223 1222
 			{
1224 1223
 				$cols = $matches[1];
1225 1224
 			}
1226
-			elseif (strpos($cols,' AS ') !== false)
1225
+			elseif (strpos($cols, ' AS ') !== false)
1227 1226
 			{
1228
-				list(,$cols) = explode(' AS ',$cols);
1227
+				list(,$cols) = explode(' AS ', $cols);
1229 1228
 			}
1230
-			foreach((array)$cols as $col)
1229
+			foreach ((array)$cols as $col)
1231 1230
 			{
1232
-				if (substr($col,0,7) == 'egw_cal')	// remove table name
1231
+				if (substr($col, 0, 7) == 'egw_cal')	// remove table name
1233 1232
 				{
1234
-					$col = preg_replace('/^egw_cal[a-z_]*\./','',$col);
1233
+					$col = preg_replace('/^egw_cal[a-z_]*\./', '', $col);
1235 1234
 				}
1236 1235
 				if (isset($app_cols[$col]))
1237 1236
 				{
@@ -1244,7 +1243,7 @@  discard block
 block discarded – undo
1244 1243
 			}
1245 1244
 		}
1246 1245
 		//error_log(__METHOD__."(".array2string($app_cols).", ".array2string($required).", '$required_app') returning ".array2string(implode(',',$return_cols)));
1247
-		return implode(',',$return_cols);
1246
+		return implode(',', $return_cols);
1248 1247
 	}
1249 1248
 
1250 1249
 	/**
@@ -1254,21 +1253,21 @@  discard block
 block discarded – undo
1254 1253
 	 * @param string $table
1255 1254
 	 * @return array of column names
1256 1255
 	 */
1257
-	static private function get_columns($app,$table)
1256
+	static private function get_columns($app, $table)
1258 1257
 	{
1259 1258
 		if ($table != 'egw_cal')
1260 1259
 		{
1261
-			$table_def = $GLOBALS['egw']->db->get_table_definitions($app,$table);
1260
+			$table_def = $GLOBALS['egw']->db->get_table_definitions($app, $table);
1262 1261
 			$cols = array_keys($table_def['fd']);
1263 1262
 		}
1264 1263
 		else
1265 1264
 		{
1266 1265
 			// special handling for egw_cal, as old databases have a different column order!!!
1267
-			$cols =& Api\Cache::getSession(__CLASS__,$table);
1266
+			$cols = & Api\Cache::getSession(__CLASS__, $table);
1268 1267
 
1269 1268
 			if (is_null($cols))
1270 1269
 			{
1271
-				$meta = $GLOBALS['egw']->db->metadata($table,true);
1270
+				$meta = $GLOBALS['egw']->db->metadata($table, true);
1272 1271
 				$cols = array_keys($meta['meta']);
1273 1272
 			}
1274 1273
 		}
@@ -1321,12 +1320,12 @@  discard block
 block discarded – undo
1321 1320
 	 * @param int &$etag etag=null etag to check or null, on return new etag
1322 1321
 	 * @return boolean|int false on error, 0 if etag does not match, cal_id otherwise
1323 1322
 	 */
1324
-	function save($event,&$set_recurrences,&$set_recurrences_start=0,$change_since=0,&$etag=null)
1323
+	function save($event, &$set_recurrences, &$set_recurrences_start = 0, $change_since = 0, &$etag = null)
1325 1324
 	{
1326 1325
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
1327 1326
 		{
1328 1327
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
1329
-			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!
1328
+			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!
1330 1329
 		}
1331 1330
 		else
1332 1331
 		{
@@ -1337,7 +1336,7 @@  discard block
 block discarded – undo
1337 1336
 
1338 1337
 		//error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag) ".function_backtrace());
1339 1338
 
1340
-		$cal_id = (int) $event['id'];
1339
+		$cal_id = (int)$event['id'];
1341 1340
 		unset($event['id']);
1342 1341
 		$set_recurrences = $set_recurrences || !$cal_id && $event['recur_type'] != MCAL_RECUR_NONE;
1343 1342
 
@@ -1365,9 +1364,9 @@  discard block
 block discarded – undo
1365 1364
 		}
1366 1365
 
1367 1366
 		// add colum prefix 'cal_' if there's not already a 'recur_' prefix
1368
-		foreach($event as $col => $val)
1367
+		foreach ($event as $col => $val)
1369 1368
 		{
1370
-			if ($col[0] != '#' && substr($col,0,6) != 'recur_' && substr($col,0,6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name')
1369
+			if ($col[0] != '#' && substr($col, 0, 6) != 'recur_' && substr($col, 0, 6) != 'range_' && $col != 'alarm' && $col != 'tz_id' && $col != 'caldav_name')
1371 1370
 			{
1372 1371
 				$event['cal_'.$col] = $val;
1373 1372
 				unset($event[$col]);
@@ -1377,13 +1376,12 @@  discard block
 block discarded – undo
1377 1376
 		if (isset($event['cal_start'])) $event['range_start'] = $event['cal_start'];
1378 1377
 		if (isset($event['cal_end']))
1379 1378
 		{
1380
-			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] :
1381
-				($event['recur_enddate'] ? $event['recur_enddate'] : null);
1379
+			$event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] : ($event['recur_enddate'] ? $event['recur_enddate'] : null);
1382 1380
 		}
1383 1381
 		// ensure that we find mathing entries later on
1384 1382
 		if (!is_array($event['cal_category']))
1385 1383
 		{
1386
-			$categories = array_unique(explode(',',$event['cal_category']));
1384
+			$categories = array_unique(explode(',', $event['cal_category']));
1387 1385
 			sort($categories);
1388 1386
 		}
1389 1387
 		else
@@ -1392,7 +1390,7 @@  discard block
 block discarded – undo
1392 1390
 		}
1393 1391
 		sort($categories, SORT_NUMERIC);
1394 1392
 
1395
-		$event['cal_category'] = implode(',',$categories);
1393
+		$event['cal_category'] = implode(',', $categories);
1396 1394
 
1397 1395
 		// make sure recurring events never reference to an other recurrent event
1398 1396
 		if ($event['recur_type'] != MCAL_RECUR_NONE) $event['cal_reference'] = 0;
@@ -1410,18 +1408,18 @@  discard block
 block discarded – undo
1410 1408
 			// read only timezone id, to check if it is changed
1411 1409
 			if ($event['recur_type'] != MCAL_RECUR_NONE)
1412 1410
 			{
1413
-				$old_tz_id = $this->db->select($this->cal_table,'tz_id',$where,__LINE__,__FILE__,'calendar')->fetchColumn();
1411
+				$old_tz_id = $this->db->select($this->cal_table, 'tz_id', $where, __LINE__, __FILE__, 'calendar')->fetchColumn();
1414 1412
 			}
1415 1413
 			if (!is_null($etag)) $where['cal_etag'] = $etag;
1416 1414
 
1417 1415
 			unset($event['cal_etag']);
1418
-			$event[] = 'cal_etag=cal_etag+1';	// always update the etag, even if none given to check
1416
+			$event[] = 'cal_etag=cal_etag+1'; // always update the etag, even if none given to check
1419 1417
 
1420
-			$this->db->update($this->cal_table,$event,$where,__LINE__,__FILE__,'calendar');
1418
+			$this->db->update($this->cal_table, $event, $where, __LINE__, __FILE__, 'calendar');
1421 1419
 
1422 1420
 			if (!is_null($etag) && $this->db->affected_rows() < 1)
1423 1421
 			{
1424
-				return 0;	// wrong etag, someone else updated the entry
1422
+				return 0; // wrong etag, someone else updated the entry
1425 1423
 			}
1426 1424
 			if (!is_null($etag)) ++$etag;
1427 1425
 		}
@@ -1430,10 +1428,10 @@  discard block
 block discarded – undo
1430 1428
 			// new event
1431 1429
 			if (!$event['cal_owner']) $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id'];
1432 1430
 
1433
-			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = '';	// uid is NOT NULL!
1431
+			if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = ''; // uid is NOT NULL!
1434 1432
 
1435
-			$this->db->insert($this->cal_table,$event,false,__LINE__,__FILE__,'calendar');
1436
-			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table,'cal_id')))
1433
+			$this->db->insert($this->cal_table, $event, false, __LINE__, __FILE__, 'calendar');
1434
+			if (!($cal_id = $this->db->get_last_insert_id($this->cal_table, 'cal_id')))
1437 1435
 			{
1438 1436
 				return false;
1439 1437
 			}
@@ -1443,7 +1441,7 @@  discard block
 block discarded – undo
1443 1441
 		// event without uid or not strong enough uid
1444 1442
 		if (!isset($event['cal_uid']) || strlen($event['cal_uid']) < $minimum_uid_length)
1445 1443
 		{
1446
-			$update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar',$cal_id);
1444
+			$update['cal_uid'] = $event['cal_uid'] = Api\CalDAV::generate_uid('calendar', $cal_id);
1447 1445
 		}
1448 1446
 		// set caldav_name, if not given by caller
1449 1447
 		if (empty($event['caldav_name']) && version_compare($GLOBALS['egw_info']['apps']['calendar']['version'], '1.9.003', '>='))
@@ -1452,37 +1450,37 @@  discard block
 block discarded – undo
1452 1450
 		}
1453 1451
 		if ($update)
1454 1452
 		{
1455
-			$this->db->update($this->cal_table, $update, array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
1453
+			$this->db->update($this->cal_table, $update, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar');
1456 1454
 		}
1457 1455
 
1458 1456
 		if ($event['recur_type'] == MCAL_RECUR_NONE)
1459 1457
 		{
1460
-			$this->db->delete($this->dates_table,array(
1458
+			$this->db->delete($this->dates_table, array(
1461 1459
 				'cal_id' => $cal_id),
1462
-				__LINE__,__FILE__,'calendar');
1460
+				__LINE__, __FILE__, 'calendar');
1463 1461
 
1464 1462
 			// delete all user-records, with recur-date != 0
1465
-			$this->db->delete($this->user_table,array(
1463
+			$this->db->delete($this->user_table, array(
1466 1464
 				'cal_id' => $cal_id, 'cal_recur_date != 0'),
1467
-				__LINE__,__FILE__,'calendar');
1465
+				__LINE__, __FILE__, 'calendar');
1468 1466
 
1469
-			$this->db->delete($this->repeats_table,array(
1467
+			$this->db->delete($this->repeats_table, array(
1470 1468
 				'cal_id' => $cal_id),
1471
-				__LINE__,__FILE__,'calendar');
1469
+				__LINE__, __FILE__, 'calendar');
1472 1470
 
1473 1471
 			// add exception marker to master, so participants added to exceptions *only* get found
1474 1472
 			if ($event['cal_reference'])
1475 1473
 			{
1476 1474
 				$master_participants = array();
1477
-				foreach($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array(
1475
+				foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee', array(
1478 1476
 					'cal_id' => $event['cal_reference'],
1479 1477
 					'cal_recur_date' => 0,
1480
-					"cal_status != 'X'",	// deleted need to be replaced with exception marker too
1478
+					"cal_status != 'X'", // deleted need to be replaced with exception marker too
1481 1479
 				), __LINE__, __FILE__, 'calendar') as $row)
1482 1480
 				{
1483 1481
 					$master_participants[] = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1484 1482
 				}
1485
-				foreach(array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid)
1483
+				foreach (array_diff(array_keys((array)$event['cal_participants']), $master_participants) as $uid)
1486 1484
 				{
1487 1485
 					$user_type = $user_id = null;
1488 1486
 					self::split_user($uid, $user_type, $user_id, true);
@@ -1501,10 +1499,10 @@  discard block
 block discarded – undo
1501 1499
 		else // write information about recuring event, if recur_type is present in the array
1502 1500
 		{
1503 1501
 			// fetch information about the currently saved (old) event
1504
-			$old_min = (int) $this->db->select($this->dates_table,'MIN(cal_start)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn();
1505
-			$old_duration = (int) $this->db->select($this->dates_table,'MIN(cal_end)',array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn() - $old_min;
1502
+			$old_min = (int)$this->db->select($this->dates_table, 'MIN(cal_start)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn();
1503
+			$old_duration = (int)$this->db->select($this->dates_table, 'MIN(cal_end)', array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn() - $old_min;
1506 1504
 			$old_exceptions = array();
1507
-			foreach($this->db->select($this->dates_table, 'cal_start', array(
1505
+			foreach ($this->db->select($this->dates_table, 'cal_start', array(
1508 1506
 				'cal_id' => $cal_id,
1509 1507
 				'recur_exception' => true
1510 1508
 			), __LINE__, __FILE__, false, 'ORDER BY cal_start', 'calendar') as $row)
@@ -1523,8 +1521,8 @@  discard block
 block discarded – undo
1523 1521
 				'cal_recur_date' => 0,
1524 1522
 			);
1525 1523
 			$old_participants = array();
1526
-			foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where,
1527
-				__LINE__,__FILE__,false,'','calendar') as $row)
1524
+			foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status,cal_quantity,cal_role', $where,
1525
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
1528 1526
 			{
1529 1527
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1530 1528
 				$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
@@ -1534,7 +1532,7 @@  discard block
 block discarded – undo
1534 1532
 			// re-check: did so much recurrence data change that we have to rebuild it from scratch?
1535 1533
 			if (!$set_recurrences)
1536 1534
 			{
1537
-				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int) $event['cal_start']) ||
1535
+				$set_recurrences = (isset($event['cal_start']) && (int)$old_min != (int)$event['cal_start']) ||
1538 1536
 				    $event['recur_type'] != $old_repeats['recur_type'] || $event['recur_data'] != $old_repeats['recur_data'] ||
1539 1537
 					(int)$event['recur_interval'] != (int)$old_repeats['recur_interval'] || $event['tz_id'] != $old_tz_id;
1540 1538
 			}
@@ -1543,22 +1541,22 @@  discard block
 block discarded – undo
1543 1541
 			{
1544 1542
 				// too much recurrence data has changed, we have to do a rebuild from scratch
1545 1543
 				// delete all, but the lowest dates record
1546
-				$this->db->delete($this->dates_table,array(
1544
+				$this->db->delete($this->dates_table, array(
1547 1545
 					'cal_id' => $cal_id,
1548 1546
 					'cal_start > '.(int)$old_min,
1549
-				),__LINE__,__FILE__,'calendar');
1547
+				), __LINE__, __FILE__, 'calendar');
1550 1548
 
1551 1549
 				// delete all user-records, with recur-date != 0
1552
-				$this->db->delete($this->user_table,array(
1550
+				$this->db->delete($this->user_table, array(
1553 1551
 					'cal_id' => $cal_id,
1554 1552
 					'cal_recur_date != 0',
1555
-				),__LINE__,__FILE__,'calendar');
1553
+				), __LINE__, __FILE__, 'calendar');
1556 1554
 			}
1557 1555
 			else
1558 1556
 			{
1559 1557
 				// we adjust some possibly changed recurrences manually
1560 1558
 				// deleted exceptions: re-insert recurrences into the user and dates table
1561
-				if (count($deleted_exceptions = array_diff($old_exceptions,$event['recur_exception'])))
1559
+				if (count($deleted_exceptions = array_diff($old_exceptions, $event['recur_exception'])))
1562 1560
 				{
1563 1561
 					if (isset($event['cal_participants']))
1564 1562
 					{
@@ -1569,7 +1567,7 @@  discard block
 block discarded – undo
1569 1567
 						// use old default
1570 1568
 						$participants = $old_participants;
1571 1569
 					}
1572
-					foreach($deleted_exceptions as $id => $deleted_exception)
1570
+					foreach ($deleted_exceptions as $id => $deleted_exception)
1573 1571
 					{
1574 1572
 						// rebuild participants for the re-inserted recurrence
1575 1573
 						$this->recurrence($cal_id, $deleted_exception, $deleted_exception + $old_duration, $participants);
@@ -1577,24 +1575,24 @@  discard block
 block discarded – undo
1577 1575
 				}
1578 1576
 
1579 1577
 				// check if recurrence enddate was adjusted
1580
-				if(isset($event['recur_enddate']))
1578
+				if (isset($event['recur_enddate']))
1581 1579
 				{
1582 1580
 					// recurrences need to be truncated
1583
-					if((int)$event['recur_enddate'] > 0 &&
1581
+					if ((int)$event['recur_enddate'] > 0 &&
1584 1582
 						((int)$old_repeats['recur_enddate'] == 0 || (int)$old_repeats['recur_enddate'] > (int)$event['recur_enddate'])
1585 1583
 					)
1586 1584
 					{
1587
-						$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1588
-						$this->db->delete($this->dates_table,array('cal_id' => $cal_id,'cal_start >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar');
1585
+						$this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar');
1586
+						$this->db->delete($this->dates_table, array('cal_id' => $cal_id, 'cal_start >= '.($event['recur_enddate'] + 1 * DAY_s)), __LINE__, __FILE__, 'calendar');
1589 1587
 					}
1590 1588
 
1591 1589
 					// recurrences need to be expanded
1592
-					if(((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1590
+					if (((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0)
1593 1591
 						|| ((int)$event['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] < (int)$event['recur_enddate'])
1594 1592
 					)
1595 1593
 					{
1596 1594
 						$set_recurrences = true;
1597
-						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1*DAY_s);
1595
+						$set_recurrences_start = ($old_repeats['recur_enddate'] + 1 * DAY_s);
1598 1596
 					}
1599 1597
 					//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");
1600 1598
 				}
@@ -1603,9 +1601,9 @@  discard block
 block discarded – undo
1603 1601
 				if (count($event['recur_exception']))
1604 1602
 				{
1605 1603
 					// added and existing exceptions: delete the execeptions from the user table, it could be the first time
1606
-					$this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date' => $event['recur_exception']),__LINE__,__FILE__,'calendar');
1604
+					$this->db->delete($this->user_table, array('cal_id' => $cal_id, 'cal_recur_date' => $event['recur_exception']), __LINE__, __FILE__, 'calendar');
1607 1605
 					// update recur_exception flag based on current exceptions
1608
-					$this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table,array(
1606
+					$this->db->update($this->dates_table, 'recur_exception='.$this->db->expression($this->dates_table, array(
1609 1607
 						'cal_start' => $event['recur_exception'],
1610 1608
 					)), array(
1611 1609
 						'cal_id' => $cal_id,
@@ -1614,25 +1612,25 @@  discard block
 block discarded – undo
1614 1612
 			}
1615 1613
 
1616 1614
 			// write the repeats table
1617
-			unset($event[0]);	// unset the 'etag=etag+1', as it's not in the repeats table
1618
-			$this->db->insert($this->repeats_table,$event,array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
1615
+			unset($event[0]); // unset the 'etag=etag+1', as it's not in the repeats table
1616
+			$this->db->insert($this->repeats_table, $event, array('cal_id' => $cal_id), __LINE__, __FILE__, 'calendar');
1619 1617
 		}
1620 1618
 		// update start- and endtime if present in the event-array, evtl. we need to move all recurrences
1621 1619
 		if (isset($event['cal_start']) && isset($event['cal_end']))
1622 1620
 		{
1623
-			$this->move($cal_id,$event['cal_start'],$event['cal_end'],!$cal_id ? false : $change_since, $old_min, $old_min +  $old_duration);
1621
+			$this->move($cal_id, $event['cal_start'], $event['cal_end'], !$cal_id ? false : $change_since, $old_min, $old_min + $old_duration);
1624 1622
 		}
1625 1623
 		// update participants if present in the event-array
1626 1624
 		if (isset($event['cal_participants']))
1627 1625
 		{
1628
-			$this->participants($cal_id,$event['cal_participants'],!$cal_id ? false : $change_since);
1626
+			$this->participants($cal_id, $event['cal_participants'], !$cal_id ? false : $change_since);
1629 1627
 		}
1630 1628
 		// Custom fields
1631
-		foreach($event as $name => $value)
1629
+		foreach ($event as $name => $value)
1632 1630
 		{
1633 1631
 			if ($name[0] == '#')
1634 1632
 			{
1635
-				if (is_array($value) && array_key_exists('id',$value))
1633
+				if (is_array($value) && array_key_exists('id', $value))
1636 1634
 				{
1637 1635
 					//error_log(__METHOD__.__LINE__."$name => ".array2string($value).function_backtrace());
1638 1636
 					$value = $value['id'];
@@ -1640,19 +1638,19 @@  discard block
 block discarded – undo
1640 1638
 				}
1641 1639
 				if ($value)
1642 1640
 				{
1643
-					$this->db->insert($this->extra_table,array(
1644
-						'cal_extra_value'	=> is_array($value) ? implode(',',$value) : $value,
1645
-					),array(
1641
+					$this->db->insert($this->extra_table, array(
1642
+						'cal_extra_value'	=> is_array($value) ? implode(',', $value) : $value,
1643
+					), array(
1646 1644
 						'cal_id'			=> $cal_id,
1647
-						'cal_extra_name'	=> substr($name,1),
1648
-					),__LINE__,__FILE__,'calendar');
1645
+						'cal_extra_name'	=> substr($name, 1),
1646
+					), __LINE__, __FILE__, 'calendar');
1649 1647
 				}
1650 1648
 				else
1651 1649
 				{
1652
-					$this->db->delete($this->extra_table,array(
1650
+					$this->db->delete($this->extra_table, array(
1653 1651
 						'cal_id'			=> $cal_id,
1654
-						'cal_extra_name'	=> substr($name,1),
1655
-					),__LINE__,__FILE__,'calendar');
1652
+						'cal_extra_name'	=> substr($name, 1),
1653
+					), __LINE__, __FILE__, 'calendar');
1656 1654
 				}
1657 1655
 			}
1658 1656
 		}
@@ -1663,9 +1661,9 @@  discard block
 block discarded – undo
1663 1661
 			{
1664 1662
 				if ($alarm['id'] && strpos($alarm['id'], 'cal:'.$cal_id.':') !== 0)
1665 1663
 				{
1666
-					unset($alarm['id']);	// unset the temporary id to add the alarm
1664
+					unset($alarm['id']); // unset the temporary id to add the alarm
1667 1665
 				}
1668
-				if(!isset($alarm['offset']))
1666
+				if (!isset($alarm['offset']))
1669 1667
 				{
1670 1668
 					$alarm['offset'] = $event['cal_start'] - $alarm['time'];
1671 1669
 				}
@@ -1676,14 +1674,14 @@  discard block
 block discarded – undo
1676 1674
 
1677 1675
 				if ($alarm['time'] < time() && !self::shift_alarm($event, $alarm))
1678 1676
 				{
1679
-					continue;	// pgoerzen: don't add alarm in the past
1677
+					continue; // pgoerzen: don't add alarm in the past
1680 1678
 				}
1681
-				$this->save_alarm($cal_id, $alarm, false);	// false: not update modified, we do it anyway
1679
+				$this->save_alarm($cal_id, $alarm, false); // false: not update modified, we do it anyway
1682 1680
 			}
1683 1681
 		}
1684 1682
 		if (is_null($etag))
1685 1683
 		{
1686
-			$etag = $this->db->select($this->cal_table,'cal_etag',array('cal_id' => $cal_id),__LINE__,__FILE__,false,'','calendar')->fetchColumn();
1684
+			$etag = $this->db->select($this->cal_table, 'cal_etag', array('cal_id' => $cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetchColumn();
1687 1685
 		}
1688 1686
 
1689 1687
 		// if event is an exception: update modified of master, to force etag, ctag and sync-token change
@@ -1703,7 +1701,7 @@  discard block
 block discarded – undo
1703 1701
 	 *	are dealing with, default is now.
1704 1702
 	 * @return boolean true if alarm could be shifted, false if not
1705 1703
 	 */
1706
-	public static function shift_alarm(array $_event, array &$alarm, $timestamp=null)
1704
+	public static function shift_alarm(array $_event, array &$alarm, $timestamp = null)
1707 1705
 	{
1708 1706
 		if ($_event['recur_type'] == MCAL_RECUR_NONE)
1709 1707
 		{
@@ -1714,7 +1712,7 @@  discard block
 block discarded – undo
1714 1712
 		$rrule = calendar_rrule::event2rrule($event, false);
1715 1713
 		foreach ($rrule as $time)
1716 1714
 		{
1717
-			if ($start < ($ts = Api\DateTime::to($time,'server')))
1715
+			if ($start < ($ts = Api\DateTime::to($time, 'server')))
1718 1716
 			{
1719 1717
 				$alarm['time'] = $ts - $alarm['offset'];
1720 1718
 				return true;
@@ -1735,34 +1733,34 @@  discard block
 block discarded – undo
1735 1733
 	 * @todo Recalculate recurrences, if timezone changes
1736 1734
 	 * @return int|boolean number of moved recurrences or false on error
1737 1735
 	 */
1738
-	function move($cal_id,$start,$end,$change_since=0,$old_start=0,$old_end=0)
1736
+	function move($cal_id, $start, $end, $change_since = 0, $old_start = 0, $old_end = 0)
1739 1737
 	{
1740 1738
 		//echo "<p>socal::move($cal_id,$start,$end,$change_since,$old_start,$old_end)</p>\n";
1741 1739
 
1742
-		if (!(int) $cal_id) return false;
1740
+		if (!(int)$cal_id) return false;
1743 1741
 
1744 1742
 		if (!$old_start)
1745 1743
 		{
1746
-			if ($change_since !== false) $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1747
-				array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetch();
1744
+			if ($change_since !== false) $row = $this->db->select($this->dates_table, 'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end',
1745
+				array('cal_id'=>$cal_id), __LINE__, __FILE__, false, '', 'calendar')->fetch();
1748 1746
 			// if no recurrence found, create one with the new dates
1749 1747
 			if ($change_since === false || !$row || !$row['cal_start'] || !$row['cal_end'])
1750 1748
 			{
1751
-				$this->db->insert($this->dates_table,array(
1749
+				$this->db->insert($this->dates_table, array(
1752 1750
 					'cal_id'    => $cal_id,
1753 1751
 					'cal_start' => $start,
1754 1752
 					'cal_end'   => $end,
1755
-				),false,__LINE__,__FILE__,'calendar');
1753
+				), false, __LINE__, __FILE__, 'calendar');
1756 1754
 
1757 1755
 				return 1;
1758 1756
 			}
1759
-			$move_start = (int) ($start-$row['cal_start']);
1760
-			$move_end   = (int) ($end-$row['cal_end']);
1757
+			$move_start = (int)($start - $row['cal_start']);
1758
+			$move_end   = (int)($end - $row['cal_end']);
1761 1759
 		}
1762 1760
 		else
1763 1761
 		{
1764
-			$move_start = (int) ($start-$old_start);
1765
-			$move_end   = (int) ($end-$old_end);
1762
+			$move_start = (int)($start - $old_start);
1763
+			$move_end   = (int)($end - $old_end);
1766 1764
 		}
1767 1765
 		$where = 'cal_id='.(int)$cal_id;
1768 1766
 
@@ -1770,13 +1768,13 @@  discard block
 block discarded – undo
1770 1768
 		{
1771 1769
 			// move the recur-date of the participants
1772 1770
 			$this->db->query("UPDATE $this->user_table SET cal_recur_date=cal_recur_date+$move_start WHERE $where AND cal_recur_date ".
1773
-				((int)$change_since ? '>= '.(int)$change_since : '!= 0'),__LINE__,__FILE__);
1771
+				((int)$change_since ? '>= '.(int)$change_since : '!= 0'), __LINE__, __FILE__);
1774 1772
 		}
1775 1773
 		if ($move_start || $move_end)
1776 1774
 		{
1777 1775
 			// move the event and it's recurrences
1778 1776
 			$this->db->query("UPDATE $this->dates_table SET cal_start=cal_start+$move_start,cal_end=cal_end+$move_end WHERE $where".
1779
-				((int) $change_since ? ' AND cal_start >= '.(int) $change_since : ''),__LINE__,__FILE__);
1777
+				((int)$change_since ? ' AND cal_start >= '.(int)$change_since : ''), __LINE__, __FILE__);
1780 1778
 		}
1781 1779
 		return $this->db->affected_rows();
1782 1780
 	}
@@ -1795,8 +1793,7 @@  discard block
 block discarded – undo
1795 1793
 		}
1796 1794
 		if (is_array($attendee))
1797 1795
 		{
1798
-			$email = !empty($attendee['email']) ? $user_attendee['email'] :
1799
-				(strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']);
1796
+			$email = !empty($attendee['email']) ? $user_attendee['email'] : (strtolower(substr($attendee['url'], 0, 7)) == 'mailto:' ? substr($user_attendee['url'], 7) : $attendee['url']);
1800 1797
 			$attendee = !empty($attendee['cn']) ? $attendee['cn'].' <'.$email.'>' : $email;
1801 1798
 		}
1802 1799
 		return $attendee;
@@ -1809,11 +1806,11 @@  discard block
 block discarded – undo
1809 1806
 	 * @param string|array $attendee attendee information: email, json or array with attr cn and url
1810 1807
 	 * @return string|int combined id
1811 1808
 	 */
1812
-	static function combine_user($user_type, $user_id, $attendee=null)
1809
+	static function combine_user($user_type, $user_id, $attendee = null)
1813 1810
 	{
1814 1811
 		if (!$user_type || $user_type == 'u')
1815 1812
 		{
1816
-			return (int) $user_id;
1813
+			return (int)$user_id;
1817 1814
 		}
1818 1815
 		if ($user_type == 'e' && $attendee)
1819 1816
 		{
@@ -1833,12 +1830,12 @@  discard block
 block discarded – undo
1833 1830
 	 * @param string|int &$user_id id
1834 1831
 	 * @param boolean $md5_email =false md5 hash user_id for email / user_type=="e"
1835 1832
 	 */
1836
-	static function split_user($uid, &$user_type, &$user_id, $md5_email=false)
1833
+	static function split_user($uid, &$user_type, &$user_id, $md5_email = false)
1837 1834
 	{
1838 1835
 		if (is_numeric($uid))
1839 1836
 		{
1840 1837
 			$user_type = 'u';
1841
-			$user_id = (int) $uid;
1838
+			$user_id = (int)$uid;
1842 1839
 		}
1843 1840
 		// create md5 hash from lowercased and trimed raw email ("[email protected]", not "Ralf Becker <[email protected]>")
1844 1841
 		elseif ($md5_email && $uid[0] == 'e')
@@ -1852,7 +1849,7 @@  discard block
 block discarded – undo
1852 1849
 		else
1853 1850
 		{
1854 1851
 			$user_type = $uid[0];
1855
-			$user_id = substr($uid,1);
1852
+			$user_id = substr($uid, 1);
1856 1853
 		}
1857 1854
 	}
1858 1855
 
@@ -1864,7 +1861,7 @@  discard block
 block discarded – undo
1864 1861
 	 * @param string $role ='REQ-PARTICIPANT'
1865 1862
 	 * @return string
1866 1863
 	 */
1867
-	static function combine_status($status,$quantity=1,$role='REQ-PARTICIPANT')
1864
+	static function combine_status($status, $quantity = 1, $role = 'REQ-PARTICIPANT')
1868 1865
 	{
1869 1866
 		if ((int)$quantity > 1) $status .= (int)$quantity;
1870 1867
 		if ($role != 'REQ-PARTICIPANT') $status .= $role;
@@ -1880,13 +1877,13 @@  discard block
 block discarded – undo
1880 1877
 	 * @param string &$role=null only O: role
1881 1878
 	 * @return string status U, T, A or R, same as $status parameter on return
1882 1879
 	 */
1883
-	static function split_status(&$status,&$quantity=null,&$role=null)
1880
+	static function split_status(&$status, &$quantity = null, &$role = null)
1884 1881
 	{
1885 1882
 		$quantity = 1;
1886 1883
 		$role = 'REQ-PARTICIPANT';
1887 1884
 		//error_log(__METHOD__.__LINE__.array2string($status));
1888 1885
 		$matches = null;
1889
-		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/',$status,$matches))
1886
+		if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/', $status, $matches))
1890 1887
 		{
1891 1888
 			if ((int)$matches[1] > 0) $quantity = (int)$matches[1];
1892 1889
 			if ($matches[2]) $role = $matches[2];
@@ -1913,14 +1910,14 @@  discard block
 block discarded – undo
1913 1910
 	 *		true = only add participants if needed, no participant will be deleted (participants to check/add required in $participants)
1914 1911
 	 * @return int|boolean number of updated recurrences or false on error
1915 1912
 	 */
1916
-	function participants($cal_id,$participants,$change_since=0,$add_only=false)
1913
+	function participants($cal_id, $participants, $change_since = 0, $add_only = false)
1917 1914
 	{
1918 1915
 		//error_log(__METHOD__."($cal_id,".array2string($participants).",$change_since,$add_only");
1919 1916
 
1920 1917
 		$recurrences = array();
1921 1918
 
1922 1919
 		// remove group-invitations, they are NOT stored in the db
1923
-		foreach($participants as $uid => $status)
1920
+		foreach ($participants as $uid => $status)
1924 1921
 		{
1925 1922
 			if ($status[0] == 'G')
1926 1923
 			{
@@ -1929,7 +1926,7 @@  discard block
 block discarded – undo
1929 1926
 		}
1930 1927
 		$where = array('cal_id' => $cal_id);
1931 1928
 
1932
-		if ((int) $change_since)
1929
+		if ((int)$change_since)
1933 1930
 		{
1934 1931
 			$where[] = '(cal_recur_date=0 OR cal_recur_date >= '.(int)$change_since.')';
1935 1932
 		}
@@ -1937,31 +1934,31 @@  discard block
 block discarded – undo
1937 1934
 		if ($change_since !== false)
1938 1935
 		{
1939 1936
 			// find all existing recurrences
1940
-			foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row)
1937
+			foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row)
1941 1938
 			{
1942 1939
 				$recurrences[] = $row['cal_recur_date'];
1943 1940
 			}
1944 1941
 
1945 1942
 			// update existing entries
1946
-			$existing_entries = $this->db->select($this->user_table,'*',$where,__LINE__,__FILE__,false,'ORDER BY cal_recur_date DESC','calendar');
1943
+			$existing_entries = $this->db->select($this->user_table, '*', $where, __LINE__, __FILE__, false, 'ORDER BY cal_recur_date DESC', 'calendar');
1947 1944
 
1948 1945
 			// create a full list of participants which already exist in the db
1949 1946
 			// with status, quantity and role of the earliest recurence
1950 1947
 			$old_participants = array();
1951
-			foreach($existing_entries as $row)
1948
+			foreach ($existing_entries as $row)
1952 1949
 			{
1953 1950
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1954 1951
 				if ($row['cal_recur_date'] || !isset($old_participants[$uid]))
1955 1952
 				{
1956
-					$old_participants[$uid] = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
1953
+					$old_participants[$uid] = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
1957 1954
 				}
1958 1955
 			}
1959 1956
 
1960 1957
 			// tag participants which should be deleted
1961
-			if($add_only === false)
1958
+			if ($add_only === false)
1962 1959
 			{
1963 1960
 				$deleted = array();
1964
-				foreach($existing_entries as $row)
1961
+				foreach ($existing_entries as $row)
1965 1962
 				{
1966 1963
 					$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1967 1964
 					// delete not longer set participants
@@ -1974,7 +1971,7 @@  discard block
 block discarded – undo
1974 1971
 
1975 1972
 			// only keep added OR status (incl. quantity!) changed participants for further steps
1976 1973
 			// we do not touch unchanged (!) existing ones
1977
-			foreach($participants as $uid => $status)
1974
+			foreach ($participants as $uid => $status)
1978 1975
 			{
1979 1976
 				if ($old_participants[$uid] === $status)
1980 1977
 				{
@@ -1986,46 +1983,46 @@  discard block
 block discarded – undo
1986 1983
 			if ($add_only === false && count($deleted))
1987 1984
 			{
1988 1985
 				$to_or = array();
1989
-				$table_def = $this->db->get_table_definitions('calendar',$this->user_table);
1990
-				foreach($deleted as $type => $ids)
1986
+				$table_def = $this->db->get_table_definitions('calendar', $this->user_table);
1987
+				foreach ($deleted as $type => $ids)
1991 1988
 				{
1992
-					$to_or[] = $this->db->expression($table_def,array(
1989
+					$to_or[] = $this->db->expression($table_def, array(
1993 1990
 						'cal_user_type' => $type,
1994 1991
 						'cal_user_id'   => $ids,
1995 1992
 					));
1996 1993
 				}
1997
-				$where[] = '('.implode(' OR ',$to_or).')';
1998
-				$where[] = "cal_status!='E'";	// do NOT delete exception marker
1999
-				$this->db->update($this->user_table,array('cal_status'=>'X'),$where,__LINE__,__FILE__,'calendar');
1994
+				$where[] = '('.implode(' OR ', $to_or).')';
1995
+				$where[] = "cal_status!='E'"; // do NOT delete exception marker
1996
+				$this->db->update($this->user_table, array('cal_status'=>'X'), $where, __LINE__, __FILE__, 'calendar');
2000 1997
 			}
2001 1998
 		}
2002 1999
 
2003 2000
 		if (count($participants))	// participants which need to be added
2004 2001
 		{
2005
-			if (!count($recurrences)) $recurrences[] = 0;   // insert the default recurrence
2002
+			if (!count($recurrences)) $recurrences[] = 0; // insert the default recurrence
2006 2003
 
2007 2004
 			$delete_deleted = array();
2008 2005
 
2009 2006
 			// update participants
2010
-			foreach($participants as $uid => $status)
2007
+			foreach ($participants as $uid => $status)
2011 2008
 			{
2012 2009
 				$type = $id = $quantity = $role = null;
2013 2010
 				self::split_user($uid, $type, $id, true);
2014
-				self::split_status($status,$quantity,$role);
2011
+				self::split_status($status, $quantity, $role);
2015 2012
 				$set = array(
2016 2013
 					'cal_status'	  => $status,
2017 2014
 					'cal_quantity'	  => $quantity,
2018 2015
 					'cal_role'        => $role,
2019 2016
 					'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null,
2020 2017
 				);
2021
-				foreach($recurrences as $recur_date)
2018
+				foreach ($recurrences as $recur_date)
2022 2019
 				{
2023
-					$this->db->insert($this->user_table,$set,array(
2020
+					$this->db->insert($this->user_table, $set, array(
2024 2021
 						'cal_id'	      => $cal_id,
2025 2022
 						'cal_recur_date'  => $recur_date,
2026 2023
 						'cal_user_type'   => $type,
2027 2024
 						'cal_user_id' 	  => $id,
2028
-					),__LINE__,__FILE__,'calendar');
2025
+					), __LINE__, __FILE__, 'calendar');
2029 2026
 				}
2030 2027
 				// for new or changed group-invitations, remove previously deleted members, so they show up again
2031 2028
 				if ($uid < 0)
@@ -2035,13 +2032,13 @@  discard block
 block discarded – undo
2035 2032
 			}
2036 2033
 			if ($delete_deleted)
2037 2034
 			{
2038
-				$this->db->delete($this->user_table, $where=array(
2035
+				$this->db->delete($this->user_table, $where = array(
2039 2036
 					'cal_id' => $cal_id,
2040 2037
 					'cal_recur_date' => $recurrences,
2041 2038
 					'cal_user_type' => 'u',
2042 2039
 					'cal_user_id' => array_unique($delete_deleted),
2043 2040
 					'cal_status' => 'X',
2044
-				),__LINE__,__FILE__,'calendar');
2041
+				), __LINE__, __FILE__, 'calendar');
2045 2042
 				//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');
2046 2043
 			}
2047 2044
 		}
@@ -2060,7 +2057,7 @@  discard block
 block discarded – undo
2060 2057
 	 * @param string $attendee =null extra attendee information to set for all types (incl. accounts!)
2061 2058
 	 * @return int number of changed recurrences
2062 2059
 	 */
2063
-	function set_status($cal_id,$user_type,$user_id,$status,$recur_date=0,$role=null,$attendee=null)
2060
+	function set_status($cal_id, $user_type, $user_id, $status, $recur_date = 0, $role = null, $attendee = null)
2064 2061
 	{
2065 2062
 		static $status_code_short = array(
2066 2063
 			REJECTED 	=> 'R',
@@ -2085,7 +2082,7 @@  discard block
 block discarded – undo
2085 2082
 			'cal_user_type'	=> $user_type,
2086 2083
 			'cal_user_id'   => $user_id_md5,
2087 2084
 		);
2088
-		if ((int) $recur_date)
2085
+		if ((int)$recur_date)
2089 2086
 		{
2090 2087
 			$where['cal_recur_date'] = $recur_date;
2091 2088
 		}
@@ -2096,7 +2093,7 @@  discard block
 block discarded – undo
2096 2093
 
2097 2094
 		if ($status == 'G')		// remove group invitations, as we dont store them in the db
2098 2095
 		{
2099
-			$this->db->delete($this->user_table,$where,__LINE__,__FILE__,'calendar');
2096
+			$this->db->delete($this->user_table, $where, __LINE__, __FILE__, 'calendar');
2100 2097
 			$ret = $this->db->affected_rows();
2101 2098
 		}
2102 2099
 		else
@@ -2104,7 +2101,7 @@  discard block
 block discarded – undo
2104 2101
 			$set = array('cal_status' => $status);
2105 2102
 			if ($user_type == 'e' || $attendee) $set['cal_user_attendee'] = $attendee ? $attendee : $user_id;
2106 2103
 			if (!is_null($role) && $role != 'REQ-PARTICIPANT') $set['cal_role'] = $role;
2107
-			$this->db->insert($this->user_table,$set,$where,__LINE__,__FILE__,'calendar');
2104
+			$this->db->insert($this->user_table, $set, $where, __LINE__, __FILE__, 'calendar');
2108 2105
 			// for new or changed group-invitations, remove previously deleted members, so they show up again
2109 2106
 			if (($ret = $this->db->affected_rows()) && $user_type == 'u' && $user_id < 0)
2110 2107
 			{
@@ -2117,7 +2114,7 @@  discard block
 block discarded – undo
2117 2114
 		// update modified and modifier in main table
2118 2115
 		if ($ret)
2119 2116
 		{
2120
-			$this->updateModified($cal_id, true);	// true = update series master too
2117
+			$this->updateModified($cal_id, true); // true = update series master too
2121 2118
 		}
2122 2119
 		//error_log(__METHOD__."($cal_id,$user_type,$user_id,$status,$recur_date) = $ret");
2123 2120
 		return $ret;
@@ -2132,7 +2129,7 @@  discard block
 block discarded – undo
2132 2129
 	 * @param array $participants uid => status pairs
2133 2130
 	 * @param boolean $exception =null true or false to set recure_exception flag, null leave it unchanged (new are by default no exception)
2134 2131
 	 */
2135
-	function recurrence($cal_id,$start,$end,$participants,$exception=null)
2132
+	function recurrence($cal_id, $start, $end, $participants, $exception = null)
2136 2133
 	{
2137 2134
 		//error_log(__METHOD__."($cal_id, $start, $end, ".array2string($participants).", ".array2string($exception));
2138 2135
 		$update = array('cal_end' => $end);
@@ -2141,7 +2138,7 @@  discard block
 block discarded – undo
2141 2138
 		$this->db->insert($this->dates_table, $update, array(
2142 2139
 			'cal_id' => $cal_id,
2143 2140
 			'cal_start'  => $start,
2144
-		),__LINE__,__FILE__,'calendar');
2141
+		), __LINE__, __FILE__, 'calendar');
2145 2142
 
2146 2143
 		if (!is_array($participants))
2147 2144
 		{
@@ -2149,26 +2146,26 @@  discard block
 block discarded – undo
2149 2146
 		}
2150 2147
 		if ($exception !== true)
2151 2148
 		{
2152
-			foreach($participants as $uid => $status)
2149
+			foreach ($participants as $uid => $status)
2153 2150
 			{
2154
-				if ($status == 'G') continue;	// dont save group-invitations
2151
+				if ($status == 'G') continue; // dont save group-invitations
2155 2152
 
2156 2153
 				$type = '';
2157 2154
 				$id = null;
2158 2155
 				self::split_user($uid, $type, $id, true);
2159 2156
 				$quantity = $role = null;
2160
-				self::split_status($status,$quantity,$role);
2161
-				$this->db->insert($this->user_table,array(
2157
+				self::split_status($status, $quantity, $role);
2158
+				$this->db->insert($this->user_table, array(
2162 2159
 					'cal_status'	=> $status,
2163 2160
 					'cal_quantity'	=> $quantity,
2164 2161
 					'cal_role'		=> $role,
2165 2162
 					'cal_user_attendee' => $type == 'e' ? substr($uid, 1) : null,
2166
-				),array(
2163
+				), array(
2167 2164
 					'cal_id'		 => $cal_id,
2168 2165
 					'cal_recur_date' => $start,
2169 2166
 					'cal_user_type'  => $type,
2170 2167
 					'cal_user_id' 	 => $id,
2171
-				),__LINE__,__FILE__,'calendar');
2168
+				), __LINE__, __FILE__, 'calendar');
2172 2169
 			}
2173 2170
 		}
2174 2171
 	}
@@ -2182,7 +2179,7 @@  discard block
 block discarded – undo
2182 2179
 	function unfinished_recuring($time)
2183 2180
 	{
2184 2181
 		$ids = array();
2185
-		foreach($rs=$this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start",
2182
+		foreach ($rs = $this->db->select($this->repeats_table, "$this->repeats_table.cal_id,MAX(cal_start) AS cal_start",
2186 2183
 			'(range_end IS NULL OR range_end > '.(int)$time.')',
2187 2184
 			__LINE__, __FILE__, false, "GROUP BY $this->repeats_table.cal_id,range_end", 'calendar', 0,
2188 2185
 			" JOIN $this->cal_table ON $this->repeats_table.cal_id=$this->cal_table.cal_id".
@@ -2208,9 +2205,9 @@  discard block
 block discarded – undo
2208 2205
 		// update timestamp of series master, updates own timestamp too, which does not hurt ;-)
2209 2206
 		$this->updateModified($cal_id, true);
2210 2207
 
2211
-		foreach($this->all_tables as $table)
2208
+		foreach ($this->all_tables as $table)
2212 2209
 		{
2213
-			$this->db->delete($table,array('cal_id'=>$cal_id),__LINE__,__FILE__,'calendar');
2210
+			$this->db->delete($table, array('cal_id'=>$cal_id), __LINE__, __FILE__, 'calendar');
2214 2211
 		}
2215 2212
 	}
2216 2213
 
@@ -2226,19 +2223,19 @@  discard block
 block discarded – undo
2226 2223
 	function purge($date)
2227 2224
 	{
2228 2225
 		// with new range_end we simple delete all with range_end < $date (range_end NULL is never returned)
2229
-		foreach($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row)
2226
+		foreach ($this->db->select($this->cal_table, 'cal_id', 'range_end < '.(int)$date, __LINE__, __FILE__, false, '', 'calendar') as $row)
2230 2227
 		{
2231 2228
 			//echo __METHOD__." About to delete".$row['cal_id']."\r\n";
2232
-			foreach($this->all_tables as $table)
2229
+			foreach ($this->all_tables as $table)
2233 2230
 			{
2234 2231
 				$this->db->delete($table, array('cal_id'=>$row['cal_id']), __LINE__, __FILE__, 'calendar');
2235 2232
 			}
2236 2233
 			// handle sync
2237
-			$this->db->update('egw_api_content_history',array(
2234
+			$this->db->update('egw_api_content_history', array(
2238 2235
 				'sync_deleted' => time(),
2239
-			),array(
2236
+			), array(
2240 2237
 				'sync_appname' => 'calendar',
2241
-				'sync_contentid' => $row['cal_id'],	// sync_contentid is varchar(60)!
2238
+				'sync_contentid' => $row['cal_id'], // sync_contentid is varchar(60)!
2242 2239
 			), __LINE__, __FILE__);
2243 2240
 			// handle links
2244 2241
 			Link::unlink('', 'calendar', $row['cal_id']);
@@ -2261,23 +2258,23 @@  discard block
 block discarded – undo
2261 2258
 	 * @param boolean $update_cache =null true: re-read given $cal_id, false: delete given $cal_id
2262 2259
 	 * @return array of (cal_id => array of) alarms with alarm-id as key
2263 2260
 	 */
2264
-	function read_alarms($cal_id, $update_cache=null)
2261
+	function read_alarms($cal_id, $update_cache = null)
2265 2262
 	{
2266 2263
 		if (!isset(self::$alarm_cache) && is_array($cal_id))
2267 2264
 		{
2268 2265
 			self::$alarm_cache = array();
2269 2266
 			if (($jobs = $this->async->read('cal:%')))
2270 2267
 			{
2271
-				foreach($jobs as $id => $job)
2268
+				foreach ($jobs as $id => $job)
2272 2269
 				{
2273
-					$alarm         = $job['data'];	// text, enabled
2270
+					$alarm         = $job['data']; // text, enabled
2274 2271
 					$alarm['id']   = $id;
2275 2272
 					$alarm['time'] = $job['next'];
2276 2273
 
2277 2274
 					self::$alarm_cache[$alarm['cal_id']][$id] = $alarm;
2278 2275
 				}
2279 2276
 			}
2280
-			unset($update_cache);	// just done
2277
+			unset($update_cache); // just done
2281 2278
 		}
2282 2279
 		$alarms = array();
2283 2280
 
@@ -2285,13 +2282,13 @@  discard block
 block discarded – undo
2285 2282
 		{
2286 2283
 			if (isset($update_cache))
2287 2284
 			{
2288
-				foreach((array)$cal_id as $id)
2285
+				foreach ((array)$cal_id as $id)
2289 2286
 				{
2290 2287
 					if ($update_cache === false)
2291 2288
 					{
2292 2289
 						unset(self::$alarm_cache[$cal_id]);
2293 2290
 					}
2294
-					elseif($update_cache === true)
2291
+					elseif ($update_cache === true)
2295 2292
 					{
2296 2293
 						self::$alarm_cache[$cal_id] = $this->read_alarms_nocache($cal_id);
2297 2294
 					}
@@ -2303,7 +2300,7 @@  discard block
 block discarded – undo
2303 2300
 			}
2304 2301
 			else
2305 2302
 			{
2306
-				foreach($cal_id as $id)
2303
+				foreach ($cal_id as $id)
2307 2304
 				{
2308 2305
 					$alarms[$id] = (array)self::$alarm_cache[$id];
2309 2306
 				}
@@ -2318,9 +2315,9 @@  discard block
 block discarded – undo
2318 2315
 	{
2319 2316
 		if (($jobs = $this->async->read('cal:'.(int)$cal_id.':%')))
2320 2317
 		{
2321
-			foreach($jobs as $id => $job)
2318
+			foreach ($jobs as $id => $job)
2322 2319
 			{
2323
-				$alarm         = $job['data'];	// text, enabled
2320
+				$alarm         = $job['data']; // text, enabled
2324 2321
 				$alarm['id']   = $id;
2325 2322
 				$alarm['time'] = $job['next'];
2326 2323
 
@@ -2343,8 +2340,8 @@  discard block
 block discarded – undo
2343 2340
 		{
2344 2341
 			return False;
2345 2342
 		}
2346
-		list($alarm_id,$job) = each($jobs);
2347
-		$alarm         = $job['data'];	// text, enabled
2343
+		list($alarm_id, $job) = each($jobs);
2344
+		$alarm         = $job['data']; // text, enabled
2348 2345
 		$alarm['id']   = $alarm_id;
2349 2346
 		$alarm['time'] = $job['next'];
2350 2347
 
@@ -2360,12 +2357,12 @@  discard block
 block discarded – undo
2360 2357
 	 * @param boolean $update_modified =true call update modified, default true
2361 2358
 	 * @return string id of the alarm
2362 2359
 	 */
2363
-	function save_alarm($cal_id, $alarm, $update_modified=true)
2360
+	function save_alarm($cal_id, $alarm, $update_modified = true)
2364 2361
 	{
2365 2362
 		//error_log(__METHOD__."($cal_id, ".array2string($alarm).', '.array2string($update_modified).') '.function_backtrace());
2366 2363
 		if (!($id = $alarm['id']))
2367 2364
 		{
2368
-			$alarms = $this->read_alarms($cal_id);	// find a free alarm#
2365
+			$alarms = $this->read_alarms($cal_id); // find a free alarm#
2369 2366
 			$n = count($alarms);
2370 2367
 			do
2371 2368
 			{
@@ -2378,12 +2375,12 @@  discard block
 block discarded – undo
2378 2375
 		{
2379 2376
 			$this->async->cancel_timer($id);
2380 2377
 		}
2381
-		$alarm['cal_id'] = $cal_id;		// we need the back-reference
2378
+		$alarm['cal_id'] = $cal_id; // we need the back-reference
2382 2379
 		// add an alarm uid, if none is given
2383 2380
 		if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) $alarm['uid'] = (string)new Horde_Support_Uuid;
2384 2381
 		//error_log(__METHOD__.__LINE__.' Save Alarm for CalID:'.$cal_id.'->'.array2string($alarm).'-->'.$id.'#'.function_backtrace());
2385 2382
 		// allways store job with the alarm owner as job-owner to get eg. the correct from address
2386
-		if (!$this->async->set_timer($alarm['time'],$id,'calendar.calendar_boupdate.send_alarm',$alarm,$alarm['owner']))
2383
+		if (!$this->async->set_timer($alarm['time'], $id, 'calendar.calendar_boupdate.send_alarm', $alarm, $alarm['owner']))
2387 2384
 		{
2388 2385
 			return False;
2389 2386
 		}
@@ -2410,7 +2407,7 @@  discard block
 block discarded – undo
2410 2407
 		//error_log(__METHOD__."($cal_id) ".function_backtrace());
2411 2408
 		if (($alarms = $this->read_alarms($cal_id)))
2412 2409
 		{
2413
-			foreach(array_keys($alarms) as $id)
2410
+			foreach (array_keys($alarms) as $id)
2414 2411
 			{
2415 2412
 				$this->async->cancel_timer($id);
2416 2413
 			}
@@ -2430,7 +2427,7 @@  discard block
 block discarded – undo
2430 2427
 	{
2431 2428
 		//error_log(__METHOD__."('$id') ".function_backtrace());
2432 2429
 		// update the modification information of the related event
2433
-		list(,$cal_id) = explode(':',$id);
2430
+		list(,$cal_id) = explode(':', $id);
2434 2431
 		if ($cal_id)
2435 2432
 		{
2436 2433
 			$this->updateModified($cal_id, true);
@@ -2449,7 +2446,7 @@  discard block
 block discarded – undo
2449 2446
 	 * @param array|int $old_user integer old user or array with keys 'account_id' and 'new_owner' as the deleteaccount hook uses it
2450 2447
 	 * @param int $new_user =null
2451 2448
 	 */
2452
-	function deleteaccount($old_user, $new_user=null)
2449
+	function deleteaccount($old_user, $new_user = null)
2453 2450
 	{
2454 2451
 		if (is_array($old_user))
2455 2452
 		{
@@ -2460,52 +2457,52 @@  discard block
 block discarded – undo
2460 2457
 		{
2461 2458
 			$user_type = '';
2462 2459
 			$user_id = null;
2463
-			self::split_user($old_user,$user_type,$user_id);
2460
+			self::split_user($old_user, $user_type, $user_id);
2464 2461
 
2465 2462
 			if ($user_type == 'u')	// only accounts can be owners of events
2466 2463
 			{
2467
-				foreach($this->db->select($this->cal_table,'cal_id',array('cal_owner' => $old_user),__LINE__,__FILE__,false,'','calendar') as $row)
2464
+				foreach ($this->db->select($this->cal_table, 'cal_id', array('cal_owner' => $old_user), __LINE__, __FILE__, false, '', 'calendar') as $row)
2468 2465
 				{
2469 2466
 					$this->delete($row['cal_id']);
2470 2467
 				}
2471 2468
 			}
2472
-			$this->db->delete($this->user_table,array(
2469
+			$this->db->delete($this->user_table, array(
2473 2470
 				'cal_user_type' => $user_type,
2474 2471
 				'cal_user_id'   => $user_id,
2475
-			),__LINE__,__FILE__,'calendar');
2472
+			), __LINE__, __FILE__, 'calendar');
2476 2473
 
2477 2474
 			// delete calendar entries without participants (can happen if the deleted user is the only participants, but not the owner)
2478
-			foreach($this->db->select($this->cal_table,"DISTINCT $this->cal_table.cal_id",'cal_user_id IS NULL',__LINE__,__FILE__,
2479
-				False,'','calendar',0,"LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2475
+			foreach ($this->db->select($this->cal_table, "DISTINCT $this->cal_table.cal_id", 'cal_user_id IS NULL', __LINE__, __FILE__,
2476
+				False, '', 'calendar', 0, "LEFT JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id") as $row)
2480 2477
 			{
2481 2478
 				$this->delete($row['cal_id']);
2482 2479
 			}
2483 2480
 		}
2484 2481
 		else
2485 2482
 		{
2486
-			$this->db->update($this->cal_table,array('cal_owner' => $new_user),array('cal_owner' => $old_user),__LINE__,__FILE__,'calendar');
2483
+			$this->db->update($this->cal_table, array('cal_owner' => $new_user), array('cal_owner' => $old_user), __LINE__, __FILE__, 'calendar');
2487 2484
 			// delete participation of old user, if new user is already a participant
2488 2485
 			$ids = array();
2489
-			foreach($this->db->select($this->user_table,'cal_id',array(		// MySQL does NOT allow to run this as delete!
2486
+			foreach ($this->db->select($this->user_table, 'cal_id', array(		// MySQL does NOT allow to run this as delete!
2490 2487
 				'cal_user_type' => 'u',
2491 2488
 				'cal_user_id' => $old_user,
2492 2489
 				"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')",
2493
-			),__LINE__,__FILE__,false,'','calendar') as $row)
2490
+			), __LINE__, __FILE__, false, '', 'calendar') as $row)
2494 2491
 			{
2495 2492
 				$ids[] = $row['cal_id'];
2496 2493
 			}
2497
-			if ($ids) $this->db->delete($this->user_table,array(
2494
+			if ($ids) $this->db->delete($this->user_table, array(
2498 2495
 				'cal_user_type' => 'u',
2499 2496
 				'cal_user_id' => $old_user,
2500 2497
 				'cal_id' => $ids,
2501
-			),__LINE__,__FILE__,'calendar');
2498
+			), __LINE__, __FILE__, 'calendar');
2502 2499
 			// now change participant in the rest to contain new user instead of old user
2503
-			$this->db->update($this->user_table,array(
2500
+			$this->db->update($this->user_table, array(
2504 2501
 				'cal_user_id' => $new_user,
2505
-			),array(
2502
+			), array(
2506 2503
 				'cal_user_type' => 'u',
2507 2504
 				'cal_user_id' => $old_user,
2508
-			),__LINE__,__FILE__,'calendar');
2505
+			), __LINE__, __FILE__, 'calendar');
2509 2506
 		}
2510 2507
 	}
2511 2508
 
@@ -2519,18 +2516,18 @@  discard block
 block discarded – undo
2519 2516
 	 *
2520 2517
 	 * @return array recur_date => status pairs (index 0 => main status)
2521 2518
 	 */
2522
-	function get_recurrences($cal_id, $uid=null, $start=0, $end=0)
2519
+	function get_recurrences($cal_id, $uid = null, $start = 0, $end = 0)
2523 2520
 	{
2524 2521
 		$participant_status = array();
2525 2522
 		$where = array('cal_id' => $cal_id);
2526
-		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2527
-		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2523
+		if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')';
2524
+		if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')';
2528 2525
 		if ($start != 0 && $end != 0)
2529 2526
 		{
2530
-			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
2531
-						' AND cal_recur_date <= ' . (int)$end . '))';
2527
+			$where[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start.
2528
+						' AND cal_recur_date <= '.(int)$end.'))';
2532 2529
 		}
2533
-		foreach($this->db->select($this->user_table,'DISTINCT cal_recur_date',$where,__LINE__,__FILE__,false,'','calendar') as $row)
2530
+		foreach ($this->db->select($this->user_table, 'DISTINCT cal_recur_date', $where, __LINE__, __FILE__, false, '', 'calendar') as $row)
2534 2531
 		{
2535 2532
 			// inititalize the array
2536 2533
 			$participant_status[$row['cal_recur_date']] = null;
@@ -2544,17 +2541,17 @@  discard block
 block discarded – undo
2544 2541
 			'cal_user_type'	=> $user_type ? $user_type : 'u',
2545 2542
 			'cal_user_id'   => $user_id,
2546 2543
 		);
2547
-		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')';
2548
-		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')';
2544
+		if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= '.(int)$start.')';
2545
+		if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= '.(int)$end.')';
2549 2546
 		if ($start != 0 && $end != 0)
2550 2547
 		{
2551
-			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start .
2552
-						' AND cal_recur_date <= ' . (int)$end . '))';
2548
+			$where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= '.(int)$start.
2549
+						' AND cal_recur_date <= '.(int)$end.'))';
2553 2550
 		}
2554
-		foreach ($this->db->select($this->user_table,'cal_recur_date,cal_status,cal_quantity,cal_role',$where2,
2555
-				__LINE__,__FILE__,false,'','calendar') as $row)
2551
+		foreach ($this->db->select($this->user_table, 'cal_recur_date,cal_status,cal_quantity,cal_role', $where2,
2552
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2556 2553
 		{
2557
-			$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
2554
+			$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
2558 2555
 			$participant_status[$row['cal_recur_date']] = $status;
2559 2556
 		}
2560 2557
 		return $participant_status;
@@ -2603,8 +2600,8 @@  discard block
 block discarded – undo
2603 2600
 			'cal_uid'		=> $uid,
2604 2601
 		);
2605 2602
 		$related = array();
2606
-		foreach ($this->db->select($this->cal_table,'cal_id,cal_reference',$where,
2607
-				__LINE__,__FILE__,false,'','calendar') as $row)
2603
+		foreach ($this->db->select($this->cal_table, 'cal_id,cal_reference', $where,
2604
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2608 2605
 		{
2609 2606
 			if ($row['cal_reference'] != 0)
2610 2607
 			{
@@ -2633,10 +2630,10 @@  discard block
 block discarded – undo
2633 2630
 	 *
2634 2631
 	 * @return array		Array of exception days (false for non-recurring events).
2635 2632
 	 */
2636
-	function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all')
2633
+	function get_recurrence_exceptions($event, $tz_id = null, $start = 0, $end = 0, $filter = 'all')
2637 2634
 	{
2638 2635
 		if (!is_array($event)) return false;
2639
-		$cal_id = (int) $event['id'];
2636
+		$cal_id = (int)$event['id'];
2640 2637
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2641 2638
 		//		"($cal_id, $tz_id, $filter): " . $event['tzid']);
2642 2639
 		if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false;
@@ -2660,27 +2657,27 @@  discard block
 block discarded – undo
2660 2657
 		while ($egw_rrule->valid())
2661 2658
 		{
2662 2659
 			while ($egw_rrule->exceptions &&
2663
-				in_array($egw_rrule->current->format('Ymd'),$egw_rrule->exceptions))
2660
+				in_array($egw_rrule->current->format('Ymd'), $egw_rrule->exceptions))
2664 2661
 			{
2665
-				if (in_array($filter, array('map','tz_map','rrule','tz_rrule')))
2662
+				if (in_array($filter, array('map', 'tz_map', 'rrule', 'tz_rrule')))
2666 2663
 				{
2667 2664
 					 // real exception
2668
-					$locts = (int)Api\DateTime::to($egw_rrule->current(),'server');
2665
+					$locts = (int)Api\DateTime::to($egw_rrule->current(), 'server');
2669 2666
 					if ($expand_all)
2670 2667
 					{
2671
-						$remts = (int)Api\DateTime::to($remote_rrule->current(),'server');
2668
+						$remts = (int)Api\DateTime::to($remote_rrule->current(), 'server');
2672 2669
 						if ($remote)
2673 2670
 						{
2674
-							$days[$locts]= $remts;
2671
+							$days[$locts] = $remts;
2675 2672
 						}
2676 2673
 						else
2677 2674
 						{
2678
-							$days[$remts]= $locts;
2675
+							$days[$remts] = $locts;
2679 2676
 						}
2680 2677
 					}
2681 2678
 					else
2682 2679
 					{
2683
-						$days[$locts]= $locts;
2680
+						$days[$locts] = $locts;
2684 2681
 					}
2685 2682
 				}
2686 2683
 				if ($expand_all)
@@ -2691,14 +2688,14 @@  discard block
 block discarded – undo
2691 2688
 				if (!$egw_rrule->valid()) return $days;
2692 2689
 			}
2693 2690
 			$day = $egw_rrule->current();
2694
-			$locts = (int)Api\DateTime::to($day,'server');
2691
+			$locts = (int)Api\DateTime::to($day, 'server');
2695 2692
 			$tz_exception = ($filter == 'tz_rrule');
2696 2693
 			//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2697 2694
 			//	'()[EVENT Server]: ' . $day->format('Ymd\THis') . " ($locts)");
2698 2695
 			if ($expand_all)
2699 2696
 			{
2700 2697
 				$remote_day = $remote_rrule->current();
2701
-				$remts = (int)Api\DateTime::to($remote_day,'server');
2698
+				$remts = (int)Api\DateTime::to($remote_day, 'server');
2702 2699
 			//	error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2703 2700
 			//	'()[EVENT Device]: ' . $remote_day->format('Ymd\THis') . " ($remts)");
2704 2701
 			}
@@ -2717,11 +2714,11 @@  discard block
 block discarded – undo
2717 2714
 						//	'() tz exception: ' . $day->format('Ymd\THis'));
2718 2715
 						if ($remote)
2719 2716
 						{
2720
-							$days[$locts]= $remts;
2717
+							$days[$locts] = $remts;
2721 2718
 						}
2722 2719
 						else
2723 2720
 						{
2724
-							$days[$remts]= $locts;
2721
+							$days[$remts] = $locts;
2725 2722
 						}
2726 2723
 					}
2727 2724
 				}
@@ -2743,18 +2740,18 @@  discard block
 block discarded – undo
2743 2740
 							{
2744 2741
 								if ($remote)
2745 2742
 								{
2746
-									$days[$locts]= $remts;
2743
+									$days[$locts] = $remts;
2747 2744
 								}
2748 2745
 								else
2749 2746
 								{
2750
-									$days[$remts]= $locts;
2747
+									$days[$remts] = $locts;
2751 2748
 								}
2752 2749
 							}
2753 2750
 						}
2754 2751
 					}
2755 2752
 					elseif ($filter != 'map')
2756 2753
 					{
2757
-						$days[$locts]= $locts;
2754
+						$days[$locts] = $locts;
2758 2755
 					}
2759 2756
 				}
2760 2757
 				elseif (($filter == 'map' || filter == 'tz_map') &&
@@ -2764,11 +2761,11 @@  discard block
 block discarded – undo
2764 2761
 					if ($expand_all)
2765 2762
 					{
2766 2763
 
2767
-						$days[$remts]= $locts;
2764
+						$days[$remts] = $locts;
2768 2765
 					}
2769 2766
 					else
2770 2767
 					{
2771
-						$days[$locts]= $locts;
2768
+						$days[$locts] = $locts;
2772 2769
 					}
2773 2770
 				}
2774 2771
 			}
@@ -2792,9 +2789,9 @@  discard block
 block discarded – undo
2792 2789
 	 */
2793 2790
 	function status_pseudo_exception($cal_id, $recur_date, $filter)
2794 2791
 	{
2795
-		static $recurrence_zero=null;
2796
-		static $cached_id=null;
2797
-		static $user=null;
2792
+		static $recurrence_zero = null;
2793
+		static $cached_id = null;
2794
+		static $user = null;
2798 2795
 
2799 2796
 		if (!isset($cached_id) || $cached_id != $cal_id)
2800 2797
 		{
@@ -2805,8 +2802,8 @@  discard block
 block discarded – undo
2805 2802
 				'cal_id' => $cal_id,
2806 2803
 				'cal_recur_date' => 0,
2807 2804
 			);
2808
-			foreach ($this->db->select($this->user_table,'cal_user_type,cal_user_id,cal_user_attendee,cal_status',$where,
2809
-				__LINE__,__FILE__,false,'','calendar') as $row)
2805
+			foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where,
2806
+				__LINE__, __FILE__, false, '', 'calendar') as $row)
2810 2807
 			{
2811 2808
 				switch ($row['cal_user_type'])
2812 2809
 				{
@@ -2829,8 +2826,8 @@  discard block
 block discarded – undo
2829 2826
 			'cal_id' => $cal_id,
2830 2827
 			'cal_recur_date' => $recur_date,
2831 2828
 		);
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)
2829
+		foreach ($this->db->select($this->user_table, 'cal_user_type,cal_user_id,cal_user_attendee,cal_status', $where,
2830
+			__LINE__, __FILE__, false, '', 'calendar') as $row)
2834 2831
 		{
2835 2832
 			switch ($row['cal_user_type'])
2836 2833
 			{
@@ -2927,14 +2924,14 @@  discard block
 block discarded – undo
2927 2924
 			}
2928 2925
 			$timezone = self::$tz_cache[$event['tzid']];
2929 2926
 		}
2930
-		$start_time = new Api\DateTime($event['start'],Api\DateTime::$server_timezone);
2927
+		$start_time = new Api\DateTime($event['start'], Api\DateTime::$server_timezone);
2931 2928
 		$start_time->setTimezone($timezone);
2932
-		$end_time = new Api\DateTime($event['end'],Api\DateTime::$server_timezone);
2929
+		$end_time = new Api\DateTime($event['end'], Api\DateTime::$server_timezone);
2933 2930
 		$end_time->setTimezone($timezone);
2934 2931
 		//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2935 2932
 		//	'(): ' . $start . '-' . $end);
2936
-		$start = Api\DateTime::to($start_time,'array');
2937
-		$end = Api\DateTime::to($end_time,'array');
2933
+		$start = Api\DateTime::to($start_time, 'array');
2934
+		$end = Api\DateTime::to($end_time, 'array');
2938 2935
 
2939 2936
 
2940 2937
 		return !$start['hour'] && !$start['minute'] && $end['hour'] == 23 && $end['minute'] == 59;
@@ -2948,7 +2945,7 @@  discard block
 block discarded – undo
2948 2945
 	 *
2949 2946
 	 * @return DateTime
2950 2947
 	 */
2951
-	function &startOfDay(Api\DateTime $time, $tz_id=null)
2948
+	function &startOfDay(Api\DateTime $time, $tz_id = null)
2952 2949
 	{
2953 2950
 		if (empty($tz_id))
2954 2951
 		{
@@ -2973,14 +2970,14 @@  discard block
 block discarded – undo
2973 2970
 	 * @param int $time =null new timestamp, default current (server-)time
2974 2971
 	 * @param int $modifier =null uid of the modifier, default current user
2975 2972
 	 */
2976
-	function updateModified($id, $update_master=false, $time=null, $modifier=null)
2973
+	function updateModified($id, $update_master = false, $time = null, $modifier = null)
2977 2974
 	{
2978 2975
 		if (is_null($time) || !$time) $time = time();
2979 2976
 		if (is_null($modifier)) $modifier = $GLOBALS['egw_info']['user']['account_id'];
2980 2977
 
2981 2978
 		$this->db->update($this->cal_table,
2982 2979
 			array('cal_modified' => $time, 'cal_modifier' => $modifier),
2983
-			array('cal_id' => $id), __LINE__,__FILE__, 'calendar');
2980
+			array('cal_id' => $id), __LINE__, __FILE__, 'calendar');
2984 2981
 
2985 2982
 		// if event is an exception: update modified of master, to force etag, ctag and sync-token change
2986 2983
 		if ($update_master)
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/images.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,17 +28,17 @@  discard block
 block discarded – undo
28 28
 
29 29
 include '../header.inc.php';
30 30
 
31
-$content = json_encode(Api\Image::map(preg_match('/^[a-z0-9_-]+$/i',$_GET['template']) ? $_GET['template'] : null, $_GET['svg']),
32
-	JSON_FORCE_OBJECT |	// export empty php-arrays as empty objects, not empty arrays
33
-	JSON_UNESCAPED_SLASHES | // do not escape slashes, smaller and better readable
31
+$content = json_encode(Api\Image::map(preg_match('/^[a-z0-9_-]+$/i', $_GET['template']) ? $_GET['template'] : null, $_GET['svg']),
32
+	JSON_FORCE_OBJECT|// export empty php-arrays as empty objects, not empty arrays
33
+	JSON_UNESCAPED_SLASHES|// do not escape slashes, smaller and better readable
34 34
 	(!empty($_GET['debug']) ? JSON_PRETTY_PRINT : 0));
35 35
 
36 36
 // use an etag over the image mapp
37 37
 $etag = '"'.md5($content).'"';
38 38
 
39 39
 // headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
40
-Api\Session::cache_control(86400);	// cache for one day
41
-Header('Content-Type: '.(empty($_GET['debug'])?'text/javascript':'application/json').'; charset=utf-8');
40
+Api\Session::cache_control(86400); // cache for one day
41
+Header('Content-Type: '.(empty($_GET['debug']) ? 'text/javascript' : 'application/json').'; charset=utf-8');
42 42
 Header('ETag: '.$etag);
43 43
 
44 44
 // if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 if (empty($_GET['debug'])) $content = 'egw.set_images('.$content.", egw && egw.window !== window);\n";
52 52
 
53 53
 // we run our own gzip compression, to set a correct Content-Length of the encoded content
54
-if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode'))
54
+if (in_array('gzip', explode(',', $_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode'))
55 55
 {
56 56
 	$content = gzencode($content);
57 57
 	header('Content-Encoding: gzip');
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,10 @@
 block discarded – undo
48 48
 	exit;
49 49
 }
50 50
 
51
-if (empty($_GET['debug'])) $content = 'egw.set_images('.$content.", egw && egw.window !== window);\n";
51
+if (empty($_GET['debug']))
52
+{
53
+	$content = 'egw.set_images('.$content.", egw && egw.window !== window);\n";
54
+}
52 55
 
53 56
 // we run our own gzip compression, to set a correct Content-Length of the encoded content
54 57
 if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode'))
Please login to merge, or discard this patch.
api/src/Framework/IncludeMgr.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	private function parse_file($file)
81 81
 	{
82 82
 		// file is from url and can contain query-params, eg. /phpgwapi/inc/jscalendar-setup.php?dateformat=d.m.Y&amp;lang=de
83
-		if (strpos($file,'?') !== false) list($file) = explode('?',$file);
83
+		if (strpos($file, '?') !== false) list($file) = explode('?', $file);
84 84
 
85 85
 		// Mark the file as parsed
86 86
 		$this->parsed_files[$file] = true;
@@ -284,17 +284,17 @@  discard block
 block discarded – undo
284 284
 	 * @returns the correct path on the server if the file is found or false, if the
285 285
 	 *  file is not found or no further processing is needed.
286 286
 	 */
287
-	private function translate_params($package, $file=null, $app='api')
287
+	private function translate_params($package, $file = null, $app = 'api')
288 288
 	{
289 289
 		if ($package[0] == '/' && is_readable(EGW_SERVER_ROOT.parse_url($path = $package, PHP_URL_PATH)) ||
290 290
 			// fix old /phpgwapi/js/ path by replacing it with /api/js/
291 291
 			substr($package, 0, 13) == '/phpgwapi/js/' && is_readable(EGW_SERVER_ROOT.parse_url($path = str_replace('/phpgwapi/js/', '/api/js/', $package), PHP_URL_PATH)) ||
292 292
 			$package[0] == '/' && is_readable(EGW_SERVER_ROOT.($path = $package)) ||
293
-			$package == '.' && is_readable(EGW_SERVER_ROOT.($path="/$app/js/$file.js")) ||
294
-			is_readable(EGW_SERVER_ROOT.($path="/$app/js/$package/$file.js")) ||
293
+			$package == '.' && is_readable(EGW_SERVER_ROOT.($path = "/$app/js/$file.js")) ||
294
+			is_readable(EGW_SERVER_ROOT.($path = "/$app/js/$package/$file.js")) ||
295 295
 			// fix not found by using app='api'
296
-			$app != 'api' && is_readable(EGW_SERVER_ROOT.($path="/api/js/$package/$file.js")) ||
297
-			$app != 'phpgwapi' && is_readable(EGW_SERVER_ROOT.($path="/phpgwapi/js/$package/$file.js")))
296
+			$app != 'api' && is_readable(EGW_SERVER_ROOT.($path = "/api/js/$package/$file.js")) ||
297
+			$app != 'phpgwapi' && is_readable(EGW_SERVER_ROOT.($path = "/phpgwapi/js/$package/$file.js")))
298 298
 		{
299 299
 			// normalise /./ to /
300 300
 			$path = str_replace('/./', '/', $path);
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 			// 	adding the ctime to all js files...
306 306
 			if (is_array($file))
307 307
 			{
308
-				foreach($file as $name => $val)
308
+				foreach ($file as $name => $val)
309 309
 				{
310 310
 					$args .= (empty($args) ? '?' : '&').$name.'='.urlencode($val);
311 311
 				}
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 	 * @param array $files
376 376
 	 * @param boolean $clear_files =false if true clear list of files, before including given ones
377 377
 	 */
378
-	public function include_files(array $files, $clear_files=false)
378
+	public function include_files(array $files, $clear_files = false)
379 379
 	{
380 380
 		if ($clear_files) $this->included_files = array();
381 381
 
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 	 * @param boolean $clear_files =false if true clear list of files after returning them
392 392
 	 * @return array
393 393
 	 */
394
-	public function get_included_files($clear_files=false)
394
+	public function get_included_files($clear_files = false)
395 395
 	{
396 396
 		$ret = array_keys($this->included_files);
397 397
 		if ($clear_files) $this->included_files = array();
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 
425 425
 	$paths = !empty($_GET['path']) ? (array)$_GET['path'] : (array)'/stylite/js/filemanager/filemanager.js';
426 426
 
427
-	foreach($paths as $path)
427
+	foreach ($paths as $path)
428 428
 	{
429 429
 		echo "\t<h1>".htmlspecialchars($path)."</h1>\n";
430 430
 		$mgr->include_js_file($path);
Please login to merge, or discard this patch.
Braces   +16 added lines, -4 removed lines patch added patch discarded remove patch
@@ -80,7 +80,10 @@  discard block
 block discarded – undo
80 80
 	private function parse_file($file)
81 81
 	{
82 82
 		// file is from url and can contain query-params, eg. /phpgwapi/inc/jscalendar-setup.php?dateformat=d.m.Y&amp;lang=de
83
-		if (strpos($file,'?') !== false) list($file) = explode('?',$file);
83
+		if (strpos($file,'?') !== false)
84
+		{
85
+			list($file) = explode('?',$file);
86
+		}
84 87
 
85 88
 		// Mark the file as parsed
86 89
 		$this->parsed_files[$file] = true;
@@ -326,12 +329,15 @@  discard block
 block discarded – undo
326 329
 			}
327 330
 		}
328 331
 
329
-		if (self::$DEBUG_MODE) // DEBUG_MODE is currently ALWAYS true. Comment this code out if you don't want error messages.
332
+		if (self::$DEBUG_MODE)
333
+		{
334
+			// DEBUG_MODE is currently ALWAYS true. Comment this code out if you don't want error messages.
330 335
 		{
331 336
 			//error_log(__METHOD__."($package,$file,$app) $path NOT found".($this->debug_processing_file ? " while processing file '{$this->debug_processing_file}'." : "!").' '.function_backtrace());
332 337
 		}
333 338
 
334 339
 		return false;
340
+		}
335 341
 	}
336 342
 
337 343
 	/**
@@ -377,7 +383,10 @@  discard block
 block discarded – undo
377 383
 	 */
378 384
 	public function include_files(array $files, $clear_files=false)
379 385
 	{
380
-		if ($clear_files) $this->included_files = array();
386
+		if ($clear_files)
387
+		{
388
+			$this->included_files = array();
389
+		}
381 390
 
382 391
 		foreach ($files as $file)
383 392
 		{
@@ -394,7 +403,10 @@  discard block
 block discarded – undo
394 403
 	public function get_included_files($clear_files=false)
395 404
 	{
396 405
 		$ret = array_keys($this->included_files);
397
-		if ($clear_files) $this->included_files = array();
406
+		if ($clear_files)
407
+		{
408
+			$this->included_files = array();
409
+		}
398 410
 		return $ret;
399 411
 	}
400 412
 
Please login to merge, or discard this patch.
api/src/Framework/Template.php 3 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.
Doc Comments   +6 added lines, -1 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 * @param string $parent name of tempalte containing $handle
157 157
 	 * @param string $handle name of part
158 158
 	 * @param string $name name of variable/placeholder
159
-	 * @return boolean
159
+	 * @return false|null
160 160
 	 */
161 161
 	function set_block($parent, $handle, $name = '')
162 162
 	{
@@ -311,6 +311,8 @@  discard block
 block discarded – undo
311 311
 
312 312
 	/**
313 313
 	 * This is short for finish parse
314
+	 * @param string $target
315
+	 * @param string $handle
314 316
 	 */
315 317
 	function fp($target, $handle, $append = False)
316 318
 	{
@@ -319,6 +321,8 @@  discard block
 block discarded – undo
319 321
 
320 322
 	/**
321 323
 	 * This is a short cut for print finish parse
324
+	 * @param string $target
325
+	 * @param string $handle
322 326
 	 */
323 327
 	function pfp($target, $handle, $append = False)
324 328
 	{
@@ -365,6 +369,7 @@  discard block
 block discarded – undo
365 369
 	 * Return undefined variables/placeholders of a handle
366 370
 	 *
367 371
 	 * @param string handle handle of a template
372
+	 * @param string $handle
368 373
 	 * @return array|boolean array with undefined variables as key and value, or false if none
369 374
 	 */
370 375
 	function get_undefined($handle)
Please login to merge, or discard this patch.
api/src/Framework/Tutorial.php 3 patches
Spacing   +7 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param array $content
34 34
 	 */
35
-	function popup ($content=null)
35
+	function popup($content = null)
36 36
 	{
37 37
 		// check and if not done register tutorial_menu hook
38 38
 		if (!Api\Hooks::exists('sidebox_all', 'api') ||
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		if (!is_array($content))
49 49
 		{
50 50
 			// Get tutorial object id
51
-			$tuid_indx = explode('-',$_GET['tuid']);
51
+			$tuid_indx = explode('-', $_GET['tuid']);
52 52
 			$appName = $tuid_indx[0];
53 53
 			$lang = $tuid_indx[1];
54 54
 			$id = $tuid_indx[2];
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		{
58 58
 			$appName = $content['list']['apps'];
59 59
 			$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
60
-			$id ="0";
60
+			$id = "0";
61 61
 		}
62 62
 		// read tutorials json file to fetch data
63 63
 		$tutorials = json_decode(self::getJsonData(), true);
@@ -74,8 +74,7 @@  discard block
 block discarded – undo
74 74
 		if (in_array($appName, array_keys($GLOBALS['egw_info']['user']['apps'])) || $appName === "introduction")
75 75
 		{
76 76
 			// fallback to english video
77
-			$tutorial = $tutorials[$appName][$lang][$id]? $tutorials[$appName][$lang][$id]:
78
-				$tutorials[$appName]['en'][$id];
77
+			$tutorial = $tutorials[$appName][$lang][$id] ? $tutorials[$appName][$lang][$id] : $tutorials[$appName]['en'][$id];
79 78
 
80 79
 			$list = array(
81 80
 				'apps' => $appName,
@@ -86,7 +85,7 @@  discard block
 block discarded – undo
86 85
 				$v ['onclick'] = 'app[egw.app_name()].tutorial_videoOnClick("'.$v['src'].'")';
87 86
 				array_push($list, $v);
88 87
 			}
89
-			$content = array (
88
+			$content = array(
90 89
 				'src' => $tutorial['src'],
91 90
 				'title' => $tutorial['title'],
92 91
 				'desc' => $tutorial['desc'],
@@ -137,13 +136,13 @@  discard block
 block discarded – undo
137 136
 	public static function tutorial_menu()
138 137
 	{
139 138
 		if (Api\Header\UserAgent::mobile()) return;
140
-		$tutorials = json_decode(self::getJsonData(),true);
139
+		$tutorials = json_decode(self::getJsonData(), true);
141 140
 		$appname = $GLOBALS['egw_info']['flags']['currentapp'];
142 141
 		if (!is_array($tutorials[$appname])) return false;
143 142
 		if (!$GLOBALS['egw_info']['server']['egw_tutorial_disable']
144 143
 			|| $GLOBALS['egw_info']['server']['egw_tutorial_disable'] == 'intro')
145 144
 		{
146
-			$file = Array (
145
+			$file = Array(
147 146
 				array(
148 147
 					'text'    => '<div id="egw_tutorial_'.$appname.'_sidebox" class="egwTutorial"/>',
149 148
 					'no_lang' => true,
Please login to merge, or discard this patch.
Braces   +16 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,7 +65,10 @@  discard block
 block discarded – undo
65 65
 		foreach (array_keys($tutorials) as $app)
66 66
 		{
67 67
 			// show only apps user has access to them
68
-			if (in_array($app, array_keys($GLOBALS['egw_info']['user']['apps']))) $apps [$app] = $app;
68
+			if (in_array($app, array_keys($GLOBALS['egw_info']['user']['apps'])))
69
+			{
70
+				$apps [$app] = $app;
71
+			}
69 72
 		}
70 73
 		$sel_options = array(
71 74
 			'apps' => $apps,
@@ -122,7 +125,10 @@  discard block
 block discarded – undo
122 125
 		{
123 126
 			$json = file_get_contents('http://www.egroupware.de/videos/tutorials.json');
124 127
 			// Fallback tutorials.json
125
-			if (!$json) $json = file_get_contents('api/setup/tutorials.json');
128
+			if (!$json)
129
+			{
130
+				$json = file_get_contents('api/setup/tutorials.json');
131
+			}
126 132
 			// Cache the json object for two hours
127 133
 			Api\Cache::setCache(Api\Cache::TREE, __CLASS__, 'egw_tutorial_json', $json, 7200);
128 134
 		}
@@ -136,10 +142,16 @@  discard block
 block discarded – undo
136 142
 	 */
137 143
 	public static function tutorial_menu()
138 144
 	{
139
-		if (Api\Header\UserAgent::mobile()) return;
145
+		if (Api\Header\UserAgent::mobile())
146
+		{
147
+			return;
148
+		}
140 149
 		$tutorials = json_decode(self::getJsonData(),true);
141 150
 		$appname = $GLOBALS['egw_info']['flags']['currentapp'];
142
-		if (!is_array($tutorials[$appname])) return false;
151
+		if (!is_array($tutorials[$appname]))
152
+		{
153
+			return false;
154
+		}
143 155
 		if (!$GLOBALS['egw_info']['server']['egw_tutorial_disable']
144 156
 			|| $GLOBALS['egw_info']['server']['egw_tutorial_disable'] == 'intro')
145 157
 		{
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@
 block discarded – undo
143 143
 		if (!$GLOBALS['egw_info']['server']['egw_tutorial_disable']
144 144
 			|| $GLOBALS['egw_info']['server']['egw_tutorial_disable'] == 'intro')
145 145
 		{
146
-			$file = Array (
146
+			$file = array (
147 147
 				array(
148 148
 					'text'    => '<div id="egw_tutorial_'.$appname.'_sidebox" class="egwTutorial"/>',
149 149
 					'no_lang' => true,
Please login to merge, or discard this patch.