Completed
Push — 16.1 ( 1e4888...9df24e )
by Ralf
12:06
created
api/src/Etemplate/Widget/Vfs.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -230,6 +230,7 @@
 block discarded – undo
230 230
 	* If the entry is not yet created, the file information is stored into the widget's value.
231 231
 	* When the form is submitted, the information for all files uploaded is available in the returned
232 232
 	* $content array and the application should deal with the file.
233
+	* @return string
233 234
 	*/
234 235
 	public static function store_file($path, $file)
235 236
 	{
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -224,13 +224,13 @@
 block discarded – undo
224 224
 	}
225 225
 
226 226
 	/**
227
-	* Ajax callback to receive an incoming file
228
-	*
229
-	* The incoming file is automatically placed into the appropriate VFS location.
230
-	* If the entry is not yet created, the file information is stored into the widget's value.
231
-	* When the form is submitted, the information for all files uploaded is available in the returned
232
-	* $content array and the application should deal with the file.
233
-	*/
227
+	 * Ajax callback to receive an incoming file
228
+	 *
229
+	 * The incoming file is automatically placed into the appropriate VFS location.
230
+	 * If the entry is not yet created, the file information is stored into the widget's value.
231
+	 * When the form is submitted, the information for all files uploaded is available in the returned
232
+	 * $content array and the application should deal with the file.
233
+	 */
234 234
 	public static function store_file($path, $file)
235 235
 	{
236 236
 		$name = $_REQUEST['widget_id'];
Please login to merge, or discard this patch.
Braces   +40 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,7 +27,10 @@  discard block
 block discarded – undo
27 27
 
28 28
 	public function __construct($xml='')
29 29
 	{
30
-		if($xml) parent::__construct($xml);
30
+		if($xml)
31
+		{
32
+			parent::__construct($xml);
33
+		}
31 34
 	}
32 35
 
33 36
 	/**
@@ -64,9 +67,15 @@  discard block
 block discarded – undo
64 67
 				}
65 68
 				$value =& self::get_array(self::$request->content, $form_name, true);
66 69
 				$path = Api\Link::vfs_path($app,$id,'',true);
67
-				if (!empty($relpath)) $path .= '/'.$relpath;
70
+				if (!empty($relpath))
71
+				{
72
+					$path .= '/'.$relpath;
73
+				}
68 74
 
69
-				if (true) $value = array();
75
+				if (true)
76
+				{
77
+					$value = array();
78
+				}
70 79
 
71 80
 				// Single file, already existing
72 81
 				if (substr($path,-1) != '/' && Api\Vfs::file_exists($path) && !Api\Vfs::is_dir($path))
@@ -194,7 +203,10 @@  discard block
 block discarded – undo
194 203
 				$replace[substr($link['id']['tmp_name'], strlen(Api\Vfs::PREFIX))] =
195 204
 					Api\Link::vfs_path($app, $id, Api\Vfs::basename($link['id']['tmp_name']), true);
196 205
 
197
-				if (!in_array($matches[1], $remove_dir)) $remove_dir[] = $matches[1];
206
+				if (!in_array($matches[1], $remove_dir))
207
+				{
208
+					$remove_dir[] = $matches[1];
209
+				}
198 210
 			}
199 211
 		}
200 212
 		if ($replace)
@@ -218,7 +230,10 @@  discard block
 block discarded – undo
218 230
 	 */
219 231
 	static function get_temp_dir($app, $postfix=null)
220 232
 	{
221
-		if (!isset($postfix)) $postfix = md5(time().session_id());
233
+		if (!isset($postfix))
234
+		{
235
+			$postfix = md5(time().session_id());
236
+		}
222 237
 
223 238
 		return '/home/'.$GLOBALS['egw_info']['user']['account_lid'].'/.tmp/'.$app.'_'.$postfix;
224 239
 	}
@@ -245,10 +260,13 @@  discard block
 block discarded – undo
245 260
 		{
246 261
 			// add extension to path
247 262
 			$parts = explode('.',$filename);
248
-			if (($extension = array_pop($parts)) && Api\MimeMagic::ext2mime($extension))       // really an extension --> add it to path
263
+			if (($extension = array_pop($parts)) && Api\MimeMagic::ext2mime($extension))
264
+			{
265
+				// really an extension --> add it to path
249 266
 			{
250 267
 				$path .= '.'.$extension;
251 268
 			}
269
+			}
252 270
 		}
253 271
 		else    // multiple upload with dir given (trailing slash)
254 272
 		{
@@ -294,7 +312,10 @@  discard block
 block discarded – undo
294 312
 		switch($this->type)
295 313
 		{
296 314
 			case 'vfs-upload':
297
-				if(!is_array($value)) $value = array();
315
+				if(!is_array($value))
316
+				{
317
+					$value = array();
318
+				}
298 319
 				/* Check & skip files that made it asyncronously
299 320
 				list($app,$id,$relpath) = explode(':',$this->id,3);
300 321
 				//...
@@ -305,7 +326,10 @@  discard block
 block discarded – undo
305 326
 				parent::validate($cname, $content, $validated);
306 327
 				break;
307 328
 		}
308
-		if (true) $valid = $value;
329
+		if (true)
330
+		{
331
+			$valid = $value;
332
+		}
309 333
 	}
310 334
 
311 335
 	/**
@@ -317,14 +341,20 @@  discard block
 block discarded – undo
317 341
 		if (empty($id) || $id == 'undefined')
318 342
 		{
319 343
 			static $tmppath = array();      // static var, so all vfs-uploads get created in the same temporary dir
320
-			if (!isset($tmppath[$app])) $tmppath[$app] = self::get_temp_dir ($app);
344
+			if (!isset($tmppath[$app]))
345
+			{
346
+				$tmppath[$app] = self::get_temp_dir ($app);
347
+			}
321 348
 			$path = $tmppath[$app];
322 349
 		}
323 350
 		else
324 351
 		{
325 352
 			$path = Api\Link::vfs_path($app,$id,'',true);
326 353
 		}
327
-		if (!empty($relpath)) $path .= '/'.$relpath;
354
+		if (!empty($relpath))
355
+		{
356
+			$path .= '/'.$relpath;
357
+		}
328 358
 		return $path;
329 359
 	}
330 360
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -41 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
 	// Legacy option for vfs-upload
26 26
 	protected $legacy_options = "mime";
27 27
 
28
-	public function __construct($xml='')
28
+	public function __construct($xml = '')
29 29
 	{
30
-		if($xml) parent::__construct($xml);
30
+		if ($xml) parent::__construct($xml);
31 31
 	}
32 32
 
33 33
 	/**
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function beforeSendToClient($cname, $expand = array())
38 38
 	{
39
-		if($this->type == 'vfs-upload' || $this->attrs['type'] == 'vfs-upload')
39
+		if ($this->type == 'vfs-upload' || $this->attrs['type'] == 'vfs-upload')
40 40
 		{
41 41
 			$form_name = self::form_name($cname, $this->id, $expand ? $expand : array('cont'=>self::$request->content));
42
-			if($this->attrs['path'])
42
+			if ($this->attrs['path'])
43 43
 			{
44 44
 				$path = $this->attrs['path'];
45 45
 			}
@@ -50,26 +50,26 @@  discard block
 block discarded – undo
50 50
 
51 51
 			$this->setElementAttribute($form_name, 'path', $path);
52 52
 			// ID maps to path - check there for any existing files
53
-			list($app,$id,$relpath) = explode(':',$path,3);
54
-			if($app && $id)
53
+			list($app, $id, $relpath) = explode(':', $path, 3);
54
+			if ($app && $id)
55 55
 			{
56
-				if(!is_numeric($id))
56
+				if (!is_numeric($id))
57 57
 				{
58
-					$_id = self::expand_name($id,0,0,0,0,self::$request->content);
59
-					if($_id != $id)
58
+					$_id = self::expand_name($id, 0, 0, 0, 0, self::$request->content);
59
+					if ($_id != $id)
60 60
 					{
61 61
 						$id = $_id;
62 62
 						$form_name = "$app:$id:$relpath";
63 63
 					}
64 64
 				}
65
-				$value =& self::get_array(self::$request->content, $form_name, true);
66
-				$path = Api\Link::vfs_path($app,$id,'',true);
65
+				$value = & self::get_array(self::$request->content, $form_name, true);
66
+				$path = Api\Link::vfs_path($app, $id, '', true);
67 67
 				if (!empty($relpath)) $path .= '/'.$relpath;
68 68
 
69 69
 				if (true) $value = array();
70 70
 
71 71
 				// Single file, already existing
72
-				if (substr($path,-1) != '/' && Api\Vfs::file_exists($path) && !Api\Vfs::is_dir($path))
72
+				if (substr($path, -1) != '/' && Api\Vfs::file_exists($path) && !Api\Vfs::is_dir($path))
73 73
 				{
74 74
 					$file = Api\Vfs::stat($path);
75 75
 					$file['path'] = $path;
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
 					$value = array($file);
79 79
 				}
80 80
 				// Single file, missing extension in path
81
-				else if (substr($path, -1) != '/' && !Api\Vfs::file_exists($path) && $relpath && substr($relpath,-4,1) !== '.')
81
+				else if (substr($path, -1) != '/' && !Api\Vfs::file_exists($path) && $relpath && substr($relpath, -4, 1) !== '.')
82 82
 				{
83
-					$find = Api\Vfs::find(substr($path,0, - strlen($relpath)), array(
83
+					$find = Api\Vfs::find(substr($path, 0, - strlen($relpath)), array(
84 84
 						'type' => 'f',
85 85
 						'maxdepth' => 1,
86
-						'name' => $relpath . '*'
86
+						'name' => $relpath.'*'
87 87
 					));
88
-					foreach($find as $file)
88
+					foreach ($find as $file)
89 89
 					{
90 90
 						$file_info = Api\Vfs::stat($file);
91 91
 						$file_info['path'] = $file;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 				else if (substr($path, -1) == '/' && Api\Vfs::is_dir($path))
98 98
 				{
99 99
 					$scan = Api\Vfs::scandir($path);
100
-					foreach($scan as $file)
100
+					foreach ($scan as $file)
101 101
 					{
102 102
 						$file_info = Api\Vfs::stat("$path$file");
103 103
 						$file_info['path'] = "$path$file";
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	public static function ajax_upload()
114 114
 	{
115 115
 		parent::ajax_upload();
116
-		foreach($_FILES as $file)
116
+		foreach ($_FILES as $file)
117 117
 		{
118 118
 			self::store_file($_REQUEST['path'] ? $_REQUEST['path'] : $_REQUEST['widget_id'], $file);
119 119
 		}
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	{
127 127
 		$request_id = urldecode($_REQUEST['request_id']);
128 128
 		$widget_id = $_REQUEST['widget_id'];
129
-		if(!self::$request = Etemplate\Request::read($request_id))
129
+		if (!self::$request = Etemplate\Request::read($request_id))
130 130
 		{
131 131
 			$error = lang("Could not read session");
132 132
 		}
@@ -143,8 +143,7 @@  discard block
 block discarded – undo
143 143
 		else
144 144
 		{
145 145
 			$data = self::$request->content[$widget_id];
146
-			$path = self::store_file($path = (!is_array($data) && $data[0] == '/' ? $data :
147
-				self::get_vfs_path($data['to_app'].':'.$data['to_id'])).'/', $_FILES['upload']);
146
+			$path = self::store_file($path = (!is_array($data) && $data[0] == '/' ? $data : self::get_vfs_path($data['to_app'].':'.$data['to_id'])).'/', $_FILES['upload']);
148 147
 
149 148
 			// store temp. vfs-path like links to be able to move it to correct location after entry is stored
150 149
 			if (!$data['to_id'] || is_array($data['to_id']))
@@ -187,10 +186,10 @@  discard block
 block discarded – undo
187 186
 	static function fix_html_dragins($app, $id, array $links, &$html)
188 187
 	{
189 188
 		$replace = $remove_dir = array();
190
-		foreach($links as $link)
189
+		foreach ($links as $link)
191 190
 		{
192 191
 			$matches = null;
193
-			if (is_array($link) && preg_match('|^'.preg_quote(Api\Vfs::PREFIX,'|').'('.preg_quote(self::get_temp_dir($app, ''), '|').'[^/]+)/|', $link['id']['tmp_name'], $matches))
192
+			if (is_array($link) && preg_match('|^'.preg_quote(Api\Vfs::PREFIX, '|').'('.preg_quote(self::get_temp_dir($app, ''), '|').'[^/]+)/|', $link['id']['tmp_name'], $matches))
194 193
 			{
195 194
 				$replace[substr($link['id']['tmp_name'], strlen(Api\Vfs::PREFIX))] =
196 195
 					Api\Link::vfs_path($app, $id, Api\Vfs::basename($link['id']['tmp_name']), true);
@@ -202,7 +201,7 @@  discard block
 block discarded – undo
202 201
 		{
203 202
 			$html = strtr($old = $html, $replace);
204 203
 			// remove all dirs
205
-			foreach($remove_dir as $dir)
204
+			foreach ($remove_dir as $dir)
206 205
 			{
207 206
 				Api\Vfs::remove($dir);
208 207
 			}
@@ -217,7 +216,7 @@  discard block
 block discarded – undo
217 216
 	 * @param string $postfix =null default random id
218 217
 	 * @return string vfs path
219 218
 	 */
220
-	static function get_temp_dir($app, $postfix=null)
219
+	static function get_temp_dir($app, $postfix = null)
221 220
 	{
222 221
 		if (!isset($postfix)) $postfix = md5(time().session_id());
223 222
 
@@ -237,15 +236,15 @@  discard block
 block discarded – undo
237 236
 		$name = $_REQUEST['widget_id'];
238 237
 
239 238
 		// Find real path
240
-		if($path[0] != '/')
239
+		if ($path[0] != '/')
241 240
 		{
242 241
 			$path = self::get_vfs_path($path);
243 242
 		}
244 243
 		$filename = $file['name'];
245
-		if (substr($path,-1) != '/')
244
+		if (substr($path, -1) != '/')
246 245
 		{
247 246
 			// add extension to path
248
-			$parts = explode('.',$filename);
247
+			$parts = explode('.', $filename);
249 248
 			if (($extension = array_pop($parts)) && Api\MimeMagic::ext2mime($extension))       // really an extension --> add it to path
250 249
 			{
251 250
 				$path .= '.'.$extension;
@@ -257,17 +256,17 @@  discard block
 block discarded – undo
257 256
 		}
258 257
 		if (!($dir = Api\Vfs::dirname($path)))
259 258
 		{
260
-			self::set_validation_error($name,lang('Error create parent directory %1!', "dirname('$path') === false"));
259
+			self::set_validation_error($name, lang('Error create parent directory %1!', "dirname('$path') === false"));
261 260
 			return false;
262 261
 		}
263
-		if (!Api\Vfs::file_exists($dir) && !Api\Vfs::mkdir($dir,null,STREAM_MKDIR_RECURSIVE))
262
+		if (!Api\Vfs::file_exists($dir) && !Api\Vfs::mkdir($dir, null, STREAM_MKDIR_RECURSIVE))
264 263
 		{
265
-			self::set_validation_error($name,lang('Error create parent directory %1!',Api\Vfs::decodePath($dir)));
264
+			self::set_validation_error($name, lang('Error create parent directory %1!', Api\Vfs::decodePath($dir)));
266 265
 			return false;
267 266
 		}
268
-		if (!copy($file['tmp_name'],Api\Vfs::PREFIX.$path))
267
+		if (!copy($file['tmp_name'], Api\Vfs::PREFIX.$path))
269 268
 		{
270
-			self::set_validation_error($name,lang('Error copying uploaded file to vfs!'));
269
+			self::set_validation_error($name, lang('Error copying uploaded file to vfs!'));
271 270
 			return false;
272 271
 		}
273 272
 
@@ -286,7 +285,7 @@  discard block
 block discarded – undo
286 285
 	 * @param array $content
287 286
 	 * @param array &$validated=array() validated content
288 287
 	 */
289
-	public function validate($cname, array $expand, array $content, &$validated=array())
288
+	public function validate($cname, array $expand, array $content, &$validated = array())
290 289
 	{
291 290
 		// do not validate, as it would overwrite preserved values with null!
292 291
 		if (in_array($this->type, array('vfs-size', 'vfs-uid', 'vfs-gid', 'vfs', 'vfs-mime')))
@@ -295,12 +294,12 @@  discard block
 block discarded – undo
295 294
 		}
296 295
 		$form_name = self::form_name($cname, $this->id, $expand);
297 296
 		$value = $value_in = self::get_array($content, $form_name);
298
-		$valid =& self::get_array($validated, $form_name, true);
297
+		$valid = & self::get_array($validated, $form_name, true);
299 298
 
300
-		switch($this->type)
299
+		switch ($this->type)
301 300
 		{
302 301
 			case 'vfs-upload':
303
-				if(!is_array($value)) $value = array();
302
+				if (!is_array($value)) $value = array();
304 303
 				/* Check & skip files that made it asyncronously
305 304
 				list($app,$id,$relpath) = explode(':',$this->id,3);
306 305
 				//...
@@ -319,16 +318,16 @@  discard block
 block discarded – undo
319 318
 	 */
320 319
 	public static function get_vfs_path($path)
321 320
 	{
322
-		list($app,$id,$relpath) = explode(':',$path,3);
321
+		list($app, $id, $relpath) = explode(':', $path, 3);
323 322
 		if (empty($id) || $id == 'undefined')
324 323
 		{
325
-			static $tmppath = array();      // static var, so all vfs-uploads get created in the same temporary dir
326
-			if (!isset($tmppath[$app])) $tmppath[$app] = self::get_temp_dir ($app);
324
+			static $tmppath = array(); // static var, so all vfs-uploads get created in the same temporary dir
325
+			if (!isset($tmppath[$app])) $tmppath[$app] = self::get_temp_dir($app);
327 326
 			$path = $tmppath[$app];
328 327
 		}
329 328
 		else
330 329
 		{
331
-			$path = Api\Link::vfs_path($app,$id,'',true);
330
+			$path = Api\Link::vfs_path($app, $id, '', true);
332 331
 		}
333 332
 		if (!empty($relpath)) $path .= '/'.$relpath;
334 333
 		return $path;
Please login to merge, or discard this patch.
api/src/Storage.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -210,12 +210,12 @@
 block discarded – undo
210 210
 	}
211 211
 
212 212
 	/**
213
-	* saves custom field data
214
-	*
215
-	* @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #)
216
-	* @param array $extra_cols =array() extra-data to be saved
217
-	* @return bool false on success, errornumber on failure
218
-	*/
213
+	 * saves custom field data
214
+	 *
215
+	 * @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #)
216
+	 * @param array $extra_cols =array() extra-data to be saved
217
+	 * @return bool false on success, errornumber on failure
218
+	 */
219 219
 	function save_customfields($data, array $extra_cols=array())
220 220
 	{
221 221
 		foreach (array_keys((array)$this->customfields) as $name)
Please login to merge, or discard this patch.
Spacing   +100 added lines, -102 removed lines patch added patch discarded remove patch
@@ -118,41 +118,41 @@  discard block
 block discarded – undo
118 118
 	 * @param boolean $allow_multiple_values =false should we allow AND store multiple values (1:N relations)
119 119
 	 * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use DateTime objects
120 120
 	 */
121
-	function __construct($app,$table,$extra_table,$column_prefix='',
122
-		$extra_key='_name',$extra_value='_value',$extra_id='_id',
123
-		Db $db=null,$no_clone=true,$allow_multiple_values=false,$timestamp_type=null)
121
+	function __construct($app, $table, $extra_table, $column_prefix = '',
122
+		$extra_key = '_name', $extra_value = '_value', $extra_id = '_id',
123
+		Db $db = null, $no_clone = true, $allow_multiple_values = false, $timestamp_type = null)
124 124
 	{
125 125
 		// calling the Storage\Base constructor
126
-		parent::__construct($app,$table,$db,$column_prefix,$no_clone,$timestamp_type);
126
+		parent::__construct($app, $table, $db, $column_prefix, $no_clone, $timestamp_type);
127 127
 
128 128
 		$this->allow_multiple_values = $allow_multiple_values;
129 129
 		$this->extra_table = $extra_table;
130
-		if (!$this->extra_id) $this->extra_id = $this->autoinc_id;	// default to auto id of regular table
130
+		if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table
131 131
 
132 132
 		// if names from columns of extra table are only postfixes (starting with _), prepend column prefix
133
-		if (!($prefix=$column_prefix))
133
+		if (!($prefix = $column_prefix))
134 134
 		{
135
-			list($prefix) = explode('_',$this->autoinc_id);
135
+			list($prefix) = explode('_', $this->autoinc_id);
136 136
 		}
137
-		elseif(substr($prefix,-1) == '_')
137
+		elseif (substr($prefix, -1) == '_')
138 138
 		{
139
-			$prefix = substr($prefix,0,-1);	// remove trailing underscore from column prefix parameter
139
+			$prefix = substr($prefix, 0, -1); // remove trailing underscore from column prefix parameter
140 140
 		}
141
-		foreach(array(
141
+		foreach (array(
142 142
 			'extra_id' => $extra_id,
143 143
 			'extra_key' => $extra_key,
144 144
 			'extra_value' => $extra_value
145 145
 		) as $col => $val)
146 146
 		{
147 147
 			$this->$col = $col_name = $val;
148
-			if ($col_name[0] == '_') $this->$col = $prefix . $val;
148
+			if ($col_name[0] == '_') $this->$col = $prefix.$val;
149 149
 		}
150 150
 		// some sanity checks, maybe they should be active only for development
151
-		if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table)))
151
+		if (!($extra_defs = $this->db->get_table_definitions($app, $extra_table)))
152 152
 		{
153 153
 			throw new Exception\WrongParameter("extra table $extra_table is NOT defined!");
154 154
 		}
155
-		foreach(array('extra_id','extra_key','extra_value') as $col)
155
+		foreach (array('extra_id', 'extra_key', 'extra_value') as $col)
156 156
 		{
157 157
 			if (!$this->$col || !isset($extra_defs['fd'][$this->$col]))
158 158
 			{
@@ -177,23 +177,23 @@  discard block
 block discarded – undo
177 177
 	 * @param array $field_names =null custom fields to read, default all
178 178
 	 * @return array id => $this->cf_field(name) => value
179 179
 	 */
180
-	function read_customfields($ids,$field_names=null)
180
+	function read_customfields($ids, $field_names = null)
181 181
 	{
182 182
 		if (is_null($field_names)) $field_names = array_keys($this->customfields);
183 183
 
184
-		foreach((array)$ids as $key => $id)
184
+		foreach ((array)$ids as $key => $id)
185 185
 		{
186 186
 			if (!(int)$id && is_array($ids)) unset($ids[$key]);
187 187
 		}
188
-		if (!$ids || !$field_names) return array();	// nothing to do
188
+		if (!$ids || !$field_names) return array(); // nothing to do
189 189
 
190 190
 		$entries = array();
191
-		foreach($this->db->select($this->extra_table,'*',array(
191
+		foreach ($this->db->select($this->extra_table, '*', array(
192 192
 			$this->extra_id => $ids,
193 193
 			$this->extra_key => $field_names,
194
-		),__LINE__,__FILE__,false,'',$this->app) as $row)
194
+		), __LINE__, __FILE__, false, '', $this->app) as $row)
195 195
 		{
196
-			$entry =& $entries[$row[$this->extra_id]];
196
+			$entry = & $entries[$row[$this->extra_id]];
197 197
 			if (!is_array($entry)) $entry = array();
198 198
 			$field = $this->get_cf_field($row[$this->extra_key]);
199 199
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	* @param array $extra_cols =array() extra-data to be saved
217 217
 	* @return bool false on success, errornumber on failure
218 218
 	*/
219
-	function save_customfields($data, array $extra_cols=array())
219
+	function save_customfields($data, array $extra_cols = array())
220 220
 	{
221 221
 		foreach (array_keys((array)$this->customfields) as $name)
222 222
 		{
@@ -229,22 +229,21 @@  discard block
 block discarded – undo
229 229
 			$is_multiple = $this->is_multiple($name);
230 230
 
231 231
 			// we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index
232
-			if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
232
+			if (empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
233 233
 			{
234
-				$this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app);
235
-				if (empty($data[$field])) continue;	// nothing else to do for empty values
234
+				$this->db->delete($this->extra_table, $where, __LINE__, __FILE__, $this->app);
235
+				if (empty($data[$field])) continue; // nothing else to do for empty values
236 236
 			}
237
-			foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) :
238
-				// regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
237
+			foreach ($is_multiple && !is_array($data[$field]) ? explode(',', $data[$field]) : // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
239 238
 				(array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value)
240 239
 			{
241
-				if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app))
240
+				if (!$this->db->insert($this->extra_table, array($this->extra_value => $value) + $extra_cols, $where, __LINE__, __FILE__, $this->app))
242 241
 				{
243 242
 					return $this->db->Errno;
244 243
 				}
245 244
 			}
246 245
 		}
247
-		return false;	// no error
246
+		return false; // no error
248 247
 	}
249 248
 
250 249
 	/**
@@ -260,7 +259,7 @@  discard block
 block discarded – undo
260 259
 
261 260
 		if ($this->customfields)
262 261
 		{
263
-			foreach(array_keys($this->customfields) as $name)
262
+			foreach (array_keys($this->customfields) as $name)
264 263
 			{
265 264
 				if (isset($new[$field = $this->get_cf_field($name)]))
266 265
 				{
@@ -280,16 +279,16 @@  discard block
 block discarded – undo
280 279
 	 * @param string $join sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
281 280
 	 * @return array|boolean data if row could be retrived else False
282 281
 	 */
283
-	function read($keys,$extra_cols='',$join='')
282
+	function read($keys, $extra_cols = '', $join = '')
284 283
 	{
285
-		if (!parent::read($keys,$extra_cols,$join))
284
+		if (!parent::read($keys, $extra_cols, $join))
286 285
 		{
287 286
 			return false;
288 287
 		}
289 288
 		if (($id = (int)$this->data[$this->db_key_cols[$this->autoinc_id]]) && $this->customfields &&
290 289
 			($cfs = $this->read_customfields($id)))
291 290
 		{
292
-			$this->data = array_merge($this->data,$cfs[$id]);
291
+			$this->data = array_merge($this->data, $cfs[$id]);
293 292
 		}
294 293
 		return $this->data;
295 294
 	}
@@ -303,14 +302,14 @@  discard block
 block discarded – undo
303 302
 	 * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows!
304 303
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
305 304
 	 */
306
-	function save($keys=null,$extra_where=null)
305
+	function save($keys = null, $extra_where = null)
307 306
 	{
308 307
 		if (is_array($keys) && count($keys) && !isset($keys[0]))	// allow to use an etag, eg array('etag=etag+1')
309 308
 		{
310 309
 			$this->data_merge($keys);
311 310
 			$keys = null;
312 311
 		}
313
-		$ret = parent::save($keys,$extra_where);
312
+		$ret = parent::save($keys, $extra_where);
314 313
 
315 314
 		if ($ret == 0 && $this->customfields)
316 315
 		{
@@ -328,26 +327,26 @@  discard block
 block discarded – undo
328 327
 	 * @param boolean $only_return_ids =false return $ids of delete call to db object, but not run it (can be used by extending classes!)
329 328
 	 * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids
330 329
 	 */
331
-	function delete($keys=null,$only_return_ids=false)
330
+	function delete($keys = null, $only_return_ids = false)
332 331
 	{
333 332
 		if ($this->customfields || $only_return_ids)
334 333
 		{
335
-			$query = parent::delete($keys,true);
334
+			$query = parent::delete($keys, true);
336 335
 			// check if query contains more then the id's
337 336
 			if (!isset($query[$this->autoinc_id]) || count($query) != 1)
338 337
 			{
339
-				foreach($this->db->select($this->table_name,$this->autoinc_id,$query,__LINE__,__FILE__,false,'',$this->app) as $row)
338
+				foreach ($this->db->select($this->table_name, $this->autoinc_id, $query, __LINE__, __FILE__, false, '', $this->app) as $row)
340 339
 				{
341 340
 					$ids[] = $row[$this->autoinc_id];
342 341
 				}
343
-				if (!$ids) return 0;	// no rows affected
342
+				if (!$ids) return 0; // no rows affected
344 343
 			}
345 344
 			else
346 345
 			{
347 346
 				$ids = (array)$query[$this->autoinc_id];
348 347
 			}
349 348
 			if ($only_return_ids) return $ids;
350
-			$this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__);
349
+			$this->db->delete($this->extra_table, array($this->extra_id => $ids), __LINE__, __FILE__);
351 350
 		}
352 351
 		return parent::delete($keys);
353 352
 	}
@@ -370,32 +369,32 @@  discard block
 block discarded – undo
370 369
 	 * @param string|array $extra_cols =array()
371 370
 	 * @return int total number of rows
372 371
 	 */
373
-	function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array())
372
+	function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array())
374 373
 	{
375
-		parent::get_rows($query,$rows,$readonlys,$join,$need_full_no_count,$only_keys,$extra_cols);
374
+		parent::get_rows($query, $rows, $readonlys, $join, $need_full_no_count, $only_keys, $extra_cols);
376 375
 
377
-		$selectcols = $query['selectcols'] ? explode(',',$query['selectcols']) : array();
376
+		$selectcols = $query['selectcols'] ? explode(',', $query['selectcols']) : array();
378 377
 
379
-		if ($rows && $this->customfields && (!$selectcols || in_array('customfields',$selectcols)))
378
+		if ($rows && $this->customfields && (!$selectcols || in_array('customfields', $selectcols)))
380 379
 		{
381 380
 			$id2keys = array();
382
-			foreach($rows as $key => $row)
381
+			foreach ($rows as $key => $row)
383 382
 			{
384 383
 				$id2keys[$row[$this->db_key_cols[$this->autoinc_id]]] = $key;
385 384
 			}
386 385
 			// check if only certain cf's to show
387 386
 			if (!in_array('customfields', $selectcols))
388 387
 			{
389
-				foreach($selectcols as $col)
388
+				foreach ($selectcols as $col)
390 389
 				{
391 390
 					if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col);
392 391
 				}
393 392
 			}
394
-			if (($cfs = $this->read_customfields(array_keys($id2keys),$fields)))
393
+			if (($cfs = $this->read_customfields(array_keys($id2keys), $fields)))
395 394
 			{
396
-				foreach($cfs as $id => $data)
395
+				foreach ($cfs as $id => $data)
397 396
 				{
398
-					$rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]],$data);
397
+					$rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]], $data);
399 398
 				}
400 399
 			}
401 400
 		}
@@ -422,12 +421,12 @@  discard block
 block discarded – undo
422 421
 	 * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false
423 422
 	 * @return array|NULL array of matching rows (the row is an array of the cols) or NULL
424 423
 	 */
425
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
424
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false)
426 425
 	{
427 426
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
428 427
 		if (!$this->customfields)
429 428
 		{
430
-			return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
429
+			return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
431 430
 		}
432 431
 		if ($only_keys === false)
433 432
 		{
@@ -436,7 +435,7 @@  discard block
 block discarded – undo
436 435
 		// if string given as criteria --> search in all (or $this->columns_to_search) columns including custom fields
437 436
 		if ($criteria && is_string($criteria))
438 437
 		{
439
-			$criteria = $this->search2criteria($criteria,$wildcard,$op);
438
+			$criteria = $this->search2criteria($criteria, $wildcard, $op);
440 439
 		}
441 440
 		if ($criteria && is_array($criteria))
442 441
 		{
@@ -445,10 +444,10 @@  discard block
 block discarded – undo
445 444
 			{
446 445
 				if (($negate = $criteria[$this->extra_value][0] === '!'))
447 446
 				{
448
-					$criteria[$this->extra_value] = substr($criteria[$this->extra_value],1);
447
+					$criteria[$this->extra_value] = substr($criteria[$this->extra_value], 1);
449 448
 				}
450
-				$criteria[] = $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : '').
451
-					$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' .
449
+				$criteria[] = $this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : '').
450
+					$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.
452 451
 					$this->db->quote($wildcard.$criteria[$this->extra_value].$wildcard);
453 452
 				unset($criteria[$this->extra_value]);
454 453
 			}
@@ -457,14 +456,14 @@  discard block
 block discarded – undo
457 456
 			{
458 457
 				if ($criteria[$this->autoinc_id])
459 458
 				{
460
-					$criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',
459
+					$criteria[] = $this->db->expression($this->table_name, $this->table_name.'.',
461 460
 						array($this->autoinc_id => $criteria[$this->autoinc_id]));
462 461
 				}
463 462
 				unset($criteria[$this->autoinc_id]);
464 463
 			}
465 464
 			// replace ambiguous column with (an exact match of) table_name.column
466 465
 			$extra_join_added = $join && strpos($join, $this->extra_join) !== false;
467
-			foreach($criteria as $name => $val)
466
+			foreach ($criteria as $name => $val)
468 467
 			{
469 468
 				// only add extra_join, if we really need it
470 469
 				if (!$extra_join_added && (
@@ -476,9 +475,9 @@  discard block
 block discarded – undo
476 475
 					$extra_join_added = true;
477 476
 				}
478 477
 				$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
479
-				if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)])
478
+				if (is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)])
480 479
 				{
481
-					$criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
480
+					$criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
482 481
 						array_search($name, $this->db_cols) => $val,
483 482
 					));
484 483
 					unset($criteria[$name]);
@@ -490,12 +489,12 @@  discard block
 block discarded – undo
490 489
 						$name = substr($name, 1);
491 490
 						if (($negate = $criteria[$name][0] === '!'))
492 491
 						{
493
-							$val = substr($val,1);
492
+							$val = substr($val, 1);
494 493
 						}
495
-						$cfcriteria[] = '(' . $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : '').
496
-							$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' .
497
-							$this->db->quote($wildcard.$val.$wildcard) . ' AND ' .
498
-							$this->extra_table.'.'.$this->extra_key . ' = ' . $this->db->quote($name) .
494
+						$cfcriteria[] = '('.$this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : '').
495
+							$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.
496
+							$this->db->quote($wildcard.$val.$wildcard).' AND '.
497
+							$this->extra_table.'.'.$this->extra_key.' = '.$this->db->quote($name).
499 498
 							')';
500 499
 						unset($criteria[self::CF_PREFIX.$name]);
501 500
 					}
@@ -507,38 +506,38 @@  discard block
 block discarded – undo
507 506
 					}
508 507
 				}
509 508
 			}
510
-			if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria);
509
+			if ($cfcriteria && $op == 'OR') $criteria[] = implode(' OR ', $cfcriteria);
511 510
 		}
512
-		if($only_keys === true)
511
+		if ($only_keys === true)
513 512
 		{
514 513
 			// Expand to keys here, so table_name can be prepended below
515 514
 			$only_keys = array_values($this->db_key_cols);
516 515
 		}
517 516
 		// replace ambiguous column with (an exact match of) table_name.column
518
-		if(is_array($only_keys))
517
+		if (is_array($only_keys))
519 518
 		{
520
-			foreach($only_keys as $key => &$col)
519
+			foreach ($only_keys as $key => &$col)
521 520
 			{
522
-				if(is_numeric($key) && in_array($col, $this->db_cols, true))
521
+				if (is_numeric($key) && in_array($col, $this->db_cols, true))
523 522
 				{
524
-					$col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col;
523
+					$col = $this->table_name.'.'.array_search($col, $this->db_cols).' AS '.$col;
525 524
 				}
526 525
 			}
527 526
 		}
528 527
 		// check if we order by a custom field --> join cf table for given cf and order by it's value
529
-		if (strpos($order_by,self::CF_PREFIX) !== false)
528
+		if (strpos($order_by, self::CF_PREFIX) !== false)
530 529
 		{
531 530
 			// fields to order by, as cutomfields may have names with spaces, we examine each order by criteria
532
-			$fields2order = explode(',',$order_by);
533
-			foreach($fields2order as $v)
531
+			$fields2order = explode(',', $order_by);
532
+			foreach ($fields2order as $v)
534 533
 			{
535
-				if (strpos($v,self::CF_PREFIX) !== false)
534
+				if (strpos($v, self::CF_PREFIX) !== false)
536 535
 				{
537 536
 					// we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname
538
-					$buff = explode(' ',trim($v));
537
+					$buff = explode(' ', trim($v));
539 538
 					$orderDir = array_pop($buff);
540
-					$key = substr(trim(implode(' ',$buff)), 1);
541
-					switch($this->customfields[$key]['type'])
539
+					$key = substr(trim(implode(' ', $buff)), 1);
540
+					switch ($this->customfields[$key]['type'])
542 541
 					{
543 542
 						case 'int':
544 543
 							$order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'.
@@ -571,26 +570,26 @@  discard block
 block discarded – undo
571 570
 		{
572 571
 			$_cfnames = array_keys($this->customfields);
573 572
 			$extra_filter = null;
574
-			foreach($filter as $name => $val)
573
+			foreach ($filter as $name => $val)
575 574
 			{
576 575
 				// replace ambiguous auto-id with (an exact match of) table_name.autoid
577 576
 				if (is_string($name) && $name == $this->autoinc_id)
578 577
 				{
579 578
 					if ((int)$filter[$this->autoinc_id])
580 579
 					{
581
-						$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
580
+						$filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
582 581
 							$this->autoinc_id => $filter[$this->autoinc_id],
583 582
 						));
584 583
 					}
585 584
 					unset($filter[$this->autoinc_id]);
586 585
 				}
587 586
 				// replace ambiguous column with (an exact match of) table_name.column
588
-				elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols))
587
+				elseif (is_string($name) && $val != null && in_array($name, $this->db_cols))
589 588
 				{
590 589
 					$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
591 590
 					if ($extra_columns['fd'][array_search($name, $this->db_cols)])
592 591
 					{
593
-						$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
592
+						$filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
594 593
 							array_search($name, $this->db_cols) => $val,
595 594
 						));
596 595
 						unset($filter[$name]);
@@ -602,61 +601,61 @@  discard block
 block discarded – undo
602 601
 					{
603 602
 						if ($val[0] === '!')	// negative filter
604 603
 						{
605
-							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1));
604
+							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val, 1));
606 605
 						}
607 606
 						else	// using Db::expression to allow to use array() with possible values or NULL
608 607
 						{
609
-							if($this->customfields[$this->get_cf_name($name)]['type'] == 'select' &&
608
+							if ($this->customfields[$this->get_cf_name($name)]['type'] == 'select' &&
610 609
 								$this->customfields[$this->get_cf_name($name)]['rows'] > 1)
611 610
 							{
612 611
 								// Multi-select - any entry with the filter value selected matches
613
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.
614
-									$this->extra_value,$this->db->expression($this->extra_table,array(
615
-										$this->db->concat("','",$this->extra_value,"','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%')
612
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.
613
+									$this->extra_value, $this->db->expression($this->extra_table, array(
614
+										$this->db->concat("','", $this->extra_value, "','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%')
616 615
 									))
617 616
 								);
618 617
 							}
619 618
 							elseif ($this->customfields[$this->get_cf_name($name)]['type'] == 'text')
620 619
 							{
621
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.$this->extra_value,
622
-										$this->db->expression($this->extra_table,array(
620
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.$this->extra_value,
621
+										$this->db->expression($this->extra_table, array(
623 622
 										$this->extra_value.' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($wildcard.$val.$wildcard)
624 623
 									))
625 624
 								);
626 625
 							}
627 626
 							else
628 627
 							{
629
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.
630
-									$this->extra_value,$this->db->expression($this->extra_table,array($this->extra_value => $val)));
628
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.
629
+									$this->extra_value, $this->db->expression($this->extra_table, array($this->extra_value => $val)));
631 630
 							}
632 631
 						}
633 632
 						// need to use a LEFT JOIN for negative search or to allow NULL values
634
-						$need_left_join = $val[0] === '!' || strpos($sql_filter,'IS NULL') !== false ? ' LEFT ' : '';
635
-						$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$need_left_join.$this->extra_join_filter.
633
+						$need_left_join = $val[0] === '!' || strpos($sql_filter, 'IS NULL') !== false ? ' LEFT ' : '';
634
+						$join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $need_left_join.$this->extra_join_filter.
636 635
 							' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($name)).
637 636
 							' AND '.$sql_filter);
638 637
 						++$extra_filter;
639 638
 					}
640 639
 					unset($filter[$name]);
641 640
 				}
642
-				elseif(is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
641
+				elseif (is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
643 642
 				{
644
-					$_cf = explode(' ',$val);
645
-					foreach($_cf as $cf_np)
643
+					$_cf = explode(' ', $val);
644
+					foreach ($_cf as $cf_np)
646 645
 					{
647 646
 						// building cf_name by glueing parts together (, in case someone used whitespace in their custom field names)
648
-						$tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np;
647
+						$tcf_name = ($tcf_name ? $tcf_name.' ' : '').$cf_np;
649 648
 						// reacts on the first one found that matches an existing customfield, should be better then the old behavior of
650 649
 						// simply splitting by " " and using the first part
651
-						if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false )
650
+						if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn, (array)$_cfnames, true) !== false)
652 651
 						{
653 652
 							$cf = $tcf_name;
654 653
 							break;
655 654
 						}
656 655
 					}
657
-					$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter.
656
+					$join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $this->extra_join_filter.
658 657
 						' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($cf)).
659
-						' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val));
658
+						' AND '.str_replace($cf, 'extra_filter.'.$this->extra_value, $val));
660 659
 					++$extra_filter;
661 660
 					unset($filter[$name]);
662 661
 				}
@@ -668,15 +667,14 @@  discard block
 block discarded – undo
668 667
 			if (is_array($only_keys))
669 668
 			{
670 669
 				$only_keys = array_values($only_keys);
671
-				$only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] :
672
-					$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id);
670
+				$only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id);
673 671
 			}
674 672
 			else
675 673
 			{
676 674
 				$only_keys = 'DISTINCT '.$only_keys;
677 675
 			}
678 676
 		}
679
-		return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
677
+		return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
680 678
 	}
681 679
 
682 680
 	/**
@@ -716,7 +714,7 @@  discard block
 block discarded – undo
716 714
 	 */
717 715
 	function get_cf_name($field)
718 716
 	{
719
-		return substr($field,1);
717
+		return substr($field, 1);
720 718
 	}
721 719
 
722 720
 	/**
@@ -738,7 +736,7 @@  discard block
 block discarded – undo
738 736
 	 */
739 737
 	function is_multiple($name)
740 738
 	{
741
-		return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) &&
739
+		return $this->allow_multiple_values && in_array($this->customfields[$name]['type'], array('select', 'select-account')) &&
742 740
 			$this->customfields[$name]['rows'] > 1;
743 741
 	}
744 742
 }
Please login to merge, or discard this patch.
Braces   +64 added lines, -15 removed lines patch added patch discarded remove patch
@@ -127,7 +127,11 @@  discard block
 block discarded – undo
127 127
 
128 128
 		$this->allow_multiple_values = $allow_multiple_values;
129 129
 		$this->extra_table = $extra_table;
130
-		if (!$this->extra_id) $this->extra_id = $this->autoinc_id;	// default to auto id of regular table
130
+		if (!$this->extra_id)
131
+		{
132
+			$this->extra_id = $this->autoinc_id;
133
+		}
134
+		// default to auto id of regular table
131 135
 
132 136
 		// if names from columns of extra table are only postfixes (starting with _), prepend column prefix
133 137
 		if (!($prefix=$column_prefix))
@@ -145,7 +149,10 @@  discard block
 block discarded – undo
145 149
 		) as $col => $val)
146 150
 		{
147 151
 			$this->$col = $col_name = $val;
148
-			if ($col_name[0] == '_') $this->$col = $prefix . $val;
152
+			if ($col_name[0] == '_')
153
+			{
154
+				$this->$col = $prefix . $val;
155
+			}
149 156
 		}
150 157
 		// some sanity checks, maybe they should be active only for development
151 158
 		if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table)))
@@ -179,13 +186,23 @@  discard block
 block discarded – undo
179 186
 	 */
180 187
 	function read_customfields($ids,$field_names=null)
181 188
 	{
182
-		if (is_null($field_names)) $field_names = array_keys($this->customfields);
189
+		if (is_null($field_names))
190
+		{
191
+			$field_names = array_keys($this->customfields);
192
+		}
183 193
 
184 194
 		foreach((array)$ids as $key => $id)
185 195
 		{
186
-			if (!(int)$id && is_array($ids)) unset($ids[$key]);
196
+			if (!(int)$id && is_array($ids))
197
+			{
198
+				unset($ids[$key]);
199
+			}
187 200
 		}
188
-		if (!$ids || !$field_names) return array();	// nothing to do
201
+		if (!$ids || !$field_names)
202
+		{
203
+			return array();
204
+		}
205
+		// nothing to do
189 206
 
190 207
 		$entries = array();
191 208
 		foreach($this->db->select($this->extra_table,'*',array(
@@ -194,7 +211,10 @@  discard block
 block discarded – undo
194 211
 		),__LINE__,__FILE__,false,'',$this->app) as $row)
195 212
 		{
196 213
 			$entry =& $entries[$row[$this->extra_id]];
197
-			if (!is_array($entry)) $entry = array();
214
+			if (!is_array($entry))
215
+			{
216
+				$entry = array();
217
+			}
198 218
 			$field = $this->get_cf_field($row[$this->extra_key]);
199 219
 
200 220
 			if ($this->allow_multiple_values && $this->is_multiple($row[$this->extra_key]))
@@ -220,7 +240,10 @@  discard block
 block discarded – undo
220 240
 	{
221 241
 		foreach (array_keys((array)$this->customfields) as $name)
222 242
 		{
223
-			if (!isset($data[$field = $this->get_cf_field($name)])) continue;
243
+			if (!isset($data[$field = $this->get_cf_field($name)]))
244
+			{
245
+				continue;
246
+			}
224 247
 
225 248
 			$where = array(
226 249
 				$this->extra_id    => isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]],
@@ -232,7 +255,11 @@  discard block
 block discarded – undo
232 255
 			if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
233 256
 			{
234 257
 				$this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app);
235
-				if (empty($data[$field])) continue;	// nothing else to do for empty values
258
+				if (empty($data[$field]))
259
+				{
260
+					continue;
261
+				}
262
+				// nothing else to do for empty values
236 263
 			}
237 264
 			foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) :
238 265
 				// regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
@@ -305,9 +332,12 @@  discard block
 block discarded – undo
305 332
 	 */
306 333
 	function save($keys=null,$extra_where=null)
307 334
 	{
308
-		if (is_array($keys) && count($keys) && !isset($keys[0]))	// allow to use an etag, eg array('etag=etag+1')
335
+		if (is_array($keys) && count($keys) && !isset($keys[0]))
336
+		{
337
+			// allow to use an etag, eg array('etag=etag+1')
309 338
 		{
310 339
 			$this->data_merge($keys);
340
+		}
311 341
 			$keys = null;
312 342
 		}
313 343
 		$ret = parent::save($keys,$extra_where);
@@ -340,13 +370,20 @@  discard block
 block discarded – undo
340 370
 				{
341 371
 					$ids[] = $row[$this->autoinc_id];
342 372
 				}
343
-				if (!$ids) return 0;	// no rows affected
373
+				if (!$ids)
374
+				{
375
+					return 0;
376
+				}
377
+				// no rows affected
344 378
 			}
345 379
 			else
346 380
 			{
347 381
 				$ids = (array)$query[$this->autoinc_id];
348 382
 			}
349
-			if ($only_return_ids) return $ids;
383
+			if ($only_return_ids)
384
+			{
385
+				return $ids;
386
+			}
350 387
 			$this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__);
351 388
 		}
352 389
 		return parent::delete($keys);
@@ -388,7 +425,10 @@  discard block
 block discarded – undo
388 425
 			{
389 426
 				foreach($selectcols as $col)
390 427
 				{
391
-					if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col);
428
+					if ($this->is_cf($col))
429
+					{
430
+						$fields[] = $this->get_cf_name($col);
431
+					}
392 432
 				}
393 433
 			}
394 434
 			if (($cfs = $this->read_customfields(array_keys($id2keys),$fields)))
@@ -507,7 +547,10 @@  discard block
 block discarded – undo
507 547
 					}
508 548
 				}
509 549
 			}
510
-			if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria);
550
+			if ($cfcriteria && $op =='OR')
551
+			{
552
+				$criteria[] = implode(' OR ',$cfcriteria);
553
+			}
511 554
 		}
512 555
 		if($only_keys === true)
513 556
 		{
@@ -598,11 +641,14 @@  discard block
 block discarded – undo
598 641
 				}
599 642
 				elseif (is_string($name) && $this->is_cf($name))
600 643
 				{
601
-					if (!empty($val))	// empty -> dont filter
644
+					if (!empty($val))
645
+					{
646
+						// empty -> dont filter
602 647
 					{
603 648
 						if ($val[0] === '!')	// negative filter
604 649
 						{
605 650
 							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1));
651
+					}
606 652
 						}
607 653
 						else	// using Db::expression to allow to use array() with possible values or NULL
608 654
 						{
@@ -639,9 +685,12 @@  discard block
 block discarded – undo
639 685
 					}
640 686
 					unset($filter[$name]);
641 687
 				}
642
-				elseif(is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
688
+				elseif(is_int($name) && $this->is_cf($val))
689
+				{
690
+					// lettersearch: #cfname LIKE 's%'
643 691
 				{
644 692
 					$_cf = explode(' ',$val);
693
+				}
645 694
 					foreach($_cf as $cf_np)
646 695
 					{
647 696
 						// building cf_name by glueing parts together (, in case someone used whitespace in their custom field names)
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/File.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@  discard block
 block discarded – undo
27 27
 	 *
28 28
 	 * @param string $xml
29 29
 	 */
30
-	public function __construct($xml='')
30
+	public function __construct($xml = '')
31 31
 	{
32
-		if($xml) parent::__construct($xml);
32
+		if ($xml) parent::__construct($xml);
33 33
 
34 34
 		// Legacy multiple - id ends in []
35
-		if(substr($this->id,-2) == '[]')
35
+		if (substr($this->id, -2) == '[]')
36 36
 		{
37 37
 			$this->setElementAttribute($this->id, 'multiple', true);
38 38
 		}
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		$response = Api\Json\Response::get();
53 53
 		$request_id = str_replace(' ', '+', rawurldecode($_REQUEST['request_id']));
54 54
 		$widget_id = $_REQUEST['widget_id'];
55
-		if(!self::$request = Etemplate\Request::read($request_id)) {
55
+		if (!self::$request = Etemplate\Request::read($request_id)) {
56 56
 			$response->error("Could not read session");
57 57
 			return;
58 58
 		}
@@ -70,20 +70,20 @@  discard block
 block discarded – undo
70 70
 		foreach ($_FILES as $field => &$files)
71 71
 		{
72 72
 			$widget = $template->getElementById($widget_id ? $widget_id : $field);
73
-			if($widget && $widget->attrs['mime']) {
73
+			if ($widget && $widget->attrs['mime']) {
74 74
 				$mime = $widget->attrs['mime'];
75 75
 			}
76 76
 
77 77
 			// Check for legacy [] in id to indicate multiple - it changes format
78
-			if(is_array($files['name'])) {
78
+			if (is_array($files['name'])) {
79 79
 				$file_list = array();
80
-				foreach($files as $f_field => $values)
80
+				foreach ($files as $f_field => $values)
81 81
 				{
82
-					foreach($values as $key => $f_value) {
82
+					foreach ($values as $key => $f_value) {
83 83
 						$file_list[$key][$f_field] = $f_value;
84 84
 					}
85 85
 				}
86
-				foreach($file_list as $file)
86
+				foreach ($file_list as $file)
87 87
 				{
88 88
 					self::process_uploaded_file($field, $file, $mime, $file_data);
89 89
 				}
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 		$response->data($file_data);
100 100
 
101 101
 		// Check for a callback, call it if there is one
102
-		foreach($_FILES as $field => $file)
102
+		foreach ($_FILES as $field => $file)
103 103
 		{
104
-			if(($element = $template->getElementById($field)))
104
+			if (($element = $template->getElementById($field)))
105 105
 			{
106 106
 				$callback = $element->attrs['callback'];
107
-				if(!$callback) $callback = $template->getElementAttribute($field, 'callback');
108
-				if($callback)
107
+				if (!$callback) $callback = $template->getElementAttribute($field, 'callback');
108
+				if ($callback)
109 109
 				{
110 110
 					ExecMethod($callback, $_FILES[$field]);
111 111
 				}
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	protected static function process_uploaded_file($field, Array &$file, $mime, Array &$file_data)
120 120
 	{
121
-		unset($field);	// not used
121
+		unset($field); // not used
122 122
 
123 123
 		// Chunks get mangled a little
124
-		if($file['name'] == 'blob')
124
+		if ($file['name'] == 'blob')
125 125
 		{
126 126
 			$file['name'] = $_POST['resumableFilename'];
127 127
 			$file['type'] = $_POST['resumableType'];
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 
130 130
 		if ($file['error'] == UPLOAD_ERR_OK && trim($file['name']) != '' && $file['size'] > 0 && is_uploaded_file($file['tmp_name'])) {
131 131
 			// Mime check
132
-			if($mime)
132
+			if ($mime)
133 133
 			{
134 134
 				$type = $file['type'];
135 135
 				$is_preg = $mime[0] == '/';
136
-				if (!$is_preg && strcasecmp($mime,$type) ||
137
-					$is_preg && !preg_match($mime,$type))
136
+				if (!$is_preg && strcasecmp($mime, $type) ||
137
+					$is_preg && !preg_match($mime, $type))
138 138
 				{
139
-					$file_data[$file['name']] = $file['name'].':'.lang('File is of wrong type (%1 != %2)!',$type,$mime);
139
+					$file_data[$file['name']] = $file['name'].':'.lang('File is of wrong type (%1 != %2)!', $type, $mime);
140 140
 					//error_log(__METHOD__.__LINE__.array2string($file_data[$file['name']]));
141 141
 					return false;
142 142
 				}
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
 			// Resumable / chunked uploads
146 146
 			// init the destination file (format <filename.ext>.part<#chunk>
147 147
 			// the file is stored in a temporary directory
148
-			$temp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/'.str_replace('/','_',$_POST['resumableIdentifier']);
149
-			$dest_file = $temp_dir.'/'.str_replace('/','_',$_POST['resumableFilename']).'.part'.(int)$_POST['resumableChunkNumber'];
148
+			$temp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/'.str_replace('/', '_', $_POST['resumableIdentifier']);
149
+			$dest_file = $temp_dir.'/'.str_replace('/', '_', $_POST['resumableFilename']).'.part'.(int)$_POST['resumableChunkNumber'];
150 150
 
151 151
 			// create the temporary directory
152 152
 			if (!is_dir($temp_dir))
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 			else
163 163
 			{
164 164
 				// check if all the parts present, and create the final destination file
165
-				$new_file = self::createFileFromChunks($temp_dir, str_replace('/','_',$_POST['resumableFilename']),
165
+				$new_file = self::createFileFromChunks($temp_dir, str_replace('/', '_', $_POST['resumableFilename']),
166 166
 						$_POST['resumableChunkSize'], $_POST['resumableTotalSize']);
167 167
 			}
168
-			if( $new_file) {
168
+			if ($new_file) {
169 169
 				$file['tmp_name'] = $new_file;
170 170
 
171 171
 				// Data to send back to client
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
 		// count all the parts of this file
196 196
 		$total_files = 0;
197
-		foreach(scandir($temp_dir) as $file) {
197
+		foreach (scandir($temp_dir) as $file) {
198 198
 			if (stripos($file, $fileName) !== false) {
199 199
 				$total_files++;
200 200
 			}
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
 
203 203
 		// check that all the parts are present
204 204
 		// the size of the last part is between chunkSize and 2*$chunkSize
205
-		if ($total_files * $chunkSize >=  ($totalSize - $chunkSize + 1)) {
205
+		if ($total_files * $chunkSize >= ($totalSize - $chunkSize + 1)) {
206 206
 			if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir']))
207 207
 			{
208
-				$new_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'egw_');
208
+				$new_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'egw_');
209 209
 			}
210 210
 			else
211 211
 			{
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
 			// create the final destination file
216 216
 			if (($fp = fopen($new_file, 'w')) !== false) {
217
-				for ($i=1; $i<=$total_files; $i++) {
217
+				for ($i = 1; $i <= $total_files; $i++) {
218 218
 					fwrite($fp, file_get_contents($temp_dir.'/'.$fileName.'.part'.$i));
219 219
 				}
220 220
 				fclose($fp);
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 			{
251 251
 				if ($object != "." && $object != "..")
252 252
 				{
253
-					if (filetype($dir . "/" . $object) == "dir")
253
+					if (filetype($dir."/".$object) == "dir")
254 254
 					{
255
-						self::rrmdir($dir . "/" . $object);
255
+						self::rrmdir($dir."/".$object);
256 256
 					}
257 257
 					else
258 258
 					{
259
-						unlink($dir . "/" . $object);
259
+						unlink($dir."/".$object);
260 260
 					}
261 261
 				}
262 262
 			}
@@ -273,23 +273,23 @@  discard block
 block discarded – undo
273 273
 	 * @param array $content
274 274
 	 * @param array &$validated=array() validated content
275 275
 	 */
276
-	public function validate($cname, array $expand, array $content, &$validated=array())
276
+	public function validate($cname, array $expand, array $content, &$validated = array())
277 277
 	{
278 278
 		$form_name = self::form_name($cname, $this->id, $expand);
279 279
 
280 280
 		if (!$this->is_readonly($cname, $form_name))
281 281
 		{
282 282
 			$value = $value_in = self::get_array($content, $form_name);
283
-			$valid =& self::get_array($validated, $form_name, true);
283
+			$valid = & self::get_array($validated, $form_name, true);
284 284
 
285
-			if(!is_array($value)) $value = array();
285
+			if (!is_array($value)) $value = array();
286 286
 
287 287
 			// Incoming values indexed by temp name
288
-			if($value[0]) $value = $value[0];
288
+			if ($value[0]) $value = $value[0];
289 289
 
290
-			foreach($value as $tmp => $file)
290
+			foreach ($value as $tmp => $file)
291 291
 			{
292
-				if(!$file) continue;
292
+				if (!$file) continue;
293 293
 				if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir']))
294 294
 				{
295 295
 					$path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmp;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 				);
310 310
 			}
311 311
 
312
-			if($valid && !$this->attrs['multiple']) $valid = $valid[0];
312
+			if ($valid && !$this->attrs['multiple']) $valid = $valid[0];
313 313
 		}
314 314
 	}
315 315
 }
Please login to merge, or discard this patch.
calendar/inc/class.calendar_so.inc.php 2 patches
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.
Spacing   +391 added lines, -394 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-1 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
 			}
@@ -772,11 +772,11 @@  discard block
 block discarded – undo
772 772
 		if ($users)
773 773
 		{
774 774
 			$users_by_type = array();
775
-			foreach((array)$users as $user)
775
+			foreach ((array)$users as $user)
776 776
 			{
777 777
 				if (is_numeric($user))
778 778
 				{
779
-					$users_by_type['u'][] = (int) $user;
779
+					$users_by_type['u'][] = (int)$user;
780 780
 				}
781 781
 				else
782 782
 				{
@@ -787,45 +787,45 @@  discard block
 block discarded – undo
787 787
 			}
788 788
 			$to_or = $user_or = array();
789 789
 			$owner_or = null;
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,18 +882,18 @@  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
 		}
890 889
 
891 890
 		// Check for some special sorting, used by planner views
892
-		if($params['order'] == 'participants , cal_non_blocking DESC')
891
+		if ($params['order'] == 'participants , cal_non_blocking DESC')
893 892
 		{
894 893
 			$order = ($GLOBALS['egw_info']['user']['preferences']['common']['account_display'] == 'lastname' ? 'n_family' : 'n_fileas');
895 894
 			$cols .= ",egw_addressbook.{$order}";
896 895
 			$join .= "LEFT JOIN egw_addressbook ON ".
897
-					($this->db->Type == 'pgsql'? "egw_addressbook.account_id::varchar = ":"egw_addressbook.account_id = ").
896
+					($this->db->Type == 'pgsql' ? "egw_addressbook.account_id::varchar = " : "egw_addressbook.account_id = ").
898 897
 					"{$this->user_table}.cal_user_id";
899 898
 			$params['order'] = "$order, cal_non_blocking DESC";
900 899
 		}
@@ -927,29 +926,29 @@  discard block
 block discarded – undo
927 926
 			// as replace the OR by construction of a suitable UNION for performance reasons
928 927
 			if ($owner_or || $user_or)
929 928
 			{
930
-				foreach($user_or as $user_sql)
929
+				foreach ($user_or as $user_sql)
931 930
 				{
932 931
 					$selects[] = $select;
933
-					$selects[count($selects)-1]['where'][] = $user_sql;
932
+					$selects[count($selects) - 1]['where'][] = $user_sql;
934 933
 					if ($params['enum_recuring'])
935 934
 					{
936
-						$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
935
+						$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
937 936
 						$selects[] = $select;
938
-						$selects[count($selects)-1]['where'][] = $user_sql;
939
-						$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
937
+						$selects[count($selects) - 1]['where'][] = $user_sql;
938
+						$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
940 939
 					}
941 940
 				}
942 941
 				// if the query is to be filtered by owner we need to add more selects for the union
943 942
 				if ($owner_or)
944 943
 				{
945 944
 					$selects[] = $select;
946
-					$selects[count($selects)-1]['where'][] = $owner_or;
945
+					$selects[count($selects) - 1]['where'][] = $owner_or;
947 946
 					if ($params['enum_recuring'])
948 947
 					{
949
-						$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
948
+						$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
950 949
 						$selects[] = $select;
951
-						$selects[count($selects)-1]['where'][] = $owner_or;
952
-						$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
950
+						$selects[count($selects) - 1]['where'][] = $owner_or;
951
+						$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
953 952
 					}
954 953
 				}
955 954
 			}
@@ -959,34 +958,34 @@  discard block
 block discarded – undo
959 958
 				$selects[] = $select;
960 959
 				if ($params['enum_recuring'])
961 960
 				{
962
-					$selects[count($selects)-1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
961
+					$selects[count($selects) - 1]['where'][] = "recur_type IS NULL AND $this->user_table.cal_recur_date=0";
963 962
 					$selects[] = $select;
964
-					$selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
963
+					$selects[count($selects) - 1]['where'][] = "$this->user_table.cal_recur_date=cal_start";
965 964
 				}
966 965
 			}
967 966
 			if (is_numeric($offset) && !$params['no_total'])	// get the total too
968 967
 			{
969 968
 				$save_selects = $selects;
970 969
 				// 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)
971
-				foreach(array_keys($selects) as $key)
970
+				foreach (array_keys($selects) as $key)
972 971
 				{
973 972
 					$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";
974 973
 					if (!$params['enum_recuring'])
975 974
 					{
976
-						$selects[$key]['cols'] = str_replace(array('cal_start','cal_end'),
977
-							array('range_start AS cal_start','range_end AS cal_end'), $selects[$key]['cols']);
975
+						$selects[$key]['cols'] = str_replace(array('cal_start', 'cal_end'),
976
+							array('range_start AS cal_start', 'range_end AS cal_end'), $selects[$key]['cols']);
978 977
 					}
979 978
 				}
980
-				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
979
+				if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
981 980
 
982
-				$this->total = $this->db->union($selects,__LINE__,__FILE__)->NumRows();
981
+				$this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows();
983 982
 
984 983
 				// restore original cols / selects
985 984
 				$selects = $save_selects; unset($save_selects);
986 985
 			}
987
-			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
986
+			if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
988 987
 
989
-			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
988
+			$rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows);
990 989
 		}
991 990
 		else	// MsSQL oder MySQL 3.23
992 991
 		{
@@ -1009,27 +1008,27 @@  discard block
 block discarded – undo
1009 1008
 				$selects[0]['cols'] = "$this->cal_table.cal_id,cal_start";
1010 1009
 				if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
1011 1010
 				{
1012
-					self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1011
+					self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1013 1012
 				}
1014 1013
 				$this->total = $this->db->union($selects, __LINE__, __FILE__)->NumRows();
1015 1014
 				$selects = $save_selects;
1016 1015
 			}
1017 1016
 			if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union'])
1018 1017
 			{
1019
-				self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']);
1018
+				self::get_union_selects($selects, $start, $end, $users, $cat_id, $filter, $params['query'], $params['users']);
1020 1019
 			}
1021
-			$rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows);
1020
+			$rs = $this->db->union($selects, __LINE__, __FILE__, $params['order'], $offset, $num_rows);
1022 1021
 		}
1023 1022
 		//error_log(__METHOD__."() useUnionQuery=$useUnionQuery --> query took ".(microtime(true)-$starttime).'s '.$rs->sql);
1024 1023
 
1025 1024
 		if (isset($params['cols']))
1026 1025
 		{
1027
-			return $rs;	// if colums are specified we return the recordset / iterator
1026
+			return $rs; // if colums are specified we return the recordset / iterator
1028 1027
 		}
1029 1028
 		// Todo: return $this->get_events($rs);
1030 1029
 
1031 1030
 		$events = $ids = $recur_dates = $recur_ids = array();
1032
-		foreach($rs as $row)
1031
+		foreach ($rs as $row)
1033 1032
 		{
1034 1033
 			$id = $row['cal_id'];
1035 1034
 			if (is_numeric($id)) $ids[] = $id;
@@ -1041,9 +1040,9 @@  discard block
 block discarded – undo
1041 1040
 			}
1042 1041
 			if ($row['participants'])
1043 1042
 			{
1044
-				$row['participants'] = explode(',',$row['participants']);
1043
+				$row['participants'] = explode(',', $row['participants']);
1045 1044
 				$row['participants'] = array_combine($row['participants'],
1046
-					array_fill(0,count($row['participants']),''));
1045
+					array_fill(0, count($row['participants']), ''));
1047 1046
 			}
1048 1047
 			else
1049 1048
 			{
@@ -1052,9 +1051,9 @@  discard block
 block discarded – undo
1052 1051
 			$row['recur_exception'] = $row['alarm'] = array();
1053 1052
 
1054 1053
 			// compile a list of recurrences per cal_id
1055
-			if (!in_array($id,(array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1054
+			if (!in_array($id, (array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id;
1056 1055
 
1057
-			$events[$id] = Api\Db::strip_array_keys($row,'cal_');
1056
+			$events[$id] = Api\Db::strip_array_keys($row, 'cal_');
1058 1057
 		}
1059 1058
 		//_debug_array($events);
1060 1059
 		if (count($ids))
@@ -1064,26 +1063,26 @@  discard block
 block discarded – undo
1064 1063
 			// now ready all users with the given cal_id AND (cal_recur_date=0 or the fitting recur-date)
1065 1064
 			// This will always read the first entry of each recuring event too, we eliminate it later
1066 1065
 			$recur_dates[] = 0;
1067
-			$utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',',$ids).")".
1066
+			$utcal_id_view = " (SELECT * FROM ".$this->user_table." WHERE cal_id IN (".implode(',', $ids).")".
1068 1067
 				($filter != 'everything' ? " AND cal_status NOT IN ('X','E')" : '').") utcalid ";
1069 1068
 			//$utrecurdate_view = " (select * from ".$this->user_table." where cal_recur_date in (".implode(',',array_unique($recur_dates)).")) utrecurdates ";
1070
-			foreach($this->db->select($utcal_id_view,'*',array(
1069
+			foreach ($this->db->select($utcal_id_view, '*', array(
1071 1070
 					//'cal_id' => array_unique($ids),
1072 1071
 					'cal_recur_date' => $recur_dates,
1073
-				),__LINE__,__FILE__,false,'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT,'calendar',-1,$join='',
1074
-				$this->db->get_table_definitions('calendar',$this->user_table)) as $row)	// DESC puts users before resources and contacts
1072
+				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT, 'calendar', -1, $join = '',
1073
+				$this->db->get_table_definitions('calendar', $this->user_table)) as $row)	// DESC puts users before resources and contacts
1075 1074
 			{
1076 1075
 				$id = $row['cal_id'];
1077 1076
 				if ($row['cal_recur_date']) $id .= '-'.$row['cal_recur_date'];
1078 1077
 
1079 1078
 				// combine all participant data in uid and status values
1080 1079
 				$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']);
1081
-				$status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']);
1080
+				$status = self::combine_status($row['cal_status'], $row['cal_quantity'], $row['cal_role']);
1082 1081
 
1083 1082
 				// set accept/reject/tentative of series for all recurrences
1084 1083
 				if (!$row['cal_recur_date'])
1085 1084
 				{
1086
-					foreach((array)$recur_ids[$row['cal_id']] as $i)
1085
+					foreach ((array)$recur_ids[$row['cal_id']] as $i)
1087 1086
 					{
1088 1087
 						if (isset($events[$i]) && !isset($events[$i]['participants'][$uid]))
1089 1088
 						{
@@ -1098,16 +1097,16 @@  discard block
 block discarded – undo
1098 1097
 			// query recurrance exceptions, if needed: enum_recuring && !daywise is used in calendar_groupdav::get_series($uid,...)
1099 1098
 			if (!$params['enum_recuring'] || !$params['daywise'])
1100 1099
 			{
1101
-				foreach($this->db->select($this->dates_table, 'cal_id,cal_start', array(
1100
+				foreach ($this->db->select($this->dates_table, 'cal_id,cal_start', array(
1102 1101
 					'cal_id' => $ids,
1103 1102
 					'recur_exception' => true,
1104 1103
 				), __LINE__, __FILE__, false, 'ORDER BY cal_id,cal_start', 'calendar') as $row)
1105 1104
 				{
1106 1105
 					// for enum_recurring events are not indexed by cal_id, but $cal_id.'-'.$cal_start
1107 1106
 					// find master, which is first recurrence
1108
-					if (!isset($events[$id=$row['cal_id']]))
1107
+					if (!isset($events[$id = $row['cal_id']]))
1109 1108
 					{
1110
-						foreach($events as $id => $event)
1109
+						foreach ($events as $id => $event)
1111 1110
 						{
1112 1111
 							if ($event['id'] == $row['cal_id']) break;
1113 1112
 						}
@@ -1120,10 +1119,10 @@  discard block
 block discarded – undo
1120 1119
 			{
1121 1120
 				$where = array('cal_id' => $ids);
1122 1121
 				if ($params['cfs']) $where['cal_extra_name'] = $params['cfs'];
1123
-				foreach($this->db->select($this->extra_table,'*',$where,
1124
-					__LINE__,__FILE__,false,'','calendar') as $row)
1122
+				foreach ($this->db->select($this->extra_table, '*', $where,
1123
+					__LINE__, __FILE__, false, '', 'calendar') as $row)
1125 1124
 				{
1126
-					foreach((array)$recur_ids[$row['cal_id']] as $id)
1125
+					foreach ((array)$recur_ids[$row['cal_id']] as $id)
1127 1126
 					{
1128 1127
 						if (isset($events[$id]))
1129 1128
 						{
@@ -1133,9 +1132,9 @@  discard block
 block discarded – undo
1133 1132
 				}
1134 1133
 			}
1135 1134
 			// alarms
1136
-			foreach($this->read_alarms($ids) as $cal_id => $alarms)
1135
+			foreach ($this->read_alarms($ids) as $cal_id => $alarms)
1137 1136
 			{
1138
-				foreach($alarms as $id => $alarm)
1137
+				foreach ($alarms as $id => $alarm)
1139 1138
 				{
1140 1139
 					$event_start = $alarm['time'] + $alarm['offset'];
1141 1140
 
@@ -1172,16 +1171,16 @@  discard block
 block discarded – undo
1172 1171
 	 * @param $query
1173 1172
 	 * @param $users_raw as passed to calendar_bo::search (no members and memberships added)
1174 1173
 	 */
1175
-	private static function get_union_selects(array &$selects,$start,$end,$users,$cat_id,$filter,$query,$users_raw)
1174
+	private static function get_union_selects(array &$selects, $start, $end, $users, $cat_id, $filter, $query, $users_raw)
1176 1175
 	{
1177
-		if (in_array(basename($_SERVER['SCRIPT_FILENAME']),array('groupdav.php','rpc.php','xmlrpc.php','/activesync/index.php')) ||
1178
-			!in_array($GLOBALS['egw_info']['flags']['currentapp'],array('calendar','home')))
1176
+		if (in_array(basename($_SERVER['SCRIPT_FILENAME']), array('groupdav.php', 'rpc.php', 'xmlrpc.php', '/activesync/index.php')) ||
1177
+			!in_array($GLOBALS['egw_info']['flags']['currentapp'], array('calendar', 'home')))
1179 1178
 		{
1180
-			return;    // disable integration for GroupDAV, SyncML, ...
1179
+			return; // disable integration for GroupDAV, SyncML, ...
1181 1180
 		}
1182 1181
 		self::$integration_data = Api\Hooks::process(array(
1183 1182
 			'location' => 'calendar_search_union',
1184
-			'cols'  => $selects[0]['cols'],    // cols to return
1183
+			'cols'  => $selects[0]['cols'], // cols to return
1185 1184
 			'start' => $start,
1186 1185
 			'end'   => $end,
1187 1186
 			'users' => $users,
@@ -1190,12 +1189,12 @@  discard block
 block discarded – undo
1190 1189
 			'filter'=> $filter,
1191 1190
 			'query' => $query,
1192 1191
 		));
1193
-		foreach(self::$integration_data as $data)
1192
+		foreach (self::$integration_data as $data)
1194 1193
 		{
1195 1194
 			if (is_array($data['selects']))
1196 1195
 			{
1197 1196
 				//echo $app; _debug_array($data);
1198
-				$selects = array_merge($selects,$data['selects']);
1197
+				$selects = array_merge($selects, $data['selects']);
1199 1198
 			}
1200 1199
 		}
1201 1200
 	}
@@ -1220,35 +1219,35 @@  discard block
 block discarded – undo
1220 1219
 	 * @param string $required_app ='calendar'
1221 1220
 	 * @return string cols for union query to match ones supplied in $required
1222 1221
 	 */
1223
-	public static function union_cols(array $app_cols,$required,$required_app='calendar')
1222
+	public static function union_cols(array $app_cols, $required, $required_app = 'calendar')
1224 1223
 	{
1225 1224
 		// remove evtl. used DISTINCT, we currently dont need it
1226
-		if (($distinct = substr($required,0,9) == 'DISTINCT '))
1225
+		if (($distinct = substr($required, 0, 9) == 'DISTINCT '))
1227 1226
 		{
1228
-			$required = substr($required,9);
1227
+			$required = substr($required, 9);
1229 1228
 		}
1230 1229
 		$return_cols = array();
1231
-		foreach(is_array($required) ? $required : explode(',',$required) as $cols)
1230
+		foreach (is_array($required) ? $required : explode(',', $required) as $cols)
1232 1231
 		{
1233 1232
 			$matches = null;
1234
-			if (substr($cols,-2) == '.*')
1233
+			if (substr($cols, -2) == '.*')
1235 1234
 			{
1236
-				$cols = self::get_columns($required_app,substr($cols,0,-2));
1235
+				$cols = self::get_columns($required_app, substr($cols, 0, -2));
1237 1236
 			}
1238 1237
 			// remove CAST added for PostgreSQL from eg. "CAST(egw_cal.cal_id AS varchar)"
1239 1238
 			elseif (preg_match('/CAST\(([a-z0-9_.]+) AS [a-z0-9_]+\)/i', $cols, $matches))
1240 1239
 			{
1241 1240
 				$cols = $matches[1];
1242 1241
 			}
1243
-			elseif (strpos($cols,' AS ') !== false)
1242
+			elseif (strpos($cols, ' AS ') !== false)
1244 1243
 			{
1245
-				list(,$cols) = explode(' AS ',$cols);
1244
+				list(,$cols) = explode(' AS ', $cols);
1246 1245
 			}
1247
-			foreach((array)$cols as $col)
1246
+			foreach ((array)$cols as $col)
1248 1247
 			{
1249
-				if (substr($col,0,7) == 'egw_cal')	// remove table name
1248
+				if (substr($col, 0, 7) == 'egw_cal')	// remove table name
1250 1249
 				{
1251
-					$col = preg_replace('/^egw_cal[a-z_]*\./','',$col);
1250
+					$col = preg_replace('/^egw_cal[a-z_]*\./', '', $col);
1252 1251
 				}
1253 1252
 				if (isset($app_cols[$col]))
1254 1253
 				{
@@ -1261,7 +1260,7 @@  discard block
 block discarded – undo
1261 1260
 			}
1262 1261
 		}
1263 1262
 		//error_log(__METHOD__."(".array2string($app_cols).", ".array2string($required).", '$required_app') returning ".array2string(implode(',',$return_cols)));
1264
-		return implode(',',$return_cols);
1263
+		return implode(',', $return_cols);
1265 1264
 	}
1266 1265
 
1267 1266
 	/**
@@ -1271,21 +1270,21 @@  discard block
 block discarded – undo
1271 1270
 	 * @param string $table
1272 1271
 	 * @return array of column names
1273 1272
 	 */
1274
-	static private function get_columns($app,$table)
1273
+	static private function get_columns($app, $table)
1275 1274
 	{
1276 1275
 		if ($table != 'egw_cal')
1277 1276
 		{
1278
-			$table_def = $GLOBALS['egw']->db->get_table_definitions($app,$table);
1277
+			$table_def = $GLOBALS['egw']->db->get_table_definitions($app, $table);
1279 1278
 			$cols = array_keys($table_def['fd']);
1280 1279
 		}
1281 1280
 		else
1282 1281
 		{
1283 1282
 			// special handling for egw_cal, as old databases have a different column order!!!
1284
-			$cols =& Api\Cache::getSession(__CLASS__,$table);
1283
+			$cols = & Api\Cache::getSession(__CLASS__, $table);
1285 1284
 
1286 1285
 			if (is_null($cols))
1287 1286
 			{
1288
-				$meta = $GLOBALS['egw']->db->metadata($table,true);
1287
+				$meta = $GLOBALS['egw']->db->metadata($table, true);
1289 1288
 				$cols = array_keys($meta['meta']);
1290 1289
 			}
1291 1290
 		}
@@ -1338,12 +1337,12 @@  discard block
 block discarded – undo
1338 1337
 	 * @param int &$etag etag=null etag to check or null, on return new etag
1339 1338
 	 * @return boolean|int false on error, 0 if etag does not match, cal_id otherwise
1340 1339
 	 */
1341
-	function save($event,&$set_recurrences,&$set_recurrences_start=0,$change_since=0,&$etag=null)
1340
+	function save($event, &$set_recurrences, &$set_recurrences_start = 0, $change_since = 0, &$etag = null)
1342 1341
 	{
1343 1342
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
1344 1343
 		{
1345 1344
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
1346
-			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!
1345
+			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!
1347 1346
 		}
1348 1347
 		else
1349 1348
 		{
@@ -1354,7 +1353,7 @@  discard block
 block discarded – undo
1354 1353
 
1355 1354
 		//error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag) ".function_backtrace());
1356 1355
 
1357
-		$cal_id = (int) $event['id'];
1356
+		$cal_id = (int)$event['id'];
1358 1357
 		unset($event['id']);
1359 1358
 		$set_recurrences = $set_recurrences || !$cal_id && $event['recur_type'] != MCAL_RECUR_NONE;
1360 1359
 
@@ -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/src/Contacts/Sql.php 1 patch
Spacing   +117 added lines, -119 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @var string
46 46
 	 */
47
-	var $contacts_id='id';
47
+	var $contacts_id = 'id';
48 48
 
49 49
 	/**
50 50
 	 * Name of the table for distribution lists
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @param Api\Db $db =null
69 69
 	 */
70
-	function __construct(Api\Db $db=null)
70
+	function __construct(Api\Db $db = null)
71 71
 	{
72 72
 		parent::__construct('api', 'egw_addressbook', self::EXTRA_TABLE,
73 73
 			'contact_', '_name', '_value', '_id', $db);
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 		if (isset($param['op']) && !empty($param['op'])) $op = $param['op'];
115 115
 		$advanced_search = false;
116 116
 		if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true;
117
-		$wildcard ='%';
118
-		if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:'');
117
+		$wildcard = '%';
118
+		if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : '');
119 119
 
120 120
 		// fix cat_id filter to search in comma-separated multiple cats and return subcats
121 121
 		if ($filter['cat_id'])
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			// we have no private grants in addressbook at the moment, they have then to be added here too
134 134
 			if ($param['owner'])
135 135
 			{
136
-				if (!$this->grants[(int) $filter['owner']]) return false;	// we have no access to that addressbook
136
+				if (!$this->grants[(int)$filter['owner']]) return false; // we have no access to that addressbook
137 137
 
138 138
 				$filter['owner'] = $param['owner'];
139 139
 				$filter['private'] = 0;
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 			{
143 143
 				if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap')
144 144
 				{
145
-					$filter[] = $this->table_name.'.contact_owner != 0';	// in case there have been accounts in sql previously
145
+					$filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously
146 146
 				}
147 147
 				$filter[] = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id'].
148 148
 					" OR contact_private=0 AND ".$this->table_name.".contact_owner IN (".
149
-					implode(',',array_keys($this->grants))."))";
149
+					implode(',', array_keys($this->grants))."))";
150 150
 			}
151 151
 		}
152 152
 		if ($param['searchletter'])
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
 		}
156 156
 		else
157 157
 		{
158
-			$filter[] = "org_name != ''";// AND org_name IS NOT NULL";
158
+			$filter[] = "org_name != ''"; // AND org_name IS NOT NULL";
159 159
 		}
160 160
 		$sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC';
161 161
 
162
-		list(,$by) = explode(',',$param['org_view']);
162
+		list(,$by) = explode(',', $param['org_view']);
163 163
 		if (!$by)
164 164
 		{
165 165
 			$extra = array(
@@ -172,50 +172,49 @@  discard block
 block discarded – undo
172 172
 		else	// by adr_one_location or org_unit
173 173
 		{
174 174
 			// org total for more then one $by
175
-			$by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" :
176
-				"COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)";
177
-			parent::search($param['search'],array('org_name'),
175
+			$by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)";
176
+			parent::search($param['search'], array('org_name'),
178 177
 				"GROUP BY org_name HAVING $by_expr > 1 ORDER BY org_name $sort", array(
179 178
 				"NULL AS $by",
180 179
 				'1 AS is_main',
181 180
 				'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count',
182 181
 				"COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count",
183 182
 				"COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count",
184
-			),$wildcard,false,$op/*'OR'*/,'UNION',$filter);
183
+			), $wildcard, false, $op/*'OR'*/, 'UNION', $filter);
185 184
 			// org by location
186
-			parent::search($param['search'],array('org_name'),
185
+			parent::search($param['search'], array('org_name'),
187 186
 				"GROUP BY org_name,$by ORDER BY org_name $sort,$by $sort", array(
188 187
 				"CASE WHEN $by IS NULL THEN '' ELSE $by END AS $by",
189 188
 				'0 AS is_main',
190 189
 				'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count',
191 190
 				"COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count",
192 191
 				"COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count",
193
-			),$wildcard,false,$op/*'OR'*/,'UNION',$filter);
192
+			), $wildcard, false, $op/*'OR'*/, 'UNION', $filter);
194 193
 			$append = "ORDER BY org_name $sort,is_main DESC,$by $sort";
195 194
 		}
196
-		$rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/,
197
-			array($param['start'],$param['num_rows']),$filter);
195
+		$rows = parent::search($param['search'], array('org_name'), $append, $extra, $wildcard, false, $op/*'OR'*/,
196
+			array($param['start'], $param['num_rows']), $filter);
198 197
 
199 198
 		if (!$rows) return false;
200 199
 
201 200
 		// query the values for *_count == 1, to display them instead
202 201
 		$filter['org_name'] = $orgs = array();
203
-		foreach($rows as $row)
202
+		foreach ($rows as $row)
204 203
 		{
205 204
 			if ($row['org_unit_count'] == 1 || $row['adr_one_locality_count'] == 1)
206 205
 			{
207
-				$filter['org_name'][$row['org_name']] = $row['org_name'];	// use as key too to have every org only once
206
+				$filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once
208 207
 			}
209
-			$org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count']==1 ? $row[$by] : '|||') : '');
208
+			$org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count'] == 1 ? $row[$by] : '|||') : '');
210 209
 			$orgs[$org_key] = $row;
211 210
 		}
212 211
 		unset($rows);
213 212
 
214 213
 		if (count($filter['org_name']))
215 214
 		{
216
-			foreach((array) parent::search(null, array('org_name','org_unit','adr_one_locality'),
215
+			foreach ((array)parent::search(null, array('org_name', 'org_unit', 'adr_one_locality'),
217 216
 				'GROUP BY org_name,org_unit,adr_one_locality',
218
-				'',$wildcard,false,$op/*'AND'*/,false,$filter) as $row)
217
+				'', $wildcard, false, $op/*'AND'*/, false, $filter) as $row)
219 218
 			{
220 219
 				$org_key = $row['org_name'].($by ? '|||'.$row[$by] : '');
221 220
 				if ($orgs[$org_key]['org_unit_count'] == 1)
@@ -265,9 +264,9 @@  discard block
 block discarded – undo
265 264
 	 * @param boolean $ignore_acl =false true: no acl check
266 265
 	 * @return boolean/array of matching rows (the row is an array of the cols) or False
267 266
 	 */
268
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false, $ignore_acl=false)
267
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false, $ignore_acl = false)
269 268
 	{
270
-		if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n";
269
+		if ((int)$this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n";
271 270
 		//error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')");
272 271
 
273 272
 		$owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null);
@@ -283,10 +282,10 @@  discard block
 block discarded – undo
283 282
 		{
284 283
 			if ($filter['cat_id'][0] == '!')
285 284
 			{
286
-				$filter['cat_id'] = substr($filter['cat_id'],1);
285
+				$filter['cat_id'] = substr($filter['cat_id'], 1);
287 286
 				$not = 'NOT';
288 287
 			}
289
-			$filter[] = $this->_cat_filter($filter['cat_id'],$not);
288
+			$filter[] = $this->_cat_filter($filter['cat_id'], $not);
290 289
 			unset($filter['cat_id']);
291 290
 		}
292 291
 
@@ -296,17 +295,17 @@  discard block
 block discarded – undo
296 295
 		{
297 296
 			// add read ACL for groupmembers (they have no
298 297
 			if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
299
-				(!isset($filter['owner']) || in_array('0',(array)$filter['owner'])))
298
+				(!isset($filter['owner']) || in_array('0', (array)$filter['owner'])))
300 299
 			{
301 300
 				$groupmembers = array();
302
-				foreach($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $group_id)
301
+				foreach ($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $group_id)
303 302
 				{
304
-					if (($members = $GLOBALS['egw']->accounts->members($group_id,true)))
303
+					if (($members = $GLOBALS['egw']->accounts->members($group_id, true)))
305 304
 					{
306
-						$groupmembers = array_merge($groupmembers,$members);
305
+						$groupmembers = array_merge($groupmembers, $members);
307 306
 					}
308 307
 				}
309
-				$groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.',array(
308
+				$groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.', array(
310 309
 					'account_id' => array_unique($groupmembers),
311 310
 				));
312 311
 			}
@@ -314,34 +313,34 @@  discard block
 block discarded – undo
314 313
 			if (isset($filter['owner']))
315 314
 			{
316 315
 				// no grants for selected owner/addressbook
317
-				if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants))))
316
+				if (!($filter['owner'] = array_intersect((array)$filter['owner'], array_keys($this->grants))))
318 317
 				{
319 318
 					if (!isset($groupmember_sql)) return false;
320
-					$filter[] = substr($groupmember_sql,4);
319
+					$filter[] = substr($groupmember_sql, 4);
321 320
 					unset($filter['owner']);
322 321
 				}
323 322
 				// for an owner filter, which does NOT include current user, filter out private entries
324
-				elseif (!in_array($GLOBALS['egw_info']['user']['account_id'],$filter['owner']))
323
+				elseif (!in_array($GLOBALS['egw_info']['user']['account_id'], $filter['owner']))
325 324
 				{
326 325
 					$filter['private'] = 0;
327 326
 				}
328 327
 				// if multiple addressbooks (incl. current owner) are searched, we need full acl filter
329
-				elseif(count($filter['owner']) > 1)
328
+				elseif (count($filter['owner']) > 1)
330 329
 				{
331 330
 					$filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id'].
332 331
 						" OR contact_private=0 AND $this->table_name.contact_owner IN (".
333
-						implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)";
332
+						implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)";
334 333
 				}
335 334
 			}
336 335
 			else	// search all addressbooks, incl. accounts
337 336
 			{
338 337
 				if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap')
339 338
 				{
340
-					$filter[] = $this->table_name.'.contact_owner != 0';	// in case there have been accounts in sql previously
339
+					$filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously
341 340
 				}
342 341
 				$filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id'].
343 342
 					" OR contact_private=0 AND $this->table_name.contact_owner IN (".
344
-					implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)";
343
+					implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)";
345 344
 			}
346 345
 		}
347 346
 		if (isset($filter['list']))
@@ -351,21 +350,21 @@  discard block
 block discarded – undo
351 350
 			unset($filter['list']);
352 351
 		}
353 352
 		// add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin)
354
-		if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository,0,3) == 'sql' &&
355
-			strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter))
353
+		if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository, 0, 3) == 'sql' &&
354
+			strpos($join, $GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id', $filter))
356 355
 		{
357 356
 			$join .= self::ACCOUNT_ACTIVE_JOIN;
358
-			$filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER);
357
+			$filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER);
359 358
 		}
360 359
 		if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by))	// search also adds a join for custom fields!
361 360
 		{
362
-			switch(gettype($only_keys))
361
+			switch (gettype($only_keys))
363 362
 			{
364 363
 				case 'boolean':
365 364
 					// Correctly handled by parent class
366 365
 					break;
367 366
 				case 'string':
368
-					$only_keys = explode(',',$only_keys);
367
+					$only_keys = explode(',', $only_keys);
369 368
 					// fall through
370 369
 			}
371 370
 			// postgres requires that expressions in order by appear in the columns of a distinct select
@@ -373,14 +372,14 @@  discard block
 block discarded – undo
373 372
 			if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui",
374 373
 				$order_by, $all_matches, PREG_SET_ORDER))
375 374
 			{
376
-				if (!is_array($extra_cols))	$extra_cols = $extra_cols ? explode(',',$extra_cols) : array();
377
-				foreach($all_matches as $matches)
375
+				if (!is_array($extra_cols))	$extra_cols = $extra_cols ? explode(',', $extra_cols) : array();
376
+				foreach ($all_matches as $matches)
378 377
 				{
379 378
 					$table = '';
380 379
 					$column = $matches[1];
381
-					if ($column[0] == '#') continue;	// order by custom field is handeled in so_sql_cf anyway
380
+					if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway
382 381
 					if (($key = array_search($column, $this->db_cols)) !== false) $column = $key;
383
-					if (strpos($column,'.') === false)
382
+					if (strpos($column, '.') === false)
384 383
 					{
385 384
 						$table = $column == $this->extra_value ? $this->extra_table : $this->table_name;
386 385
 						if (isset($this->db_cols[$column]))
@@ -396,34 +395,34 @@  discard block
 block discarded – undo
396 395
 					//_debug_array($matches);
397 396
 					if (!empty($order_by) && $table) // postgres requires explizit order by
398 397
 					{
399
-						$order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by);
398
+						$order_by = str_replace($matches[0], $table.$column.' '.$matches[2].' '.$matches[3].$matches[4], $order_by);
400 399
 					}
401 400
 				}
402 401
 				//_debug_array($order_by); _debug_array($extra_cols);
403 402
 			}
404 403
 
405 404
 			// Understand search by date with wildcard (????.10.??) according to user date preference
406
-			if(is_string($criteria) && strpos($criteria, '?') !== false)
405
+			if (is_string($criteria) && strpos($criteria, '?') !== false)
407 406
 			{
408 407
 				// First, check for a 'date', with wildcards, in the user's format
409
-				$date_regex = str_replace('Q','d',
410
-					str_replace(array('Y','m','d','.','-'),
411
-						array('(?P<Y>(?:\?|\Q){4})','(?P<m>(?:\?|\Q){2})','(?P<d>(?:\?|\Q){2})','\.','\-'),
408
+				$date_regex = str_replace('Q', 'd',
409
+					str_replace(array('Y', 'm', 'd', '.', '-'),
410
+						array('(?P<Y>(?:\?|\Q){4})', '(?P<m>(?:\?|\Q){2})', '(?P<d>(?:\?|\Q){2})', '\.', '\-'),
412 411
 							$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']));
413 412
 
414
-				if(preg_match_all('$'.$date_regex.'$', $criteria, $matches))
413
+				if (preg_match_all('$'.$date_regex.'$', $criteria, $matches))
415 414
 				{
416
-					foreach($matches[0] as $m_id => $match)
415
+					foreach ($matches[0] as $m_id => $match)
417 416
 					{
418 417
 						// Birthday is Y-m-d
419
-						$criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*",$criteria);
418
+						$criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*", $criteria);
420 419
 					}
421 420
 				}
422 421
 			}
423 422
 		}
424
-		$rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
423
+		$rows = & parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
425 424
 
426
-		if ($start === false) $this->total = is_array($rows) ? count($rows) : 0;	// so_sql sets total only for $start !== false!
425
+		if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false!
427 426
 
428 427
 		return $rows;
429 428
 	}
@@ -435,18 +434,18 @@  discard block
 block discarded – undo
435 434
 	 * @param int|array $cat_id
436 435
 	 * @return string sql to filter by given cat
437 436
 	 */
438
-	function _cat_filter($cat_id, $not='')
437
+	function _cat_filter($cat_id, $not = '')
439 438
 	{
440 439
 		if (!is_object($GLOBALS['egw']->categories))
441 440
 		{
442 441
 			$GLOBALS['egw']->categories = new Api\Categories;
443 442
 		}
444
-		foreach($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat)
443
+		foreach ($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat)
445 444
 		{
446
-			$cat_filter[] = $this->db->concat("','",cat_id,"','")." $not LIKE '%,$cat,%'";
445
+			$cat_filter[] = $this->db->concat("','", cat_id, "','")." $not LIKE '%,$cat,%'";
447 446
 		}
448
-		$cfilter = '('.implode(' OR ',$cat_filter).')';
449
-		if(!empty($not))
447
+		$cfilter = '('.implode(' OR ', $cat_filter).')';
448
+		if (!empty($not))
450 449
 		{
451 450
 			$cfilter = "( $cfilter OR cat_id IS NULL )";
452 451
 		}
@@ -463,9 +462,9 @@  discard block
 block discarded – undo
463 462
 	function _cat_search($cats)
464 463
 	{
465 464
 		$cat_filter = array();
466
-		foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat)
465
+		foreach (is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',', $cats)) as $cat)
467 466
 		{
468
-			if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'";
467
+			if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','", cat_id, "','")." LIKE '%,$cat,%'";
469 468
 		}
470 469
 		return $cat_filter;
471 470
 	}
@@ -476,32 +475,32 @@  discard block
 block discarded – undo
476 475
 	 * @param int $account_id account-id of the old owner
477 476
 	 * @param int $new_owner account-id of the new owner
478 477
 	 */
479
-	function change_owner($account_id,$new_owner)
478
+	function change_owner($account_id, $new_owner)
480 479
 	{
481 480
 		if (!$new_owner)	// otherwise we would create an account (contact_owner==0)
482 481
 		{
483 482
 			throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!");
484 483
 		}
485 484
 		// contacts
486
-		$this->db->update($this->table_name,array(
485
+		$this->db->update($this->table_name, array(
487 486
 			'contact_owner' => $new_owner,
488
-		),array(
487
+		), array(
489 488
 			'contact_owner' => $account_id,
490
-		),__LINE__,__FILE__);
489
+		), __LINE__, __FILE__);
491 490
 
492 491
 		// cfs
493 492
 		$this->db->update(self::EXTRA_TABLE, array(
494 493
 			'contact_owner' => $new_owner
495
-		),array(
494
+		), array(
496 495
 			'contact_owner' => $account_id
497 496
 		), __LINE__, __FILE__);
498 497
 
499 498
 		// lists
500 499
 		$this->db->update($this->lists_table, array(
501 500
 			'list_owner' => $new_owner,
502
-		),array(
501
+		), array(
503 502
 			'list_owner' => $account_id,
504
-		),__LINE__,__FILE__);
503
+		), __LINE__, __FILE__);
505 504
 	}
506 505
 
507 506
 	/**
@@ -515,21 +514,21 @@  discard block
 block discarded – undo
515 514
 	 * 	if int|array only return members from the given owners addressbook(s)
516 515
 	 * @return array with list_id => array(list_id,list_name,list_owner,...) pairs
517 516
 	 */
518
-	function get_lists($uids,$uid_column='list_owner',$member_attr=null,$limit_in_ab=false)
517
+	function get_lists($uids, $uid_column = 'list_owner', $member_attr = null, $limit_in_ab = false)
519 518
 	{
520 519
 		if (is_array($uids) && array_key_exists('list_id', $uids))
521 520
 		{
522
-			$uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.',array('list_id' => $uids['list_id']));
521
+			$uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.', array('list_id' => $uids['list_id']));
523 522
 			unset($uids['list_id']);
524 523
 		}
525 524
 		$lists = array();
526
-		foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__,
527
-			false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row)
525
+		foreach ($this->db->select($this->lists_table, '*', $uid_column ? array($uid_column=>$uids) : $uids, __LINE__, __FILE__,
526
+			false, 'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row)
528 527
 		{
529 528
 			if ($member_attr) $row['members'] = array();
530 529
 			$lists[$row['list_id']] = $row;
531 530
 		}
532
-		if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name')))
531
+		if ($lists && $member_attr && in_array($member_attr, array('contact_id', 'contact_uid', 'caldav_name')))
533 532
 		{
534 533
 			if ($limit_in_ab)
535 534
 			{
@@ -543,10 +542,9 @@  discard block
 block discarded – undo
543 542
 					$in_ab_join .= "list_owner=$this->table_name.contact_owner";
544 543
 				}
545 544
 			}
546
-			foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr",
545
+			foreach ($this->db->select($this->ab2list_table, "$this->ab2list_table.list_id,$this->table_name.$member_attr",
547 546
 				$this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))),
548
-				__LINE__,__FILE__,false,$member_attr=='contact_id' ? '' :
549
-				'',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row)
547
+				__LINE__, __FILE__, false, $member_attr == 'contact_id' ? '' : '', false, 0, "JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row)
550 548
 			{
551 549
 				$lists[$row['list_id']]['members'][] = $row[$member_attr];
552 550
 			}
@@ -564,7 +562,7 @@  discard block
 block discarded – undo
564 562
 	 * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name'
565 563
 	 * @return int|boolean integer list_id or false on error
566 564
 	 */
567
-	function add_list($keys,$owner,$contacts=array(),array &$data=array())
565
+	function add_list($keys, $owner, $contacts = array(), array &$data = array())
568 566
 	{
569 567
 		//error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace());
570 568
 		if (!$keys && !$data || !(int)$owner) return false;
@@ -578,7 +576,7 @@  discard block
 block discarded – undo
578 576
 		{
579 577
 			$data['list_owner'] = $owner;
580 578
 		}
581
-		if (!$keys || !($list_id = $this->db->select($this->lists_table,'list_id',$keys,__LINE__,__FILE__)->fetchColumn()))
579
+		if (!$keys || !($list_id = $this->db->select($this->lists_table, 'list_id', $keys, __LINE__, __FILE__)->fetchColumn()))
582 580
 		{
583 581
 			$data['list_created'] = time();
584 582
 			$data['list_creator'] = $GLOBALS['egw_info']['user']['account_id'];
@@ -591,9 +589,9 @@  discard block
 block discarded – undo
591 589
 		$data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id'];
592 590
 		if (!$data['list_id']) unset($data['list_id']);
593 591
 
594
-		if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false;
592
+		if (!$this->db->insert($this->lists_table, $data, $keys, __LINE__, __FILE__)) return false;
595 593
 
596
-		if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) &&
594
+		if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table, 'list_id')) &&
597 595
 			(!isset($data['list_uid']) || !isset($data['list_carddav_name'])))
598 596
 		{
599 597
 			$update = array();
@@ -605,9 +603,9 @@  discard block
 block discarded – undo
605 603
 			{
606 604
 				$update['list_carddav_name'] = $data['list_carddav_name'] = $data['list_uid'].'.vcf';
607 605
 			}
608
-			$this->db->update($this->lists_table,$update,array('list_id'=>$list_id),__LINE__,__FILE__);
606
+			$this->db->update($this->lists_table, $update, array('list_id'=>$list_id), __LINE__, __FILE__);
609 607
 
610
-			$this->add2list($list_id,$contacts,array());
608
+			$this->add2list($list_id, $contacts, array());
611 609
 		}
612 610
 		if ($keys) $data += $keys;
613 611
 		//error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id));
@@ -622,39 +620,39 @@  discard block
 block discarded – undo
622 620
 	 * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array()
623 621
 	 * @return false on error
624 622
 	 */
625
-	function add2list($contact,$list,array $existing=null)
623
+	function add2list($contact, $list, array $existing = null)
626 624
 	{
627 625
 		if (!(int)$list || !is_array($contact) && !(int)$contact) return false;
628 626
 
629 627
 		if (!is_array($existing))
630 628
 		{
631 629
 			$existing = array();
632
-			foreach($this->db->select($this->ab2list_table,'contact_id',array('list_id'=>$list),__LINE__,__FILE__) as $row)
630
+			foreach ($this->db->select($this->ab2list_table, 'contact_id', array('list_id'=>$list), __LINE__, __FILE__) as $row)
633 631
 			{
634 632
 				$existing[] = $row['contact_id'];
635 633
 			}
636 634
 		}
637
-		if (!($to_add = array_diff((array)$contact,$existing)))
635
+		if (!($to_add = array_diff((array)$contact, $existing)))
638 636
 		{
639
-			return true;	// no need to insert it, would give sql error
637
+			return true; // no need to insert it, would give sql error
640 638
 		}
641
-		foreach($to_add as $contact)
639
+		foreach ($to_add as $contact)
642 640
 		{
643
-			$this->db->insert($this->ab2list_table,array(
641
+			$this->db->insert($this->ab2list_table, array(
644 642
 				'contact_id' => $contact,
645 643
 				'list_id' => $list,
646 644
 				'list_added' => time(),
647 645
 				'list_added_by' => $GLOBALS['egw_info']['user']['account_id'],
648
-			),array(),__LINE__,__FILE__);
646
+			), array(), __LINE__, __FILE__);
649 647
 		}
650 648
 		// update etag
651
-		return $this->db->update($this->lists_table,array(
649
+		return $this->db->update($this->lists_table, array(
652 650
 			'list_etag=list_etag+1',
653 651
 			'list_modified' => time(),
654 652
 			'list_modifier' => $GLOBALS['egw_info']['user']['account_id'],
655
-		),array(
653
+		), array(
656 654
 			'list_id' => $list,
657
-		),__LINE__,__FILE__);
655
+		), __LINE__, __FILE__);
658 656
 	}
659 657
 
660 658
 	/**
@@ -664,7 +662,7 @@  discard block
 block discarded – undo
664 662
 	 * @param int $list =null list-id or null to remove from all lists
665 663
 	 * @return false on error
666 664
 	 */
667
-	function remove_from_list($contact,$list=null)
665
+	function remove_from_list($contact, $list = null)
668 666
 	{
669 667
 		if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false;
670 668
 
@@ -678,24 +676,24 @@  discard block
 block discarded – undo
678 676
 		else
679 677
 		{
680 678
 			$list = array();
681
-			foreach($this->db->select($this->ab2list_table,'list_id',$where,__LINE__,__FILE__) as $row)
679
+			foreach ($this->db->select($this->ab2list_table, 'list_id', $where, __LINE__, __FILE__) as $row)
682 680
 			{
683 681
 				$list[] = $row['list_id'];
684 682
 			}
685 683
 		}
686
-		if (!$this->db->delete($this->ab2list_table,$where,__LINE__,__FILE__))
684
+		if (!$this->db->delete($this->ab2list_table, $where, __LINE__, __FILE__))
687 685
 		{
688 686
 			return false;
689 687
 		}
690
-		foreach((array)$list as $list_id)
688
+		foreach ((array)$list as $list_id)
691 689
 		{
692
-			$this->db->update($this->lists_table,array(
690
+			$this->db->update($this->lists_table, array(
693 691
 				'list_etag=list_etag+1',
694 692
 				'list_modified' => time(),
695 693
 				'list_modifier' => $GLOBALS['egw_info']['user']['account_id'],
696
-			),array(
694
+			), array(
697 695
 				'list_id' => $list_id,
698
-			),__LINE__,__FILE__);
696
+			), __LINE__, __FILE__);
699 697
 		}
700 698
 		return true;
701 699
 	}
@@ -708,9 +706,9 @@  discard block
 block discarded – undo
708 706
 	 */
709 707
 	function delete_list($list)
710 708
 	{
711
-		if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false;
709
+		if (!$this->db->delete($this->lists_table, array('list_id' => $list), __LINE__, __FILE__)) return false;
712 710
 
713
-		$this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__);
711
+		$this->db->delete($this->ab2list_table, array('list_id' => $list), __LINE__, __FILE__);
714 712
 
715 713
 		return $this->db->affected_rows();
716 714
 	}
@@ -721,12 +719,12 @@  discard block
 block discarded – undo
721 719
 	 * @param int|array $owner =null null for all lists user has access too
722 720
 	 * @return int
723 721
 	 */
724
-	function lists_ctag($owner=null)
722
+	function lists_ctag($owner = null)
725 723
 	{
726 724
 		if (is_null($owner)) $owner = array_keys($this->grants);
727 725
 
728
-		if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner),
729
-			__LINE__,__FILE__)->fetchColumn()))
726
+		if (!($modified = $this->db->select($this->lists_table, 'MAX(list_modified)', array('list_owner'=>$owner),
727
+			__LINE__, __FILE__)->fetchColumn()))
730 728
 		{
731 729
 			return 0;
732 730
 		}
@@ -741,7 +739,7 @@  discard block
 block discarded – undo
741 739
 	 * @param string $join
742 740
 	 * @return array|boolean
743 741
 	 */
744
-	function read($keys,$extra_cols='',$join='')
742
+	function read($keys, $extra_cols = '', $join = '')
745 743
 	{
746 744
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) {
747 745
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
@@ -754,11 +752,11 @@  discard block
 block discarded – undo
754 752
 			$keys = array('uid' => $keys);
755 753
 		}
756 754
 		try {
757
-			$contact = parent::read($keys,$extra_cols,$join);
755
+			$contact = parent::read($keys, $extra_cols, $join);
758 756
 		}
759 757
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
760 758
 		// caused by non-ascii chars compared with ascii field uid
761
-		catch(Api\Db\Exception $e) {
759
+		catch (Api\Db\Exception $e) {
762 760
 			_egw_log_exception($e);
763 761
 			return false;
764 762
 		}
@@ -766,7 +764,7 @@  discard block
 block discarded – undo
766 764
 		// enforce a minium uid strength
767 765
 		if (is_array($contact) && (!isset($contact['uid'])
768 766
 				|| strlen($contact['uid']) < $minimum_uid_length)) {
769
-			parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id'])));
767
+			parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook', $contact['id'])));
770 768
 		}
771 769
 		return $contact;
772 770
 	}
@@ -780,7 +778,7 @@  discard block
 block discarded – undo
780 778
 	 */
781 779
 	function save($keys = NULL, $extra_where = NULL)
782 780
 	{
783
-		unset($extra_where);	// not used, but required by function signature
781
+		unset($extra_where); // not used, but required by function signature
784 782
 
785 783
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) {
786 784
 			$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
@@ -796,9 +794,9 @@  discard block
 block discarded – undo
796 794
 		{
797 795
 			$etag = $this->data['etag'];
798 796
 			unset($this->data['etag']);
799
-			if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag))))
797
+			if (!($err = parent::save(array('contact_etag=contact_etag+1'), array('contact_etag' => $etag))))
800 798
 			{
801
-				$this->data['etag'] = $etag+1;
799
+				$this->data['etag'] = $etag + 1;
802 800
 			}
803 801
 			else
804 802
 			{
@@ -818,7 +816,7 @@  discard block
 block discarded – undo
818 816
 		// enforce a minium uid strength
819 817
 		if (!isset($this->data['uid']) || strlen($this->data['uid']) < $minimum_uid_length)
820 818
 		{
821
-			$update['uid'] = Api\CalDAV::generate_uid('addressbook',$this->data['id']);
819
+			$update['uid'] = Api\CalDAV::generate_uid('addressbook', $this->data['id']);
822 820
 			//echo "<p>set uid={$this->data['uid']}, etag={$this->data['etag']}</p>";
823 821
 		}
824 822
 		// set carddav_name, if not given by caller
@@ -844,7 +842,7 @@  discard block
 block discarded – undo
844 842
 	{
845 843
 		if (!$list) return false;
846 844
 
847
-		return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch();
845
+		return $this->db->select($this->lists_table, '*', array('list_id'=>$list), __LINE__, __FILE__)->fetch();
848 846
 	}
849 847
 
850 848
 	/**
@@ -855,9 +853,9 @@  discard block
 block discarded – undo
855 853
 	 * @param array $extra_cols =array() extra-data to be saved
856 854
 	 * @return bool false on success, errornumber on failure
857 855
 	 */
858
-	function save_customfields($data, array $extra_cols=array())
856
+	function save_customfields($data, array $extra_cols = array())
859 857
 	{
860
-		return parent::save_customfields($data, array('contact_owner' => $data['owner'])+$extra_cols);
858
+		return parent::save_customfields($data, array('contact_owner' => $data['owner']) + $extra_cols);
861 859
 	}
862 860
 
863 861
 	/**
@@ -866,6 +864,6 @@  discard block
 block discarded – undo
866 864
 	*/
867 865
 	function delete_customfields($data)
868 866
 	{
869
-		$this->db->delete($this->extra_table,$data,__LINE__,__FILE__);
867
+		$this->db->delete($this->extra_table, $data, __LINE__, __FILE__);
870 868
 	}
871 869
 }
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/Customfields.php 2 patches
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
 		'date'     => 'Date',
43 43
 		'date-time'=> 'Date+Time',
44 44
 		'select-account' => 'Select account',
45
-		'button'   => 'Button',         // button to execute javascript
45
+		'button'   => 'Button', // button to execute javascript
46 46
 		'url'      => 'Url',
47 47
 		'url-email'=> 'EMail',
48 48
 		'url-phone'=> 'Phone number',
49 49
 		'htmlarea' => 'Formatted Text (HTML)',
50
-		'link-entry' => 'Select entry',         // should be last type, as the individual apps get added behind
50
+		'link-entry' => 'Select entry', // should be last type, as the individual apps get added behind
51 51
 	);
52 52
 
53 53
 	/**
@@ -86,24 +86,24 @@  discard block
 block discarded – undo
86 86
 	 * @param string $cname
87 87
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
88 88
 	 */
89
-	public function beforeSendToClient($cname, array $expand=null)
89
+	public function beforeSendToClient($cname, array $expand = null)
90 90
 	{
91 91
 		// No name, no way to get parameters client-side.
92
-		if(!$this->id) $this->id = self::GLOBAL_ID;
92
+		if (!$this->id) $this->id = self::GLOBAL_ID;
93 93
 
94 94
 		$form_name = self::form_name($cname, $this->id, $expand);
95 95
 
96 96
 		// Store properties at top level, so all customfield widgets can share
97
-		if($this->attrs['app'])
97
+		if ($this->attrs['app'])
98 98
 		{
99 99
 			$app = $this->attrs['app'];
100 100
 		}
101 101
 		else
102 102
 		{
103
-			$app =& $this->getElementAttribute(self::GLOBAL_VALS, 'app');
104
-			if($this->getElementAttribute($form_name, 'app'))
103
+			$app = & $this->getElementAttribute(self::GLOBAL_VALS, 'app');
104
+			if ($this->getElementAttribute($form_name, 'app'))
105 105
 			{
106
-				$app =& $this->getElementAttribute($form_name, 'app');
106
+				$app = & $this->getElementAttribute($form_name, 'app');
107 107
 			}
108 108
 			else
109 109
 			{
@@ -112,21 +112,21 @@  discard block
 block discarded – undo
112 112
 			}
113 113
 		}
114 114
 
115
-		if($this->getElementAttribute($form_name, 'customfields'))
115
+		if ($this->getElementAttribute($form_name, 'customfields'))
116 116
 		{
117
-			$customfields =& $this->getElementAttribute($form_name, 'customfields');
117
+			$customfields = & $this->getElementAttribute($form_name, 'customfields');
118 118
 		}
119
-		elseif($app)
119
+		elseif ($app)
120 120
 		{
121 121
 			// Checking creates it even if it wasn't there
122 122
 			unset(self::$request->modifications[$form_name]['customfields']);
123
-			$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
123
+			$customfields = & $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
124 124
 		}
125 125
 
126
-		if(!$app)
126
+		if (!$app)
127 127
 		{
128
-			$app =& $this->setElementAttribute(self::GLOBAL_VALS, 'app', $GLOBALS['egw_info']['flags']['currentapp']);
129
-			$customfields =& $this->setElementAttribute(self::GLOBAL_VALS, 'customfields', Api\Storage\Customfields::get($app));
128
+			$app = & $this->setElementAttribute(self::GLOBAL_VALS, 'app', $GLOBALS['egw_info']['flags']['currentapp']);
129
+			$customfields = & $this->setElementAttribute(self::GLOBAL_VALS, 'customfields', Api\Storage\Customfields::get($app));
130 130
 		}
131 131
 
132 132
 		// if we are in the etemplate editor or the app has no cf's, load the cf's from the app the tpl belongs too
@@ -134,29 +134,29 @@  discard block
 block discarded – undo
134 134
 			($GLOBALS['egw_info']['flags']['currentapp'] == 'etemplate' || !$this->attrs['customfields']) || !isset($customfields))
135 135
 		{
136 136
 			// app changed
137
-			$customfields =& Api\Storage\Customfields::get($app);
137
+			$customfields = & Api\Storage\Customfields::get($app);
138 138
 		}
139 139
 		// Filter fields
140
-		if($this->attrs['field-names'])
140
+		if ($this->attrs['field-names'])
141 141
 		{
142 142
 			$fields_name = explode(',', $this->attrs['field-names']);
143
-			foreach($fields_name as &$f)
143
+			foreach ($fields_name as &$f)
144 144
 			{
145 145
 				if ($f[0] == "!")
146 146
 				{
147
-					$f= substr($f,1);
148
-					$negate_fields[]= $f;
147
+					$f = substr($f, 1);
148
+					$negate_fields[] = $f;
149 149
 				}
150
-				$field_filters []= $f;
150
+				$field_filters [] = $f;
151 151
 			}
152 152
 		}
153 153
 
154 154
 		$fields = $customfields;
155 155
 
156
-		$use_private = self::expand_name($this->attrs['use-private'],0,0,'','',self::$cont);
157
-		$this->attrs['sub-type'] = self::expand_name($this->attrs['sub-type'],0,0,'','',self::$cont);
156
+		$use_private = self::expand_name($this->attrs['use-private'], 0, 0, '', '', self::$cont);
157
+		$this->attrs['sub-type'] = self::expand_name($this->attrs['sub-type'], 0, 0, '', '', self::$cont);
158 158
 
159
-		foreach((array)$fields as $key => $field)
159
+		foreach ((array)$fields as $key => $field)
160 160
 		{
161 161
 			// remove private or non-private cf's, if only one kind should be displayed
162 162
 			if ((string)$use_private !== '' && (boolean)$field['private'] != (boolean)$use_private)
@@ -165,36 +165,36 @@  discard block
 block discarded – undo
165 165
 			}
166 166
 
167 167
 			// Remove filtered fields
168
-			if($field_filters && in_array($key, $negate_fields) && in_array($key, $field_filters))
168
+			if ($field_filters && in_array($key, $negate_fields) && in_array($key, $field_filters))
169 169
 			{
170 170
 				unset($fields[$key]);
171 171
 			}
172 172
 		}
173 173
 		// check if name refers to a single custom field --> show only that
174 174
 		$matches = null;
175
-		if (($pos=strpos($form_name,self::$prefix)) !== false && // allow the prefixed name to be an array index too
176
-			preg_match($preg = '/'.self::$prefix.'([^\]]+)/',$form_name,$matches) && isset($fields[$name=$matches[1]]))
175
+		if (($pos = strpos($form_name, self::$prefix)) !== false && // allow the prefixed name to be an array index too
176
+			preg_match($preg = '/'.self::$prefix.'([^\]]+)/', $form_name, $matches) && isset($fields[$name = $matches[1]]))
177 177
 		{
178 178
 			$fields = array($name => $fields[$name]);
179 179
 			$value = array(self::$prefix.$name => $value);
180 180
 			$form_name = self::$prefix.$name;
181 181
 		}
182 182
 
183
-		if(!is_array($fields)) $fields = array();
184
-		switch($type = $this->type)
183
+		if (!is_array($fields)) $fields = array();
184
+		switch ($type = $this->type)
185 185
 		{
186 186
 			case 'customfields-types':
187
-				foreach(self::$cf_types as $lname => $label)
187
+				foreach (self::$cf_types as $lname => $label)
188 188
 				{
189 189
 					$sel_options[$lname] = lang($label);
190
-					$fields_with_vals[]=$lname;
190
+					$fields_with_vals[] = $lname;
191 191
 				}
192 192
 				$link_types = array_intersect_key(Api\Link::app_list('query'), Api\Link::app_list('title'));
193 193
 				// Explicitly add in filemanager, which does not support query or title
194 194
 				$link_types['filemanager'] = lang('filemanager');
195 195
 
196 196
 				ksort($link_types);
197
-				foreach($link_types as $lname => $label)
197
+				foreach ($link_types as $lname => $label)
198 198
 				{
199 199
 					$sel_options[$lname] = '- '.$label;
200 200
 				}
@@ -202,32 +202,32 @@  discard block
 block discarded – undo
202 202
 				self::$transformation['type'][$type]['no_lang'] = true;
203 203
 				return parent::beforeSendToClient($cname, $expand);
204 204
 			case 'customfields-list':
205
-				foreach(array_reverse($fields) as $lname => $field)
205
+				foreach (array_reverse($fields) as $lname => $field)
206 206
 				{
207 207
 					if (!empty($this->attrs['sub-type']) && !empty($field['type2']) &&
208
-						strpos(','.$field['type2'].',',','.$field['type2'].',') === false) continue;    // not for our content type//
208
+						strpos(','.$field['type2'].',', ','.$field['type2'].',') === false) continue; // not for our content type//
209 209
 					if (isset($value[self::$prefix.$lname]) && $value[self::$prefix.$lname] !== '') //break;
210 210
 					{
211
-						$fields_with_vals[]=$lname;
211
+						$fields_with_vals[] = $lname;
212 212
 					}
213 213
 					//$stop_at_field = $name;
214 214
 				}
215 215
 				break;
216 216
 			default:
217
-				foreach(array_reverse($fields) as $lname => $field)
217
+				foreach (array_reverse($fields) as $lname => $field)
218 218
 				{
219
-					$fields_with_vals[]=$lname;
219
+					$fields_with_vals[] = $lname;
220 220
 				}
221 221
 		}
222 222
 		// need to encode values/select-options to keep their order
223
-		foreach($customfields as &$data)
223
+		foreach ($customfields as &$data)
224 224
 		{
225 225
 			if (!empty($data['values']))
226 226
 			{
227 227
 				Select::fix_encoded_options($data['values']);
228 228
 			}
229 229
 		}
230
-		if($fields != $customfields)
230
+		if ($fields != $customfields)
231 231
 		{
232 232
 			// This widget has different settings from global
233 233
 			$this->setElementAttribute($form_name, 'customfields', $fields);
@@ -239,14 +239,14 @@  discard block
 block discarded – undo
239 239
 		parent::beforeSendToClient($cname, $expand);
240 240
 
241 241
 		// Re-format date custom fields from Y-m-d
242
-		$field_settings =& self::get_array(self::$request->modifications, "{$this->id}[customfields]",true);
242
+		$field_settings = & self::get_array(self::$request->modifications, "{$this->id}[customfields]", true);
243 243
 		if (true) $field_settings = array();
244 244
 		$link_types = Api\Link::app_list();
245
-		foreach($fields as $fname => $field)
245
+		foreach ($fields as $fname => $field)
246 246
 		{
247 247
 			// Run beforeSendToClient for each field
248 248
 			$widget = $this->_widget($fname, $field);
249
-			if(method_exists($widget, 'beforeSendToClient'))
249
+			if (method_exists($widget, 'beforeSendToClient'))
250 250
 			{
251 251
 				$widget->beforeSendToClient($this->id == self::GLOBAL_ID ? '' : $this->id, $expand);
252 252
 			}
@@ -263,13 +263,13 @@  discard block
 block discarded – undo
263 263
 	protected function _widget($fname, array $field)
264 264
 	{
265 265
 		static $link_types = null;
266
-		if (!isset($link_types)) $link_types = Api\Link::app_list ();
266
+		if (!isset($link_types)) $link_types = Api\Link::app_list();
267 267
 
268 268
 		$type = $field['type'];
269 269
 		// Link-tos needs to change from appname to link-to
270
-		if($link_types[$field['type']])
270
+		if ($link_types[$field['type']])
271 271
 		{
272
-			if($type == 'filemanager')
272
+			if ($type == 'filemanager')
273 273
 			{
274 274
 				$type = 'vfs-upload';
275 275
 			}
@@ -285,18 +285,18 @@  discard block
 block discarded – undo
285 285
 		$widget->set_attrs($xml);
286 286
 		
287 287
 		// some type-specific (default) attributes
288
-		switch($type)
288
+		switch ($type)
289 289
 		{
290 290
 			case 'date':
291 291
 			case 'date-time':
292 292
 				$widget->attrs['dataformat'] = $type == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
293
-				if($field['values']['min']) $widget->attrs['min'] = $field['values']['min'];
294
-				if($field['values']['max']) $widget->attrs['min'] = $field['values']['max'];
293
+				if ($field['values']['min']) $widget->attrs['min'] = $field['values']['min'];
294
+				if ($field['values']['max']) $widget->attrs['min'] = $field['values']['max'];
295 295
 				break;
296 296
 
297 297
 			case 'vfs-upload':
298
-				$widget->attrs['path'] = $field['app'] . ':' .
299
-					self::expand_name('$cont['.Api\Link::get_registry($field['app'],'view_id').']',0,0,0,0,self::$request->content).
298
+				$widget->attrs['path'] = $field['app'].':'.
299
+					self::expand_name('$cont['.Api\Link::get_registry($field['app'], 'view_id').']', 0, 0, 0, 0, self::$request->content).
300 300
 					':'.$field['label'];
301 301
 				break;
302 302
 
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	 * @param array $content
356 356
 	 * @param array &$validated=array() validated content
357 357
 	 */
358
-	public function validate($cname, array $expand, array $content, &$validated=array())
358
+	public function validate($cname, array $expand, array $content, &$validated = array())
359 359
 	{
360 360
 		if ($this->id)
361 361
 		{
@@ -371,14 +371,14 @@  discard block
 block discarded – undo
371 371
 		// if we have no id / use self::GLOBAL_ID, we have to set $value_in in global namespace for regular widgets validation to find
372 372
 		if (!$this->id) $content = array_merge($content, $value_in);
373 373
 		//error_log(__METHOD__."($cname, ...) form_name=$form_name, use-private={$this->attrs['use-private']}, value_in=".array2string($value_in));
374
-		$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
375
-		if(is_array($value_in))
374
+		$customfields = & $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
375
+		if (is_array($value_in))
376 376
 		{
377
-			foreach($value_in as $field => $value)
377
+			foreach ($value_in as $field => $value)
378 378
 			{
379
-				$field_settings = $customfields[$fname=substr($field,1)];
379
+				$field_settings = $customfields[$fname = substr($field, 1)];
380 380
 
381
-				if ((string)$this->attrs['use-private'] !== '' &&	// are only (non-)private fields requested
381
+				if ((string)$this->attrs['use-private'] !== '' && // are only (non-)private fields requested
382 382
 					(boolean)$field_settings['private'] != ($this->attrs['use-private'] != '0'))
383 383
 				{
384 384
 					continue;
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
 				// widget has no validate method, eg. is only displaying stuff --> nothing to validate
397 397
 				if (!method_exists($widget, 'validate')) continue;
398 398
 				$widget->validate($form_name != self::GLOBAL_ID ? $form_name : $cname, $expand, $content, $validated);
399
-				$field_name = $this->id[0] == self::$prefix && $customfields[substr($this->id,1)] ? $this->id : self::form_name($form_name != self::GLOBAL_ID ? $form_name : $cname, $field);
400
-				$valid =& self::get_array($validated, $field_name, true);
399
+				$field_name = $this->id[0] == self::$prefix && $customfields[substr($this->id, 1)] ? $this->id : self::form_name($form_name != self::GLOBAL_ID ? $form_name : $cname, $field);
400
+				$valid = & self::get_array($validated, $field_name, true);
401 401
 
402 402
 				if (is_array($valid)) $valid = implode(',', $valid);
403 403
 				// NULL is valid for most fields, but not custom fields due to backend handling
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 		elseif ($this->type == 'customfields-types')
410 410
 		{
411 411
 			// Transformation doesn't handle validation
412
-			$valid =& self::get_array($validated, $this->id ? $form_name : $field, true);
412
+			$valid = & self::get_array($validated, $this->id ? $form_name : $field, true);
413 413
 			if (true) $valid = $value_in;
414 414
 			//error_log(__METHOD__."() $form_name $field: ".array2string($value).' --> '.array2string($value));
415 415
 		}
Please login to merge, or discard this patch.
Braces   +57 added lines, -14 removed lines patch added patch discarded remove patch
@@ -89,7 +89,10 @@  discard block
 block discarded – undo
89 89
 	public function beforeSendToClient($cname, array $expand=null)
90 90
 	{
91 91
 		// No name, no way to get parameters client-side.
92
-		if(!$this->id) $this->id = self::GLOBAL_ID;
92
+		if(!$this->id)
93
+		{
94
+			$this->id = self::GLOBAL_ID;
95
+		}
93 96
 
94 97
 		$form_name = self::form_name($cname, $this->id, $expand);
95 98
 
@@ -180,7 +183,10 @@  discard block
 block discarded – undo
180 183
 			$form_name = self::$prefix.$name;
181 184
 		}
182 185
 
183
-		if(!is_array($fields)) $fields = array();
186
+		if(!is_array($fields))
187
+		{
188
+			$fields = array();
189
+		}
184 190
 		switch($type = $this->type)
185 191
 		{
186 192
 			case 'customfields-types':
@@ -205,11 +211,18 @@  discard block
 block discarded – undo
205 211
 				foreach(array_reverse($fields) as $lname => $field)
206 212
 				{
207 213
 					if (!empty($this->attrs['sub-type']) && !empty($field['type2']) &&
208
-						strpos(','.$field['type2'].',',','.$field['type2'].',') === false) continue;    // not for our content type//
209
-					if (isset($value[self::$prefix.$lname]) && $value[self::$prefix.$lname] !== '') //break;
214
+						strpos(','.$field['type2'].',',','.$field['type2'].',') === false)
215
+					{
216
+						continue;
217
+					}
218
+					// not for our content type//
219
+					if (isset($value[self::$prefix.$lname]) && $value[self::$prefix.$lname] !== '')
220
+					{
221
+						//break;
210 222
 					{
211 223
 						$fields_with_vals[]=$lname;
212 224
 					}
225
+					}
213 226
 					//$stop_at_field = $name;
214 227
 				}
215 228
 				break;
@@ -240,7 +253,10 @@  discard block
 block discarded – undo
240 253
 
241 254
 		// Re-format date custom fields from Y-m-d
242 255
 		$field_settings =& self::get_array(self::$request->modifications, "{$this->id}[customfields]",true);
243
-		if (true) $field_settings = array();
256
+		if (true)
257
+		{
258
+			$field_settings = array();
259
+		}
244 260
 		$link_types = Api\Link::app_list();
245 261
 		foreach($fields as $fname => $field)
246 262
 		{
@@ -263,7 +279,10 @@  discard block
 block discarded – undo
263 279
 	protected function _widget($fname, array $field)
264 280
 	{
265 281
 		static $link_types = null;
266
-		if (!isset($link_types)) $link_types = Api\Link::app_list ();
282
+		if (!isset($link_types))
283
+		{
284
+			$link_types = Api\Link::app_list ();
285
+		}
267 286
 
268 287
 		$type = $field['type'];
269 288
 		// Link-tos needs to change from appname to link-to
@@ -290,8 +309,14 @@  discard block
 block discarded – undo
290 309
 			case 'date':
291 310
 			case 'date-time':
292 311
 				$widget->attrs['dataformat'] = $type == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
293
-				if($field['values']['min']) $widget->attrs['min'] = $field['values']['min'];
294
-				if($field['values']['max']) $widget->attrs['min'] = $field['values']['max'];
312
+				if($field['values']['min'])
313
+				{
314
+					$widget->attrs['min'] = $field['values']['min'];
315
+				}
316
+				if($field['values']['max'])
317
+				{
318
+					$widget->attrs['min'] = $field['values']['max'];
319
+				}
295 320
 				break;
296 321
 
297 322
 			case 'vfs-upload':
@@ -308,7 +333,10 @@  discard block
 block discarded – undo
308 333
 				break;
309 334
 
310 335
 			default:
311
-				if (substr($type, 0, 7) !== 'select-' && $type != 'ajax_select') break;
336
+				if (substr($type, 0, 7) !== 'select-' && $type != 'ajax_select')
337
+				{
338
+					break;
339
+				}
312 340
 				// fall-through for all select-* widgets
313 341
 			case 'select':
314 342
 				$this->attrs['multiple'] = $field['rows'] > 1;
@@ -369,7 +397,10 @@  discard block
 block discarded – undo
369 397
 		$all_readonly = $this->is_readonly($cname, $form_name);
370 398
 		$value_in = self::get_array($content, $form_name);
371 399
 		// if we have no id / use self::GLOBAL_ID, we have to set $value_in in global namespace for regular widgets validation to find
372
-		if (!$this->id) $content = array_merge($content, $value_in);
400
+		if (!$this->id)
401
+		{
402
+			$content = array_merge($content, $value_in);
403
+		}
373 404
 		//error_log(__METHOD__."($cname, ...) form_name=$form_name, use-private={$this->attrs['use-private']}, value_in=".array2string($value_in));
374 405
 		$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
375 406
 		if(is_array($value_in))
@@ -394,15 +425,24 @@  discard block
 block discarded – undo
394 425
 				// run validation method of widget implementing this custom field
395 426
 				$widget = $this->_widget($fname, $field_settings);
396 427
 				// widget has no validate method, eg. is only displaying stuff --> nothing to validate
397
-				if (!method_exists($widget, 'validate')) continue;
428
+				if (!method_exists($widget, 'validate'))
429
+				{
430
+					continue;
431
+				}
398 432
 				$widget->validate($form_name != self::GLOBAL_ID ? $form_name : $cname, $expand, $content, $validated);
399 433
 				$field_name = $this->id[0] == self::$prefix && $customfields[substr($this->id,1)] ? $this->id : self::form_name($form_name != self::GLOBAL_ID ? $form_name : $cname, $field);
400 434
 				$valid =& self::get_array($validated, $field_name, true);
401 435
 
402
-				if (is_array($valid)) $valid = implode(',', $valid);
436
+				if (is_array($valid))
437
+				{
438
+					$valid = implode(',', $valid);
439
+				}
403 440
 				// NULL is valid for most fields, but not custom fields due to backend handling
404 441
 				// See so_sql_cf->save()
405
-				if (is_null($valid)) $valid = false;
442
+				if (is_null($valid))
443
+				{
444
+					$valid = false;
445
+				}
406 446
 				//error_log(__METHOD__."() $field_name: ".array2string($value).' --> '.array2string($valid));
407 447
 			}
408 448
 		}
@@ -410,7 +450,10 @@  discard block
 block discarded – undo
410 450
 		{
411 451
 			// Transformation doesn't handle validation
412 452
 			$valid =& self::get_array($validated, $this->id ? $form_name : $field, true);
413
-			if (true) $valid = $value_in;
453
+			if (true)
454
+			{
455
+				$valid = $value_in;
456
+			}
414 457
 			//error_log(__METHOD__."() $form_name $field: ".array2string($value).' --> '.array2string($value));
415 458
 		}
416 459
 	}
Please login to merge, or discard this patch.
infolog/inc/class.infolog_so.inc.php 1 patch
Spacing   +160 added lines, -161 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 * @param array $grants =array()
72 72
 	 * @return soinfolog
73 73
 	 */
74
-	function __construct( $grants=array() )
74
+	function __construct($grants = array())
75 75
 	{
76 76
 		$this->db     = clone($GLOBALS['egw']->db);
77 77
 		$this->db->set_app('infolog');
@@ -87,18 +87,18 @@  discard block
 block discarded – undo
87 87
 	 * @param array $info infolog entry as array
88 88
 	 * @return boolean
89 89
 	 */
90
-	function is_responsible($info,$user=null)
90
+	function is_responsible($info, $user = null)
91 91
 	{
92 92
 		if (!$user) $user = $this->user;
93 93
 
94 94
 		static $um_cache = array();
95
-		if ($user == $this->user) $user_and_memberships =& $um_cache[$user];
95
+		if ($user == $this->user) $user_and_memberships = & $um_cache[$user];
96 96
 		if (!isset($user_and_memberships))
97 97
 		{
98
-			$user_and_memberships = $GLOBALS['egw']->accounts->memberships($user,true);
98
+			$user_and_memberships = $GLOBALS['egw']->accounts->memberships($user, true);
99 99
 			$user_and_memberships[] = $user;
100 100
 		}
101
-		return $info['info_responsible'] && array_intersect((array)$info['info_responsible'],$user_and_memberships);
101
+		return $info['info_responsible'] && array_intersect((array)$info['info_responsible'], $user_and_memberships);
102 102
 	}
103 103
 
104 104
 	/**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @param int $user =null user to check, default (null) $this->user
112 112
 	 * @return boolean True if access is granted else False
113 113
 	 */
114
-	function check_access( $info,$required_rights,$implicit_edit=false,array $grants=null,$user=null )
114
+	function check_access($info, $required_rights, $implicit_edit = false, array $grants = null, $user = null)
115 115
 	{
116 116
 		if (is_null($grants)) $grants = $this->grants;
117 117
 		if (!$user) $user = $this->user;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 		{
124 124
 
125 125
 		}
126
-		elseif ((int) $info != $this->data['info_id'])      	// already loaded?
126
+		elseif ((int)$info != $this->data['info_id'])      	// already loaded?
127 127
 		{
128 128
 			// dont change our own internal data,
129 129
 			$backup_data = $this->data;
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
 			return False;
140 140
 		}
141 141
 		$owner = $info['info_owner'];
142
-		$access_ok = $owner == $user ||	// user has all rights
142
+		$access_ok = $owner == $user || // user has all rights
143 143
 			// ACL only on public entrys || $owner granted _PRIVATE
144
-			(!!($grants[$owner] & $required_rights) ||
145
-				$this->is_responsible($info,$user) &&	// implicite rights for responsible user(s) and his memberships
144
+			(!!($grants[$owner]&$required_rights) ||
145
+				$this->is_responsible($info, $user) && // implicite rights for responsible user(s) and his memberships
146 146
 				($required_rights == Acl::READ || $required_rights == Acl::ADD || $implicit_edit && $required_rights == Acl::EDIT)) &&
147
-			($info['info_access'] == 'public' || !!($this->grants[$user] & Acl::PRIVAT));
147
+			($info['info_access'] == 'public' || !!($this->grants[$user]&Acl::PRIVAT));
148 148
 
149 149
 		// error_log(__METHOD__."($info[info_id],$required_rights,$implicit_edit,".array2string($grants).",$user) returning ".array2string($access_ok));
150 150
 		return $access_ok;
@@ -163,23 +163,22 @@  discard block
 block discarded – undo
163 163
 		if (!$users) return '0';
164 164
 
165 165
 		$responsible = array();
166
-		foreach((array)$users as $user)
166
+		foreach ((array)$users as $user)
167 167
 		{
168
-			$responsible = array_merge($responsible,(array)
169
-				($user > 0 ? $GLOBALS['egw']->accounts->memberships($user,true) :
170
-					$GLOBALS['egw']->accounts->members($user,true)));
168
+			$responsible = array_merge($responsible, (array)
169
+				($user > 0 ? $GLOBALS['egw']->accounts->memberships($user, true) : $GLOBALS['egw']->accounts->members($user, true)));
171 170
 			$responsible[] = $user;
172 171
 		}
173 172
 		if (is_array($users))
174 173
 		{
175 174
 			$responsible = array_unique($responsible);
176 175
 		}
177
-		foreach($responsible as $key => $uid)
176
+		foreach ($responsible as $key => $uid)
178 177
 		{
179
-			$responsible[$key] = $this->db->concat("','",'info_responsible',"','")." LIKE '%,$uid,%'";
178
+			$responsible[$key] = $this->db->concat("','", 'info_responsible', "','")." LIKE '%,$uid,%'";
180 179
 		}
181 180
 		//echo "<p align=right>responsible_filter($user) = ".'('.implode(' OR ',$responsible).')'."</p>\n";
182
-		return '('.implode(' OR ',$responsible).')';
181
+		return '('.implode(' OR ', $responsible).')';
183 182
 	}
184 183
 
185 184
 	/**
@@ -194,17 +193,17 @@  discard block
 block discarded – undo
194 193
 	function aclFilter($_filter = False)
195 194
 	{
196 195
 		$vars = null;
197
-		preg_match('/(my|responsible|delegated|own|privat|private|all|user)([0-9,-]*)/',$_filter,$vars);
196
+		preg_match('/(my|responsible|delegated|own|privat|private|all|user)([0-9,-]*)/', $_filter, $vars);
198 197
 		$filter = $vars[1];
199 198
 		$f_user = $vars[2];
200 199
 
201 200
 		if (isset($this->acl_filter[$filter.$f_user]))
202 201
 		{
203
-			return $this->acl_filter[$filter.$f_user];  // used cached filter if found
202
+			return $this->acl_filter[$filter.$f_user]; // used cached filter if found
204 203
 		}
205
-		if ($f_user && strpos($f_user,',') !== false)
204
+		if ($f_user && strpos($f_user, ',') !== false)
206 205
 		{
207
-			$f_user = explode(',',$f_user);
206
+			$f_user = explode(',', $f_user);
208 207
 		}
209 208
 
210 209
 		$filtermethod = " (info_owner=$this->user"; // user has all rights
@@ -221,24 +220,24 @@  discard block
 block discarded – undo
221 220
 		{
222 221
 			if (is_array($this->grants))
223 222
 			{
224
-				foreach($this->grants as $user => $grant)
223
+				foreach ($this->grants as $user => $grant)
225 224
 				{
226 225
 					// echo "<p>grants: user=$user, grant=$grant</p>";
227
-					if ($grant & (EGW_ACL_READ|EGW_ACL_EDIT))
226
+					if ($grant&(EGW_ACL_READ|EGW_ACL_EDIT))
228 227
 					{
229 228
 						$public_user_list[] = $user;
230 229
 					}
231
-					if ($grant & Acl::PRIVAT)
230
+					if ($grant&Acl::PRIVAT)
232 231
 					{
233 232
 						$private_user_list[] = $user;
234 233
 					}
235 234
 				}
236 235
 				if (count($private_user_list))
237 236
 				{
238
-					$has_private_access = $this->db->expression($this->info_table,array('info_owner' => $private_user_list));
237
+					$has_private_access = $this->db->expression($this->info_table, array('info_owner' => $private_user_list));
239 238
 				}
240 239
 			}
241
-			$public_access = $this->db->expression($this->info_table,array('info_owner' => $public_user_list));
240
+			$public_access = $this->db->expression($this->info_table, array('info_owner' => $public_user_list));
242 241
 			// implicit read-rights for responsible user
243 242
 			$filtermethod .= " OR (".$this->responsible_filter($this->user).')';
244 243
 
@@ -246,9 +245,9 @@  discard block
 block discarded – undo
246 245
 			if ($filter == 'private' || $filter == 'privat' || $filter == 'own')
247 246
 			{
248 247
 				$filtermethod .= " OR (".$this->responsible_filter($this->user).
249
-					($filter == 'own' && count($public_user_list) ?	// offer's should show up in own, eg. startpage, but need read-access
248
+					($filter == 'own' && count($public_user_list) ? // offer's should show up in own, eg. startpage, but need read-access
250 249
 						" OR info_status = 'offer' AND $public_access" : '').")".
251
-				                 " AND (info_access='public'".($has_private_access?" OR $has_private_access":'').')';
250
+				                 " AND (info_access='public'".($has_private_access ? " OR $has_private_access" : '').')';
252 251
 			}
253 252
 			elseif ($filter != 'my' && $filter != 'responsible')	// none --> all entrys user has rights to see
254 253
 			{
@@ -265,13 +264,13 @@  discard block
 block discarded – undo
265 264
 
266 265
 			if ($filter == 'user' && $f_user)
267 266
 			{
268
-				$filtermethod .= $this->db->expression($this->info_table,' AND (',array(
267
+				$filtermethod .= $this->db->expression($this->info_table, ' AND (', array(
269 268
 					'info_owner' => $f_user,
270
-				)," AND info_responsible='0' OR ",$this->responsible_filter($f_user),')');
269
+				), " AND info_responsible='0' OR ", $this->responsible_filter($f_user), ')');
271 270
 			}
272 271
 		}
273 272
 		//echo "<p>aclFilter(filter='$_filter',user='$f_user') = '$filtermethod', privat_user_list=".print_r($privat_user_list,True).", public_user_list=".print_r($public_user_list,True)."</p>\n";
274
-		return $this->acl_filter[$filter.$f_user] = $filtermethod;  // cache the filter
273
+		return $this->acl_filter[$filter.$f_user] = $filtermethod; // cache the filter
275 274
 	}
276 275
 
277 276
 	/**
@@ -281,18 +280,18 @@  discard block
 block discarded – undo
281 280
 	 * @param boolean $prefix_and =true if true prefix the fileter with ' AND '
282 281
 	 * @return string the necesary sql
283 282
 	 */
284
-	function statusFilter($_filter = '',$prefix_and=true)
283
+	function statusFilter($_filter = '', $prefix_and = true)
285 284
 	{
286 285
 		$vars = null;
287
-		preg_match('/(done|open|offer|deleted|\+deleted)/',$_filter,$vars);
286
+		preg_match('/(done|open|offer|deleted|\+deleted)/', $_filter, $vars);
288 287
 		$filter = $vars[1];
289 288
 
290 289
 		switch ($filter)
291 290
 		{
292 291
 			case 'done':	$filter = "info_status IN ('done','billed','cancelled')"; break;
293 292
 			case 'open':	$filter = "NOT (info_status IN ('done','billed','cancelled','deleted','template','nonactive','archive'))"; break;
294
-			case 'offer':	$filter = "info_status = 'offer'";    break;
295
-			case 'deleted': $filter = "info_status = 'deleted'";  break;
293
+			case 'offer':	$filter = "info_status = 'offer'"; break;
294
+			case 'deleted': $filter = "info_status = 'deleted'"; break;
296 295
 			case '+deleted':$filter = "NOT (info_status IN ('template','nonactive','archive'))"; break;
297 296
 			default:        $filter = "NOT (info_status IN ('deleted','template','nonactive','archive'))"; break;
298 297
 		}
@@ -313,18 +312,18 @@  discard block
 block discarded – undo
313 312
 	function dateFilter($_filter = '')
314 313
 	{
315 314
 		$vars = null;
316
-		preg_match('/(open-upcoming|upcoming|today|overdue|date|enddate)([-\\/.0-9]*)/',$_filter,$vars);
315
+		preg_match('/(open-upcoming|upcoming|today|overdue|date|enddate)([-\\/.0-9]*)/', $_filter, $vars);
317 316
 		$filter = $vars[1];
318 317
 
319
-		if (isset($vars[2]) && !empty($vars[2]) && ($date = preg_split('/[-\\/.]/',$vars[2])))
318
+		if (isset($vars[2]) && !empty($vars[2]) && ($date = preg_split('/[-\\/.]/', $vars[2])))
320 319
 		{
321
-			$today = mktime(-$this->tz_offset,0,0,intval($date[1]),intval($date[2]),intval($date[0]));
322
-			$tomorrow = mktime(-$this->tz_offset,0,0,intval($date[1]),intval($date[2])+1,intval($date[0]));
320
+			$today = mktime(-$this->tz_offset, 0, 0, intval($date[1]), intval($date[2]), intval($date[0]));
321
+			$tomorrow = mktime(-$this->tz_offset, 0, 0, intval($date[1]), intval($date[2]) + 1, intval($date[0]));
323 322
 		}
324 323
 		else
325 324
 		{
326
-			$now = getdate(time()-60*60*$this->tz_offset);
327
-			$tomorrow = mktime(-$this->tz_offset,0,0,$now['mon'],$now['mday']+1,$now['year']);
325
+			$now = getdate(time() - 60 * 60 * $this->tz_offset);
326
+			$tomorrow = mktime(-$this->tz_offset, 0, 0, $now['mon'], $now['mday'] + 1, $now['year']);
328 327
 		}
329 328
 		switch ($filter)
330 329
 		{
@@ -388,7 +387,7 @@  discard block
 block discarded – undo
388 387
 			$minimum_uid_length = 8;
389 388
 		}
390 389
 
391
-		if (!$where || !($this->data = $this->db->select($this->info_table,'*',$where,__LINE__,__FILE__)->fetch()))
390
+		if (!$where || !($this->data = $this->db->select($this->info_table, '*', $where, __LINE__, __FILE__)->fetch()))
392 391
 		{
393 392
 			$this->init( );
394 393
 			//error_log(__METHOD__.'('.array2string($where).') returning FALSE');
@@ -400,15 +399,15 @@  discard block
 block discarded – undo
400 399
 			$this->data['info_uid'] = Api\CalDAV::generate_uid('infolog', $this->data['info_id']);
401 400
 			$this->db->update($this->info_table,
402 401
 				array('info_uid' => $this->data['info_uid']),
403
-				array('info_id' => $this->data['info_id']), __LINE__,__FILE__);
402
+				array('info_id' => $this->data['info_id']), __LINE__, __FILE__);
404 403
 		}
405 404
 		if (!is_array($this->data['info_responsible']))
406 405
 		{
407
-			$this->data['info_responsible'] = $this->data['info_responsible'] ? explode(',',$this->data['info_responsible']) : array();
406
+			$this->data['info_responsible'] = $this->data['info_responsible'] ? explode(',', $this->data['info_responsible']) : array();
408 407
 		}
409 408
 		// Cast back to integer
410 409
 		$this->data['info_id_parent'] = (int)$this->data['info_id_parent'];
411
-		foreach($this->db->select($this->extra_table,'info_extra_name,info_extra_value',array('info_id'=>$this->data['info_id']),__LINE__,__FILE__) as $row)
410
+		foreach ($this->db->select($this->extra_table, 'info_extra_name,info_extra_value', array('info_id'=>$this->data['info_id']), __LINE__, __FILE__) as $row)
412 411
 		{
413 412
 			$this->data['#'.$row['info_extra_name']] = $row['info_extra_value'];
414 413
 		}
@@ -423,16 +422,16 @@  discard block
 block discarded – undo
423 422
 	 * @param boolean $delete_children delete the children, if not set there parent-id to $new_parent
424 423
 	 * @param int $new_parent new parent-id to set for subs
425 424
 	 */
426
-	function delete($info_id,$delete_children=True,$new_parent=0)  // did _not_ ensure ACL
425
+	function delete($info_id, $delete_children = True, $new_parent = 0)  // did _not_ ensure ACL
427 426
 	{
428 427
 		//echo "<p>soinfolog::delete($info_id,'$delete_children',$new_parent)</p>\n";
429
-		if ((int) $info_id <= 0)
428
+		if ((int)$info_id <= 0)
430 429
 		{
431 430
 			return;
432 431
 		}
433
-		$this->db->delete($this->info_table,array('info_id'=>$info_id),__LINE__,__FILE__);
434
-		$this->db->delete($this->extra_table,array('info_id'=>$info_id),__LINE__,__FILE__);
435
-		Link::unlink(0,'infolog',$info_id);
432
+		$this->db->delete($this->info_table, array('info_id'=>$info_id), __LINE__, __FILE__);
433
+		$this->db->delete($this->extra_table, array('info_id'=>$info_id), __LINE__, __FILE__);
434
+		Link::unlink(0, 'infolog', $info_id);
436 435
 
437 436
 		if ($this->data['info_id'] == $info_id)
438 437
 		{
@@ -441,17 +440,17 @@  discard block
 block discarded – undo
441 440
 		// delete children, if they are owned by the user
442 441
 		if ($delete_children)
443 442
 		{
444
-			$db2 = clone($this->db);	// we need an extra result-set
445
-			foreach($db2->select($this->info_table,'info_id',array(
443
+			$db2 = clone($this->db); // we need an extra result-set
444
+			foreach ($db2->select($this->info_table, 'info_id', array(
446 445
 					'info_id_parent'	=> $info_id,
447 446
 					'info_owner'		=> $this->user,
448
-				),__LINE__,__FILE__) as $row)
447
+				), __LINE__, __FILE__) as $row)
449 448
 			{
450 449
 				$this->delete($row['info_id'], $delete_children);
451 450
 			}
452 451
 		}
453 452
 		// set parent_id to $new_parent or 0 for all not deleted children
454
-		$this->db->update($this->info_table,array('info_id_parent'=>$new_parent),array('info_id_parent'=>$info_id),__LINE__,__FILE__);
453
+		$this->db->update($this->info_table, array('info_id_parent'=>$new_parent), array('info_id_parent'=>$info_id), __LINE__, __FILE__);
455 454
 	}
456 455
 
457 456
 	/**
@@ -463,9 +462,9 @@  discard block
 block discarded – undo
463 462
 	function get_children($info_id)
464 463
 	{
465 464
 		$children = array();
466
-		foreach($this->db->select($this->info_table, 'info_id,info_owner', array(
465
+		foreach ($this->db->select($this->info_table, 'info_id,info_owner', array(
467 466
 			'info_id_parent'	=> $info_id,
468
-		),__LINE__,__FILE__) as $row)
467
+		), __LINE__, __FILE__) as $row)
469 468
 		{
470 469
 			$children[$row['info_id']] = $row['info_owner'];
471 470
 		}
@@ -481,27 +480,27 @@  discard block
 block discarded – undo
481 480
 	 */
482 481
 	function change_delete_owner(array $args)  // new_owner=0 means delete
483 482
 	{
484
-		if (!(int) $args['new_owner'])
483
+		if (!(int)$args['new_owner'])
485 484
 		{
486
-			foreach($this->db->select($this->info_table,'info_id',array('info_owner'=>$args['account_id']),__LINE__,__FILE__,false,'','infolog') as $row)
485
+			foreach ($this->db->select($this->info_table, 'info_id', array('info_owner'=>$args['account_id']), __LINE__, __FILE__, false, '', 'infolog') as $row)
487 486
 			{
488
-				$this->delete($row['info_id'],False);
487
+				$this->delete($row['info_id'], False);
489 488
 			}
490 489
 		}
491 490
 		else
492 491
 		{
493
-			$this->db->update($this->info_table,array('info_owner'=>$args['new_owner']),array('info_owner'=>$args['account_id']),__LINE__,__FILE__,'infolog');
492
+			$this->db->update($this->info_table, array('info_owner'=>$args['new_owner']), array('info_owner'=>$args['account_id']), __LINE__, __FILE__, 'infolog');
494 493
 		}
495
-		foreach($this->db->select($this->info_table,'info_id,info_responsible',
496
-			$this->db->concat("','",'info_responsible',"','").' LIKE '.$this->db->quote('%,'.(int)$args['account_id'].',%'),
497
-			__LINE__,__FILE__,false,'','infolog') as $row)
494
+		foreach ($this->db->select($this->info_table, 'info_id,info_responsible',
495
+			$this->db->concat("','", 'info_responsible', "','").' LIKE '.$this->db->quote('%,'.(int)$args['account_id'].',%'),
496
+			__LINE__, __FILE__, false, '', 'infolog') as $row)
498 497
 		{
499
-			$new_responsible = explode(',',$row['info_responsible']);
500
-			unset($new_responsible[array_search($args['account_id'],$new_responsible)]);
498
+			$new_responsible = explode(',', $row['info_responsible']);
499
+			unset($new_responsible[array_search($args['account_id'], $new_responsible)]);
501 500
 			if ((int)$args['new_owner']) $new_responsible[] = (int)$args['new_owner'];
502
-			$this->db->update($this->info_table,array(
503
-				'info_responsible' => implode(',',$new_responsible),
504
-			),array('info_id' => $row['info_id']),__LINE__,__FILE__,'infolog');
501
+			$this->db->update($this->info_table, array(
502
+				'info_responsible' => implode(',', $new_responsible),
503
+			), array('info_id' => $row['info_id']), __LINE__, __FILE__, 'infolog');
505 504
 		}
506 505
 	}
507 506
 
@@ -514,7 +513,7 @@  discard block
 block discarded – undo
514 513
 	 * @param boolean $force_insert =false force using insert, even if an id is given eg. for import
515 514
 	 * @return int|boolean info_id, false on error or 0 if the entry has been updated in the meantime
516 515
 	 */
517
-	function write($values, $check_modified=0, $purge_cfs=null, $force_insert=false)  // did _not_ ensure ACL
516
+	function write($values, $check_modified = 0, $purge_cfs = null, $force_insert = false)  // did _not_ ensure ACL
518 517
 	{
519 518
 		if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
520 519
 		{
@@ -526,19 +525,19 @@  discard block
 block discarded – undo
526 525
 		}
527 526
 
528 527
 		//echo "soinfolog::write(,$check_modified) values="; _debug_array($values);
529
-		$info_id = (int) $values['info_id'];
528
+		$info_id = (int)$values['info_id'];
530 529
 
531
-		if (array_key_exists('info_responsible',$values))	// isset($values['info_responsible']) returns false for NULL!
530
+		if (array_key_exists('info_responsible', $values))	// isset($values['info_responsible']) returns false for NULL!
532 531
 		{
533
-			$values['info_responsible'] = $values['info_responsible'] ? implode(',',$values['info_responsible']) : '0';
532
+			$values['info_responsible'] = $values['info_responsible'] ? implode(',', $values['info_responsible']) : '0';
534 533
 		}
535
-		$table_def = $this->db->get_table_definitions('infolog',$this->info_table);
534
+		$table_def = $this->db->get_table_definitions('infolog', $this->info_table);
536 535
 		$to_write = array();
537
-		foreach($values as $key => $val)
536
+		foreach ($values as $key => $val)
538 537
 		{
539 538
 			if (($key != 'info_id' || $force_insert && $info_id > 0) && isset($table_def['fd'][$key]))
540 539
 			{
541
-				$to_write[$key] = $this->data[$key] = $val;   // update internal data
540
+				$to_write[$key] = $this->data[$key] = $val; // update internal data
542 541
 			}
543 542
 		}
544 543
 		// writing no price as SQL NULL (required by postgres)
@@ -548,23 +547,23 @@  discard block
 block discarded – undo
548 547
 		{
549 548
 			$where = array('info_id' => $info_id);
550 549
 			if ($check_modified) $where['info_datemodified'] = $check_modified;
551
-			if (!$this->db->update($this->info_table,$to_write,$where,__LINE__,__FILE__))
550
+			if (!$this->db->update($this->info_table, $to_write, $where, __LINE__, __FILE__))
552 551
 			{
553 552
 				//error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning false");
554
-				return false;	// Error
553
+				return false; // Error
555 554
 			}
556 555
 			if ($check_modified && $this->db->affected_rows() < 1)
557 556
 			{
558 557
 				//error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning 0 (nothing updated, eg. condition not met)");
559
-				return 0;	// someone else updated the modtime or deleted the entry
558
+				return 0; // someone else updated the modtime or deleted the entry
560 559
 			}
561 560
 		}
562 561
 		else
563 562
 		{
564
-			if (!isset($to_write['info_id_parent'])) $to_write['info_id_parent'] = 0;	// must not be null
563
+			if (!isset($to_write['info_id_parent'])) $to_write['info_id_parent'] = 0; // must not be null
565 564
 
566
-			$this->db->insert($this->info_table,$to_write,false,__LINE__,__FILE__);
567
-			$info_id = $this->data['info_id'] = $this->db->get_last_insert_id($this->info_table,'info_id');
565
+			$this->db->insert($this->info_table, $to_write, false, __LINE__, __FILE__);
566
+			$info_id = $this->data['info_id'] = $this->db->get_last_insert_id($this->info_table, 'info_id');
568 567
 		}
569 568
 
570 569
 		$update = array();
@@ -580,8 +579,8 @@  discard block
 block discarded – undo
580 579
 		}
581 580
 		if ($update)
582 581
 		{
583
-			$this->db->update($this->info_table,$update,
584
-				array('info_id' => $info_id), __LINE__,__FILE__);
582
+			$this->db->update($this->info_table, $update,
583
+				array('info_id' => $info_id), __LINE__, __FILE__);
585 584
 		}
586 585
 
587 586
 		//echo "<p>soinfolog.write values= "; _debug_array($values);
@@ -591,38 +590,38 @@  discard block
 block discarded – undo
591 590
 		{
592 591
 			$where = array('info_id' => $info_id);
593 592
 			if ($purge_cfs == 'ical') $where[] = "info_extra_name LIKE '#%'";
594
-			$this->db->delete($this->extra_table,$where,__LINE__,__FILE__);
593
+			$this->db->delete($this->extra_table, $where, __LINE__, __FILE__);
595 594
 		}
596 595
 		$to_delete = array();
597
-		foreach($values as $key => $val)
596
+		foreach ($values as $key => $val)
598 597
 		{
599 598
 			if ($key[0] != '#')
600 599
 			{
601
-				continue;	// no customfield
600
+				continue; // no customfield
602 601
 			}
603
-			$this->data[$key] = $val;	// update internal data
602
+			$this->data[$key] = $val; // update internal data
604 603
 
605 604
 			if ($val)
606 605
 			{
607
-				$this->db->insert($this->extra_table,array(
606
+				$this->db->insert($this->extra_table, array(
608 607
 						// store multivalued CalDAV properties as serialized array, everything else get comma-separated
609
-						'info_extra_value'	=> is_array($val) ? ($key[1] == '#' ? serialize($val) : implode(',',$val)) : $val,
610
-					),array(
608
+						'info_extra_value'	=> is_array($val) ? ($key[1] == '#' ? serialize($val) : implode(',', $val)) : $val,
609
+					), array(
611 610
 						'info_id'			=> $info_id,
612
-						'info_extra_name'	=> substr($key,1),
613
-					),__LINE__,__FILE__);
611
+						'info_extra_name'	=> substr($key, 1),
612
+					), __LINE__, __FILE__);
614 613
 			}
615 614
 			else
616 615
 			{
617
-				$to_delete[] = substr($key,1);
616
+				$to_delete[] = substr($key, 1);
618 617
 			}
619 618
 		}
620 619
 		if ($to_delete && !$purge_cfs)
621 620
 		{
622
-			$this->db->delete($this->extra_table,array(
621
+			$this->db->delete($this->extra_table, array(
623 622
 					'info_id'			=> $info_id,
624 623
 					'info_extra_name'	=> $to_delete,
625
-				),__LINE__,__FILE__);
624
+				), __LINE__, __FILE__);
626 625
 		}
627 626
 		// echo "<p>soinfolog.write this->data= "; _debug_array($this->data);
628 627
 		//error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning id=".$this->data['info_id']);
@@ -638,18 +637,18 @@  discard block
 block discarded – undo
638 637
 	 * @param int|array $info_id id(s) of log-entry
639 638
 	 * @return int|array the number of sub-entries or indexed by info_id, if array as param given
640 639
 	 */
641
-	function anzSubs( $info_id )
640
+	function anzSubs($info_id)
642 641
 	{
643 642
 		if (!is_array($info_id) || !$info_id)
644 643
 		{
645 644
 			if ((int)$info_id <= 0) return 0;
646 645
 		}
647 646
 		$counts = array();
648
-		foreach($this->db->select($this->info_table,'info_id_parent,COUNT(*) AS info_anz_subs',array(
647
+		foreach ($this->db->select($this->info_table, 'info_id_parent,COUNT(*) AS info_anz_subs', array(
649 648
 			'info_id_parent' => $info_id,
650
-			"info_status != 'deleted'",	// dont count deleted subs as subs, as they are not shown by default
651
-		),__LINE__,__FILE__,
652
-			false,'GROUP BY info_id_parent','infolog') as $row)
649
+			"info_status != 'deleted'", // dont count deleted subs as subs, as they are not shown by default
650
+		), __LINE__, __FILE__,
651
+			false, 'GROUP BY info_id_parent', 'infolog') as $row)
653 652
 		{
654 653
 			$counts[$row['info_id_parent']] = (int)$row['info_anz_subs'];
655 654
 		}
@@ -676,7 +675,7 @@  discard block
 block discarded – undo
676 675
 	 * @param boolean $no_acl =false true: ignore all acl
677 676
 	 * @return array|iterator with id's as key of the matching log-entries or recordset/iterator if cols is set
678 677
 	 */
679
-	function search(&$query, $no_acl=false)
678
+	function search(&$query, $no_acl = false)
680 679
 	{
681 680
 		//error_log(__METHOD__.'('.array2string($query).')');
682 681
 		$action2app = array(
@@ -690,102 +689,102 @@  discard block
 block discarded – undo
690 689
 			$action = isset($action2app[$query['action']]) ? $action2app[$query['action']] : $query['action'];
691 690
 			if ($action)
692 691
 			{
693
-				$links = Link\Storage::get_links($action=='sp'?'infolog':$action,
694
-					is_array($query['action_id']) ? $query['action_id'] : explode(',',$query['action_id']),'infolog','',$query['col_filter']['info_status'] =='deleted');
692
+				$links = Link\Storage::get_links($action == 'sp' ? 'infolog' : $action,
693
+					is_array($query['action_id']) ? $query['action_id'] : explode(',', $query['action_id']), 'infolog', '', $query['col_filter']['info_status'] == 'deleted');
695 694
 
696 695
 				if (count($links))
697 696
 				{
698
-					$links = call_user_func_array('array_merge',$links);	// flatten the array
699
-					$link_extra = ($action == 'sp' ? 'OR' : 'AND')." main.info_id IN (".implode(',',$links).')';
697
+					$links = call_user_func_array('array_merge', $links); // flatten the array
698
+					$link_extra = ($action == 'sp' ? 'OR' : 'AND')." main.info_id IN (".implode(',', $links).')';
700 699
 				}
701 700
 			}
702 701
 		}
703
-		$sortbycf='';
704
-		if (!empty($query['order']) && (preg_match('/^[a-z_0-9, ]+$/i',$query['order']) || stripos($query['order'],'#')!==FALSE ) &&
705
-			(empty($query['sort']) || preg_match('/^(DESC|ASC)$/i',$query['sort'])))
702
+		$sortbycf = '';
703
+		if (!empty($query['order']) && (preg_match('/^[a-z_0-9, ]+$/i', $query['order']) || stripos($query['order'], '#') !== FALSE) &&
704
+			(empty($query['sort']) || preg_match('/^(DESC|ASC)$/i', $query['sort'])))
706 705
 		{
707 706
 			$order = array();
708
-			foreach(explode(',',$query['order']) as $val)
707
+			foreach (explode(',', $query['order']) as $val)
709 708
 			{
710 709
 				$val = trim($val);
711 710
 				if ($val[0] == '#')
712 711
 				{
713
-					$sortbycf = substr($val,1);
712
+					$sortbycf = substr($val, 1);
714 713
 					$val = "cfsortcrit IS NULL,cfsortcrit";
715 714
 				}
716 715
 				else
717 716
 				{
718 717
 					static $table_def = null;
719
-					if (is_null($table_def)) $table_def = $this->db->get_table_definitions('infolog',$this->info_table);
720
-					if (substr($val,0,5) != 'info_' && isset($table_def['fd']['info_'.$val])) $val = 'info_'.$val;
718
+					if (is_null($table_def)) $table_def = $this->db->get_table_definitions('infolog', $this->info_table);
719
+					if (substr($val, 0, 5) != 'info_' && isset($table_def['fd']['info_'.$val])) $val = 'info_'.$val;
721 720
 					if ($val == 'info_des' && $this->db->capabilities['order_on_text'] !== true)
722 721
 					{
723 722
 						if (!$this->db->capabilities['order_on_text']) continue;
724 723
 
725
-						$val = sprintf($this->db->capabilities['order_on_text'],$val);
724
+						$val = sprintf($this->db->capabilities['order_on_text'], $val);
726 725
 					}
727 726
 				}
728 727
 				$order[] = $val;
729 728
 			}
730
-			$ordermethod = 'ORDER BY ' . implode(',',$order) . ' ' . $query['sort'];
729
+			$ordermethod = 'ORDER BY '.implode(',', $order).' '.$query['sort'];
731 730
 		}
732 731
 		else
733 732
 		{
734
-			$ordermethod = 'ORDER BY info_datemodified DESC';   // newest first
733
+			$ordermethod = 'ORDER BY info_datemodified DESC'; // newest first
735 734
 		}
736 735
 		$filtermethod = $no_acl ? '1=1' : $this->aclFilter($query['filter']);
737 736
 		if (!$query['col_filter']['info_status'])  $filtermethod .= $this->statusFilter($query['filter']);
738 737
 		$filtermethod .= $this->dateFilter($query['filter']);
739
-		$cfcolfilter=0;
738
+		$cfcolfilter = 0;
740 739
 		if (is_array($query['col_filter']))
741 740
 		{
742
-			foreach($query['col_filter'] as $col => $data)
741
+			foreach ($query['col_filter'] as $col => $data)
743 742
 			{
744 743
 				if (is_int($col))
745 744
 				{
746 745
 					$filtermethod .= ' AND '.$data;
747 746
 					continue;
748 747
 				}
749
-				if ($col[0] != '#' && substr($col,0,5) != 'info_' && isset($table_def['fd']['info_'.$col])) $col = 'info_'.$col;
750
-				if ((string)$data !== '' && preg_match('/^[a-z_0-9]+$/i',$col))
748
+				if ($col[0] != '#' && substr($col, 0, 5) != 'info_' && isset($table_def['fd']['info_'.$col])) $col = 'info_'.$col;
749
+				if ((string)$data !== '' && preg_match('/^[a-z_0-9]+$/i', $col))
751 750
 				{
752 751
 					switch ($col)
753 752
 					{
754 753
 						case 'info_responsible':
755
-							$data = (int) $data;
754
+							$data = (int)$data;
756 755
 							if (!$data) continue;
757 756
 							$filtermethod .= ' AND ('.$this->responsible_filter($data)." OR info_responsible='0' AND ".
758
-								$this->db->expression($this->info_table,array(
759
-									'info_owner' => $data > 0 ? $data : $GLOBALS['egw']->accounts->members($data,true)
757
+								$this->db->expression($this->info_table, array(
758
+									'info_owner' => $data > 0 ? $data : $GLOBALS['egw']->accounts->members($data, true)
760 759
 								)).')';
761 760
 							break;
762 761
 
763 762
 						case 'info_id':	// info_id itself is ambigous
764
-							$filtermethod .= ' AND '.$this->db->expression($this->info_table,'main.',array('info_id' => $data));
763
+							$filtermethod .= ' AND '.$this->db->expression($this->info_table, 'main.', array('info_id' => $data));
765 764
 							break;
766 765
 
767 766
 						default:
768
-							$filtermethod .= ' AND '.$this->db->expression($this->info_table,array($col => $data));
767
+							$filtermethod .= ' AND '.$this->db->expression($this->info_table, array($col => $data));
769 768
 							break;
770 769
 					}
771 770
 				}
772
-				if ($col[0] == '#' &&  $query['custom_fields'] && $data)
771
+				if ($col[0] == '#' && $query['custom_fields'] && $data)
773 772
 				{
774 773
 					$filtermethod .= " AND main.info_id IN (SELECT DISTINCT info_id FROM $this->extra_table WHERE ";
775 774
 					$custom_fields = Api\Storage\Customfields::get('infolog');
776 775
 
777
-					if($custom_fields[substr($col,1)]['type'] == 'select' && $custom_fields[substr($col,1)]['rows'] > 1)
776
+					if ($custom_fields[substr($col, 1)]['type'] == 'select' && $custom_fields[substr($col, 1)]['rows'] > 1)
778 777
 					{
779 778
 						// Multi-select - any entry with the filter value selected matches
780 779
 						$filtermethod .= $this->db->expression($this->extra_table, array(
781
-							'info_extra_name' => substr($col,1),
782
-							$this->db->concat("','",'info_extra_value',"','").' '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$data.',%'),
780
+							'info_extra_name' => substr($col, 1),
781
+							$this->db->concat("','", 'info_extra_value', "','").' '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$data.',%'),
783 782
 						)).')';
784 783
 					}
785 784
 					else
786 785
 					{
787
-						$filtermethod .= $this->db->expression($this->extra_table,array(
788
-							'info_extra_name'  => substr($col,1),
786
+						$filtermethod .= $this->db->expression($this->extra_table, array(
787
+							'info_extra_name'  => substr($col, 1),
789 788
 							'info_extra_value' => $data,
790 789
 						)).')';
791 790
 					}
@@ -797,15 +796,15 @@  discard block
 block discarded – undo
797 796
 
798 797
 		if ((int)$query['cat_id'])
799 798
 		{
800
-			$categories = new Api\Categories('','infolog');
799
+			$categories = new Api\Categories('', 'infolog');
801 800
 			$cats = $categories->return_all_children((int)$query['cat_id']);
802
-			$filtermethod .= ' AND info_cat'.(count($cats)>1? ' IN ('.implode(',',$cats).') ' : '='.(int)$query['cat_id']);
801
+			$filtermethod .= ' AND info_cat'.(count($cats) > 1 ? ' IN ('.implode(',', $cats).') ' : '='.(int)$query['cat_id']);
803 802
 		}
804 803
 		$join = $distinct = '';
805
-		if ($query['query']) $query['search'] = $query['query'];	// allow both names
804
+		if ($query['query']) $query['search'] = $query['query']; // allow both names
806 805
 		if ($query['search'])			  // we search in _from, _subject, _des and _extra_value for $query
807 806
 		{
808
-			$columns = array('info_from','info_addr','info_location','info_subject','info_extra_value');
807
+			$columns = array('info_from', 'info_addr', 'info_location', 'info_subject', 'info_extra_value');
809 808
 			// at the moment MaxDB 7.5 cant cast nor search text columns, it's suppost to change in 7.6
810 809
 			if ($this->db->capabilities['like_on_text']) $columns[] = 'info_des';
811 810
 
@@ -814,13 +813,13 @@  discard block
 block discarded – undo
814 813
 			$so_sql->table_name = 'main';
815 814
 			$search = $so_sql->search2criteria($query['search'], $wildcard, $op, null, $columns);
816 815
 			$sql_query = 'AND ('.(is_numeric($query['search']) ? 'main.info_id='.(int)$query['search'].' OR ' : '').
817
-				implode($op, $search) .')';
816
+				implode($op, $search).')';
818 817
 
819
-			$join = ($cfcolfilter>0 ? '':'LEFT')." JOIN $this->extra_table ON main.info_id=$this->extra_table.info_id ";
818
+			$join = ($cfcolfilter > 0 ? '' : 'LEFT')." JOIN $this->extra_table ON main.info_id=$this->extra_table.info_id ";
820 819
 			// mssql and others cant use DISTICT if text columns (info_des) are involved
821 820
 			$distinct = $this->db->capabilities['distinct_on_text'] ? 'DISTINCT' : '';
822 821
 		}
823
-		$pid = 'AND ' . $this->db->expression($this->info_table,array('info_id_parent' => ($action == 'sp' ?$query['action_id'] : 0)));
822
+		$pid = 'AND '.$this->db->expression($this->info_table, array('info_id_parent' => ($action == 'sp' ? $query['action_id'] : 0)));
824 823
 
825 824
 		if ($GLOBALS['egw_info']['user']['preferences']['infolog']['listNoSubs'] != '1' && $action != 'sp' ||
826 825
 			(string)$query['col_filter']['info_id_parent'] !== '' ||
@@ -841,14 +840,14 @@  discard block
 block discarded – undo
841 840
 			}
842 841
 			else
843 842
 			{
844
-				$query['total'] = $this->db->query($sql="SELECT $distinct main.info_id ".$sql_query,__LINE__,__FILE__)->NumRows();
843
+				$query['total'] = $this->db->query($sql = "SELECT $distinct main.info_id ".$sql_query, __LINE__, __FILE__)->NumRows();
845 844
 			}
846 845
 			$info_customfield = '';
847 846
 			if ($sortbycf != '')
848 847
 			{
849 848
 				$sort_col = "(SELECT DISTINCT info_extra_value FROM $this->extra_table sub2 WHERE sub2.info_id=main.info_id AND info_extra_name=".$this->db->quote($sortbycf).")";
850 849
 				if (!isset($custom_fields)) $custom_fields = Api\Storage\Customfields::get('infolog');
851
-				switch($custom_fields[$sortbycf]['type'])
850
+				switch ($custom_fields[$sortbycf]['type'])
852 851
 				{
853 852
 					case 'int':
854 853
 						$sort_col = $this->db->to_int($sort_col);
@@ -867,9 +866,9 @@  discard block
 block discarded – undo
867 866
 					$query['start'] = 0;
868 867
 				}
869 868
 				$cols = isset($query['cols']) ? $query['cols'] : 'main.*';
870
-				if (is_array($cols)) $cols = implode(',',$cols);
871
-				$rs = $this->db->query($sql='SELECT '.$mysql_calc_rows.' '.$distinct.' '.$cols.' '.$info_customfield.' '.$sql_query.$query['append'].' '.$ordermethod,__LINE__,__FILE__,
872
-					(int) $query['start'],isset($query['start']) ? (int) $query['num_rows'] : -1,false,Api\Db::FETCH_ASSOC);
869
+				if (is_array($cols)) $cols = implode(',', $cols);
870
+				$rs = $this->db->query($sql = 'SELECT '.$mysql_calc_rows.' '.$distinct.' '.$cols.' '.$info_customfield.' '.$sql_query.$query['append'].' '.$ordermethod, __LINE__, __FILE__,
871
+					(int)$query['start'], isset($query['start']) ? (int)$query['num_rows'] : -1, false, Api\Db::FETCH_ASSOC);
873 872
 				//echo "<p>db::query('$sql',,,".(int)$query['start'].','.(isset($query['start']) ? (int) $query['num_rows'] : -1).")</p>\n";
874 873
 
875 874
 				if ($mysql_calc_rows)
@@ -884,9 +883,9 @@  discard block
 block discarded – undo
884 883
 			{
885 884
 				return $rs;
886 885
 			}
887
-			foreach($rs as $info)
886
+			foreach ($rs as $info)
888 887
 			{
889
-				$info['info_responsible'] = $info['info_responsible'] ? explode(',',$info['info_responsible']) : array();
888
+				$info['info_responsible'] = $info['info_responsible'] ? explode(',', $info['info_responsible']) : array();
890 889
 
891 890
 				$ids[$info['info_id']] = $info;
892 891
 			}
@@ -899,19 +898,19 @@  discard block
 block discarded – undo
899 898
 			}
900 899
 			// if no specific custom field is selected, show/query all custom fields
901 900
 			if ($ids && ($query['custom_fields'] || $query['csv_export'] ||
902
-				$index_load_cfs && $query['col_filter']['info_type'] && in_array($query['col_filter']['info_type'],$index_load_cfs)))
901
+				$index_load_cfs && $query['col_filter']['info_type'] && in_array($query['col_filter']['info_type'], $index_load_cfs)))
903 902
 			{
904 903
 				$where = array('info_id' => array_keys($ids));
905
-				if (!($query['csv_export'] || strchr(is_array($query['selectcols']) ? implode(',',$query['selectcols']):$query['selectcols'],'#') === false ||
906
-					$index_load_cfs && $query['col_filter']['info_type'] && in_array($query['col_filter']['info_type'],$index_load_cfs)))
904
+				if (!($query['csv_export'] || strchr(is_array($query['selectcols']) ? implode(',', $query['selectcols']) : $query['selectcols'], '#') === false ||
905
+					$index_load_cfs && $query['col_filter']['info_type'] && in_array($query['col_filter']['info_type'], $index_load_cfs)))
907 906
 				{
908 907
 					$where['info_extra_name'] = array();
909
-					foreach(is_array($query['selectcols']) ? $query['selectcols'] : explode(',',$query['selectcols']) as $col)
908
+					foreach (is_array($query['selectcols']) ? $query['selectcols'] : explode(',', $query['selectcols']) as $col)
910 909
 					{
911
-						if ($col[0] == '#') $where['info_extra_name'][] = substr($col,1);
910
+						if ($col[0] == '#') $where['info_extra_name'][] = substr($col, 1);
912 911
 					}
913 912
 				}
914
-				foreach($this->db->select($this->extra_table,'*',$where,__LINE__,__FILE__) as $row)
913
+				foreach ($this->db->select($this->extra_table, '*', $where, __LINE__, __FILE__) as $row)
915 914
 				{
916 915
 					$ids[$row['info_id']]['#'.$row['info_extra_name']] = $row['info_extra_value'];
917 916
 				}
@@ -936,27 +935,27 @@  discard block
 block discarded – undo
936 935
 	{
937 936
 		$users = array();
938 937
 
939
-		foreach($this->db->select($this->info_table,'DISTINCT info_owner',array(
940
-			str_replace(' AND ','',$this->statusFilter('open')),
941
-			'(ABS(info_startdate-'.time().')<'.(4*24*60*60).' OR '.	// start_day within 4 days
942
-			'ABS(info_enddate-'.time().')<'.(4*24*60*60).')',		// end_day within 4 days
943
-		),__LINE__,__FILE__) as $row)
938
+		foreach ($this->db->select($this->info_table, 'DISTINCT info_owner', array(
939
+			str_replace(' AND ', '', $this->statusFilter('open')),
940
+			'(ABS(info_startdate-'.time().')<'.(4 * 24 * 60 * 60).' OR '.// start_day within 4 days
941
+			'ABS(info_enddate-'.time().')<'.(4 * 24 * 60 * 60).')', // end_day within 4 days
942
+		), __LINE__, __FILE__) as $row)
944 943
 		{
945 944
 			$users[] = $row['info_responsible'];
946 945
 		}
947
-		foreach($this->db->select($this->info_table,'DISTINCT info_responsible',$this->statusFilter('open',false),__LINE__,__FILE__) as $row)
946
+		foreach ($this->db->select($this->info_table, 'DISTINCT info_responsible', $this->statusFilter('open', false), __LINE__, __FILE__) as $row)
948 947
 		{
949
-			foreach(explode(',', $row['info_responsible']) as $responsible)
948
+			foreach (explode(',', $row['info_responsible']) as $responsible)
950 949
 			{
951 950
 				if ($GLOBALS['egw']->accounts->get_type($responsible) == 'g')
952 951
 				{
953
-					$responsible = $GLOBALS['egw']->accounts->members($responsible,true);
952
+					$responsible = $GLOBALS['egw']->accounts->members($responsible, true);
954 953
 				}
955 954
 				if ($responsible)
956 955
 				{
957
-					foreach(is_array($responsible) ? $responsible : array($responsible) as $user)
956
+					foreach (is_array($responsible) ? $responsible : array($responsible) as $user)
958 957
 					{
959
-						if ($user && !in_array($user,$users)) $users[] = $user;
958
+						if ($user && !in_array($user, $users)) $users[] = $user;
960 959
 					}
961 960
 				}
962 961
 			}
Please login to merge, or discard this patch.
calendar/inc/class.calendar_uiforms.inc.php 1 patch
Spacing   +461 added lines, -463 removed lines patch added patch discarded remove patch
@@ -55,18 +55,18 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @var locktime in seconds
57 57
 	 */
58
-	var $locktime_default=1;
58
+	var $locktime_default = 1;
59 59
 
60 60
 	/**
61 61
 	 * Constructor
62 62
 	 */
63 63
 	function __construct()
64 64
 	{
65
-		parent::__construct(true);	// call the parent's constructor
65
+		parent::__construct(true); // call the parent's constructor
66 66
 
67
-		for ($n=15; $n <= 16*60; $n+=($n < 60 ? 15 : ($n < 240 ? 30 : ($n < 600 ? 60 : 120))))
67
+		for ($n = 15; $n <= 16 * 60; $n += ($n < 60 ? 15 : ($n < 240 ? 30 : ($n < 600 ? 60 : 120))))
68 68
 		{
69
-			$this->durations[$n*60] = sprintf('%d:%02d',$n/60,$n%60);
69
+			$this->durations[$n * 60] = sprintf('%d:%02d', $n / 60, $n % 60);
70 70
 		}
71 71
 	}
72 72
 
@@ -78,11 +78,10 @@  discard block
 block discarded – undo
78 78
 	function &default_add_event()
79 79
 	{
80 80
 		$extra_participants = $_GET['participants'] ?
81
-			(!is_array($_GET['participants']) ? explode(',',$_GET['participants']) : $_GET['participants']) :
82
-			array();
81
+			(!is_array($_GET['participants']) ? explode(',', $_GET['participants']) : $_GET['participants']) : array();
83 82
 
84 83
 		// if participant is a contact, add its link title as title
85
-		foreach($extra_participants as $uid)
84
+		foreach ($extra_participants as $uid)
86 85
 		{
87 86
 			if ($uid[0] == 'c')
88 87
 			{
@@ -94,14 +93,14 @@  discard block
 block discarded – undo
94 93
 		if (isset($_GET['owner']))
95 94
 		{
96 95
 			$owner = $_GET['owner'];
97
-			if(!is_array($owner) && strpos($owner, ','))
96
+			if (!is_array($owner) && strpos($owner, ','))
98 97
 			{
99
-				$owner = explode(',',$owner);
98
+				$owner = explode(',', $owner);
100 99
 			}
101
-			if(is_array($owner))
100
+			if (is_array($owner))
102 101
 			{
103 102
 				// old behavior "selected" should also be used for not set preference, therefore we need to test for !== '0'
104
-				if($this->cal_prefs['default_participant'] !== '0' || count($extra_participants) === 0 && count($owner) === 1)
103
+				if ($this->cal_prefs['default_participant'] !== '0' || count($extra_participants) === 0 && count($owner) === 1)
105 104
 				{
106 105
 					$extra_participants += $owner;
107 106
 				}
@@ -117,21 +116,21 @@  discard block
 block discarded – undo
117 116
 			// old behavior "selected" should also be used for not set preference, therefore we need to test for === '0'
118 117
 			$owner = $this->cal_prefs['default_participant'] === '0' ? $this->user : $this->owner;
119 118
 		}
120
-		error_log(__METHOD__ . ' owner: ' . array2string($owner));
119
+		error_log(__METHOD__.' owner: '.array2string($owner));
121 120
 
122 121
 		if (!$owner || !is_numeric($owner) || $GLOBALS['egw']->accounts->get_type($owner) != 'u' ||
123
-			!$this->bo->check_perms(Acl::ADD,0,$owner))
122
+			!$this->bo->check_perms(Acl::ADD, 0, $owner))
124 123
 		{
125 124
 			if ($owner)	// make an owner who is no user or we have no add-rights a participant
126 125
 			{
127
-				if(!is_array($owner))
126
+				if (!is_array($owner))
128 127
 				{
129
-					$owner = explode(',',$owner);
128
+					$owner = explode(',', $owner);
130 129
 				}
131 130
 				// if we come from ressources we don't need any users selected in calendar
132 131
 				if (!isset($_GET['participants']) || $_GET['participants'][0] != 'r')
133 132
 				{
134
-					foreach($owner as $uid)
133
+					foreach ($owner as $uid)
135 134
 					{
136 135
 						$extra_participants[] = $uid;
137 136
 					}
@@ -141,71 +140,71 @@  discard block
 block discarded – undo
141 140
 		}
142 141
 		//error_log("this->owner=$this->owner, _GET[owner]=$_GET[owner], user=$this->user => owner=$owner, extra_participants=".implode(',',$extra_participants).")");
143 142
 
144
-		if(isset($_GET['start']))
143
+		if (isset($_GET['start']))
145 144
 		{
146 145
 			$start = Api\DateTime::to($_GET['start'], 'ts');
147 146
 		}
148 147
 		else
149 148
 		{
150 149
 			$start = $this->bo->date2ts(array(
151
-				'full' => isset($_GET['date']) && (int) $_GET['date'] ? (int) $_GET['date'] : $this->date,
152
-				'hour' => (int) (isset($_GET['hour']) ? $_GET['hour'] : $this->bo->cal_prefs['workdaystarts']),
153
-				'minute' => (int) $_GET['minute'],
150
+				'full' => isset($_GET['date']) && (int)$_GET['date'] ? (int)$_GET['date'] : $this->date,
151
+				'hour' => (int)(isset($_GET['hour']) ? $_GET['hour'] : $this->bo->cal_prefs['workdaystarts']),
152
+				'minute' => (int)$_GET['minute'],
154 153
 			));
155 154
 		}
156 155
 		//echo "<p>_GET[date]=$_GET[date], _GET[hour]=$_GET[hour], _GET[minute]=$_GET[minute], this->date=$this->date ==> start=$start=".date('Y-m-d H:i',$start)."</p>\n";
157 156
 
158 157
 		$participant_types['u'] = $participant_types = $participants = array();
159
-		foreach($extra_participants as $uid)
158
+		foreach ($extra_participants as $uid)
160 159
 		{
161
-			if (isset($participants[$uid])) continue;	// already included
160
+			if (isset($participants[$uid])) continue; // already included
162 161
 
163
-			if (!$this->bo->check_acl_invite($uid)) continue;	// no right to invite --> ignored
162
+			if (!$this->bo->check_acl_invite($uid)) continue; // no right to invite --> ignored
164 163
 
165 164
 			if (is_numeric($uid))
166 165
 			{
167 166
 				$participants[$uid] = $participant_types['u'][$uid] =
168
-					calendar_so::combine_status($uid == $this->user ? 'A' : 'U',1,
169
-					($uid == $this->user || ($uid == $owner && $this->bo->check_perms(Acl::ADD,0,$owner))) ? 'CHAIR' : 'REQ-PARTICIPANT');
167
+					calendar_so::combine_status($uid == $this->user ? 'A' : 'U', 1,
168
+					($uid == $this->user || ($uid == $owner && $this->bo->check_perms(Acl::ADD, 0, $owner))) ? 'CHAIR' : 'REQ-PARTICIPANT');
170 169
 			}
171 170
 			elseif (is_array($this->bo->resources[$uid[0]]))
172 171
 			{
173 172
 				// Expand mailing lists
174
-				if($uid[0] == 'l')
173
+				if ($uid[0] == 'l')
175 174
 				{
176
-					foreach($this->bo->enum_mailing_list($uid) as $contact)
175
+					foreach ($this->bo->enum_mailing_list($uid) as $contact)
177 176
 					{
178
-						$participants[$contact] = $participant_types['c'][substr($contact,1)] =
179
-							calendar_so::combine_status('U',1,'REQ-PARTICIPANT');
177
+						$participants[$contact] = $participant_types['c'][substr($contact, 1)] =
178
+							calendar_so::combine_status('U', 1, 'REQ-PARTICIPANT');
180 179
 					}
181 180
 					continue;
182 181
 				}
183 182
 				// if contact is a user, use the user instead (as the GUI)
184
-				if ($uid[0] == 'c' && ($account_id = $GLOBALS['egw']->accounts->name2id(substr($uid,1),'person_id')))
183
+				if ($uid[0] == 'c' && ($account_id = $GLOBALS['egw']->accounts->name2id(substr($uid, 1), 'person_id')))
185 184
 				{
186 185
 					$uid = $account_id;
187 186
 					$participants[$uid] = $participant_types['u'][$uid] =
188
-						calendar_so::combine_status($uid == $this->user ? 'A' : 'U',1,
189
-						($uid == $this->user || ($uid == $owner && $this->bo->check_perms(Acl::ADD,0,$owner))) ? 'CHAIR' : 'REQ-PARTICIPANT');
187
+						calendar_so::combine_status($uid == $this->user ? 'A' : 'U', 1,
188
+						($uid == $this->user || ($uid == $owner && $this->bo->check_perms(Acl::ADD, 0, $owner))) ? 'CHAIR' : 'REQ-PARTICIPANT');
190 189
 					continue;
191 190
 				}
192 191
 				$res_data = $this->bo->resources[$uid[0]];
193
-				list($id,$quantity) = explode(':',substr($uid,1));
194
-				if (($status = $res_data['new_status'] ? ExecMethod($res_data['new_status'],$id) : 'U'))
192
+				list($id, $quantity) = explode(':', substr($uid, 1));
193
+				if (($status = $res_data['new_status'] ? ExecMethod($res_data['new_status'], $id) : 'U'))
195 194
 				{
196 195
 					$participants[$uid] = $participant_types[$uid[0]][$id] =
197
-						calendar_so::combine_status($status,$quantity,'REQ-PARTICIPANT');
196
+						calendar_so::combine_status($status, $quantity, 'REQ-PARTICIPANT');
198 197
 				}
199 198
 			}
200 199
 		}
201 200
 		if (!$participants)	// if all participants got removed, include current user
202 201
 		{
203
-			$participants[$this->user] = $participant_types['u'][$this->user] = calendar_so::combine_status('A',1,'CHAIR');
202
+			$participants[$this->user] = $participant_types['u'][$this->user] = calendar_so::combine_status('A', 1, 'CHAIR');
204 203
 		}
205
-		if(isset($_GET['cat_id']))
204
+		if (isset($_GET['cat_id']))
206 205
 		{
207
-			$cat_id = explode(',',$_GET['cat_id']);
208
-			foreach($cat_id as &$cat)
206
+			$cat_id = explode(',', $_GET['cat_id']);
207
+			foreach ($cat_id as &$cat)
209 208
 			{
210 209
 				$cat = (int)$cat;
211 210
 			}
@@ -216,16 +215,16 @@  discard block
 block discarded – undo
216 215
 		if ((string)$this->cal_prefs['default-alarm'] !== '')
217 216
 		{
218 217
 			$offset = 60 * $this->cal_prefs['default-alarm'];
219
-			$alarms[1] =  array(
218
+			$alarms[1] = array(
220 219
 				'default' => 1,
221
-				'offset' => $offset ,
220
+				'offset' => $offset,
222 221
 				'time'   => $start - $offset,
223 222
 				'all'    => false,
224 223
 				'owner'  => $owner,
225 224
 				'id'	=> 1,
226 225
 			);
227 226
 		}
228
-		$duration = isset($_GET['duration']) ? (int)$_GET['duration'] : (int) $this->bo->cal_prefs['defaultlength']*60;
227
+		$duration = isset($_GET['duration']) ? (int)$_GET['duration'] : (int)$this->bo->cal_prefs['defaultlength'] * 60;
229 228
 		$end = isset($_GET['end']) ? Api\DateTime::to($_GET['end'], 'ts') : $start + $duration;
230 229
 		return array(
231 230
 			'participant_types' => $participant_types,
@@ -234,7 +233,7 @@  discard block
 block discarded – undo
234 233
 			'start' => $start,
235 234
 			'end'   => $end,
236 235
 			'tzid'  => $this->bo->common_prefs['tz'],
237
-			'priority' => 2,	// normal
236
+			'priority' => 2, // normal
238 237
 			'public'=> $this->cal_prefs['default_private'] ? 0 : 1,
239 238
 			'alarm' => $alarms,
240 239
 			'recur_exception' => array(),
@@ -253,7 +252,7 @@  discard block
 block discarded – undo
253 252
 	{
254 253
 		if (!is_array($content))	// redirect from etemplate, if POST empty
255 254
 		{
256
-			return $this->edit(null,null,strip_tags($_GET['msg']));
255
+			return $this->edit(null, null, strip_tags($_GET['msg']));
257 256
 		}
258 257
 		// clear notification errors
259 258
 		notifications::errors(true);
@@ -267,22 +266,22 @@  discard block
 block discarded – undo
267 266
 		$update_type = $content['id'] ? ($content['recur_type'] == MCAL_RECUR_NONE ? 'update' : 'edit') : 'add';
268 267
 
269 268
 		list($button) = @each($content['button']);
270
-		if (!$button && $content['action']) $button = $content['action'];	// action selectbox
269
+		if (!$button && $content['action']) $button = $content['action']; // action selectbox
271 270
 		unset($content['button']); unset($content['action']);
272 271
 
273 272
 		$view = $content['view'];
274 273
 		if ($button == 'ical')
275 274
 		{
276
-			$msg = $this->export($content['id'],true);
275
+			$msg = $this->export($content['id'], true);
277 276
 		}
278 277
 		// delete a recur-exception
279 278
 		if ($content['recur_exception']['delete_exception'])
280 279
 		{
281 280
 			list($date) = each($content['recur_exception']['delete_exception']);
282 281
 			// eT2 converts time to
283
-			if (!is_numeric($date)) $date = Api\DateTime::to (str_replace('Z','', $date), 'ts');
282
+			if (!is_numeric($date)) $date = Api\DateTime::to(str_replace('Z', '', $date), 'ts');
284 283
 			unset($content['recur_exception']['delete_exception']);
285
-			if (($key = array_search($date,$content['recur_exception'])) !== false)
284
+			if (($key = array_search($date, $content['recur_exception'])) !== false)
286 285
 			{
287 286
 				// propagate the exception to a single event
288 287
 				$recur_exceptions = $this->bo->so->get_related($content['uid']);
@@ -292,7 +291,7 @@  discard block
 block discarded – undo
292 291
 							$exception['recurrence'] != $content['recur_exception'][$key]) continue;
293 292
 					$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
294 293
 					$exception['reference'] = $exception['recurrence'] = 0;
295
-					$this->bo->update($exception, true, true,false,true,$messages,$content['no_notifications']);
294
+					$this->bo->update($exception, true, true, false, true, $messages, $content['no_notifications']);
296 295
 					break;
297 296
 				}
298 297
 				unset($content['recur_exception'][$key]);
@@ -333,7 +332,7 @@  discard block
 block discarded – undo
333 332
 			$def_alarm = $this->cal_prefs['default-alarm'.($content['whole_day'] ? '-wholeday' : '')];
334 333
 			if ((string)$def_alarm === '')
335 334
 			{
336
-				unset($content['alarm'][1]);	// '' = no alarm on whole day --> delete it
335
+				unset($content['alarm'][1]); // '' = no alarm on whole day --> delete it
337 336
 			}
338 337
 			else
339 338
 			{
@@ -347,7 +346,7 @@  discard block
 block discarded – undo
347 346
 		unset($event['alarm']['delete_alarm']);
348 347
 		unset($event['duration']);
349 348
 
350
-		if (in_array($button,array('ignore','freetime','reedit','confirm_edit_series')))
349
+		if (in_array($button, array('ignore', 'freetime', 'reedit', 'confirm_edit_series')))
351 350
 		{
352 351
 			// no conversation necessary, event is already in the right format
353 352
 		}
@@ -367,7 +366,7 @@  discard block
 block discarded – undo
367 366
 			if ($event['recur_type'] == MCAL_RECUR_NONE && $event['recur_data']) $event['recur_type'] = MCAL_RECUR_WEEKLY;
368 367
 			if ($event['recur_type'] == MCAL_RECUR_WEEKLY && !$event['recur_data'])
369 368
 			{
370
-				$event['recur_data'] = 1 << (int)date('w',$event['start']);
369
+				$event['recur_data'] = 1 << (int)date('w', $event['start']);
371 370
 			}
372 371
 			if ($event['recur_type'] != MCAL_RECUR_NONE && !isset($event['recur_enddate']))
373 372
 			{
@@ -379,9 +378,9 @@  discard block
 block discarded – undo
379 378
 
380 379
 				$event['participants'] = $event['participant_types'] = array();
381 380
 
382
-				foreach($content['participants'] as $key => $data)
381
+				foreach ($content['participants'] as $key => $data)
383 382
 				{
384
-					switch($key)
383
+					switch ($key)
385 384
 					{
386 385
 						case 'delete':		// handled in default
387 386
 						case 'quantity':	// handled in new_resource
@@ -390,7 +389,7 @@  discard block
 block discarded – undo
390 389
 						case 'status_date':
391 390
 							break;
392 391
 						case 'participant':
393
-							foreach($data as $participant)
392
+							foreach ($data as $participant)
394 393
 							{
395 394
 								if (is_null($participant))
396 395
 								{
@@ -399,17 +398,17 @@  discard block
 block discarded – undo
399 398
 
400 399
 								// email or rfc822 addresse (eg. "Ralf Becker <[email protected]>")
401 400
 								$email = array();
402
-								if(preg_match('/^(.*<)?([a-z0-9_.-]+@[a-z0-9_.-]{5,})>?$/i',$participant,$email))
401
+								if (preg_match('/^(.*<)?([a-z0-9_.-]+@[a-z0-9_.-]{5,})>?$/i', $participant, $email))
403 402
 								{
404
-									$status = calendar_so::combine_status('U',$content['participants']['quantity'],$content['participants']['role']);
405
-									if (($data = $GLOBALS['egw']->accounts->name2id($email[2],'account_email')) && $this->bo->check_acl_invite($data))
403
+									$status = calendar_so::combine_status('U', $content['participants']['quantity'], $content['participants']['role']);
404
+									if (($data = $GLOBALS['egw']->accounts->name2id($email[2], 'account_email')) && $this->bo->check_acl_invite($data))
406 405
 									{
407 406
 										$event['participants'][$data] = $event['participant_types']['u'][$data] = $status;
408 407
 									}
409
-									elseif ((list($data) = ExecMethod2('addressbook.addressbook_bo.search',array(
408
+									elseif ((list($data) = ExecMethod2('addressbook.addressbook_bo.search', array(
410 409
 										'email' => $email[2],
411 410
 										'email_home' => $email[2],
412
-									),true,'','','',false,'OR')))
411
+									), true, '', '', '', false, 'OR')))
413 412
 									{
414 413
 										$event['participants']['c'.$data['id']] = $event['participant_types']['c'][$data['id']] = $status;
415 414
 									}
@@ -420,7 +419,7 @@  discard block
 block discarded – undo
420 419
 								}
421 420
 								else
422 421
 								{
423
-									if(is_numeric($participant))
422
+									if (is_numeric($participant))
424 423
 									{
425 424
 										$uid = $participant;
426 425
 										$id = $participant;
@@ -429,12 +428,12 @@  discard block
 block discarded – undo
429 428
 									else
430 429
 									{
431 430
 										$uid = $participant;
432
-										$id = substr($participant,1);
431
+										$id = substr($participant, 1);
433 432
 										$resource = $this->bo->resources[$participant[0]];
434 433
 									}
435
-									if(!$this->bo->check_acl_invite($uid))
434
+									if (!$this->bo->check_acl_invite($uid))
436 435
 									{
437
-										if(!$msg_permission_denied_added)
436
+										if (!$msg_permission_denied_added)
438 437
 										{
439 438
 											$msg .= lang('Permission denied!');
440 439
 											$msg_permission_denied_added = true;
@@ -444,19 +443,18 @@  discard block
 block discarded – undo
444 443
 
445 444
 									$type = $resource['type'];
446 445
 									$status = isset($this->bo->resources[$type]['new_status']) ?
447
-										ExecMethod($this->bo->resources[$type]['new_status'],$id) :
448
-										($uid == $this->bo->user ? 'A' : 'U');
446
+										ExecMethod($this->bo->resources[$type]['new_status'], $id) : ($uid == $this->bo->user ? 'A' : 'U');
449 447
 
450 448
 									// Expand mailing lists
451
-									if($type == 'l')
449
+									if ($type == 'l')
452 450
 									{
453
-										foreach($this->bo->enum_mailing_list($participant) as $contact)
451
+										foreach ($this->bo->enum_mailing_list($participant) as $contact)
454 452
 										{
455 453
 											// Mailing lists can contain users, so allow for that possibility
456 454
 											$_type = is_numeric($contact) ? '' : $contact[0];
457
-											$_uid = is_numeric($contact) ? $contact : substr($contact,1);
455
+											$_uid = is_numeric($contact) ? $contact : substr($contact, 1);
458 456
 											$event['participants'][$contact] = $event['participant_types'][$_type][$_uid] =
459
-												calendar_so::combine_status($status,$content['participants']['quantity'],$content['participants']['role']);
457
+												calendar_so::combine_status($status, $content['participants']['quantity'], $content['participants']['role']);
460 458
 										}
461 459
 										continue;
462 460
 									}
@@ -466,8 +464,8 @@  discard block
 block discarded – undo
466 464
 										// todo check real availability = maximum - already booked quantity
467 465
 										if (isset($res_info['useable']) && $content['participants']['quantity'] > $res_info['useable'])
468 466
 										{
469
-											$msg .= lang('Maximum available quantity of %1 exceeded!',$res_info['useable']);
470
-											foreach(array('quantity','resource','role') as $n)
467
+											$msg .= lang('Maximum available quantity of %1 exceeded!', $res_info['useable']);
468
+											foreach (array('quantity', 'resource', 'role') as $n)
471 469
 											{
472 470
 												$event['participants'][$n] = $content['participants'][$n];
473 471
 											}
@@ -476,7 +474,7 @@  discard block
 block discarded – undo
476 474
 										else
477 475
 										{
478 476
 											$event['participants'][$uid] = $event['participant_types'][$type][$id] =
479
-												calendar_so::combine_status($status,$content['participants']['quantity'],$content['participants']['role']);
477
+												calendar_so::combine_status($status, $content['participants']['quantity'], $content['participants']['role']);
480 478
 										}
481 479
 									}
482 480
 								}
@@ -490,14 +488,14 @@  discard block
 block discarded – undo
490 488
 							break;
491 489
 
492 490
 						default:		// existing participant row
493
-							if (!is_array($data)) continue;	// widgets in participant tab, above participant list
494
-							foreach(array('uid','status','quantity','role') as $name)
491
+							if (!is_array($data)) continue; // widgets in participant tab, above participant list
492
+							foreach (array('uid', 'status', 'quantity', 'role') as $name)
495 493
 							{
496 494
 								$$name = $data[$name];
497 495
 							}
498 496
 							if ($content['participants']['delete'][$uid] || $content['participants']['delete'][md5($uid)])
499 497
 							{
500
-								$uid = false;	// entry has been deleted
498
+								$uid = false; // entry has been deleted
501 499
 							}
502 500
 							elseif ($uid)
503 501
 							{
@@ -508,27 +506,27 @@  discard block
 block discarded – undo
508 506
 								}
509 507
 								else
510 508
 								{
511
-									$id = substr($uid,1);
509
+									$id = substr($uid, 1);
512 510
 									$type = $uid[0];
513 511
 								}
514 512
 								if ($data['old_status'] != $status && !(!$data['old_status'] && $status == 'G'))
515 513
 								{
516 514
 									//echo "<p>$uid: status changed '$data[old_status]' --> '$status<'/p>\n";
517 515
 									$new_status = calendar_so::combine_status($status, $quantity, $role);
518
-									if ($this->bo->set_status($event['id'],$uid,$new_status,isset($content['edit_single']) ? $content['participants']['status_date'] : 0, false, true, $content['no_notifications']))
516
+									if ($this->bo->set_status($event['id'], $uid, $new_status, isset($content['edit_single']) ? $content['participants']['status_date'] : 0, false, true, $content['no_notifications']))
519 517
 									{
520 518
 										// Update main window
521 519
 										$d = new Api\DateTime($content['edit_single'], Api\DateTime::$user_timezone);
522 520
 										$client_updated = $this->update_client($event['id'], $d);
523 521
 
524 522
 										// refreshing the calendar-view with the changed participant-status
525
-										if($event['recur_type'] != MCAL_RECUR_NONE)
523
+										if ($event['recur_type'] != MCAL_RECUR_NONE)
526 524
 										{
527 525
 											$msg = lang('Status for all future scheduled days changed');
528 526
 										}
529 527
 										else
530 528
 										{
531
-											if(isset($content['edit_single']))
529
+											if (isset($content['edit_single']))
532 530
 											{
533 531
 												$msg = lang('Status for this particular day changed');
534 532
 												// prevent accidentally creating a real exception afterwards
@@ -549,7 +547,7 @@  discard block
 block discarded – undo
549 547
 										if ($status == 'R' && $event['alarm'])
550 548
 										{
551 549
 											// remove from bo->set_status deleted alarms of rejected users from UI too
552
-											foreach($event['alarm'] as $alarm_id => $alarm)
550
+											foreach ($event['alarm'] as $alarm_id => $alarm)
553 551
 											{
554 552
 												if ((string)$alarm['owner'] === (string)$uid)
555 553
 												{
@@ -562,7 +560,7 @@  discard block
 block discarded – undo
562 560
 								if ($uid && $status != 'G')
563 561
 								{
564 562
 									$event['participants'][$uid] = $event['participant_types'][$type][$id] =
565
-										calendar_so::combine_status($status,$quantity,$role);
563
+										calendar_so::combine_status($status, $quantity, $role);
566 564
 								}
567 565
 							}
568 566
 							break;
@@ -581,26 +579,26 @@  discard block
 block discarded – undo
581 579
 			'tabs'			=> $content['tabs'],
582 580
 			'template'      => $content['template'],
583 581
 		);
584
-		$noerror=true;
582
+		$noerror = true;
585 583
 
586 584
 		//error_log(__METHOD__.$button.'#'.array2string($content['edit_single']).'#');
587 585
 
588 586
 		$ignore_conflicts = $status_reset_to_unknown = false;
589 587
 
590
-		switch((string)$button)
588
+		switch ((string)$button)
591 589
 		{
592 590
 			case 'ignore':
593 591
 				$ignore_conflicts = true;
594
-				$button = $event['button_was'];	// save or apply
592
+				$button = $event['button_was']; // save or apply
595 593
 				unset($event['button_was']);
596 594
 				break;
597 595
 
598 596
 		}
599 597
 
600
-		switch((string)$button)
598
+		switch ((string)$button)
601 599
 		{
602 600
 		case 'exception':	// create an exception in a recuring event
603
-			$msg = $this->_create_exception($event,$preserv);
601
+			$msg = $this->_create_exception($event, $preserv);
604 602
 			break;
605 603
 
606 604
 		case 'copy':	// create new event with copied content, some content need to be unset to make a "new" event
@@ -611,29 +609,29 @@  discard block
 block discarded – undo
611 609
 			unset($event['recurrence']);
612 610
 			unset($preserv['recurrence']);
613 611
 			unset($event['recur_exception']);
614
-			unset($event['edit_single']);	// in case it has been set
612
+			unset($event['edit_single']); // in case it has been set
615 613
 			unset($event['modified']);
616 614
 			unset($event['modifier']);
617 615
 			unset($event['caldav_name']);
618
-			$event['owner'] = !(int)$event['owner'] || !$this->bo->check_perms(Acl::ADD,0,$event['owner']) ? $this->user : $event['owner'];
616
+			$event['owner'] = !(int)$event['owner'] || !$this->bo->check_perms(Acl::ADD, 0, $event['owner']) ? $this->user : $event['owner'];
619 617
 
620 618
 			// Clear participant stati
621
-			foreach($event['participant_types'] as $type => &$participants)
619
+			foreach ($event['participant_types'] as $type => &$participants)
622 620
 			{
623
-				foreach($participants as $id => &$p_response)
621
+				foreach ($participants as $id => &$p_response)
624 622
 				{
625
-					if($type == 'u' && $id == $event['owner']) continue;
623
+					if ($type == 'u' && $id == $event['owner']) continue;
626 624
 					calendar_so::split_status($p_response, $quantity, $role);
627 625
 					// if resource defines callback for status of new status (eg. Resources app acknowledges direct booking acl), call it
628
-					$status = isset($this->bo->resources[$type]['new_status']) ? ExecMethod($this->bo->resources[$type]['new_status'],$id) : 'U';
629
-					$p_response = calendar_so::combine_status($status,$quantity,$role);
626
+					$status = isset($this->bo->resources[$type]['new_status']) ? ExecMethod($this->bo->resources[$type]['new_status'], $id) : 'U';
627
+					$p_response = calendar_so::combine_status($status, $quantity, $role);
630 628
 				}
631 629
 			}
632 630
 
633 631
 			// Copy alarms
634 632
 			if (is_array($event['alarm']))
635 633
 			{
636
-				foreach($event['alarm'] as $n => &$alarm)
634
+				foreach ($event['alarm'] as $n => &$alarm)
637 635
 				{
638 636
 					unset($alarm['id']);
639 637
 					unset($alarm['cal_id']);
@@ -643,7 +641,7 @@  discard block
 block discarded – undo
643 641
 			// Get links to be copied
644 642
 			// With no ID, $content['link_to']['to_id'] is used
645 643
 			$content['link_to']['to_id'] = array('to_app' => 'calendar', 'to_id' => 0);
646
-			foreach(Link::get_links('calendar', $content['id']) as $link)
644
+			foreach (Link::get_links('calendar', $content['id']) as $link)
647 645
 			{
648 646
 				if ($link['app'] != Link::VFS_APPNAME)
649 647
 				{
@@ -659,7 +657,7 @@  discard block
 block discarded – undo
659 657
 			}
660 658
 			unset($link);
661 659
 			$preserv['view'] = $preserv['edit_single'] = false;
662
-			$msg = lang('%1 copied - the copy can now be edited', lang(Link::get_registry('calendar','entry')));
660
+			$msg = lang('%1 copied - the copy can now be edited', lang(Link::get_registry('calendar', 'entry')));
663 661
 			$event['title'] = lang('Copy of:').' '.$event['title'];
664 662
 			break;
665 663
 
@@ -669,7 +667,7 @@  discard block
 block discarded – undo
669 667
 		case 'print':
670 668
 		case 'apply':
671 669
 		case 'infolog':
672
-			if ($event['id'] && !$this->bo->check_perms(Acl::EDIT,$event))
670
+			if ($event['id'] && !$this->bo->check_perms(Acl::EDIT, $event))
673 671
 			{
674 672
 				$msg = lang('Permission denied');
675 673
 				$button = '';
@@ -687,7 +685,7 @@  discard block
 block discarded – undo
687 685
 				$button = '';
688 686
 				break;
689 687
 			}
690
-			if ($event['recur_type'] != MCAL_RECUR_NONE && $event['end']-$event['start'] > calendar_rrule::recurrence_interval($event['recur_type'], $event['recur_interval']))
688
+			if ($event['recur_type'] != MCAL_RECUR_NONE && $event['end'] - $event['start'] > calendar_rrule::recurrence_interval($event['recur_type'], $event['recur_interval']))
691 689
 			{
692 690
 				$msg = lang('Error: Duration of event longer then recurrence interval!');
693 691
 				$button = '';
@@ -717,14 +715,14 @@  discard block
 block discarded – undo
717 715
 				$event['reference'] = $event['id'];
718 716
 				$event['recurrence'] = $content['edit_single'];
719 717
 				unset($event['id']);
720
-				$conflicts = $this->bo->update($event,$ignore_conflicts,true,false,true,$messages,$content['no_notifications']);
718
+				$conflicts = $this->bo->update($event, $ignore_conflicts, true, false, true, $messages, $content['no_notifications']);
721 719
 				if (!is_array($conflicts) && $conflicts)
722 720
 				{
723 721
 					// now we need to add the original start as recur-execption to the series
724 722
 					$recur_event = $this->bo->read($event['reference']);
725 723
 					$recur_event['recur_exception'][] = $content['edit_single'];
726 724
 					// check if we need to move the alarms, because they are next on that exception
727
-					foreach($recur_event['alarm'] as $id => $alarm)
725
+					foreach ($recur_event['alarm'] as $id => $alarm)
728 726
 					{
729 727
 						if ($alarm['time'] == $content['edit_single'] - $alarm['offset'])
730 728
 						{
@@ -740,11 +738,11 @@  discard block
 block discarded – undo
740 738
 							}
741 739
 						}
742 740
 					}
743
-					unset($recur_event['start']); unset($recur_event['end']);	// no update necessary
744
-					unset($recur_event['alarm']);	// unsetting alarms too, as they cant be updated without start!
745
-					$this->bo->update($recur_event,true);	// no conflict check here
741
+					unset($recur_event['start']); unset($recur_event['end']); // no update necessary
742
+					unset($recur_event['alarm']); // unsetting alarms too, as they cant be updated without start!
743
+					$this->bo->update($recur_event, true); // no conflict check here
746 744
 
747
-					if(Api\Json\Response::isJSONResponse())
745
+					if (Api\Json\Response::isJSONResponse())
748 746
 					{
749 747
 						// Sending null will trigger a removal of the original
750 748
 						// for that date
@@ -752,7 +750,7 @@  discard block
 block discarded – undo
752 750
 					}
753 751
 
754 752
 					unset($recur_event);
755
-					unset($event['edit_single']);			// if we further edit it, it's just a single event
753
+					unset($event['edit_single']); // if we further edit it, it's just a single event
756 754
 					unset($preserv['edit_single']);
757 755
 				}
758 756
 				else	// conflict or error, we need to reset everything to the state befor we tried to save it
@@ -783,8 +781,8 @@  discard block
 block discarded – undo
783 781
 							{
784 782
 								$offset = $off2;
785 783
 							}
786
-							$msg = $this->_break_recurring($event, $old_event, $event['actual_date'] + $offset,$content['no_notifications']);
787
-							if($msg)
784
+							$msg = $this->_break_recurring($event, $old_event, $event['actual_date'] + $offset, $content['no_notifications']);
785
+							if ($msg)
788 786
 							{
789 787
 								$noerror = false;
790 788
 							}
@@ -797,10 +795,10 @@  discard block
 block discarded – undo
797 795
 							$event['whole_day'] != $old_event['whole_day'])
798 796
 						{
799 797
 							$sameday = (date('Ymd', $old_event['start']) == date('Ymd', $event['start']));
800
-							foreach((array)$event['participants'] as $uid => $status)
798
+							foreach ((array)$event['participants'] as $uid => $status)
801 799
 							{
802 800
 								$q = $r = null;
803
-								calendar_so::split_status($status,$q,$r);
801
+								calendar_so::split_status($status, $q, $r);
804 802
 								if ($uid[0] != 'c' && $uid[0] != 'e' && $uid != $this->bo->user && $status != 'U')
805 803
 								{
806 804
 									$preferences = new Api\Preferences($uid);
@@ -813,7 +811,7 @@  discard block
 block discarded – undo
813 811
 											if ($sameday) break;
814 812
 										default:
815 813
 											$status_reset_to_unknown = true;
816
-											$event['participants'][$uid] = calendar_so::combine_status('U',$q,$r);
814
+											$event['participants'][$uid] = calendar_so::combine_status('U', $q, $r);
817 815
 											// todo: report reset status to user
818 816
 									}
819 817
 								}
@@ -825,43 +823,43 @@  discard block
 block discarded – undo
825 823
 				}
826 824
 				// Adding participants needs to be done as an edit, in case we
827 825
 				// have participants visible in seperate calendars
828
-				if(is_array($old_event['participants']) && count(array_diff_key($event['participants'], $old_event['participants'])))
826
+				if (is_array($old_event['participants']) && count(array_diff_key($event['participants'], $old_event['participants'])))
829 827
 				{
830 828
 					$update_type = 'edit';
831 829
 				}
832 830
 				// Changing category may affect event filtering
833
-				if($this->cal_prefs['saved_states']['cat_id'] && $old_event['category'] != $event['category'])
831
+				if ($this->cal_prefs['saved_states']['cat_id'] && $old_event['category'] != $event['category'])
834 832
 				{
835 833
 					$update_type = 'edit';
836 834
 				}
837
-				$conflicts = $this->bo->update($event,$ignore_conflicts,true,false,true,$messages,$content['no_notifications']);
835
+				$conflicts = $this->bo->update($event, $ignore_conflicts, true, false, true, $messages, $content['no_notifications']);
838 836
 				unset($event['ignore']);
839 837
 			}
840 838
 			if (is_array($conflicts))
841 839
 			{
842
-				$event['button_was'] = $button;	// remember for ignore
843
-				return $this->conflicts($event,$conflicts,$preserv);
840
+				$event['button_was'] = $button; // remember for ignore
841
+				return $this->conflicts($event, $conflicts, $preserv);
844 842
 			}
845 843
 
846 844
 			// Event spans multiple days, need an edit to make sure they all get updated
847 845
 			// We could check old date, as removing from days could still be an update
848
-			if(date('Ymd', $event['start']) != date('Ymd', $event['end']))
846
+			if (date('Ymd', $event['start']) != date('Ymd', $event['end']))
849 847
 			{
850 848
 				$update_type = 'edit';
851 849
 			}
852 850
 			// check if there are messages from update, eg. removed participants or Api\Categories because of missing rights
853 851
 			if ($messages)
854 852
 			{
855
-				$msg  .= ($msg ? ', ' : '').implode(', ',$messages);
853
+				$msg .= ($msg ? ', ' : '').implode(', ', $messages);
856 854
 			}
857 855
 			if ($conflicts === 0)
858 856
 			{
859
-				$msg .= ($msg ? ', ' : '') .lang('Error: the entry has been updated since you opened it for editing!').'<br />'.
860
-							lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.','<a href="'.
861
-								htmlspecialchars(Egw::link('/index.php',array(
857
+				$msg .= ($msg ? ', ' : '').lang('Error: the entry has been updated since you opened it for editing!').'<br />'.
858
+							lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.', '<a href="'.
859
+								htmlspecialchars(Egw::link('/index.php', array(
862 860
 								'menuaction' => 'calendar.calendar_uiforms.edit',
863 861
 								'cal_id'    => $content['id'],
864
-							))).'">','</a>');
862
+							))).'">', '</a>');
865 863
 				$noerror = false;
866 864
 			}
867 865
 			elseif ($conflicts > 0)
@@ -883,19 +881,19 @@  discard block
 block discarded – undo
883 881
 						// if alarm would be in the past (eg. event moved back) --> move to next possible recurrence
884 882
 						if ($alarm['time'] < $this->bo->now_su)
885 883
 						{
886
-							if (($next_occurrence = $this->bo->read($event['id'], $this->bo->now_su+$alarm['offset'], true)))
884
+							if (($next_occurrence = $this->bo->read($event['id'], $this->bo->now_su + $alarm['offset'], true)))
887 885
 							{
888
-								$alarm['time'] =  $next_occurrence['start'] - $alarm['offset'];
886
+								$alarm['time'] = $next_occurrence['start'] - $alarm['offset'];
889 887
 							}
890 888
 							else
891 889
 							{
892
-								$alarm = false;	// no (further) recurence found --> ignore alarm
890
+								$alarm = false; // no (further) recurence found --> ignore alarm
893 891
 							}
894 892
 						}
895 893
 						// alarm is currently on a previous recurrence --> set for first recurrence of new series
896 894
 						elseif ($event_time < $event['start'])
897 895
 						{
898
-							$alarm['time'] =  $event['start'] - $alarm['offset'];
896
+							$alarm['time'] = $event['start'] - $alarm['offset'];
899 897
 						}
900 898
 						if ($alarm)
901 899
 						{
@@ -904,9 +902,9 @@  discard block
 block discarded – undo
904 902
 						}
905 903
 					}
906 904
 					// attach all future exceptions to the new series
907
-					$events =& $this->bo->search(array(
905
+					$events = & $this->bo->search(array(
908 906
 						'query' => array('cal_uid' => $old_event['uid']),
909
-						'filter' => 'owner',  // return all possible entries
907
+						'filter' => 'owner', // return all possible entries
910 908
 						'daywise' => false,
911 909
 						'date_format' => 'ts',
912 910
 					));
@@ -917,7 +915,7 @@  discard block
 block discarded – undo
917 915
 							$exception['recurrence'] += $offset;
918 916
 							$exception['reference'] = $event['id'];
919 917
 							$exception['uid'] = $event['uid'];
920
-							$this->bo->update($exception, true, true, true, true, $msg=null, $content['no_notifications']);
918
+							$this->bo->update($exception, true, true, true, true, $msg = null, $content['no_notifications']);
921 919
 						}
922 920
 					}
923 921
 				}
@@ -925,12 +923,12 @@  discard block
 block discarded – undo
925 923
 				$message = lang('Event saved');
926 924
 				if ($status_reset_to_unknown)
927 925
 				{
928
-					foreach((array)$event['participants'] as $uid => $status)
926
+					foreach ((array)$event['participants'] as $uid => $status)
929 927
 					{
930 928
 						if ($uid[0] != 'c' && $uid[0] != 'e' && $uid != $this->bo->user)
931 929
 						{
932
-							calendar_so::split_status($status,$q,$r);
933
-							$status = calendar_so::combine_status('U',$q,$r);
930
+							calendar_so::split_status($status, $q, $r);
931
+							$status = calendar_so::combine_status('U', $q, $r);
934 932
 							$this->bo->set_status($event['id'], $uid, $status, 0, true);
935 933
 						}
936 934
 					}
@@ -938,17 +936,17 @@  discard block
 block discarded – undo
938 936
 				}
939 937
 
940 938
 				$response = Api\Json\Response::get();
941
-				if($response && $update_type != 'delete')
939
+				if ($response && $update_type != 'delete')
942 940
 				{
943 941
 					$client_updated = $this->update_client($event['id']);
944 942
 				}
945 943
 
946
-				$msg = $message . ($msg ? ', ' . $msg : '');
944
+				$msg = $message.($msg ? ', '.$msg : '');
947 945
 				Framework::refresh_opener($msg, 'calendar', $event['id'], $client_updated ? ($event['recur_type'] ? 'edit' : $update_type) : 'delete');
948 946
 				// writing links for new entry, existing ones are handled by the widget itself
949 947
 				if (!$content['id'] && is_array($content['link_to']['to_id']))
950 948
 				{
951
-					Link::link('calendar',$event['id'],$content['link_to']['to_id']);
949
+					Link::link('calendar', $event['id'], $content['link_to']['to_id']);
952 950
 				}
953 951
 			}
954 952
 			else
@@ -958,7 +956,7 @@  discard block
 block discarded – undo
958 956
 			break;
959 957
 
960 958
 		case 'cancel':
961
-			if($content['cancel_needs_refresh'])
959
+			if ($content['cancel_needs_refresh'])
962 960
 			{
963 961
 				Framework::refresh_opener($msg, 'calendar');
964 962
 			}
@@ -996,7 +994,7 @@  discard block
 block discarded – undo
996 994
 			{
997 995
 				$content['new_alarm']['date'] = $next_occurrence['start'] - $offset;
998 996
 			}
999
-			if ($this->bo->check_perms(Acl::EDIT,!$content['new_alarm']['owner'] ? $event : 0,$content['new_alarm']['owner']))
997
+			if ($this->bo->check_perms(Acl::EDIT, !$content['new_alarm']['owner'] ? $event : 0, $content['new_alarm']['owner']))
1000 998
 			{
1001 999
 				$alarm = array(
1002 1000
 					'offset' => $offset,
@@ -1010,13 +1008,13 @@  discard block
 block discarded – undo
1010 1008
 				}
1011 1009
 				elseif ($event['id'])	// save the alarm immediatly
1012 1010
 				{
1013
-					if (($alarm_id = $this->bo->save_alarm($event['id'],$alarm)))
1011
+					if (($alarm_id = $this->bo->save_alarm($event['id'], $alarm)))
1014 1012
 					{
1015 1013
 						$alarm['id'] = $alarm_id;
1016 1014
 						$event['alarm'][$alarm_id] = $alarm;
1017 1015
 
1018 1016
 						$msg = lang('Alarm added');
1019
-						Framework::refresh_opener($msg,'calendar', $event['id'], 'update');
1017
+						Framework::refresh_opener($msg, 'calendar', $event['id'], 'update');
1020 1018
 					}
1021 1019
 					else
1022 1020
 					{
@@ -1025,7 +1023,7 @@  discard block
 block discarded – undo
1025 1023
 				}
1026 1024
 				else
1027 1025
 				{
1028
-					for($alarm['id']=1; isset($event['alarm'][$alarm['id']]); $alarm['id']++) {}	// get a temporary non-conflicting, numeric id
1026
+					for ($alarm['id'] = 1; isset($event['alarm'][$alarm['id']]); $alarm['id']++) {}	// get a temporary non-conflicting, numeric id
1029 1027
 					$event['alarm'][$alarm['id']] = $alarm;
1030 1028
 				}
1031 1029
 			}
@@ -1042,31 +1040,31 @@  discard block
 block discarded – undo
1042 1040
 		}
1043 1041
 		// New event, send data before updating so it's there
1044 1042
 		$response = Api\Json\Response::get();
1045
-		if($response && !$content['id'] && $event['id'])
1043
+		if ($response && !$content['id'] && $event['id'])
1046 1044
 		{
1047 1045
 			$client_updated = $this->update_client($event['id']);
1048 1046
 		}
1049
-		if (in_array($button,array('cancel','save','delete','delete_exceptions','delete_keep_exceptions')) && $noerror)
1047
+		if (in_array($button, array('cancel', 'save', 'delete', 'delete_exceptions', 'delete_keep_exceptions')) && $noerror)
1050 1048
 		{
1051 1049
 			if ($content['lock_token'])	// remove an existing lock
1052 1050
 			{
1053
-				Vfs::unlock(Vfs::app_entry_lock_path('calendar',$content['id']),$content['lock_token'],false);
1051
+				Vfs::unlock(Vfs::app_entry_lock_path('calendar', $content['id']), $content['lock_token'], false);
1054 1052
 			}
1055 1053
 			if ($content['no_popup'])
1056 1054
 			{
1057
-				Egw::redirect_link('/index.php',array(
1055
+				Egw::redirect_link('/index.php', array(
1058 1056
 					'menuaction' => 'calendar.calendar_uiviews.index',
1059 1057
 					'msg'        => $msg,
1060 1058
 				));
1061 1059
 			}
1062
-			if (in_array($button,array('delete_exceptions','delete_keep_exceptions')) || $content['recur_type'] && $button == 'delete')
1060
+			if (in_array($button, array('delete_exceptions', 'delete_keep_exceptions')) || $content['recur_type'] && $button == 'delete')
1063 1061
 			{
1064
-				Framework::refresh_opener($msg,'calendar');
1062
+				Framework::refresh_opener($msg, 'calendar');
1065 1063
 			}
1066 1064
 			else
1067 1065
 			{
1068 1066
 				Framework::refresh_opener($msg, 'calendar',
1069
-					$event['id'] . ($content['edit_single'] ? ':' . (int)$content['edit_single'] : '' ),
1067
+					$event['id'].($content['edit_single'] ? ':'.(int)$content['edit_single'] : ''),
1070 1068
 					$button == 'save' && $client_updated ? ($content['id'] ? $update_type : 'add') : 'delete'
1071 1069
 				);
1072 1070
 			}
@@ -1074,7 +1072,7 @@  discard block
 block discarded – undo
1074 1072
 			exit();
1075 1073
 		}
1076 1074
 		unset($event['no_notifications']);
1077
-		return $this->edit($event,$preserv,$msg,$event['id'] ? $event['id'] : $content['link_to']['to_id']);
1075
+		return $this->edit($event, $preserv, $msg, $event['id'] ? $event['id'] : $content['link_to']['to_id']);
1078 1076
 	}
1079 1077
 
1080 1078
 	/**
@@ -1086,7 +1084,7 @@  discard block
 block discarded – undo
1086 1084
 	 * @param array &$preserv
1087 1085
 	 * @return string message that exception was created
1088 1086
 	 */
1089
-	function _create_exception(&$event,&$preserv)
1087
+	function _create_exception(&$event, &$preserv)
1090 1088
 	{
1091 1089
 		// In some cases where the user makes the first day an exception, actual_date may be missing
1092 1090
 		$preserv['actual_date'] = $preserv['actual_date'] ? $preserv['actual_date'] : $event['start'];
@@ -1096,17 +1094,17 @@  discard block
 block discarded – undo
1096 1094
 		$event['recurrence'] = $preserv['recurrence'] = $preserv['actual_date'];
1097 1095
 		$event['start'] = $preserv['edit_single'] = $preserv['actual_date'];
1098 1096
 		$event['recur_type'] = MCAL_RECUR_NONE;
1099
-		foreach(array('recur_enddate','recur_interval','recur_exception','recur_data') as $name)
1097
+		foreach (array('recur_enddate', 'recur_interval', 'recur_exception', 'recur_data') as $name)
1100 1098
 		{
1101 1099
 			unset($event[$name]);
1102 1100
 		}
1103 1101
 		// add all alarms as new alarms to execption
1104 1102
 		$event['alarm'] = array_values((array)$event['alarm']);
1105
-		foreach($event['alarm'] as &$alarm)
1103
+		foreach ($event['alarm'] as &$alarm)
1106 1104
 		{
1107 1105
 			unset($alarm['uid'], $alarm['id'], $alarm['time']);
1108 1106
 		}
1109
-		if($this->bo->check_perms(Acl::EDIT,$event))
1107
+		if ($this->bo->check_perms(Acl::EDIT, $event))
1110 1108
 		{
1111 1109
 			return lang('Save event as exception - Delete single occurrence - Edit status or alarms for this particular day');
1112 1110
 		}
@@ -1133,14 +1131,14 @@  discard block
 block discarded – undo
1133 1131
 	{
1134 1132
 		$msg = false;
1135 1133
 
1136
-		if(!$as_of_date )
1134
+		if (!$as_of_date)
1137 1135
 		{
1138 1136
 			$as_of_date = time();
1139 1137
 		}
1140 1138
 
1141 1139
 		//error_log(__METHOD__ . Api\DateTime::to($old_event['start']) . ' -> '. Api\DateTime::to($event['start']) . ' as of ' . Api\DateTime::to($as_of_date));
1142 1140
 
1143
-		if(!($next_occurrence = $this->bo->read($event['id'], $this->bo->now_su + 1, true)))
1141
+		if (!($next_occurrence = $this->bo->read($event['id'], $this->bo->now_su + 1, true)))
1144 1142
 		{
1145 1143
 			$msg = lang("Error: You can't shift a series from the past!");
1146 1144
 			return $msg;
@@ -1153,11 +1151,11 @@  discard block
 block discarded – undo
1153 1151
 		$duration = $event['duration'] ? $event['duration'] : $event['end'] - $event['start'];
1154 1152
 
1155 1153
 		// base start-date of new series on actual / clicked date
1156
-		$event['start'] = $as_of_date ;
1154
+		$event['start'] = $as_of_date;
1157 1155
 
1158
-		if (Api\DateTime::to($old_event['start'],'Ymd') < Api\DateTime::to($as_of_date,'Ymd') ||
1156
+		if (Api\DateTime::to($old_event['start'], 'Ymd') < Api\DateTime::to($as_of_date, 'Ymd') ||
1159 1157
 			// Adjust for requested date in the past
1160
-			Api\DateTime::to($as_of_date,'ts') < time()
1158
+			Api\DateTime::to($as_of_date, 'ts') < time()
1161 1159
 		)
1162 1160
 		{
1163 1161
 
@@ -1177,17 +1175,17 @@  discard block
 block discarded – undo
1177 1175
 				$rriter->next_no_exception();
1178 1176
 				$occurrence = $rriter->current();
1179 1177
 			}
1180
-			while ($rriter->valid()  && (
1178
+			while ($rriter->valid() && (
1181 1179
 				Api\DateTime::to($occurrence, 'ts') <= time() ||
1182
-				Api\DateTime::to($occurrence, 'Ymd') < Api\DateTime::to($as_of_date,'Ymd')
1180
+				Api\DateTime::to($occurrence, 'Ymd') < Api\DateTime::to($as_of_date, 'Ymd')
1183 1181
 			) && ($last = $occurrence));
1184 1182
 
1185 1183
 
1186 1184
 			// Make sure as_of_date is still valid, may have to move forward
1187
-			if(Api\DateTime::to($as_of_date,'ts') < Api\DateTime::to($last,'ts') ||
1185
+			if (Api\DateTime::to($as_of_date, 'ts') < Api\DateTime::to($last, 'ts') ||
1188 1186
 				Api\DateTime::to($as_of_date, 'Ymd') == Api\DateTime::to($last, 'Ymd'))
1189 1187
 			{
1190
-				$event['start'] = Api\DateTime::to($rriter->current(),'ts') + $offset;
1188
+				$event['start'] = Api\DateTime::to($rriter->current(), 'ts') + $offset;
1191 1189
 			}
1192 1190
 
1193 1191
 			//error_log(__METHOD__ ." Series should end at " . Api\DateTime::to($last) . " New series starts at " . Api\DateTime::to($event['start']));
@@ -1195,7 +1193,7 @@  discard block
 block discarded – undo
1195 1193
 			{
1196 1194
 				$event['end'] = $event['start'] + $duration;
1197 1195
 			}
1198
-			elseif($event['end'] < $event['start'])
1196
+			elseif ($event['end'] < $event['start'])
1199 1197
 			{
1200 1198
 				$event['end'] = $old_event['end'] - $old_event['start'] + $event['start'];
1201 1199
 			}
@@ -1204,7 +1202,7 @@  discard block
 block discarded – undo
1204 1202
 			$event['participants'] = $old_event['participants'];
1205 1203
 			foreach ($old_event['recur_exception'] as $key => $exdate)
1206 1204
 			{
1207
-				if ($exdate > Api\DateTime::to($last,'ts'))
1205
+				if ($exdate > Api\DateTime::to($last, 'ts'))
1208 1206
 				{
1209 1207
 					//error_log("Moved exception on " . Api\DateTime::to($exdate));
1210 1208
 					unset($old_event['recur_exception'][$key]);
@@ -1218,18 +1216,18 @@  discard block
 block discarded – undo
1218 1216
 			}
1219 1217
 			$last->setTime(0, 0, 0);
1220 1218
 			$old_event['recur_enddate'] = Api\DateTime::to($last, 'ts');
1221
-			if (!$this->bo->update($old_event,true,true,false,true,$dummy=null,$no_notifications))
1219
+			if (!$this->bo->update($old_event, true, true, false, true, $dummy = null, $no_notifications))
1222 1220
 			{
1223
-				$msg .= ($msg ? ', ' : '') .lang('Error: the entry has been updated since you opened it for editing!').'<br />'.
1224
-					lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.','<a href="'.
1225
-						htmlspecialchars(Egw::link('/index.php',array(
1221
+				$msg .= ($msg ? ', ' : '').lang('Error: the entry has been updated since you opened it for editing!').'<br />'.
1222
+					lang('Copy your changes to the clipboard, %1reload the entry%2 and merge them.', '<a href="'.
1223
+						htmlspecialchars(Egw::link('/index.php', array(
1226 1224
 							'menuaction' => 'calendar.calendar_uiforms.edit',
1227 1225
 							'cal_id'    => $event['id'],
1228
-						))).'">','</a>');
1226
+						))).'">', '</a>');
1229 1227
 				$event = $orig_event;
1230 1228
 			}
1231 1229
 		}
1232
-		$event['start'] = Api\DateTime::to($event['start'],'ts');
1230
+		$event['start'] = Api\DateTime::to($event['start'], 'ts');
1233 1231
 		return $msg;
1234 1232
 	}
1235 1233
 
@@ -1240,11 +1238,11 @@  discard block
 block discarded – undo
1240 1238
 	 * @param boolean $added
1241 1239
 	 * @return string javascript window.open command
1242 1240
 	 */
1243
-	function ajax_custom_mail($event,$added,$asrequest=false)
1241
+	function ajax_custom_mail($event, $added, $asrequest = false)
1244 1242
 	{
1245 1243
 		$to = array();
1246 1244
 
1247
-		foreach($event['participants'] as $uid => $status)
1245
+		foreach ($event['participants'] as $uid => $status)
1248 1246
 		{
1249 1247
 			//error_log(__METHOD__.__LINE__.' '.$uid.':'.array2string($status));
1250 1248
 			if (empty($status)) continue;
@@ -1253,32 +1251,32 @@  discard block
 block discarded – undo
1253 1251
 
1254 1252
 			if (isset($status['uid']) && is_numeric($status['uid']) && $GLOBALS['egw']->accounts->get_type($status['uid']) == 'u')
1255 1253
 			{
1256
-				if (!($email = $GLOBALS['egw']->accounts->id2name($status['uid'],'account_email'))) continue;
1254
+				if (!($email = $GLOBALS['egw']->accounts->id2name($status['uid'], 'account_email'))) continue;
1257 1255
 
1258 1256
 				$toadd = $GLOBALS['egw']->accounts->id2name($status['uid'], 'account_firstname').' '.
1259 1257
 					$GLOBALS['egw']->accounts->id2name($status['uid'], 'account_lastname').' <'.$email.'>';
1260 1258
 
1261
-				if (!in_array($toadd,$to)) $to[] = $toadd;
1259
+				if (!in_array($toadd, $to)) $to[] = $toadd;
1262 1260
 			}
1263 1261
 			elseif ($uid < 0)
1264 1262
 			{
1265
-				foreach($GLOBALS['egw']->accounts->members($uid,true) as $uid)
1263
+				foreach ($GLOBALS['egw']->accounts->members($uid, true) as $uid)
1266 1264
 				{
1267
-					if (!($email = $GLOBALS['egw']->accounts->id2name($uid,'account_email'))) continue;
1265
+					if (!($email = $GLOBALS['egw']->accounts->id2name($uid, 'account_email'))) continue;
1268 1266
 
1269 1267
 					$toadd = $GLOBALS['egw']->accounts->id2name($uid, 'account_firstname').' '.
1270 1268
 						$GLOBALS['egw']->accounts->id2name($uid, 'account_lastname').' <'.$email.'>';
1271 1269
 
1272 1270
 					// dont add groupmembers if they already rejected the event, or are the current user
1273
-					if (!in_array($toadd,$to) && ($event['participants'][$uid] !== 'R' && $uid != $this->user)) $to[] = $toadd;
1271
+					if (!in_array($toadd, $to) && ($event['participants'][$uid] !== 'R' && $uid != $this->user)) $to[] = $toadd;
1274 1272
 				}
1275 1273
 			}
1276
-			elseif(!empty($status['uid'])&& !is_numeric(substr($status['uid'],0,1)) && ($info = $this->bo->resource_info($status['uid'])))
1274
+			elseif (!empty($status['uid']) && !is_numeric(substr($status['uid'], 0, 1)) && ($info = $this->bo->resource_info($status['uid'])))
1277 1275
 			{
1278 1276
 				$to[] = $info['email'];
1279 1277
 				//error_log(__METHOD__.__LINE__.array2string($to));
1280 1278
 			}
1281
-			elseif(!is_numeric(substr($uid,0,1)) && ($info = $this->bo->resource_info($uid)))
1279
+			elseif (!is_numeric(substr($uid, 0, 1)) && ($info = $this->bo->resource_info($uid)))
1282 1280
 			{
1283 1281
 				$to[] = $info['email'];
1284 1282
 				//error_log(__METHOD__.__LINE__.array2string($to));
@@ -1287,7 +1285,7 @@  discard block
 block discarded – undo
1287 1285
 		// prefer event description over standard notification text
1288 1286
 		if (empty($event['description']))
1289 1287
 		{
1290
-			list(,$body) = $this->bo->get_update_message($event,$added ? MSG_ADDED : MSG_MODIFIED);	// update-message is in TZ of the user
1288
+			list(,$body) = $this->bo->get_update_message($event, $added ? MSG_ADDED : MSG_MODIFIED); // update-message is in TZ of the user
1291 1289
 		}
1292 1290
 		else
1293 1291
 		{
@@ -1302,12 +1300,12 @@  discard block
 block discarded – undo
1302 1300
 		$boical = new calendar_ical();
1303 1301
 		// we need to pass $event[id] so iCal class reads event again,
1304 1302
 		// as event is in user TZ, but iCal class expects server TZ!
1305
-		$ics = $boical->exportVCal(array($event['id']),'2.0','REQUEST',false);
1303
+		$ics = $boical->exportVCal(array($event['id']), '2.0', 'REQUEST', false);
1306 1304
 
1307
-		$ics_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'ics');
1308
-		if(($f = fopen($ics_file,'w')))
1305
+		$ics_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'ics');
1306
+		if (($f = fopen($ics_file, 'w')))
1309 1307
 		{
1310
-			fwrite($f,$ics);
1308
+			fwrite($f, $ics);
1311 1309
 			fclose($f);
1312 1310
 		}
1313 1311
 		//error_log(__METHOD__.__LINE__.array2string($to));
@@ -1319,7 +1317,7 @@  discard block
 block discarded – undo
1319 1317
 			'preset[body]'    => $body,
1320 1318
 			'preset[name]'    => 'event.ics',
1321 1319
 			'preset[file]'    => $ics_file,
1322
-			'preset[type]'    => 'text/calendar'.($asrequest?'; method=REQUEST':''),
1320
+			'preset[type]'    => 'text/calendar'.($asrequest ? '; method=REQUEST' : ''),
1323 1321
 			'preset[size]'    => filesize($ics_file),
1324 1322
 		);
1325 1323
 		if ($asrequest) $vars['preset[msg]'] = lang('You attempt to mail a meetingrequest to the recipients above. Depending on the client this mail is opened with, the recipient may or may not see the mailbody below, but only see the meeting request attached.');
@@ -1375,7 +1373,7 @@  discard block
 block discarded – undo
1375 1373
 	 * @param mixed $link_to_id ='' from or for the link-widget
1376 1374
 	 * @param string $msg_type =null default automatic detect, if it contains "error"
1377 1375
 	 */
1378
-	function edit($event=null,$preserv=null,$msg='',$link_to_id='',$msg_type=null)
1376
+	function edit($event = null, $preserv = null, $msg = '', $link_to_id = '', $msg_type = null)
1379 1377
 	{
1380 1378
 		$sel_options = array(
1381 1379
 			'recur_type' => &$this->bo->recur_types,
@@ -1399,8 +1397,8 @@  discard block
 block discarded – undo
1399 1397
 				'no_popup' => isset($_GET['no_popup']),
1400 1398
 				'template' => isset($_GET['template']) ? $_GET['template'] : (isset($_REQUEST['print']) ? 'calendar.print' : 'calendar.edit'),
1401 1399
 			);
1402
-			$cal_id = (int) $_GET['cal_id'];
1403
-			if($_GET['action'])
1400
+			$cal_id = (int)$_GET['cal_id'];
1401
+			if ($_GET['action'])
1404 1402
 			{
1405 1403
 				$event = $this->bo->read($cal_id);
1406 1404
 				$event['action'] = $_GET['action'];
@@ -1418,14 +1416,14 @@  discard block
 block discarded – undo
1418 1416
 			{
1419 1417
 				//error_log(__METHOD__."() Error: importing the iCal: vfs file not found '$_GET[ical_vfs]'!");
1420 1418
 				$msg = lang('Error: importing the iCal').': '.lang('VFS file not found').': '.$_GET['ical_vfs'];
1421
-				$event =& $this->default_add_event();
1419
+				$event = & $this->default_add_event();
1422 1420
 			}
1423 1421
 			if (!empty($_GET['ical_data']) &&
1424 1422
 				!($_GET['ical'] = Link::get_data($_GET['ical_data'])))
1425 1423
 			{
1426 1424
 				//error_log(__METHOD__."() Error: importing the iCal: data not found '$_GET[ical_data]'!");
1427 1425
 				$msg = lang('Error: importing the iCal').': '.lang('Data not found').': '.$_GET['ical_data'];
1428
-				$event =& $this->default_add_event();
1426
+				$event = & $this->default_add_event();
1429 1427
 			}
1430 1428
 			if (!empty($_GET['ical']))
1431 1429
 			{
@@ -1434,14 +1432,14 @@  discard block
 block discarded – undo
1434 1432
 				{
1435 1433
 					error_log(__METHOD__."('$_GET[ical]') error parsing iCal!");
1436 1434
 					$msg = lang('Error: importing the iCal');
1437
-					$event =& $this->default_add_event();
1435
+					$event = & $this->default_add_event();
1438 1436
 				}
1439 1437
 				else
1440 1438
 				{
1441 1439
 					if (count($events) > 1)
1442 1440
 					{
1443 1441
 						$msg = lang('%1 events in iCal file, only first one imported and displayed!', count($events));
1444
-						$msg_type = 'notice';	// no not hide automatic
1442
+						$msg_type = 'notice'; // no not hide automatic
1445 1443
 					}
1446 1444
 					// as icaltoegw returns timestamps in server-time, we have to convert them here to user-time
1447 1445
 					$this->bo->db2data($events, 'ts');
@@ -1454,7 +1452,7 @@  discard block
 block discarded – undo
1454 1452
 					else
1455 1453
 					{
1456 1454
 						$event['participant_types'] = array();
1457
-						foreach($event['participants'] as $uid => $status)
1455
+						foreach ($event['participants'] as $uid => $status)
1458 1456
 						{
1459 1457
 							$user_type = $user_id = null;
1460 1458
 							calendar_so::split_user($uid, $user_type, $user_id);
@@ -1475,15 +1473,15 @@  discard block
 block discarded – undo
1475 1473
 					}
1476 1474
 					else
1477 1475
 					{
1478
-						$GLOBALS['egw']->framework->render('<p class="message" align="center">'.lang('Permission denied')."</p>\n",null,true);
1476
+						$GLOBALS['egw']->framework->render('<p class="message" align="center">'.lang('Permission denied')."</p>\n", null, true);
1479 1477
 						exit();
1480 1478
 					}
1481 1479
 				}
1482
-				$event =& $this->default_add_event();
1480
+				$event = & $this->default_add_event();
1483 1481
 			}
1484 1482
 			else
1485 1483
 			{
1486
-				$preserv['actual_date'] = $event['start'];		// remember the date clicked
1484
+				$preserv['actual_date'] = $event['start']; // remember the date clicked
1487 1485
 				if ($event['recur_type'] != MCAL_RECUR_NONE)
1488 1486
 				{
1489 1487
 					if (empty($event['whole_day']))
@@ -1496,10 +1494,10 @@  discard block
 block discarded – undo
1496 1494
 						$date->setUser();
1497 1495
 					}
1498 1496
 					$event = $this->bo->read($cal_id, $date, true);
1499
-					$preserv['actual_date'] = $event['start'];		// remember the date clicked
1497
+					$preserv['actual_date'] = $event['start']; // remember the date clicked
1500 1498
 					if ($_GET['exception'])
1501 1499
 					{
1502
-						$msg = $this->_create_exception($event,$preserv);
1500
+						$msg = $this->_create_exception($event, $preserv);
1503 1501
 					}
1504 1502
 					else
1505 1503
 					{
@@ -1508,9 +1506,9 @@  discard block
 block discarded – undo
1508 1506
 				}
1509 1507
 			}
1510 1508
 			// set new start and end if given by $_GET
1511
-			if(isset($_GET['start'])) { $event['start'] = Api\DateTime::to($_GET['start'],'ts'); }
1512
-			if(isset($_GET['end'])) { $event['end'] = Api\DateTime::to($_GET['end'],'ts'); }
1513
-			if(isset($_GET['non_blocking'])) { $event['non_blocking'] = (bool)$_GET['non_blocking']; }
1509
+			if (isset($_GET['start'])) { $event['start'] = Api\DateTime::to($_GET['start'], 'ts'); }
1510
+			if (isset($_GET['end'])) { $event['end'] = Api\DateTime::to($_GET['end'], 'ts'); }
1511
+			if (isset($_GET['non_blocking'])) { $event['non_blocking'] = (bool)$_GET['non_blocking']; }
1514 1512
 			// check if the event is the whole day
1515 1513
 			$start = $this->bo->date2array($event['start']);
1516 1514
 			$end = $this->bo->date2array($event['end']);
@@ -1520,30 +1518,30 @@  discard block
 block discarded – undo
1520 1518
 			if (!$event['id'] && isset($_REQUEST['link_app']) && isset($_REQUEST['link_id']))
1521 1519
 			{
1522 1520
 				$link_ids = is_array($_REQUEST['link_id']) ? $_REQUEST['link_id'] : array($_REQUEST['link_id']);
1523
-				foreach(is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
1521
+				foreach (is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
1524 1522
 				{
1525 1523
 					$link_id = $link_ids[$n];
1526
-					if(!preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id))	// guard against XSS
1524
+					if (!preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i', $link_app.':'.$link_id))	// guard against XSS
1527 1525
 					{
1528 1526
 						continue;
1529 1527
 					}
1530
-					if(!$n)
1528
+					if (!$n)
1531 1529
 					{
1532
-						$event['title'] = Link::title($link_app,$link_id);
1530
+						$event['title'] = Link::title($link_app, $link_id);
1533 1531
 						// ask first linked app via "calendar_set" hook, for further data to set, incl. links
1534
-						if (($set = Api\Hooks::single($event+array('location'=>'calendar_set','entry_id'=>$link_id),$link_app)))
1532
+						if (($set = Api\Hooks::single($event + array('location'=>'calendar_set', 'entry_id'=>$link_id), $link_app)))
1535 1533
 						{
1536
-							foreach((array)$set['link_app'] as $i => $l_app)
1534
+							foreach ((array)$set['link_app'] as $i => $l_app)
1537 1535
 							{
1538
-								if (($l_id=$set['link_id'][$i])) Link::link('calendar',$event['link_to']['to_id'],$l_app,$l_id);
1536
+								if (($l_id = $set['link_id'][$i])) Link::link('calendar', $event['link_to']['to_id'], $l_app, $l_id);
1539 1537
 							}
1540 1538
 							unset($set['link_app']);
1541 1539
 							unset($set['link_id']);
1542 1540
 
1543
-							$event = array_merge($event,$set);
1541
+							$event = array_merge($event, $set);
1544 1542
 						}
1545 1543
 					}
1546
-					Link::link('calendar',$link_to_id,$link_app,$link_id);
1544
+					Link::link('calendar', $link_to_id, $link_app, $link_id);
1547 1545
 				}
1548 1546
 			}
1549 1547
 		}
@@ -1553,44 +1551,44 @@  discard block
 block discarded – undo
1553 1551
 		{
1554 1552
 			$etpl->read($preserv['template'] = 'calendar.edit');
1555 1553
 		}
1556
-		$view = $preserv['view'] = $preserv['view'] || $event['id'] && !$this->bo->check_perms(Acl::EDIT,$event);
1554
+		$view = $preserv['view'] = $preserv['view'] || $event['id'] && !$this->bo->check_perms(Acl::EDIT, $event);
1557 1555
 		//echo "view=$view, event="; _debug_array($event);
1558 1556
 		// shared locking of entries to edit
1559 1557
 		if (!$view && ($locktime = $GLOBALS['egw_info']['server']['Lock_Time_Calender']) && $event['id'])
1560 1558
 		{
1561
-			$lock_path = Vfs::app_entry_lock_path('calendar',$event['id']);
1559
+			$lock_path = Vfs::app_entry_lock_path('calendar', $event['id']);
1562 1560
 			$lock_owner = 'mailto:'.$GLOBALS['egw_info']['user']['account_email'];
1563 1561
 
1564 1562
 			if (($preserv['lock_token'] = $event['lock_token']))		// already locked --> refresh the lock
1565 1563
 			{
1566
-				Vfs::lock($lock_path,$preserv['lock_token'],$locktime,$lock_owner,$scope='shared',$type='write',true,false);
1564
+				Vfs::lock($lock_path, $preserv['lock_token'], $locktime, $lock_owner, $scope = 'shared', $type = 'write', true, false);
1567 1565
 			}
1568 1566
 			if (($lock = Vfs::checkLock($lock_path)) && $lock['owner'] != $lock_owner)
1569 1567
 			{
1570 1568
 				$msg .= ' '.lang('This entry is currently opened by %1!',
1571
-					(($lock_uid = $GLOBALS['egw']->accounts->name2id(substr($lock['owner'],7),'account_email')) ?
1569
+					(($lock_uid = $GLOBALS['egw']->accounts->name2id(substr($lock['owner'], 7), 'account_email')) ?
1572 1570
 					Api\Accounts::username($lock_uid) : $lock['owner']));
1573 1571
 			}
1574
-			elseif($lock)
1572
+			elseif ($lock)
1575 1573
 			{
1576 1574
 				$preserv['lock_token'] = $lock['token'];
1577 1575
 			}
1578
-			elseif(Vfs::lock($lock_path,$preserv['lock_token'],$locktime,$lock_owner,$scope='shared',$type='write',false,false))
1576
+			elseif (Vfs::lock($lock_path, $preserv['lock_token'], $locktime, $lock_owner, $scope = 'shared', $type = 'write', false, false))
1579 1577
 			{
1580 1578
 				//We handle AJAX_REQUEST in client-side for unlocking the locked entry, in case of closing the entry by X button or close button
1581 1579
 			}
1582 1580
 			else
1583 1581
 			{
1584
-				$msg .= ' '.lang("Can't aquire lock!");		// eg. an exclusive lock via CalDAV ...
1582
+				$msg .= ' '.lang("Can't aquire lock!"); // eg. an exclusive lock via CalDAV ...
1585 1583
 				$view = true;
1586 1584
 			}
1587 1585
 		}
1588
-		$content = array_merge($event,array(
1586
+		$content = array_merge($event, array(
1589 1587
 			'link_to' => array(
1590 1588
 				'to_id'  => $link_to_id,
1591 1589
 				'to_app' => 'calendar',
1592 1590
 			),
1593
-			'edit_single' => $preserv['edit_single'],	// need to be in content too, as it is used in the template
1591
+			'edit_single' => $preserv['edit_single'], // need to be in content too, as it is used in the template
1594 1592
 			'tabs'   => $preserv['tabs'],
1595 1593
 			'view' => $view,
1596 1594
 			'query_delete_exceptions' => (int)($event['recur_type'] && $event['recur_exception']),
@@ -1602,11 +1600,11 @@  discard block
 block discarded – undo
1602 1600
 		$row = 3;
1603 1601
 		$readonlys = $content['participants'] = $preserv['participants'] = array();
1604 1602
 		// preserve some ui elements, if set eg. under error-conditions
1605
-		foreach(array('quantity','resource','role') as $n)
1603
+		foreach (array('quantity', 'resource', 'role') as $n)
1606 1604
 		{
1607 1605
 			if (isset($event['participants'][$n])) $content['participants'][$n] = $event['participants'][$n];
1608 1606
 		}
1609
-		foreach($event['participant_types'] as $type => $participants)
1607
+		foreach ($event['participant_types'] as $type => $participants)
1610 1608
 		{
1611 1609
 			$name = 'accounts';
1612 1610
 			if (isset($this->bo->resources[$type]))
@@ -1615,17 +1613,17 @@  discard block
 block discarded – undo
1615 1613
 			}
1616 1614
 			// sort participants (in there group/app) by title
1617 1615
 			uksort($participants, array($this, 'uid_title_cmp'));
1618
-			foreach($participants as $id => $status)
1616
+			foreach ($participants as $id => $status)
1619 1617
 			{
1620 1618
 				$uid = $type == 'u' ? $id : $type.$id;
1621 1619
 				$quantity = $role = null;
1622
-				calendar_so::split_status($status,$quantity,$role);
1620
+				calendar_so::split_status($status, $quantity, $role);
1623 1621
 				$preserv['participants'][$row] = $content['participants'][$row] = array(
1624 1622
 					'app'      => $name == 'accounts' ? ($GLOBALS['egw']->accounts->get_type($id) == 'g' ? 'Group' : 'User') : $name,
1625 1623
 					'uid'      => $uid,
1626 1624
 					'status'   => $status,
1627 1625
 					'old_status' => $status,
1628
-					'quantity' => $quantity > 1 || $uid[0] == 'r' ? $quantity : '',	// only display quantity for resources or if > 1
1626
+					'quantity' => $quantity > 1 || $uid[0] == 'r' ? $quantity : '', // only display quantity for resources or if > 1
1629 1627
 					'role'     => $role,
1630 1628
 				);
1631 1629
 				// replace iCal roles with a nicer label and remove regular REQ-PARTICIPANT
@@ -1634,33 +1632,33 @@  discard block
 block discarded – undo
1634 1632
 					$content['participants'][$row]['role_label'] = lang($this->bo->roles[$role]);
1635 1633
 				}
1636 1634
 				// allow third party apps to use categories for roles
1637
-				elseif(substr($role,0,6) == 'X-CAT-')
1635
+				elseif (substr($role, 0, 6) == 'X-CAT-')
1638 1636
 				{
1639
-					$content['participants'][$row]['role_label'] = $GLOBALS['egw']->categories->id2name(substr($role,6));
1637
+					$content['participants'][$row]['role_label'] = $GLOBALS['egw']->categories->id2name(substr($role, 6));
1640 1638
 				}
1641 1639
 				else
1642 1640
 				{
1643
-					$content['participants'][$row]['role_label'] = lang(str_replace('X-','',$role));
1641
+					$content['participants'][$row]['role_label'] = lang(str_replace('X-', '', $role));
1644 1642
 				}
1645
-				$content['participants'][$row]['delete_id'] = strpbrk($uid,'"\'<>') !== false ? md5($uid) : $uid;
1643
+				$content['participants'][$row]['delete_id'] = strpbrk($uid, '"\'<>') !== false ? md5($uid) : $uid;
1646 1644
 				//echo "<p>$uid ($quantity): $role --> {$content['participants'][$row]['role']}</p>\n";
1647 1645
 
1648
-				if (($no_status = !$this->bo->check_status_perms($uid,$event)) || $view)
1646
+				if (($no_status = !$this->bo->check_status_perms($uid, $event)) || $view)
1649 1647
 					$readonlys['participants'][$row]['status'] = $no_status;
1650
-				if ($preserv['hide_delete'] || !$this->bo->check_perms(Acl::EDIT,$event))
1648
+				if ($preserv['hide_delete'] || !$this->bo->check_perms(Acl::EDIT, $event))
1651 1649
 					$readonlys['participants']['delete'][$uid] = true;
1652 1650
 				// todo: make the participants available as links with email as title
1653 1651
 				$content['participants'][$row++]['title'] = $this->get_title($uid);
1654 1652
 				// enumerate group-invitations, so people can accept/reject them
1655 1653
 				if ($name == 'accounts' && $GLOBALS['egw']->accounts->get_type($id) == 'g' &&
1656
-					($members = $GLOBALS['egw']->accounts->members($id,true)))
1654
+					($members = $GLOBALS['egw']->accounts->members($id, true)))
1657 1655
 				{
1658 1656
 					$sel_options['status']['G'] = lang('Select one');
1659 1657
 					// sort members by title
1660 1658
 					usort($members, array($this, 'uid_title_cmp'));
1661
-					foreach($members as $member)
1659
+					foreach ($members as $member)
1662 1660
 					{
1663
-						if (!isset($participants[$member]) && $this->bo->check_perms(Acl::READ,0,$member))
1661
+						if (!isset($participants[$member]) && $this->bo->check_perms(Acl::READ, 0, $member))
1664 1662
 						{
1665 1663
 							$preserv['participants'][$row] = $content['participants'][$row] = array(
1666 1664
 								'app'      => 'Group invitation',
@@ -1669,7 +1667,7 @@  discard block
 block discarded – undo
1669 1667
 							);
1670 1668
 							$readonlys['participants'][$row]['quantity'] = $readonlys['participants']['delete'][$member] = true;
1671 1669
 							// read access is enough to invite participants, but you need edit rights to change status
1672
-							$readonlys['participants'][$row]['status'] = !$this->bo->check_perms(Acl::EDIT,0,$member);
1670
+							$readonlys['participants'][$row]['status'] = !$this->bo->check_perms(Acl::EDIT, 0, $member);
1673 1671
 							$content['participants'][$row++]['title'] = Api\Accounts::username($member);
1674 1672
 						}
1675 1673
 					}
@@ -1677,43 +1675,43 @@  discard block
 block discarded – undo
1677 1675
 			}
1678 1676
 			// resouces / apps we shedule, atm. resources and addressbook
1679 1677
 			$content['participants']['cal_resources'] = '';
1680
-			foreach($this->bo->resources as $data)
1678
+			foreach ($this->bo->resources as $data)
1681 1679
 			{
1682
-				if ($data['app'] == 'email') continue;	// make no sense, as we cant search for email
1680
+				if ($data['app'] == 'email') continue; // make no sense, as we cant search for email
1683 1681
 				$content['participants']['cal_resources'] .= ','.$data['app'];
1684 1682
 			}
1685 1683
 		}
1686 1684
 		$content['participants']['status_date'] = $preserv['actual_date'];
1687
-		$preserved = array_merge($preserv,$content);
1685
+		$preserved = array_merge($preserv, $content);
1688 1686
 		$event['new_alarm']['options'] = $content['new_alarm']['options'];
1689 1687
 		if ($event['alarm'])
1690 1688
 		{
1691 1689
 			// makes keys of the alarm-array starting with 1
1692 1690
 			$content['alarm'] = array(false);
1693
-			foreach(array_values($event['alarm']) as $id => $alarm)
1691
+			foreach (array_values($event['alarm']) as $id => $alarm)
1694 1692
 			{
1695
-				if (!$alarm['all'] && !$this->bo->check_perms(Acl::READ,0,$alarm['owner']))
1693
+				if (!$alarm['all'] && !$this->bo->check_perms(Acl::READ, 0, $alarm['owner']))
1696 1694
 				{
1697
-					continue;	// no read rights to the calendar of the alarm-owner, dont show the alarm
1695
+					continue; // no read rights to the calendar of the alarm-owner, dont show the alarm
1698 1696
 				}
1699
-				$alarm['all'] = (int) $alarm['all'];
1697
+				$alarm['all'] = (int)$alarm['all'];
1700 1698
 				$after = false;
1701
-				if($alarm['offset'] < 0)
1699
+				if ($alarm['offset'] < 0)
1702 1700
 				{
1703 1701
 					$after = true;
1704 1702
 					$alarm['offset'] = -1 * $alarm['offset'];
1705 1703
 				}
1706
-				$days = (int) ($alarm['offset'] / DAY_s);
1707
-				$hours = (int) (($alarm['offset'] % DAY_s) / HOUR_s);
1708
-				$minutes = (int) (($alarm['offset'] % HOUR_s) / 60);
1704
+				$days = (int)($alarm['offset'] / DAY_s);
1705
+				$hours = (int)(($alarm['offset'] % DAY_s) / HOUR_s);
1706
+				$minutes = (int)(($alarm['offset'] % HOUR_s) / 60);
1709 1707
 				$label = array();
1710 1708
 				if ($days) $label[] = $days.' '.lang('days');
1711 1709
 				if ($hours) $label[] = $hours.' '.lang('hours');
1712 1710
 				if ($minutes) $label[] = $minutes.' '.lang('Minutes');
1713
-				$alarm['offset'] = implode(', ',$label) . ' ' . ($after ? lang('after') : lang('before'));
1711
+				$alarm['offset'] = implode(', ', $label).' '.($after ? lang('after') : lang('before'));
1714 1712
 				$content['alarm'][] = $alarm;
1715 1713
 
1716
-				$readonlys['alarm[delete_alarm]['.$alarm['id'].']'] = !$this->bo->check_perms(Acl::EDIT,$alarm['all'] ? $event : 0,$alarm['owner']);
1714
+				$readonlys['alarm[delete_alarm]['.$alarm['id'].']'] = !$this->bo->check_perms(Acl::EDIT, $alarm['all'] ? $event : 0, $alarm['owner']);
1717 1715
 			}
1718 1716
 			if (count($content['alarm']) == 1)
1719 1717
 			{
@@ -1728,20 +1726,20 @@  discard block
 block discarded – undo
1728 1726
 
1729 1727
 		if ($view)
1730 1728
 		{
1731
-			$readonlys['__ALL__'] = true;	// making everything readonly, but widgets set explicitly to false
1729
+			$readonlys['__ALL__'] = true; // making everything readonly, but widgets set explicitly to false
1732 1730
 			$readonlys['button[cancel]'] = $readonlys['action'] =
1733 1731
 				$readonlys['before_after'] = $readonlys['button[add_alarm]'] = $readonlys['new_alarm[owner]'] =
1734 1732
 				$readonlys['new_alarm[options]'] = $readonlys['new_alarm[date]'] = false;
1735 1733
 
1736 1734
 			$content['participants']['no_add'] = true;
1737 1735
 
1738
-			if(!$event['whole_day'])
1736
+			if (!$event['whole_day'])
1739 1737
 			{
1740 1738
 				$etpl->setElementAttribute('whole_day', 'disabled', true);
1741 1739
 			}
1742 1740
 
1743 1741
 			// respect category permissions
1744
-			if(!empty($event['category']))
1742
+			if (!empty($event['category']))
1745 1743
 			{
1746 1744
 				$content['category'] = $this->categories->check_list(Acl::READ, $event['category']);
1747 1745
 			}
@@ -1752,7 +1750,7 @@  discard block
 block discarded – undo
1752 1750
 
1753 1751
 			if ($event['recur_type'] != MCAL_RECUR_NONE)
1754 1752
 			{
1755
-				$readonlys['recur_exception'] = !count($content['recur_exception']);	// otherwise we get a delete button
1753
+				$readonlys['recur_exception'] = !count($content['recur_exception']); // otherwise we get a delete button
1756 1754
 				//$onclick =& $etpl->get_cell_attribute('button[delete]','onclick');
1757 1755
 				//$onclick = str_replace('Delete this event','Delete this series of recuring events',$onclick);
1758 1756
 			}
@@ -1762,9 +1760,9 @@  discard block
 block discarded – undo
1762 1760
 				$readonlys['recur_interval'] = $readonlys['recur_data'] = true;
1763 1761
 			}
1764 1762
 		}
1765
-		if($content['category'] && !is_array($content['category']))
1763
+		if ($content['category'] && !is_array($content['category']))
1766 1764
 		{
1767
-			$content['category'] = explode(',',$event['category']);
1765
+			$content['category'] = explode(',', $event['category']);
1768 1766
 		}
1769 1767
 		// disabling the custom fields tab, if there are none
1770 1768
 		$readonlys['tabs'] = array(
@@ -1781,13 +1779,13 @@  discard block
 block discarded – undo
1781 1779
 		{
1782 1780
 			$readonlys['action'] = true;
1783 1781
 		}
1784
-		if (!($readonlys['button[exception]'] = !$this->bo->check_perms(Acl::EDIT,$event) || $event['recur_type'] == MCAL_RECUR_NONE || ($event['recur_enddate'] &&$event['start'] > $event['recur_enddate'])))
1782
+		if (!($readonlys['button[exception]'] = !$this->bo->check_perms(Acl::EDIT, $event) || $event['recur_type'] == MCAL_RECUR_NONE || ($event['recur_enddate'] && $event['start'] > $event['recur_enddate'])))
1785 1783
 		{
1786 1784
 			$content['exception_label'] = $this->bo->long_date(max($preserved['actual_date'], $event['start']));
1787 1785
 		}
1788
-		$readonlys['button[delete]'] = !$event['id'] || $preserved['hide_delete'] || !$this->bo->check_perms(Acl::DELETE,$event);
1786
+		$readonlys['button[delete]'] = !$event['id'] || $preserved['hide_delete'] || !$this->bo->check_perms(Acl::DELETE, $event);
1789 1787
 
1790
-		if (!$event['id'] || $this->bo->check_perms(Acl::EDIT,$event))	// new event or edit rights to the event ==> allow to add alarm for all users
1788
+		if (!$event['id'] || $this->bo->check_perms(Acl::EDIT, $event))	// new event or edit rights to the event ==> allow to add alarm for all users
1791 1789
 		{
1792 1790
 			$sel_options['owner'][0] = lang('All participants');
1793 1791
 		}
@@ -1795,25 +1793,25 @@  discard block
 block discarded – undo
1795 1793
 		{
1796 1794
 			$sel_options['owner'][$this->user] = $this->bo->participant_name($this->user);
1797 1795
 		}
1798
-		foreach((array) $event['participant_types']['u'] as $uid => $status)
1796
+		foreach ((array)$event['participant_types']['u'] as $uid => $status)
1799 1797
 		{
1800
-			if ($uid != $this->user && $status != 'R' && $this->bo->check_perms(Acl::EDIT,0,$uid))
1798
+			if ($uid != $this->user && $status != 'R' && $this->bo->check_perms(Acl::EDIT, 0, $uid))
1801 1799
 			{
1802 1800
 				$sel_options['owner'][$uid] = $this->bo->participant_name($uid);
1803 1801
 			}
1804 1802
 		}
1805
-		$content['no_add_alarm'] = !count($sel_options['owner']);	// no rights to set any alarm
1803
+		$content['no_add_alarm'] = !count($sel_options['owner']); // no rights to set any alarm
1806 1804
 		if (!$event['id'])
1807 1805
 		{
1808
-			$etpl->set_cell_attribute('button[new_alarm]','type','checkbox');
1806
+			$etpl->set_cell_attribute('button[new_alarm]', 'type', 'checkbox');
1809 1807
 		}
1810 1808
 		if ($preserved['no_popup'])
1811 1809
 		{
1812
-			$etpl->set_cell_attribute('button[cancel]','onclick','');
1810
+			$etpl->set_cell_attribute('button[cancel]', 'onclick', '');
1813 1811
 		}
1814 1812
 
1815 1813
 		// Allow admins to restore deleted events
1816
-		if($GLOBALS['egw_info']['server']['calendar_delete_history'] && $event['deleted'] )
1814
+		if ($GLOBALS['egw_info']['server']['calendar_delete_history'] && $event['deleted'])
1817 1815
 		{
1818 1816
 			$content['deleted'] = $preserved['deleted'] = null;
1819 1817
 			$etpl->set_cell_attribute('button[save]', 'label', 'Recover');
@@ -1825,7 +1823,7 @@  discard block
 block discarded – undo
1825 1823
 		// Setup history tab
1826 1824
 		$this->setup_history($content, $sel_options);
1827 1825
 
1828
-		$GLOBALS['egw_info']['flags']['app_header'] = lang('calendar') . ' - '
1826
+		$GLOBALS['egw_info']['flags']['app_header'] = lang('calendar').' - '
1829 1827
 			. (!$event['id'] ? lang('Add')
1830 1828
 				: ($view ? ($content['edit_single'] ? lang('View exception') : ($content['recur_type'] ? lang('View series') : lang('View')))
1831 1829
 					: ($content['edit_single'] ? lang('Create exception') : ($content['recur_type'] ? lang('Edit series') : lang('Edit')))));
@@ -1835,15 +1833,15 @@  discard block
 block discarded – undo
1835 1833
 		if (!empty($preserved['lock_token'])) $content['lock_token'] = $preserved['lock_token'];
1836 1834
 
1837 1835
 		// non_interactive==true from $_GET calls immediate save action without displaying the edit form
1838
-		if(isset($_GET['non_interactive']) && (bool)$_GET['non_interactive'] === true)
1836
+		if (isset($_GET['non_interactive']) && (bool)$_GET['non_interactive'] === true)
1839 1837
 		{
1840
-			unset($_GET['non_interactive']);	// prevent process_exec <--> edit loops
1838
+			unset($_GET['non_interactive']); // prevent process_exec <--> edit loops
1841 1839
 			$content['button']['save'] = true;
1842
-			$this->process_edit(array_merge($content,$preserved));
1840
+			$this->process_edit(array_merge($content, $preserved));
1843 1841
 		}
1844 1842
 		else
1845 1843
 		{
1846
-			$etpl->exec('calendar.calendar_uiforms.process_edit',$content,$sel_options,$readonlys,$preserved,$preserved['no_popup'] ? 0 : 2);
1844
+			$etpl->exec('calendar.calendar_uiforms.process_edit', $content, $sel_options, $readonlys, $preserved, $preserved['no_popup'] ? 0 : 2);
1847 1845
 		}
1848 1846
 	}
1849 1847
 
@@ -1853,14 +1851,14 @@  discard block
 block discarded – undo
1853 1851
 	 * @param int $id
1854 1852
 	 * @param string $token
1855 1853
 	 */
1856
-	function ajax_unlock($id,$token)
1854
+	function ajax_unlock($id, $token)
1857 1855
 	{
1858
-		$lock_path = Vfs::app_entry_lock_path('calendar',$id);
1856
+		$lock_path = Vfs::app_entry_lock_path('calendar', $id);
1859 1857
 		$lock_owner = 'mailto:'.$GLOBALS['egw_info']['user']['account_email'];
1860 1858
 
1861 1859
 		if (($lock = Vfs::checkLock($lock_path)) && $lock['owner'] == $lock_owner || $lock['token'] == $token)
1862 1860
 		{
1863
-			Vfs::unlock($lock_path,$token,false);
1861
+			Vfs::unlock($lock_path, $token, false);
1864 1862
 		}
1865 1863
 	}
1866 1864
 
@@ -1872,17 +1870,17 @@  discard block
 block discarded – undo
1872 1870
 	 * 		are called by new mail-app; and we intend to use the stuff passed on by session
1873 1871
 	 * @param string $msg = null
1874 1872
 	 */
1875
-	function meeting(array $event=null, $msg=null)
1873
+	function meeting(array $event = null, $msg = null)
1876 1874
 	{
1877 1875
 		$user = $GLOBALS['egw_info']['user']['account_id'];
1878 1876
 		$readonlys['button[apply]'] = true;
1879
-		$_usesession=!is_array($event);
1877
+		$_usesession = !is_array($event);
1880 1878
 		//special usage if $event is array('event'=>null,'msg'=>'','useSession'=>true) we
1881 1879
 		//are called by new mail-app; and we intend to use the stuff passed on by session
1882
-		if ($event == array('event'=>null,'msg'=>'','useSession'=>true))
1880
+		if ($event == array('event'=>null, 'msg'=>'', 'useSession'=>true))
1883 1881
 		{
1884
-			$event=null; // set to null
1885
-			$_usesession=true; // trigger session read
1882
+			$event = null; // set to null
1883
+			$_usesession = true; // trigger session read
1886 1884
 		}
1887 1885
 		if (!is_array($event))
1888 1886
 		{
@@ -1911,7 +1909,7 @@  discard block
 block discarded – undo
1911 1909
 
1912 1910
 			if (($existing_event = $this->bo->read($event['uid'])) && !$existing_event['deleted'])
1913 1911
 			{
1914
-				switch(strtolower($ical_method))
1912
+				switch (strtolower($ical_method))
1915 1913
 				{
1916 1914
 					case 'reply':
1917 1915
 						// first participant is the one replying (our iCal parser adds owner first!)
@@ -1965,19 +1963,19 @@  discard block
 block discarded – undo
1965 1963
 			}
1966 1964
 			else	// event not in calendar
1967 1965
 			{
1968
-				$readonlys['button[cancel]'] = true;	// no way to remove a canceled event not in calendar
1966
+				$readonlys['button[cancel]'] = true; // no way to remove a canceled event not in calendar
1969 1967
 			}
1970 1968
 			$event['participant_types'] = array();
1971
-			foreach($event['participants'] as $uid => $status)
1969
+			foreach ($event['participants'] as $uid => $status)
1972 1970
 			{
1973 1971
 				$user_type = $user_id = null;
1974 1972
 				calendar_so::split_user($uid, $user_type, $user_id);
1975 1973
 				$event['participants'][$uid] = $event['participant_types'][$user_type][$user_id] =
1976
-					$status && $status !== 'X' ? $status : 'U';	// X --> no status given --> U = unknown
1974
+					$status && $status !== 'X' ? $status : 'U'; // X --> no status given --> U = unknown
1977 1975
 			}
1978 1976
 			//error_log(__METHOD__."(...) parsed as ".array2string($event));
1979 1977
 			$event['recure'] = $this->bo->recure2string($event);
1980
-			$event['all_participants'] = implode(",\n",$this->bo->participants($event, true));
1978
+			$event['all_participants'] = implode(",\n", $this->bo->participants($event, true));
1981 1979
 
1982 1980
 			// ignore events in the past (for recurring events check enddate!)
1983 1981
 			if ($this->bo->date2ts($event['start']) < $this->bo->now_su &&
@@ -1997,23 +1995,23 @@  discard block
 block discarded – undo
1997 1995
 			// clear notification errors
1998 1996
 			notifications::errors(true);
1999 1997
 
2000
-			switch($button)
1998
+			switch ($button)
2001 1999
 			{
2002 2000
 				case 'reject':
2003 2001
 					if (!$event['id'])
2004 2002
 					{
2005 2003
 						// send reply to organizer
2006
-						$this->bo->send_update(MSG_REJECTED,array('e'.$event['organizer'] => 'DCHAIR'),$event);
2007
-						break;	// no need to store rejected event
2004
+						$this->bo->send_update(MSG_REJECTED, array('e'.$event['organizer'] => 'DCHAIR'), $event);
2005
+						break; // no need to store rejected event
2008 2006
 					}
2009 2007
 					// fall-through
2010 2008
 				case 'accept':
2011 2009
 				case 'tentativ':
2012
-					$status = strtoupper($button[0]);	// A, R or T
2010
+					$status = strtoupper($button[0]); // A, R or T
2013 2011
 					if (!$event['id'])
2014 2012
 					{
2015 2013
 						// if organizer is a EGroupware user, but we have no rights to organizers calendar
2016
-						if (isset($event['owner']) && !$this->bo->check_perms(Acl::ADD,0,$event['owner']))
2014
+						if (isset($event['owner']) && !$this->bo->check_perms(Acl::ADD, 0, $event['owner']))
2017 2015
 						{
2018 2016
 							// --> make organize a participant with role chair and current user the owner
2019 2017
 							$event['participant_types']['u'] = $event['participants'][$event['owner']] =
@@ -2021,7 +2019,7 @@  discard block
 block discarded – undo
2021 2019
 							$event['owner'] = $this->user;
2022 2020
 						}
2023 2021
 						// store event without notifications!
2024
-						if (($event['id'] = $this->bo->update($event, $ignore_conflicts=true, true, false, true, $msg, true)))
2022
+						if (($event['id'] = $this->bo->update($event, $ignore_conflicts = true, true, false, true, $msg, true)))
2025 2023
 						{
2026 2024
 							$msg[] = lang('Event saved');
2027 2025
 						}
@@ -2059,7 +2057,7 @@  discard block
 block discarded – undo
2059 2057
 		Framework::message(implode("\n", (array)$msg));
2060 2058
 		$readonlys['button[edit]'] = !$event['id'];
2061 2059
 		$event['ics_method'] = $readonlys['ics_method'] = strtolower($ical_method);
2062
-		switch(strtolower($ical_method))
2060
+		switch (strtolower($ical_method))
2063 2061
 		{
2064 2062
 			case 'reply':
2065 2063
 				$event['ics_method_label'] = lang('Reply to meeting request');
@@ -2083,37 +2081,37 @@  discard block
 block discarded – undo
2083 2081
 	 * @param array $conflicts array with conflicting events, the events are not garantied to be readable by the user!
2084 2082
 	 * @param array $preserv data to preserv
2085 2083
 	 */
2086
-	function conflicts($event,$conflicts,$preserv)
2084
+	function conflicts($event, $conflicts, $preserv)
2087 2085
 	{
2088 2086
 		$etpl = new Etemplate('calendar.conflicts');
2089 2087
 		$allConflicts = array();
2090 2088
 
2091
-		foreach($conflicts as $k => $conflict)
2089
+		foreach ($conflicts as $k => $conflict)
2092 2090
 		{
2093
-			$is_readable = $this->bo->check_perms(Acl::READ,$conflict);
2091
+			$is_readable = $this->bo->check_perms(Acl::READ, $conflict);
2094 2092
 
2095 2093
 			$conflicts[$k] += array(
2096 2094
 				'icon_participants' => $is_readable ? (count($conflict['participants']) > 1 ? 'users' : 'single') : 'private',
2097
-				'tooltip_participants' => $is_readable ? implode(', ',$this->bo->participants($conflict)) : '',
2098
-				'time' => $this->bo->long_date($conflict['start'],$conflict['end'],true),
2099
-				'conflicting_participants' => implode(",\n",$this->bo->participants(array(
2100
-					'participants' => array_intersect_key((array)$conflict['participants'],$event['participants']),
2101
-				),true,true)),	// show group invitations too
2095
+				'tooltip_participants' => $is_readable ? implode(', ', $this->bo->participants($conflict)) : '',
2096
+				'time' => $this->bo->long_date($conflict['start'], $conflict['end'], true),
2097
+				'conflicting_participants' => implode(",\n", $this->bo->participants(array(
2098
+					'participants' => array_intersect_key((array)$conflict['participants'], $event['participants']),
2099
+				), true, true)), // show group invitations too
2102 2100
 				'icon_recur' => $conflict['recur_type'] != MCAL_RECUR_NONE ? 'recur' : '',
2103 2101
 				'text_recur' => $conflict['recur_type'] != MCAL_RECUR_NONE ? lang('Recurring event') : ' ',
2104 2102
 			);
2105
-				$allConflicts += array_intersect_key((array)$conflict['participants'],$event['participants']);
2103
+				$allConflicts += array_intersect_key((array)$conflict['participants'], $event['participants']);
2106 2104
 			}
2107 2105
 		$content = $event + array(
2108
-			'conflicts' => array_values($conflicts),	// conflicts have id-start as key
2106
+			'conflicts' => array_values($conflicts), // conflicts have id-start as key
2109 2107
 		);
2110
-		$GLOBALS['egw_info']['flags']['app_header'] = lang('calendar') . ' - ' . lang('Scheduling conflict');
2108
+		$GLOBALS['egw_info']['flags']['app_header'] = lang('calendar').' - '.lang('Scheduling conflict');
2111 2109
 		$resources_config = Api\Config::read('resources');
2112 2110
 		$readonlys = array();
2113 2111
 
2114 2112
 		foreach (array_keys($allConflicts) as $pId)
2115 2113
 		{
2116
-			if(substr($pId,0,1) == 'r' && $resources_config ) // resources Allow ignore conflicts
2114
+			if (substr($pId, 0, 1) == 'r' && $resources_config) // resources Allow ignore conflicts
2117 2115
 			{
2118 2116
 
2119 2117
 				switch ($resources_config['ignoreconflicts'])
@@ -2133,7 +2131,7 @@  discard block
 block discarded – undo
2133 2131
 				}
2134 2132
 			}
2135 2133
 		}
2136
-		$etpl->exec('calendar.calendar_uiforms.process_edit',$content,array(),$readonlys,array_merge($event,$preserv),$preserv['no_popup'] ? 0 : 2);
2134
+		$etpl->exec('calendar.calendar_uiforms.process_edit', $content, array(), $readonlys, array_merge($event, $preserv), $preserv['no_popup'] ? 0 : 2);
2137 2135
 	}
2138 2136
 
2139 2137
 	/**
@@ -2151,7 +2149,7 @@  discard block
 block discarded – undo
2151 2149
 		//$response->addAlert(__METHOD__.'('.array2string($edit_content).')');
2152 2150
 
2153 2151
 		// convert start/end date-time values to timestamps
2154
-		foreach(array('start', 'end') as $name)
2152
+		foreach (array('start', 'end') as $name)
2155 2153
 		{
2156 2154
 			if (!empty($edit_content[$name]))
2157 2155
 			{
@@ -2181,7 +2179,7 @@  discard block
 block discarded – undo
2181 2179
 			'recur_type'   => $edit_content['recur_type'],
2182 2180
 			'participants' => array(),
2183 2181
 		);
2184
-		foreach($edit_content['participants'] as $key => $data)
2182
+		foreach ($edit_content['participants'] as $key => $data)
2185 2183
 		{
2186 2184
 			if (is_numeric($key) && !$edit_content['participants']['delete'][$data['uid']] &&
2187 2185
 				!$edit_content['participants']['delete'][md5($data['uid'])])
@@ -2196,21 +2194,21 @@  discard block
 block discarded – undo
2196 2194
 		// default search parameters
2197 2195
 		$content['start_time'] = $edit_content['whole_day'] ? 0 : $this->cal_prefs['workdaystarts'];
2198 2196
 		$content['end_time'] = $this->cal_prefs['workdayends'];
2199
-		if ($this->cal_prefs['workdayends']*HOUR_s < $this->cal_prefs['workdaystarts']*HOUR_s+$content['duration'])
2197
+		if ($this->cal_prefs['workdayends'] * HOUR_s < $this->cal_prefs['workdaystarts'] * HOUR_s + $content['duration'])
2200 2198
 		{
2201
-			$content['end_time'] = 0;	// no end-time limit, as duration would never fit
2199
+			$content['end_time'] = 0; // no end-time limit, as duration would never fit
2202 2200
 		}
2203 2201
 		$content['weekdays'] = MCAL_M_WEEKDAYS;
2204 2202
 
2205 2203
 		$content['search_window'] = 7 * DAY_s;
2206 2204
 
2207 2205
 		// store content in session
2208
-		Api\Cache::setSession('calendar','freetimesearch_args_'.(int)$edit_content['id'],$content);
2206
+		Api\Cache::setSession('calendar', 'freetimesearch_args_'.(int)$edit_content['id'], $content);
2209 2207
 
2210 2208
 		//menuaction=calendar.calendar_uiforms.freetimesearch&values2url('start,end,duration,participants,recur_type,whole_day'),ft_search,700,500
2211
-		$link = 'calendar.calendar_uiforms.freetimesearch&cal_id='. $edit_content['id'];
2209
+		$link = 'calendar.calendar_uiforms.freetimesearch&cal_id='.$edit_content['id'];
2212 2210
 
2213
-		$response->call('app.calendar.freetime_search_popup',$link);
2211
+		$response->call('app.calendar.freetime_search_popup', $link);
2214 2212
 
2215 2213
 		//$response->addScriptCall('egw_openWindowCentered2',$link,'ft_search',700,500);
2216 2214
 
@@ -2233,26 +2231,26 @@  discard block
 block discarded – undo
2233 2231
 	{
2234 2232
 		$etpl = new Etemplate('calendar.freetimesearch');
2235 2233
 		$sel_options['search_window'] = array(
2236
-			7*DAY_s		=> lang('one week'),
2237
-			14*DAY_s	=> lang('two weeks'),
2238
-			31*DAY_s	=> lang('one month'),
2239
-			92*DAY_s	=> lang('three month'),
2240
-			365*DAY_s	=> lang('one year'),
2234
+			7 * DAY_s		=> lang('one week'),
2235
+			14 * DAY_s	=> lang('two weeks'),
2236
+			31 * DAY_s	=> lang('one month'),
2237
+			92 * DAY_s	=> lang('three month'),
2238
+			365 * DAY_s	=> lang('one year'),
2241 2239
 		);
2242 2240
 		if (!is_array($content))
2243 2241
 		{
2244 2242
 			// get content from session (and delete it immediatly)
2245
-			$content = Api\Cache::getSession('calendar','freetimesearch_args_'.(int)$_GET['cal_id']);
2246
-			Api\Cache::unsetSession('calendar','freetimesearch_args_'.(int)$_GET['cal_id']);
2243
+			$content = Api\Cache::getSession('calendar', 'freetimesearch_args_'.(int)$_GET['cal_id']);
2244
+			Api\Cache::unsetSession('calendar', 'freetimesearch_args_'.(int)$_GET['cal_id']);
2247 2245
 			//Since the start_time and end_time from calendar_user_preferences are numbers, not timestamp, in order to show them on date-timeonly
2248 2246
 			//widget we need to convert them from numbers to timestamps, only for the first time when we have template without content
2249 2247
 			$sTime = $content['start_time'];
2250 2248
 			$eTime = $content['end_time'];
2251
-			$content['start_time'] = strtotime(((strlen($content['start_time'])<2)?("0".$content['start_time']):$content['start_time']).":00");
2252
-			$content['end_time'] = strtotime(((strlen($content['end_time'])<2)?("0".$content['end_time']):$content['end_time']).":00");
2249
+			$content['start_time'] = strtotime(((strlen($content['start_time']) < 2) ? ("0".$content['start_time']) : $content['start_time']).":00");
2250
+			$content['end_time'] = strtotime(((strlen($content['end_time']) < 2) ? ("0".$content['end_time']) : $content['end_time']).":00");
2253 2251
 
2254 2252
 			// pick a searchwindow fitting the duration (search for a 10 day slot in a one week window never succeeds)
2255
-			foreach(array_keys($sel_options['search_window']) as $window)
2253
+			foreach (array_keys($sel_options['search_window']) as $window)
2256 2254
 			{
2257 2255
 				if ($window > $content['duration'])
2258 2256
 				{
@@ -2279,19 +2277,19 @@  discard block
 block discarded – undo
2279 2277
 		{
2280 2278
 			$content['msg'] .= lang('Only the initial date of that recuring event is checked!');
2281 2279
 		}
2282
-		$content['freetime'] = $this->freetime($content['participants'],$content['start'],$content['start']+$content['search_window'],$content['duration'],$content['cal_id']);
2283
-		$content['freetime'] = $this->split_freetime_daywise($content['freetime'],$content['duration'],(is_array($content['weekdays'])?$weekds:$content['weekdays']),$sTime,$eTime,$sel_options);
2280
+		$content['freetime'] = $this->freetime($content['participants'], $content['start'], $content['start'] + $content['search_window'], $content['duration'], $content['cal_id']);
2281
+		$content['freetime'] = $this->split_freetime_daywise($content['freetime'], $content['duration'], (is_array($content['weekdays']) ? $weekds : $content['weekdays']), $sTime, $eTime, $sel_options);
2284 2282
 
2285
-		$GLOBALS['egw_info']['flags']['app_header'] = lang('calendar') . ' - ' . lang('freetime search');
2283
+		$GLOBALS['egw_info']['flags']['app_header'] = lang('calendar').' - '.lang('freetime search');
2286 2284
 
2287 2285
 		$sel_options['duration'] = $this->durations;
2288 2286
 		if ($content['duration'] && isset($sel_options['duration'][$content['duration']])) $content['end'] = '';
2289 2287
 
2290
-		$etpl->exec('calendar.calendar_uiforms.freetimesearch',$content,$sel_options,NULL,array(
2288
+		$etpl->exec('calendar.calendar_uiforms.freetimesearch', $content, $sel_options, NULL, array(
2291 2289
 				'participants'	=> $content['participants'],
2292 2290
 				'cal_id'		=> $content['cal_id'],
2293 2291
 				'recur_type'	=> $content['recur_type'],
2294
-			),2);
2292
+			), 2);
2295 2293
 	}
2296 2294
 
2297 2295
 	/**
@@ -2304,15 +2302,15 @@  discard block
 block discarded – undo
2304 2302
 	 * @param int $cal_id own id for existing events, to exclude them from being busy-time, default 0
2305 2303
 	 * @return array of free time-slots: array with start and end values
2306 2304
 	 */
2307
-	function freetime($participants,$start,$end,$duration=1,$cal_id=0)
2305
+	function freetime($participants, $start, $end, $duration = 1, $cal_id = 0)
2308 2306
 	{
2309
-		if ($this->debug > 2) $this->bo->debug_message(__METHOD__.'(participants=%1, start=%2, end=%3, duration=%4, cal_id=%5)',true,$participants,$start,$end,$duration,$cal_id);
2307
+		if ($this->debug > 2) $this->bo->debug_message(__METHOD__.'(participants=%1, start=%2, end=%3, duration=%4, cal_id=%5)', true, $participants, $start, $end, $duration, $cal_id);
2310 2308
 
2311 2309
 		$busy = $this->bo->search(array(
2312 2310
 			'start' => $start,
2313 2311
 			'end'	=> $end,
2314 2312
 			'users'	=> $participants,
2315
-			'ignore_acl' => true,	// otherwise we get only events readable by the user
2313
+			'ignore_acl' => true, // otherwise we get only events readable by the user
2316 2314
 		));
2317 2315
 		$busy[] = array(	// add end-of-search-date as event, to cope with empty search and get freetime til that date
2318 2316
 			'start'	=> $end,
@@ -2321,15 +2319,15 @@  discard block
 block discarded – undo
2321 2319
 		$ft_start = $start;
2322 2320
 		$freetime = array();
2323 2321
 		$n = 0;
2324
-		foreach($busy as $event)
2322
+		foreach ($busy as $event)
2325 2323
 		{
2326
-			if ((int)$cal_id && $event['id'] == (int)$cal_id) continue;	// ignore our own event
2324
+			if ((int)$cal_id && $event['id'] == (int)$cal_id) continue; // ignore our own event
2327 2325
 
2328 2326
  			if ($event['non_blocking']) continue; // ignore non_blocking events
2329 2327
 
2330 2328
 			// check if from all wanted participants at least one has a not rejected status in found event
2331 2329
 			$non_rejected_found = false;
2332
-			foreach($participants as $uid)
2330
+			foreach ($participants as $uid)
2333 2331
 			{
2334 2332
 				if ($event['participants'][$uid] == 'R') continue;
2335 2333
 
@@ -2345,10 +2343,10 @@  discard block
 block discarded – undo
2345 2343
 
2346 2344
 			if ($this->debug)
2347 2345
 			{
2348
-				echo "<p>ft_start=".date('D d.m.Y H:i',$ft_start)."<br>\n";
2346
+				echo "<p>ft_start=".date('D d.m.Y H:i', $ft_start)."<br>\n";
2349 2347
 				echo "event[title]=$event[title]<br>\n";
2350
-				echo "event[start]=".date('D d.m.Y H:i',$event['start'])."<br>\n";
2351
-				echo "event[end]=".date('D d.m.Y H:i',$event['end'])."<br>\n";
2348
+				echo "event[start]=".date('D d.m.Y H:i', $event['start'])."<br>\n";
2349
+				echo "event[end]=".date('D d.m.Y H:i', $event['end'])."<br>\n";
2352 2350
 			}
2353 2351
 			// $events ends before our actual position ==> ignore it
2354 2352
 			if ($event['end'] < $ft_start)
@@ -2372,11 +2370,11 @@  discard block
 block discarded – undo
2372 2370
 					'start'	=> $ft_start,
2373 2371
 					'end'	=> $ft_end,
2374 2372
 				);
2375
-				if ($this->debug > 1) echo "<p>freetime: ".date('D d.m.Y H:i',$ft_start)." - ".date('D d.m.Y H:i',$ft_end)."</p>\n";
2373
+				if ($this->debug > 1) echo "<p>freetime: ".date('D d.m.Y H:i', $ft_start)." - ".date('D d.m.Y H:i', $ft_end)."</p>\n";
2376 2374
 			}
2377 2375
 			$ft_start = $event['end'];
2378 2376
 		}
2379
-		if ($this->debug > 0) $this->bo->debug_message('uiforms::freetime(participants=%1, start=%2, end=%3, duration=%4, cal_id=%5) freetime=%6',true,$participants,$start,$end,$duration,$cal_id,$freetime);
2377
+		if ($this->debug > 0) $this->bo->debug_message('uiforms::freetime(participants=%1, start=%2, end=%3, duration=%4, cal_id=%5) freetime=%6', true, $participants, $start, $end, $duration, $cal_id, $freetime);
2380 2378
 
2381 2379
 		return $freetime;
2382 2380
 	}
@@ -2396,46 +2394,46 @@  discard block
 block discarded – undo
2396 2394
 	 */
2397 2395
 	function split_freetime_daywise($freetime, $duration, $weekdays, $_start_time, $_end_time, &$sel_options)
2398 2396
 	{
2399
-		if ($this->debug > 1) $this->bo->debug_message('uiforms::split_freetime_daywise(freetime=%1, duration=%2, start_time=%3, end_time=%4)',true,$freetime,$duration,$_start_time,$_end_time);
2397
+		if ($this->debug > 1) $this->bo->debug_message('uiforms::split_freetime_daywise(freetime=%1, duration=%2, start_time=%3, end_time=%4)', true, $freetime, $duration, $_start_time, $_end_time);
2400 2398
 
2401 2399
 		$freetime_daywise = array();
2402 2400
 		if (!is_array($sel_options)) $sel_options = array();
2403 2401
 		$time_format = $this->common_prefs['timeformat'] == 12 ? 'h:i a' : 'H:i';
2404 2402
 
2405
-		$start_time = (int) $_start_time;	// ignore leading zeros
2406
-		$end_time   = (int) $_end_time;
2403
+		$start_time = (int)$_start_time; // ignore leading zeros
2404
+		$end_time   = (int)$_end_time;
2407 2405
 
2408 2406
 		// ignore the end_time, if duration would never fit
2409
-		if (($end_time - $start_time)*HOUR_s < $duration)
2407
+		if (($end_time - $start_time) * HOUR_s < $duration)
2410 2408
 		{
2411 2409
 			$end_time = 0;
2412
-			if ($this->debug > 1) $this->bo->debug_message('uiforms::split_freetime_daywise(, duration=%2, start_time=%3,..) end_time set to 0, it never fits durationn otherwise',true,$duration,$start_time);
2410
+			if ($this->debug > 1) $this->bo->debug_message('uiforms::split_freetime_daywise(, duration=%2, start_time=%3,..) end_time set to 0, it never fits durationn otherwise', true, $duration, $start_time);
2413 2411
 		}
2414 2412
 		$n = 0;
2415
-		foreach($freetime as $ft)
2413
+		foreach ($freetime as $ft)
2416 2414
 		{
2417 2415
 			$adaybegin = $this->bo->date2array($ft['start']);
2418 2416
 			$adaybegin['hour'] = $adaybegin['minute'] = $adaybegin['second'] = 0;
2419 2417
 			unset($adaybegin['raw']);
2420 2418
 			$daybegin = $this->bo->date2ts($adaybegin);
2421 2419
 
2422
-			for($t = $daybegin; $t < $ft['end']; $t += DAY_s,$daybegin += DAY_s)
2420
+			for ($t = $daybegin; $t < $ft['end']; $t += DAY_s, $daybegin += DAY_s)
2423 2421
 			{
2424
-				$dow = date('w',$daybegin+DAY_s/2);	// 0=Sun, .., 6=Sat
2425
-				$mcal_dow = pow(2,$dow);
2426
-				if (!($weekdays & $mcal_dow))
2422
+				$dow = date('w', $daybegin + DAY_s / 2); // 0=Sun, .., 6=Sat
2423
+				$mcal_dow = pow(2, $dow);
2424
+				if (!($weekdays&$mcal_dow))
2427 2425
 				{
2428 2426
 					//echo "wrong day of week $dow<br>\n";
2429
-					continue;	// wrong day of week
2427
+					continue; // wrong day of week
2430 2428
 				}
2431 2429
 				$start = $t < $ft['start'] ? $ft['start'] : $t;
2432 2430
 
2433
-				if ($start-$daybegin < $start_time*HOUR_s)	// start earlier then start_time
2431
+				if ($start - $daybegin < $start_time * HOUR_s)	// start earlier then start_time
2434 2432
 				{
2435
-					$start = $daybegin + $start_time*HOUR_s;
2433
+					$start = $daybegin + $start_time * HOUR_s;
2436 2434
 				}
2437 2435
 				// if end_time given use it, else the original slot's end
2438
-				$end = $end_time ? $daybegin + $end_time*HOUR_s : $ft['end'];
2436
+				$end = $end_time ? $daybegin + $end_time * HOUR_s : $ft['end'];
2439 2437
 				if ($end > $ft['end']) $end = $ft['end'];
2440 2438
 
2441 2439
 				// slot to small for duration
@@ -2449,11 +2447,11 @@  discard block
 block discarded – undo
2449 2447
 					'end'	=> $end,
2450 2448
 				);
2451 2449
 				$times = array();
2452
-				for ($s = $start; $s+$duration <= $end && $s < $daybegin+DAY_s; $s += 60*$this->cal_prefs['interval'])
2450
+				for ($s = $start; $s + $duration <= $end && $s < $daybegin + DAY_s; $s += 60 * $this->cal_prefs['interval'])
2453 2451
 				{
2454 2452
 					$e = $s + $duration;
2455
-					$end_date = $e-$daybegin > DAY_s ? lang(date('l',$e)).' '.date($this->common_prefs['dateformat'],$e).' ' : '';
2456
-					$times[$s] = date($time_format,$s).' - '.$end_date.date($time_format,$e);
2453
+					$end_date = $e - $daybegin > DAY_s ? lang(date('l', $e)).' '.date($this->common_prefs['dateformat'], $e).' ' : '';
2454
+					$times[$s] = date($time_format, $s).' - '.$end_date.date($time_format, $e);
2457 2455
 				}
2458 2456
 				$sel_options[$n.'start'] = $times;
2459 2457
 			}
@@ -2468,13 +2466,13 @@  discard block
 block discarded – undo
2468 2466
      * @param boolean $return_error should an error-msg be returned or a regular page with it generated (default)
2469 2467
      * @return string error-msg if $return_error
2470 2468
      */
2471
-    function export($content=0,$return_error=false)
2469
+    function export($content = 0, $return_error = false)
2472 2470
     {
2473 2471
 		$boical = new calendar_ical();
2474 2472
 		#error_log(__METHOD__.print_r($content,true));
2475 2473
 		if (is_numeric($cal_id = $content ? $content : $_REQUEST['cal_id']))
2476 2474
 		{
2477
-			if (!($ical =& $boical->exportVCal(array($cal_id),'2.0','PUBLISH',false)))
2475
+			if (!($ical = & $boical->exportVCal(array($cal_id), '2.0', 'PUBLISH', false)))
2478 2476
 			{
2479 2477
 				$msg = lang('Permission denied');
2480 2478
 
@@ -2482,20 +2480,20 @@  discard block
 block discarded – undo
2482 2480
 			}
2483 2481
 			else
2484 2482
 			{
2485
-				html::content_header('event.ics','text/calendar',bytes($ical));
2483
+				html::content_header('event.ics', 'text/calendar', bytes($ical));
2486 2484
 				echo $ical;
2487 2485
 				common::egw_exit();
2488 2486
 			}
2489 2487
 		}
2490 2488
 		if (is_array($content))
2491 2489
 		{
2492
-			$events =& $this->bo->search(array(
2490
+			$events = & $this->bo->search(array(
2493 2491
 				'start' => $content['start'],
2494 2492
 				'end'   => $content['end'],
2495 2493
 				'enum_recuring' => false,
2496 2494
 				'daywise'       => false,
2497 2495
 				'owner'         => $this->owner,
2498
-				'date_format'   => 'server',    // timestamp in server time for boical class
2496
+				'date_format'   => 'server', // timestamp in server time for boical class
2499 2497
 			));
2500 2498
 			if (!$events)
2501 2499
 			{
@@ -2503,8 +2501,8 @@  discard block
 block discarded – undo
2503 2501
 			}
2504 2502
 			else
2505 2503
 			{
2506
-				$ical =& $boical->exportVCal($events,'2.0','PUBLISH',false);
2507
-				html::content_header($content['file'] ? $content['file'] : 'event.ics','text/calendar',bytes($ical));
2504
+				$ical = & $boical->exportVCal($events, '2.0', 'PUBLISH', false);
2505
+				html::content_header($content['file'] ? $content['file'] : 'event.ics', 'text/calendar', bytes($ical));
2508 2506
 				echo $ical;
2509 2507
 				common::egw_exit();
2510 2508
 			}
@@ -2520,9 +2518,9 @@  discard block
 block discarded – undo
2520 2518
 		}
2521 2519
 		$content['msg'] = $msg;
2522 2520
 
2523
-		$GLOBALS['egw_info']['flags']['app_header'] = lang('calendar') . ' - ' . lang('iCal Export');
2521
+		$GLOBALS['egw_info']['flags']['app_header'] = lang('calendar').' - '.lang('iCal Export');
2524 2522
 		$etpl = new etemplate_new('calendar.export');
2525
-		$etpl->exec('calendar.calendar_uiforms.export',$content);
2523
+		$etpl->exec('calendar.calendar_uiforms.export', $content);
2526 2524
     }
2527 2525
 
2528 2526
 	/**
@@ -2530,7 +2528,7 @@  discard block
 block discarded – undo
2530 2528
 	 *
2531 2529
 	 * @param array $_content
2532 2530
 	 */
2533
-	function cat_acl(array $_content=null)
2531
+	function cat_acl(array $_content = null)
2534 2532
 	{
2535 2533
 		if (!$GLOBALS['egw_info']['user']['apps']['admin'])
2536 2534
 		{
@@ -2542,15 +2540,15 @@  discard block
 block discarded – undo
2542 2540
 			unset($_content['button']);
2543 2541
 			if ($button != 'cancel')	// store changed Acl
2544 2542
 			{
2545
-				foreach($_content as $data)
2543
+				foreach ($_content as $data)
2546 2544
 				{
2547 2545
 					if (!($cat_id = $data['cat_id'])) continue;
2548
-					foreach(array_merge((array)$data['add'],(array)$data['status'],array_keys((array)$data['old'])) as $account_id)
2546
+					foreach (array_merge((array)$data['add'], (array)$data['status'], array_keys((array)$data['old'])) as $account_id)
2549 2547
 					{
2550 2548
 						$rights = 0;
2551
-						if (in_array($account_id,(array)$data['add'])) $rights |= calendar_boupdate::CAT_ACL_ADD;
2552
-						if (in_array($account_id,(array)$data['status'])) $rights |= calendar_boupdate::CAT_ACL_STATUS;
2553
-						if ($account_id) $this->bo->set_cat_rights($cat_id,$account_id,$rights);
2549
+						if (in_array($account_id, (array)$data['add'])) $rights |= calendar_boupdate::CAT_ACL_ADD;
2550
+						if (in_array($account_id, (array)$data['status'])) $rights |= calendar_boupdate::CAT_ACL_STATUS;
2551
+						if ($account_id) $this->bo->set_cat_rights($cat_id, $account_id, $rights);
2554 2552
 					}
2555 2553
 				}
2556 2554
 			}
@@ -2562,20 +2560,20 @@  discard block
 block discarded – undo
2562 2560
 				), 'admin');
2563 2561
 			}
2564 2562
 		}
2565
-		$content= $preserv = array();
2563
+		$content = $preserv = array();
2566 2564
 		$n = 1;
2567
-		foreach($this->bo->get_cat_rights() as $Lcat_id => $data)
2565
+		foreach ($this->bo->get_cat_rights() as $Lcat_id => $data)
2568 2566
 		{
2569
-			$cat_id = substr($Lcat_id,1);
2567
+			$cat_id = substr($Lcat_id, 1);
2570 2568
 			$row = array(
2571 2569
 				'cat_id' => $cat_id,
2572 2570
 				'add' => array(),
2573 2571
 				'status' => array(),
2574 2572
 			);
2575
-			foreach($data as $account_id => $rights)
2573
+			foreach ($data as $account_id => $rights)
2576 2574
 			{
2577
-				if ($rights & calendar_boupdate::CAT_ACL_ADD) $row['add'][] = $account_id;
2578
-				if ($rights & calendar_boupdate::CAT_ACL_STATUS) $row['status'][] = $account_id;
2575
+				if ($rights&calendar_boupdate::CAT_ACL_ADD) $row['add'][] = $account_id;
2576
+				if ($rights&calendar_boupdate::CAT_ACL_STATUS) $row['status'][] = $account_id;
2579 2577
 			}
2580 2578
 			$content[$n] = $row;
2581 2579
 			$preserv[$n] = array(
@@ -2591,7 +2589,7 @@  discard block
 block discarded – undo
2591 2589
 		$GLOBALS['egw_info']['flags']['app_header'] = lang('Calendar').' - '.lang('Category ACL');
2592 2590
 		$tmp = new Etemplate('calendar.cat_acl');
2593 2591
 		$GLOBALS['egw_info']['flags']['nonavbar'] = 1;
2594
-		$tmp->exec('calendar.calendar_uiforms.cat_acl',$content,null,$readonlys,$preserv);
2592
+		$tmp->exec('calendar.calendar_uiforms.cat_acl', $content, null, $readonlys, $preserv);
2595 2593
 	}
2596 2594
 
2597 2595
 	/**
@@ -2641,18 +2639,18 @@  discard block
 block discarded – undo
2641 2639
 
2642 2640
 
2643 2641
 		// Get participants for only this one, if it's recurring.  The date is on the end of the value.
2644
-		if($content['recur_type'] || $content['recurrence'])
2642
+		if ($content['recur_type'] || $content['recurrence'])
2645 2643
 		{
2646 2644
 			$content['history']['filter'] = array(
2647 2645
 				'(history_status NOT LIKE \'participants%\' OR (history_status LIKE \'participants%\' AND (
2648
-					history_new_value LIKE \'%' . Api\Storage\Tracking::ONE2N_SEPERATOR . $content['recurrence'] . '\' OR
2649
-					history_old_value LIKE \'%' . Api\Storage\Tracking::ONE2N_SEPERATOR . $content['recurrence'] . '\')))'
2646
+					history_new_value LIKE \'%' . Api\Storage\Tracking::ONE2N_SEPERATOR.$content['recurrence'].'\' OR
2647
+					history_old_value LIKE \'%' . Api\Storage\Tracking::ONE2N_SEPERATOR.$content['recurrence'].'\')))'
2650 2648
 			);
2651 2649
 		}
2652 2650
 
2653 2651
 		// Translate labels
2654 2652
 		$tracking = new calendar_tracking();
2655
-		foreach($tracking->field2label as $field => $label)
2653
+		foreach ($tracking->field2label as $field => $label)
2656 2654
 		{
2657 2655
 			$sel_options[$status][$field] = lang($label);
2658 2656
 		}
@@ -2671,44 +2669,44 @@  discard block
 block discarded – undo
2671 2669
 	 *	which particular instance was dragged
2672 2670
 	 * @return string XML response if no error occurs
2673 2671
 	 */
2674
-	function ajax_moveEvent($_eventId,$calendarOwner,$targetDateTime,$targetOwner,$durationT=null,$seriesInstance=null)
2672
+	function ajax_moveEvent($_eventId, $calendarOwner, $targetDateTime, $targetOwner, $durationT = null, $seriesInstance = null)
2675 2673
 	{
2676
-		list($eventId, $date) = explode(':', $_eventId,2);
2674
+		list($eventId, $date) = explode(':', $_eventId, 2);
2677 2675
 		$ignore_conflicts = false;
2678 2676
 
2679 2677
 		// we do not allow dragging into another users calendar ATM
2680
-		if($targetOwner < 0)
2678
+		if ($targetOwner < 0)
2681 2679
 		{
2682 2680
 			$targetOwner = array($targetOwner);
2683 2681
 		}
2684
-		if($targetOwner == 0 || is_array($targetOwner) && $targetOwner[0] == 0)
2682
+		if ($targetOwner == 0 || is_array($targetOwner) && $targetOwner[0] == 0)
2685 2683
 		{
2686 2684
 			$targetOwner = $calendarOwner;
2687 2685
 		}
2688 2686
 		// But you may be viewing multiple users, or a group calendar and
2689 2687
 		// dragging your event - dragging across calendars does not change owner
2690
-		if(is_array($targetOwner) && !in_array($calendarOwner, $targetOwner))
2688
+		if (is_array($targetOwner) && !in_array($calendarOwner, $targetOwner))
2691 2689
 		{
2692 2690
 			$return = true;
2693
-			foreach($targetOwner as $owner)
2691
+			foreach ($targetOwner as $owner)
2694 2692
 			{
2695
-				if($owner < 0 && in_array($calendarOwner, $GLOBALS['egw']->accounts->members($owner,true)))
2693
+				if ($owner < 0 && in_array($calendarOwner, $GLOBALS['egw']->accounts->members($owner, true)))
2696 2694
 				{
2697 2695
 					$return = false;
2698 2696
 					break;
2699 2697
 				}
2700
-				else if ($owner > 0 && $this->bo->check_perms(Acl::EDIT, $eventId,0,'ts',$date))
2698
+				else if ($owner > 0 && $this->bo->check_perms(Acl::EDIT, $eventId, 0, 'ts', $date))
2701 2699
 				{
2702 2700
 					$return = false;
2703 2701
 					break;
2704 2702
 				}
2705 2703
 			}
2706
-			if($return) return;
2704
+			if ($return) return;
2707 2705
 		}
2708
-		$old_event=$event=$this->bo->read($eventId);
2706
+		$old_event = $event = $this->bo->read($eventId);
2709 2707
 		if (!$durationT)
2710 2708
 		{
2711
-			$duration=$event['end']-$event['start'];
2709
+			$duration = $event['end'] - $event['start'];
2712 2710
 		}
2713 2711
 		// Drag a normal event to whole day non-blocking
2714 2712
 		else if ($durationT == 'whole_day')
@@ -2716,7 +2714,7 @@  discard block
 block discarded – undo
2716 2714
 			$event['whole_day'] = true;
2717 2715
 			$event['non_blocking'] = true;
2718 2716
 			// Make duration whole days, less 1 second
2719
-			$duration = round(($event['end']-$event['start'])/DAY_s) * DAY_s - 1;
2717
+			$duration = round(($event['end'] - $event['start']) / DAY_s) * DAY_s - 1;
2720 2718
 		}
2721 2719
 		else
2722 2720
 		{
@@ -2729,18 +2727,18 @@  discard block
 block discarded – undo
2729 2727
 			$d = new Api\DateTime($date, Api\DateTime::$user_timezone);
2730 2728
 			if (!empty($event['whole_day']))
2731 2729
 			{
2732
-				$d =& $this->bo->so->startOfDay($d);
2730
+				$d = & $this->bo->so->startOfDay($d);
2733 2731
 				$d->setUser();
2734 2732
 			}
2735 2733
 			$event = $this->bo->read($eventId, $d, true);
2736 2734
 
2737 2735
 			// For DnD, create an exception if they gave the date
2738 2736
 			$preserv = null;
2739
-			$this->_create_exception($event,$preserv);
2737
+			$this->_create_exception($event, $preserv);
2740 2738
 			unset($event['id']);
2741 2739
 
2742 2740
 			$messages = null;
2743
-			$conflicts = $this->bo->update($event,false,true,false,true,$messages);
2741
+			$conflicts = $this->bo->update($event, false, true, false, true, $messages);
2744 2742
 			if (!is_array($conflicts) && $conflicts)
2745 2743
 			{
2746 2744
 				// now we need to add the original start as recur-execption to the series
@@ -2748,28 +2746,28 @@  discard block
 block discarded – undo
2748 2746
 				$recur_event['recur_exception'][] = $d->format('ts');
2749 2747
 				// check if we need to move the alarms, because they are next on that exception
2750 2748
 				$this->bo->check_move_alarms($recur_event, null, $d);
2751
-				unset($recur_event['start']); unset($recur_event['end']);	// no update necessary
2752
-				unset($recur_event['alarm']);	// unsetting alarms too, as they cant be updated without start!
2753
-				$this->bo->update($recur_event,true);	// no conflict check here
2749
+				unset($recur_event['start']); unset($recur_event['end']); // no update necessary
2750
+				unset($recur_event['alarm']); // unsetting alarms too, as they cant be updated without start!
2751
+				$this->bo->update($recur_event, true); // no conflict check here
2754 2752
 
2755 2753
 				// Sending null will trigger a removal of the original for that date
2756 2754
 				Api\Json\Response::get()->generic('data', array('uid' => 'calendar::'.$_eventId, 'data' => null));
2757 2755
 
2758 2756
 				unset($recur_event);
2759
-				unset($event['edit_single']);			// if we further edit it, it's just a single event
2757
+				unset($event['edit_single']); // if we further edit it, it's just a single event
2760 2758
 				unset($preserv['edit_single']);
2761 2759
 			}
2762 2760
 		}
2763 2761
 
2764 2762
 		$d = new Api\DateTime($targetDateTime, Api\DateTime::$user_timezone);
2765 2763
 		$event['start'] = $d->format('ts');
2766
-		$event['end'] = $event['start']+$duration;
2764
+		$event['end'] = $event['start'] + $duration;
2767 2765
 
2768 2766
 		if ($event['recur_type'] != MCAL_RECUR_NONE && !$date && $seriesInstance)
2769 2767
 		{
2770 2768
 			// calculate offset against clicked recurrance,
2771 2769
 			// depending on which is smaller
2772
-			$offset = Api\DateTime::to($targetDateTime,'ts') - Api\DateTime::to($seriesInstance,'ts');
2770
+			$offset = Api\DateTime::to($targetDateTime, 'ts') - Api\DateTime::to($seriesInstance, 'ts');
2773 2771
 			$event['start'] = $old_event['start'] + $offset;
2774 2772
 			$event['duration'] = $duration;
2775 2773
 
@@ -2780,31 +2778,31 @@  discard block
 block discarded – undo
2780 2778
 			// Can't handle conflict.  Just ignore it.
2781 2779
 			$ignore_conflicts = true;
2782 2780
 		}
2783
-		if(!$event['recur_type'])
2781
+		if (!$event['recur_type'])
2784 2782
 		{
2785 2783
 			$this->bo->check_move_alarms($event, $old_event);
2786 2784
 		}
2787 2785
 
2788 2786
 		// Drag a whole day to a time
2789
-		if($durationT && $durationT != 'whole_day')
2787
+		if ($durationT && $durationT != 'whole_day')
2790 2788
 		{
2791 2789
 			$event['whole_day'] = ($duration == DAY_s);
2792 2790
 			$event['non_blocking'] = false;
2793 2791
 			// If there's a conflict, it won't save the change and the conflict popup will be blank
2794 2792
 			// so save the change now, and then let the conflict check happen.
2795 2793
 			$message = null;
2796
-			$this->bo->update($event,true, true, false, true, $message,true);
2794
+			$this->bo->update($event, true, true, false, true, $message, true);
2797 2795
 
2798 2796
 			// Whole day non blocking with DAY_s would add a day
2799
-			if($duration==DAY_s) $duration=0;
2797
+			if ($duration == DAY_s) $duration = 0;
2800 2798
 		}
2801 2799
 
2802 2800
 		$status_reset_to_unknown = false;
2803 2801
 		$sameday = (date('Ymd', $old_event['start']) == date('Ymd', $event['start']));
2804
-		foreach((array)$event['participants'] as $uid => $status)
2802
+		foreach ((array)$event['participants'] as $uid => $status)
2805 2803
 		{
2806 2804
 			$q = $r = null;
2807
-			calendar_so::split_status($status,$q,$r);
2805
+			calendar_so::split_status($status, $q, $r);
2808 2806
 			if ($uid[0] != 'c' && $uid[0] != 'e' && $uid != $this->bo->user && $status != 'U')
2809 2807
 			{
2810 2808
 				$preferences = new Api\Preferences($uid);
@@ -2817,23 +2815,23 @@  discard block
 block discarded – undo
2817 2815
 						if ($sameday) break;
2818 2816
 					default:
2819 2817
 						$status_reset_to_unknown = true;
2820
-						$event['participants'][$uid] = calendar_so::combine_status('U',$q,$r);
2818
+						$event['participants'][$uid] = calendar_so::combine_status('U', $q, $r);
2821 2819
 						// todo: report reset status to user
2822 2820
 				}
2823 2821
 			}
2824 2822
 		}
2825 2823
 
2826 2824
 		$message = false;
2827
-		$conflicts=$this->bo->update($event,$ignore_conflicts, true, false, true, $message);
2825
+		$conflicts = $this->bo->update($event, $ignore_conflicts, true, false, true, $message);
2828 2826
 
2829
-		$this->update_client($event['id'],$d);
2827
+		$this->update_client($event['id'], $d);
2830 2828
 		$response = Api\Json\Response::get();
2831
-		if(!is_array($conflicts) && $conflicts)
2829
+		if (!is_array($conflicts) && $conflicts)
2832 2830
 		{
2833
-			if(is_int($conflicts))
2831
+			if (is_int($conflicts))
2834 2832
 			{
2835 2833
 				$event['id'] = $conflicts;
2836
-				$response->call('egw.refresh', '','calendar',$event['id'],'edit');
2834
+				$response->call('egw.refresh', '', 'calendar', $event['id'], 'edit');
2837 2835
 			}
2838 2836
 		}
2839 2837
 		else if ($conflicts)
@@ -2846,21 +2844,21 @@  discard block
 block discarded – undo
2846 2844
 					.'&end='.$event['end']
2847 2845
 					.'&non_interactive=true'
2848 2846
 					.'&cancel_needs_refresh=true',
2849
-				'',750,410);
2847
+				'', 750, 410);
2850 2848
 		}
2851 2849
 		else if ($message)
2852 2850
 		{
2853
-			$response->call('egw.message',  implode('<br />', $message));
2851
+			$response->call('egw.message', implode('<br />', $message));
2854 2852
 		}
2855
-		if($event['id'] != $eventId ) $this->update_client($_eventId);
2853
+		if ($event['id'] != $eventId) $this->update_client($_eventId);
2856 2854
 		if ($status_reset_to_unknown)
2857 2855
 		{
2858
-			foreach((array)$event['participants'] as $uid => $status)
2856
+			foreach ((array)$event['participants'] as $uid => $status)
2859 2857
 			{
2860 2858
 				if ($uid[0] != 'c' && $uid[0] != 'e' && $uid != $this->bo->user)
2861 2859
 				{
2862
-					calendar_so::split_status($status,$q,$r);
2863
-					$status = calendar_so::combine_status('U',$q,$r);
2860
+					calendar_so::split_status($status, $q, $r);
2861
+					$status = calendar_so::combine_status('U', $q, $r);
2864 2862
 					$this->bo->set_status($event['id'], $uid, $status, 0, true);
2865 2863
 				}
2866 2864
 			}
@@ -2877,7 +2875,7 @@  discard block
 block discarded – undo
2877 2875
 	{
2878 2876
 		list($eventId, $date) = explode(':', $_eventId);
2879 2877
 		$event = $this->bo->read($eventId);
2880
-		if($date)
2878
+		if ($date)
2881 2879
 		{
2882 2880
 			$d = new Api\DateTime($date, Api\DateTime::$user_timezone);
2883 2881
 		}
@@ -2887,29 +2885,29 @@  discard block
 block discarded – undo
2887 2885
 		{
2888 2886
 			if (!empty($event['whole_day']))
2889 2887
 			{
2890
-				$d =& $this->bo->so->startOfDay($date);
2888
+				$d = & $this->bo->so->startOfDay($date);
2891 2889
 				$d->setUser();
2892 2890
 			}
2893 2891
 			$event = $this->bo->read($eventId, $d, true);
2894 2892
 			$date = $d->format('ts');
2895 2893
 		}
2896
-		if($event['participants'][$uid])
2894
+		if ($event['participants'][$uid])
2897 2895
 		{
2898 2896
 			$q = $r = null;
2899
-			calendar_so::split_status($event['participants'][$uid],$q,$r);
2900
-			$event['participants'][$uid] = $status = calendar_so::combine_status($status,$q,$r);
2901
-			$this->bo->set_status($event['id'],$uid,$status,$date,true);
2897
+			calendar_so::split_status($event['participants'][$uid], $q, $r);
2898
+			$event['participants'][$uid] = $status = calendar_so::combine_status($status, $q, $r);
2899
+			$this->bo->set_status($event['id'], $uid, $status, $date, true);
2902 2900
 		}
2903 2901
 		else
2904 2902
 		{
2905 2903
 			// Group membership
2906
-			foreach($event['participants'] as $id => $status)
2904
+			foreach ($event['participants'] as $id => $status)
2907 2905
 			{
2908
-				if($GLOBALS['egw']->accounts->get_type($id) == 'g' && in_array($uid,$GLOBALS['egw']->accounts->members($id,true)))
2906
+				if ($GLOBALS['egw']->accounts->get_type($id) == 'g' && in_array($uid, $GLOBALS['egw']->accounts->members($id, true)))
2909 2907
 				{
2910
-					calendar_so::split_status($event['participants'][$uid],$q,$r);
2911
-					$event['participants'][$uid] = $status = calendar_so::combine_status($status,$q,$r);
2912
-					$this->bo->set_status($event['id'],$uid,$status,$date,true);
2908
+					calendar_so::split_status($event['participants'][$uid], $q, $r);
2909
+					$event['participants'][$uid] = $status = calendar_so::combine_status($status, $q, $r);
2910
+					$this->bo->set_status($event['id'], $uid, $status, $date, true);
2913 2911
 					break;
2914 2912
 				}
2915 2913
 			}
@@ -2917,7 +2915,7 @@  discard block
 block discarded – undo
2917 2915
 
2918 2916
 		// Directly update stored data.  If event is still visible, it will
2919 2917
 		// be notified & update itself.
2920
-		$this->update_client($eventId,$d);
2918
+		$this->update_client($eventId, $d);
2921 2919
 	}
2922 2920
 
2923 2921
 	/**
@@ -2925,8 +2923,8 @@  discard block
 block discarded – undo
2925 2923
 	 */
2926 2924
 	public function ajax_delete($eventId)
2927 2925
 	{
2928
-		list($id, $date) = explode(':',$eventId);
2929
-		$event=$this->bo->read($id);
2926
+		list($id, $date) = explode(':', $eventId);
2927
+		$event = $this->bo->read($id);
2930 2928
 		$response = Api\Json\Response::get();
2931 2929
 
2932 2930
 		if ($this->bo->delete($event['id'], (int)$date))
@@ -2939,11 +2937,11 @@  discard block
 block discarded – undo
2939 2937
 			{
2940 2938
 				$msg = lang('Event deleted');
2941 2939
 			}
2942
-			$response->apply('egw.refresh', Array($msg,'calendar',$eventId,'delete'));
2940
+			$response->apply('egw.refresh', Array($msg, 'calendar', $eventId, 'delete'));
2943 2941
 		}
2944 2942
 		else
2945 2943
 		{
2946
-			$response->apply('egw.message', Array(lang('Error')),'error');
2944
+			$response->apply('egw.message', Array(lang('Error')), 'error');
2947 2945
 		}
2948 2946
 	}
2949 2947
 
@@ -2956,10 +2954,10 @@  discard block
 block discarded – undo
2956 2954
 	 */
2957 2955
 	public function ajax_invite($_eventId, $invite = array(), $remove = array())
2958 2956
 	{
2959
-		list($eventId, $date) = explode(':', $_eventId,2);
2957
+		list($eventId, $date) = explode(':', $_eventId, 2);
2960 2958
 
2961 2959
 		$event = $this->bo->read($eventId);
2962
-		if($date)
2960
+		if ($date)
2963 2961
 		{
2964 2962
 			$d = new Api\DateTime($date, Api\DateTime::$user_timezone);
2965 2963
 		}
@@ -2969,17 +2967,17 @@  discard block
 block discarded – undo
2969 2967
 		{
2970 2968
 			if (!empty($event['whole_day']))
2971 2969
 			{
2972
-				$d =& $this->bo->so->startOfDay($date);
2970
+				$d = & $this->bo->so->startOfDay($date);
2973 2971
 				$d->setUser();
2974 2972
 			}
2975 2973
 			$event = $this->bo->read($eventId, $d, true);
2976 2974
 			// For DnD, create an exception if they gave the date
2977 2975
 			$preserv = null;
2978
-			$this->_create_exception($event,$preserv);
2976
+			$this->_create_exception($event, $preserv);
2979 2977
 			unset($event['id']);
2980 2978
 
2981 2979
 			$messages = null;
2982
-			$conflicts = $this->bo->update($event,true,true,false,true,$messages);
2980
+			$conflicts = $this->bo->update($event, true, true, false, true, $messages);
2983 2981
 			if (!is_array($conflicts) && $conflicts)
2984 2982
 			{
2985 2983
 				// now we need to add the original start as recur-execption to the series
@@ -2987,28 +2985,28 @@  discard block
 block discarded – undo
2987 2985
 				$recur_event['recur_exception'][] = $d->format('ts');
2988 2986
 				// check if we need to move the alarms, because they are next on that exception
2989 2987
 				$this->bo->check_move_alarms($recur_event, null, $d);
2990
-				unset($recur_event['start']); unset($recur_event['end']);	// no update necessary
2991
-				unset($recur_event['alarm']);	// unsetting alarms too, as they cant be updated without start!
2992
-				$this->bo->update($recur_event,true);	// no conflict check here
2988
+				unset($recur_event['start']); unset($recur_event['end']); // no update necessary
2989
+				unset($recur_event['alarm']); // unsetting alarms too, as they cant be updated without start!
2990
+				$this->bo->update($recur_event, true); // no conflict check here
2993 2991
 
2994 2992
 				// Sending null will trigger a removal of the original for that date
2995 2993
 				Api\Json\Response::get()->generic('data', array('uid' => 'calendar::'.$_eventId, 'data' => null));
2996 2994
 
2997 2995
 				unset($recur_event);
2998
-				unset($event['edit_single']);			// if we further edit it, it's just a single event
2996
+				unset($event['edit_single']); // if we further edit it, it's just a single event
2999 2997
 				unset($preserv['edit_single']);
3000 2998
 			}
3001 2999
 		}
3002
-		foreach($remove as $participant)
3000
+		foreach ($remove as $participant)
3003 3001
 		{
3004 3002
 			unset($event['participants'][$participant]);
3005 3003
 		}
3006
-		foreach($invite as $participant)
3004
+		foreach ($invite as $participant)
3007 3005
 		{
3008 3006
 			$event['participants'][$participant] = 'U';
3009 3007
 		}
3010 3008
 		$message = null;
3011
-		$conflicts=$this->bo->update($event,false, true, false, true, $message);
3009
+		$conflicts = $this->bo->update($event, false, true, false, true, $message);
3012 3010
 
3013 3011
 		$response = Api\Json\Response::get();
3014 3012
 
@@ -3016,8 +3014,8 @@  discard block
 block discarded – undo
3016 3014
 		{
3017 3015
 			// Save it anyway, was done with explicit user interaction,
3018 3016
 			// and if we don't we lose the invite
3019
-			$this->bo->update($event,true);	// no conflict check here
3020
-			$this->update_client($event['id'],$d);
3017
+			$this->bo->update($event, true); // no conflict check here
3018
+			$this->update_client($event['id'], $d);
3021 3019
 			$response->call(
3022 3020
 				'egw_openWindowCentered2',
3023 3021
 				$GLOBALS['egw_info']['server']['webserver_url'].'/index.php?menuaction=calendar.calendar_uiforms.edit
@@ -3026,22 +3024,22 @@  discard block
 block discarded – undo
3026 3024
 					.'&end='.$event['end']
3027 3025
 					.'&non_interactive=true'
3028 3026
 					.'&cancel_needs_refresh=true',
3029
-				'',750,410);
3027
+				'', 750, 410);
3030 3028
 		}
3031 3029
 		else if ($message)
3032 3030
 		{
3033
-			$response->call('egw.message',  implode('<br />', $message));
3031
+			$response->call('egw.message', implode('<br />', $message));
3034 3032
 		}
3035
-		if($conflicts)
3033
+		if ($conflicts)
3036 3034
 		{
3037
-			$this->update_client($event['id'],$d);
3038
-			if(is_int($conflicts))
3035
+			$this->update_client($event['id'], $d);
3036
+			if (is_int($conflicts))
3039 3037
 			{
3040 3038
 				$event['id'] = $conflicts;
3041 3039
 			}
3042
-			if($event['id'])
3040
+			if ($event['id'])
3043 3041
 			{
3044
-				$response->call('egw.refresh', '','calendar',$event['id'],'edit');
3042
+				$response->call('egw.refresh', '', 'calendar', $event['id'], 'edit');
3045 3043
 			}
3046 3044
 		}
3047 3045
 	}
@@ -3052,13 +3050,13 @@  discard block
 block discarded – undo
3052 3050
 	 * @param array $mailContent = null mail content
3053 3051
 	 * @return  array
3054 3052
 	 */
3055
-	function mail_import(array $mailContent=null)
3053
+	function mail_import(array $mailContent = null)
3056 3054
 	{
3057 3055
 		// It would get called from compose as a popup with egw_data
3058 3056
 		if (!is_array($mailContent) && ($_GET['egw_data']))
3059 3057
 		{
3060 3058
 			// get raw mail data
3061
-			Link::get_data ($_GET['egw_data']);
3059
+			Link::get_data($_GET['egw_data']);
3062 3060
 			return false;
3063 3061
 		}
3064 3062
 
@@ -3068,7 +3066,7 @@  discard block
 block discarded – undo
3068 3066
 			$AB = new Api\Contacts();
3069 3067
 			$accounts = array(0 => $GLOBALS['egw_info']['user']['account_id']);
3070 3068
 
3071
-			$participants[0] = array (
3069
+			$participants[0] = array(
3072 3070
 				'uid' => $GLOBALS['egw_info']['user']['account_id'],
3073 3071
 				'delete_id' => $GLOBALS['egw_info']['user']['account_id'],
3074 3072
 				'status' => 'A',
@@ -3076,23 +3074,23 @@  discard block
 block discarded – undo
3076 3074
 				'app' => 'User',
3077 3075
 				'role' => 'REQ-PARTICIPANT'
3078 3076
 			);
3079
-			foreach($mailContent['addresses'] as $address)
3077
+			foreach ($mailContent['addresses'] as $address)
3080 3078
 			{
3081 3079
 				// Get available contacts from the email
3082 3080
 				$contacts = $AB->search(array(
3083 3081
 						'email' => $address['email'],
3084 3082
 						'email_home' => $address['email']
3085
-					),'contact_id,contact_email,contact_email_home,egw_addressbook.account_id as account_id','','','',false,'OR',false,array('owner' => 0),'',false);
3083
+					), 'contact_id,contact_email,contact_email_home,egw_addressbook.account_id as account_id', '', '', '', false, 'OR', false, array('owner' => 0), '', false);
3086 3084
 				if (is_array($contacts))
3087 3085
 				{
3088
-					foreach($contacts as $account)
3086
+					foreach ($contacts as $account)
3089 3087
 					{
3090 3088
 						$accounts[] = $account['account_id'];
3091 3089
 					}
3092 3090
 				}
3093 3091
 				else
3094 3092
 				{
3095
-					$participants []= array (
3093
+					$participants [] = array(
3096 3094
 						'app' => 'email',
3097 3095
 						'uid' => 'e'.$address['email'],
3098 3096
 						'status' => 'U',
@@ -3100,7 +3098,7 @@  discard block
 block discarded – undo
3100 3098
 					);
3101 3099
 				}
3102 3100
 			}
3103
-			$participants = array_merge($participants , array(
3101
+			$participants = array_merge($participants, array(
3104 3102
 				"participant" => $accounts,
3105 3103
 				"role" => "REQ-PARTICIPANT",
3106 3104
 				"add" => "pressed"
@@ -3124,14 +3122,14 @@  discard block
 block discarded – undo
3124 3122
 			{
3125 3123
 				foreach ($mailContent['attachments'] as $attachment)
3126 3124
 				{
3127
-					if($attachment['egw_data'])
3125
+					if ($attachment['egw_data'])
3128 3126
 					{
3129
-						Link::link('calendar',$event['link_to']['to_id'],Link::DATA_APPNAME,  $attachment);
3127
+						Link::link('calendar', $event['link_to']['to_id'], Link::DATA_APPNAME, $attachment);
3130 3128
 					}
3131
-					else if(is_readable($attachment['tmp_name']) ||
3129
+					else if (is_readable($attachment['tmp_name']) ||
3132 3130
 						(Vfs::is_readable($attachment['tmp_name']) && parse_url($attachment['tmp_name'], PHP_URL_SCHEME) === 'vfs'))
3133 3131
 					{
3134
-						Link::link('calendar',$event['link_to']['to_id'],'file',  $attachment);
3132
+						Link::link('calendar', $event['link_to']['to_id'], 'file', $attachment);
3135 3133
 					}
3136 3134
 				}
3137 3135
 			}
Please login to merge, or discard this patch.
api/src/Contacts.php 1 patch
Spacing   +264 added lines, -265 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 namespace EGroupware\Api;
18 18
 
19
-use calendar_bo;	// to_do: do NOT require it, just use if there
19
+use calendar_bo; // to_do: do NOT require it, just use if there
20 20
 
21 21
 /**
22 22
  * Business object for contacts
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	/**
39 39
 	 * @var array $timestamps timestamps
40 40
 	 */
41
-	var $timestamps = array('modified','created');
41
+	var $timestamps = array('modified', 'created');
42 42
 
43 43
 	/**
44 44
 	 * @var array $fileas_types
@@ -173,28 +173,28 @@  discard block
 block discarded – undo
173 173
 	 * @param string $contact_app ='addressbook' used for acl->get_grants()
174 174
 	 * @param Db $db =null
175 175
 	 */
176
-	function __construct($contact_app='addressbook',Db $db=null)
176
+	function __construct($contact_app = 'addressbook', Db $db = null)
177 177
 	{
178
-		parent::__construct($contact_app,$db);
178
+		parent::__construct($contact_app, $db);
179 179
 		if ($this->log)
180 180
 		{
181 181
 			$this->logfile = $GLOBALS['egw_info']['server']['temp_dir'].'/log-addressbook_bo';
182
-			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($contact_app)\n", 3 ,$this->logfile);
182
+			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($contact_app)\n", 3, $this->logfile);
183 183
 		}
184 184
 
185
-		$this->now_su = DateTime::to('now','ts');
185
+		$this->now_su = DateTime::to('now', 'ts');
186 186
 
187
-		$this->prefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook'];
187
+		$this->prefs = & $GLOBALS['egw_info']['user']['preferences']['addressbook'];
188 188
 		// get the default addressbook from the users prefs
189 189
 		$this->default_addressbook = $GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] ?
190 190
 			(int)$GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'] : $this->user;
191
-		$this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'],-1) == 'p';
191
+		$this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook']['add_default'], -1) == 'p';
192 192
 		if ($this->default_addressbook > 0 && $this->default_addressbook != $this->user &&
193 193
 			($this->default_private ||
194 194
 			$this->default_addressbook == (int)$GLOBALS['egw']->preferences->forced['addressbook']['add_default'] ||
195 195
 			$this->default_addressbook == (int)$GLOBALS['egw']->preferences->default['addressbook']['add_default']))
196 196
 		{
197
-			$this->default_addressbook = $this->user;	// admin set a default or forced pref for personal addressbook
197
+			$this->default_addressbook = $this->user; // admin set a default or forced pref for personal addressbook
198 198
 		}
199 199
 		$this->private_addressbook = self::private_addressbook($this->contact_repository == 'sql', $this->prefs);
200 200
 
@@ -299,27 +299,27 @@  discard block
 block discarded – undo
299 299
 		$this->own_account_acl = $GLOBALS['egw_info']['server']['own_account_acl'];
300 300
 		if (!is_array($this->own_account_acl)) $this->own_account_acl = json_php_unserialize($this->own_account_acl, true);
301 301
 		// we have only one acl (n_fn) for the whole name, as not all backends store every part in an own field
302
-		if ($this->own_account_acl && in_array('n_fn',$this->own_account_acl))
302
+		if ($this->own_account_acl && in_array('n_fn', $this->own_account_acl))
303 303
 		{
304
-			$this->own_account_acl = array_merge($this->own_account_acl,array('n_prefix','n_given','n_middle','n_family','n_suffix'));
304
+			$this->own_account_acl = array_merge($this->own_account_acl, array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix'));
305 305
 		}
306 306
 		if ($GLOBALS['egw_info']['server']['org_fileds_to_update'])
307 307
 		{
308
-			$this->org_fields =  $GLOBALS['egw_info']['server']['org_fileds_to_update'];
308
+			$this->org_fields = $GLOBALS['egw_info']['server']['org_fileds_to_update'];
309 309
 			if (!is_array($this->org_fields)) $this->org_fields = unserialize($this->org_fields);
310 310
 
311 311
 			// Set country code if country name is selected
312
-			$supported_fields = $this->get_fields('supported',null,0);
313
-			if(in_array('adr_one_countrycode', $supported_fields) && in_array('adr_one_countryname',$this->org_fields))
312
+			$supported_fields = $this->get_fields('supported', null, 0);
313
+			if (in_array('adr_one_countrycode', $supported_fields) && in_array('adr_one_countryname', $this->org_fields))
314 314
 			{
315 315
 				$this->org_fields[] = 'adr_one_countrycode';
316 316
 			}
317
-			if(in_array('adr_two_countrycode', $supported_fields) && in_array('adr_two_countryname',$this->org_fields))
317
+			if (in_array('adr_two_countrycode', $supported_fields) && in_array('adr_two_countryname', $this->org_fields))
318 318
 			{
319 319
 				$this->org_fields[] = 'adr_two_countrycode';
320 320
 			}
321 321
 		}
322
-		$this->categories = new Categories($this->user,'addressbook');
322
+		$this->categories = new Categories($this->user, 'addressbook');
323 323
 
324 324
 		$this->delete_history = $GLOBALS['egw_info']['server']['history'];
325 325
 	}
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @param array $prefs addressbook preferences
334 334
 	 * @return boolean
335 335
 	 */
336
-	public static function private_addressbook($contact_repository, array $prefs=null)
336
+	public static function private_addressbook($contact_repository, array $prefs = null)
337 337
 	{
338 338
 		return $contact_repository == 'sql' && $prefs['private_addressbook'];
339 339
 	}
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 	 * @param int $user =null account_id or null for current user
348 348
 	 * @return array with owner => label pairs
349 349
 	 */
350
-	function get_addressbooks($required=Acl::READ,$extra_label=null,$user=null)
350
+	function get_addressbooks($required = Acl::READ, $extra_label = null, $user = null)
351 351
 	{
352 352
 		if (is_null($user))
353 353
 		{
@@ -366,11 +366,11 @@  discard block
 block discarded – undo
366 366
 		if ($extra_label) $addressbooks[''] = $extra_label;
367 367
 		$addressbooks[$user] = lang('Personal');
368 368
 		// add all group addressbooks the user has the necessary rights too
369
-		foreach($grants as $uid => $rights)
369
+		foreach ($grants as $uid => $rights)
370 370
 		{
371
-			if (($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'g')
371
+			if (($rights&$required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'g')
372 372
 			{
373
-				$to_sort[$uid] = lang('Group %1',$GLOBALS['egw']->accounts->id2name($uid));
373
+				$to_sort[$uid] = lang('Group %1', $GLOBALS['egw']->accounts->id2name($uid));
374 374
 			}
375 375
 		}
376 376
 		if ($to_sort)
@@ -378,19 +378,19 @@  discard block
 block discarded – undo
378 378
 			asort($to_sort);
379 379
 			$addressbooks += $to_sort;
380 380
 		}
381
-		if ($required != Acl::ADD &&	// do NOT allow to set accounts as default addressbook (AB can add accounts)
381
+		if ($required != Acl::ADD && // do NOT allow to set accounts as default addressbook (AB can add accounts)
382 382
 			!$preferences['addressbook']['hide_accounts'] && (
383
-				($grants[0] & $required) == $required ||
383
+				($grants[0]&$required) == $required ||
384 384
 				$preferences['common']['account_selection'] == 'groupmembers' &&
385
-				$this->account_repository != 'ldap' && ($required & Acl::READ)))
385
+				$this->account_repository != 'ldap' && ($required&Acl::READ)))
386 386
 		{
387 387
 			$addressbooks[0] = lang('Accounts');
388 388
 		}
389 389
 		// add all other user addressbooks the user has the necessary rights too
390 390
 		$to_sort = array();
391
-		foreach($grants as $uid => $rights)
391
+		foreach ($grants as $uid => $rights)
392 392
 		{
393
-			if ($uid != $user && ($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'u')
393
+			if ($uid != $user && ($rights&$required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'u')
394 394
 			{
395 395
 				$to_sort[$uid] = Accounts::username($uid);
396 396
 			}
@@ -415,22 +415,22 @@  discard block
 block discarded – undo
415 415
 	 * @param boolean $isUpdate =false If true, reads the old record for any not set fields
416 416
 	 * @return string
417 417
 	 */
418
-	function fileas($contact,$type=null, $isUpdate=false)
418
+	function fileas($contact, $type = null, $isUpdate = false)
419 419
 	{
420 420
 		if (is_null($type)) $type = $contact['fileas_type'];
421 421
 		if (!$type) $type = $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0];
422 422
 
423
-		if (strpos($type,'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact);
423
+		if (strpos($type, 'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact);
424 424
 
425
-		if($isUpdate)
425
+		if ($isUpdate)
426 426
 		{
427
-			$fileas_fields = array('n_prefix','n_given','n_middle','n_family','n_suffix','n_fn','org_name','org_unit','adr_one_locality','bday');
427
+			$fileas_fields = array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix', 'n_fn', 'org_name', 'org_unit', 'adr_one_locality', 'bday');
428 428
 			$old = null;
429
-			foreach($fileas_fields as $field)
429
+			foreach ($fileas_fields as $field)
430 430
 			{
431
-				if(!isset($contact[$field]))
431
+				if (!isset($contact[$field]))
432 432
 				{
433
-					if(is_null($old)) $old = $this->read($contact['id']);
433
+					if (is_null($old)) $old = $this->read($contact['id']);
434 434
 					$contact[$field] = $old[$field];
435 435
 				}
436 436
 			}
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
 		}
439 439
 
440 440
 		// removing empty delimiters, caused by empty contact fields
441
-		$fileas = str_replace(array(', , : ',', : ',': , ',', , ',': : ',' ()'),
442
-			array(': ',': ',': ',', ',': ',''),
441
+		$fileas = str_replace(array(', , : ', ', : ', ': , ', ', , ', ': : ', ' ()'),
442
+			array(': ', ': ', ': ', ', ', ': ', ''),
443 443
 			strtr($type, array(
444 444
 				'n_prefix' => $contact['n_prefix'],
445 445
 				'n_given'  => $contact['n_given'],
@@ -453,13 +453,13 @@  discard block
 block discarded – undo
453 453
 				'bday'     => (int)$contact['bday'] ? DateTime::to($contact['bday'], true) : $contact['bday'],
454 454
 			)));
455 455
 
456
-		while ($fileas[0] == ':' ||  $fileas[0] == ',')
456
+		while ($fileas[0] == ':' || $fileas[0] == ',')
457 457
 		{
458
-			$fileas = substr($fileas,2);
458
+			$fileas = substr($fileas, 2);
459 459
 		}
460
-		while (substr($fileas,-2) == ': ' || substr($fileas,-2) == ', ')
460
+		while (substr($fileas, -2) == ': ' || substr($fileas, -2) == ', ')
461 461
 		{
462
-			$fileas = substr($fileas,0,-2);
462
+			$fileas = substr($fileas, 0, -2);
463 463
 		}
464 464
 		return $fileas;
465 465
 	}
@@ -471,15 +471,15 @@  discard block
 block discarded – undo
471 471
 	 * @param string $file_as =null file_as type, default null to read it from the contact, unknown/not set type default to the first one
472 472
 	 * @return string
473 473
 	 */
474
-	function fileas_type($contact,$file_as=null)
474
+	function fileas_type($contact, $file_as = null)
475 475
 	{
476 476
 		if (is_null($file_as)) $file_as = $contact['n_fileas'];
477 477
 
478 478
 		if ($file_as)
479 479
 		{
480
-			foreach($this->fileas_types as $type)
480
+			foreach ($this->fileas_types as $type)
481 481
 			{
482
-				if ($this->fileas($contact,$type) == $file_as)
482
+				if ($this->fileas($contact, $type) == $file_as)
483 483
 				{
484 484
 					return $type;
485 485
 				}
@@ -496,10 +496,10 @@  discard block
 block discarded – undo
496 496
 	 */
497 497
 	public static function cf_options()
498 498
 	{
499
-		$cf_fields = Storage\Customfields::get('addressbook',TRUE);
500
-		foreach ($cf_fields as $key => $value )
499
+		$cf_fields = Storage\Customfields::get('addressbook', TRUE);
500
+		foreach ($cf_fields as $key => $value)
501 501
 		{
502
-			$options[$key]= $value['label'];
502
+			$options[$key] = $value['label'];
503 503
 		}
504 504
 		return $options;
505 505
 	}
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 * @param array $contact =null real content to use, default none
511 511
 	 * @return array with options: fileas type => label pairs
512 512
 	 */
513
-	function fileas_options($contact=null)
513
+	function fileas_options($contact = null)
514 514
 	{
515 515
 		$labels = array(
516 516
 			'n_prefix' => lang('prefix'),
@@ -524,13 +524,13 @@  discard block
 block discarded – undo
524 524
 			'adr_one_locality' => lang('city'),
525 525
 			'bday'     => lang('Birthday'),
526 526
 		);
527
-		foreach(array_keys($labels) as $name)
527
+		foreach (array_keys($labels) as $name)
528 528
 		{
529 529
 			if ($contact[$name]) $labels[$name] = $contact[$name];
530 530
 		}
531
-		foreach($this->fileas_types as $fileas_type)
531
+		foreach ($this->fileas_types as $fileas_type)
532 532
 		{
533
-			$options[$fileas_type] = $this->fileas($labels,$fileas_type);
533
+			$options[$fileas_type] = $this->fileas($labels, $fileas_type);
534 534
 		}
535 535
 		return $options;
536 536
 	}
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	 * @param int &$errors=null on return number of errors
546 546
 	 * @return int|boolean number of contacts updated, false for wrong fileas type
547 547
 	 */
548
-	function set_all_fileas($fileas_type,$all=false,&$errors=null,$ignore_acl=false)
548
+	function set_all_fileas($fileas_type, $all = false, &$errors = null, $ignore_acl = false)
549 549
 	{
550 550
 		if ($fileas_type != '' && !in_array($fileas_type, $this->fileas_types))
551 551
 		{
@@ -553,17 +553,17 @@  discard block
 block discarded – undo
553 553
 		}
554 554
 		if ($ignore_acl)
555 555
 		{
556
-			unset($this->somain->grants);	// to NOT limit search to contacts readable by current user
556
+			unset($this->somain->grants); // to NOT limit search to contacts readable by current user
557 557
 		}
558 558
 		// to be able to work on huge contact repositories we read the contacts in chunks of 100
559
-		for($n = $updated = $errors = 0; ($contacts = parent::search($all ? array() : array(
559
+		for ($n = $updated = $errors = 0; ($contacts = parent::search($all ? array() : array(
560 560
 			'n_fileas IS NULL',
561 561
 			"n_fileas=''",
562 562
 			'n_fn IS NULL',
563 563
 			"n_fn=''",
564
-		),false,'','','',false,'OR',array($n*100,100))); ++$n)
564
+		), false, '', '', '', false, 'OR', array($n * 100, 100))); ++$n)
565 565
 		{
566
-			foreach($contacts as $contact)
566
+			foreach ($contacts as $contact)
567 567
 			{
568 568
 				$old_fn     = $contact['n_fn'];
569 569
 				$old_fileas = $contact['n_fileas'];
@@ -571,19 +571,19 @@  discard block
 block discarded – undo
571 571
 				// only update fileas if type is given AND (all should be updated or n_fileas is empty)
572 572
 				if ($fileas_type && ($all || empty($contact['n_fileas'])))
573 573
 				{
574
-					$contact['n_fileas'] = $this->fileas($contact,$fileas_type);
574
+					$contact['n_fileas'] = $this->fileas($contact, $fileas_type);
575 575
 				}
576 576
 				if ($old_fileas != $contact['n_fileas'] || $old_fn != $contact['n_fn'])
577 577
 				{
578 578
 					// only specify/write updated fields plus "keys"
579
-					$contact = array_intersect_key($contact,array(
579
+					$contact = array_intersect_key($contact, array(
580 580
 						'id' => true,
581 581
 						'owner' => true,
582 582
 						'private' => true,
583 583
 						'account_id' => true,
584 584
 						'uid' => true,
585
-					)+($old_fileas != $contact['n_fileas'] ? array('n_fileas' => true) : array())+($old_fn != $contact['n_fn'] ? array('n_fn' => true) : array()));
586
-					if ($this->save($contact,$ignore_acl))
585
+					) + ($old_fileas != $contact['n_fileas'] ? array('n_fileas' => true) : array()) + ($old_fn != $contact['n_fn'] ? array('n_fn' => true) : array()));
586
+					if ($this->save($contact, $ignore_acl))
587 587
 					{
588 588
 						$updated++;
589 589
 					}
@@ -606,11 +606,11 @@  discard block
 block discarded – undo
606 606
 	 * @param int &$errors=null on return number of errors
607 607
 	 * @return int|boolean number of contacts updated
608 608
 	 */
609
-	function set_all_cleanup(&$errors=null,$ignore_acl=false)
609
+	function set_all_cleanup(&$errors = null, $ignore_acl = false)
610 610
 	{
611 611
 		if ($ignore_acl)
612 612
 		{
613
-			unset($this->somain->grants);	// to NOT limit search to contacts readable by current user
613
+			unset($this->somain->grants); // to NOT limit search to contacts readable by current user
614 614
 		}
615 615
 
616 616
 		// fields that must not be touched
@@ -632,14 +632,14 @@  discard block
 block discarded – undo
632 632
 		);
633 633
 
634 634
 		// to be able to work on huge contact repositories we read the contacts in chunks of 100
635
-		for($n = $updated = $errors = 0; ($contacts = parent::search(array(),false,'','','',false,'OR',array($n*100,100))); ++$n)
635
+		for ($n = $updated = $errors = 0; ($contacts = parent::search(array(), false, '', '', '', false, 'OR', array($n * 100, 100))); ++$n)
636 636
 		{
637
-			foreach($contacts as $contact)
637
+			foreach ($contacts as $contact)
638 638
 			{
639 639
 				$fields_to_update = array();
640
-				foreach($contact as $field_name => $field_value)
640
+				foreach ($contact as $field_name => $field_value)
641 641
 				{
642
-					if($fields_exclude[$field_name] === true) continue; // dont touch specified field
642
+					if ($fields_exclude[$field_name] === true) continue; // dont touch specified field
643 643
 
644 644
 					if (is_string($field_value) && $field_name != 'pubkey' && $field_name != 'jpegphoto')
645 645
 					{
@@ -649,9 +649,9 @@  discard block
 block discarded – undo
649 649
 							$fields_to_update[$field_name] = $field_value = trim($field_value);
650 650
 						}
651 651
 						// check if field contains a carriage return - exclude notes
652
-						if ($field_name != 'note' && strpos($field_value,"\x0D\x0A") !== false)
652
+						if ($field_name != 'note' && strpos($field_value, "\x0D\x0A") !== false)
653 653
 						{
654
-							$fields_to_update[$field_name] = $field_value = str_replace("\x0D\x0A"," ",$field_value);
654
+							$fields_to_update[$field_name] = $field_value = str_replace("\x0D\x0A", " ", $field_value);
655 655
 						}
656 656
 					}
657 657
 					// check if a field contains an empty string
@@ -661,13 +661,13 @@  discard block
 block discarded – undo
661 661
 					}
662 662
 					// check for valid birthday date
663 663
 					if ($field_name == 'bday' && $field_value != null &&
664
-						!preg_match('/^(18|19|20|21|22)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/',$field_value))
664
+						!preg_match('/^(18|19|20|21|22)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/', $field_value))
665 665
 					{
666 666
 						$fields_to_update[$field_name] = $field_value = null;
667 667
 					}
668 668
 				}
669 669
 
670
-				if(count($fields_to_update) > 0)
670
+				if (count($fields_to_update) > 0)
671 671
 				{
672 672
 					$contact_to_save = array(
673 673
 						'id' => $contact['id'],
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 						'account_id' => $contact['account_id'],
677 677
 						'uid' => $contact['uid']) + $fields_to_update;
678 678
 
679
-					if ($this->save($contact_to_save,$ignore_acl))
679
+					if ($this->save($contact_to_save, $ignore_acl))
680 680
 					{
681 681
 						$updated++;
682 682
 					}
@@ -701,14 +701,14 @@  discard block
 block discarded – undo
701 701
 		if (empty($contact['n_family']) && empty($contact['n_given'])) {
702 702
 			$cpart = array('org_name');
703 703
 		} else {
704
-			$cpart = array('n_prefix','n_given','n_middle','n_family','n_suffix');
704
+			$cpart = array('n_prefix', 'n_given', 'n_middle', 'n_family', 'n_suffix');
705 705
 		}
706 706
 		$parts = array();
707
-		foreach($cpart as $n)
707
+		foreach ($cpart as $n)
708 708
 		{
709 709
 			if ($contact[$n]) $parts[] = $contact[$n];
710 710
 		}
711
-		return implode(' ',$parts);
711
+		return implode(' ', $parts);
712 712
 	}
713 713
 
714 714
 	/**
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
 	 *
723 723
 	 * @return array updated data
724 724
 	 */
725
-	function db2data($data, $date_format='ts')
725
+	function db2data($data, $date_format = 'ts')
726 726
 	{
727 727
 		static $fb_url = false;
728 728
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 				$data[$name] = DateTime::server2user($data[$name], $date_format);
735 735
 			}
736 736
 		}
737
-		$data['photo'] = $this->photo_src($data['id'],$data['jpegphoto'],'',$data['etag']);
737
+		$data['photo'] = $this->photo_src($data['id'], $data['jpegphoto'], '', $data['etag']);
738 738
 
739 739
 		// set freebusy_uri for accounts
740 740
 		if (!$data['freebusy_uri'] && !$data['owner'] && $data['account_id'] && !is_object($GLOBALS['egw_setup']))
@@ -757,13 +757,13 @@  discard block
 block discarded – undo
757 757
 	 * @param string $etag =null etag to set in url to allow caching with Expires header
758 758
 	 * @return string/array
759 759
 	 */
760
-	function photo_src($id,$jpeg,$default='',$etag=null)
760
+	function photo_src($id, $jpeg, $default = '', $etag = null)
761 761
 	{
762 762
 		//error_log(__METHOD__."($id, ..., etag=$etag) ".  function_backtrace());
763 763
 		return $jpeg ? array(
764 764
 			'menuaction' => 'addressbook.addressbook_ui.photo',
765 765
 			'contact_id' => $id,
766
-		)+(isset($etag) ? array(
766
+		) + (isset($etag) ? array(
767 767
 			'etag'       => $etag,
768 768
 		) : array()) : $default;
769 769
 	}
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 	 *
780 780
 	 * @return array upated data
781 781
 	 */
782
-	function data2db($data, $date_format='ts')
782
+	function data2db($data, $date_format = 'ts')
783 783
 	{
784 784
 		// convert timestamps from user-time to server-time in the db
785 785
 		foreach ($this->timestamps as $name)
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 	* @param int $check_etag =null
801 801
 	* @return boolean|int true on success or false on failiure, 0 if etag does not match
802 802
 	*/
803
-	function delete($contact,$deny_account_delete=true,$check_etag=null)
803
+	function delete($contact, $deny_account_delete = true, $check_etag = null)
804 804
 	{
805 805
 		if (is_array($contact) && isset($contact['id']))
806 806
 		{
@@ -810,12 +810,12 @@  discard block
 block discarded – undo
810 810
 		{
811 811
 			$contact = array($contact);
812 812
 		}
813
-		foreach($contact as $c)
813
+		foreach ($contact as $c)
814 814
 		{
815 815
 			$id = is_array($c) ? $c['id'] : $c;
816 816
 
817 817
 			$ok = false;
818
-			if ($this->check_perms(Acl::DELETE,$c,$deny_account_delete))
818
+			if ($this->check_perms(Acl::DELETE, $c, $deny_account_delete))
819 819
 			{
820 820
 				if (!($old = $this->read($id))) return false;
821 821
 				// check if we only mark contacts as deleted, or really delete them
@@ -826,12 +826,12 @@  discard block
 block discarded – undo
826 826
 					$delete = $old;
827 827
 					$delete['tid'] = self::DELETED_TYPE;
828 828
 					if ($check_etag) $delete['etag'] = $check_etag;
829
-					if (($ok = $this->save($delete))) $ok = true;	// we have to return true or false
830
-					Link::unlink(0,'addressbook',$id,'','','',true);
829
+					if (($ok = $this->save($delete))) $ok = true; // we have to return true or false
830
+					Link::unlink(0, 'addressbook', $id, '', '', '', true);
831 831
 				}
832
-				elseif (($ok = parent::delete($id,$check_etag)))
832
+				elseif (($ok = parent::delete($id, $check_etag)))
833 833
 				{
834
-					Link::unlink(0,'addressbook',$id);
834
+					Link::unlink(0, 'addressbook', $id);
835 835
 				}
836 836
 
837 837
 				// Don't notify of final purge
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	* @param boolean $touch_modified =true should modified/r be updated
859 859
 	* @return int/string/boolean id on success, false on failure, the error-message is in $this->error
860 860
 	*/
861
-	function save(&$contact, $ignore_acl=false, $touch_modified=true)
861
+	function save(&$contact, $ignore_acl = false, $touch_modified = true)
862 862
 	{
863 863
 		// remember if we add or update a entry
864 864
 		if (($isUpdate = $contact['id']))
@@ -867,11 +867,11 @@  discard block
 block discarded – undo
867 867
 			{
868 868
 				if (($old = $this->read($contact['id'])))	// --> try reading the old entry and set it from there
869 869
 				{
870
-					if(!isset($contact['owner']))
870
+					if (!isset($contact['owner']))
871 871
 					{
872 872
 						$contact['owner'] = $old['owner'];
873 873
 					}
874
-					if(!isset($contact['private']))
874
+					if (!isset($contact['private']))
875 875
 					{
876 876
 						$contact['private'] = $old['private'];
877 877
 					}
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
 		{
904 904
 			$contact['private'] = 0;
905 905
 		}
906
-		if(!$ignore_acl && !$this->check_perms($isUpdate ? Acl::EDIT : Acl::ADD,$contact))
906
+		if (!$ignore_acl && !$this->check_perms($isUpdate ? Acl::EDIT : Acl::ADD, $contact))
907 907
 		{
908 908
 			$this->error = 'access denied';
909 909
 			return false;
@@ -916,15 +916,15 @@  discard block
 block discarded – undo
916 916
 		// convert categories
917 917
 		if (is_array($contact['cat_id']))
918 918
 		{
919
-			$contact['cat_id'] = implode(',',$contact['cat_id']);
919
+			$contact['cat_id'] = implode(',', $contact['cat_id']);
920 920
 		}
921 921
 
922 922
 		// Update country codes
923
-		foreach(array('adr_one_', 'adr_two_') as $c_prefix) {
924
-			if($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] &&
923
+		foreach (array('adr_one_', 'adr_two_') as $c_prefix) {
924
+			if ($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] &&
925 925
 				$code = Country::country_code($contact[$c_prefix.'countryname']))
926 926
 			{
927
-				if(strlen($code) == 2)
927
+				if (strlen($code) == 2)
928 928
 				{
929 929
 					$contact[$c_prefix.'countrycode'] = $code;
930 930
 				}
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
 					$contact[$c_prefix.'countrycode'] = null;
934 934
 				}
935 935
 			}
936
-			if($contact[$c_prefix.'countrycode'] != null)
936
+			if ($contact[$c_prefix.'countrycode'] != null)
937 937
 			{
938 938
 				$contact[$c_prefix.'countryname'] = null;
939 939
 			}
@@ -961,9 +961,9 @@  discard block
 block discarded – undo
961 961
 		// (non-admin) user editing his own account, make sure he does not change fields he is not allowed to (eg. via SyncML or xmlrpc)
962 962
 		if (!$ignore_acl && !$contact['owner'] && !($this->is_admin($contact) || $this->allow_account_edit()))
963 963
 		{
964
-			foreach(array_keys($contact) as $field)
964
+			foreach (array_keys($contact) as $field)
965 965
 			{
966
-				if (!in_array($field,$this->own_account_acl) && !in_array($field,array('id','owner','account_id','modified','modifier')))
966
+				if (!in_array($field, $this->own_account_acl) && !in_array($field, array('id', 'owner', 'account_id', 'modified', 'modifier')))
967 967
 				{
968 968
 					// user is not allowed to change that
969 969
 					if ($old)
@@ -984,12 +984,12 @@  discard block
 block discarded – undo
984 984
 		{
985 985
 			if (isset($to_write['owner']) && !empty($to_write['owner']))
986 986
 			{
987
-				error_log(__METHOD__.__LINE__." Trying to change account to owner:". $to_write['owner'].' Account affected:'.array2string($old).' Data send:'.array2string($to_write));
987
+				error_log(__METHOD__.__LINE__." Trying to change account to owner:".$to_write['owner'].' Account affected:'.array2string($old).' Data send:'.array2string($to_write));
988 988
 				unset($to_write['owner']);
989 989
 			}
990 990
 		}
991 991
 
992
-		if(!($this->error = parent::save($to_write)))
992
+		if (!($this->error = parent::save($to_write)))
993 993
 		{
994 994
 			$contact['id'] = $to_write['id'];
995 995
 			$contact['uid'] = $to_write['uid'];
@@ -1003,27 +1003,27 @@  discard block
 block discarded – undo
1003 1003
 				$GLOBALS['egw']->accounts->cache_invalidate($contact['account_id']);
1004 1004
 				// call edit-accout hook, to let other apps know about changed account (names or email)
1005 1005
 				$GLOBALS['hook_values'] = $GLOBALS['egw']->accounts->read($contact['account_id']);
1006
-				Hooks::process($GLOBALS['hook_values']+array(
1006
+				Hooks::process($GLOBALS['hook_values'] + array(
1007 1007
 					'location' => 'editaccount',
1008
-				),False,True);	// called for every app now, not only enabled ones)
1008
+				), False, True); // called for every app now, not only enabled ones)
1009 1009
 			}
1010 1010
 			// notify interested apps about changes in the account-contact data
1011 1011
 			if (!$to_write['owner'] && $to_write['account_id'] && $isUpdate)
1012 1012
 			{
1013 1013
 				$to_write['location'] = 'editaccountcontact';
1014
-				Hooks::process($to_write,False,True);	// called for every app now, not only enabled ones));
1014
+				Hooks::process($to_write, False, True); // called for every app now, not only enabled ones));
1015 1015
 			}
1016 1016
 			// Notify linked apps about changes in the contact data
1017
-			Link::notify_update('addressbook',  $contact['id'], $contact);
1017
+			Link::notify_update('addressbook', $contact['id'], $contact);
1018 1018
 
1019 1019
 			// Check for restore of deleted contact, restore held links
1020
-			if($old && $old['tid'] == self::DELETED_TYPE && $contact['tid'] != self::DELETED_TYPE)
1020
+			if ($old && $old['tid'] == self::DELETED_TYPE && $contact['tid'] != self::DELETED_TYPE)
1021 1021
 			{
1022 1022
 				Link::restore('addressbook', $contact['id']);
1023 1023
 			}
1024 1024
 
1025 1025
 			// Record change history for sql - doesn't work for LDAP accounts
1026
-			if(!$contact['account_id'] || $contact['account_id'] && $this->account_repository == 'sql')
1026
+			if (!$contact['account_id'] || $contact['account_id'] && $this->account_repository == 'sql')
1027 1027
 			{
1028 1028
 				$deleted = ($old['tid'] == self::DELETED_TYPE || $contact['tid'] == self::DELETED_TYPE);
1029 1029
 				if (!isset($this->tracking)) $this->tracking = new Contacts\Tracking($this);
@@ -1031,12 +1031,12 @@  discard block
 block discarded – undo
1031 1031
 			}
1032 1032
 
1033 1033
 			// Expire birthday cache for this year and next if birthday changed
1034
-			if($isUpdate && $old['bday'] !== $to_write['bday'] || !$isUpdate && $to_write['bday'])
1034
+			if ($isUpdate && $old['bday'] !== $to_write['bday'] || !$isUpdate && $to_write['bday'])
1035 1035
 			{
1036
-				$year = (int) date('Y',time());
1037
-				Cache::unsetInstance(__CLASS__,"birthday-$year-{$to_write['owner']}");
1036
+				$year = (int)date('Y', time());
1037
+				Cache::unsetInstance(__CLASS__, "birthday-$year-{$to_write['owner']}");
1038 1038
 				$year++;
1039
-				Cache::unsetInstance(__CLASS__,"birthday-$year-{$to_write['owner']}");
1039
+				Cache::unsetInstance(__CLASS__, "birthday-$year-{$to_write['owner']}");
1040 1040
 			}
1041 1041
 		}
1042 1042
 
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
 	 * @param int $dst_w =240 max width to resize to
1051 1051
 	 * @return string with resized jpeg photo, null on error
1052 1052
 	 */
1053
-	public static function resize_photo($photo,$dst_w=240)
1053
+	public static function resize_photo($photo, $dst_w = 240)
1054 1054
 	{
1055 1055
 		if (is_resource($photo))
1056 1056
 		{
@@ -1066,15 +1066,15 @@  discard block
 block discarded – undo
1066 1066
 		//error_log(__METHOD__."() got image $src_w * $src_h, is_jpeg=".array2string(substr($photo,0,2) === "\377\330"));
1067 1067
 
1068 1068
 		// if $photo is to width or not a jpeg image --> resize it
1069
-		if ($src_w > $dst_w || cut_bytes($photo,0,2) !== "\377\330")
1069
+		if ($src_w > $dst_w || cut_bytes($photo, 0, 2) !== "\377\330")
1070 1070
 		{
1071 1071
 			//error_log(__METHOD__."(,dst_w=$dst_w) src_w=$src_w, cut_bytes(photo,0,2)=".array2string(cut_bytes($photo,0,2)).' --> resizing');
1072 1072
 			// scale the image to a width of 60 and a height according to the proportion of the source image
1073
-			$resized = imagecreatetruecolor($dst_w,$dst_h = round($src_h * $dst_w / $src_w));
1074
-			imagecopyresized($resized,$image,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
1073
+			$resized = imagecreatetruecolor($dst_w, $dst_h = round($src_h * $dst_w / $src_w));
1074
+			imagecopyresized($resized, $image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
1075 1075
 
1076 1076
 			ob_start();
1077
-			imagejpeg($resized,null,90);
1077
+			imagejpeg($resized, null, 90);
1078 1078
 			$photo = ob_get_contents();
1079 1079
 			ob_end_clean();
1080 1080
 
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
 	* @param boolean $ignore_acl =false true: no acl check
1096 1096
 	* @return array|boolean array with contact data, null if not found or false on no view perms
1097 1097
 	*/
1098
-	function read($contact_id, $ignore_acl=false)
1098
+	function read($contact_id, $ignore_acl = false)
1099 1099
 	{
1100 1100
 		// get so_sql_cf to read private customfields too, if we ignore acl
1101 1101
 		if ($ignore_acl && is_a($this->somain, __CLASS__.'\\Sql'))
@@ -1105,11 +1105,11 @@  discard block
 block discarded – undo
1105 1105
 		}
1106 1106
 		if (!($data = parent::read($contact_id)))
1107 1107
 		{
1108
-			$data = null;	// not found
1108
+			$data = null; // not found
1109 1109
 		}
1110
-		elseif (!$ignore_acl && !$this->check_perms(Acl::READ,$data))
1110
+		elseif (!$ignore_acl && !$this->check_perms(Acl::READ, $data))
1111 1111
 		{
1112
-			$data = false;	// no view perms
1112
+			$data = false; // no view perms
1113 1113
 		}
1114 1114
 		else
1115 1115
 		{
@@ -1117,10 +1117,10 @@  discard block
 block discarded – undo
1117 1117
 			$data['fileas_type'] = $this->fileas_type($data);
1118 1118
 
1119 1119
 			// Update country name from code
1120
-			if($data['adr_one_countrycode'] != null) {
1120
+			if ($data['adr_one_countrycode'] != null) {
1121 1121
 				$data['adr_one_countryname'] = Country::get_full_name($data['adr_one_countrycode'], true);
1122 1122
 			}
1123
-			if($data['adr_two_countrycode'] != null) {
1123
+			if ($data['adr_two_countrycode'] != null) {
1124 1124
 				$data['adr_two_countryname'] = Country::get_full_name($data['adr_two_countrycode'], true);
1125 1125
 			}
1126 1126
 		}
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
 	 * @param int $user =null for which user to check, default current user
1145 1145
 	 * @return boolean true permission granted, false for permission denied, null for contact does not exist
1146 1146
 	 */
1147
-	function check_perms($needed,$contact,$deny_account_delete=false,$user=null)
1147
+	function check_perms($needed, $contact, $deny_account_delete = false, $user = null)
1148 1148
 	{
1149 1149
 		if (!$user) $user = $this->user;
1150 1150
 		if ($user == $this->user)
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 		else
1156 1156
 		{
1157 1157
 			$grants = $this->get_grants($user);
1158
-			$memberships =  $GLOBALS['egw']->accounts->memberships($user,true);
1158
+			$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1159 1159
 		}
1160 1160
 
1161 1161
 		if ((!is_array($contact) || !isset($contact['owner'])) &&
@@ -1181,12 +1181,12 @@  discard block
 block discarded – undo
1181 1181
 			$GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
1182 1182
 			!isset($GLOBALS['egw_info']['user']['apps']['admin']))
1183 1183
 		{
1184
-			$access = !!array_intersect($memberships,$GLOBALS['egw']->accounts->memberships($contact['account_id'],true));
1184
+			$access = !!array_intersect($memberships, $GLOBALS['egw']->accounts->memberships($contact['account_id'], true));
1185 1185
 		}
1186 1186
 		else
1187 1187
 		{
1188
-			$access = ($grants[$owner] & $needed) &&
1189
-				(!$contact['private'] || ($grants[$owner] & Acl::PRIVAT) || in_array($owner,$memberships));
1188
+			$access = ($grants[$owner]&$needed) &&
1189
+				(!$contact['private'] || ($grants[$owner]&Acl::PRIVAT) || in_array($owner, $memberships));
1190 1190
 		}
1191 1191
 		//error_log(__METHOD__."($needed,$contact[id],$deny_account_delete,$user) returning ".array2string($access));
1192 1192
 		return $access;
@@ -1201,11 +1201,11 @@  discard block
 block discarded – undo
1201 1201
 	 * @param int $user =null for which user to check, default current user
1202 1202
 	 * @return boolean true if access is granted or false otherwise
1203 1203
 	 */
1204
-	function file_access($id,$check,$rel_path=null,$user=null)
1204
+	function file_access($id, $check, $rel_path = null, $user = null)
1205 1205
 	{
1206
-		unset($rel_path);	// not used, but required by function signature
1206
+		unset($rel_path); // not used, but required by function signature
1207 1207
 
1208
-		return $this->check_perms($check,$id,false,$user);
1208
+		return $this->check_perms($check, $id, false, $user);
1209 1209
 	}
1210 1210
 
1211 1211
 	/**
@@ -1217,18 +1217,18 @@  discard block
 block discarded – undo
1217 1217
 	function read_org($org_id)
1218 1218
 	{
1219 1219
 		if (!$org_id) return false;
1220
-		if (strpos($org_id,'*AND*')!== false) $org_id = str_replace('*AND*','&',$org_id);
1220
+		if (strpos($org_id, '*AND*') !== false) $org_id = str_replace('*AND*', '&', $org_id);
1221 1221
 		$org = array();
1222
-		foreach(explode('|||',$org_id) as $part)
1222
+		foreach (explode('|||', $org_id) as $part)
1223 1223
 		{
1224
-			list($name,$value) = explode(':',$part,2);
1224
+			list($name, $value) = explode(':', $part, 2);
1225 1225
 			$org[$name] = $value;
1226 1226
 		}
1227
-		$csvs = array('cat_id');	// fields with comma-separated-values
1227
+		$csvs = array('cat_id'); // fields with comma-separated-values
1228 1228
 
1229 1229
 		// split regular fields and custom fields
1230 1230
 		$custom_fields = $regular_fields = array();
1231
-		foreach($this->org_fields as $name)
1231
+		foreach ($this->org_fields as $name)
1232 1232
 		{
1233 1233
 			if ($name[0] != '#')
1234 1234
 			{
@@ -1236,9 +1236,9 @@  discard block
 block discarded – undo
1236 1236
 			}
1237 1237
 			else
1238 1238
 			{
1239
-				$custom_fields[] = $name = substr($name,1);
1239
+				$custom_fields[] = $name = substr($name, 1);
1240 1240
 				$regular_fields['id'] = 'id';
1241
-				if (substr($this->customfields[$name]['type'],0,6)=='select' && $this->customfields[$name]['rows'] ||	// multiselection
1241
+				if (substr($this->customfields[$name]['type'], 0, 6) == 'select' && $this->customfields[$name]['rows'] || // multiselection
1242 1242
 					$this->customfields[$name]['type'] == 'radio')
1243 1243
 				{
1244 1244
 					$csvs[] = '#'.$name;
@@ -1246,24 +1246,24 @@  discard block
 block discarded – undo
1246 1246
 			}
1247 1247
 		}
1248 1248
 		// read the regular fields
1249
-		$contacts = parent::search('',$regular_fields,'','','',false,'AND',false,$org);
1249
+		$contacts = parent::search('', $regular_fields, '', '', '', false, 'AND', false, $org);
1250 1250
 		if (!$contacts) return false;
1251 1251
 
1252 1252
 		// if we have custom fields, read and merge them in
1253 1253
 		if ($custom_fields)
1254 1254
 		{
1255
-			foreach($contacts as $contact)
1255
+			foreach ($contacts as $contact)
1256 1256
 			{
1257 1257
 				$ids[] = $contact['id'];
1258 1258
 			}
1259
-			if (($cfs = $this->read_customfields($ids,$custom_fields)))
1259
+			if (($cfs = $this->read_customfields($ids, $custom_fields)))
1260 1260
 			{
1261 1261
 				foreach ($contacts as &$contact)
1262 1262
 				{
1263 1263
 					$id = $contact['id'];
1264 1264
 					if (isset($cfs[$id]))
1265 1265
 					{
1266
-						foreach($cfs[$id] as $name => $value)
1266
+						foreach ($cfs[$id] as $name => $value)
1267 1267
 						{
1268 1268
 							$contact['#'.$name] = $value;
1269 1269
 						}
@@ -1275,33 +1275,33 @@  discard block
 block discarded – undo
1275 1275
 
1276 1276
 		// create a statistic about the commonness of each fields values
1277 1277
 		$fields = array();
1278
-		foreach($contacts as $contact)
1278
+		foreach ($contacts as $contact)
1279 1279
 		{
1280
-			foreach($contact as $name => $value)
1280
+			foreach ($contact as $name => $value)
1281 1281
 			{
1282
-				if (!in_array($name,$csvs))
1282
+				if (!in_array($name, $csvs))
1283 1283
 				{
1284 1284
 					$fields[$name][$value]++;
1285 1285
 				}
1286 1286
 				else
1287 1287
 				{
1288 1288
 					// for comma separated fields, we have to use each single value
1289
-					foreach(explode(',',$value) as $val)
1289
+					foreach (explode(',', $value) as $val)
1290 1290
 					{
1291 1291
 						$fields[$name][$val]++;
1292 1292
 					}
1293 1293
 				}
1294 1294
 			}
1295 1295
 		}
1296
-		foreach($fields as $name => $values)
1296
+		foreach ($fields as $name => $values)
1297 1297
 		{
1298
-			if (!in_array($name,$this->org_fields)) continue;
1298
+			if (!in_array($name, $this->org_fields)) continue;
1299 1299
 
1300
-			arsort($values,SORT_NUMERIC);
1301
-			list($value,$num) = each($values);
1302
-			if ($value && $num / (double) count($contacts) >= $this->org_common_factor)
1300
+			arsort($values, SORT_NUMERIC);
1301
+			list($value, $num) = each($values);
1302
+			if ($value && $num / (double)count($contacts) >= $this->org_common_factor)
1303 1303
 			{
1304
-				if (!in_array($name,$csvs))
1304
+				if (!in_array($name, $csvs))
1305 1305
 				{
1306 1306
 					$org[$name] = $value;
1307 1307
 				}
@@ -1310,12 +1310,12 @@  discard block
 block discarded – undo
1310 1310
 					$org[$name] = array();
1311 1311
 					foreach ($values as $value => $num)
1312 1312
 					{
1313
-						if ($value && $num / (double) count($contacts) >= $this->org_common_factor)
1313
+						if ($value && $num / (double)count($contacts) >= $this->org_common_factor)
1314 1314
 						{
1315 1315
 							$org[$name][] = $value;
1316 1316
 						}
1317 1317
 					}
1318
-					$org[$name] = implode(',',$org[$name]);
1318
+					$org[$name] = implode(',', $org[$name]);
1319 1319
 				}
1320 1320
 			}
1321 1321
 		}
@@ -1329,10 +1329,10 @@  discard block
 block discarded – undo
1329 1329
 	 * @param array $fields field-name => value pairs
1330 1330
 	 * @return array with contacts
1331 1331
 	 */
1332
-	function org_similar($org_name,$fields)
1332
+	function org_similar($org_name, $fields)
1333 1333
 	{
1334 1334
 		$criteria = array();
1335
-		foreach($this->org_fields as $name)
1335
+		foreach ($this->org_fields as $name)
1336 1336
 		{
1337 1337
 			if (isset($fields[$name]))
1338 1338
 			{
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
 				}
1347 1347
 			}
1348 1348
 		}
1349
-		return parent::search($criteria,false,'n_family,n_given','','',false,'OR',false,array('org_name'=>$org_name));
1349
+		return parent::search($criteria, false, 'n_family,n_given', '', '', false, 'OR', false, array('org_name'=>$org_name));
1350 1350
 	}
1351 1351
 
1352 1352
 	/**
@@ -1357,10 +1357,10 @@  discard block
 block discarded – undo
1357 1357
 	 * @param boolean $only_org_fields =true check and return only org_fields, default true
1358 1358
 	 * @return array with field-name => value from $from
1359 1359
 	 */
1360
-	function changed_fields($from,$to,$only_org_fields=true)
1360
+	function changed_fields($from, $to, $only_org_fields = true)
1361 1361
 	{
1362 1362
 		// we only care about countryname, if contrycode is empty
1363
-		foreach(array(
1363
+		foreach (array(
1364 1364
 			'adr_one_countryname' => 'adr_one_countrycode',
1365 1365
 			'adr_two_countryname' => 'adr_one_countrycode',
1366 1366
 		) as $name => $code)
@@ -1369,13 +1369,13 @@  discard block
 block discarded – undo
1369 1369
 			if (!empty($to[$code])) $to[$name] = '';
1370 1370
 		}
1371 1371
 		$changed = array();
1372
-		foreach($only_org_fields ? $this->org_fields : array_keys($this->contact_fields) as $name)
1372
+		foreach ($only_org_fields ? $this->org_fields : array_keys($this->contact_fields) as $name)
1373 1373
 		{
1374
-			if (in_array($name,array('modified','modifier')))	// never count these
1374
+			if (in_array($name, array('modified', 'modifier')))	// never count these
1375 1375
 			{
1376 1376
 				continue;
1377 1377
 			}
1378
-			if ((string) $from[$name] != (string) $to[$name])
1378
+			if ((string)$from[$name] != (string)$to[$name])
1379 1379
 			{
1380 1380
 				$changed[$name] = $from[$name];
1381 1381
 			}
@@ -1392,35 +1392,35 @@  discard block
 block discarded – undo
1392 1392
 	 * @param array $members =null org-members to change, default null --> function queries them itself
1393 1393
 	 * @return array/boolean (changed-members,changed-fields,failed-members) or false if no org_fields changed or no (other) members matching that fields
1394 1394
 	 */
1395
-	function change_org($org_name,$from,$to,$members=null)
1395
+	function change_org($org_name, $from, $to, $members = null)
1396 1396
 	{
1397
-		if (!($changed = $this->changed_fields($from,$to,true))) return false;
1397
+		if (!($changed = $this->changed_fields($from, $to, true))) return false;
1398 1398
 
1399 1399
 		if (is_null($members) || !is_array($members))
1400 1400
 		{
1401
-			$members = $this->org_similar($org_name,$changed);
1401
+			$members = $this->org_similar($org_name, $changed);
1402 1402
 		}
1403 1403
 		if (!$members) return false;
1404 1404
 
1405 1405
 		$ids = array();
1406
-		foreach($members as $member)
1406
+		foreach ($members as $member)
1407 1407
 		{
1408 1408
 			$ids[] = $member['id'];
1409 1409
 		}
1410 1410
 		$customfields = $this->read_customfields($ids);
1411 1411
 
1412 1412
 		$changed_members = $changed_fields = $failed_members = 0;
1413
-		foreach($members as $member)
1413
+		foreach ($members as $member)
1414 1414
 		{
1415 1415
 			if (isset($customfields[$member['id']]))
1416 1416
 			{
1417
-				foreach(array_keys($this->customfields) as $name)
1417
+				foreach (array_keys($this->customfields) as $name)
1418 1418
 				{
1419 1419
 					$member['#'.$name] = $customfields[$member['id']][$name];
1420 1420
 				}
1421 1421
 			}
1422 1422
 			$fields = 0;
1423
-			foreach($changed as $name => $value)
1423
+			foreach ($changed as $name => $value)
1424 1424
 			{
1425 1425
 				if ((string)$value == (string)$member[$name])
1426 1426
 				{
@@ -1430,7 +1430,7 @@  discard block
 block discarded – undo
1430 1430
 			}
1431 1431
 			if ($fields)
1432 1432
 			{
1433
-				if (!$this->check_perms(Acl::EDIT,$member) || !$this->save($member))
1433
+				if (!$this->check_perms(Acl::EDIT, $member) || !$this->save($member))
1434 1434
 				{
1435 1435
 					++$failed_members;
1436 1436
 				}
@@ -1441,7 +1441,7 @@  discard block
 block discarded – undo
1441 1441
 				}
1442 1442
 			}
1443 1443
 		}
1444
-		return array($changed_members,$changed_fields,$failed_members);
1444
+		return array($changed_members, $changed_fields, $failed_members);
1445 1445
 	}
1446 1446
 
1447 1447
 	/**
@@ -1468,12 +1468,12 @@  discard block
 block discarded – undo
1468 1468
 			if ($contact['n_fileas']) return $contact['n_fileas'];
1469 1469
 			$type = null;
1470 1470
 		}
1471
-		$title =  $this->fileas($contact,$type);
1471
+		$title = $this->fileas($contact, $type);
1472 1472
 		if ($this->prefs['link_title_cf'] && $contact['#'.$this->prefs['link_title_cf']])
1473 1473
 		{
1474
-			$title .= ' ' . $contact['#'.$this->prefs['link_title_cf']];
1474
+			$title .= ' '.$contact['#'.$this->prefs['link_title_cf']];
1475 1475
 		}
1476
-		return $title ;
1476
+		return $title;
1477 1477
 	}
1478 1478
 
1479 1479
 	/**
@@ -1487,21 +1487,21 @@  discard block
 block discarded – undo
1487 1487
 	function link_titles(array $ids)
1488 1488
 	{
1489 1489
 		$titles = array();
1490
-		if (($contacts =& $this->search(array('contact_id' => $ids),false)))
1490
+		if (($contacts = & $this->search(array('contact_id' => $ids), false)))
1491 1491
 		{
1492 1492
 			$ids = array();
1493
-			foreach($contacts as $contact)
1493
+			foreach ($contacts as $contact)
1494 1494
 			{
1495 1495
 				$ids[] = $contact['id'];
1496 1496
 			}
1497 1497
 			$cfs = $this->read_customfields($ids);
1498
-			foreach($contacts as $contact)
1498
+			foreach ($contacts as $contact)
1499 1499
 			{
1500
-			   	$titles[$contact['id']] = $this->link_title($contact+(array)$cfs[$contact['id']]);
1500
+			   	$titles[$contact['id']] = $this->link_title($contact + (array)$cfs[$contact['id']]);
1501 1501
 			}
1502 1502
 		}
1503 1503
 		// we assume all not returned contacts are not readable for the user (as we report all deleted contacts to egw_link)
1504
-		foreach($ids as $id)
1504
+		foreach ($ids as $id)
1505 1505
 		{
1506 1506
 			if (!isset($titles[$id]))
1507 1507
 			{
@@ -1528,23 +1528,23 @@  discard block
 block discarded – undo
1528 1528
 		{
1529 1529
 			$criteria = is_array($pattern) ? $pattern['search'] : $pattern;
1530 1530
 		}
1531
-		if($options['start'] || $options['num_rows'])
1531
+		if ($options['start'] || $options['num_rows'])
1532 1532
 		{
1533 1533
 			$limit = array($options['start'], $options['num_rows']);
1534 1534
 		}
1535 1535
 		$filter = (array)$options['filter'];
1536 1536
 		if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $filter['account_id'] = null;
1537
-		if (($contacts =& parent::search($criteria,false,'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR', $limit, $filter)))
1537
+		if (($contacts = & parent::search($criteria, false, 'org_name,n_family,n_given,cat_id,contact_email', '', '%', false, 'OR', $limit, $filter)))
1538 1538
 		{
1539 1539
 			$ids = array();
1540
-			foreach($contacts as $contact)
1540
+			foreach ($contacts as $contact)
1541 1541
 			{
1542 1542
 				$ids[] = $contact['id'];
1543 1543
 			}
1544 1544
 			$cfs = $this->read_customfields($ids);
1545
-			foreach($contacts as $contact)
1545
+			foreach ($contacts as $contact)
1546 1546
 			{
1547
-				$result[$contact['id']] = $this->link_title($contact+(array)$cfs[$contact['id']]);
1547
+				$result[$contact['id']] = $this->link_title($contact + (array)$cfs[$contact['id']]);
1548 1548
 				// make sure to return a correctly quoted rfc822 address, if requested
1549 1549
 				if ($options['type'] === 'email')
1550 1550
 				{
@@ -1585,7 +1585,7 @@  discard block
 block discarded – undo
1585 1585
 		// let link query know, to append email to list
1586 1586
 		$options['type'] = 'email';
1587 1587
 
1588
-		return $this->link_query($pattern,$options);
1588
+		return $this->link_query($pattern, $options);
1589 1589
 	}
1590 1590
 
1591 1591
 	/**
@@ -1599,7 +1599,7 @@  discard block
 block discarded – undo
1599 1599
 		if (!$ids) return null;
1600 1600
 
1601 1601
 		$data = array();
1602
-		foreach(!is_array($ids) ? array($ids) : $ids as $id)
1602
+		foreach (!is_array($ids) ? array($ids) : $ids as $id)
1603 1603
 		{
1604 1604
 			if (!($contact = $this->read($id))) continue;
1605 1605
 
@@ -1621,7 +1621,7 @@  discard block
 block discarded – undo
1621 1621
 	 * @param boolean $extra_title =true if true, use a short date only title and put the full title as extra_title (tooltip)
1622 1622
 	 * @return array
1623 1623
 	 */
1624
-	function read_calendar($uids,$extra_title=true)
1624
+	function read_calendar($uids, $extra_title = true)
1625 1625
 	{
1626 1626
 		if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return array();
1627 1627
 
@@ -1636,9 +1636,9 @@  discard block
 block discarded – undo
1636 1636
 
1637 1637
 		//_debug_array($events);
1638 1638
 		$calendars = array();
1639
-		foreach($events as $event)
1639
+		foreach ($events as $event)
1640 1640
 		{
1641
-			foreach($event['participants'] as $uid => $status)
1641
+			foreach ($event['participants'] as $uid => $status)
1642 1642
 			{
1643 1643
 				if ($status == 'R' && !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])
1644 1644
 				{
@@ -1655,13 +1655,13 @@  discard block
 block discarded – undo
1655 1655
 							'app' => 'calendar',
1656 1656
 							'title' => $bocal->link_title($event),
1657 1657
 							'extra_args' => array(
1658
-								'date' => date('Ymd',$event['start']),
1658
+								'date' => date('Ymd', $event['start']),
1659 1659
 							),
1660 1660
 						);
1661 1661
 						if ($extra_title)
1662 1662
 						{
1663 1663
 							$link['extra_title'] = $link['title'];
1664
-							$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']);
1664
+							$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $event['start']);
1665 1665
 						}
1666 1666
 						$calendars[$uid]['last_link'] = $link;
1667 1667
 					}
@@ -1676,13 +1676,13 @@  discard block
 block discarded – undo
1676 1676
 							'app' => 'calendar',
1677 1677
 							'title' => $bocal->link_title($event),
1678 1678
 							'extra_args' => array(
1679
-								'date' => date('Ymd',$event['start']),
1679
+								'date' => date('Ymd', $event['start']),
1680 1680
 							),
1681 1681
 						);
1682 1682
 						if ($extra_title)
1683 1683
 						{
1684 1684
 							$link['extra_title'] = $link['title'];
1685
-							$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']);
1685
+							$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $event['start']);
1686 1686
 						}
1687 1687
 						$calendars[$uid]['next_link'] = $link;
1688 1688
 					}
@@ -1701,8 +1701,8 @@  discard block
 block discarded – undo
1701 1701
 	 */
1702 1702
 	public function read_birthdays($addressbook, $year)
1703 1703
 	{
1704
-		$birthdays = Cache::getInstance(__CLASS__,"birthday-$year-$addressbook");
1705
-		if($birthdays !== null)
1704
+		$birthdays = Cache::getInstance(__CLASS__, "birthday-$year-$addressbook");
1705
+		if ($birthdays !== null)
1706 1706
 		{
1707 1707
 			return $birthdays;
1708 1708
 		}
@@ -1713,44 +1713,43 @@  discard block
 block discarded – undo
1713 1713
 			'n_family' => "!''",
1714 1714
 			'bday' => "!''",
1715 1715
 		);
1716
-		$bdays =& $this->search('',array('id','n_family','n_given','n_prefix','n_middle','bday'),
1717
-			'contact_bday ASC',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter);
1716
+		$bdays = & $this->search('', array('id', 'n_family', 'n_given', 'n_prefix', 'n_middle', 'bday'),
1717
+			'contact_bday ASC', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter);
1718 1718
 
1719 1719
 		if ($bdays)
1720 1720
 		{
1721 1721
 			// sort by month and day only
1722 1722
 			usort($bdays, function($a, $b)
1723 1723
 			{
1724
-				return (int) $a['bday'] == (int) $b['bday'] ?
1725
-					strcmp($a['bday'], $b['bday']) :
1726
-					(int) $a['bday'] - (int) $b['bday'];
1724
+				return (int)$a['bday'] == (int)$b['bday'] ?
1725
+					strcmp($a['bday'], $b['bday']) : (int)$a['bday'] - (int)$b['bday'];
1727 1726
 			});
1728
-			foreach($bdays as $pers)
1727
+			foreach ($bdays as $pers)
1729 1728
 			{
1730
-				if (empty($pers['bday']) || $pers['bday']=='0000-00-00 0' || $pers['bday']=='0000-00-00' || $pers['bday']=='0.0.00')
1729
+				if (empty($pers['bday']) || $pers['bday'] == '0000-00-00 0' || $pers['bday'] == '0000-00-00' || $pers['bday'] == '0.0.00')
1731 1730
 				{
1732 1731
 					//error_log(__METHOD__.__LINE__.' Skipping entry for invalid birthday:'.array2string($pers));
1733 1732
 					continue;
1734 1733
 				}
1735
-				list($y,$m,$d) = explode('-',$pers['bday']);
1734
+				list($y, $m, $d) = explode('-', $pers['bday']);
1736 1735
 				if ($y > $year)
1737 1736
 				{
1738 1737
 					// not yet born
1739 1738
 					continue;
1740 1739
 				}
1741
-				$birthdays[sprintf('%04d%02d%02d',$year,$m,$d)][] = array(
1740
+				$birthdays[sprintf('%04d%02d%02d', $year, $m, $d)][] = array(
1742 1741
 					'day'       => $d,
1743 1742
 					'month'     => $m,
1744 1743
 					'occurence' => 0,
1745 1744
 					'name'      => lang('Birthday').' '.($pers['n_given'] ? $pers['n_given'] : $pers['n_prefix']).' '.$pers['n_middle'].' '.
1746 1745
 						$pers['n_family'].
1747
-						($GLOBALS['egw_info']['server']['hide_birthdays'] == 'age' ? ' '.($year - $y): '').
1748
-						($y && in_array($GLOBALS['egw_info']['server']['hide_birthdays'], array('','age')) ? ' ('.$y.')' : ''),
1749
-					'birthyear' => $y,	// this can be used to identify birthdays from holidays
1746
+						($GLOBALS['egw_info']['server']['hide_birthdays'] == 'age' ? ' '.($year - $y) : '').
1747
+						($y && in_array($GLOBALS['egw_info']['server']['hide_birthdays'], array('', 'age')) ? ' ('.$y.')' : ''),
1748
+					'birthyear' => $y, // this can be used to identify birthdays from holidays
1750 1749
 				);
1751 1750
 			}
1752 1751
 		}
1753
-		Cache::setInstance(__CLASS__,"birthday-$year-$addressbook", $birthdays, self::BIRTHDAY_CACHE_TIME);
1752
+		Cache::setInstance(__CLASS__, "birthday-$year-$addressbook", $birthdays, self::BIRTHDAY_CACHE_TIME);
1754 1753
 		return $birthdays;
1755 1754
 	}
1756 1755
 
@@ -1773,7 +1772,7 @@  discard block
 block discarded – undo
1773 1772
 	{
1774 1773
 		// get all cats if you want to drop sub cats
1775 1774
 		$drop_subs = ($data['drop_subs'] && !$data['modify_subs']);
1776
-		if($drop_subs)
1775
+		if ($drop_subs)
1777 1776
 		{
1778 1777
 			$cats = new Categories('', 'addressbook');
1779 1778
 			$cat_ids = $cats->return_all_children($data['cat_id']);
@@ -1784,14 +1783,14 @@  discard block
 block discarded – undo
1784 1783
 		}
1785 1784
 
1786 1785
 		// Get addresses that use the category
1787
-		@set_time_limit( 0 );
1788
-		foreach($cat_ids as $cat_id)
1786
+		@set_time_limit(0);
1787
+		foreach ($cat_ids as $cat_id)
1789 1788
 		{
1790 1789
 			if (($ids = $this->search(array('cat_id' => $cat_id), false)))
1791 1790
 			{
1792
-				foreach($ids as &$info)
1791
+				foreach ($ids as &$info)
1793 1792
 				{
1794
-					$info['cat_id'] = implode(',',array_diff(explode(',',$info['cat_id']), $cat_ids));
1793
+					$info['cat_id'] = implode(',', array_diff(explode(',', $info['cat_id']), $cat_ids));
1795 1794
 					$this->save($info);
1796 1795
 				}
1797 1796
 			}
@@ -1813,14 +1812,14 @@  discard block
 block discarded – undo
1813 1812
 		$account = null;
1814 1813
 		$custom_fields = Storage\Customfields::get('addressbook', true);
1815 1814
 		$custom_field_list = $this->read_customfields($ids);
1816
-		foreach(parent::search(array('id'=>$ids),false) as $contact)	// $this->search calls the extended search from ui!
1815
+		foreach (parent::search(array('id'=>$ids), false) as $contact)	// $this->search calls the extended search from ui!
1817 1816
 		{
1818 1817
 			if ($contact['account_id'])
1819 1818
 			{
1820 1819
 				if (!is_null($account))
1821 1820
 				{
1822 1821
 					echo $this->error = 'Can not merge more then one account!';
1823
-					return false;	// we dont deal with two accounts!
1822
+					return false; // we dont deal with two accounts!
1824 1823
 				}
1825 1824
 				$account = $contact;
1826 1825
 				continue;
@@ -1828,7 +1827,7 @@  discard block
 block discarded – undo
1828 1827
 			// Add in custom fields
1829 1828
 			if (is_array($custom_field_list[$contact['id']])) $contact = array_merge($contact, $custom_field_list[$contact['id']]);
1830 1829
 
1831
-			$pos = array_search($contact['id'],$ids);
1830
+			$pos = array_search($contact['id'], $ids);
1832 1831
 			$contacts[$pos] = $contact;
1833 1832
 		}
1834 1833
 		if (!is_null($account))	// we found an account, so we merge the contacts into it
@@ -1841,38 +1840,38 @@  discard block
 block discarded – undo
1841 1840
 			$target = $contacts[0];
1842 1841
 			unset($contacts[0]);
1843 1842
 		}
1844
-		if (!$this->check_perms(Acl::EDIT,$target))
1843
+		if (!$this->check_perms(Acl::EDIT, $target))
1845 1844
 		{
1846 1845
 			echo $this->error = 'No edit permission for the target contact!';
1847 1846
 			return 0;
1848 1847
 		}
1849
-		foreach($contacts as $contact)
1848
+		foreach ($contacts as $contact)
1850 1849
 		{
1851
-			foreach($contact as $name => $value)
1850
+			foreach ($contact as $name => $value)
1852 1851
 			{
1853 1852
 				if (!$value) continue;
1854 1853
 
1855
-				switch($name)
1854
+				switch ($name)
1856 1855
 				{
1857 1856
 					case 'id':
1858 1857
 					case 'tid':
1859 1858
 					case 'owner':
1860 1859
 					case 'private':
1861 1860
 					case 'etag';
1862
-						break;	// ignored
1861
+						break; // ignored
1863 1862
 
1864 1863
 					case 'cat_id':	// cats are all merged together
1865
-						if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',',$target['cat_id']) : array();
1866
-						$target['cat_id'] = array_unique(array_merge($target['cat_id'],is_array($value)?$value:explode(',',$value)));
1864
+						if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',', $target['cat_id']) : array();
1865
+						$target['cat_id'] = array_unique(array_merge($target['cat_id'], is_array($value) ? $value : explode(',', $value)));
1867 1866
 						break;
1868 1867
 
1869 1868
 					default:
1870 1869
 						// Multi-select custom fields can also be merged
1871
-						if($name[0] == '#') {
1870
+						if ($name[0] == '#') {
1872 1871
 							$c_name = substr($name, 1);
1873
-							if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) {
1874
-								if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',',$target[$name]) : array();
1875
-								$target[$name] = implode(',',array_unique(array_merge($target[$name],is_array($value)?$value:explode(',',$value))));
1872
+							if ($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) {
1873
+								if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',', $target[$name]) : array();
1874
+								$target[$name] = implode(',', array_unique(array_merge($target[$name], is_array($value) ? $value : explode(',', $value))));
1876 1875
 							}
1877 1876
 						}
1878 1877
 						if (!$target[$name]) $target[$name] = $value;
@@ -1883,29 +1882,29 @@  discard block
 block discarded – undo
1883 1882
 		if (!$this->save($target)) return 0;
1884 1883
 
1885 1884
 		$success = 1;
1886
-		foreach($contacts as $contact)
1885
+		foreach ($contacts as $contact)
1887 1886
 		{
1888
-			if (!$this->check_perms(Acl::DELETE,$contact))
1887
+			if (!$this->check_perms(Acl::DELETE, $contact))
1889 1888
 			{
1890 1889
 				continue;
1891 1890
 			}
1892
-			foreach(Link::get_links('addressbook',$contact['id']) as $data)
1891
+			foreach (Link::get_links('addressbook', $contact['id']) as $data)
1893 1892
 			{
1894 1893
 				//_debug_array(array('function'=>__METHOD__,'line'=>__LINE__,'app'=>'addressbook','id'=>$contact['id'],'data:'=>$data,'target'=>$target['id']));
1895 1894
 				// info_from and info_link_id (main link)
1896
-				$newlinkID = Link::link('addressbook',$target['id'],$data['app'],$data['id'],$data['remark'],$target['owner']);
1895
+				$newlinkID = Link::link('addressbook', $target['id'], $data['app'], $data['id'], $data['remark'], $target['owner']);
1897 1896
 				//_debug_array(array('newLinkID'=>$newlinkID));
1898 1897
 				if ($newlinkID)
1899 1898
 				{
1900 1899
 					// update egw_infolog set info_link_id=$newlinkID where info_id=$data['id'] and info_link_id=$data['link_id']
1901
-					if ($data['app']=='infolog')
1900
+					if ($data['app'] == 'infolog')
1902 1901
 					{
1903
-						$this->db->update('egw_infolog',array(
1902
+						$this->db->update('egw_infolog', array(
1904 1903
 								'info_link_id' => $newlinkID
1905
-							),array(
1904
+							), array(
1906 1905
 								'info_id' => $data['id'],
1907 1906
 								'info_link_id' => $data['link_id']
1908
-							),__LINE__,__FILE__,'infolog');
1907
+							), __LINE__, __FILE__, 'infolog');
1909 1908
 					}
1910 1909
 					unset($newlinkID);
1911 1910
 				}
@@ -1930,14 +1929,14 @@  discard block
 block discarded – undo
1930 1929
 	 * @param int $owner =null
1931 1930
 	 * @return boolean
1932 1931
 	 */
1933
-	function check_list($list,$required,$owner=null)
1932
+	function check_list($list, $required, $owner = null)
1934 1933
 	{
1935 1934
 		if ($list && ($list_data = $this->read_list($list)))
1936 1935
 		{
1937 1936
 			$owner = $list_data['list_owner'];
1938 1937
 		}
1939 1938
 		//error_log(__METHOD__."($list, $required, $owner) grants[$owner]=".$this->grants[$owner]." returning ".array2string(!!($this->grants[$owner] & $required)));
1940
-		return !!($this->grants[$owner] & $required);
1939
+		return !!($this->grants[$owner]&$required);
1941 1940
 	}
1942 1941
 
1943 1942
 	/**
@@ -1949,17 +1948,17 @@  discard block
 block discarded – undo
1949 1948
 	 * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name'
1950 1949
 	 * @return int|boolean integer list_id or false on error
1951 1950
 	 */
1952
-	function add_list($keys,$owner,$contacts=array(),array &$data=array())
1951
+	function add_list($keys, $owner, $contacts = array(), array &$data = array())
1953 1952
 	{
1954
-		if (!$this->check_list(null,Acl::ADD|Acl::EDIT,$owner)) return false;
1953
+		if (!$this->check_list(null, Acl::ADD|Acl::EDIT, $owner)) return false;
1955 1954
 
1956 1955
 		try {
1957
-			$ret = parent::add_list($keys,$owner,$contacts,$data);
1956
+			$ret = parent::add_list($keys, $owner, $contacts, $data);
1958 1957
 			if ($ret) unset(self::$list_cache[$ret]);
1959 1958
 		}
1960 1959
 		// catch sql error, as creating same name&owner list gives a sql error doublicate key
1961
-		catch(Api\Db\Exception\InvalidSql $e) {
1962
-			unset($e);	// not used
1960
+		catch (Api\Db\Exception\InvalidSql $e) {
1961
+			unset($e); // not used
1963 1962
 			return false;
1964 1963
 		}
1965 1964
 		return $ret;
@@ -1973,13 +1972,13 @@  discard block
 block discarded – undo
1973 1972
 	 * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array()
1974 1973
 	 * @return false on error
1975 1974
 	 */
1976
-	function add2list($contact,$list,array $existing=null)
1975
+	function add2list($contact, $list, array $existing = null)
1977 1976
 	{
1978
-		if (!$this->check_list($list,Acl::EDIT)) return false;
1977
+		if (!$this->check_list($list, Acl::EDIT)) return false;
1979 1978
 
1980 1979
 		unset(self::$list_cache[$list]);
1981 1980
 
1982
-		return parent::add2list($contact,$list,$existing);
1981
+		return parent::add2list($contact, $list, $existing);
1983 1982
 	}
1984 1983
 
1985 1984
 	/**
@@ -1989,9 +1988,9 @@  discard block
 block discarded – undo
1989 1988
 	 * @param int $list list-id
1990 1989
 	 * @return false on error
1991 1990
 	 */
1992
-	function remove_from_list($contact,$list=null)
1991
+	function remove_from_list($contact, $list = null)
1993 1992
 	{
1994
-		if ($list && !$this->check_list($list,Acl::EDIT)) return false;
1993
+		if ($list && !$this->check_list($list, Acl::EDIT)) return false;
1995 1994
 
1996 1995
 		if ($list)
1997 1996
 		{
@@ -2002,7 +2001,7 @@  discard block
 block discarded – undo
2002 2001
 			self::$list_cache = array();
2003 2002
 		}
2004 2003
 
2005
-		return parent::remove_from_list($contact,$list);
2004
+		return parent::remove_from_list($contact, $list);
2006 2005
 	}
2007 2006
 
2008 2007
 	/**
@@ -2013,9 +2012,9 @@  discard block
 block discarded – undo
2013 2012
 	 */
2014 2013
 	function delete_list($list)
2015 2014
 	{
2016
-		if (!$this->check_list($list,Acl::DELETE)) return false;
2015
+		if (!$this->check_list($list, Acl::DELETE)) return false;
2017 2016
 
2018
-		foreach((array)$list as $l)
2017
+		foreach ((array)$list as $l)
2019 2018
 		{
2020 2019
 			unset(self::$list_cache[$l]);
2021 2020
 		}
@@ -2051,7 +2050,7 @@  discard block
 block discarded – undo
2051 2050
 	{
2052 2051
 		$code = Country::country_code($country);
2053 2052
 
2054
-		switch($code)
2053
+		switch ($code)
2055 2054
 		{
2056 2055
 			case 'AU':
2057 2056
 			case 'CA':
@@ -2115,12 +2114,12 @@  discard block
 block discarded – undo
2115 2114
 	 *  by the ones the user normally does not see due to category permissions - used to preserve categories
2116 2115
 	 * @return array category ids (found, added and preserved categories)
2117 2116
 	 */
2118
-	function find_or_add_categories($catname_list, $contact_id=null)
2117
+	function find_or_add_categories($catname_list, $contact_id = null)
2119 2118
 	{
2120 2119
 		if ($contact_id && $contact_id > 0 && ($old_contact = $this->read($contact_id)))
2121 2120
 		{
2122 2121
 			// preserve categories without users read access
2123
-			$old_categories = explode(',',$old_contact['cat_id']);
2122
+			$old_categories = explode(',', $old_contact['cat_id']);
2124 2123
 			$old_cats_preserve = array();
2125 2124
 			if (is_array($old_categories) && count($old_categories) > 0)
2126 2125
 			{
@@ -2174,15 +2173,15 @@  discard block
 block discarded – undo
2174 2173
 	{
2175 2174
 		if (!is_object($this->categories))
2176 2175
 		{
2177
-			$this->categories = new Categories($this->user,'addressbook');
2176
+			$this->categories = new Categories($this->user, 'addressbook');
2178 2177
 		}
2179 2178
 
2180 2179
 		if (!is_array($cat_id_list))
2181 2180
 		{
2182
-			$cat_id_list = explode(',',$cat_id_list);
2181
+			$cat_id_list = explode(',', $cat_id_list);
2183 2182
 		}
2184 2183
 		$cat_list = array();
2185
-		foreach($cat_id_list as $cat_id)
2184
+		foreach ($cat_id_list as $cat_id)
2186 2185
 		{
2187 2186
 			if ($cat_id && $this->categories->check_perms(Acl::READ, $cat_id) &&
2188 2187
 					($cat_name = $this->categories->id2name($cat_id)) && $cat_name != '--')
@@ -2214,14 +2213,14 @@  discard block
 block discarded – undo
2214 2213
 	 * @param boolean $relax =false if asked to relax, we only match against some key fields
2215 2214
 	 * @return array od matching contact_ids
2216 2215
 	 */
2217
-	function find_contact($contact, $relax=false)
2216
+	function find_contact($contact, $relax = false)
2218 2217
 	{
2219 2218
 		$empty_addr_one = $empty_addr_two = true;
2220 2219
 
2221 2220
 		if ($this->log)
2222 2221
 		{
2223 2222
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2224
-				. '('. ($relax ? 'RELAX': 'EXACT') . ')[ContactData]:'
2223
+				. '('.($relax ? 'RELAX' : 'EXACT').')[ContactData]:'
2225 2224
 				. array2string($contact)
2226 2225
 				. "\n", 3, $this->logfile);
2227 2226
 		}
@@ -2232,7 +2231,7 @@  discard block
 block discarded – undo
2232 2231
 			if ($this->log)
2233 2232
 			{
2234 2233
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2235
-					. '()[ContactID]: ' . $contact['id']
2234
+					. '()[ContactID]: '.$contact['id']
2236 2235
 					. "\n", 3, $this->logfile);
2237 2236
 			}
2238 2237
 			// We only do a simple consistency check
@@ -2250,11 +2249,11 @@  discard block
 block discarded – undo
2250 2249
 			if ($this->log)
2251 2250
 			{
2252 2251
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2253
-					. '()[ContactUID]: ' . $contact['uid']
2252
+					. '()[ContactUID]: '.$contact['uid']
2254 2253
 					. "\n", 3, $this->logfile);
2255 2254
 			}
2256 2255
 			// Try the given UID first
2257
-			$criteria = array ('contact_uid' => $contact['uid']);
2256
+			$criteria = array('contact_uid' => $contact['uid']);
2258 2257
 			if (($foundContacts = parent::search($criteria)))
2259 2258
 			{
2260 2259
 				foreach ($foundContacts as $egwContact)
@@ -2337,7 +2336,7 @@  discard block
 block discarded – undo
2337 2336
 		{
2338 2337
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2339 2338
 				. '()[Addressbook FIND Step 1]: '
2340
-				. 'CRITERIA = ' . array2string($criteria)
2339
+				. 'CRITERIA = '.array2string($criteria)
2341 2340
 				. "\n", 3, $this->logfile);
2342 2341
 		}
2343 2342
 
@@ -2366,7 +2365,7 @@  discard block
 block discarded – undo
2366 2365
 			{
2367 2366
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2368 2367
 					. '()[Addressbook FIND Step 2]: '
2369
-					. 'CRITERIA = ' . array2string($criteria)
2368
+					. 'CRITERIA = '.array2string($criteria)
2370 2369
 					. "\n", 3, $this->logfile);
2371 2370
 			}
2372 2371
 
@@ -2390,7 +2389,7 @@  discard block
 block discarded – undo
2390 2389
 				{
2391 2390
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2392 2391
 						. '()[Addressbook FIND Step 3]: '
2393
-						. 'CRITERIA = ' . array2string($criteria)
2392
+						. 'CRITERIA = '.array2string($criteria)
2394 2393
 						. "\n", 3, $this->logfile);
2395 2394
 				}
2396 2395
 
@@ -2416,7 +2415,7 @@  discard block
 block discarded – undo
2416 2415
 			{
2417 2416
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2418 2417
 					. '()[Addressbook FIND Step 4]: '
2419
-					. 'CRITERIA = ' . array2string($criteria)
2418
+					. 'CRITERIA = '.array2string($criteria)
2420 2419
 					. "\n", 3, $this->logfile);
2421 2420
 			}
2422 2421
 			if (($foundContacts = parent::search($criteria, true, '', '', '', true)))
@@ -2430,7 +2429,7 @@  discard block
 block discarded – undo
2430 2429
 		if ($this->log)
2431 2430
 		{
2432 2431
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2433
-				. '()[FOUND]: ' . array2string($matchingContacts)
2432
+				. '()[FOUND]: '.array2string($matchingContacts)
2434 2433
 				. "\n", 3, $this->logfile);
2435 2434
 		}
2436 2435
 		return $matchingContacts;
@@ -2447,9 +2446,9 @@  discard block
 block discarded – undo
2447 2446
 	 * @param int|array $owner =null 0=accounts, null=all addressbooks or integer account_id of user or group
2448 2447
 	 * @return string
2449 2448
 	 */
2450
-	public function get_ctag($owner=null)
2449
+	public function get_ctag($owner = null)
2451 2450
 	{
2452
-		$filter = array('tid' => null);	// tid=null --> use all entries incl. deleted (tid='D')
2451
+		$filter = array('tid' => null); // tid=null --> use all entries incl. deleted (tid='D')
2453 2452
 		// show addressbook of a single user?
2454 2453
 		if (!is_null($owner)) $filter['owner'] = $owner;
2455 2454
 
@@ -2458,11 +2457,11 @@  discard block
 block discarded – undo
2458 2457
 		{
2459 2458
 			$filter['account_id'] = null;
2460 2459
 		}
2461
-		$result = $this->search(array(),'contact_modified','contact_modified DESC','','',false,'AND',array(0,1),$filter);
2460
+		$result = $this->search(array(), 'contact_modified', 'contact_modified DESC', '', '', false, 'AND', array(0, 1), $filter);
2462 2461
 
2463 2462
 		if (!$result || !isset($result[0]['modified']))
2464 2463
 		{
2465
-			$ctag = 'empty';	// ctag for empty addressbook
2464
+			$ctag = 'empty'; // ctag for empty addressbook
2466 2465
 		}
2467 2466
 		else
2468 2467
 		{
Please login to merge, or discard this patch.