Completed
Push — 16.1 ( 7ccc73...046888 )
by Nathan
64:46 queued 51:15
created
api/src/WebDAV/Server/Filesystem.php 6 patches
Doc Comments   +11 added lines, -9 removed lines patch added patch discarded remove patch
@@ -254,6 +254,7 @@  discard block
 block discarded – undo
254 254
      *
255 255
      * @param  string  program name
256 256
      * @param  string  optional search path, defaults to $PATH
257
+     * @param string $name
257 258
      * @return bool    true if executable program found in path
258 259
      */
259 260
     function _can_execute($name, $path = false)
@@ -319,6 +320,7 @@  discard block
 block discarded – undo
319 320
      * try to detect the mime type of a file
320 321
      *
321 322
      * @param  string  file path
323
+     * @param string $fspath
322 324
      * @return string  guessed mime type
323 325
      */
324 326
     function _mimetype($fspath)
@@ -416,7 +418,7 @@  discard block
 block discarded – undo
416 418
      * GET method handler
417 419
      *
418 420
      * @param  array  parameter passing array
419
-     * @return bool   true on success
421
+     * @return null|boolean   true on success
420 422
      */
421 423
     function GET(&$options)
422 424
     {
@@ -446,7 +448,7 @@  discard block
 block discarded – undo
446 448
      * See RFC 2518, Section 8.4 on GET/HEAD for collections
447 449
      *
448 450
      * @param  string  directory path
449
-     * @return void    function has to handle HTTP response itself
451
+     * @return null|false    function has to handle HTTP response itself
450 452
      */
451 453
     function GetDir($fspath, &$options)
452 454
     {
@@ -533,7 +535,7 @@  discard block
 block discarded – undo
533 535
      * MKCOL method handler
534 536
      *
535 537
      * @param  array  general parameter passing array
536
-     * @return bool   true on success
538
+     * @return string   true on success
537 539
      */
538 540
     function MKCOL($options)
539 541
     {
@@ -570,7 +572,7 @@  discard block
 block discarded – undo
570 572
      * DELETE method handler
571 573
      *
572 574
      * @param  array  general parameter passing array
573
-     * @return bool   true on success
575
+     * @return string   true on success
574 576
      */
575 577
     function DELETE($options)
576 578
     {
@@ -600,7 +602,7 @@  discard block
 block discarded – undo
600 602
      * MOVE method handler
601 603
      *
602 604
      * @param  array  general parameter passing array
603
-     * @return bool   true on success
605
+     * @return string   true on success
604 606
      */
605 607
     function MOVE($options)
606 608
     {
@@ -611,7 +613,7 @@  discard block
 block discarded – undo
611 613
      * COPY method handler
612 614
      *
613 615
      * @param  array  general parameter passing array
614
-     * @return bool   true on success
616
+     * @return string   true on success
615 617
      */
616 618
     function COPY($options, $del=false)
617 619
     {
@@ -751,7 +753,7 @@  discard block
 block discarded – undo
751 753
      * PROPPATCH method handler
752 754
      *
753 755
      * @param  array  general parameter passing array
754
-     * @return bool   true on success
756
+     * @return string   true on success
755 757
      */
756 758
     function PROPPATCH(&$options)
757 759
     {
@@ -790,7 +792,7 @@  discard block
 block discarded – undo
790 792
      * LOCK method handler
791 793
      *
792 794
      * @param  array  general parameter passing array
793
-     * @return bool   true on success
795
+     * @return string|boolean   true on success
794 796
      */
795 797
     function LOCK(&$options)
796 798
     {
@@ -848,7 +850,7 @@  discard block
 block discarded – undo
848 850
      * UNLOCK method handler
849 851
      *
850 852
      * @param  array  general parameter passing array
851
-     * @return bool   true on success
853
+     * @return string   true on success
852 854
      */
853 855
     function UNLOCK(&$options)
854 856
     {
Please login to merge, or discard this patch.
Indentation   +827 added lines, -827 removed lines patch added patch discarded remove patch
@@ -44,793 +44,793 @@  discard block
 block discarded – undo
44 44
  */
45 45
 class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server
46 46
 {
47
-    /**
48
-     * Root directory for WebDAV access
49
-     *
50
-     * Defaults to webserver document root (set by ServeRequest)
51
-     *
52
-     * @access private
53
-     * @var    string
54
-     */
55
-    var $base = "";
56
-
57
-    /**
58
-     * MySQL Host where property and locking information is stored
59
-     *
60
-     * @access private
61
-     * @var    string
62
-     */
63
-    var $db_host = "localhost";
64
-
65
-    /**
66
-     * MySQL database for property/locking information storage
67
-     *
68
-     * @access private
69
-     * @var    string
70
-     */
71
-    var $db_name = "webdav";
72
-
73
-    /**
74
-     * MySQL table name prefix
75
-     *
76
-     * @access private
77
-     * @var    string
78
-     */
79
-    var $db_prefix = "";
80
-
81
-    /**
82
-     * MySQL user for property/locking db access
83
-     *
84
-     * @access private
85
-     * @var    string
86
-     */
87
-    var $db_user = "root";
88
-
89
-    /**
90
-     * MySQL password for property/locking db access
91
-     *
92
-     * @access private
93
-     * @var    string
94
-     */
95
-    var $db_passwd = "";
96
-
97
-    /**
98
-     * Serve a webdav request
99
-     *
100
-     * @access public
101
-     * @param  string
102
-     */
103
-    function ServeRequest($base = false)
104
-    {
105
-        // special treatment for litmus compliance test
106
-        // reply on its identifier header
107
-        // not needed for the test itself but eases debugging
108
-        if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
109
-            error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110
-            header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111
-        }
112
-
113
-        // set root directory, defaults to webserver document root if not set
114
-        if ($base) {
115
-            $this->base = realpath($base); // TODO throw if not a directory
116
-        } else if (!$this->base) {
117
-            $this->base = $this->_SERVER['DOCUMENT_ROOT'];
118
-        }
119
-
120
-        // establish connection to property/locking db
121
-        mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error());
122
-        mysql_select_db($this->db_name) or die(mysql_error());
123
-        // TODO throw on connection problems
124
-
125
-        // let the base class do all the work
126
-        parent::ServeRequest();
127
-    }
128
-
129
-    /**
130
-     * No authentication is needed here
131
-     *
132
-     * @access private
133
-     * @param  string  HTTP Authentication type (Basic, Digest, ...)
134
-     * @param  string  Username
135
-     * @param  string  Password
136
-     * @return bool    true on successful authentication
137
-     */
138
-    function check_auth($type, $user, $pass)
139
-    {
140
-        return true;
141
-    }
142
-
143
-
144
-    /**
145
-     * PROPFIND method handler
146
-     *
147
-     * @param  array  general parameter passing array
148
-     * @param  array  return array for file properties
149
-     * @return bool   true on success
150
-     */
151
-    function PROPFIND(&$options, &$files)
152
-    {
153
-        // get absolute fs path to requested resource
154
-        $fspath = $this->base . $options["path"];
155
-
156
-        // sanity check
157
-        if (!file_exists($fspath)) {
158
-            return false;
159
-        }
160
-
161
-        // prepare property array
162
-        $files["files"] = array();
163
-
164
-        // store information for the requested path itself
165
-        $files["files"][] = $this->fileinfo($options["path"]);
166
-
167
-        // information for contained resources requested?
168
-        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
169
-
170
-            // make sure path ends with '/'
171
-            $options["path"] = $this->_slashify($options["path"]);
172
-
173
-            // try to open directory
174
-            $handle = opendir($fspath);
175
-
176
-            if ($handle) {
177
-                // ok, now get all its contents
178
-                while ($filename = readdir($handle)) {
179
-                    if ($filename != "." && $filename != "..") {
180
-                        $files["files"][] = $this->fileinfo($options["path"].$filename);
181
-                    }
182
-                }
183
-                // TODO recursion needed if "Depth: infinite"
184
-            	closedir($handle);
185
-            }
186
-        }
187
-
188
-        // ok, all done
189
-        return true;
190
-    }
191
-
192
-    /**
193
-     * Get properties for a single file/resource
194
-     *
195
-     * @param  string  resource path
196
-     * @return array   resource properties
197
-     */
198
-    function fileinfo($path)
199
-    {
200
-        // map URI path to filesystem path
201
-        $fspath = $this->base . $path;
202
-
203
-        // create result array
204
-        $info = array();
205
-        // TODO remove slash append code when base clase is able to do it itself
206
-        $info["path"]  = is_dir($fspath) ? $this->_slashify($path) : $path;
207
-        $info["props"] = array();
208
-
209
-        // no special beautified displayname here ...
210
-        $info["props"][] = $this->mkprop("displayname", strtoupper($path));
211
-
212
-        // creation and modification time
213
-        $info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
214
-        $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215
-
216
-        // Microsoft extensions: last access time and 'hidden' status
217
-        $info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
218
-        $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219
-
220
-        // type and size (caller already made sure that path exists)
221
-        if (is_dir($fspath)) {
222
-            // directory (WebDAV collection)
223
-            $info["props"][] = $this->mkprop("resourcetype", "collection");
224
-            $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
-        } else {
226
-            // plain file (WebDAV resource)
227
-            $info["props"][] = $this->mkprop("resourcetype", "");
228
-            if ($this->_is_readable($fspath)) {
229
-                $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
-            } else {
231
-                $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232
-            }
233
-            $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
234
-        }
235
-
236
-        // get additional properties from database
237
-        $query = "SELECT ns, name, value
47
+	/**
48
+	 * Root directory for WebDAV access
49
+	 *
50
+	 * Defaults to webserver document root (set by ServeRequest)
51
+	 *
52
+	 * @access private
53
+	 * @var    string
54
+	 */
55
+	var $base = "";
56
+
57
+	/**
58
+	 * MySQL Host where property and locking information is stored
59
+	 *
60
+	 * @access private
61
+	 * @var    string
62
+	 */
63
+	var $db_host = "localhost";
64
+
65
+	/**
66
+	 * MySQL database for property/locking information storage
67
+	 *
68
+	 * @access private
69
+	 * @var    string
70
+	 */
71
+	var $db_name = "webdav";
72
+
73
+	/**
74
+	 * MySQL table name prefix
75
+	 *
76
+	 * @access private
77
+	 * @var    string
78
+	 */
79
+	var $db_prefix = "";
80
+
81
+	/**
82
+	 * MySQL user for property/locking db access
83
+	 *
84
+	 * @access private
85
+	 * @var    string
86
+	 */
87
+	var $db_user = "root";
88
+
89
+	/**
90
+	 * MySQL password for property/locking db access
91
+	 *
92
+	 * @access private
93
+	 * @var    string
94
+	 */
95
+	var $db_passwd = "";
96
+
97
+	/**
98
+	 * Serve a webdav request
99
+	 *
100
+	 * @access public
101
+	 * @param  string
102
+	 */
103
+	function ServeRequest($base = false)
104
+	{
105
+		// special treatment for litmus compliance test
106
+		// reply on its identifier header
107
+		// not needed for the test itself but eases debugging
108
+		if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
109
+			error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110
+			header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111
+		}
112
+
113
+		// set root directory, defaults to webserver document root if not set
114
+		if ($base) {
115
+			$this->base = realpath($base); // TODO throw if not a directory
116
+		} else if (!$this->base) {
117
+			$this->base = $this->_SERVER['DOCUMENT_ROOT'];
118
+		}
119
+
120
+		// establish connection to property/locking db
121
+		mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error());
122
+		mysql_select_db($this->db_name) or die(mysql_error());
123
+		// TODO throw on connection problems
124
+
125
+		// let the base class do all the work
126
+		parent::ServeRequest();
127
+	}
128
+
129
+	/**
130
+	 * No authentication is needed here
131
+	 *
132
+	 * @access private
133
+	 * @param  string  HTTP Authentication type (Basic, Digest, ...)
134
+	 * @param  string  Username
135
+	 * @param  string  Password
136
+	 * @return bool    true on successful authentication
137
+	 */
138
+	function check_auth($type, $user, $pass)
139
+	{
140
+		return true;
141
+	}
142
+
143
+
144
+	/**
145
+	 * PROPFIND method handler
146
+	 *
147
+	 * @param  array  general parameter passing array
148
+	 * @param  array  return array for file properties
149
+	 * @return bool   true on success
150
+	 */
151
+	function PROPFIND(&$options, &$files)
152
+	{
153
+		// get absolute fs path to requested resource
154
+		$fspath = $this->base . $options["path"];
155
+
156
+		// sanity check
157
+		if (!file_exists($fspath)) {
158
+			return false;
159
+		}
160
+
161
+		// prepare property array
162
+		$files["files"] = array();
163
+
164
+		// store information for the requested path itself
165
+		$files["files"][] = $this->fileinfo($options["path"]);
166
+
167
+		// information for contained resources requested?
168
+		if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
169
+
170
+			// make sure path ends with '/'
171
+			$options["path"] = $this->_slashify($options["path"]);
172
+
173
+			// try to open directory
174
+			$handle = opendir($fspath);
175
+
176
+			if ($handle) {
177
+				// ok, now get all its contents
178
+				while ($filename = readdir($handle)) {
179
+					if ($filename != "." && $filename != "..") {
180
+						$files["files"][] = $this->fileinfo($options["path"].$filename);
181
+					}
182
+				}
183
+				// TODO recursion needed if "Depth: infinite"
184
+				closedir($handle);
185
+			}
186
+		}
187
+
188
+		// ok, all done
189
+		return true;
190
+	}
191
+
192
+	/**
193
+	 * Get properties for a single file/resource
194
+	 *
195
+	 * @param  string  resource path
196
+	 * @return array   resource properties
197
+	 */
198
+	function fileinfo($path)
199
+	{
200
+		// map URI path to filesystem path
201
+		$fspath = $this->base . $path;
202
+
203
+		// create result array
204
+		$info = array();
205
+		// TODO remove slash append code when base clase is able to do it itself
206
+		$info["path"]  = is_dir($fspath) ? $this->_slashify($path) : $path;
207
+		$info["props"] = array();
208
+
209
+		// no special beautified displayname here ...
210
+		$info["props"][] = $this->mkprop("displayname", strtoupper($path));
211
+
212
+		// creation and modification time
213
+		$info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
214
+		$info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215
+
216
+		// Microsoft extensions: last access time and 'hidden' status
217
+		$info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
218
+		$info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219
+
220
+		// type and size (caller already made sure that path exists)
221
+		if (is_dir($fspath)) {
222
+			// directory (WebDAV collection)
223
+			$info["props"][] = $this->mkprop("resourcetype", "collection");
224
+			$info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
+		} else {
226
+			// plain file (WebDAV resource)
227
+			$info["props"][] = $this->mkprop("resourcetype", "");
228
+			if ($this->_is_readable($fspath)) {
229
+				$info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
+			} else {
231
+				$info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232
+			}
233
+			$info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
234
+		}
235
+
236
+		// get additional properties from database
237
+		$query = "SELECT ns, name, value
238 238
                         FROM {$this->db_prefix}properties
239 239
                        WHERE path = '$path'";
240
-        $res = mysql_query($query);
241
-        while ($row = mysql_fetch_assoc($res)) {
242
-            $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243
-        }
244
-        mysql_free_result($res);
245
-
246
-        return $info;
247
-    }
248
-
249
-    /**
250
-     * detect if a given program is found in the search PATH
251
-     *
252
-     * helper function used by _mimetype() to detect if the
253
-     * external 'file' utility is available
254
-     *
255
-     * @param  string  program name
256
-     * @param  string  optional search path, defaults to $PATH
257
-     * @return bool    true if executable program found in path
258
-     */
259
-    function _can_execute($name, $path = false)
260
-    {
261
-        // path defaults to PATH from environment if not set
262
-        if ($path === false) {
263
-            $path = getenv("PATH");
264
-        }
265
-
266
-        // check method depends on operating system
267
-        if (!strncmp(PHP_OS, "WIN", 3)) {
268
-            // on Windows an appropriate COM or EXE file needs to exist
269
-            $exts     = array(".exe", ".com");
270
-            $check_fn = "file_exists";
271
-        } else {
272
-            // anywhere else we look for an executable file of that name
273
-            $exts     = array("");
274
-            $check_fn = "is_executable";
275
-        }
276
-
277
-        // now check the directories in the path for the program
278
-        foreach (explode(PATH_SEPARATOR, $path) as $dir) {
279
-            // skip invalid path entries
280
-            if (!file_exists($dir)) continue;
281
-            if (!is_dir($dir)) continue;
282
-
283
-            // and now look for the file
284
-            foreach ($exts as $ext) {
285
-                if ($check_fn("$dir/$name".$ext)) return true;
286
-            }
287
-        }
288
-
289
-        return false;
290
-    }
291
-
292
-    /**
293
-     * Check if path is readable by current user
294
-     *
295
-     * Allow extending classes to overwrite it
296
-     *
297
-     * @param string $fspath
298
-     * @return boolean
299
-     */
300
-    function _is_readable($fspath)
301
-    {
302
-    	return is_readable($fspath);
303
-    }
304
-
305
-    /**
306
-     * Check if path is writable by current user
307
-     *
308
-     * Allow extending classes to overwrite it
309
-     *
310
-     * @param string $fspath
311
-     * @return boolean
312
-     */
313
-    function _is_writable($fspath)
314
-    {
315
-    	return is_writable($fspath);
316
-    }
317
-
318
-    /**
319
-     * try to detect the mime type of a file
320
-     *
321
-     * @param  string  file path
322
-     * @return string  guessed mime type
323
-     */
324
-    function _mimetype($fspath)
325
-    {
326
-        if (is_dir($fspath)) {
327
-            // directories are easy
328
-            return "httpd/unix-directory";
329
-        } else if (function_exists("mime_content_type")) {
330
-            // use mime magic extension if available
331
-            $mime_type = mime_content_type($fspath);
332
-        } else if ($this->_can_execute("file")) {
333
-            // it looks like we have a 'file' command,
334
-            // lets see it it does have mime support
335
-            $fp    = popen("file -i '$fspath' 2>/dev/null", "r");
336
-            $reply = fgets($fp);
337
-            pclose($fp);
338
-
339
-            // popen will not return an error if the binary was not found
340
-            // and find may not have mime support using "-i"
341
-            // so we test the format of the returned string
342
-
343
-            // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
-                $reply = substr($reply, strlen($fspath)+2);
346
-                // followed by the mime type (maybe including options)
347
-                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348
-                    $mime_type = $matches[0];
349
-                }
350
-            }
351
-        }
352
-
353
-        if (empty($mime_type)) {
354
-            // Fallback solution: try to guess the type by the file extension
355
-            // TODO: add more ...
356
-            // TODO: it has been suggested to delegate mimetype detection
357
-            //       to apache but this has at least three issues:
358
-            //       - works only with apache
359
-            //       - needs file to be within the document tree
360
-            //       - requires apache mod_magic
361
-            // TODO: can we use the registry for this on Windows?
362
-            //       OTOH if the server is Windos the clients are likely to
363
-            //       be Windows, too, and tend do ignore the Content-Type
364
-            //       anyway (overriding it with information taken from
365
-            //       the registry)
366
-            // TODO: have a seperate PEAR class for mimetype detection?
367
-            switch (strtolower(strrchr(basename($fspath), "."))) {
368
-            case ".html":
369
-                $mime_type = "text/html";
370
-                break;
371
-            case ".gif":
372
-                $mime_type = "image/gif";
373
-                break;
374
-            case ".jpg":
375
-                $mime_type = "image/jpeg";
376
-                break;
377
-            default:
378
-                $mime_type = "application/octet-stream";
379
-                break;
380
-            }
381
-        }
382
-
383
-        return $mime_type;
384
-    }
385
-
386
-    /**
387
-     * HEAD method handler
388
-     *
389
-     * @param  array  parameter passing array
390
-     * @return bool   true on success
391
-     */
392
-    function HEAD(&$options)
393
-    {
394
-        // get absolute fs path to requested resource
395
-        $fspath = $this->base . $options["path"];
396
-
397
-        // sanity check
398
-        if (!file_exists($fspath)) return false;
399
-
400
-        // detect resource type
401
-        $options['mimetype'] = $this->_mimetype($fspath);
402
-
403
-        // detect modification time
404
-        // see rfc2518, section 13.7
405
-        // some clients seem to treat this as a reverse rule
406
-        // requiering a Last-Modified header if the getlastmodified header was set
407
-        $options['mtime'] = filemtime($fspath);
408
-
409
-        // detect resource size
410
-        $options['size'] = filesize($fspath);
411
-
412
-        return true;
413
-    }
414
-
415
-    /**
416
-     * GET method handler
417
-     *
418
-     * @param  array  parameter passing array
419
-     * @return bool   true on success
420
-     */
421
-    function GET(&$options)
422
-    {
423
-        // get absolute fs path to requested resource
424
-        $fspath = $this->base . $options["path"];
425
-
426
-        // is this a collection?
427
-        if (is_dir($fspath)) {
428
-            return $this->GetDir($fspath, $options);
429
-        }
430
-
431
-        // the header output is the same as for HEAD
432
-        if (!$this->HEAD($options)) {
433
-            return false;
434
-        }
435
-
436
-        // no need to check result here, it is handled by the base class
437
-        $options['stream'] = fopen($fspath, "r");
438
-
439
-        return true;
440
-    }
441
-
442
-    /**
443
-     * GET method handler for directories
444
-     *
445
-     * This is a very simple mod_index lookalike.
446
-     * See RFC 2518, Section 8.4 on GET/HEAD for collections
447
-     *
448
-     * @param  string  directory path
449
-     * @return void    function has to handle HTTP response itself
450
-     */
451
-    function GetDir($fspath, &$options)
452
-    {
453
-        $path = $this->_slashify($options["path"]);
454
-        if ($path != $options["path"]) {
455
-            header("Location: ".$this->base_uri.$path);
456
-            exit;
457
-        }
458
-
459
-        // fixed width directory column format
460
-        $format = "%15s  %-19s  %-s\n";
461
-
462
-        if (!$this->_is_readable($fspath)) {
463
-            return false;
464
-        }
465
-
466
-        $handle = opendir($fspath);
467
-        if (!$handle) {
468
-            return false;
469
-        }
470
-
471
-        echo "<html><head><title>Index of ".htmlspecialchars(urldecode($options['path']))."</title></head>\n";
472
-
473
-        echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n";
474
-
475
-        echo "<pre>";
476
-        printf($format, "Size", "Last modified", "Filename");
477
-        echo "<hr>";
478
-
479
-        while ($filename = readdir($handle)) {
480
-            if ($filename != "." && $filename != "..") {
481
-                $fullpath = $fspath.$filename;
482
-                $name     = htmlspecialchars($filename);
483
-                printf($format,
484
-                       number_format(filesize($fullpath)),
485
-                       strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)),
486
-                       '<a href="'.$name.'">'.urldecode($name).'</a>');
487
-            }
488
-        }
489
-
490
-        echo "</pre>";
491
-
492
-        closedir($handle);
493
-
494
-        echo "</html>\n";
495
-
496
-        exit;
497
-    }
498
-
499
-    /**
500
-     * PUT method handler
501
-     *
502
-     * @param  array  parameter passing array
503
-     * @return bool   true on success
504
-     */
505
-    function PUT(&$options)
506
-    {
507
-        $fspath = $this->base . $options["path"];
508
-
509
-        $dir = dirname($fspath);
510
-        if (!file_exists($dir) || !is_dir($dir)) {
511
-            return "409 Conflict"; // TODO right status code for both?
512
-        }
513
-
514
-        $options["new"] = ! file_exists($fspath);
515
-
516
-        if ($options["new"] && !$this->_is_writable($dir)) {
517
-            return "403 Forbidden";
518
-        }
519
-        if (!$options["new"] && !$this->_is_writable($fspath)) {
520
-            return "403 Forbidden";
521
-        }
522
-        if (!$options["new"] && is_dir($fspath)) {
523
-            return "403 Forbidden";
524
-        }
525
-
526
-        $fp = fopen($fspath, "w");
527
-
528
-        return $fp;
529
-    }
530
-
531
-
532
-    /**
533
-     * MKCOL method handler
534
-     *
535
-     * @param  array  general parameter passing array
536
-     * @return bool   true on success
537
-     */
538
-    function MKCOL($options)
539
-    {
540
-        $path   = $this->base .$options["path"];
541
-        $parent = dirname($path);
542
-        $name   = basename($path);
543
-
544
-        if (!file_exists($parent)) {
545
-            return "409 Conflict";
546
-        }
547
-
548
-        if (!is_dir($parent)) {
549
-            return "403 Forbidden";
550
-        }
551
-
552
-        if ( file_exists($parent."/".$name) ) {
553
-            return "405 Method not allowed";
554
-        }
555
-
556
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
557
-            return "415 Unsupported media type";
558
-        }
559
-
560
-        $stat = mkdir($parent."/".$name, 0777);
561
-        if (!$stat) {
562
-            return "403 Forbidden";
563
-        }
564
-
565
-        return ("201 Created");
566
-    }
567
-
568
-
569
-    /**
570
-     * DELETE method handler
571
-     *
572
-     * @param  array  general parameter passing array
573
-     * @return bool   true on success
574
-     */
575
-    function DELETE($options)
576
-    {
577
-        $path = $this->base . "/" .$options["path"];
578
-
579
-        if (!file_exists($path)) {
580
-            return "404 Not found";
581
-        }
582
-
583
-        if (is_dir($path)) {
584
-            $query = "DELETE FROM {$this->db_prefix}properties
240
+		$res = mysql_query($query);
241
+		while ($row = mysql_fetch_assoc($res)) {
242
+			$info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243
+		}
244
+		mysql_free_result($res);
245
+
246
+		return $info;
247
+	}
248
+
249
+	/**
250
+	 * detect if a given program is found in the search PATH
251
+	 *
252
+	 * helper function used by _mimetype() to detect if the
253
+	 * external 'file' utility is available
254
+	 *
255
+	 * @param  string  program name
256
+	 * @param  string  optional search path, defaults to $PATH
257
+	 * @return bool    true if executable program found in path
258
+	 */
259
+	function _can_execute($name, $path = false)
260
+	{
261
+		// path defaults to PATH from environment if not set
262
+		if ($path === false) {
263
+			$path = getenv("PATH");
264
+		}
265
+
266
+		// check method depends on operating system
267
+		if (!strncmp(PHP_OS, "WIN", 3)) {
268
+			// on Windows an appropriate COM or EXE file needs to exist
269
+			$exts     = array(".exe", ".com");
270
+			$check_fn = "file_exists";
271
+		} else {
272
+			// anywhere else we look for an executable file of that name
273
+			$exts     = array("");
274
+			$check_fn = "is_executable";
275
+		}
276
+
277
+		// now check the directories in the path for the program
278
+		foreach (explode(PATH_SEPARATOR, $path) as $dir) {
279
+			// skip invalid path entries
280
+			if (!file_exists($dir)) continue;
281
+			if (!is_dir($dir)) continue;
282
+
283
+			// and now look for the file
284
+			foreach ($exts as $ext) {
285
+				if ($check_fn("$dir/$name".$ext)) return true;
286
+			}
287
+		}
288
+
289
+		return false;
290
+	}
291
+
292
+	/**
293
+	 * Check if path is readable by current user
294
+	 *
295
+	 * Allow extending classes to overwrite it
296
+	 *
297
+	 * @param string $fspath
298
+	 * @return boolean
299
+	 */
300
+	function _is_readable($fspath)
301
+	{
302
+		return is_readable($fspath);
303
+	}
304
+
305
+	/**
306
+	 * Check if path is writable by current user
307
+	 *
308
+	 * Allow extending classes to overwrite it
309
+	 *
310
+	 * @param string $fspath
311
+	 * @return boolean
312
+	 */
313
+	function _is_writable($fspath)
314
+	{
315
+		return is_writable($fspath);
316
+	}
317
+
318
+	/**
319
+	 * try to detect the mime type of a file
320
+	 *
321
+	 * @param  string  file path
322
+	 * @return string  guessed mime type
323
+	 */
324
+	function _mimetype($fspath)
325
+	{
326
+		if (is_dir($fspath)) {
327
+			// directories are easy
328
+			return "httpd/unix-directory";
329
+		} else if (function_exists("mime_content_type")) {
330
+			// use mime magic extension if available
331
+			$mime_type = mime_content_type($fspath);
332
+		} else if ($this->_can_execute("file")) {
333
+			// it looks like we have a 'file' command,
334
+			// lets see it it does have mime support
335
+			$fp    = popen("file -i '$fspath' 2>/dev/null", "r");
336
+			$reply = fgets($fp);
337
+			pclose($fp);
338
+
339
+			// popen will not return an error if the binary was not found
340
+			// and find may not have mime support using "-i"
341
+			// so we test the format of the returned string
342
+
343
+			// the reply begins with the requested filename
344
+			if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
+				$reply = substr($reply, strlen($fspath)+2);
346
+				// followed by the mime type (maybe including options)
347
+				if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348
+					$mime_type = $matches[0];
349
+				}
350
+			}
351
+		}
352
+
353
+		if (empty($mime_type)) {
354
+			// Fallback solution: try to guess the type by the file extension
355
+			// TODO: add more ...
356
+			// TODO: it has been suggested to delegate mimetype detection
357
+			//       to apache but this has at least three issues:
358
+			//       - works only with apache
359
+			//       - needs file to be within the document tree
360
+			//       - requires apache mod_magic
361
+			// TODO: can we use the registry for this on Windows?
362
+			//       OTOH if the server is Windos the clients are likely to
363
+			//       be Windows, too, and tend do ignore the Content-Type
364
+			//       anyway (overriding it with information taken from
365
+			//       the registry)
366
+			// TODO: have a seperate PEAR class for mimetype detection?
367
+			switch (strtolower(strrchr(basename($fspath), "."))) {
368
+			case ".html":
369
+				$mime_type = "text/html";
370
+				break;
371
+			case ".gif":
372
+				$mime_type = "image/gif";
373
+				break;
374
+			case ".jpg":
375
+				$mime_type = "image/jpeg";
376
+				break;
377
+			default:
378
+				$mime_type = "application/octet-stream";
379
+				break;
380
+			}
381
+		}
382
+
383
+		return $mime_type;
384
+	}
385
+
386
+	/**
387
+	 * HEAD method handler
388
+	 *
389
+	 * @param  array  parameter passing array
390
+	 * @return bool   true on success
391
+	 */
392
+	function HEAD(&$options)
393
+	{
394
+		// get absolute fs path to requested resource
395
+		$fspath = $this->base . $options["path"];
396
+
397
+		// sanity check
398
+		if (!file_exists($fspath)) return false;
399
+
400
+		// detect resource type
401
+		$options['mimetype'] = $this->_mimetype($fspath);
402
+
403
+		// detect modification time
404
+		// see rfc2518, section 13.7
405
+		// some clients seem to treat this as a reverse rule
406
+		// requiering a Last-Modified header if the getlastmodified header was set
407
+		$options['mtime'] = filemtime($fspath);
408
+
409
+		// detect resource size
410
+		$options['size'] = filesize($fspath);
411
+
412
+		return true;
413
+	}
414
+
415
+	/**
416
+	 * GET method handler
417
+	 *
418
+	 * @param  array  parameter passing array
419
+	 * @return bool   true on success
420
+	 */
421
+	function GET(&$options)
422
+	{
423
+		// get absolute fs path to requested resource
424
+		$fspath = $this->base . $options["path"];
425
+
426
+		// is this a collection?
427
+		if (is_dir($fspath)) {
428
+			return $this->GetDir($fspath, $options);
429
+		}
430
+
431
+		// the header output is the same as for HEAD
432
+		if (!$this->HEAD($options)) {
433
+			return false;
434
+		}
435
+
436
+		// no need to check result here, it is handled by the base class
437
+		$options['stream'] = fopen($fspath, "r");
438
+
439
+		return true;
440
+	}
441
+
442
+	/**
443
+	 * GET method handler for directories
444
+	 *
445
+	 * This is a very simple mod_index lookalike.
446
+	 * See RFC 2518, Section 8.4 on GET/HEAD for collections
447
+	 *
448
+	 * @param  string  directory path
449
+	 * @return void    function has to handle HTTP response itself
450
+	 */
451
+	function GetDir($fspath, &$options)
452
+	{
453
+		$path = $this->_slashify($options["path"]);
454
+		if ($path != $options["path"]) {
455
+			header("Location: ".$this->base_uri.$path);
456
+			exit;
457
+		}
458
+
459
+		// fixed width directory column format
460
+		$format = "%15s  %-19s  %-s\n";
461
+
462
+		if (!$this->_is_readable($fspath)) {
463
+			return false;
464
+		}
465
+
466
+		$handle = opendir($fspath);
467
+		if (!$handle) {
468
+			return false;
469
+		}
470
+
471
+		echo "<html><head><title>Index of ".htmlspecialchars(urldecode($options['path']))."</title></head>\n";
472
+
473
+		echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n";
474
+
475
+		echo "<pre>";
476
+		printf($format, "Size", "Last modified", "Filename");
477
+		echo "<hr>";
478
+
479
+		while ($filename = readdir($handle)) {
480
+			if ($filename != "." && $filename != "..") {
481
+				$fullpath = $fspath.$filename;
482
+				$name     = htmlspecialchars($filename);
483
+				printf($format,
484
+					   number_format(filesize($fullpath)),
485
+					   strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)),
486
+					   '<a href="'.$name.'">'.urldecode($name).'</a>');
487
+			}
488
+		}
489
+
490
+		echo "</pre>";
491
+
492
+		closedir($handle);
493
+
494
+		echo "</html>\n";
495
+
496
+		exit;
497
+	}
498
+
499
+	/**
500
+	 * PUT method handler
501
+	 *
502
+	 * @param  array  parameter passing array
503
+	 * @return bool   true on success
504
+	 */
505
+	function PUT(&$options)
506
+	{
507
+		$fspath = $this->base . $options["path"];
508
+
509
+		$dir = dirname($fspath);
510
+		if (!file_exists($dir) || !is_dir($dir)) {
511
+			return "409 Conflict"; // TODO right status code for both?
512
+		}
513
+
514
+		$options["new"] = ! file_exists($fspath);
515
+
516
+		if ($options["new"] && !$this->_is_writable($dir)) {
517
+			return "403 Forbidden";
518
+		}
519
+		if (!$options["new"] && !$this->_is_writable($fspath)) {
520
+			return "403 Forbidden";
521
+		}
522
+		if (!$options["new"] && is_dir($fspath)) {
523
+			return "403 Forbidden";
524
+		}
525
+
526
+		$fp = fopen($fspath, "w");
527
+
528
+		return $fp;
529
+	}
530
+
531
+
532
+	/**
533
+	 * MKCOL method handler
534
+	 *
535
+	 * @param  array  general parameter passing array
536
+	 * @return bool   true on success
537
+	 */
538
+	function MKCOL($options)
539
+	{
540
+		$path   = $this->base .$options["path"];
541
+		$parent = dirname($path);
542
+		$name   = basename($path);
543
+
544
+		if (!file_exists($parent)) {
545
+			return "409 Conflict";
546
+		}
547
+
548
+		if (!is_dir($parent)) {
549
+			return "403 Forbidden";
550
+		}
551
+
552
+		if ( file_exists($parent."/".$name) ) {
553
+			return "405 Method not allowed";
554
+		}
555
+
556
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
557
+			return "415 Unsupported media type";
558
+		}
559
+
560
+		$stat = mkdir($parent."/".$name, 0777);
561
+		if (!$stat) {
562
+			return "403 Forbidden";
563
+		}
564
+
565
+		return ("201 Created");
566
+	}
567
+
568
+
569
+	/**
570
+	 * DELETE method handler
571
+	 *
572
+	 * @param  array  general parameter passing array
573
+	 * @return bool   true on success
574
+	 */
575
+	function DELETE($options)
576
+	{
577
+		$path = $this->base . "/" .$options["path"];
578
+
579
+		if (!file_exists($path)) {
580
+			return "404 Not found";
581
+		}
582
+
583
+		if (is_dir($path)) {
584
+			$query = "DELETE FROM {$this->db_prefix}properties
585 585
                            WHERE path LIKE '".$this->_slashify($options["path"])."%'";
586
-            mysql_query($query);
587
-            System::rm(array("-rf", $path));
588
-        } else {
589
-            unlink($path);
590
-        }
591
-        $query = "DELETE FROM {$this->db_prefix}properties
586
+			mysql_query($query);
587
+			System::rm(array("-rf", $path));
588
+		} else {
589
+			unlink($path);
590
+		}
591
+		$query = "DELETE FROM {$this->db_prefix}properties
592 592
                        WHERE path = '$options[path]'";
593
-        mysql_query($query);
594
-
595
-        return "204 No Content";
596
-    }
597
-
598
-
599
-    /**
600
-     * MOVE method handler
601
-     *
602
-     * @param  array  general parameter passing array
603
-     * @return bool   true on success
604
-     */
605
-    function MOVE($options)
606
-    {
607
-        return $this->COPY($options, true);
608
-    }
609
-
610
-    /**
611
-     * COPY method handler
612
-     *
613
-     * @param  array  general parameter passing array
614
-     * @return bool   true on success
615
-     */
616
-    function COPY($options, $del=false)
617
-    {
618
-        // TODO Property updates still broken (Litmus should detect this?)
619
-
620
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
621
-            return "415 Unsupported media type";
622
-        }
623
-
624
-        // no copying to different WebDAV Servers yet
625
-        if (isset($options["dest_url"])) {
626
-            return "502 bad gateway";
627
-        }
628
-
629
-        $source = $this->base . $options["path"];
630
-        if (!file_exists($source)) {
631
-            return "404 Not found";
632
-        }
633
-
634
-        if (is_dir($source)) { // resource is a collection
635
-            switch ($options["depth"]) {
636
-            case "infinity": // valid
637
-                break;
638
-            case "0": // valid for COPY only
639
-                if ($del) { // MOVE?
640
-                    return "400 Bad request";
641
-                }
642
-                break;
643
-            case "1": // invalid for both COPY and MOVE
644
-            default:
645
-                return "400 Bad request";
646
-            }
647
-        }
648
-
649
-        $dest         = $this->base . $options["dest"];
650
-        $destdir      = dirname($dest);
651
-
652
-        if (!file_exists($destdir) || !is_dir($destdir)) {
653
-            return "409 Conflict";
654
-        }
655
-
656
-
657
-        $new          = !file_exists($dest);
658
-        $existing_col = false;
659
-
660
-        if (!$new) {
661
-            if ($del && is_dir($dest)) {
662
-                if (!$options["overwrite"]) {
663
-                    return "412 precondition failed";
664
-                }
665
-                $dest .= basename($source);
666
-                if (file_exists($dest)) {
667
-                    $options["dest"] .= basename($source);
668
-                } else {
669
-                    $new          = true;
670
-                    $existing_col = true;
671
-                }
672
-            }
673
-        }
674
-
675
-        if (!$new) {
676
-            if ($options["overwrite"]) {
677
-                $stat = $this->DELETE(array("path" => $options["dest"]));
678
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
679
-                    return $stat;
680
-                }
681
-            } else {
682
-                return "412 precondition failed";
683
-            }
684
-        }
685
-
686
-        if ($del) {
687
-            if (!rename($source, $dest)) {
688
-                return "500 Internal server error";
689
-            }
690
-            $destpath = $this->_unslashify($options["dest"]);
691
-            if (is_dir($source)) {
692
-                $query = "UPDATE {$this->db_prefix}properties
593
+		mysql_query($query);
594
+
595
+		return "204 No Content";
596
+	}
597
+
598
+
599
+	/**
600
+	 * MOVE method handler
601
+	 *
602
+	 * @param  array  general parameter passing array
603
+	 * @return bool   true on success
604
+	 */
605
+	function MOVE($options)
606
+	{
607
+		return $this->COPY($options, true);
608
+	}
609
+
610
+	/**
611
+	 * COPY method handler
612
+	 *
613
+	 * @param  array  general parameter passing array
614
+	 * @return bool   true on success
615
+	 */
616
+	function COPY($options, $del=false)
617
+	{
618
+		// TODO Property updates still broken (Litmus should detect this?)
619
+
620
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
621
+			return "415 Unsupported media type";
622
+		}
623
+
624
+		// no copying to different WebDAV Servers yet
625
+		if (isset($options["dest_url"])) {
626
+			return "502 bad gateway";
627
+		}
628
+
629
+		$source = $this->base . $options["path"];
630
+		if (!file_exists($source)) {
631
+			return "404 Not found";
632
+		}
633
+
634
+		if (is_dir($source)) { // resource is a collection
635
+			switch ($options["depth"]) {
636
+			case "infinity": // valid
637
+				break;
638
+			case "0": // valid for COPY only
639
+				if ($del) { // MOVE?
640
+					return "400 Bad request";
641
+				}
642
+				break;
643
+			case "1": // invalid for both COPY and MOVE
644
+			default:
645
+				return "400 Bad request";
646
+			}
647
+		}
648
+
649
+		$dest         = $this->base . $options["dest"];
650
+		$destdir      = dirname($dest);
651
+
652
+		if (!file_exists($destdir) || !is_dir($destdir)) {
653
+			return "409 Conflict";
654
+		}
655
+
656
+
657
+		$new          = !file_exists($dest);
658
+		$existing_col = false;
659
+
660
+		if (!$new) {
661
+			if ($del && is_dir($dest)) {
662
+				if (!$options["overwrite"]) {
663
+					return "412 precondition failed";
664
+				}
665
+				$dest .= basename($source);
666
+				if (file_exists($dest)) {
667
+					$options["dest"] .= basename($source);
668
+				} else {
669
+					$new          = true;
670
+					$existing_col = true;
671
+				}
672
+			}
673
+		}
674
+
675
+		if (!$new) {
676
+			if ($options["overwrite"]) {
677
+				$stat = $this->DELETE(array("path" => $options["dest"]));
678
+				if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
679
+					return $stat;
680
+				}
681
+			} else {
682
+				return "412 precondition failed";
683
+			}
684
+		}
685
+
686
+		if ($del) {
687
+			if (!rename($source, $dest)) {
688
+				return "500 Internal server error";
689
+			}
690
+			$destpath = $this->_unslashify($options["dest"]);
691
+			if (is_dir($source)) {
692
+				$query = "UPDATE {$this->db_prefix}properties
693 693
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
694 694
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
695
-                mysql_query($query);
696
-            }
695
+				mysql_query($query);
696
+			}
697 697
 
698
-            $query = "UPDATE {$this->db_prefix}properties
698
+			$query = "UPDATE {$this->db_prefix}properties
699 699
                              SET path = '".$destpath."'
700 700
                            WHERE path = '".$options["path"]."'";
701
-            mysql_query($query);
702
-        } else {
703
-            if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
704
-                $files = System::find($source);
705
-                $files = array_reverse($files);
706
-            } else {
707
-                $files = array($source);
708
-            }
709
-
710
-            if (!is_array($files) || empty($files)) {
711
-                return "500 Internal server error";
712
-            }
713
-
714
-
715
-            foreach ($files as $file) {
716
-                if (is_dir($file)) {
717
-                    $file = $this->_slashify($file);
718
-                }
719
-
720
-                $destfile = str_replace($source, $dest, $file);
721
-
722
-                if (is_dir($file)) {
723
-                    if (!file_exists($destfile)) {
724
-                        if (!$this->_is_writable(dirname($destfile))) {
725
-                            return "403 Forbidden";
726
-                        }
727
-                        if (!mkdir($destfile)) {
728
-                            return "409 Conflict";
729
-                        }
730
-                    } else if (!is_dir($destfile)) {
731
-                        return "409 Conflict";
732
-                    }
733
-                } else {
734
-
735
-                    if (!copy($file, $destfile)) {
736
-                        return "409 Conflict";
737
-                    }
738
-                }
739
-            }
740
-
741
-            $query = "INSERT INTO {$this->db_prefix}properties
701
+			mysql_query($query);
702
+		} else {
703
+			if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
704
+				$files = System::find($source);
705
+				$files = array_reverse($files);
706
+			} else {
707
+				$files = array($source);
708
+			}
709
+
710
+			if (!is_array($files) || empty($files)) {
711
+				return "500 Internal server error";
712
+			}
713
+
714
+
715
+			foreach ($files as $file) {
716
+				if (is_dir($file)) {
717
+					$file = $this->_slashify($file);
718
+				}
719
+
720
+				$destfile = str_replace($source, $dest, $file);
721
+
722
+				if (is_dir($file)) {
723
+					if (!file_exists($destfile)) {
724
+						if (!$this->_is_writable(dirname($destfile))) {
725
+							return "403 Forbidden";
726
+						}
727
+						if (!mkdir($destfile)) {
728
+							return "409 Conflict";
729
+						}
730
+					} else if (!is_dir($destfile)) {
731
+						return "409 Conflict";
732
+					}
733
+				} else {
734
+
735
+					if (!copy($file, $destfile)) {
736
+						return "409 Conflict";
737
+					}
738
+				}
739
+			}
740
+
741
+			$query = "INSERT INTO {$this->db_prefix}properties
742 742
                                SELECT *
743 743
                                  FROM {$this->db_prefix}properties
744 744
                                 WHERE path = '".$options['path']."'";
745
-        }
746
-
747
-        return ($new && !$existing_col) ? "201 Created" : "204 No Content";
748
-    }
749
-
750
-    /**
751
-     * PROPPATCH method handler
752
-     *
753
-     * @param  array  general parameter passing array
754
-     * @return bool   true on success
755
-     */
756
-    function PROPPATCH(&$options)
757
-    {
758
-        global $prefs, $tab;
759
-
760
-        $msg  = "";
761
-        $path = $options["path"];
762
-        $dir  = dirname($path)."/";
763
-        $base = basename($path);
764
-
765
-        foreach ($options["props"] as $key => $prop) {
766
-            if ($prop["ns"] == "DAV:") {
767
-                $options["props"][$key]['status'] = "403 Forbidden";
768
-            } else {
769
-                if (isset($prop["val"])) {
770
-                    $query = "REPLACE INTO {$this->db_prefix}properties
745
+		}
746
+
747
+		return ($new && !$existing_col) ? "201 Created" : "204 No Content";
748
+	}
749
+
750
+	/**
751
+	 * PROPPATCH method handler
752
+	 *
753
+	 * @param  array  general parameter passing array
754
+	 * @return bool   true on success
755
+	 */
756
+	function PROPPATCH(&$options)
757
+	{
758
+		global $prefs, $tab;
759
+
760
+		$msg  = "";
761
+		$path = $options["path"];
762
+		$dir  = dirname($path)."/";
763
+		$base = basename($path);
764
+
765
+		foreach ($options["props"] as $key => $prop) {
766
+			if ($prop["ns"] == "DAV:") {
767
+				$options["props"][$key]['status'] = "403 Forbidden";
768
+			} else {
769
+				if (isset($prop["val"])) {
770
+					$query = "REPLACE INTO {$this->db_prefix}properties
771 771
                                            SET path = '$options[path]'
772 772
                                              , name = '$prop[name]'
773 773
                                              , ns= '$prop[ns]'
774 774
                                              , value = '$prop[val]'";
775
-                } else {
776
-                    $query = "DELETE FROM {$this->db_prefix}properties
775
+				} else {
776
+					$query = "DELETE FROM {$this->db_prefix}properties
777 777
                                         WHERE path = '$options[path]'
778 778
                                           AND name = '$prop[name]'
779 779
                                           AND ns = '$prop[ns]'";
780
-                }
781
-                mysql_query($query);
782
-            }
783
-        }
784
-
785
-        return "";
786
-    }
787
-
788
-
789
-    /**
790
-     * LOCK method handler
791
-     *
792
-     * @param  array  general parameter passing array
793
-     * @return bool   true on success
794
-     */
795
-    function LOCK(&$options)
796
-    {
797
-        // get absolute fs path to requested resource
798
-        $fspath = $this->base . $options["path"];
799
-
800
-        // TODO recursive locks on directories not supported yet
801
-        // makes litmus test "32. lock_collection" fail
802
-        if (is_dir($fspath) && !empty($options["depth"])) {
803
-            return "409 Conflict";
804
-        }
805
-
806
-        $options["timeout"] = time()+300; // 5min. hardcoded
807
-
808
-        if (isset($options["update"])) { // Lock Update
809
-            $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
810
-
811
-            $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
812
-            $res   = mysql_query($query);
813
-            $row   = mysql_fetch_assoc($res);
814
-            mysql_free_result($res);
815
-
816
-            if (is_array($row)) {
817
-                $query = "UPDATE {$this->db_prefix}locks
780
+				}
781
+				mysql_query($query);
782
+			}
783
+		}
784
+
785
+		return "";
786
+	}
787
+
788
+
789
+	/**
790
+	 * LOCK method handler
791
+	 *
792
+	 * @param  array  general parameter passing array
793
+	 * @return bool   true on success
794
+	 */
795
+	function LOCK(&$options)
796
+	{
797
+		// get absolute fs path to requested resource
798
+		$fspath = $this->base . $options["path"];
799
+
800
+		// TODO recursive locks on directories not supported yet
801
+		// makes litmus test "32. lock_collection" fail
802
+		if (is_dir($fspath) && !empty($options["depth"])) {
803
+			return "409 Conflict";
804
+		}
805
+
806
+		$options["timeout"] = time()+300; // 5min. hardcoded
807
+
808
+		if (isset($options["update"])) { // Lock Update
809
+			$where = "WHERE path = '$options[path]' AND token = '$options[update]'";
810
+
811
+			$query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
812
+			$res   = mysql_query($query);
813
+			$row   = mysql_fetch_assoc($res);
814
+			mysql_free_result($res);
815
+
816
+			if (is_array($row)) {
817
+				$query = "UPDATE {$this->db_prefix}locks
818 818
                                  SET expires = '$options[timeout]'
819 819
                                    , modified = ".time()."
820 820
                               $where";
821
-                mysql_query($query);
821
+				mysql_query($query);
822 822
 
823
-                $options['owner'] = $row['owner'];
824
-                $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
825
-                $options['type']  = $row["exclusivelock"] ? "write"     : "read";
823
+				$options['owner'] = $row['owner'];
824
+				$options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
825
+				$options['type']  = $row["exclusivelock"] ? "write"     : "read";
826 826
 
827
-                return true;
828
-            } else {
829
-                return false;
830
-            }
831
-        }
827
+				return true;
828
+			} else {
829
+				return false;
830
+			}
831
+		}
832 832
 
833
-        $query = "INSERT INTO {$this->db_prefix}locks
833
+		$query = "INSERT INTO {$this->db_prefix}locks
834 834
                         SET token   = '$options[locktoken]'
835 835
                           , path    = '$options[path]'
836 836
                           , created = ".time()."
@@ -838,76 +838,76 @@  discard block
 block discarded – undo
838 838
                           , owner   = '$options[owner]'
839 839
                           , expires = '$options[timeout]'
840 840
                           , exclusivelock  = " .($options['scope'] === "exclusive" ? "1" : "0")
841
-            ;
842
-        mysql_query($query);
843
-
844
-        return mysql_affected_rows() ? "200 OK" : "409 Conflict";
845
-    }
846
-
847
-    /**
848
-     * UNLOCK method handler
849
-     *
850
-     * @param  array  general parameter passing array
851
-     * @return bool   true on success
852
-     */
853
-    function UNLOCK(&$options)
854
-    {
855
-        $query = "DELETE FROM {$this->db_prefix}locks
841
+			;
842
+		mysql_query($query);
843
+
844
+		return mysql_affected_rows() ? "200 OK" : "409 Conflict";
845
+	}
846
+
847
+	/**
848
+	 * UNLOCK method handler
849
+	 *
850
+	 * @param  array  general parameter passing array
851
+	 * @return bool   true on success
852
+	 */
853
+	function UNLOCK(&$options)
854
+	{
855
+		$query = "DELETE FROM {$this->db_prefix}locks
856 856
                       WHERE path = '$options[path]'
857 857
                         AND token = '$options[token]'";
858
-        mysql_query($query);
859
-
860
-        return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
861
-    }
862
-
863
-    /**
864
-     * checkLock() helper
865
-     *
866
-     * @param  string resource path to check for locks
867
-     * @return bool   true on success
868
-     */
869
-    function checkLock($path)
870
-    {
871
-        $result = false;
872
-
873
-        $query = "SELECT owner, token, created, modified, expires, exclusivelock
858
+		mysql_query($query);
859
+
860
+		return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
861
+	}
862
+
863
+	/**
864
+	 * checkLock() helper
865
+	 *
866
+	 * @param  string resource path to check for locks
867
+	 * @return bool   true on success
868
+	 */
869
+	function checkLock($path)
870
+	{
871
+		$result = false;
872
+
873
+		$query = "SELECT owner, token, created, modified, expires, exclusivelock
874 874
                   FROM {$this->db_prefix}locks
875 875
                  WHERE path = '$path'
876 876
                ";
877
-        $res = mysql_query($query);
878
-
879
-        if ($res) {
880
-            $row = mysql_fetch_array($res);
881
-            mysql_free_result($res);
882
-
883
-            if ($row) {
884
-                $result = array( "type"    => "write",
885
-                                 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886
-                                 "depth"   => 0,
887
-                                 "owner"   => $row['owner'],
888
-                                 "token"   => $row['token'],
889
-                                 "created" => $row['created'],
890
-                                 "modified" => $row['modified'],
891
-                                 "expires" => $row['expires']
892
-                                 );
893
-            }
894
-        }
895
-
896
-        return $result;
897
-    }
898
-
899
-
900
-    /**
901
-     * create database tables for property and lock storage
902
-     *
903
-     * @param  void
904
-     * @return bool   true on success
905
-     */
906
-    function create_database()
907
-    {
908
-        // TODO
909
-        return false;
910
-    }
877
+		$res = mysql_query($query);
878
+
879
+		if ($res) {
880
+			$row = mysql_fetch_array($res);
881
+			mysql_free_result($res);
882
+
883
+			if ($row) {
884
+				$result = array( "type"    => "write",
885
+								 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886
+								 "depth"   => 0,
887
+								 "owner"   => $row['owner'],
888
+								 "token"   => $row['token'],
889
+								 "created" => $row['created'],
890
+								 "modified" => $row['modified'],
891
+								 "expires" => $row['expires']
892
+								 );
893
+			}
894
+		}
895
+
896
+		return $result;
897
+	}
898
+
899
+
900
+	/**
901
+	 * create database tables for property and lock storage
902
+	 *
903
+	 * @param  void
904
+	 * @return bool   true on success
905
+	 */
906
+	function create_database()
907
+	{
908
+		// TODO
909
+		return false;
910
+	}
911 911
 }
912 912
 
913 913
 
Please login to merge, or discard this patch.
Switch Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -365,18 +365,18 @@  discard block
 block discarded – undo
365 365
             //       the registry)
366 366
             // TODO: have a seperate PEAR class for mimetype detection?
367 367
             switch (strtolower(strrchr(basename($fspath), "."))) {
368
-            case ".html":
369
-                $mime_type = "text/html";
370
-                break;
371
-            case ".gif":
372
-                $mime_type = "image/gif";
373
-                break;
374
-            case ".jpg":
375
-                $mime_type = "image/jpeg";
376
-                break;
377
-            default:
378
-                $mime_type = "application/octet-stream";
379
-                break;
368
+            	case ".html":
369
+                	$mime_type = "text/html";
370
+                	break;
371
+            	case ".gif":
372
+                	$mime_type = "image/gif";
373
+                	break;
374
+            	case ".jpg":
375
+                	$mime_type = "image/jpeg";
376
+                	break;
377
+            	default:
378
+                	$mime_type = "application/octet-stream";
379
+                	break;
380 380
             }
381 381
         }
382 382
 
@@ -633,16 +633,16 @@  discard block
 block discarded – undo
633 633
 
634 634
         if (is_dir($source)) { // resource is a collection
635 635
             switch ($options["depth"]) {
636
-            case "infinity": // valid
637
-                break;
638
-            case "0": // valid for COPY only
639
-                if ($del) { // MOVE?
640
-                    return "400 Bad request";
641
-                }
642
-                break;
643
-            case "1": // invalid for both COPY and MOVE
644
-            default:
645
-                return "400 Bad request";
636
+            	case "infinity": // valid
637
+                	break;
638
+            	case "0": // valid for COPY only
639
+                	if ($del) { // MOVE?
640
+                    	return "400 Bad request";
641
+                	}
642
+                	break;
643
+            	case "1": // invalid for both COPY and MOVE
644
+            	default:
645
+                	return "400 Bad request";
646 646
             }
647 647
         }
648 648
 
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     function PROPFIND(&$options, &$files)
152 152
     {
153 153
         // get absolute fs path to requested resource
154
-        $fspath = $this->base . $options["path"];
154
+        $fspath = $this->base.$options["path"];
155 155
 
156 156
         // sanity check
157 157
         if (!file_exists($fspath)) {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     function fileinfo($path)
199 199
     {
200 200
         // map URI path to filesystem path
201
-        $fspath = $this->base . $path;
201
+        $fspath = $this->base.$path;
202 202
 
203 203
         // create result array
204 204
         $info = array();
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
         $info["props"][] = $this->mkprop("displayname", strtoupper($path));
211 211
 
212 212
         // creation and modification time
213
-        $info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
213
+        $info["props"][] = $this->mkprop("creationdate", filectime($fspath));
214 214
         $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215 215
 
216 216
         // Microsoft extensions: last access time and 'hidden' status
217
-        $info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
217
+        $info["props"][] = $this->mkprop("lastaccessed", fileatime($fspath));
218 218
         $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219 219
 
220 220
         // type and size (caller already made sure that path exists)
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
             // so we test the format of the returned string
342 342
 
343 343
             // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
-                $reply = substr($reply, strlen($fspath)+2);
344
+            if (!strncmp($reply, "$fspath: ", strlen($fspath) + 2)) {
345
+                $reply = substr($reply, strlen($fspath) + 2);
346 346
                 // followed by the mime type (maybe including options)
347 347
                 if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348 348
                     $mime_type = $matches[0];
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
     function HEAD(&$options)
393 393
     {
394 394
         // get absolute fs path to requested resource
395
-        $fspath = $this->base . $options["path"];
395
+        $fspath = $this->base.$options["path"];
396 396
 
397 397
         // sanity check
398 398
         if (!file_exists($fspath)) return false;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
     function GET(&$options)
422 422
     {
423 423
         // get absolute fs path to requested resource
424
-        $fspath = $this->base . $options["path"];
424
+        $fspath = $this->base.$options["path"];
425 425
 
426 426
         // is this a collection?
427 427
         if (is_dir($fspath)) {
@@ -504,14 +504,14 @@  discard block
 block discarded – undo
504 504
      */
505 505
     function PUT(&$options)
506 506
     {
507
-        $fspath = $this->base . $options["path"];
507
+        $fspath = $this->base.$options["path"];
508 508
 
509 509
         $dir = dirname($fspath);
510 510
         if (!file_exists($dir) || !is_dir($dir)) {
511 511
             return "409 Conflict"; // TODO right status code for both?
512 512
         }
513 513
 
514
-        $options["new"] = ! file_exists($fspath);
514
+        $options["new"] = !file_exists($fspath);
515 515
 
516 516
         if ($options["new"] && !$this->_is_writable($dir)) {
517 517
             return "403 Forbidden";
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
      */
538 538
     function MKCOL($options)
539 539
     {
540
-        $path   = $this->base .$options["path"];
540
+        $path   = $this->base.$options["path"];
541 541
         $parent = dirname($path);
542 542
         $name   = basename($path);
543 543
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             return "403 Forbidden";
550 550
         }
551 551
 
552
-        if ( file_exists($parent."/".$name) ) {
552
+        if (file_exists($parent."/".$name)) {
553 553
             return "405 Method not allowed";
554 554
         }
555 555
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      */
575 575
     function DELETE($options)
576 576
     {
577
-        $path = $this->base . "/" .$options["path"];
577
+        $path = $this->base."/".$options["path"];
578 578
 
579 579
         if (!file_exists($path)) {
580 580
             return "404 Not found";
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
      * @param  array  general parameter passing array
614 614
      * @return bool   true on success
615 615
      */
616
-    function COPY($options, $del=false)
616
+    function COPY($options, $del = false)
617 617
     {
618 618
         // TODO Property updates still broken (Litmus should detect this?)
619 619
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
             return "502 bad gateway";
627 627
         }
628 628
 
629
-        $source = $this->base . $options["path"];
629
+        $source = $this->base.$options["path"];
630 630
         if (!file_exists($source)) {
631 631
             return "404 Not found";
632 632
         }
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
             }
647 647
         }
648 648
 
649
-        $dest         = $this->base . $options["dest"];
649
+        $dest         = $this->base.$options["dest"];
650 650
         $destdir      = dirname($dest);
651 651
 
652 652
         if (!file_exists($destdir) || !is_dir($destdir)) {
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
     function LOCK(&$options)
796 796
     {
797 797
         // get absolute fs path to requested resource
798
-        $fspath = $this->base . $options["path"];
798
+        $fspath = $this->base.$options["path"];
799 799
 
800 800
         // TODO recursive locks on directories not supported yet
801 801
         // makes litmus test "32. lock_collection" fail
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
             return "409 Conflict";
804 804
         }
805 805
 
806
-        $options["timeout"] = time()+300; // 5min. hardcoded
806
+        $options["timeout"] = time() + 300; // 5min. hardcoded
807 807
 
808 808
         if (isset($options["update"])) { // Lock Update
809 809
             $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 
823 823
                 $options['owner'] = $row['owner'];
824 824
                 $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
825
-                $options['type']  = $row["exclusivelock"] ? "write"     : "read";
825
+                $options['type']  = $row["exclusivelock"] ? "write" : "read";
826 826
 
827 827
                 return true;
828 828
             } else {
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
                           , modified = ".time()."
838 838
                           , owner   = '$options[owner]'
839 839
                           , expires = '$options[timeout]'
840
-                          , exclusivelock  = " .($options['scope'] === "exclusive" ? "1" : "0")
840
+                          , exclusivelock  = ".($options['scope'] === "exclusive" ? "1" : "0")
841 841
             ;
842 842
         mysql_query($query);
843 843
 
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
             mysql_free_result($res);
882 882
 
883 883
             if ($row) {
884
-                $result = array( "type"    => "write",
884
+                $result = array("type"    => "write",
885 885
                                  "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886 886
                                  "depth"   => 0,
887 887
                                  "owner"   => $row['owner'],
Please login to merge, or discard this patch.
Braces   +212 added lines, -91 removed lines patch added patch discarded remove patch
@@ -105,15 +105,19 @@  discard block
 block discarded – undo
105 105
         // special treatment for litmus compliance test
106 106
         // reply on its identifier header
107 107
         // not needed for the test itself but eases debugging
108
-        if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
108
+        if (isset($this->_SERVER['HTTP_X_LITMUS']))
109
+        {
109 110
             error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110 111
             header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111 112
         }
112 113
 
113 114
         // set root directory, defaults to webserver document root if not set
114
-        if ($base) {
115
+        if ($base)
116
+        {
115 117
             $this->base = realpath($base); // TODO throw if not a directory
116
-        } else if (!$this->base) {
118
+        }
119
+        else if (!$this->base)
120
+        {
117 121
             $this->base = $this->_SERVER['DOCUMENT_ROOT'];
118 122
         }
119 123
 
@@ -154,7 +158,8 @@  discard block
 block discarded – undo
154 158
         $fspath = $this->base . $options["path"];
155 159
 
156 160
         // sanity check
157
-        if (!file_exists($fspath)) {
161
+        if (!file_exists($fspath))
162
+        {
158 163
             return false;
159 164
         }
160 165
 
@@ -165,7 +170,8 @@  discard block
 block discarded – undo
165 170
         $files["files"][] = $this->fileinfo($options["path"]);
166 171
 
167 172
         // information for contained resources requested?
168
-        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
173
+        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath))
174
+        {
169 175
 
170 176
             // make sure path ends with '/'
171 177
             $options["path"] = $this->_slashify($options["path"]);
@@ -173,10 +179,13 @@  discard block
 block discarded – undo
173 179
             // try to open directory
174 180
             $handle = opendir($fspath);
175 181
 
176
-            if ($handle) {
182
+            if ($handle)
183
+            {
177 184
                 // ok, now get all its contents
178
-                while ($filename = readdir($handle)) {
179
-                    if ($filename != "." && $filename != "..") {
185
+                while ($filename = readdir($handle))
186
+                {
187
+                    if ($filename != "." && $filename != "..")
188
+                    {
180 189
                         $files["files"][] = $this->fileinfo($options["path"].$filename);
181 190
                     }
182 191
                 }
@@ -218,16 +227,22 @@  discard block
 block discarded – undo
218 227
         $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219 228
 
220 229
         // type and size (caller already made sure that path exists)
221
-        if (is_dir($fspath)) {
230
+        if (is_dir($fspath))
231
+        {
222 232
             // directory (WebDAV collection)
223 233
             $info["props"][] = $this->mkprop("resourcetype", "collection");
224 234
             $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
-        } else {
235
+        }
236
+        else
237
+        {
226 238
             // plain file (WebDAV resource)
227 239
             $info["props"][] = $this->mkprop("resourcetype", "");
228
-            if ($this->_is_readable($fspath)) {
240
+            if ($this->_is_readable($fspath))
241
+            {
229 242
                 $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
-            } else {
243
+            }
244
+            else
245
+            {
231 246
                 $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232 247
             }
233 248
             $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
@@ -238,7 +253,8 @@  discard block
 block discarded – undo
238 253
                         FROM {$this->db_prefix}properties
239 254
                        WHERE path = '$path'";
240 255
         $res = mysql_query($query);
241
-        while ($row = mysql_fetch_assoc($res)) {
256
+        while ($row = mysql_fetch_assoc($res))
257
+        {
242 258
             $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243 259
         }
244 260
         mysql_free_result($res);
@@ -259,30 +275,45 @@  discard block
 block discarded – undo
259 275
     function _can_execute($name, $path = false)
260 276
     {
261 277
         // path defaults to PATH from environment if not set
262
-        if ($path === false) {
278
+        if ($path === false)
279
+        {
263 280
             $path = getenv("PATH");
264 281
         }
265 282
 
266 283
         // check method depends on operating system
267
-        if (!strncmp(PHP_OS, "WIN", 3)) {
284
+        if (!strncmp(PHP_OS, "WIN", 3))
285
+        {
268 286
             // on Windows an appropriate COM or EXE file needs to exist
269 287
             $exts     = array(".exe", ".com");
270 288
             $check_fn = "file_exists";
271
-        } else {
289
+        }
290
+        else
291
+        {
272 292
             // anywhere else we look for an executable file of that name
273 293
             $exts     = array("");
274 294
             $check_fn = "is_executable";
275 295
         }
276 296
 
277 297
         // now check the directories in the path for the program
278
-        foreach (explode(PATH_SEPARATOR, $path) as $dir) {
298
+        foreach (explode(PATH_SEPARATOR, $path) as $dir)
299
+        {
279 300
             // skip invalid path entries
280
-            if (!file_exists($dir)) continue;
281
-            if (!is_dir($dir)) continue;
301
+            if (!file_exists($dir))
302
+            {
303
+            	continue;
304
+            }
305
+            if (!is_dir($dir))
306
+            {
307
+            	continue;
308
+            }
282 309
 
283 310
             // and now look for the file
284
-            foreach ($exts as $ext) {
285
-                if ($check_fn("$dir/$name".$ext)) return true;
311
+            foreach ($exts as $ext)
312
+            {
313
+                if ($check_fn("$dir/$name".$ext))
314
+                {
315
+                	return true;
316
+                }
286 317
             }
287 318
         }
288 319
 
@@ -323,13 +354,18 @@  discard block
 block discarded – undo
323 354
      */
324 355
     function _mimetype($fspath)
325 356
     {
326
-        if (is_dir($fspath)) {
357
+        if (is_dir($fspath))
358
+        {
327 359
             // directories are easy
328 360
             return "httpd/unix-directory";
329
-        } else if (function_exists("mime_content_type")) {
361
+        }
362
+        else if (function_exists("mime_content_type"))
363
+        {
330 364
             // use mime magic extension if available
331 365
             $mime_type = mime_content_type($fspath);
332
-        } else if ($this->_can_execute("file")) {
366
+        }
367
+        else if ($this->_can_execute("file"))
368
+        {
333 369
             // it looks like we have a 'file' command,
334 370
             // lets see it it does have mime support
335 371
             $fp    = popen("file -i '$fspath' 2>/dev/null", "r");
@@ -341,16 +377,19 @@  discard block
 block discarded – undo
341 377
             // so we test the format of the returned string
342 378
 
343 379
             // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
380
+            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2))
381
+            {
345 382
                 $reply = substr($reply, strlen($fspath)+2);
346 383
                 // followed by the mime type (maybe including options)
347
-                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
384
+                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches))
385
+                {
348 386
                     $mime_type = $matches[0];
349 387
                 }
350 388
             }
351 389
         }
352 390
 
353
-        if (empty($mime_type)) {
391
+        if (empty($mime_type))
392
+        {
354 393
             // Fallback solution: try to guess the type by the file extension
355 394
             // TODO: add more ...
356 395
             // TODO: it has been suggested to delegate mimetype detection
@@ -364,7 +403,8 @@  discard block
 block discarded – undo
364 403
             //       anyway (overriding it with information taken from
365 404
             //       the registry)
366 405
             // TODO: have a seperate PEAR class for mimetype detection?
367
-            switch (strtolower(strrchr(basename($fspath), "."))) {
406
+            switch (strtolower(strrchr(basename($fspath), ".")))
407
+            {
368 408
             case ".html":
369 409
                 $mime_type = "text/html";
370 410
                 break;
@@ -395,7 +435,10 @@  discard block
 block discarded – undo
395 435
         $fspath = $this->base . $options["path"];
396 436
 
397 437
         // sanity check
398
-        if (!file_exists($fspath)) return false;
438
+        if (!file_exists($fspath))
439
+        {
440
+        	return false;
441
+        }
399 442
 
400 443
         // detect resource type
401 444
         $options['mimetype'] = $this->_mimetype($fspath);
@@ -424,12 +467,14 @@  discard block
 block discarded – undo
424 467
         $fspath = $this->base . $options["path"];
425 468
 
426 469
         // is this a collection?
427
-        if (is_dir($fspath)) {
470
+        if (is_dir($fspath))
471
+        {
428 472
             return $this->GetDir($fspath, $options);
429 473
         }
430 474
 
431 475
         // the header output is the same as for HEAD
432
-        if (!$this->HEAD($options)) {
476
+        if (!$this->HEAD($options))
477
+        {
433 478
             return false;
434 479
         }
435 480
 
@@ -451,7 +496,8 @@  discard block
 block discarded – undo
451 496
     function GetDir($fspath, &$options)
452 497
     {
453 498
         $path = $this->_slashify($options["path"]);
454
-        if ($path != $options["path"]) {
499
+        if ($path != $options["path"])
500
+        {
455 501
             header("Location: ".$this->base_uri.$path);
456 502
             exit;
457 503
         }
@@ -459,12 +505,14 @@  discard block
 block discarded – undo
459 505
         // fixed width directory column format
460 506
         $format = "%15s  %-19s  %-s\n";
461 507
 
462
-        if (!$this->_is_readable($fspath)) {
508
+        if (!$this->_is_readable($fspath))
509
+        {
463 510
             return false;
464 511
         }
465 512
 
466 513
         $handle = opendir($fspath);
467
-        if (!$handle) {
514
+        if (!$handle)
515
+        {
468 516
             return false;
469 517
         }
470 518
 
@@ -476,8 +524,10 @@  discard block
 block discarded – undo
476 524
         printf($format, "Size", "Last modified", "Filename");
477 525
         echo "<hr>";
478 526
 
479
-        while ($filename = readdir($handle)) {
480
-            if ($filename != "." && $filename != "..") {
527
+        while ($filename = readdir($handle))
528
+        {
529
+            if ($filename != "." && $filename != "..")
530
+            {
481 531
                 $fullpath = $fspath.$filename;
482 532
                 $name     = htmlspecialchars($filename);
483 533
                 printf($format,
@@ -507,19 +557,23 @@  discard block
 block discarded – undo
507 557
         $fspath = $this->base . $options["path"];
508 558
 
509 559
         $dir = dirname($fspath);
510
-        if (!file_exists($dir) || !is_dir($dir)) {
560
+        if (!file_exists($dir) || !is_dir($dir))
561
+        {
511 562
             return "409 Conflict"; // TODO right status code for both?
512 563
         }
513 564
 
514 565
         $options["new"] = ! file_exists($fspath);
515 566
 
516
-        if ($options["new"] && !$this->_is_writable($dir)) {
567
+        if ($options["new"] && !$this->_is_writable($dir))
568
+        {
517 569
             return "403 Forbidden";
518 570
         }
519
-        if (!$options["new"] && !$this->_is_writable($fspath)) {
571
+        if (!$options["new"] && !$this->_is_writable($fspath))
572
+        {
520 573
             return "403 Forbidden";
521 574
         }
522
-        if (!$options["new"] && is_dir($fspath)) {
575
+        if (!$options["new"] && is_dir($fspath))
576
+        {
523 577
             return "403 Forbidden";
524 578
         }
525 579
 
@@ -541,24 +595,30 @@  discard block
 block discarded – undo
541 595
         $parent = dirname($path);
542 596
         $name   = basename($path);
543 597
 
544
-        if (!file_exists($parent)) {
598
+        if (!file_exists($parent))
599
+        {
545 600
             return "409 Conflict";
546 601
         }
547 602
 
548
-        if (!is_dir($parent)) {
603
+        if (!is_dir($parent))
604
+        {
549 605
             return "403 Forbidden";
550 606
         }
551 607
 
552
-        if ( file_exists($parent."/".$name) ) {
608
+        if ( file_exists($parent."/".$name) )
609
+        {
553 610
             return "405 Method not allowed";
554 611
         }
555 612
 
556
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
613
+        if (!empty($this->_SERVER["CONTENT_LENGTH"]))
614
+        {
615
+// no body parsing yet
557 616
             return "415 Unsupported media type";
558 617
         }
559 618
 
560 619
         $stat = mkdir($parent."/".$name, 0777);
561
-        if (!$stat) {
620
+        if (!$stat)
621
+        {
562 622
             return "403 Forbidden";
563 623
         }
564 624
 
@@ -576,16 +636,20 @@  discard block
 block discarded – undo
576 636
     {
577 637
         $path = $this->base . "/" .$options["path"];
578 638
 
579
-        if (!file_exists($path)) {
639
+        if (!file_exists($path))
640
+        {
580 641
             return "404 Not found";
581 642
         }
582 643
 
583
-        if (is_dir($path)) {
644
+        if (is_dir($path))
645
+        {
584 646
             $query = "DELETE FROM {$this->db_prefix}properties
585 647
                            WHERE path LIKE '".$this->_slashify($options["path"])."%'";
586 648
             mysql_query($query);
587 649
             System::rm(array("-rf", $path));
588
-        } else {
650
+        }
651
+        else
652
+        {
589 653
             unlink($path);
590 654
         }
591 655
         $query = "DELETE FROM {$this->db_prefix}properties
@@ -617,26 +681,35 @@  discard block
 block discarded – undo
617 681
     {
618 682
         // TODO Property updates still broken (Litmus should detect this?)
619 683
 
620
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
684
+        if (!empty($this->_SERVER["CONTENT_LENGTH"]))
685
+        {
686
+// no body parsing yet
621 687
             return "415 Unsupported media type";
622 688
         }
623 689
 
624 690
         // no copying to different WebDAV Servers yet
625
-        if (isset($options["dest_url"])) {
691
+        if (isset($options["dest_url"]))
692
+        {
626 693
             return "502 bad gateway";
627 694
         }
628 695
 
629 696
         $source = $this->base . $options["path"];
630
-        if (!file_exists($source)) {
697
+        if (!file_exists($source))
698
+        {
631 699
             return "404 Not found";
632 700
         }
633 701
 
634
-        if (is_dir($source)) { // resource is a collection
635
-            switch ($options["depth"]) {
702
+        if (is_dir($source))
703
+        {
704
+// resource is a collection
705
+            switch ($options["depth"])
706
+            {
636 707
             case "infinity": // valid
637 708
                 break;
638 709
             case "0": // valid for COPY only
639
-                if ($del) { // MOVE?
710
+                if ($del)
711
+                {
712
+// MOVE?
640 713
                     return "400 Bad request";
641 714
                 }
642 715
                 break;
@@ -649,7 +722,8 @@  discard block
 block discarded – undo
649 722
         $dest         = $this->base . $options["dest"];
650 723
         $destdir      = dirname($dest);
651 724
 
652
-        if (!file_exists($destdir) || !is_dir($destdir)) {
725
+        if (!file_exists($destdir) || !is_dir($destdir))
726
+        {
653 727
             return "409 Conflict";
654 728
         }
655 729
 
@@ -657,38 +731,52 @@  discard block
 block discarded – undo
657 731
         $new          = !file_exists($dest);
658 732
         $existing_col = false;
659 733
 
660
-        if (!$new) {
661
-            if ($del && is_dir($dest)) {
662
-                if (!$options["overwrite"]) {
734
+        if (!$new)
735
+        {
736
+            if ($del && is_dir($dest))
737
+            {
738
+                if (!$options["overwrite"])
739
+                {
663 740
                     return "412 precondition failed";
664 741
                 }
665 742
                 $dest .= basename($source);
666
-                if (file_exists($dest)) {
743
+                if (file_exists($dest))
744
+                {
667 745
                     $options["dest"] .= basename($source);
668
-                } else {
746
+                }
747
+                else
748
+                {
669 749
                     $new          = true;
670 750
                     $existing_col = true;
671 751
                 }
672 752
             }
673 753
         }
674 754
 
675
-        if (!$new) {
676
-            if ($options["overwrite"]) {
755
+        if (!$new)
756
+        {
757
+            if ($options["overwrite"])
758
+            {
677 759
                 $stat = $this->DELETE(array("path" => $options["dest"]));
678
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
760
+                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404"))
761
+                {
679 762
                     return $stat;
680 763
                 }
681
-            } else {
764
+            }
765
+            else
766
+            {
682 767
                 return "412 precondition failed";
683 768
             }
684 769
         }
685 770
 
686
-        if ($del) {
687
-            if (!rename($source, $dest)) {
771
+        if ($del)
772
+        {
773
+            if (!rename($source, $dest))
774
+            {
688 775
                 return "500 Internal server error";
689 776
             }
690 777
             $destpath = $this->_unslashify($options["dest"]);
691
-            if (is_dir($source)) {
778
+            if (is_dir($source))
779
+            {
692 780
                 $query = "UPDATE {$this->db_prefix}properties
693 781
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
694 782
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
@@ -699,40 +787,58 @@  discard block
 block discarded – undo
699 787
                              SET path = '".$destpath."'
700 788
                            WHERE path = '".$options["path"]."'";
701 789
             mysql_query($query);
702
-        } else {
703
-            if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
790
+        }
791
+        else
792
+        {
793
+            if (is_dir($source) && $options["depth"] == "infinity")
794
+            {
795
+// no find for depth="0"
704 796
                 $files = System::find($source);
705 797
                 $files = array_reverse($files);
706
-            } else {
798
+            }
799
+            else
800
+            {
707 801
                 $files = array($source);
708 802
             }
709 803
 
710
-            if (!is_array($files) || empty($files)) {
804
+            if (!is_array($files) || empty($files))
805
+            {
711 806
                 return "500 Internal server error";
712 807
             }
713 808
 
714 809
 
715
-            foreach ($files as $file) {
716
-                if (is_dir($file)) {
810
+            foreach ($files as $file)
811
+            {
812
+                if (is_dir($file))
813
+                {
717 814
                     $file = $this->_slashify($file);
718 815
                 }
719 816
 
720 817
                 $destfile = str_replace($source, $dest, $file);
721 818
 
722
-                if (is_dir($file)) {
723
-                    if (!file_exists($destfile)) {
724
-                        if (!$this->_is_writable(dirname($destfile))) {
819
+                if (is_dir($file))
820
+                {
821
+                    if (!file_exists($destfile))
822
+                    {
823
+                        if (!$this->_is_writable(dirname($destfile)))
824
+                        {
725 825
                             return "403 Forbidden";
726 826
                         }
727
-                        if (!mkdir($destfile)) {
827
+                        if (!mkdir($destfile))
828
+                        {
728 829
                             return "409 Conflict";
729 830
                         }
730
-                    } else if (!is_dir($destfile)) {
831
+                    }
832
+                    else if (!is_dir($destfile))
833
+                    {
731 834
                         return "409 Conflict";
732 835
                     }
733
-                } else {
836
+                }
837
+                else
838
+                {
734 839
 
735
-                    if (!copy($file, $destfile)) {
840
+                    if (!copy($file, $destfile))
841
+                    {
736 842
                         return "409 Conflict";
737 843
                     }
738 844
                 }
@@ -762,17 +868,24 @@  discard block
 block discarded – undo
762 868
         $dir  = dirname($path)."/";
763 869
         $base = basename($path);
764 870
 
765
-        foreach ($options["props"] as $key => $prop) {
766
-            if ($prop["ns"] == "DAV:") {
871
+        foreach ($options["props"] as $key => $prop)
872
+        {
873
+            if ($prop["ns"] == "DAV:")
874
+            {
767 875
                 $options["props"][$key]['status'] = "403 Forbidden";
768
-            } else {
769
-                if (isset($prop["val"])) {
876
+            }
877
+            else
878
+            {
879
+                if (isset($prop["val"]))
880
+                {
770 881
                     $query = "REPLACE INTO {$this->db_prefix}properties
771 882
                                            SET path = '$options[path]'
772 883
                                              , name = '$prop[name]'
773 884
                                              , ns= '$prop[ns]'
774 885
                                              , value = '$prop[val]'";
775
-                } else {
886
+                }
887
+                else
888
+                {
776 889
                     $query = "DELETE FROM {$this->db_prefix}properties
777 890
                                         WHERE path = '$options[path]'
778 891
                                           AND name = '$prop[name]'
@@ -799,13 +912,16 @@  discard block
 block discarded – undo
799 912
 
800 913
         // TODO recursive locks on directories not supported yet
801 914
         // makes litmus test "32. lock_collection" fail
802
-        if (is_dir($fspath) && !empty($options["depth"])) {
915
+        if (is_dir($fspath) && !empty($options["depth"]))
916
+        {
803 917
             return "409 Conflict";
804 918
         }
805 919
 
806 920
         $options["timeout"] = time()+300; // 5min. hardcoded
807 921
 
808
-        if (isset($options["update"])) { // Lock Update
922
+        if (isset($options["update"]))
923
+        {
924
+// Lock Update
809 925
             $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
810 926
 
811 927
             $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
@@ -813,7 +929,8 @@  discard block
 block discarded – undo
813 929
             $row   = mysql_fetch_assoc($res);
814 930
             mysql_free_result($res);
815 931
 
816
-            if (is_array($row)) {
932
+            if (is_array($row))
933
+            {
817 934
                 $query = "UPDATE {$this->db_prefix}locks
818 935
                                  SET expires = '$options[timeout]'
819 936
                                    , modified = ".time()."
@@ -825,7 +942,9 @@  discard block
 block discarded – undo
825 942
                 $options['type']  = $row["exclusivelock"] ? "write"     : "read";
826 943
 
827 944
                 return true;
828
-            } else {
945
+            }
946
+            else
947
+            {
829 948
                 return false;
830 949
             }
831 950
         }
@@ -876,11 +995,13 @@  discard block
 block discarded – undo
876 995
                ";
877 996
         $res = mysql_query($query);
878 997
 
879
-        if ($res) {
998
+        if ($res)
999
+        {
880 1000
             $row = mysql_fetch_array($res);
881 1001
             mysql_free_result($res);
882 1002
 
883
-            if ($row) {
1003
+            if ($row)
1004
+            {
884 1005
                 $result = array( "type"    => "write",
885 1006
                                  "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886 1007
                                  "depth"   => 0,
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -689,13 +689,13 @@  discard block
 block discarded – undo
689 689
             }
690 690
             $destpath = $this->_unslashify($options["dest"]);
691 691
             if (is_dir($source)) {
692
-                $query = "UPDATE {$this->db_prefix}properties
692
+                $query = "update {$this->db_prefix}properties
693 693
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
694 694
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
695 695
                 mysql_query($query);
696 696
             }
697 697
 
698
-            $query = "UPDATE {$this->db_prefix}properties
698
+            $query = "update {$this->db_prefix}properties
699 699
                              SET path = '".$destpath."'
700 700
                            WHERE path = '".$options["path"]."'";
701 701
             mysql_query($query);
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
             mysql_free_result($res);
815 815
 
816 816
             if (is_array($row)) {
817
-                $query = "UPDATE {$this->db_prefix}locks
817
+                $query = "update {$this->db_prefix}locks
818 818
                                  SET expires = '$options[timeout]'
819 819
                                    , modified = ".time()."
820 820
                               $where";
Please login to merge, or discard this patch.
api/src/WebDAV/Tools/_parse_lockinfo.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -87,6 +87,7 @@
 block discarded – undo
87 87
      * constructor
88 88
      *
89 89
      * @param  string  path of stream to read
90
+     * @param string $path
90 91
      * @access public
91 92
      */
92 93
     function __construct($path)
Please login to merge, or discard this patch.
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -43,209 +43,209 @@
 block discarded – undo
43 43
  */
44 44
 class _parse_lockinfo
45 45
 {
46
-    /**
47
-     * success state flag
48
-     *
49
-     * @var bool
50
-     * @access public
51
-     */
52
-    var $success = false;
53
-
54
-    /**
55
-     * lock type, currently only "write"
56
-     *
57
-     * @var string
58
-     * @access public
59
-     */
60
-    var $locktype = "";
61
-
62
-    /**
63
-     * lock scope, "shared" or "exclusive"
64
-     *
65
-     * @var string
66
-     * @access public
67
-     */
68
-    var $lockscope = "";
69
-
70
-    /**
71
-     * lock owner information
72
-     *
73
-     * @var string
74
-     * @access public
75
-     */
76
-    var $owner = "";
77
-
78
-    /**
79
-     * flag that is set during lock owner read
80
-     *
81
-     * @var bool
82
-     * @access private
83
-     */
84
-    var $collect_owner = false;
85
-
86
-    /**
87
-     * constructor
88
-     *
89
-     * @param  string  path of stream to read
90
-     * @access public
91
-     */
92
-    function __construct($path)
93
-    {
94
-        // we assume success unless problems occur
95
-        $this->success = true;
96
-
97
-        // remember if any input was parsed
98
-        $had_input = false;
99
-
100
-        // open stream
101
-        $f_in = fopen($path, "r");
102
-        if (!$f_in) {
103
-            $this->success = false;
104
-            return;
105
-        }
106
-
107
-        // create namespace aware parser
108
-        $xml_parser = xml_parser_create_ns("UTF-8", " ");
109
-
110
-        // set tag and data handlers
111
-        xml_set_element_handler($xml_parser,
112
-                                array(&$this, "_startElement"),
113
-                                array(&$this, "_endElement"));
114
-        xml_set_character_data_handler($xml_parser,
115
-                                       array(&$this, "_data"));
116
-
117
-        // we want a case sensitive parser
118
-        xml_parser_set_option($xml_parser,
119
-                              XML_OPTION_CASE_FOLDING, false);
120
-
121
-        // parse input
122
-        while ($this->success && !feof($f_in)) {
123
-            $line = fgets($f_in);
124
-            if (is_string($line)) {
125
-                $had_input = true;
126
-                $this->success &= xml_parse($xml_parser, $line, false);
127
-            }
128
-        }
129
-
130
-        // finish parsing
131
-        if ($had_input) {
132
-            $this->success &= xml_parse($xml_parser, "", true);
133
-        }
134
-
135
-        // check if required tags where found
136
-        $this->success &= !empty($this->locktype);
137
-        $this->success &= !empty($this->lockscope);
138
-
139
-        // free parser resource
140
-        xml_parser_free($xml_parser);
141
-
142
-        // close input stream
143
-        fclose($f_in);
144
-    }
145
-
146
-
147
-    /**
148
-     * tag start handler
149
-     *
150
-     * @param  resource  parser
151
-     * @param  string    tag name
152
-     * @param  array     tag attributes
153
-     * @return void
154
-     * @access private
155
-     */
156
-    function _startElement($parser, $name, $attrs)
157
-    {
158
-        // namespace handling
159
-        if (strstr($name, " ")) {
160
-            list($ns, $tag) = explode(" ", $name);
161
-        } else {
162
-            $ns  = "";
163
-            $tag = $name;
164
-        }
165
-
166
-
167
-        if ($this->collect_owner) {
168
-            // everything within the <owner> tag needs to be collected
169
-            $ns_short = "";
170
-            $ns_attr  = "";
171
-            if ($ns) {
172
-                if ($ns == "DAV:") {
173
-                    $ns_short = "D:";
174
-                } else {
175
-                    $ns_attr = " xmlns='$ns'";
176
-                }
177
-            }
178
-            $this->owner .= "<$ns_short$tag$ns_attr>";
179
-        } else if ($ns == "DAV:") {
180
-            // parse only the essential tags
181
-            switch ($tag) {
182
-            case "write":
183
-                $this->locktype = $tag;
184
-                break;
185
-            case "exclusive":
186
-            case "shared":
187
-                $this->lockscope = $tag;
188
-                break;
189
-            case "owner":
190
-                $this->collect_owner = true;
191
-                break;
192
-            }
193
-        }
194
-    }
195
-
196
-    /**
197
-     * data handler
198
-     *
199
-     * @param  resource  parser
200
-     * @param  string    data
201
-     * @return void
202
-     * @access private
203
-     */
204
-    function _data($parser, $data)
205
-    {
206
-        // only the <owner> tag has data content
207
-        if ($this->collect_owner) {
208
-            $this->owner .= $data;
209
-        }
210
-    }
211
-
212
-    /**
213
-     * tag end handler
214
-     *
215
-     * @param  resource  parser
216
-     * @param  string    tag name
217
-     * @return void
218
-     * @access private
219
-     */
220
-    function _endElement($parser, $name)
221
-    {
222
-        // namespace handling
223
-        if (strstr($name, " ")) {
224
-            list($ns, $tag) = explode(" ", $name);
225
-        } else {
226
-            $ns  = "";
227
-            $tag = $name;
228
-        }
229
-
230
-        // <owner> finished?
231
-        if (($ns == "DAV:") && ($tag == "owner")) {
232
-            $this->collect_owner = false;
233
-        }
234
-
235
-        // within <owner> we have to collect everything
236
-        if ($this->collect_owner) {
237
-            $ns_short = "";
238
-            $ns_attr  = "";
239
-            if ($ns) {
240
-                if ($ns == "DAV:") {
241
-                    $ns_short = "D:";
242
-                } else {
243
-                    $ns_attr = " xmlns='$ns'";
244
-                }
245
-            }
246
-            $this->owner .= "</$ns_short$tag$ns_attr>";
247
-        }
248
-    }
46
+	/**
47
+	 * success state flag
48
+	 *
49
+	 * @var bool
50
+	 * @access public
51
+	 */
52
+	var $success = false;
53
+
54
+	/**
55
+	 * lock type, currently only "write"
56
+	 *
57
+	 * @var string
58
+	 * @access public
59
+	 */
60
+	var $locktype = "";
61
+
62
+	/**
63
+	 * lock scope, "shared" or "exclusive"
64
+	 *
65
+	 * @var string
66
+	 * @access public
67
+	 */
68
+	var $lockscope = "";
69
+
70
+	/**
71
+	 * lock owner information
72
+	 *
73
+	 * @var string
74
+	 * @access public
75
+	 */
76
+	var $owner = "";
77
+
78
+	/**
79
+	 * flag that is set during lock owner read
80
+	 *
81
+	 * @var bool
82
+	 * @access private
83
+	 */
84
+	var $collect_owner = false;
85
+
86
+	/**
87
+	 * constructor
88
+	 *
89
+	 * @param  string  path of stream to read
90
+	 * @access public
91
+	 */
92
+	function __construct($path)
93
+	{
94
+		// we assume success unless problems occur
95
+		$this->success = true;
96
+
97
+		// remember if any input was parsed
98
+		$had_input = false;
99
+
100
+		// open stream
101
+		$f_in = fopen($path, "r");
102
+		if (!$f_in) {
103
+			$this->success = false;
104
+			return;
105
+		}
106
+
107
+		// create namespace aware parser
108
+		$xml_parser = xml_parser_create_ns("UTF-8", " ");
109
+
110
+		// set tag and data handlers
111
+		xml_set_element_handler($xml_parser,
112
+								array(&$this, "_startElement"),
113
+								array(&$this, "_endElement"));
114
+		xml_set_character_data_handler($xml_parser,
115
+									   array(&$this, "_data"));
116
+
117
+		// we want a case sensitive parser
118
+		xml_parser_set_option($xml_parser,
119
+							  XML_OPTION_CASE_FOLDING, false);
120
+
121
+		// parse input
122
+		while ($this->success && !feof($f_in)) {
123
+			$line = fgets($f_in);
124
+			if (is_string($line)) {
125
+				$had_input = true;
126
+				$this->success &= xml_parse($xml_parser, $line, false);
127
+			}
128
+		}
129
+
130
+		// finish parsing
131
+		if ($had_input) {
132
+			$this->success &= xml_parse($xml_parser, "", true);
133
+		}
134
+
135
+		// check if required tags where found
136
+		$this->success &= !empty($this->locktype);
137
+		$this->success &= !empty($this->lockscope);
138
+
139
+		// free parser resource
140
+		xml_parser_free($xml_parser);
141
+
142
+		// close input stream
143
+		fclose($f_in);
144
+	}
145
+
146
+
147
+	/**
148
+	 * tag start handler
149
+	 *
150
+	 * @param  resource  parser
151
+	 * @param  string    tag name
152
+	 * @param  array     tag attributes
153
+	 * @return void
154
+	 * @access private
155
+	 */
156
+	function _startElement($parser, $name, $attrs)
157
+	{
158
+		// namespace handling
159
+		if (strstr($name, " ")) {
160
+			list($ns, $tag) = explode(" ", $name);
161
+		} else {
162
+			$ns  = "";
163
+			$tag = $name;
164
+		}
165
+
166
+
167
+		if ($this->collect_owner) {
168
+			// everything within the <owner> tag needs to be collected
169
+			$ns_short = "";
170
+			$ns_attr  = "";
171
+			if ($ns) {
172
+				if ($ns == "DAV:") {
173
+					$ns_short = "D:";
174
+				} else {
175
+					$ns_attr = " xmlns='$ns'";
176
+				}
177
+			}
178
+			$this->owner .= "<$ns_short$tag$ns_attr>";
179
+		} else if ($ns == "DAV:") {
180
+			// parse only the essential tags
181
+			switch ($tag) {
182
+			case "write":
183
+				$this->locktype = $tag;
184
+				break;
185
+			case "exclusive":
186
+			case "shared":
187
+				$this->lockscope = $tag;
188
+				break;
189
+			case "owner":
190
+				$this->collect_owner = true;
191
+				break;
192
+			}
193
+		}
194
+	}
195
+
196
+	/**
197
+	 * data handler
198
+	 *
199
+	 * @param  resource  parser
200
+	 * @param  string    data
201
+	 * @return void
202
+	 * @access private
203
+	 */
204
+	function _data($parser, $data)
205
+	{
206
+		// only the <owner> tag has data content
207
+		if ($this->collect_owner) {
208
+			$this->owner .= $data;
209
+		}
210
+	}
211
+
212
+	/**
213
+	 * tag end handler
214
+	 *
215
+	 * @param  resource  parser
216
+	 * @param  string    tag name
217
+	 * @return void
218
+	 * @access private
219
+	 */
220
+	function _endElement($parser, $name)
221
+	{
222
+		// namespace handling
223
+		if (strstr($name, " ")) {
224
+			list($ns, $tag) = explode(" ", $name);
225
+		} else {
226
+			$ns  = "";
227
+			$tag = $name;
228
+		}
229
+
230
+		// <owner> finished?
231
+		if (($ns == "DAV:") && ($tag == "owner")) {
232
+			$this->collect_owner = false;
233
+		}
234
+
235
+		// within <owner> we have to collect everything
236
+		if ($this->collect_owner) {
237
+			$ns_short = "";
238
+			$ns_attr  = "";
239
+			if ($ns) {
240
+				if ($ns == "DAV:") {
241
+					$ns_short = "D:";
242
+				} else {
243
+					$ns_attr = " xmlns='$ns'";
244
+				}
245
+			}
246
+			$this->owner .= "</$ns_short$tag$ns_attr>";
247
+		}
248
+	}
249 249
 }
250 250
 
251 251
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -179,16 +179,16 @@
 block discarded – undo
179 179
         } else if ($ns == "DAV:") {
180 180
             // parse only the essential tags
181 181
             switch ($tag) {
182
-            case "write":
183
-                $this->locktype = $tag;
184
-                break;
185
-            case "exclusive":
186
-            case "shared":
187
-                $this->lockscope = $tag;
188
-                break;
189
-            case "owner":
190
-                $this->collect_owner = true;
191
-                break;
182
+            	case "write":
183
+                	$this->locktype = $tag;
184
+                	break;
185
+            	case "exclusive":
186
+            	case "shared":
187
+                	$this->lockscope = $tag;
188
+                	break;
189
+            	case "owner":
190
+                	$this->collect_owner = true;
191
+                	break;
192 192
             }
193 193
         }
194 194
     }
Please login to merge, or discard this patch.
Braces   +45 added lines, -20 removed lines patch added patch discarded remove patch
@@ -99,7 +99,8 @@  discard block
 block discarded – undo
99 99
 
100 100
         // open stream
101 101
         $f_in = fopen($path, "r");
102
-        if (!$f_in) {
102
+        if (!$f_in)
103
+        {
103 104
             $this->success = false;
104 105
             return;
105 106
         }
@@ -119,16 +120,19 @@  discard block
 block discarded – undo
119 120
                               XML_OPTION_CASE_FOLDING, false);
120 121
 
121 122
         // parse input
122
-        while ($this->success && !feof($f_in)) {
123
+        while ($this->success && !feof($f_in))
124
+        {
123 125
             $line = fgets($f_in);
124
-            if (is_string($line)) {
126
+            if (is_string($line))
127
+            {
125 128
                 $had_input = true;
126 129
                 $this->success &= xml_parse($xml_parser, $line, false);
127 130
             }
128 131
         }
129 132
 
130 133
         // finish parsing
131
-        if ($had_input) {
134
+        if ($had_input)
135
+        {
132 136
             $this->success &= xml_parse($xml_parser, "", true);
133 137
         }
134 138
 
@@ -156,29 +160,40 @@  discard block
 block discarded – undo
156 160
     function _startElement($parser, $name, $attrs)
157 161
     {
158 162
         // namespace handling
159
-        if (strstr($name, " ")) {
163
+        if (strstr($name, " "))
164
+        {
160 165
             list($ns, $tag) = explode(" ", $name);
161
-        } else {
166
+        }
167
+        else
168
+        {
162 169
             $ns  = "";
163 170
             $tag = $name;
164 171
         }
165 172
 
166 173
 
167
-        if ($this->collect_owner) {
174
+        if ($this->collect_owner)
175
+        {
168 176
             // everything within the <owner> tag needs to be collected
169 177
             $ns_short = "";
170 178
             $ns_attr  = "";
171
-            if ($ns) {
172
-                if ($ns == "DAV:") {
179
+            if ($ns)
180
+            {
181
+                if ($ns == "DAV:")
182
+                {
173 183
                     $ns_short = "D:";
174
-                } else {
184
+                }
185
+                else
186
+                {
175 187
                     $ns_attr = " xmlns='$ns'";
176 188
                 }
177 189
             }
178 190
             $this->owner .= "<$ns_short$tag$ns_attr>";
179
-        } else if ($ns == "DAV:") {
191
+        }
192
+        else if ($ns == "DAV:")
193
+        {
180 194
             // parse only the essential tags
181
-            switch ($tag) {
195
+            switch ($tag)
196
+            {
182 197
             case "write":
183 198
                 $this->locktype = $tag;
184 199
                 break;
@@ -204,7 +219,8 @@  discard block
 block discarded – undo
204 219
     function _data($parser, $data)
205 220
     {
206 221
         // only the <owner> tag has data content
207
-        if ($this->collect_owner) {
222
+        if ($this->collect_owner)
223
+        {
208 224
             $this->owner .= $data;
209 225
         }
210 226
     }
@@ -220,26 +236,35 @@  discard block
 block discarded – undo
220 236
     function _endElement($parser, $name)
221 237
     {
222 238
         // namespace handling
223
-        if (strstr($name, " ")) {
239
+        if (strstr($name, " "))
240
+        {
224 241
             list($ns, $tag) = explode(" ", $name);
225
-        } else {
242
+        }
243
+        else
244
+        {
226 245
             $ns  = "";
227 246
             $tag = $name;
228 247
         }
229 248
 
230 249
         // <owner> finished?
231
-        if (($ns == "DAV:") && ($tag == "owner")) {
250
+        if (($ns == "DAV:") && ($tag == "owner"))
251
+        {
232 252
             $this->collect_owner = false;
233 253
         }
234 254
 
235 255
         // within <owner> we have to collect everything
236
-        if ($this->collect_owner) {
256
+        if ($this->collect_owner)
257
+        {
237 258
             $ns_short = "";
238 259
             $ns_attr  = "";
239
-            if ($ns) {
240
-                if ($ns == "DAV:") {
260
+            if ($ns)
261
+            {
262
+                if ($ns == "DAV:")
263
+                {
241 264
                     $ns_short = "D:";
242
-                } else {
265
+                }
266
+                else
267
+                {
243 268
                     $ns_attr = " xmlns='$ns'";
244 269
                 }
245 270
             }
Please login to merge, or discard this patch.
api/src/WebDAV/Tools/_parse_proppatch.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -95,6 +95,7 @@
 block discarded – undo
95 95
      *
96 96
      * @param  string  path of input stream
97 97
      * @param boolean $store_request =false if true whole request data will be made available in $this->request
98
+     * @param string $path
98 99
      * @access public
99 100
      */
100 101
     function __construct($path, $store_request=false)
Please login to merge, or discard this patch.
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -43,198 +43,198 @@
 block discarded – undo
43 43
  */
44 44
 class _parse_proppatch
45 45
 {
46
-    /**
47
-     *
48
-     *
49
-     * @var
50
-     * @access
51
-     */
52
-    var $success;
53
-
54
-    /**
55
-     *
56
-     *
57
-     * @var
58
-     * @access
59
-     */
60
-    var $props;
61
-
62
-    /**
63
-     *
64
-     *
65
-     * @var
66
-     * @access
67
-     */
68
-    var $depth;
69
-
70
-    /**
71
-     *
72
-     *
73
-     * @var
74
-     * @access
75
-     */
76
-    var $mode;
77
-
78
-    /**
79
-     *
80
-     *
81
-     * @var
82
-     * @access
83
-     */
84
-    var $current;
85
-
86
-    /**
87
-     * On return whole request, if $store_request == true was specified in constructor
88
-     *
89
-     * @var string
90
-     */
91
-    var $request;
92
-
93
-    /**
94
-     * constructor
95
-     *
96
-     * @param  string  path of input stream
97
-     * @param boolean $store_request =false if true whole request data will be made available in $this->request
98
-     * @access public
99
-     */
100
-    function __construct($path, $store_request=false)
101
-    {
102
-        $this->success = true;
103
-
104
-        $this->depth = 0;
105
-        $this->props = array();
106
-        $had_input = false;
107
-
108
-        $f_in = fopen($path, "r");
109
-        if (!$f_in) {
110
-            $this->success = false;
111
-            return;
112
-        }
113
-
114
-        $xml_parser = xml_parser_create_ns("UTF-8", " ");
115
-
116
-        xml_set_element_handler($xml_parser,
117
-                                array(&$this, "_startElement"),
118
-                                array(&$this, "_endElement"));
119
-
120
-        xml_set_character_data_handler($xml_parser,
121
-                                       array(&$this, "_data"));
122
-
123
-        xml_parser_set_option($xml_parser,
124
-                              XML_OPTION_CASE_FOLDING, false);
125
-
126
-        while($this->success && !feof($f_in)) {
127
-            $line = fgets($f_in);
128
-            if ($store_request) $this->request .= $line;
129
-            if (is_string($line)) {
130
-                $had_input = true;
131
-                $this->success &= xml_parse($xml_parser, $line, false);
132
-            }
133
-        }
134
-
135
-        if($had_input) {
136
-            $this->success &= xml_parse($xml_parser, "", true);
137
-        }
138
-
139
-        xml_parser_free($xml_parser);
140
-
141
-        fclose($f_in);
142
-    }
143
-
144
-    /**
145
-     * tag start handler
146
-     *
147
-     * @param  resource  parser
148
-     * @param  string    tag name
149
-     * @param  array     tag attributes
150
-     * @return void
151
-     * @access private
152
-     */
153
-    function _startElement($parser, $name, $attrs)
154
-    {
155
-        if (strstr($name, " ")) {
156
-            list($ns, $tag) = explode(" ", $name);
157
-            if ($ns == "")
158
-                $this->success = false;
159
-        } else {
160
-            $ns = "";
161
-            $tag = $name;
162
-        }
163
-
164
-        if ($this->depth == 1) {
165
-            $this->mode = $tag;
166
-        }
167
-
168
-        if ($this->depth == 3) {
169
-            $prop = array("name" => $tag);
170
-            $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
-            if ($this->mode == "set") {
172
-                $this->current["val"] = "";     // default set val
173
-            }
174
-        }
175
-
176
-        if ($this->depth >= 4) {
177
-            $this->current["val"] .= "<$tag";
178
-            if (isset($attr)) {
179
-                foreach ($attr as $key => $val) {
180
-                    $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181
-                }
182
-            }
183
-            $this->current["val"] .= ">";
184
-        }
185
-
186
-
187
-
188
-        $this->depth++;
189
-    }
190
-
191
-    /**
192
-     * tag end handler
193
-     *
194
-     * @param  resource  parser
195
-     * @param  string    tag name
196
-     * @return void
197
-     * @access private
198
-     */
199
-    function _endElement($parser, $name)
200
-    {
201
-        if (strstr($name, " ")) {
202
-            list($ns, $tag) = explode(" ", $name);
203
-            if ($ns == "")
204
-                $this->success = false;
205
-        } else {
206
-            $ns = "";
207
-            $tag = $name;
208
-        }
209
-
210
-        $this->depth--;
211
-
212
-        if ($this->depth >= 4) {
213
-            $this->current["val"] .= "</$tag>";
214
-        }
215
-
216
-        if ($this->depth == 3) {
217
-            if (isset($this->current)) {
218
-                $this->props[] = $this->current;
219
-                unset($this->current);
220
-            }
221
-        }
222
-    }
223
-
224
-    /**
225
-     * input data handler
226
-     *
227
-     * @param  resource  parser
228
-     * @param  string    data
229
-     * @return void
230
-     * @access private
231
-     */
232
-    function _data($parser, $data)
233
-    {
234
-        if (isset($this->current)) {
235
-            $this->current["val"] .= $data;
236
-        }
237
-    }
46
+	/**
47
+	 *
48
+	 *
49
+	 * @var
50
+	 * @access
51
+	 */
52
+	var $success;
53
+
54
+	/**
55
+	 *
56
+	 *
57
+	 * @var
58
+	 * @access
59
+	 */
60
+	var $props;
61
+
62
+	/**
63
+	 *
64
+	 *
65
+	 * @var
66
+	 * @access
67
+	 */
68
+	var $depth;
69
+
70
+	/**
71
+	 *
72
+	 *
73
+	 * @var
74
+	 * @access
75
+	 */
76
+	var $mode;
77
+
78
+	/**
79
+	 *
80
+	 *
81
+	 * @var
82
+	 * @access
83
+	 */
84
+	var $current;
85
+
86
+	/**
87
+	 * On return whole request, if $store_request == true was specified in constructor
88
+	 *
89
+	 * @var string
90
+	 */
91
+	var $request;
92
+
93
+	/**
94
+	 * constructor
95
+	 *
96
+	 * @param  string  path of input stream
97
+	 * @param boolean $store_request =false if true whole request data will be made available in $this->request
98
+	 * @access public
99
+	 */
100
+	function __construct($path, $store_request=false)
101
+	{
102
+		$this->success = true;
103
+
104
+		$this->depth = 0;
105
+		$this->props = array();
106
+		$had_input = false;
107
+
108
+		$f_in = fopen($path, "r");
109
+		if (!$f_in) {
110
+			$this->success = false;
111
+			return;
112
+		}
113
+
114
+		$xml_parser = xml_parser_create_ns("UTF-8", " ");
115
+
116
+		xml_set_element_handler($xml_parser,
117
+								array(&$this, "_startElement"),
118
+								array(&$this, "_endElement"));
119
+
120
+		xml_set_character_data_handler($xml_parser,
121
+									   array(&$this, "_data"));
122
+
123
+		xml_parser_set_option($xml_parser,
124
+							  XML_OPTION_CASE_FOLDING, false);
125
+
126
+		while($this->success && !feof($f_in)) {
127
+			$line = fgets($f_in);
128
+			if ($store_request) $this->request .= $line;
129
+			if (is_string($line)) {
130
+				$had_input = true;
131
+				$this->success &= xml_parse($xml_parser, $line, false);
132
+			}
133
+		}
134
+
135
+		if($had_input) {
136
+			$this->success &= xml_parse($xml_parser, "", true);
137
+		}
138
+
139
+		xml_parser_free($xml_parser);
140
+
141
+		fclose($f_in);
142
+	}
143
+
144
+	/**
145
+	 * tag start handler
146
+	 *
147
+	 * @param  resource  parser
148
+	 * @param  string    tag name
149
+	 * @param  array     tag attributes
150
+	 * @return void
151
+	 * @access private
152
+	 */
153
+	function _startElement($parser, $name, $attrs)
154
+	{
155
+		if (strstr($name, " ")) {
156
+			list($ns, $tag) = explode(" ", $name);
157
+			if ($ns == "")
158
+				$this->success = false;
159
+		} else {
160
+			$ns = "";
161
+			$tag = $name;
162
+		}
163
+
164
+		if ($this->depth == 1) {
165
+			$this->mode = $tag;
166
+		}
167
+
168
+		if ($this->depth == 3) {
169
+			$prop = array("name" => $tag);
170
+			$this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
+			if ($this->mode == "set") {
172
+				$this->current["val"] = "";     // default set val
173
+			}
174
+		}
175
+
176
+		if ($this->depth >= 4) {
177
+			$this->current["val"] .= "<$tag";
178
+			if (isset($attr)) {
179
+				foreach ($attr as $key => $val) {
180
+					$this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181
+				}
182
+			}
183
+			$this->current["val"] .= ">";
184
+		}
185
+
186
+
187
+
188
+		$this->depth++;
189
+	}
190
+
191
+	/**
192
+	 * tag end handler
193
+	 *
194
+	 * @param  resource  parser
195
+	 * @param  string    tag name
196
+	 * @return void
197
+	 * @access private
198
+	 */
199
+	function _endElement($parser, $name)
200
+	{
201
+		if (strstr($name, " ")) {
202
+			list($ns, $tag) = explode(" ", $name);
203
+			if ($ns == "")
204
+				$this->success = false;
205
+		} else {
206
+			$ns = "";
207
+			$tag = $name;
208
+		}
209
+
210
+		$this->depth--;
211
+
212
+		if ($this->depth >= 4) {
213
+			$this->current["val"] .= "</$tag>";
214
+		}
215
+
216
+		if ($this->depth == 3) {
217
+			if (isset($this->current)) {
218
+				$this->props[] = $this->current;
219
+				unset($this->current);
220
+			}
221
+		}
222
+	}
223
+
224
+	/**
225
+	 * input data handler
226
+	 *
227
+	 * @param  resource  parser
228
+	 * @param  string    data
229
+	 * @return void
230
+	 * @access private
231
+	 */
232
+	function _data($parser, $data)
233
+	{
234
+		if (isset($this->current)) {
235
+			$this->current["val"] .= $data;
236
+		}
237
+	}
238 238
 }
239 239
 
240 240
 /*
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      * @param boolean $store_request =false if true whole request data will be made available in $this->request
98 98
      * @access public
99 99
      */
100
-    function __construct($path, $store_request=false)
100
+    function __construct($path, $store_request = false)
101 101
     {
102 102
         $this->success = true;
103 103
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         xml_parser_set_option($xml_parser,
124 124
                               XML_OPTION_CASE_FOLDING, false);
125 125
 
126
-        while($this->success && !feof($f_in)) {
126
+        while ($this->success && !feof($f_in)) {
127 127
             $line = fgets($f_in);
128 128
             if ($store_request) $this->request .= $line;
129 129
             if (is_string($line)) {
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             }
133 133
         }
134 134
 
135
-        if($had_input) {
135
+        if ($had_input) {
136 136
             $this->success &= xml_parse($xml_parser, "", true);
137 137
         }
138 138
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             $prop = array("name" => $tag);
170 170
             $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171 171
             if ($this->mode == "set") {
172
-                $this->current["val"] = "";     // default set val
172
+                $this->current["val"] = ""; // default set val
173 173
             }
174 174
         }
175 175
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             $this->current["val"] .= "<$tag";
178 178
             if (isset($attr)) {
179 179
                 foreach ($attr as $key => $val) {
180
-                    $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
180
+                    $this->current["val"] .= ' '.$key.'="'.str_replace('"', '&quot;', $val).'"';
181 181
                 }
182 182
             }
183 183
             $this->current["val"] .= ">";
Please login to merge, or discard this patch.
Braces   +48 added lines, -21 removed lines patch added patch discarded remove patch
@@ -106,7 +106,8 @@  discard block
 block discarded – undo
106 106
         $had_input = false;
107 107
 
108 108
         $f_in = fopen($path, "r");
109
-        if (!$f_in) {
109
+        if (!$f_in)
110
+        {
110 111
             $this->success = false;
111 112
             return;
112 113
         }
@@ -123,16 +124,22 @@  discard block
 block discarded – undo
123 124
         xml_parser_set_option($xml_parser,
124 125
                               XML_OPTION_CASE_FOLDING, false);
125 126
 
126
-        while($this->success && !feof($f_in)) {
127
+        while($this->success && !feof($f_in))
128
+        {
127 129
             $line = fgets($f_in);
128
-            if ($store_request) $this->request .= $line;
129
-            if (is_string($line)) {
130
+            if ($store_request)
131
+            {
132
+            	$this->request .= $line;
133
+            }
134
+            if (is_string($line))
135
+            {
130 136
                 $had_input = true;
131 137
                 $this->success &= xml_parse($xml_parser, $line, false);
132 138
             }
133 139
         }
134 140
 
135
-        if($had_input) {
141
+        if($had_input)
142
+        {
136 143
             $this->success &= xml_parse($xml_parser, "", true);
137 144
         }
138 145
 
@@ -152,31 +159,42 @@  discard block
 block discarded – undo
152 159
      */
153 160
     function _startElement($parser, $name, $attrs)
154 161
     {
155
-        if (strstr($name, " ")) {
162
+        if (strstr($name, " "))
163
+        {
156 164
             list($ns, $tag) = explode(" ", $name);
157 165
             if ($ns == "")
158
-                $this->success = false;
159
-        } else {
166
+            {
167
+                            $this->success = false;
168
+            }
169
+        }
170
+        else
171
+        {
160 172
             $ns = "";
161 173
             $tag = $name;
162 174
         }
163 175
 
164
-        if ($this->depth == 1) {
176
+        if ($this->depth == 1)
177
+        {
165 178
             $this->mode = $tag;
166 179
         }
167 180
 
168
-        if ($this->depth == 3) {
181
+        if ($this->depth == 3)
182
+        {
169 183
             $prop = array("name" => $tag);
170 184
             $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
-            if ($this->mode == "set") {
185
+            if ($this->mode == "set")
186
+            {
172 187
                 $this->current["val"] = "";     // default set val
173 188
             }
174 189
         }
175 190
 
176
-        if ($this->depth >= 4) {
191
+        if ($this->depth >= 4)
192
+        {
177 193
             $this->current["val"] .= "<$tag";
178
-            if (isset($attr)) {
179
-                foreach ($attr as $key => $val) {
194
+            if (isset($attr))
195
+            {
196
+                foreach ($attr as $key => $val)
197
+                {
180 198
                     $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181 199
                 }
182 200
             }
@@ -198,23 +216,31 @@  discard block
 block discarded – undo
198 216
      */
199 217
     function _endElement($parser, $name)
200 218
     {
201
-        if (strstr($name, " ")) {
219
+        if (strstr($name, " "))
220
+        {
202 221
             list($ns, $tag) = explode(" ", $name);
203 222
             if ($ns == "")
204
-                $this->success = false;
205
-        } else {
223
+            {
224
+                            $this->success = false;
225
+            }
226
+        }
227
+        else
228
+        {
206 229
             $ns = "";
207 230
             $tag = $name;
208 231
         }
209 232
 
210 233
         $this->depth--;
211 234
 
212
-        if ($this->depth >= 4) {
235
+        if ($this->depth >= 4)
236
+        {
213 237
             $this->current["val"] .= "</$tag>";
214 238
         }
215 239
 
216
-        if ($this->depth == 3) {
217
-            if (isset($this->current)) {
240
+        if ($this->depth == 3)
241
+        {
242
+            if (isset($this->current))
243
+            {
218 244
                 $this->props[] = $this->current;
219 245
                 unset($this->current);
220 246
             }
@@ -231,7 +257,8 @@  discard block
 block discarded – undo
231 257
      */
232 258
     function _data($parser, $data)
233 259
     {
234
-        if (isset($this->current)) {
260
+        if (isset($this->current))
261
+        {
235 262
             $this->current["val"] .= $data;
236 263
         }
237 264
     }
Please login to merge, or discard this patch.
api/thumbnail.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -80,6 +80,7 @@
 block discarded – undo
80 80
 
81 81
 /**
82 82
  * Returns the maximum width/height of a thumbnail
83
+ * @return integer|null
83 84
  */
84 85
 function get_maxsize()
85 86
 {
Please login to merge, or discard this patch.
Spacing   +25 added lines, -26 removed lines patch added patch discarded remove patch
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 		}
71 71
 	}
72 72
 
73
-	if (!preg_match('/^[a-z0-9_-]+$/i',$app))
73
+	if (!preg_match('/^[a-z0-9_-]+$/i', $app))
74 74
 	{
75
-		die('Stop');	// just to prevent someone doing nasty things
75
+		die('Stop'); // just to prevent someone doing nasty things
76 76
 	}
77 77
 
78 78
 	return $app;
@@ -83,8 +83,7 @@  discard block
 block discarded – undo
83 83
  */
84 84
 function get_maxsize()
85 85
 {
86
-	$preset = !($GLOBALS['egw_info']['server']['link_list_thumbnail'] > 0) ? 64 :
87
-		$GLOBALS['egw_info']['server']['link_list_thumbnail'];
86
+	$preset = !($GLOBALS['egw_info']['server']['link_list_thumbnail'] > 0) ? 64 : $GLOBALS['egw_info']['server']['link_list_thumbnail'];
88 87
 
89 88
 	// Another maximum size may be passed if thumbnails are turned on
90 89
 	if ($preset != 0 && isset($_GET['thsize']) && is_numeric($_GET['thsize']))
@@ -150,7 +149,7 @@  discard block
 block discarded – undo
150 149
 	}
151 150
 	$dst = gen_dstfile($stat && !empty($stat['url']) ? $stat['url'] : $src, $maxsize, $height, $width, $minsize);
152 151
 	$dst_dir = dirname($dst);
153
-	if(file_exists($dst_dir))
152
+	if (file_exists($dst_dir))
154 153
 	{
155 154
 		// Check whether the destination file already exists and is newer than
156 155
 		// the source file. Assume the file doesn't exist if thumbnailing is turned off.
@@ -190,7 +189,7 @@  discard block
 block discarded – undo
190 189
 		{
191 190
 			// Allow client to cache these, makes scrolling in filemanager much nicer
192 191
 			// setting maximum allow caching time of one year, if url contains (non-empty) moditication time
193
-			Api\Session::cache_control(empty($_GET['mtime']) ? 300 : 31536000, true);	// true = private / browser only caching
192
+			Api\Session::cache_control(empty($_GET['mtime']) ? 300 : 31536000, true); // true = private / browser only caching
194 193
 			header('Content-Type: '.$output_mime);
195 194
 			readfile($dst);
196 195
 			return true;
@@ -212,7 +211,7 @@  discard block
 block discarded – undo
212 211
  * @param int $minsize =null
213 212
  * @return string
214 213
  */
215
-function gen_dstfile($src, $maxsize, $height=null, $width=null, $minsize=null)
214
+function gen_dstfile($src, $maxsize, $height = null, $width = null, $minsize = null)
216 215
 {
217 216
 	// Use the egroupware file cache to store the thumbnails on a per instance basis
218 217
 	$cachefile = new Api\Cache\Files(array());
@@ -238,7 +237,7 @@  discard block
 block discarded – undo
238 237
  * TODO: As this is a general purpose function, it might probably be moved
239 238
  *   to some other php file or an "image utils" class.
240 239
  */
241
-function get_scaled_image_size($w, $h, $maxw, $maxh, $minw=0, $minh=0)
240
+function get_scaled_image_size($w, $h, $maxw, $maxh, $minw = 0, $minh = 0)
242 241
 {
243 242
 	//Scale will contain the factor by which the image has to be scaled down
244 243
 	$scale = 1.0;
@@ -299,7 +298,7 @@  discard block
 block discarded – undo
299 298
  * @param int $maxh the maximum height of the thumbnail
300 299
  * @returns boolean|resource false or a gd_image
301 300
  */
302
-function gd_image_load($file,$maxw,$maxh)
301
+function gd_image_load($file, $maxw, $maxh)
303 302
 {
304 303
 	// Get mime type
305 304
 	list($type, $image_type) = explode('/', $mime = Vfs::mime_content_type($file));
@@ -307,9 +306,9 @@  discard block
 block discarded – undo
307 306
 	if (!$type) list($type, $image_type) = explode('/', $mime = Api\MimeMagic::filename2mime($file));
308 307
 
309 308
 	// Call the according gd constructor depending on the file type
310
-	if($type == 'image')
309
+	if ($type == 'image')
311 310
 	{
312
-		if (in_array($image_type, array('tiff','jpeg')) && ($image = exif_thumbnail_load($file)))
311
+		if (in_array($image_type, array('tiff', 'jpeg')) && ($image = exif_thumbnail_load($file)))
313 312
 		{
314 313
 			return $image;
315 314
 		}
@@ -332,12 +331,12 @@  discard block
 block discarded – undo
332 331
 	else if ($type == 'application')
333 332
 	{
334 333
 		$thumb = false;
335
-		if(strpos($image_type,'vnd.oasis.opendocument.') === 0)
334
+		if (strpos($image_type, 'vnd.oasis.opendocument.') === 0)
336 335
 		{
337 336
 			// OpenDocuments have thumbnails inside already
338 337
 			$thumb = get_opendocument_thumbnail($file);
339 338
 		}
340
-		else if($image_type == 'pdf')
339
+		else if ($image_type == 'pdf')
341 340
 		{
342 341
 			$thumb = get_pdf_thumbnail($file);
343 342
 		}
@@ -347,7 +346,7 @@  discard block
 block discarded – undo
347 346
 			//$thumb = get_msoffice_thumbnail($file);
348 347
 		}
349 348
 		// Mark it with mime type icon
350
-		if($thumb)
349
+		if ($thumb)
351 350
 		{
352 351
 			// Need to scale first, or the mark will be wrong size
353 352
 			$scaled = get_scaled_image_size(imagesx($thumb), imagesy($thumb), $maxw, $maxh);
@@ -387,8 +386,8 @@  discard block
 block discarded – undo
387 386
 
388 387
 	// Image is already there, but we can't access them directly through VFS
389 388
 	$ext = $mimetype == 'application/vnd.oasis.opendocument.text' ? '.odt' : '.ods';
390
-	$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($file,$ext).'-');
391
-	copy($file,$archive);
389
+	$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($file, $ext).'-');
390
+	copy($file, $archive);
392 391
 
393 392
 	$thumbnail_url = 'zip://'.$archive.'#Thumbnails/thumbnail.png';
394 393
 	$image = imagecreatefromstring(file_get_contents($thumbnail_url));
@@ -442,7 +441,7 @@  discard block
 block discarded – undo
442 441
  */
443 442
 function get_pdf_thumbnail($file)
444 443
 {
445
-	if(!pdf_thumbnails_available()) return false;
444
+	if (!pdf_thumbnails_available()) return false;
446 445
 
447 446
 	// switch off max_excution_time, as some thumbnails take longer and
448 447
 	// will be startet over and over again, if they dont finish
@@ -471,7 +470,7 @@  discard block
 block discarded – undo
471 470
 	$target_height = imagesy($target_image);
472 471
 
473 472
 	// Find mime image, if no tag image set
474
-	if(!$tag_image && $mime)
473
+	if (!$tag_image && $mime)
475 474
 	{
476 475
 		list($app, $icon) = explode('/', Vfs::mime_icon($mime), 2);
477 476
 		list(, $path) = explode($GLOBALS['egw_info']['server']['webserver_url'],
@@ -482,16 +481,16 @@  discard block
 block discarded – undo
482 481
 
483 482
 	// Find correct size - max 1/3 target
484 483
 	$tag_size = get_scaled_image_size(imagesx($tag_image), imagesy($tag_image), $target_width / 3, $target_height / 3);
485
-	if(!$tag_size) return;
486
-	list($tag_width,$tag_height) = $tag_size;
484
+	if (!$tag_size) return;
485
+	list($tag_width, $tag_height) = $tag_size;
487 486
 
488 487
 	// Put it in
489
-	if($mime)
488
+	if ($mime)
490 489
 	{
491
-		imagecopyresampled($target_image,$tag_image,
490
+		imagecopyresampled($target_image, $tag_image,
492 491
 			$target_width - $tag_width,
493 492
 			$target_height - $tag_height,
494
-			0,0,
493
+			0, 0,
495 494
 			$tag_width,
496 495
 			$tag_height,
497 496
 			imagesx($tag_image),
@@ -545,7 +544,7 @@  discard block
 block discarded – undo
545 544
 function gd_image_thumbnail($file, $maxw, $maxh, $minw, $minh)
546 545
 {
547 546
 	//Load the image
548
-	if (($img_src = gd_image_load($file,$maxw,$maxh)) !== false)
547
+	if (($img_src = gd_image_load($file, $maxw, $maxh)) !== false)
549 548
 	{
550 549
 		//Get the constraints of the image
551 550
 		$w = imagesx($img_src);
@@ -575,14 +574,14 @@  discard block
 block discarded – undo
575 574
 */
576 575
 function gdVersion($user_ver = 0)
577 576
 {
578
-	if (! extension_loaded('gd')) { return; }
577
+	if (!extension_loaded('gd')) { return; }
579 578
 	static $gd_ver = 0;
580 579
 
581 580
 	// Just accept the specified setting if it's 1.
582 581
 	if ($user_ver == 1) { $gd_ver = 1; return 1; }
583 582
 
584 583
 	// Use the static variable if function was called previously.
585
-	if ($user_ver !=2 && $gd_ver > 0 ) { return $gd_ver; }
584
+	if ($user_ver != 2 && $gd_ver > 0) { return $gd_ver; }
586 585
 
587 586
 	// Use the gd_info() function if possible.
588 587
 	if (function_exists('gd_info')) {
Please login to merge, or discard this patch.
Braces   +38 added lines, -12 removed lines patch added patch discarded remove patch
@@ -244,10 +244,13 @@  discard block
 block discarded – undo
244 244
 	$scale = 1.0;
245 245
 
246 246
 	//Select the constraining dimension
247
-	if ($w > $h) // landscape image: constraining factor $minh or $maxw
247
+	if ($w > $h)
248
+	{
249
+		// landscape image: constraining factor $minh or $maxw
248 250
 	{
249 251
 		$scale = $minh ? $minh / $h : $maxw / $w;
250 252
 	}
253
+	}
251 254
 	else // portrail image: constraining factor $minw or $maxh
252 255
 	{
253 256
 		$scale = $minw ? $minw / $w : $maxh / $h;
@@ -304,7 +307,10 @@  discard block
 block discarded – undo
304 307
 	// Get mime type
305 308
 	list($type, $image_type) = explode('/', $mime = Vfs::mime_content_type($file));
306 309
 	// if $file is not from vfs, use Api\MimeMagic::filename2mime to get mime-type from extension
307
-	if (!$type) list($type, $image_type) = explode('/', $mime = Api\MimeMagic::filename2mime($file));
310
+	if (!$type)
311
+	{
312
+		list($type, $image_type) = explode('/', $mime = Api\MimeMagic::filename2mime($file));
313
+	}
308 314
 
309 315
 	// Call the according gd constructor depending on the file type
310 316
 	if($type == 'image')
@@ -442,7 +448,10 @@  discard block
 block discarded – undo
442 448
  */
443 449
 function get_pdf_thumbnail($file)
444 450
 {
445
-	if(!pdf_thumbnails_available()) return false;
451
+	if(!pdf_thumbnails_available())
452
+	{
453
+		return false;
454
+	}
446 455
 
447 456
 	// switch off max_excution_time, as some thumbnails take longer and
448 457
 	// will be startet over and over again, if they dont finish
@@ -482,7 +491,10 @@  discard block
 block discarded – undo
482 491
 
483 492
 	// Find correct size - max 1/3 target
484 493
 	$tag_size = get_scaled_image_size(imagesx($tag_image), imagesy($tag_image), $target_width / 3, $target_height / 3);
485
-	if(!$tag_size) return;
494
+	if(!$tag_size)
495
+	{
496
+		return;
497
+	}
486 498
 	list($tag_width,$tag_height) = $tag_size;
487 499
 
488 500
 	// Put it in
@@ -575,17 +587,24 @@  discard block
 block discarded – undo
575 587
 */
576 588
 function gdVersion($user_ver = 0)
577 589
 {
578
-	if (! extension_loaded('gd')) { return; }
590
+	if (! extension_loaded('gd'))
591
+	{
592
+return; }
579 593
 	static $gd_ver = 0;
580 594
 
581 595
 	// Just accept the specified setting if it's 1.
582
-	if ($user_ver == 1) { $gd_ver = 1; return 1; }
596
+	if ($user_ver == 1)
597
+	{
598
+$gd_ver = 1; return 1; }
583 599
 
584 600
 	// Use the static variable if function was called previously.
585
-	if ($user_ver !=2 && $gd_ver > 0 ) { return $gd_ver; }
601
+	if ($user_ver !=2 && $gd_ver > 0 )
602
+	{
603
+return $gd_ver; }
586 604
 
587 605
 	// Use the gd_info() function if possible.
588
-	if (function_exists('gd_info')) {
606
+	if (function_exists('gd_info'))
607
+	{
589 608
 		$ver_info = gd_info();
590 609
 		$match = null;
591 610
 		preg_match('/\d/', $ver_info['GD Version'], $match);
@@ -594,11 +613,15 @@  discard block
 block discarded – undo
594 613
 	}
595 614
 
596 615
 	// If phpinfo() is disabled use a specified / fail-safe choice...
597
-	if (preg_match('/phpinfo/', ini_get('disable_functions'))) {
598
-		if ($user_ver == 2) {
616
+	if (preg_match('/phpinfo/', ini_get('disable_functions')))
617
+	{
618
+		if ($user_ver == 2)
619
+		{
599 620
 			$gd_ver = 2;
600 621
 			return 2;
601
-		} else {
622
+		}
623
+		else
624
+		{
602 625
 			$gd_ver = 1;
603 626
 			return 1;
604 627
 		}
@@ -607,6 +630,9 @@  discard block
 block discarded – undo
607 630
 	ob_start();
608 631
 	phpinfo(8);
609 632
 	$info = stristr(ob_get_clean(), 'gd version');
610
-	if (preg_match('/\d/', $info, $match)) $gd_ver = $match[0];
633
+	if (preg_match('/\d/', $info, $match))
634
+	{
635
+		$gd_ver = $match[0];
636
+	}
611 637
 	return $match[0];
612 638
 }
Please login to merge, or discard this patch.
calendar/importexport/class.import_events_csv.inc.php 4 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,6 @@
 block discarded – undo
94 94
 	/**
95 95
 	 * imports entries according to given definition object.
96 96
 	 * @param resource $_stream
97
-	 * @param string $_charset
98 97
 	 * @param definition $_definition
99 98
 	 */
100 99
 	public function import( $_stream, definition $_definition ) {
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 	private $user = null;
83 83
 
84 84
 	/**
85
-         * List of import errors
86
-         */
87
-        protected $errors = array();
85
+	 * List of import errors
86
+	 */
87
+		protected $errors = array();
88 88
 
89 89
 	/**
90 90
 	 * List of actions, and how many times that action was taken
@@ -305,26 +305,26 @@  discard block
 block discarded – undo
305 305
 	}
306 306
 
307 307
 	/**
308
-        * Returns errors that were encountered during importing
309
-        * Maximum of one error message per record, but you can append if you need to
310
-        *
311
-        * @return Array (
312
-        *       record_# => error message
313
-        *       )
314
-        */
315
-        public function get_errors() {
308
+	 * Returns errors that were encountered during importing
309
+	 * Maximum of one error message per record, but you can append if you need to
310
+	 *
311
+	 * @return Array (
312
+	 *       record_# => error message
313
+	 *       )
314
+	 */
315
+		public function get_errors() {
316 316
 		return $this->errors;
317 317
 	}
318 318
 
319 319
 	/**
320
-        * Returns a list of actions taken, and the number of records for that action.
321
-        * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
322
-        *
323
-        * @return Array (
324
-        *       action => record count
325
-        * )
326
-        */
327
-        public function get_results() {
320
+	 * Returns a list of actions taken, and the number of records for that action.
321
+	 * Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
322
+	 *
323
+	 * @return Array (
324
+	 *       action => record count
325
+	 * )
326
+	 */
327
+		public function get_results() {
328 328
 		return $this->results;
329 329
 	}
330 330
 } // end of iface_export_plugin
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -10,28 +10,28 @@  discard block
 block discarded – undo
10 10
  * @version $Id: $
11 11
  */
12 12
 
13
-require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.iface_import_plugin.inc.php');
13
+require_once(EGW_INCLUDE_ROOT.'/importexport/inc/class.iface_import_plugin.inc.php');
14 14
 require_once(EGW_INCLUDE_ROOT.'/importexport/inc/class.import_csv.inc.php');
15 15
 
16 16
 
17 17
 /**
18 18
  * class import_csv for addressbook
19 19
  */
20
-class import_events_csv implements iface_import_plugin  {
20
+class import_events_csv implements iface_import_plugin {
21 21
 
22 22
 	private static $plugin_options = array(
23
-		'fieldsep', 			// char
24
-		'charset', 				// string
25
-		'event_owner', 			// int account_id or -1 for leave untuched
26
-		'owner_joins_event',	// bool
27
-		'update_cats', 			// string {override|add} overides record
23
+		'fieldsep', // char
24
+		'charset', // string
25
+		'event_owner', // int account_id or -1 for leave untuched
26
+		'owner_joins_event', // bool
27
+		'update_cats', // string {override|add} overides record
28 28
 								// with cat(s) from csv OR add the cat from
29 29
 								// csv file to exeisting cat(s) of record
30
-		'num_header_lines',		// int number of header lines
31
-		'trash_users_records',	// trashes all events of events owner before import
32
-		'field_conversion', 	// array( $csv_col_num => conversion)
33
-		'field_mapping',		// array( $csv_col_num => adb_filed)
34
-		'conditions',			/* => array containing condition arrays:
30
+		'num_header_lines', // int number of header lines
31
+		'trash_users_records', // trashes all events of events owner before import
32
+		'field_conversion', // array( $csv_col_num => conversion)
33
+		'field_mapping', // array( $csv_col_num => adb_filed)
34
+		'conditions', /* => array containing condition arrays:
35 35
 				'type' => exists, // record['uid'] exists
36 36
 				'true' => array(
37 37
 					'action' => update,
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 	/**
48 48
 	 * actions wich could be done to data entries
49 49
 	 */
50
-	private static $actions = array( 'none', 'update', 'insert', 'delete', );
50
+	private static $actions = array('none', 'update', 'insert', 'delete',);
51 51
 
52 52
 	/**
53 53
 	 * conditions for actions
54 54
 	 *
55 55
 	 * @var array
56 56
 	 */
57
-	private static $conditions = array( 'exists', 'empty', );
57
+	private static $conditions = array('exists', 'empty',);
58 58
 
59 59
 	/**
60 60
 	 * @var definition
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 	 * @param string $_charset
98 98
 	 * @param definition $_definition
99 99
 	 */
100
-	public function import( $_stream, definition $_definition ) {
101
-		$import_csv = new import_csv( $_stream, array(
100
+	public function import($_stream, definition $_definition) {
101
+		$import_csv = new import_csv($_stream, array(
102 102
 			'fieldsep' => $_definition->plugin_options['fieldsep'],
103 103
 			'charset' => $_definition->plugin_options['charset'],
104 104
 		));
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 		$this->definition = $_definition;
107 107
 
108 108
 		// user, is admin ?
109
-		$this->is_admin = isset( $GLOBALS['egw_info']['user']['apps']['admin'] ) && $GLOBALS['egw_info']['user']['apps']['admin'];
109
+		$this->is_admin = isset($GLOBALS['egw_info']['user']['apps']['admin']) && $GLOBALS['egw_info']['user']['apps']['admin'];
110 110
 		$this->user = $GLOBALS['egw_info']['user']['account_id'];
111 111
 
112 112
 		// dry run?
113
-		$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] :  false;
113
+		$this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false;
114 114
 
115 115
 		// fetch the calendar bo
116 116
 		$this->bocalupdate = new calendar_boupdate();
@@ -122,24 +122,24 @@  discard block
 block discarded – undo
122 122
 		$import_csv->conversion = $_definition->plugin_options['field_conversion'];
123 123
 
124 124
 		//check if file has a header lines
125
-		if ( isset( $_definition->plugin_options['num_header_lines'] ) ) {
126
-			$import_csv->skip_records( $_definition->plugin_options['num_header_lines'] );
125
+		if (isset($_definition->plugin_options['num_header_lines'])) {
126
+			$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
127 127
 		}
128 128
 
129 129
 		// set eventOwner
130 130
 		$plugin_options = $_definition->plugin_options;
131
-		$plugin_options['events_owner'] = isset( $_definition->plugin_options['events_owner'] ) ?
131
+		$plugin_options['events_owner'] = isset($_definition->plugin_options['events_owner']) ?
132 132
 			$_definition->plugin_options['events_owner'] : $this->user;
133 133
 		$_definition->plugin_options = $plugin_options;
134 134
 
135 135
 		// trash_users_records ?
136
-		if ( $_definition->plugin_options['trash_users_records'] === true ) {
137
-			if ( !$_definition->plugin_options['dry_run'] ) {
136
+		if ($_definition->plugin_options['trash_users_records'] === true) {
137
+			if (!$_definition->plugin_options['dry_run']) {
138 138
 				$socal = new calendar_socal();
139
-				$this->bocalupdate->so->deleteaccount( $_definition->plugin_options['events_owner']);
140
-				unset( $socal );
139
+				$this->bocalupdate->so->deleteaccount($_definition->plugin_options['events_owner']);
140
+				unset($socal);
141 141
 			} else {
142
-				$lid = $GLOBALS['egw']->accounts->id2name( $_definition->plugin_options['events_owner'] );
142
+				$lid = $GLOBALS['egw']->accounts->id2name($_definition->plugin_options['events_owner']);
143 143
 				echo "Attension: All Events of '$lid' would be deleted!\n";
144 144
 			}
145 145
 		}
@@ -147,44 +147,44 @@  discard block
 block discarded – undo
147 147
 		$this->errors = array();
148 148
 		$this->results = array();
149 149
 
150
-		while ( $record = $import_csv->get_record() ) {
150
+		while ($record = $import_csv->get_record()) {
151 151
 
152 152
 			// don't import empty events
153
-			if( count( array_unique( $record ) ) < 2 ) continue;
153
+			if (count(array_unique($record)) < 2) continue;
154 154
 
155
-			if ( $_definition->plugin_options['events_owner'] != -1 ) {
155
+			if ($_definition->plugin_options['events_owner'] != -1) {
156 156
 				$record['owner'] = $_definition->plugin_options['events_owner'];
157
-			} else unset( $record['owner'] );
157
+			} else unset($record['owner']);
158 158
 
159
-			if ( $_definition->plugin_options['conditions'] ) {
160
-				foreach ( $_definition->plugin_options['conditions'] as $condition ) {
161
-					switch ( $condition['type'] ) {
159
+			if ($_definition->plugin_options['conditions']) {
160
+				foreach ($_definition->plugin_options['conditions'] as $condition) {
161
+					switch ($condition['type']) {
162 162
 						// exists
163 163
 						case 'exists' :
164 164
 
165
-							if ( is_array( $event = $this->bocalupdate->read( $record['uid'], null, $this->is_admin ) ) ) {
165
+							if (is_array($event = $this->bocalupdate->read($record['uid'], null, $this->is_admin))) {
166 166
 								// apply action to event matching this exists condition
167 167
 								$record['id'] = $event['id'];
168 168
 
169
-								if ( $_definition->plugin_options['update_cats'] == 'add' ) {
170
-									if ( !is_array( $event['cat_id'] ) ) $event['cat_id'] = explode( ',', $event['cat_id'] );
171
-									if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] );
172
-									$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $event['cat_id'] ) ) );
169
+								if ($_definition->plugin_options['update_cats'] == 'add') {
170
+									if (!is_array($event['cat_id'])) $event['cat_id'] = explode(',', $event['cat_id']);
171
+									if (!is_array($record['cat_id'])) $record['cat_id'] = explode(',', $record['cat_id']);
172
+									$record['cat_id'] = implode(',', array_unique(array_merge($record['cat_id'], $event['cat_id'])));
173 173
 								}
174 174
 
175 175
 								// check if entry is modiefied
176
-								$event = array_intersect_key( $event, $record );
177
-								$diff = array_diff( $event, $record );
178
-								if( !empty( $diff ) ) $record['modified'] = time();
176
+								$event = array_intersect_key($event, $record);
177
+								$diff = array_diff($event, $record);
178
+								if (!empty($diff)) $record['modified'] = time();
179 179
 
180 180
 								$action = $condition['true'];
181 181
 							} else $action = $condition['false'];
182 182
 
183
-							$this->action( $action['action'], $record );
183
+							$this->action($action['action'], $record);
184 184
 							break;
185 185
 						case 'empty' :
186
-							$action = empty( $record[$condition['string']] ) ? $condition['true'] : $condition['false'];
187
-							$this->action( $action['action'], $record );
186
+							$action = empty($record[$condition['string']]) ? $condition['true'] : $condition['false'];
187
+							$this->action($action['action'], $record);
188 188
 							break;
189 189
 
190 190
 						// not supported action
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 				}
197 197
 			} else {
198 198
 				// unconditional insert
199
-				$this->action( 'insert', $record );
199
+				$this->action('insert', $record);
200 200
 			}
201 201
 		}
202 202
 	}
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 * @param array $_data event data for the action
209 209
 	 * @return bool success or not
210 210
 	 */
211
-	private function action ( $_action, $_data ) {
212
-		switch ( $_action ) {
211
+	private function action($_action, $_data) {
212
+		switch ($_action) {
213 213
 			case 'none' :
214 214
 				return true;
215 215
 
@@ -217,32 +217,32 @@  discard block
 block discarded – undo
217 217
 			case 'insert' :
218 218
 
219 219
 				// paticipants handling
220
-				$participants = $_data['participants'] ? split( '[,;]', $_data['participants'] ) : array();
220
+				$participants = $_data['participants'] ? split('[,;]', $_data['participants']) : array();
221 221
 				$_data['participants'] = array();
222
-				if ( $this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0 ) {
222
+				if ($this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0) {
223 223
 					$_data['participants'][$this->definition->plugin_options['events_owner']] = 'A';
224 224
 				}
225
-				foreach( $participants as $participant ) {
226
-					list( $participant, $status ) = explode( '=', $participant );
227
-					$valid_staties = array('U'=>'U','u'=>'U','A'=>'A','a'=>'A','R'=>'R','r'=>'R','T'=>'T','t'=>'T');
228
-					$status = isset( $valid_staties[$status] ) ? $valid_staties[$status] : 'U';
229
-					if ( $participant && is_numeric($participant ) ) {
225
+				foreach ($participants as $participant) {
226
+					list($participant, $status) = explode('=', $participant);
227
+					$valid_staties = array('U'=>'U', 'u'=>'U', 'A'=>'A', 'a'=>'A', 'R'=>'R', 'r'=>'R', 'T'=>'T', 't'=>'T');
228
+					$status = isset($valid_staties[$status]) ? $valid_staties[$status] : 'U';
229
+					if ($participant && is_numeric($participant)) {
230 230
 						$_data['participants'][$participant] = $status;
231 231
 					}
232 232
 				}
233 233
 				// no valid participants so far --> add the importing user/owner
234
-				if ( empty( $_data['participants'] ) ) {
234
+				if (empty($_data['participants'])) {
235 235
 					$_data['participants'][$this->user] = 'A';
236 236
 				}
237 237
 
238 238
 				// are we serious?
239
-				if ( $this->dry_run ) {
239
+				if ($this->dry_run) {
240 240
 					print_r($_data);
241 241
 					$this->results[$_action]++;
242 242
 				} else {
243 243
 					$messages = array();
244
-					$result = $this->bocalupdate->update( $_data, true, !$_data['modified'], $this->is_admin, true, $messages);
245
-					if(!$result) {
244
+					$result = $this->bocalupdate->update($_data, true, !$_data['modified'], $this->is_admin, true, $messages);
245
+					if (!$result) {
246 246
 						$this->errors = implode(',', $messages);
247 247
 					} else {
248 248
 						$this->results[$_action]++;
Please login to merge, or discard this patch.
Braces   +94 added lines, -38 removed lines patch added patch discarded remove patch
@@ -17,7 +17,8 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * class import_csv for addressbook
19 19
  */
20
-class import_events_csv implements iface_import_plugin  {
20
+class import_events_csv implements iface_import_plugin
21
+{
21 22
 
22 23
 	private static $plugin_options = array(
23 24
 		'fieldsep', 			// char
@@ -97,7 +98,8 @@  discard block
 block discarded – undo
97 98
 	 * @param string $_charset
98 99
 	 * @param definition $_definition
99 100
 	 */
100
-	public function import( $_stream, definition $_definition ) {
101
+	public function import( $_stream, definition $_definition )
102
+	{
101 103
 		$import_csv = new import_csv( $_stream, array(
102 104
 			'fieldsep' => $_definition->plugin_options['fieldsep'],
103 105
 			'charset' => $_definition->plugin_options['charset'],
@@ -122,7 +124,8 @@  discard block
 block discarded – undo
122 124
 		$import_csv->conversion = $_definition->plugin_options['field_conversion'];
123 125
 
124 126
 		//check if file has a header lines
125
-		if ( isset( $_definition->plugin_options['num_header_lines'] ) ) {
127
+		if ( isset( $_definition->plugin_options['num_header_lines'] ) )
128
+		{
126 129
 			$import_csv->skip_records( $_definition->plugin_options['num_header_lines'] );
127 130
 		}
128 131
 
@@ -133,12 +136,16 @@  discard block
 block discarded – undo
133 136
 		$_definition->plugin_options = $plugin_options;
134 137
 
135 138
 		// trash_users_records ?
136
-		if ( $_definition->plugin_options['trash_users_records'] === true ) {
137
-			if ( !$_definition->plugin_options['dry_run'] ) {
139
+		if ( $_definition->plugin_options['trash_users_records'] === true )
140
+		{
141
+			if ( !$_definition->plugin_options['dry_run'] )
142
+			{
138 143
 				$socal = new calendar_socal();
139 144
 				$this->bocalupdate->so->deleteaccount( $_definition->plugin_options['events_owner']);
140 145
 				unset( $socal );
141
-			} else {
146
+			}
147
+			else
148
+			{
142 149
 				$lid = $GLOBALS['egw']->accounts->id2name( $_definition->plugin_options['events_owner'] );
143 150
 				echo "Attension: All Events of '$lid' would be deleted!\n";
144 151
 			}
@@ -147,38 +154,63 @@  discard block
 block discarded – undo
147 154
 		$this->errors = array();
148 155
 		$this->results = array();
149 156
 
150
-		while ( $record = $import_csv->get_record() ) {
157
+		while ( $record = $import_csv->get_record() )
158
+		{
151 159
 
152 160
 			// don't import empty events
153
-			if( count( array_unique( $record ) ) < 2 ) continue;
161
+			if( count( array_unique( $record ) ) < 2 )
162
+			{
163
+				continue;
164
+			}
154 165
 
155
-			if ( $_definition->plugin_options['events_owner'] != -1 ) {
166
+			if ( $_definition->plugin_options['events_owner'] != -1 )
167
+			{
156 168
 				$record['owner'] = $_definition->plugin_options['events_owner'];
157
-			} else unset( $record['owner'] );
169
+			}
170
+			else {
171
+				unset( $record['owner'] );
172
+			}
158 173
 
159
-			if ( $_definition->plugin_options['conditions'] ) {
160
-				foreach ( $_definition->plugin_options['conditions'] as $condition ) {
161
-					switch ( $condition['type'] ) {
174
+			if ( $_definition->plugin_options['conditions'] )
175
+			{
176
+				foreach ( $_definition->plugin_options['conditions'] as $condition )
177
+				{
178
+					switch ( $condition['type'] )
179
+					{
162 180
 						// exists
163 181
 						case 'exists' :
164 182
 
165
-							if ( is_array( $event = $this->bocalupdate->read( $record['uid'], null, $this->is_admin ) ) ) {
183
+							if ( is_array( $event = $this->bocalupdate->read( $record['uid'], null, $this->is_admin ) ) )
184
+							{
166 185
 								// apply action to event matching this exists condition
167 186
 								$record['id'] = $event['id'];
168 187
 
169
-								if ( $_definition->plugin_options['update_cats'] == 'add' ) {
170
-									if ( !is_array( $event['cat_id'] ) ) $event['cat_id'] = explode( ',', $event['cat_id'] );
171
-									if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] );
188
+								if ( $_definition->plugin_options['update_cats'] == 'add' )
189
+								{
190
+									if ( !is_array( $event['cat_id'] ) )
191
+									{
192
+										$event['cat_id'] = explode( ',', $event['cat_id'] );
193
+									}
194
+									if ( !is_array( $record['cat_id'] ) )
195
+									{
196
+										$record['cat_id'] = explode( ',', $record['cat_id'] );
197
+									}
172 198
 									$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $event['cat_id'] ) ) );
173 199
 								}
174 200
 
175 201
 								// check if entry is modiefied
176 202
 								$event = array_intersect_key( $event, $record );
177 203
 								$diff = array_diff( $event, $record );
178
-								if( !empty( $diff ) ) $record['modified'] = time();
204
+								if( !empty( $diff ) )
205
+								{
206
+									$record['modified'] = time();
207
+								}
179 208
 
180 209
 								$action = $condition['true'];
181
-							} else $action = $condition['false'];
210
+							}
211
+							else {
212
+								$action = $condition['false'];
213
+							}
182 214
 
183 215
 							$this->action( $action['action'], $record );
184 216
 							break;
@@ -192,9 +224,14 @@  discard block
 block discarded – undo
192 224
 							throw new Exception('condition not supported!!!');
193 225
 							break;
194 226
 					}
195
-					if ($action['last']) break;
227
+					if ($action['last'])
228
+					{
229
+						break;
230
+					}
196 231
 				}
197
-			} else {
232
+			}
233
+			else
234
+			{
198 235
 				// unconditional insert
199 236
 				$this->action( 'insert', $record );
200 237
 			}
@@ -208,8 +245,10 @@  discard block
 block discarded – undo
208 245
 	 * @param array $_data event data for the action
209 246
 	 * @return bool success or not
210 247
 	 */
211
-	private function action ( $_action, $_data ) {
212
-		switch ( $_action ) {
248
+	private function action ( $_action, $_data )
249
+	{
250
+		switch ( $_action )
251
+		{
213 252
 			case 'none' :
214 253
 				return true;
215 254
 
@@ -219,32 +258,42 @@  discard block
 block discarded – undo
219 258
 				// paticipants handling
220 259
 				$participants = $_data['participants'] ? split( '[,;]', $_data['participants'] ) : array();
221 260
 				$_data['participants'] = array();
222
-				if ( $this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0 ) {
261
+				if ( $this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0 )
262
+				{
223 263
 					$_data['participants'][$this->definition->plugin_options['events_owner']] = 'A';
224 264
 				}
225
-				foreach( $participants as $participant ) {
265
+				foreach( $participants as $participant )
266
+				{
226 267
 					list( $participant, $status ) = explode( '=', $participant );
227 268
 					$valid_staties = array('U'=>'U','u'=>'U','A'=>'A','a'=>'A','R'=>'R','r'=>'R','T'=>'T','t'=>'T');
228 269
 					$status = isset( $valid_staties[$status] ) ? $valid_staties[$status] : 'U';
229
-					if ( $participant && is_numeric($participant ) ) {
270
+					if ( $participant && is_numeric($participant ) )
271
+					{
230 272
 						$_data['participants'][$participant] = $status;
231 273
 					}
232 274
 				}
233 275
 				// no valid participants so far --> add the importing user/owner
234
-				if ( empty( $_data['participants'] ) ) {
276
+				if ( empty( $_data['participants'] ) )
277
+				{
235 278
 					$_data['participants'][$this->user] = 'A';
236 279
 				}
237 280
 
238 281
 				// are we serious?
239
-				if ( $this->dry_run ) {
282
+				if ( $this->dry_run )
283
+				{
240 284
 					print_r($_data);
241 285
 					$this->results[$_action]++;
242
-				} else {
286
+				}
287
+				else
288
+				{
243 289
 					$messages = array();
244 290
 					$result = $this->bocalupdate->update( $_data, true, !$_data['modified'], $this->is_admin, true, $messages);
245
-					if(!$result) {
291
+					if(!$result)
292
+					{
246 293
 						$this->errors = implode(',', $messages);
247
-					} else {
294
+					}
295
+					else
296
+					{
248 297
 						$this->results[$_action]++;
249 298
 					}
250 299
 					return $result;
@@ -259,7 +308,8 @@  discard block
 block discarded – undo
259 308
 	 *
260 309
 	 * @return string name
261 310
 	 */
262
-	public static function get_name() {
311
+	public static function get_name()
312
+	{
263 313
 		return lang('Calendar CSV export');
264 314
 	}
265 315
 
@@ -268,7 +318,8 @@  discard block
 block discarded – undo
268 318
 	 *
269 319
 	 * @return string descriprion
270 320
 	 */
271
-	public static function get_description() {
321
+	public static function get_description()
322
+	{
272 323
 		return lang("Imports events into your Calendar from a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators.");
273 324
 	}
274 325
 
@@ -277,7 +328,8 @@  discard block
 block discarded – undo
277 328
 	 *
278 329
 	 * @return string suffix (comma seperated)
279 330
 	 */
280
-	public static function get_filesuffix() {
331
+	public static function get_filesuffix()
332
+	{
281 333
 		return 'csv';
282 334
 	}
283 335
 
@@ -293,7 +345,8 @@  discard block
 block discarded – undo
293 345
 	 * 		preserv		=> array,
294 346
 	 * )
295 347
 	 */
296
-	public function get_options_etpl() {
348
+	public function get_options_etpl()
349
+	{
297 350
 		// lets do it!
298 351
 	}
299 352
 
@@ -302,7 +355,8 @@  discard block
 block discarded – undo
302 355
 	 *
303 356
 	 * @return string etemplate name
304 357
 	 */
305
-	public function get_selectors_etpl() {
358
+	public function get_selectors_etpl()
359
+	{
306 360
 		// lets do it!
307 361
 	}
308 362
 
@@ -314,7 +368,8 @@  discard block
 block discarded – undo
314 368
         *       record_# => error message
315 369
         *       )
316 370
         */
317
-        public function get_errors() {
371
+        public function get_errors()
372
+        {
318 373
 		return $this->errors;
319 374
 	}
320 375
 
@@ -326,7 +381,8 @@  discard block
 block discarded – undo
326 381
         *       action => record count
327 382
         * )
328 383
         */
329
-        public function get_results() {
384
+        public function get_results()
385
+        {
330 386
 		return $this->results;
331 387
 	}
332 388
 } // end of iface_export_plugin
Please login to merge, or discard this patch.
calendar/inc/class.calendar_boupdate.inc.php 5 patches
Doc Comments   +11 added lines, -6 removed lines patch added patch discarded remove patch
@@ -519,6 +519,7 @@  discard block
 block discarded – undo
519 519
 	 * @param array $new_event Event after the change
520 520
 	 * @param string $role we treat CHAIR like event owners
521 521
 	 * @param string $status of current user
522
+	 * @param integer $msg_type
522 523
 	 * @return boolean true = update requested, false otherwise
523 524
 	 */
524 525
 	public static function update_requested($userid, $part_prefs, &$msg_type, $old_event ,$new_event, $role, $status=null)
@@ -594,7 +595,7 @@  discard block
 block discarded – undo
594 595
 	/**
595 596
 	 * Check calendar prefs, if a given user (integer account_id) or email (user or externals) should get notified
596 597
 	 *
597
-	 * @param int|string $user_or_email
598
+	 * @param string $user_or_email
598 599
 	 * @param string $ical_method ='REQUEST'
599 600
 	 * @param string $role ='REQ-PARTICIPANT'
600 601
 	 * @return boolean true if user requested to be notified, false if not
@@ -645,8 +646,7 @@  discard block
 block discarded – undo
645 646
 	 * Get iCal/iMip method from internal nummeric msg-type plus optional notification message and verbose name
646 647
 	 *
647 648
 	 * @param int $msg_type see MSG_* defines
648
-	 * @param string& $action=null on return verbose name
649
-	 * @param string& $msg=null on return notification message
649
+	 * @param string& $action on return verbose name
650 650
 	 */
651 651
 	function msg_type2ical_method($msg_type, &$action=null, &$msg=null)
652 652
 	{
@@ -1011,6 +1011,9 @@  discard block
 block discarded – undo
1011 1011
 		return true;
1012 1012
 	}
1013 1013
 
1014
+	/**
1015
+	 * @param integer $added
1016
+	 */
1014 1017
 	function get_update_message($event,$added)
1015 1018
 	{
1016 1019
 		$nul = null;
@@ -1300,8 +1303,8 @@  discard block
 block discarded – undo
1300 1303
 	 *
1301 1304
 	 * @param int $right self::CAT_ACL_{ADD|STATUS}
1302 1305
 	 * @param int|array $event
1303
-	 * @return boolean true if use has the right, false if not
1304
-	 * @return boolean false=access denied because of cat acl, true access granted because of cat acl,
1306
+	 * @return null|boolean true if use has the right, false if not
1307
+	 * @return null|boolean false=access denied because of cat acl, true access granted because of cat acl,
1305 1308
 	 * 	null = cat has no acl
1306 1309
 	 */
1307 1310
 	function check_cat_acl($right,$event)
@@ -1386,6 +1389,8 @@  discard block
 block discarded – undo
1386 1389
 	 * Check if current user has a given right on a category (if it's restricted!)
1387 1390
 	 *
1388 1391
 	 * @param int $cat_id
1392
+	 * @param integer $right
1393
+	 * @param integer $user
1389 1394
 	 * @return boolean false=access denied because of cat acl, true access granted because of cat acl,
1390 1395
 	 * 	null = cat has no acl
1391 1396
 	 */
@@ -1647,7 +1652,7 @@  discard block
 block discarded – undo
1647 1652
 	 * @param string $action
1648 1653
 	 * @param array $event_arr
1649 1654
 	 * @param array $disinvited
1650
-	 * @return array
1655
+	 * @return string
1651 1656
 	 */
1652 1657
 	function _get_event_details($event,$action,&$event_arr,$disinvited=array())
1653 1658
 	{
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1504,22 +1504,22 @@  discard block
 block discarded – undo
1504 1504
 		// check the old list against the new list
1505 1505
 		foreach ($old_event['participants'] as $userid => $status)
1506 1506
   		{
1507
-            if (!isset($new_event['participants'][$userid])){
1508
-            	// Attendee will be deleted this way
1509
-            	$new_event['participants'][$userid] = 'G';
1510
-            }
1511
-            elseif ($new_event['participants'][$userid] == $status)
1512
-            {
1513
-            	// Same status -- nothing to do.
1514
-            	unset($new_event['participants'][$userid]);
1515
-            }
1507
+			if (!isset($new_event['participants'][$userid])){
1508
+				// Attendee will be deleted this way
1509
+				$new_event['participants'][$userid] = 'G';
1510
+			}
1511
+			elseif ($new_event['participants'][$userid] == $status)
1512
+			{
1513
+				// Same status -- nothing to do.
1514
+				unset($new_event['participants'][$userid]);
1515
+			}
1516 1516
 		}
1517 1517
 		// write the changes
1518 1518
 		foreach ($new_event['participants'] as $userid => $status)
1519 1519
 		{
1520 1520
 			$this->set_status($old_event, $userid, $status, $recur_date, true, false,$skip_notification);
1521 1521
 		}
1522
-    }
1522
+	}
1523 1523
 
1524 1524
 	/**
1525 1525
 	 * deletes an event
@@ -2493,24 +2493,24 @@  discard block
 block discarded – undo
2493 2493
 	/**
2494 2494
 	 * classifies an incoming event from the eGW point-of-view
2495 2495
 	 *
2496
-     * exceptions: unlike other calendar apps eGW does not create an event exception
2497
-     * if just the participant state changes - therefore we have to distinguish between
2498
-     * real exceptions and status only exceptions
2499
-     *
2500
-     * @param array $event the event to check
2501
-     *
2502
-     * @return array
2503
-     * 	type =>
2504
-     * 		SINGLE a single event
2505
-     * 		SERIES-MASTER the series master
2506
-     * 		SERIES-EXCEPTION event is a real exception
2507
-	  * 		SERIES-PSEUDO-EXCEPTION event is a status only exception
2508
-	  * 		SERIES-EXCEPTION-PROPAGATE event was a status only exception in the past and is now a real exception
2509
-	  * 	stored_event => if event already exists in the database array with event data or false
2510
-	  * 	master_event => for event type SERIES-EXCEPTION, SERIES-PSEUDO-EXCEPTION or SERIES-EXCEPTION-PROPAGATE
2511
-	  * 		the corresponding series master event array
2512
-	  * 		NOTE: this param is false if event is of type SERIES-MASTER
2513
-     */
2496
+	 * exceptions: unlike other calendar apps eGW does not create an event exception
2497
+	 * if just the participant state changes - therefore we have to distinguish between
2498
+	 * real exceptions and status only exceptions
2499
+	 *
2500
+	 * @param array $event the event to check
2501
+	 *
2502
+	 * @return array
2503
+	 * 	type =>
2504
+	 * 		SINGLE a single event
2505
+	 * 		SERIES-MASTER the series master
2506
+	 * 		SERIES-EXCEPTION event is a real exception
2507
+	 * 		SERIES-PSEUDO-EXCEPTION event is a status only exception
2508
+	 * 		SERIES-EXCEPTION-PROPAGATE event was a status only exception in the past and is now a real exception
2509
+	 * 	stored_event => if event already exists in the database array with event data or false
2510
+	 * 	master_event => for event type SERIES-EXCEPTION, SERIES-PSEUDO-EXCEPTION or SERIES-EXCEPTION-PROPAGATE
2511
+	 * 		the corresponding series master event array
2512
+	 * 		NOTE: this param is false if event is of type SERIES-MASTER
2513
+	 */
2514 2514
 	function get_event_info($event)
2515 2515
 	{
2516 2516
 		$type = 'SINGLE'; // default
@@ -2681,16 +2681,16 @@  discard block
 block discarded – undo
2681 2681
 			'stored_event' => $stored_event,
2682 2682
 			'master_event' => $master_event,
2683 2683
 		);
2684
-    }
2685
-
2686
-    /**
2687
-     * Translates all timestamps for a given event from server-time to user-time.
2688
-     * The update() and save() methods expect timestamps in user-time.
2689
-     * @param &$event	the event we are working on
2690
-     *
2691
-     */
2692
-    function server2usertime (&$event)
2693
-    {
2684
+	}
2685
+
2686
+	/**
2687
+	 * Translates all timestamps for a given event from server-time to user-time.
2688
+	 * The update() and save() methods expect timestamps in user-time.
2689
+	 * @param &$event	the event we are working on
2690
+	 *
2691
+	 */
2692
+	function server2usertime (&$event)
2693
+	{
2694 2694
 		// we run all dates through date2usertime, to adjust to user-time
2695 2695
 		foreach(array('start','end','recur_enddate','recurrence') as $ts)
2696 2696
 		{
@@ -2713,7 +2713,7 @@  discard block
 block discarded – undo
2713 2713
 				$event['alarm'][$id]['time'] = $this->date2usertime($alarm['time']);
2714 2714
 			}
2715 2715
 		}
2716
-    }
2716
+	}
2717 2717
 	/**
2718 2718
 	 * Delete events that are more than $age years old
2719 2719
 	 *
Please login to merge, or discard this patch.
Upper-Lower-Casing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1708,12 +1708,12 @@  discard block
 block discarded – undo
1708 1708
 	 */
1709 1709
 	function event2array($event)
1710 1710
 	{
1711
-		$var['title'] = Array(
1711
+		$var['title'] = array(
1712 1712
 			'field'		=> lang('Title'),
1713 1713
 			'data'		=> $event['title']
1714 1714
 		);
1715 1715
 
1716
-		$var['description'] = Array(
1716
+		$var['description'] = array(
1717 1717
 			'field'	=> lang('Description'),
1718 1718
 			'data'	=> $event['description']
1719 1719
 		);
@@ -1722,48 +1722,48 @@  discard block
 block discarded – undo
1722 1722
 		{
1723 1723
 			$cat_string[] = stripslashes(Api\Categories::id2name($cat_id));
1724 1724
 		}
1725
-		$var['category'] = Array(
1725
+		$var['category'] = array(
1726 1726
 			'field'	=> lang('Category'),
1727 1727
 			'data'	=> implode(', ',$cat_string)
1728 1728
 		);
1729 1729
 
1730
-		$var['location'] = Array(
1730
+		$var['location'] = array(
1731 1731
 			'field'	=> lang('Location'),
1732 1732
 			'data'	=> $event['location']
1733 1733
 		);
1734 1734
 
1735
-		$var['startdate'] = Array(
1735
+		$var['startdate'] = array(
1736 1736
 			'field'	=> lang('Start Date/Time'),
1737 1737
 			'data'	=> $this->format_date($event['start']),
1738 1738
 		);
1739 1739
 
1740
-		$var['enddate'] = Array(
1740
+		$var['enddate'] = array(
1741 1741
 			'field'	=> lang('End Date/Time'),
1742 1742
 			'data'	=> $this->format_date($event['end']),
1743 1743
 		);
1744 1744
 
1745
-		$pri = Array(
1745
+		$pri = array(
1746 1746
 			0   => lang('None'),
1747 1747
 			1	=> lang('Low'),
1748 1748
 			2	=> lang('Normal'),
1749 1749
 			3	=> lang('High')
1750 1750
 		);
1751
-		$var['priority'] = Array(
1751
+		$var['priority'] = array(
1752 1752
 			'field'	=> lang('Priority'),
1753 1753
 			'data'	=> $pri[$event['priority']]
1754 1754
 		);
1755 1755
 
1756
-		$var['owner'] = Array(
1756
+		$var['owner'] = array(
1757 1757
 			'field'	=> lang('Owner'),
1758 1758
 			'data'	=> Api\Accounts::username($event['owner'])
1759 1759
 		);
1760 1760
 
1761
-		$var['updated'] = Array(
1761
+		$var['updated'] = array(
1762 1762
 			'field'	=> lang('Updated'),
1763 1763
 			'data'	=> $this->format_date($event['modtime']).', '.Api\Accounts::username($event['modifier'])
1764 1764
 		);
1765 1765
 
1766
-		$var['access'] = Array(
1766
+		$var['access'] = array(
1767 1767
 			'field'	=> lang('Access'),
1768 1768
 			'data'	=> $event['public'] ? lang('Public') : lang('Private')
1769 1769
 		);
@@ -1772,13 +1772,13 @@  discard block
 block discarded – undo
1772 1772
 		{
1773 1773
 			$participants = $this->participants($event,true);
1774 1774
 		}
1775
-		$var['participants'] = Array(
1775
+		$var['participants'] = array(
1776 1776
 			'field'	=> lang('Participants'),
1777 1777
 			'data'	=> $participants
1778 1778
 		);
1779 1779
 
1780 1780
 		// Repeated Events
1781
-		$var['recur_type'] = Array(
1781
+		$var['recur_type'] = array(
1782 1782
 			'field'	=> lang('Repetition'),
1783 1783
 			'data'	=> ($event['recur_type'] != MCAL_RECUR_NONE) ? $this->recure2string($event) : '',
1784 1784
 		);
@@ -1828,7 +1828,7 @@  discard block
 block discarded – undo
1828 1828
 	 * @param Api\DateTime $instance_date For recurring events, this is the date we
1829 1829
 	 *	are dealing with
1830 1830
 	 */
1831
-	function check_move_alarms(Array &$event, Array $old_event = null, Api\DateTime $instance_date = null)
1831
+	function check_move_alarms(array &$event, array $old_event = null, Api\DateTime $instance_date = null)
1832 1832
 	{
1833 1833
 		if ($old_event !== null && $event['start'] == $old_event['start']) return;
1834 1834
 
Please login to merge, or discard this patch.
Braces   +216 added lines, -55 removed lines patch added patch discarded remove patch
@@ -85,11 +85,17 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	function __construct()
87 87
 	{
88
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started',True);
88
+		if ($this->debug > 0)
89
+		{
90
+			$this->debug_message('calendar_boupdate::__construct() started',True);
91
+		}
89 92
 
90 93
 		parent::__construct();	// calling the parent constructor
91 94
 
92
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished',True);
95
+		if ($this->debug > 0)
96
+		{
97
+			$this->debug_message('calendar_boupdate::__construct() finished',True);
98
+		}
93 99
 	}
94 100
 
95 101
 	/**
@@ -120,7 +126,10 @@  discard block
 block discarded – undo
120 126
 	{
121 127
 		unset($updateTS);	// ignored, as updating timestamps is required for sync!
122 128
 		//error_log(__METHOD__."(".array2string($event).",$ignore_conflicts,$touch_modified,$ignore_acl)");
123
-		if (!is_array($messages)) $messages = $messages ? (array)$messages : array();
129
+		if (!is_array($messages))
130
+		{
131
+			$messages = $messages ? (array)$messages : array();
132
+		}
124 133
 
125 134
 		if ($this->debug > 1 || $this->debug == 'update')
126 135
 		{
@@ -140,10 +149,13 @@  discard block
 block discarded – undo
140 149
 
141 150
 		$status_reset_to_unknown = false;
142 151
 
143
-		if (($new_event = !$event['id']))	// some defaults for new entries
152
+		if (($new_event = !$event['id']))
153
+		{
154
+			// some defaults for new entries
144 155
 		{
145 156
 			// if no owner given, set user to owner
146 157
 			if (!$event['owner']) $event['owner'] = $this->user;
158
+		}
147 159
 			// set owner as participant if none is given
148 160
 			if (!is_array($event['participants']) || !count($event['participants']))
149 161
 			{
@@ -183,7 +195,10 @@  discard block
 block discarded – undo
183 195
 		// check category based ACL
184 196
 		if ($event['category'])
185 197
 		{
186
-			if (!is_array($event['category'])) $event['category'] = explode(',',$event['category']);
198
+			if (!is_array($event['category']))
199
+			{
200
+				$event['category'] = explode(',',$event['category']);
201
+			}
187 202
 			if (!$old_event || !isset($old_event['category']))
188 203
 			{
189 204
 				$old_event['category'] = array();
@@ -235,13 +250,16 @@  discard block
 block discarded – undo
235 250
 		if (!$ignore_conflicts && !$event['non_blocking'] && isset($event['start']) && isset($event['end']) &&
236 251
 			(($conflicts = $this->conflicts($event, $checked_excluding)) || $checked_excluding))
237 252
 		{
238
-			if ($checked_excluding)	// warn user if not all recurrences have been checked
253
+			if ($checked_excluding)
254
+			{
255
+				// warn user if not all recurrences have been checked
239 256
 			{
240 257
 				$conflicts['warning'] = array(
241 258
 					'start' => $checked_excluding,
242 259
 					'title' => lang('Only recurrences until %1 (excluding) have been checked!', $checked_excluding->format(true)),
243 260
 				);
244 261
 			}
262
+			}
245 263
 			return $conflicts;
246 264
 		}
247 265
 
@@ -305,7 +323,10 @@  discard block
 block discarded – undo
305 323
 		$types_with_quantity = array();
306 324
 		foreach($this->resources as $type => $data)
307 325
 		{
308
-			if ($data['max_quantity']) $types_with_quantity[] = $type;
326
+			if ($data['max_quantity'])
327
+			{
328
+				$types_with_quantity[] = $type;
329
+			}
309 330
 		}
310 331
 		// get all NOT rejected participants and evtl. their quantity
311 332
 		$quantity = $users = array();
@@ -313,12 +334,19 @@  discard block
 block discarded – undo
313 334
 		{
314 335
 			$q = $role = null;
315 336
 			calendar_so::split_status($status, $q, $role);
316
-			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue;	// ignore rejected or non-participants
337
+			if ($status == 'R' || $role == 'NON-PARTICIPANT')
338
+			{
339
+				continue;
340
+			}
341
+			// ignore rejected or non-participants
317 342
 
318
-			if ($uid < 0)	// group, check it's members too
343
+			if ($uid < 0)
344
+			{
345
+				// group, check it's members too
319 346
 			{
320 347
 				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid,true)));
321 348
 			}
349
+			}
322 350
 			$users[] = $uid;
323 351
 			if (in_array($uid[0],$types_with_quantity))
324 352
 			{
@@ -349,18 +377,24 @@  discard block
 block discarded – undo
349 377
 			$startts = $date->format('ts');
350 378
 
351 379
 			// skip past events or recurrences
352
-			if ($startts+$duration < $this->now_su) continue;
380
+			if ($startts+$duration < $this->now_su)
381
+			{
382
+				continue;
383
+			}
353 384
 
354 385
 			// abort check if configured limits are exceeded
355 386
 			if ($event['recur_type'] &&
356 387
 				(++$checked > $max_checked && $max_checked > 0 || // maximum number of checked recurrences exceeded
357 388
 				microtime(true) > $start+$max_check_time ||	// max check time exceeded
358
-				$startts > $this->config['horizont']))	// we are behind horizon for which recurrences are rendered
389
+				$startts > $this->config['horizont']))
390
+			{
391
+				// we are behind horizon for which recurrences are rendered
359 392
 			{
360 393
 				if ($this->debug > 2 || $this->debug == 'conflicts')
361 394
 				{
362 395
 					$this->debug_message(__METHOD__.'() conflict check limited to %1 recurrences, %2 seconds, until (excluding) %3',
363 396
 						$checked, microtime(true)-$start, $date);
397
+			}
364 398
 				}
365 399
 				$checked_excluding = $date;
366 400
 				break;
@@ -384,10 +418,13 @@  discard block
 block discarded – undo
384 418
 			{
385 419
 				if ($overlap['id'] == $event['id'] ||	// that's the event itself
386 420
 					$overlap['id'] == $event['reference'] ||	// event is an exception of overlap
387
-					$overlap['non_blocking'])			// that's a non_blocking event
421
+					$overlap['non_blocking'])
422
+				{
423
+					// that's a non_blocking event
388 424
 				{
389 425
 					continue;
390 426
 				}
427
+				}
391 428
 				if ($this->debug > 3 || $this->debug == 'conflicts')
392 429
 				{
393 430
 					$this->debug_message(__METHOD__.'() checking overlapping event %1',false,$overlap);
@@ -507,7 +544,11 @@  discard block
 block discarded – undo
507 544
 	 */
508 545
 	public function check_acl_invite($uid)
509 546
 	{
510
-		if (!is_numeric($uid)) return true;	// nothing implemented for resources so far
547
+		if (!is_numeric($uid))
548
+		{
549
+			return true;
550
+		}
551
+		// nothing implemented for resources so far
511 552
 
512 553
 		if (!$this->require_acl_invite)
513 554
 		{
@@ -847,14 +888,20 @@  discard block
 block discarded – undo
847 888
 		$startdate = new Api\DateTime($event['start']);
848 889
 		$enddate = new Api\DateTime($event['end']);
849 890
 		$modified = new Api\DateTime($event['modified']);
850
-		if ($old_event) $olddate = new Api\DateTime($old_event['start']);
891
+		if ($old_event)
892
+		{
893
+			$olddate = new Api\DateTime($old_event['start']);
894
+		}
851 895
 		//error_log(__METHOD__."() date_default_timezone_get()=".date_default_timezone_get().", user-timezone=".Api\DateTime::$user_timezone->getName().", startdate=".$startdate->format().", enddate=".$enddate->format().", updated=".$modified->format().", olddate=".($olddate ? $olddate->format() : ''));
852 896
 		$owner_prefs = $ics = null;
853 897
 		foreach($to_notify as $userid => $statusid)
854 898
 		{
855 899
 			$res_info = $quantity = $role = null;
856 900
 			calendar_so::split_status($statusid, $quantity, $role);
857
-			if ($this->debug > 0) error_log(__METHOD__." trying to notify $userid, with $statusid ($role)");
901
+			if ($this->debug > 0)
902
+			{
903
+				error_log(__METHOD__." trying to notify $userid, with $statusid ($role)");
904
+			}
858 905
 
859 906
 			if (!is_numeric($userid))
860 907
 			{
@@ -873,7 +920,11 @@  discard block
 block discarded – undo
873 920
 
874 921
 				if (!isset($userid))
875 922
 				{
876
-					if (empty($res_info['email'])) continue;	// no way to notify
923
+					if (empty($res_info['email']))
924
+					{
925
+						continue;
926
+					}
927
+					// no way to notify
877 928
 					// check if event-owner wants non-EGroupware users notified
878 929
 					if (is_null($owner_prefs))
879 930
 					{
@@ -947,7 +998,10 @@  discard block
 block discarded – undo
947 998
 				$details['to-lastname'] = isset($tln)? $tln: '';
948 999
 
949 1000
 				// event is in user-time of current user, now we need to calculate the tz-difference to the notified user and take it into account
950
-				if (!isset($part_prefs['common']['tz'])) $part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
1001
+				if (!isset($part_prefs['common']['tz']))
1002
+				{
1003
+					$part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
1004
+				}
951 1005
 				$timezone = new DateTimeZone($part_prefs['common']['tz']);
952 1006
 				$timeformat = $part_prefs['common']['timeformat'];
953 1007
 				switch($timeformat)
@@ -982,9 +1036,12 @@  discard block
 block discarded – undo
982 1036
 				switch($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
983 1037
 				{
984 1038
 					case 'ical':
985
-						if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
1039
+						if (is_null($ics) || $m_type != $msg_type)
1040
+						{
1041
+							// need different ical for organizer notification
986 1042
 						{
987 1043
 							$calendar_ical = new calendar_ical();
1044
+						}
988 1045
 							$calendar_ical->setSupportedFields('full');	// full iCal fields+event TZ
989 1046
 							// we need to pass $event[id] so iCal class reads event again,
990 1047
 							// as event is in user TZ, but iCal class expects server TZ!
@@ -998,7 +1055,10 @@  discard block
 block discarded – undo
998 1055
 							'encoding' => '8bit',
999 1056
 							'type' => 'text/calendar; method='.$method,
1000 1057
 						);
1001
-						if ($m_type != $msg_type) unset($ics);
1058
+						if ($m_type != $msg_type)
1059
+						{
1060
+							unset($ics);
1061
+						}
1002 1062
 						$subject = isset($cleared_event) ? $cleared_event['title'] : $event['title'];
1003 1063
 						// fall through
1004 1064
 					case 'extended':
@@ -1049,7 +1109,9 @@  discard block
 block discarded – undo
1049 1109
 						$notification->set_popupmessage($notify_body."\n\n".$details['description']."\n\n".$details_body);
1050 1110
 						$notification->set_popuplinks(array($details['link_arr']));
1051 1111
 
1052
-						if(is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1112
+						if(is_array($attachment))
1113
+						{
1114
+$notification->set_attachments(array($attachment)); }
1053 1115
 						$notification->send();
1054 1116
 						foreach(notifications::errors(true) as $error)
1055 1117
 						{
@@ -1085,7 +1147,10 @@  discard block
 block discarded – undo
1085 1147
 			Api\Translation::init();
1086 1148
 		}
1087 1149
 		// restore timezone, in case we had to reset it to server-timezone
1088
-		if ($restore_tz) date_default_timezone_set($restore_tz);
1150
+		if ($restore_tz)
1151
+		{
1152
+			date_default_timezone_set($restore_tz);
1153
+		}
1089 1154
 
1090 1155
 		return true;
1091 1156
 	}
@@ -1120,10 +1185,13 @@  discard block
 block discarded – undo
1120 1185
 		{
1121 1186
 			$to_notify = $event['participants'];
1122 1187
 		}
1123
-		elseif ($this->check_perms(Acl::READ,$event))	// checks agains $this->owner set to $alarm[owner]
1188
+		elseif ($this->check_perms(Acl::READ,$event))
1189
+		{
1190
+			// checks agains $this->owner set to $alarm[owner]
1124 1191
 		{
1125 1192
 			$to_notify[$alarm['owner']] = 'A';
1126 1193
 		}
1194
+		}
1127 1195
 		else
1128 1196
 		{
1129 1197
 			return False;	// no rights
@@ -1172,14 +1240,20 @@  discard block
 block discarded – undo
1172 1240
 		if ($event['id'])
1173 1241
 		{
1174 1242
 			// invalidate the read-cache if it contains the event we store now
1175
-			if ($event['id'] == self::$cached_event['id']) self::$cached_event = array();
1243
+			if ($event['id'] == self::$cached_event['id'])
1244
+			{
1245
+				self::$cached_event = array();
1246
+			}
1176 1247
 			$old_event = $this->read($event['id'], $event['recurrence'], false, 'server');
1177 1248
 		}
1178 1249
 		else
1179 1250
 		{
1180 1251
 			$old_event = null;
1181 1252
 		}
1182
-		if (!isset($event['whole_day'])) $event['whole_day'] = $this->isWholeDay($event);
1253
+		if (!isset($event['whole_day']))
1254
+		{
1255
+			$event['whole_day'] = $this->isWholeDay($event);
1256
+		}
1183 1257
 
1184 1258
 		// set recur-enddate/range-end to real end-date of last recurrence
1185 1259
 		if ($event['recur_type'] != MCAL_RECUR_NONE && $event['recur_enddate'] && $event['start'])
@@ -1256,7 +1330,10 @@  discard block
 block discarded – undo
1256 1330
 		foreach($timestamps as $ts)
1257 1331
 		{
1258 1332
 			// we convert here from user-time to timestamps in server-time!
1259
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1333
+			if (isset($event[$ts]))
1334
+			{
1335
+				$event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1336
+			}
1260 1337
 		}
1261 1338
 		// convert tzid name to integer tz_id, of set user default
1262 1339
 		if (empty($event['tzid']) || !($event['tz_id'] = calendar_timezones::tz2id($event['tzid'])))
@@ -1306,7 +1383,10 @@  discard block
 block discarded – undo
1306 1383
 				if (!isset($event['alarm'][$id]))
1307 1384
 				{
1308 1385
 					$alarm['time'] = $event['start'] - $alarm['offset'];
1309
-					if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
1386
+					if ($alarm['time'] < time())
1387
+					{
1388
+						calendar_so::shift_alarm($event, $alarm);
1389
+					}
1310 1390
 						// remove (not store) alarms belonging to not longer existing or rejected participants
1311 1391
 					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] :
1312 1392
 						$old_event['participants'][$alarm['owner']];
@@ -1362,7 +1442,10 @@  discard block
 block discarded – undo
1362 1442
 
1363 1443
 		// Update history
1364 1444
 		$tracking = new calendar_tracking($this);
1365
-		if (empty($event['id']) && !empty($cal_id)) $event['id']=$cal_id;
1445
+		if (empty($event['id']) && !empty($cal_id))
1446
+		{
1447
+			$event['id']=$cal_id;
1448
+		}
1366 1449
 		$tracking->track($event, $old_event);
1367 1450
 
1368 1451
 		return $cal_id;
@@ -1379,9 +1462,12 @@  discard block
 block discarded – undo
1379 1462
 	 */
1380 1463
 	function check_status_perms($uid,$event)
1381 1464
 	{
1382
-		if ($uid[0] == 'c' || $uid[0] == 'e')	// for contact we use the owner of the event
1465
+		if ($uid[0] == 'c' || $uid[0] == 'e')
1466
+		{
1467
+			// for contact we use the owner of the event
1383 1468
 		{
1384 1469
 			if (!is_array($event) && !($event = $this->read($event))) return false;
1470
+		}
1385 1471
 
1386 1472
 			return $this->check_perms(Acl::EDIT,0,$event['owner']);
1387 1473
 		}
@@ -1392,13 +1478,19 @@  discard block
 block discarded – undo
1392 1478
 			return $access;
1393 1479
 		}
1394 1480
 		// no access or denied access because of category acl --> regular check
1395
-		if (!is_numeric($uid))	// this is eg. for resources (r123)
1481
+		if (!is_numeric($uid))
1482
+		{
1483
+			// this is eg. for resources (r123)
1396 1484
 		{
1397 1485
 			$resource = $this->resource_info($uid);
1486
+		}
1398 1487
 
1399 1488
 			return Acl::EDIT & $resource['rights'];
1400 1489
 		}
1401
-		if (!is_array($event) && !($event = $this->read($event))) return false;
1490
+		if (!is_array($event) && !($event = $this->read($event)))
1491
+		{
1492
+			return false;
1493
+		}
1402 1494
 
1403 1495
 		// regular user and groups (need to check memberships too)
1404 1496
 		if (!isset($event['participants'][$uid]))
@@ -1422,7 +1514,10 @@  discard block
 block discarded – undo
1422 1514
 	 */
1423 1515
 	function check_cat_acl($right,$event)
1424 1516
 	{
1425
-		if (!is_array($event)) $event = $this->read($event);
1517
+		if (!is_array($event))
1518
+		{
1519
+			$event = $this->read($event);
1520
+		}
1426 1521
 
1427 1522
 		$ret = null;
1428 1523
 		if ($event['category'])
@@ -1479,7 +1574,10 @@  discard block
 block discarded – undo
1479 1574
 	public static function set_cat_rights($cat_id,$user,$rights)
1480 1575
 	{
1481 1576
 		//echo "<p>".__METHOD__."($cat_id,$user,$rights)</p>\n";
1482
-		if (!isset(self::$cat_rights_cache)) self::get_cat_rights($cat_id);
1577
+		if (!isset(self::$cat_rights_cache))
1578
+		{
1579
+			self::get_cat_rights($cat_id);
1580
+		}
1483 1581
 
1484 1582
 		if ((int)$rights != (int)self::$cat_rights_cache['L'.$cat_id][$user])
1485 1583
 		{
@@ -1491,7 +1589,10 @@  discard block
 block discarded – undo
1491 1589
 			else
1492 1590
 			{
1493 1591
 				unset(self::$cat_rights_cache['L'.$cat_id][$user]);
1494
-				if (!self::$cat_rights_cache['L'.$cat_id]) unset(self::$cat_rights_cache['L'.$cat_id]);
1592
+				if (!self::$cat_rights_cache['L'.$cat_id])
1593
+				{
1594
+					unset(self::$cat_rights_cache['L'.$cat_id]);
1595
+				}
1495 1596
 				$GLOBALS['egw']->acl->delete_repository('calendar','L'.$cat_id,$user);
1496 1597
 			}
1497 1598
 			Api\Cache::setSession('calendar','cat_rights',self::$cat_rights_cache);
@@ -1524,7 +1625,10 @@  discard block
 block discarded – undo
1524 1625
 				foreach($cat_rights as $uid => $value)
1525 1626
 				{
1526 1627
 					$all |= $value;
1527
-					if (in_array($uid,$memberships)) $own |= $value;
1628
+					if (in_array($uid,$memberships))
1629
+					{
1630
+						$own |= $value;
1631
+					}
1528 1632
 				}
1529 1633
 			}
1530 1634
 			foreach(array(self::CAT_ACL_ADD,self::CAT_ACL_STATUS) as $mask)
@@ -1571,13 +1675,16 @@  discard block
 block discarded – undo
1571 1675
 				is_numeric($uid)?$uid:substr($uid,1),$status,
1572 1676
 				$recur_date?$this->date2ts($recur_date,true):0,$role)))
1573 1677
 		{
1574
-			if ($status == 'R')	// remove alarms belonging to rejected participants
1678
+			if ($status == 'R')
1679
+			{
1680
+				// remove alarms belonging to rejected participants
1575 1681
 			{
1576 1682
 				foreach(is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1577 1683
 				{
1578 1684
 					if ((string)$alarm['owner'] === (string)$uid)
1579 1685
 					{
1580 1686
 						$this->so->delete_alarm($id);
1687
+			}
1581 1688
 						//error_log(__LINE__.': '.__METHOD__."(".array2string($event).", '$uid', '$status', ...) deleting alarm=".array2string($alarm).", $status=".array2string($alarm));
1582 1689
 					}
1583 1690
 				}
@@ -1591,8 +1698,15 @@  discard block
 block discarded – undo
1591 1698
 			);
1592 1699
 			if (isset($status2msg[$status]) && !$skip_notification)
1593 1700
 			{
1594
-				if (!is_array($event)) $event = $this->read($cal_id);
1595
-				if (isset($recur_date)) $event = $this->read($event['id'],$recur_date); //re-read the actually edited recurring event
1701
+				if (!is_array($event))
1702
+				{
1703
+					$event = $this->read($cal_id);
1704
+				}
1705
+				if (isset($recur_date))
1706
+				{
1707
+					$event = $this->read($event['id'],$recur_date);
1708
+				}
1709
+				//re-read the actually edited recurring event
1596 1710
 				$this->send_update($status2msg[$status],$event['participants'],$event);
1597 1711
 			}
1598 1712
 
@@ -1615,12 +1729,16 @@  discard block
 block discarded – undo
1615 1729
 	 */
1616 1730
 	function update_status($new_event, $old_event , $recur_date=0, $skip_notification=false)
1617 1731
 	{
1618
-		if (!isset($new_event['participants'])) return;
1732
+		if (!isset($new_event['participants']))
1733
+		{
1734
+			return;
1735
+		}
1619 1736
 
1620 1737
 		// check the old list against the new list
1621 1738
 		foreach ($old_event['participants'] as $userid => $status)
1622
-  		{
1623
-            if (!isset($new_event['participants'][$userid])){
1739
+		{
1740
+            if (!isset($new_event['participants'][$userid]))
1741
+            {
1624 1742
             	// Attendee will be deleted this way
1625 1743
             	$new_event['participants'][$userid] = 'G';
1626 1744
             }
@@ -1703,7 +1821,10 @@  discard block
 block discarded – undo
1703 1821
 					}
1704 1822
 					else
1705 1823
 					{
1706
-						if (!($exception = $this->read($id))) continue;
1824
+						if (!($exception = $this->read($id)))
1825
+						{
1826
+							continue;
1827
+						}
1707 1828
 						$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
1708 1829
 						$exception['reference'] = $exception['recurrence'] = 0;
1709 1830
 						$this->update($exception, true, true, false, true, $msg=null, true);
@@ -1774,7 +1895,10 @@  discard block
 block discarded – undo
1774 1895
 		$event_arr = $this->event2array($event);
1775 1896
 		foreach($event_arr as $key => $val)
1776 1897
 		{
1777
-			if ($key == 'recur_type') $key = 'repetition';
1898
+			if ($key == 'recur_type')
1899
+			{
1900
+				$key = 'repetition';
1901
+			}
1778 1902
 			$details[$key] = $val['data'];
1779 1903
 		}
1780 1904
 		$details['participants'] = $details['participants'] ? implode("\n",$details['participants']) : '';
@@ -1946,7 +2070,10 @@  discard block
 block discarded – undo
1946 2070
 	 */
1947 2071
 	function check_move_alarms(Array &$event, Array $old_event = null, Api\DateTime $instance_date = null)
1948 2072
 	{
1949
-		if ($old_event !== null && $event['start'] == $old_event['start']) return;
2073
+		if ($old_event !== null && $event['start'] == $old_event['start'])
2074
+		{
2075
+			return;
2076
+		}
1950 2077
 
1951 2078
 		$time = new Api\DateTime($event['start']);
1952 2079
 		if(!is_array($event['alarm']))
@@ -2020,7 +2147,10 @@  discard block
 block discarded – undo
2020 2147
 		if (is_array($old_event) || $old_event > 0)
2021 2148
 		{
2022 2149
 			// preserve categories without users read access
2023
-			if (!is_array($old_event)) $old_event = $this->read($old_event);
2150
+			if (!is_array($old_event))
2151
+			{
2152
+				$old_event = $this->read($old_event);
2153
+			}
2024 2154
 			$old_categories = explode(',',$old_event['category']);
2025 2155
 			$old_cats_preserve = array();
2026 2156
 			if (is_array($old_categories) && count($old_categories) > 0)
@@ -2111,7 +2241,10 @@  discard block
 block discarded – undo
2111 2241
 				"($filter)[EVENT]:" . array2string($event)."\n",3,$this->logfile);
2112 2242
 		}
2113 2243
 
2114
-		if (!isset($event['recurrence'])) $event['recurrence'] = 0;
2244
+		if (!isset($event['recurrence']))
2245
+		{
2246
+			$event['recurrence'] = 0;
2247
+		}
2115 2248
 
2116 2249
 		if ($filter == 'master')
2117 2250
 		{
@@ -2165,19 +2298,26 @@  discard block
 block discarded – undo
2165 2298
 							$matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['recurrence'];
2166 2299
 						}
2167 2300
 					}
2168
-				} elseif ($filter != 'master' && ($filter == 'exact' ||
2301
+				}
2302
+				elseif ($filter != 'master' && ($filter == 'exact' ||
2169 2303
 							$event['recur_type'] == $egwEvent['recur_type'] &&
2170 2304
 							strpos($egwEvent['title'], $event['title']) === 0))
2171 2305
 				{
2172 2306
 					$matchingEvents[] = $egwEvent['id']; // we found the event
2173 2307
 				}
2174 2308
 			}
2175
-			if (!empty($matchingEvents) || $filter == 'exact') return $matchingEvents;
2309
+			if (!empty($matchingEvents) || $filter == 'exact')
2310
+			{
2311
+				return $matchingEvents;
2312
+			}
2176 2313
 		}
2177 2314
 		unset($event['id']);
2178 2315
 
2179 2316
 		// No chance to find a master without [U]ID
2180
-		if ($filter == 'master' && empty($event['uid'])) return $matchingEvents;
2317
+		if ($filter == 'master' && empty($event['uid']))
2318
+		{
2319
+			return $matchingEvents;
2320
+		}
2181 2321
 
2182 2322
 		// only query calendars of users, we have READ-grants from
2183 2323
 		$users = array();
@@ -2186,17 +2326,23 @@  discard block
 block discarded – undo
2186 2326
 			$user = trim($user);
2187 2327
 			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY,0,$user))
2188 2328
 			{
2189
-				if ($user && !in_array($user,$users))	// already added?
2329
+				if ($user && !in_array($user,$users))
2330
+				{
2331
+					// already added?
2190 2332
 				{
2191 2333
 					$users[] = $user;
2192 2334
 				}
2335
+				}
2193 2336
 			}
2194 2337
 			elseif ($GLOBALS['egw']->accounts->get_type($user) != 'g')
2195 2338
 			{
2196 2339
 				continue;	// for non-groups (eg. users), we stop here if we have no read-rights
2197 2340
 			}
2198 2341
 			// the further code is only for real users
2199
-			if (!is_numeric($user)) continue;
2342
+			if (!is_numeric($user))
2343
+			{
2344
+				continue;
2345
+			}
2200 2346
 
2201 2347
 			// for groups we have to include the members
2202 2348
 			if ($GLOBALS['egw']->accounts->get_type($user) == 'g')
@@ -2276,7 +2422,10 @@  discard block
 block discarded – undo
2276 2422
 			}
2277 2423
 			foreach ($matchFields as $key)
2278 2424
 			{
2279
-				if (isset($event[$key])) $query['cal_'.$key] = $event[$key];
2425
+				if (isset($event[$key]))
2426
+				{
2427
+					$query['cal_'.$key] = $event[$key];
2428
+				}
2280 2429
 			}
2281 2430
 		}
2282 2431
 
@@ -2316,7 +2465,10 @@  discard block
 block discarded – undo
2316 2465
 					'[FOUND]: ' . array2string($egwEvent)."\n",3,$this->logfile);
2317 2466
 			}
2318 2467
 
2319
-			if (in_array($egwEvent['id'], $matchingEvents)) continue;
2468
+			if (in_array($egwEvent['id'], $matchingEvents))
2469
+			{
2470
+				continue;
2471
+			}
2320 2472
 
2321 2473
 			// convert timezone id of event to tzid (iCal id like 'Europe/Berlin')
2322 2474
 			if (!$egwEvent['tz_id'] || !($egwEvent['tzid'] = calendar_timezones::id2tz($egwEvent['tz_id'])))
@@ -2483,13 +2635,16 @@  discard block
 block discarded – undo
2483 2635
 					foreach ($event['participants'] as $attendee => $status)
2484 2636
 					{
2485 2637
 						if (!isset($egwEvent['participants'][$attendee]) &&
2486
-								$attendee != $egwEvent['owner']) // ||
2638
+								$attendee != $egwEvent['owner'])
2639
+						{
2640
+							// ||
2487 2641
 							//(!$relax && $egw_event['participants'][$attendee] != $status))
2488 2642
 						{
2489 2643
 							if ($this->log)
2490 2644
 							{
2491 2645
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2492 2646
 								"() additional event['participants']: $attendee\n",3,$this->logfile);
2647
+						}
2493 2648
 							}
2494 2649
 							continue 2;
2495 2650
 						}
@@ -2811,7 +2966,10 @@  discard block
 block discarded – undo
2811 2966
 		foreach(array('start','end','recur_enddate','recurrence') as $ts)
2812 2967
 		{
2813 2968
 			// we convert here from server-time to timestamps in user-time!
2814
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
2969
+			if (isset($event[$ts]))
2970
+			{
2971
+				$event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
2972
+			}
2815 2973
 		}
2816 2974
 		// same with the recur exceptions
2817 2975
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
@@ -2839,9 +2997,12 @@  discard block
 block discarded – undo
2839 2997
 	 */
2840 2998
 	function purge($age)
2841 2999
 	{
2842
-		if (is_numeric($age) && $age > 0)	// just make sure bogus values dont delete everything
3000
+		if (is_numeric($age) && $age > 0)
3001
+		{
3002
+			// just make sure bogus values dont delete everything
2843 3003
 		{
2844 3004
 			$this->so->purge(time() - 365*24*3600*(float)$age);
2845 3005
 		}
3006
+		}
2846 3007
 	}
2847 3008
 }
Please login to merge, or discard this patch.
Spacing   +307 added lines, -309 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@  discard block
 block discarded – undo
16 16
 use EGroupware\Api\Acl;
17 17
 
18 18
 // types of messsages send by calendar_boupdate::send_update
19
-define('MSG_DELETED',0);
20
-define('MSG_MODIFIED',1);
21
-define('MSG_ADDED',2);
22
-define('MSG_REJECTED',3);
23
-define('MSG_TENTATIVE',4);
24
-define('MSG_ACCEPTED',5);
25
-define('MSG_ALARM',6);
26
-define('MSG_DISINVITE',7);
27
-define('MSG_DELEGATED',8);
19
+define('MSG_DELETED', 0);
20
+define('MSG_MODIFIED', 1);
21
+define('MSG_ADDED', 2);
22
+define('MSG_REJECTED', 3);
23
+define('MSG_TENTATIVE', 4);
24
+define('MSG_ACCEPTED', 5);
25
+define('MSG_ALARM', 6);
26
+define('MSG_DISINVITE', 7);
27
+define('MSG_DELEGATED', 8);
28 28
 
29 29
 /**
30 30
  * Class to access AND manipulate all calendar data (business object)
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	function __construct()
87 87
 	{
88
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started',True);
88
+		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started', True);
89 89
 
90
-		parent::__construct();	// calling the parent constructor
90
+		parent::__construct(); // calling the parent constructor
91 91
 
92
-		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished',True);
92
+		if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished', True);
93 93
 	}
94 94
 
95 95
 	/**
@@ -116,16 +116,16 @@  discard block
 block discarded – undo
116 116
 	 * +      + +  C   +	which is clearly wrong for everything with a maximum quantity > 1
117 117
 	 * ++++++++ ++++++++
118 118
 	 */
119
-	function update(&$event,$ignore_conflicts=false,$touch_modified=true,$ignore_acl=false,$updateTS=true,&$messages=null, $skip_notification=false)
119
+	function update(&$event, $ignore_conflicts = false, $touch_modified = true, $ignore_acl = false, $updateTS = true, &$messages = null, $skip_notification = false)
120 120
 	{
121
-		unset($updateTS);	// ignored, as updating timestamps is required for sync!
121
+		unset($updateTS); // ignored, as updating timestamps is required for sync!
122 122
 		//error_log(__METHOD__."(".array2string($event).",$ignore_conflicts,$touch_modified,$ignore_acl)");
123 123
 		if (!is_array($messages)) $messages = $messages ? (array)$messages : array();
124 124
 
125 125
 		if ($this->debug > 1 || $this->debug == 'update')
126 126
 		{
127 127
 			$this->debug_message('calendar_boupdate::update(%1,ignore_conflict=%2,touch_modified=%3,ignore_acl=%4)',
128
-				false,$event,$ignore_conflicts,$touch_modified,$ignore_acl);
128
+				false, $event, $ignore_conflicts, $touch_modified, $ignore_acl);
129 129
 		}
130 130
 		// check some minimum requirements:
131 131
 		// - new events need start, end and title
@@ -153,11 +153,11 @@  discard block
 block discarded – undo
153 153
 		}
154 154
 
155 155
 		// check if user has the permission to update / create the event
156
-		if (!$ignore_acl && (!$new_event && !$this->check_perms(Acl::EDIT,$event['id']) ||
157
-			$new_event && !$this->check_perms(Acl::EDIT,0,$event['owner'])) &&
158
-			!$this->check_perms(Acl::ADD,0,$event['owner']))
156
+		if (!$ignore_acl && (!$new_event && !$this->check_perms(Acl::EDIT, $event['id']) ||
157
+			$new_event && !$this->check_perms(Acl::EDIT, 0, $event['owner'])) &&
158
+			!$this->check_perms(Acl::ADD, 0, $event['owner']))
159 159
 		{
160
-			$messages[] = lang('Access to calendar of %1 denied!',Api\Accounts::username($event['owner']));
160
+			$messages[] = lang('Access to calendar of %1 denied!', Api\Accounts::username($event['owner']));
161 161
 			return false;
162 162
 		}
163 163
 		if ($new_event)
@@ -166,24 +166,24 @@  discard block
 block discarded – undo
166 166
 		}
167 167
 		else
168 168
 		{
169
-			$old_event = $this->read((int)$event['id'],null,$ignore_acl);
169
+			$old_event = $this->read((int)$event['id'], null, $ignore_acl);
170 170
 		}
171 171
 
172 172
 		// do we need to check, if user is allowed to invite the invited participants
173
-		if ($this->require_acl_invite && ($removed = $this->remove_no_acl_invite($event,$old_event)))
173
+		if ($this->require_acl_invite && ($removed = $this->remove_no_acl_invite($event, $old_event)))
174 174
 		{
175 175
 			// report removed participants back to user
176
-			foreach($removed as $key => $account_id)
176
+			foreach ($removed as $key => $account_id)
177 177
 			{
178 178
 				$removed[$key] = $this->participant_name($account_id);
179 179
 			}
180
-			$messages[] = lang('%1 participants removed because of missing invite grants',count($removed)).
181
-				': '.implode(', ',$removed);
180
+			$messages[] = lang('%1 participants removed because of missing invite grants', count($removed)).
181
+				': '.implode(', ', $removed);
182 182
 		}
183 183
 		// check category based ACL
184 184
 		if ($event['category'])
185 185
 		{
186
-			if (!is_array($event['category'])) $event['category'] = explode(',',$event['category']);
186
+			if (!is_array($event['category'])) $event['category'] = explode(',', $event['category']);
187 187
 			if (!$old_event || !isset($old_event['category']))
188 188
 			{
189 189
 				$old_event['category'] = array();
@@ -192,38 +192,38 @@  discard block
 block discarded – undo
192 192
 			{
193 193
 				$old_event['category'] = explode(',', $old_event['category']);
194 194
 			}
195
-			foreach($event['category'] as $key => $cat_id)
195
+			foreach ($event['category'] as $key => $cat_id)
196 196
 			{
197 197
 				// check if user is allowed to update event categories
198
-				if ((!$old_event || !in_array($cat_id,$old_event['category'])) &&
199
-					self::has_cat_right(self::CAT_ACL_ADD,$cat_id,$this->user) === false)
198
+				if ((!$old_event || !in_array($cat_id, $old_event['category'])) &&
199
+					self::has_cat_right(self::CAT_ACL_ADD, $cat_id, $this->user) === false)
200 200
 				{
201 201
 					unset($event['category'][$key]);
202 202
 					// report removed category to user
203 203
 					$removed_cats[$cat_id] = $this->categories->id2name($cat_id);
204
-					continue;	// no further check, as cat was removed
204
+					continue; // no further check, as cat was removed
205 205
 				}
206 206
 				// for new or moved events check status of participants, if no category status right --> set all status to 'U' = unknown
207 207
 				if (!$status_reset_to_unknown &&
208
-					self::has_cat_right(self::CAT_ACL_STATUS,$cat_id,$this->user) === false &&
208
+					self::has_cat_right(self::CAT_ACL_STATUS, $cat_id, $this->user) === false &&
209 209
 					(!$old_event || $old_event['start'] != $event['start'] || $old_event['end'] != $event['end']))
210 210
 				{
211
-					foreach((array)$event['participants'] as $uid => $status)
211
+					foreach ((array)$event['participants'] as $uid => $status)
212 212
 					{
213 213
 						$q = $r = null;
214
-						calendar_so::split_status($status,$q,$r);
214
+						calendar_so::split_status($status, $q, $r);
215 215
 						if ($status != 'U')
216 216
 						{
217
-							$event['participants'][$uid] = calendar_so::combine_status('U',$q,$r);
217
+							$event['participants'][$uid] = calendar_so::combine_status('U', $q, $r);
218 218
 							// todo: report reset status to user
219 219
 						}
220 220
 					}
221
-					$status_reset_to_unknown = true;	// once is enough
221
+					$status_reset_to_unknown = true; // once is enough
222 222
 				}
223 223
 			}
224 224
 			if ($removed_cats)
225 225
 			{
226
-				$messages[] = lang('Category %1 removed because of missing rights',implode(', ',$removed_cats));
226
+				$messages[] = lang('Category %1 removed because of missing rights', implode(', ', $removed_cats));
227 227
 			}
228 228
 			if ($status_reset_to_unknown)
229 229
 			{
@@ -259,30 +259,30 @@  discard block
 block discarded – undo
259 259
 		$event = $this->read($cal_id, null, $ignore_acl, 'ts', $new_event && !$event['public'] ? $this->user : null);
260 260
 		//error_log("new $cal_id=". array2string($event));
261 261
 
262
-		if($old_event['deleted'] && $event['deleted'] == null)
262
+		if ($old_event['deleted'] && $event['deleted'] == null)
263 263
 		{
264 264
 			// Restored, bring back links
265 265
 			Link::restore('calendar', $cal_id);
266 266
 		}
267 267
 		if ($this->log_file)
268 268
 		{
269
-			$this->log2file($event2save,$event,$old_event);
269
+			$this->log2file($event2save, $event, $old_event);
270 270
 		}
271 271
 		// send notifications
272
-		if(!$skip_notification)
272
+		if (!$skip_notification)
273 273
 		{
274 274
 			if ($new_event)
275 275
 			{
276
-				$this->send_update(MSG_ADDED,$event['participants'],'',$event);
276
+				$this->send_update(MSG_ADDED, $event['participants'], '', $event);
277 277
 			}
278 278
 			else // update existing event
279 279
 			{
280
-				$this->check4update($event,$old_event);
280
+				$this->check4update($event, $old_event);
281 281
 			}
282 282
 		}
283 283
 
284 284
 		// notify the link-class about the update, as other apps may be subscribt to it
285
-		Link::notify_update('calendar',$cal_id,$event);
285
+		Link::notify_update('calendar', $cal_id, $event);
286 286
 
287 287
 		return $cal_id;
288 288
 	}
@@ -300,27 +300,27 @@  discard block
 block discarded – undo
300 300
 	 * @param Api\DateTime& $checked_excluding =null time until which (excluding) recurrences have been checked
301 301
 	 * @return array or events
302 302
 	 */
303
-	function conflicts(array $event, &$checked_excluding=null)
303
+	function conflicts(array $event, &$checked_excluding = null)
304 304
 	{
305 305
 		$types_with_quantity = array();
306
-		foreach($this->resources as $type => $data)
306
+		foreach ($this->resources as $type => $data)
307 307
 		{
308 308
 			if ($data['max_quantity']) $types_with_quantity[] = $type;
309 309
 		}
310 310
 		// get all NOT rejected participants and evtl. their quantity
311 311
 		$quantity = $users = array();
312
-		foreach($event['participants'] as $uid => $status)
312
+		foreach ($event['participants'] as $uid => $status)
313 313
 		{
314 314
 			$q = $role = null;
315 315
 			calendar_so::split_status($status, $q, $role);
316
-			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue;	// ignore rejected or non-participants
316
+			if ($status == 'R' || $role == 'NON-PARTICIPANT') continue; // ignore rejected or non-participants
317 317
 
318 318
 			if ($uid < 0)	// group, check it's members too
319 319
 			{
320
-				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid,true)));
320
+				$users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid, true)));
321 321
 			}
322 322
 			$users[] = $uid;
323
-			if (in_array($uid[0],$types_with_quantity))
323
+			if (in_array($uid[0], $types_with_quantity))
324 324
 			{
325 325
 				$quantity[$uid] = $q;
326 326
 			}
@@ -343,58 +343,58 @@  discard block
 block discarded – undo
343 343
 		}
344 344
 		$checked = 0;
345 345
 		$start = microtime(true);
346
-		$duration = $event['end']-$event['start'];
347
-		foreach($recurences as $date)
346
+		$duration = $event['end'] - $event['start'];
347
+		foreach ($recurences as $date)
348 348
 		{
349 349
 			$startts = $date->format('ts');
350 350
 
351 351
 			// skip past events or recurrences
352
-			if ($startts+$duration < $this->now_su) continue;
352
+			if ($startts + $duration < $this->now_su) continue;
353 353
 
354 354
 			// abort check if configured limits are exceeded
355 355
 			if ($event['recur_type'] &&
356 356
 				(++$checked > $max_checked && $max_checked > 0 || // maximum number of checked recurrences exceeded
357
-				microtime(true) > $start+$max_check_time ||	// max check time exceeded
357
+				microtime(true) > $start + $max_check_time || // max check time exceeded
358 358
 				$startts > $this->config['horizont']))	// we are behind horizon for which recurrences are rendered
359 359
 			{
360 360
 				if ($this->debug > 2 || $this->debug == 'conflicts')
361 361
 				{
362 362
 					$this->debug_message(__METHOD__.'() conflict check limited to %1 recurrences, %2 seconds, until (excluding) %3',
363
-						$checked, microtime(true)-$start, $date);
363
+						$checked, microtime(true) - $start, $date);
364 364
 				}
365 365
 				$checked_excluding = $date;
366 366
 				break;
367 367
 			}
368
-			$overlapping_events =& $this->search(array(
368
+			$overlapping_events = & $this->search(array(
369 369
 				'start' => $startts,
370
-				'end'   => $startts+$duration,
370
+				'end'   => $startts + $duration,
371 371
 				'users' => $users,
372
-				'ignore_acl' => true,	// otherwise we get only events readable by the user
373
-				'enum_groups' => true,	// otherwise group-events would not block time
372
+				'ignore_acl' => true, // otherwise we get only events readable by the user
373
+				'enum_groups' => true, // otherwise group-events would not block time
374 374
 				'query' => array(
375 375
 					'cal_non_blocking' => 0,
376 376
 				),
377
-				'no_integration' => true,	// do NOT use integration of other apps
377
+				'no_integration' => true, // do NOT use integration of other apps
378 378
 			));
379 379
 			if ($this->debug > 2 || $this->debug == 'conflicts')
380 380
 			{
381
-				$this->debug_message(__METHOD__.'() checking for potential overlapping events for users %1 from %2 to %3',false,$users,$startts,$startts+$duration);
381
+				$this->debug_message(__METHOD__.'() checking for potential overlapping events for users %1 from %2 to %3', false, $users, $startts, $startts + $duration);
382 382
 			}
383
-			foreach((array) $overlapping_events as $k => $overlap)
383
+			foreach ((array)$overlapping_events as $k => $overlap)
384 384
 			{
385
-				if ($overlap['id'] == $event['id'] ||	// that's the event itself
386
-					$overlap['id'] == $event['reference'] ||	// event is an exception of overlap
385
+				if ($overlap['id'] == $event['id'] || // that's the event itself
386
+					$overlap['id'] == $event['reference'] || // event is an exception of overlap
387 387
 					$overlap['non_blocking'])			// that's a non_blocking event
388 388
 				{
389 389
 					continue;
390 390
 				}
391 391
 				if ($this->debug > 3 || $this->debug == 'conflicts')
392 392
 				{
393
-					$this->debug_message(__METHOD__.'() checking overlapping event %1',false,$overlap);
393
+					$this->debug_message(__METHOD__.'() checking overlapping event %1', false, $overlap);
394 394
 				}
395 395
 				// check if the overlap is with a rejected participant or within the allowed quantity
396
-				$common_parts = array_intersect($users,array_keys($overlap['participants']));
397
-				foreach($common_parts as $n => $uid)
396
+				$common_parts = array_intersect($users, array_keys($overlap['participants']));
397
+				foreach ($common_parts as $n => $uid)
398 398
 				{
399 399
 					$status = $overlap['participants'][$uid];
400 400
 					calendar_so::split_status($status, $q, $role);
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
 						unset($common_parts[$n]);
404 404
 						continue;
405 405
 					}
406
-					if (is_numeric($uid) || !in_array($uid[0],$types_with_quantity))
406
+					if (is_numeric($uid) || !in_array($uid[0], $types_with_quantity))
407 407
 					{
408
-						continue;	// no quantity check: quantity allways 1 ==> conflict
408
+						continue; // no quantity check: quantity allways 1 ==> conflict
409 409
 					}
410 410
 					if (!isset($max_quantity[$uid]))
411 411
 					{
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 					$quantity[$uid] += $q;
416 416
 					if ($quantity[$uid] <= $max_quantity[$uid])
417 417
 					{
418
-						$possible_quantity_conflicts[$uid][] =& $overlapping_events[$k];	// an other event can give the conflict
418
+						$possible_quantity_conflicts[$uid][] = & $overlapping_events[$k]; // an other event can give the conflict
419 419
 						unset($common_parts[$n]);
420 420
 						continue;
421 421
 					}
@@ -425,22 +425,22 @@  discard block
 block discarded – undo
425 425
 				{
426 426
 					if ($this->debug > 3 || $this->debug == 'conflicts')
427 427
 					{
428
-						$this->debug_message(__METHOD__.'() conflicts with the following participants found %1',false,$common_parts);
428
+						$this->debug_message(__METHOD__.'() conflicts with the following participants found %1', false, $common_parts);
429 429
 					}
430
-					$conflicts[$overlap['id'].'-'.$this->date2ts($overlap['start'])] =& $overlapping_events[$k];
430
+					$conflicts[$overlap['id'].'-'.$this->date2ts($overlap['start'])] = & $overlapping_events[$k];
431 431
 				}
432 432
 			}
433 433
 		}
434 434
 		//error_log(__METHOD__."() conflict check took ".number_format(microtime(true)-$start, 3).'s');
435 435
 		// check if we are withing the allowed quantity and if not add all events using that resource
436 436
 		// seems this function is doing very strange things, it gives empty conflicts
437
-		foreach($max_quantity as $uid => $max)
437
+		foreach ($max_quantity as $uid => $max)
438 438
 		{
439 439
 			if ($quantity[$uid] > $max)
440 440
 			{
441
-				foreach((array)$possible_quantity_conflicts[$uid] as $conflict)
441
+				foreach ((array)$possible_quantity_conflicts[$uid] as $conflict)
442 442
 				{
443
-					$conflicts[$conflict['id'].'-'.$this->date2ts($conflict['start'])] =& $possible_quantity_conflicts[$k];
443
+					$conflicts[$conflict['id'].'-'.$this->date2ts($conflict['start'])] = & $possible_quantity_conflicts[$k];
444 444
 				}
445 445
 			}
446 446
 		}
@@ -448,10 +448,10 @@  discard block
 block discarded – undo
448 448
 
449 449
 		if (count($conflicts))
450 450
 		{
451
-			foreach($conflicts as $key => $conflict)
451
+			foreach ($conflicts as $key => $conflict)
452 452
 			{
453
-					$conflict['participants'] = array_intersect_key((array)$conflict['participants'],$event['participants']);
454
-				if (!$this->check_perms(Acl::READ,$conflict))
453
+					$conflict['participants'] = array_intersect_key((array)$conflict['participants'], $event['participants']);
454
+				if (!$this->check_perms(Acl::READ, $conflict))
455 455
 				{
456 456
 					$conflicts[$key] = array(
457 457
 						'id'    => $conflict['id'],
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 			}
465 465
 			if ($this->debug > 2 || $this->debug == 'conflicts')
466 466
 			{
467
-				$this->debug_message(__METHOD__.'() %1 conflicts found %2',false,count($conflicts),$conflicts);
467
+				$this->debug_message(__METHOD__.'() %1 conflicts found %2', false, count($conflicts), $conflicts);
468 468
 			}
469 469
 		}
470 470
 		return $conflicts;
@@ -476,22 +476,22 @@  discard block
 block discarded – undo
476 476
 	 * @param array $old_event =null old event with already invited participants
477 477
 	 * @return array removed participants because of missing invite grants
478 478
 	 */
479
-	public function remove_no_acl_invite(array &$event,array $old_event=null)
479
+	public function remove_no_acl_invite(array &$event, array $old_event = null)
480 480
 	{
481 481
 		if (!$this->require_acl_invite)
482 482
 		{
483
-			return array();	// nothing to check, everyone can invite everyone else
483
+			return array(); // nothing to check, everyone can invite everyone else
484 484
 		}
485 485
 		if ($event['id'] && is_null($old_event))
486 486
 		{
487 487
 			$old_event = $this->read($event['id']);
488 488
 		}
489 489
 		$removed = array();
490
-		foreach(array_keys((array)$event['participants']) as $uid)
490
+		foreach (array_keys((array)$event['participants']) as $uid)
491 491
 		{
492 492
 			if ((is_null($old_event) || !isset($old_event['participants'][$uid])) && !$this->check_acl_invite($uid))
493 493
 			{
494
-				unset($event['participants'][$uid]);	// remove participant
494
+				unset($event['participants'][$uid]); // remove participant
495 495
 				$removed[] = $uid;
496 496
 			}
497 497
 		}
@@ -507,19 +507,19 @@  discard block
 block discarded – undo
507 507
 	 */
508 508
 	public function check_acl_invite($uid)
509 509
 	{
510
-		if (!is_numeric($uid)) return true;	// nothing implemented for resources so far
510
+		if (!is_numeric($uid)) return true; // nothing implemented for resources so far
511 511
 
512 512
 		if (!$this->require_acl_invite)
513 513
 		{
514
-			$ret = true;	// no grant required
514
+			$ret = true; // no grant required
515 515
 		}
516 516
 		elseif ($this->require_acl_invite == 'groups' && $GLOBALS['egw']->accounts->get_type($uid) != 'g')
517 517
 		{
518
-			$ret = true;	// grant only required for groups
518
+			$ret = true; // grant only required for groups
519 519
 		}
520 520
 		else
521 521
 		{
522
-			$ret = $this->check_perms(self::ACL_INVITE,0,$uid);
522
+			$ret = $this->check_perms(self::ACL_INVITE, 0, $uid);
523 523
 		}
524 524
 		//error_log(__METHOD__."($uid) = ".array2string($ret));
525 525
 		//echo "<p>".__METHOD__."($uid) require_acl_invite=$this->require_acl_invite returning ".array2string($ret)."</p>\n";
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 	 * @param array $old_event the event before the update
534 534
 	 * @todo check if there is a real change, not assume every save is a change
535 535
 	 */
536
-	function check4update($new_event,$old_event)
536
+	function check4update($new_event, $old_event)
537 537
 	{
538 538
 		//error_log(__METHOD__."($new_event[title])");
539 539
 		$modified = $added = $deleted = array();
@@ -541,9 +541,9 @@  discard block
 block discarded – undo
541 541
 		//echo "<p>calendar_boupdate::check4update() new participants = ".print_r($new_event['participants'],true).", old participants =".print_r($old_event['participants'],true)."</p>\n";
542 542
 
543 543
 		// Find modified and deleted participants ...
544
-		foreach($old_event['participants'] as $old_userid => $old_status)
544
+		foreach ($old_event['participants'] as $old_userid => $old_status)
545 545
 		{
546
-			if(isset($new_event['participants'][$old_userid]))
546
+			if (isset($new_event['participants'][$old_userid]))
547 547
 			{
548 548
 				$modified[$old_userid] = $new_event['participants'][$old_userid];
549 549
 			}
@@ -553,27 +553,27 @@  discard block
 block discarded – undo
553 553
 			}
554 554
 		}
555 555
 		// Find new participants ...
556
-		foreach(array_keys((array)$new_event['participants']) as $new_userid)
556
+		foreach (array_keys((array)$new_event['participants']) as $new_userid)
557 557
 		{
558
-			if(!isset($old_event['participants'][$new_userid]))
558
+			if (!isset($old_event['participants'][$new_userid]))
559 559
 			{
560 560
 				$added[$new_userid] = 'U';
561 561
 			}
562 562
 		}
563 563
 		//echo "<p>calendar_boupdate::check4update() added=".print_r($added,true).", modified=".print_r($modified,true).", deleted=".print_r($deleted,true)."</p>\n";
564
-		if(count($added) || count($modified) || count($deleted))
564
+		if (count($added) || count($modified) || count($deleted))
565 565
 		{
566
-			if(count($added))
566
+			if (count($added))
567 567
 			{
568
-				$this->send_update(MSG_ADDED,$added,$old_event,$new_event);
568
+				$this->send_update(MSG_ADDED, $added, $old_event, $new_event);
569 569
 			}
570
-			if(count($modified))
570
+			if (count($modified))
571 571
 			{
572
-				$this->send_update(MSG_MODIFIED,$modified,$old_event,$new_event);
572
+				$this->send_update(MSG_MODIFIED, $modified, $old_event, $new_event);
573 573
 			}
574
-			if(count($deleted))
574
+			if (count($deleted))
575 575
 			{
576
-				$this->send_update(MSG_DISINVITE,$deleted,$new_event);
576
+				$this->send_update(MSG_DISINVITE, $deleted, $new_event);
577 577
 			}
578 578
 		}
579 579
 	}
@@ -590,11 +590,11 @@  discard block
 block discarded – undo
590 590
 	 * @param string $status of current user
591 591
 	 * @return boolean true = update requested, false otherwise
592 592
 	 */
593
-	public static function update_requested($userid, $part_prefs, &$msg_type, $old_event ,$new_event, $role, $status=null)
593
+	public static function update_requested($userid, $part_prefs, &$msg_type, $old_event, $new_event, $role, $status = null)
594 594
 	{
595 595
 		if ($msg_type == MSG_ALARM)
596 596
 		{
597
-			return True;	// always True for now
597
+			return True; // always True for now
598 598
 		}
599 599
 		$want_update = 0;
600 600
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 		//
603 603
 		$msg_is_response = $msg_type == MSG_REJECTED || $msg_type == MSG_ACCEPTED || $msg_type == MSG_TENTATIVE || $msg_type == MSG_DELEGATED;
604 604
 
605
-		switch($ru = $part_prefs['calendar']['receive_updates'])
605
+		switch ($ru = $part_prefs['calendar']['receive_updates'])
606 606
 		{
607 607
 			case 'responses':
608 608
 				++$want_update;
@@ -616,8 +616,8 @@  discard block
 block discarded – undo
616 616
 			default:
617 617
 				if (is_array($new_event) && is_array($old_event))
618 618
 				{
619
-					$diff = max(abs(self::date2ts($old_event['start'])-self::date2ts($new_event['start'])),
620
-						abs(self::date2ts($old_event['end'])-self::date2ts($new_event['end'])));
619
+					$diff = max(abs(self::date2ts($old_event['start']) - self::date2ts($new_event['start'])),
620
+						abs(self::date2ts($old_event['end']) - self::date2ts($new_event['end'])));
621 621
 					$check = $ru == 'time_change_4h' ? 4 * 60 * 60 - 1 : 0;
622 622
 					if ($msg_type == MSG_MODIFIED && $diff > $check)
623 623
 					{
@@ -637,13 +637,13 @@  discard block
 block discarded – undo
637 637
 				if (!is_numeric($userid) && $role == 'CHAIR' &&
638 638
 					($msg_is_response || in_array($msg_type, array(MSG_ADDED, MSG_DELETED))))
639 639
 				{
640
-					switch($msg_type)
640
+					switch ($msg_type)
641 641
 					{
642 642
 						case MSG_DELETED:	// treat deleting event as rejection to organizer
643 643
 							$msg_type = MSG_REJECTED;
644 644
 							break;
645 645
 						case MSG_ADDED:		// new events use added, but organizer needs status
646
-							switch($status[0])
646
+							switch ($status[0])
647 647
 							{
648 648
 								case 'A': $msg_type = MSG_ACCEPTED; break;
649 649
 								case 'R': $msg_type = MSG_REJECTED; break;
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
 	 * @param string $role ='REQ-PARTICIPANT'
669 669
 	 * @return boolean true if user requested to be notified, false if not
670 670
 	 */
671
-	static public function email_update_requested($user_or_email, $ical_method='REQUEST', $role='REQ-PARTICIPANT')
671
+	static public function email_update_requested($user_or_email, $ical_method = 'REQUEST', $role = 'REQ-PARTICIPANT')
672 672
 	{
673 673
 		// check if email is from a user
674 674
 		if (is_numeric($user_or_email))
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
 				)
693 693
 			);
694 694
 		}
695
-		switch($ical_method)
695
+		switch ($ical_method)
696 696
 		{
697 697
 			default:
698 698
 			case 'REQUEST':
@@ -717,9 +717,9 @@  discard block
 block discarded – undo
717 717
 	 * @param string& $action=null on return verbose name
718 718
 	 * @param string& $msg=null on return notification message
719 719
 	 */
720
-	function msg_type2ical_method($msg_type, &$action=null, &$msg=null)
720
+	function msg_type2ical_method($msg_type, &$action = null, &$msg = null)
721 721
 	{
722
-		switch($msg_type)
722
+		switch ($msg_type)
723 723
 		{
724 724
 			case MSG_DELETED:
725 725
 				$action = 'Canceled';
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 		$msg = $this->cal_prefs['notify'.$pref];
772 772
 		if (empty($msg))
773 773
 		{
774
-			$msg = $this->cal_prefs['notifyAdded'];	// use a default
774
+			$msg = $this->cal_prefs['notifyAdded']; // use a default
775 775
 		}
776 776
 		//error_log(__METHOD__."($msg_type) action='$action', $msg='$msg' returning '$method'");
777 777
 		return $method;
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 	 * @param int $user =0 User who started the notify, default current user
788 788
 	 * @return bool true/false
789 789
 	 */
790
-	function send_update($msg_type,$to_notify,$old_event,$new_event=null,$user=0)
790
+	function send_update($msg_type, $to_notify, $old_event, $new_event = null, $user = 0)
791 791
 	{
792 792
 		//error_log(__METHOD__."($msg_type,".array2string($to_notify).",...) ".array2string($new_event));
793 793
 		if (!is_array($to_notify))
@@ -799,11 +799,11 @@  discard block
 block discarded – undo
799 799
 		$owner = $old_event ? $old_event['owner'] : $new_event['owner'];
800 800
 		if ($owner && !isset($to_notify[$owner]) && $msg_type != MSG_ALARM)
801 801
 		{
802
-			$to_notify[$owner] = 'OCHAIR';	// always include the event-owner
802
+			$to_notify[$owner] = 'OCHAIR'; // always include the event-owner
803 803
 		}
804 804
 
805 805
 		// ignore events in the past (give a tolerance of 10 seconds for the script)
806
-		if($old_event && $this->date2ts($old_event['start']) < ($this->now_su - 10))
806
+		if ($old_event && $this->date2ts($old_event['start']) < ($this->now_su - 10))
807 807
 		{
808 808
 			return False;
809 809
 		}
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
 			$restore_tz = $tz;
814 814
 			date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
815 815
 		}
816
-		$temp_user = $GLOBALS['egw_info']['user'];	// save user-date of the enviroment to restore it after
816
+		$temp_user = $GLOBALS['egw_info']['user']; // save user-date of the enviroment to restore it after
817 817
 
818 818
 		if (!$user)
819 819
 		{
@@ -829,16 +829,16 @@  discard block
 block discarded – undo
829 829
 		$event = $msg_type == MSG_ADDED || $msg_type == MSG_MODIFIED ? $new_event : $old_event;
830 830
 
831 831
 		// add all group-members to the notification, unless they are already participants
832
-		foreach($to_notify as $userid => $statusid)
832
+		foreach ($to_notify as $userid => $statusid)
833 833
 		{
834 834
 			if (is_numeric($userid) && $GLOBALS['egw']->accounts->get_type($userid) == 'g' &&
835 835
 				($members = $GLOBALS['egw']->accounts->members($userid, true)))
836 836
 			{
837
-				foreach($members as $member)
837
+				foreach ($members as $member)
838 838
 				{
839 839
 					if (!isset($to_notify[$member]))
840 840
 					{
841
-						$to_notify[$member] = 'G';	// Group-invitation
841
+						$to_notify[$member] = 'G'; // Group-invitation
842 842
 					}
843 843
 				}
844 844
 			}
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 		if ($old_event) $olddate = new Api\DateTime($old_event['start']);
851 851
 		//error_log(__METHOD__."() date_default_timezone_get()=".date_default_timezone_get().", user-timezone=".Api\DateTime::$user_timezone->getName().", startdate=".$startdate->format().", enddate=".$enddate->format().", updated=".$modified->format().", olddate=".($olddate ? $olddate->format() : ''));
852 852
 		$owner_prefs = $ics = null;
853
-		foreach($to_notify as $userid => $statusid)
853
+		foreach ($to_notify as $userid => $statusid)
854 854
 		{
855 855
 			$res_info = $quantity = $role = null;
856 856
 			calendar_so::split_status($statusid, $quantity, $role);
@@ -873,14 +873,14 @@  discard block
 block discarded – undo
873 873
 
874 874
 				if (!isset($userid))
875 875
 				{
876
-					if (empty($res_info['email'])) continue;	// no way to notify
876
+					if (empty($res_info['email'])) continue; // no way to notify
877 877
 					// check if event-owner wants non-EGroupware users notified
878 878
 					if (is_null($owner_prefs))
879 879
 					{
880 880
 						$preferences = new Api\Preferences($owner);
881 881
 						$owner_prefs = $preferences->read_repository();
882 882
 					}
883
-					if ($role != 'CHAIR' &&		// always notify externals CHAIRs
883
+					if ($role != 'CHAIR' && // always notify externals CHAIRs
884 884
 						(empty($owner_prefs['calendar']['notify_externals']) ||
885 885
 						$owner_prefs['calendar']['notify_externals'] == 'no'))
886 886
 					{
@@ -892,12 +892,12 @@  discard block
 block discarded – undo
892 892
 
893 893
 			if ($statusid == 'R' || $GLOBALS['egw']->accounts->get_type($userid) == 'g')
894 894
 			{
895
-				continue;	// dont notify rejected participants or groups
895
+				continue; // dont notify rejected participants or groups
896 896
 			}
897 897
 
898
-			if($userid != $GLOBALS['egw_info']['user']['account_id'] ||
898
+			if ($userid != $GLOBALS['egw_info']['user']['account_id'] ||
899 899
 				($userid == $GLOBALS['egw_info']['user']['account_id'] &&
900
-					$user_prefs['calendar']['receive_own_updates']==1) ||
900
+					$user_prefs['calendar']['receive_own_updates'] == 1) ||
901 901
 				$msg_type == MSG_ALARM)
902 902
 			{
903 903
 				$tfn = $tln = $lid = null; //cleanup of lastname and fullname (in case they are set in a previous loop)
@@ -906,8 +906,8 @@  discard block
 block discarded – undo
906 906
 					$preferences = new Api\Preferences($userid);
907 907
 					$GLOBALS['egw_info']['user']['preferences'] = $part_prefs = $preferences->read_repository();
908 908
 					$fullname = Api\Accounts::username($userid);
909
-					$tfn = Api\Accounts::id2name($userid,'account_firstname');
910
-					$tln = Api\Accounts::id2name($userid,'account_lastname');
909
+					$tfn = Api\Accounts::id2name($userid, 'account_firstname');
910
+					$tln = Api\Accounts::id2name($userid, 'account_lastname');
911 911
 				}
912 912
 				else	// external email address: use Api\Preferences of event-owner, plus some hardcoded settings (eg. ical notification)
913 913
 				{
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 					}
919 919
 					$part_prefs = $owner_prefs;
920 920
 					$part_prefs['calendar']['receive_updates'] = $owner_prefs['calendar']['notify_externals'];
921
-					$part_prefs['calendar']['update_format'] = 'ical';	// use ical format
921
+					$part_prefs['calendar']['update_format'] = 'ical'; // use ical format
922 922
 					$fullname = $res_info && !empty($res_info['name']) ? $res_info['name'] : $userid;
923 923
 				}
924 924
 				$m_type = $msg_type;
@@ -943,14 +943,14 @@  discard block
 block discarded – undo
943 943
 				$details = $this->_get_event_details(isset($cleared_event) ? $cleared_event : $event,
944 944
 					$action, $event_arr, $disinvited);
945 945
 				$details['to-fullname'] = $fullname;
946
-				$details['to-firstname'] = isset($tfn)? $tfn: '';
947
-				$details['to-lastname'] = isset($tln)? $tln: '';
946
+				$details['to-firstname'] = isset($tfn) ? $tfn : '';
947
+				$details['to-lastname'] = isset($tln) ? $tln : '';
948 948
 
949 949
 				// event is in user-time of current user, now we need to calculate the tz-difference to the notified user and take it into account
950 950
 				if (!isset($part_prefs['common']['tz'])) $part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone'];
951 951
 				$timezone = new DateTimeZone($part_prefs['common']['tz']);
952 952
 				$timeformat = $part_prefs['common']['timeformat'];
953
-				switch($timeformat)
953
+				switch ($timeformat)
954 954
 				{
955 955
 			  		case '24':
956 956
 						$timeformat = 'H:i';
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
 						$timeformat = 'h:i a';
960 960
 						break;
961 961
 				}
962
-				$timeformat = $part_prefs['common']['dateformat'] . ', ' . $timeformat;
962
+				$timeformat = $part_prefs['common']['dateformat'].', '.$timeformat;
963 963
 
964 964
 				$startdate->setTimezone($timezone);
965 965
 				$details['startdate'] = $startdate->format($timeformat);
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
 				$details['enddate'] = $enddate->format($timeformat);
969 969
 
970 970
 				$modified->setTimezone($timezone);
971
-				$details['updated'] = $modified->format($timeformat) . ', ' . Api\Accounts::username($event['modifier']);
971
+				$details['updated'] = $modified->format($timeformat).', '.Api\Accounts::username($event['modifier']);
972 972
 
973 973
 				if ($old_event != False)
974 974
 				{
@@ -977,15 +977,14 @@  discard block
 block discarded – undo
977 977
 				}
978 978
 				//error_log(__METHOD__."() userid=$userid, timezone=".$timezone->getName().", startdate=$details[startdate], enddate=$details[enddate], updated=$details[updated], olddate=$details[olddate]");
979 979
 
980
-				list($subject,$notify_body) = explode("\n",$GLOBALS['egw']->preferences->parse_notify($notify_msg,$details),2);
980
+				list($subject, $notify_body) = explode("\n", $GLOBALS['egw']->preferences->parse_notify($notify_msg, $details), 2);
981 981
 				// alarm is NOT an iCal method, therefore we have to use extened (no iCal)
982
-				switch($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
982
+				switch ($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format'])
983 983
 				{
984
-					case 'ical':
985
-						if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
984
+					case 'ical' : if (is_null($ics) || $m_type != $msg_type)	// need different ical for organizer notification
986 985
 						{
987 986
 							$calendar_ical = new calendar_ical();
988
-							$calendar_ical->setSupportedFields('full');	// full iCal fields+event TZ
987
+							$calendar_ical->setSupportedFields('full'); // full iCal fields+event TZ
989 988
 							// we need to pass $event[id] so iCal class reads event again,
990 989
 							// as event is in user TZ, but iCal class expects server TZ!
991 990
 							$ics = $calendar_ical->exportVCal(array(isset($cleared_event) ? $cleared_event : $event['id']),
@@ -1004,11 +1003,11 @@  discard block
 block discarded – undo
1004 1003
 					case 'extended':
1005 1004
 
1006 1005
 						$details_body = lang('Event Details follow').":\n";
1007
-						foreach($event_arr as $key => $val)
1006
+						foreach ($event_arr as $key => $val)
1008 1007
 						{
1009
-							if(!empty($details[$key]))
1008
+							if (!empty($details[$key]))
1010 1009
 							{
1011
-								switch($key)
1010
+								switch ($key)
1012 1011
 								{
1013 1012
 							 		case 'access':
1014 1013
 									case 'priority':
@@ -1017,7 +1016,7 @@  discard block
 block discarded – undo
1017 1016
 									case 'title':
1018 1017
 										break;
1019 1018
 									default:
1020
-										$details_body .= sprintf("%-20s %s\n",$val['field'].':',$details[$key]);
1019
+										$details_body .= sprintf("%-20s %s\n", $val['field'].':', $details[$key]);
1021 1020
 										break;
1022 1021
 							 	}
1023 1022
 							}
@@ -1025,7 +1024,7 @@  discard block
 block discarded – undo
1025 1024
 						break;
1026 1025
 				}
1027 1026
 				// send via notification_app
1028
-				if($GLOBALS['egw_info']['apps']['notifications']['enabled'])
1027
+				if ($GLOBALS['egw_info']['apps']['notifications']['enabled'])
1029 1028
 				{
1030 1029
 					try {
1031 1030
 						//error_log(__METHOD__."() notifying $userid from $senderid: $subject");
@@ -1049,9 +1048,9 @@  discard block
 block discarded – undo
1049 1048
 						$notification->set_popupmessage($notify_body."\n\n".$details['description']."\n\n".$details_body);
1050 1049
 						$notification->set_popuplinks(array($details['link_arr']));
1051 1050
 
1052
-						if(is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1051
+						if (is_array($attachment)) { $notification->set_attachments(array($attachment)); }
1053 1052
 						$notification->send();
1054
-						foreach(notifications::errors(true) as $error)
1053
+						foreach (notifications::errors(true) as $error)
1055 1054
 						{
1056 1055
 							error_log(__METHOD__."() Error notifying $userid from $senderid: $subject: $error");
1057 1056
 						}
@@ -1090,14 +1089,14 @@  discard block
 block discarded – undo
1090 1089
 		return true;
1091 1090
 	}
1092 1091
 
1093
-	function get_update_message($event,$added)
1092
+	function get_update_message($event, $added)
1094 1093
 	{
1095 1094
 		$nul = null;
1096
-		$details = $this->_get_event_details($event,$added ? lang('Added') : lang('Modified'),$nul);
1095
+		$details = $this->_get_event_details($event, $added ? lang('Added') : lang('Modified'), $nul);
1097 1096
 
1098 1097
 		$notify_msg = $this->cal_prefs[$added || empty($this->cal_prefs['notifyModified']) ? 'notifyAdded' : 'notifyModified'];
1099 1098
 
1100
-		return explode("\n",$GLOBALS['egw']->preferences->parse_notify($notify_msg,$details),2);
1099
+		return explode("\n", $GLOBALS['egw']->preferences->parse_notify($notify_msg, $details), 2);
1101 1100
 	}
1102 1101
 
1103 1102
 	/**
@@ -1111,37 +1110,37 @@  discard block
 block discarded – undo
1111 1110
 		//echo "<p>bocalendar::send_alarm("; print_r($alarm); echo ")</p>\n";
1112 1111
 		$GLOBALS['egw_info']['user']['account_id'] = $this->owner = $alarm['owner'];
1113 1112
 
1114
-		$event_time_user = Api\DateTime::server2user($alarm['time'] + $alarm['offset']);	// alarm[time] is in server-time, read requires user-time
1115
-		if (!$alarm['owner'] || !$alarm['cal_id'] || !($event = $this->read($alarm['cal_id'],$event_time_user)))
1113
+		$event_time_user = Api\DateTime::server2user($alarm['time'] + $alarm['offset']); // alarm[time] is in server-time, read requires user-time
1114
+		if (!$alarm['owner'] || !$alarm['cal_id'] || !($event = $this->read($alarm['cal_id'], $event_time_user)))
1116 1115
 		{
1117
-			return False;	// event not found
1116
+			return False; // event not found
1118 1117
 		}
1119 1118
 		if ($alarm['all'])
1120 1119
 		{
1121 1120
 			$to_notify = $event['participants'];
1122 1121
 		}
1123
-		elseif ($this->check_perms(Acl::READ,$event))	// checks agains $this->owner set to $alarm[owner]
1122
+		elseif ($this->check_perms(Acl::READ, $event))	// checks agains $this->owner set to $alarm[owner]
1124 1123
 		{
1125 1124
 			$to_notify[$alarm['owner']] = 'A';
1126 1125
 		}
1127 1126
 		else
1128 1127
 		{
1129
-			return False;	// no rights
1128
+			return False; // no rights
1130 1129
 		}
1131 1130
 		// need to load calendar translations and set currentapp, so calendar can reload a different lang
1132 1131
 		Api\Translation::add_app('calendar');
1133 1132
 		$GLOBALS['egw_info']['flags']['currentapp'] = 'calendar';
1134 1133
 
1135
-		$ret = $this->send_update(MSG_ALARM,$to_notify,$event,False,$alarm['owner']);
1134
+		$ret = $this->send_update(MSG_ALARM, $to_notify, $event, False, $alarm['owner']);
1136 1135
 
1137 1136
 		// create a new alarm for recuring events for the next event, if one exists
1138
-		if ($event['recur_type'] != MCAL_RECUR_NONE && ($event = $this->read($alarm['cal_id'],$event_time_user+1)))
1137
+		if ($event['recur_type'] != MCAL_RECUR_NONE && ($event = $this->read($alarm['cal_id'], $event_time_user + 1)))
1139 1138
 		{
1140 1139
 			$alarm['time'] = $this->date2ts($event['start']) - $alarm['offset'];
1141 1140
 			unset($alarm['times']);
1142 1141
 			unset($alarm['next']);
1143 1142
 			//error_log(__METHOD__."() moving alarm to next recurrence ".array2string($alarm));
1144
-			$this->save_alarm($alarm['cal_id'], $alarm, false);	// false = do NOT update timestamp, as nothing changed for iCal clients
1143
+			$this->save_alarm($alarm['cal_id'], $alarm, false); // false = do NOT update timestamp, as nothing changed for iCal clients
1145 1144
 		}
1146 1145
 		return $ret;
1147 1146
 	}
@@ -1157,14 +1156,14 @@  discard block
 block discarded – undo
1157 1156
 	 * Please note: you should ALLWAYS update timestamps, as they are required for sync!
1158 1157
 	 * @return int|boolean $cal_id > 0 or false on error (eg. permission denied)
1159 1158
 	 */
1160
-	function save($event,$ignore_acl=false,$updateTS=true)
1159
+	function save($event, $ignore_acl = false, $updateTS = true)
1161 1160
 	{
1162 1161
 		//error_log(__METHOD__.'('.array2string($event).", $ignore_acl, $updateTS)");
1163 1162
 
1164 1163
 		// check if user has the permission to update / create the event
1165
-		if (!$ignore_acl && ($event['id'] && !$this->check_perms(Acl::EDIT,$event['id']) ||
1166
-			!$event['id'] && !$this->check_perms(Acl::EDIT,0,$event['owner']) &&
1167
-			!$this->check_perms(Acl::ADD,0,$event['owner'])))
1164
+		if (!$ignore_acl && ($event['id'] && !$this->check_perms(Acl::EDIT, $event['id']) ||
1165
+			!$event['id'] && !$this->check_perms(Acl::EDIT, 0, $event['owner']) &&
1166
+			!$this->check_perms(Acl::ADD, 0, $event['owner'])))
1168 1167
 		{
1169 1168
 			return false;
1170 1169
 		}
@@ -1185,7 +1184,7 @@  discard block
 block discarded – undo
1185 1184
 		if ($event['recur_type'] != MCAL_RECUR_NONE && $event['recur_enddate'] && $event['start'])
1186 1185
 		{
1187 1186
 			$event['recur_enddate'] = new Api\DateTime($event['recur_enddate'], calendar_timezones::DateTimeZone($event['tzid']));
1188
-			$event['recur_enddate']->setTime(23,59,59);
1187
+			$event['recur_enddate']->setTime(23, 59, 59);
1189 1188
 			$rrule = calendar_rrule::event2rrule($event, true, Api\DateTime::$user_timezone->getName());
1190 1189
 			$rrule->rewind();
1191 1190
 			$enddate = $rrule->current();
@@ -1244,19 +1243,19 @@  discard block
 block discarded – undo
1244 1243
 
1245 1244
 				$event['recur_enddate'] = $save_event['recur_enddate'] = $time;
1246 1245
 			}
1247
-			$timestamps = array('modified','created');
1246
+			$timestamps = array('modified', 'created');
1248 1247
 			// all-day events are handled in server time
1249 1248
 		//	$event['tzid'] = $save_event['tzid'] = Api\DateTime::$server_timezone->getName();
1250 1249
 		}
1251 1250
 		else
1252 1251
 		{
1253
-			$timestamps = array('start','end','modified','created','recur_enddate','recurrence');
1252
+			$timestamps = array('start', 'end', 'modified', 'created', 'recur_enddate', 'recurrence');
1254 1253
 		}
1255 1254
 		// we run all dates through date2ts, to adjust to server-time and the possible date-formats
1256
-		foreach($timestamps as $ts)
1255
+		foreach ($timestamps as $ts)
1257 1256
 		{
1258 1257
 			// we convert here from user-time to timestamps in server-time!
1259
-			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0;
1258
+			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts], true) : 0;
1260 1259
 		}
1261 1260
 		// convert tzid name to integer tz_id, of set user default
1262 1261
 		if (empty($event['tzid']) || !($event['tz_id'] = calendar_timezones::tz2id($event['tzid'])))
@@ -1266,7 +1265,7 @@  discard block
 block discarded – undo
1266 1265
 		// same with the recur exceptions
1267 1266
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
1268 1267
 		{
1269
-			foreach($event['recur_exception'] as &$date)
1268
+			foreach ($event['recur_exception'] as &$date)
1270 1269
 			{
1271 1270
 				if ($event['whole_day'])
1272 1271
 				{
@@ -1275,7 +1274,7 @@  discard block
 block discarded – undo
1275 1274
 				}
1276 1275
 				else
1277 1276
 				{
1278
-					$date = $this->date2ts($date,true);
1277
+					$date = $this->date2ts($date, true);
1279 1278
 				}
1280 1279
 			}
1281 1280
 			unset($date);
@@ -1283,7 +1282,7 @@  discard block
 block discarded – undo
1283 1282
 		// same with the alarms
1284 1283
 		if (isset($event['alarm']) && is_array($event['alarm']) && isset($event['start']))
1285 1284
 		{
1286
-			foreach($event['alarm'] as $id => &$alarm)
1285
+			foreach ($event['alarm'] as $id => &$alarm)
1287 1286
 			{
1288 1287
 				// remove alarms belonging to not longer existing or rejected participants
1289 1288
 				if ($alarm['owner'] && isset($event['participants']))
@@ -1301,15 +1300,14 @@  discard block
 block discarded – undo
1301 1300
 		// update all existing alarm times, in case alarm got moved and alarms are not include in $event
1302 1301
 		if ($old_event && is_array($old_event['alarm']) && isset($event['start']))
1303 1302
 		{
1304
-			foreach($old_event['alarm'] as $id => &$alarm)
1303
+			foreach ($old_event['alarm'] as $id => &$alarm)
1305 1304
 			{
1306 1305
 				if (!isset($event['alarm'][$id]))
1307 1306
 				{
1308 1307
 					$alarm['time'] = $event['start'] - $alarm['offset'];
1309 1308
 					if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
1310 1309
 						// remove (not store) alarms belonging to not longer existing or rejected participants
1311
-					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] :
1312
-						$old_event['participants'][$alarm['owner']];
1310
+					$status = isset($event['participants']) ? $event['participants'][$alarm['owner']] : $old_event['participants'][$alarm['owner']];
1313 1311
 					if (!$alarm['owner'] || isset($status) && calendar_so::split_status($status) !== 'R')
1314 1312
 					{
1315 1313
 						$this->so->save_alarm($event['id'], $alarm);
@@ -1338,7 +1336,7 @@  discard block
 block discarded – undo
1338 1336
 		}
1339 1337
 		$set_recurrences = $old_event ? abs($event['recur_enddate'] - $old_event['recur_enddate']) > 1 : false;
1340 1338
 		$set_recurrences_start = 0;
1341
-		if (($cal_id = $this->so->save($event,$set_recurrences,$set_recurrences_start,0,$event['etag'])) && $set_recurrences && $event['recur_type'] != MCAL_RECUR_NONE)
1339
+		if (($cal_id = $this->so->save($event, $set_recurrences, $set_recurrences_start, 0, $event['etag'])) && $set_recurrences && $event['recur_type'] != MCAL_RECUR_NONE)
1342 1340
 		{
1343 1341
 			$save_event['id'] = $cal_id;
1344 1342
 			// unset participants to enforce the default stati for all added recurrences
@@ -1349,7 +1347,7 @@  discard block
 block discarded – undo
1349 1347
 		// create links for new participants from addressbook, if configured
1350 1348
 		if ($cal_id && $GLOBALS['egw_info']['server']['link_contacts'] && $event['participants'])
1351 1349
 		{
1352
-			foreach($event['participants'] as $uid => $status)
1350
+			foreach ($event['participants'] as $uid => $status)
1353 1351
 			{
1354 1352
 				$user_type = $user_id = null;
1355 1353
 				calendar_so::split_user($uid, $user_type, $user_id);
@@ -1362,7 +1360,7 @@  discard block
 block discarded – undo
1362 1360
 
1363 1361
 		// Update history
1364 1362
 		$tracking = new calendar_tracking($this);
1365
-		if (empty($event['id']) && !empty($cal_id)) $event['id']=$cal_id;
1363
+		if (empty($event['id']) && !empty($cal_id)) $event['id'] = $cal_id;
1366 1364
 		$tracking->track($event, $old_event);
1367 1365
 
1368 1366
 		return $cal_id;
@@ -1377,16 +1375,16 @@  discard block
 block discarded – undo
1377 1375
 	 * @param array|int $event event array or id of the event
1378 1376
 	 * @return boolean
1379 1377
 	 */
1380
-	function check_status_perms($uid,$event)
1378
+	function check_status_perms($uid, $event)
1381 1379
 	{
1382 1380
 		if ($uid[0] == 'c' || $uid[0] == 'e')	// for contact we use the owner of the event
1383 1381
 		{
1384 1382
 			if (!is_array($event) && !($event = $this->read($event))) return false;
1385 1383
 
1386
-			return $this->check_perms(Acl::EDIT,0,$event['owner']);
1384
+			return $this->check_perms(Acl::EDIT, 0, $event['owner']);
1387 1385
 		}
1388 1386
 		// check if we have a category Acl for the event or not (null)
1389
-		$access = $this->check_cat_acl(self::CAT_ACL_STATUS,$event);
1387
+		$access = $this->check_cat_acl(self::CAT_ACL_STATUS, $event);
1390 1388
 		if (!is_null($access))
1391 1389
 		{
1392 1390
 			return $access;
@@ -1396,17 +1394,17 @@  discard block
 block discarded – undo
1396 1394
 		{
1397 1395
 			$resource = $this->resource_info($uid);
1398 1396
 
1399
-			return Acl::EDIT & $resource['rights'];
1397
+			return Acl::EDIT&$resource['rights'];
1400 1398
 		}
1401 1399
 		if (!is_array($event) && !($event = $this->read($event))) return false;
1402 1400
 
1403 1401
 		// regular user and groups (need to check memberships too)
1404 1402
 		if (!isset($event['participants'][$uid]))
1405 1403
 		{
1406
-			$memberships = $GLOBALS['egw']->accounts->memberships($uid,true);
1404
+			$memberships = $GLOBALS['egw']->accounts->memberships($uid, true);
1407 1405
 		}
1408 1406
 		$memberships[] = $uid;
1409
-		return array_intersect($memberships, array_keys($event['participants'])) && $this->check_perms(Acl::EDIT,0,$uid);
1407
+		return array_intersect($memberships, array_keys($event['participants'])) && $this->check_perms(Acl::EDIT, 0, $uid);
1410 1408
 	}
1411 1409
 
1412 1410
 	/**
@@ -1420,16 +1418,16 @@  discard block
 block discarded – undo
1420 1418
 	 * @return boolean false=access denied because of cat acl, true access granted because of cat acl,
1421 1419
 	 * 	null = cat has no acl
1422 1420
 	 */
1423
-	function check_cat_acl($right,$event)
1421
+	function check_cat_acl($right, $event)
1424 1422
 	{
1425 1423
 		if (!is_array($event)) $event = $this->read($event);
1426 1424
 
1427 1425
 		$ret = null;
1428 1426
 		if ($event['category'])
1429 1427
 		{
1430
-			foreach(is_array($event['category']) ? $event['category'] : explode(',',$event['category']) as $cat_id)
1428
+			foreach (is_array($event['category']) ? $event['category'] : explode(',', $event['category']) as $cat_id)
1431 1429
 			{
1432
-				$access = self::has_cat_right($right,$cat_id,$this->user);
1430
+				$access = self::has_cat_right($right, $cat_id, $this->user);
1433 1431
 				if ($access === true)
1434 1432
 				{
1435 1433
 					$ret = true;
@@ -1437,7 +1435,7 @@  discard block
 block discarded – undo
1437 1435
 				}
1438 1436
 				if ($access === false)
1439 1437
 				{
1440
-					$ret = false;	// cat denies access --> check further cats
1438
+					$ret = false; // cat denies access --> check further cats
1441 1439
 				}
1442 1440
 			}
1443 1441
 		}
@@ -1458,12 +1456,12 @@  discard block
 block discarded – undo
1458 1456
 	 * @param int $cat_id =null null to return array with all cats
1459 1457
 	 * @return array with account_id => right pairs
1460 1458
 	 */
1461
-	public static function get_cat_rights($cat_id=null)
1459
+	public static function get_cat_rights($cat_id = null)
1462 1460
 	{
1463 1461
 		if (!isset(self::$cat_rights_cache))
1464 1462
 		{
1465
-			self::$cat_rights_cache = Api\Cache::getSession('calendar','cat_rights',
1466
-				array($GLOBALS['egw']->acl,'get_location_grants'),array('L%','calendar'));
1463
+			self::$cat_rights_cache = Api\Cache::getSession('calendar', 'cat_rights',
1464
+				array($GLOBALS['egw']->acl, 'get_location_grants'), array('L%', 'calendar'));
1467 1465
 		}
1468 1466
 		//echo "<p>".__METHOD__."($cat_id) = ".array2string($cat_id ? self::$cat_rights_cache['L'.$cat_id] : self::$cat_rights_cache)."</p>\n";
1469 1467
 		return $cat_id ? self::$cat_rights_cache['L'.$cat_id] : self::$cat_rights_cache;
@@ -1476,7 +1474,7 @@  discard block
 block discarded – undo
1476 1474
 	 * @param int $user
1477 1475
 	 * @param int $rights self::CAT_ACL_{ADD|STATUS} or'ed together
1478 1476
 	 */
1479
-	public static function set_cat_rights($cat_id,$user,$rights)
1477
+	public static function set_cat_rights($cat_id, $user, $rights)
1480 1478
 	{
1481 1479
 		//echo "<p>".__METHOD__."($cat_id,$user,$rights)</p>\n";
1482 1480
 		if (!isset(self::$cat_rights_cache)) self::get_cat_rights($cat_id);
@@ -1486,15 +1484,15 @@  discard block
 block discarded – undo
1486 1484
 			if ($rights)
1487 1485
 			{
1488 1486
 				self::$cat_rights_cache['L'.$cat_id][$user] = $rights;
1489
-				$GLOBALS['egw']->acl->add_repository('calendar','L'.$cat_id,$user,$rights);
1487
+				$GLOBALS['egw']->acl->add_repository('calendar', 'L'.$cat_id, $user, $rights);
1490 1488
 			}
1491 1489
 			else
1492 1490
 			{
1493 1491
 				unset(self::$cat_rights_cache['L'.$cat_id][$user]);
1494 1492
 				if (!self::$cat_rights_cache['L'.$cat_id]) unset(self::$cat_rights_cache['L'.$cat_id]);
1495
-				$GLOBALS['egw']->acl->delete_repository('calendar','L'.$cat_id,$user);
1493
+				$GLOBALS['egw']->acl->delete_repository('calendar', 'L'.$cat_id, $user);
1496 1494
 			}
1497
-			Api\Cache::setSession('calendar','cat_rights',self::$cat_rights_cache);
1495
+			Api\Cache::setSession('calendar', 'cat_rights', self::$cat_rights_cache);
1498 1496
 		}
1499 1497
 	}
1500 1498
 
@@ -1505,9 +1503,9 @@  discard block
 block discarded – undo
1505 1503
 	 * @return boolean false=access denied because of cat acl, true access granted because of cat acl,
1506 1504
 	 * 	null = cat has no acl
1507 1505
 	 */
1508
-	public static function has_cat_right($right,$cat_id,$user)
1506
+	public static function has_cat_right($right, $cat_id, $user)
1509 1507
 	{
1510
-		static $cache=null;
1508
+		static $cache = null;
1511 1509
 
1512 1510
 		if (!isset($cache[$cat_id]))
1513 1511
 		{
@@ -1515,21 +1513,21 @@  discard block
 block discarded – undo
1515 1513
 			$cat_rights = self::get_cat_rights($cat_id);
1516 1514
 			if (!is_null($cat_rights))
1517 1515
 			{
1518
-				static $memberships=null;
1516
+				static $memberships = null;
1519 1517
 				if (is_null($memberships))
1520 1518
 				{
1521
-					$memberships = $GLOBALS['egw']->accounts->memberships($user,true);
1519
+					$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1522 1520
 					$memberships[] = $user;
1523 1521
 				}
1524
-				foreach($cat_rights as $uid => $value)
1522
+				foreach ($cat_rights as $uid => $value)
1525 1523
 				{
1526 1524
 					$all |= $value;
1527
-					if (in_array($uid,$memberships)) $own |= $value;
1525
+					if (in_array($uid, $memberships)) $own |= $value;
1528 1526
 				}
1529 1527
 			}
1530
-			foreach(array(self::CAT_ACL_ADD,self::CAT_ACL_STATUS) as $mask)
1528
+			foreach (array(self::CAT_ACL_ADD, self::CAT_ACL_STATUS) as $mask)
1531 1529
 			{
1532
-				$cache[$cat_id][$mask] = !($all & $mask) ? null : !!($own & $mask);
1530
+				$cache[$cat_id][$mask] = !($all&$mask) ? null : !!($own&$mask);
1533 1531
 			}
1534 1532
 		}
1535 1533
 		//echo "<p>".__METHOD__."($right,$cat_id) all=$all, own=$own returning ".array2string($cache[$cat_id][$right])."</p>\n";
@@ -1549,13 +1547,13 @@  discard block
 block discarded – undo
1549 1547
 	 * @param boolean $skip_notification =false true: do not send notification messages
1550 1548
 	 * @return int number of changed recurrences
1551 1549
 	 */
1552
-	function set_status($event,$uid,$status,$recur_date=0,$ignore_acl=false,$updateTS=true,$skip_notification=false)
1550
+	function set_status($event, $uid, $status, $recur_date = 0, $ignore_acl = false, $updateTS = true, $skip_notification = false)
1553 1551
 	{
1554 1552
 		unset($updateTS);
1555 1553
 
1556 1554
 		$cal_id = is_array($event) ? $event['id'] : $event;
1557 1555
 		//echo "<p>calendar_boupdate::set_status($cal_id,$uid,$status,$recur_date)</p>\n";
1558
-		if (!$cal_id || (!$ignore_acl && !$this->check_status_perms($uid,$event)))
1556
+		if (!$cal_id || (!$ignore_acl && !$this->check_status_perms($uid, $event)))
1559 1557
 		{
1560 1558
 			return false;
1561 1559
 		}
@@ -1564,16 +1562,16 @@  discard block
 block discarded – undo
1564 1562
 		if ($this->log)
1565 1563
 		{
1566 1564
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1567
-				"($cal_id, $uid, $status, $recur_date)\n",3,$this->logfile);
1565
+				"($cal_id, $uid, $status, $recur_date)\n", 3, $this->logfile);
1568 1566
 		}
1569 1567
 		$old_event = $this->read($cal_id, $recur_date, $ignore_acl, 'server');
1570
-		if (($Ok = $this->so->set_status($cal_id,is_numeric($uid)?'u':$uid[0],
1571
-				is_numeric($uid)?$uid:substr($uid,1),$status,
1572
-				$recur_date?$this->date2ts($recur_date,true):0,$role)))
1568
+		if (($Ok = $this->so->set_status($cal_id, is_numeric($uid) ? 'u' : $uid[0],
1569
+				is_numeric($uid) ? $uid : substr($uid, 1), $status,
1570
+				$recur_date ? $this->date2ts($recur_date, true) : 0, $role)))
1573 1571
 		{
1574 1572
 			if ($status == 'R')	// remove alarms belonging to rejected participants
1575 1573
 			{
1576
-				foreach(is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1574
+				foreach (is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm)
1577 1575
 				{
1578 1576
 					if ((string)$alarm['owner'] === (string)$uid)
1579 1577
 					{
@@ -1592,8 +1590,8 @@  discard block
 block discarded – undo
1592 1590
 			if (isset($status2msg[$status]) && !$skip_notification)
1593 1591
 			{
1594 1592
 				if (!is_array($event)) $event = $this->read($cal_id);
1595
-				if (isset($recur_date)) $event = $this->read($event['id'],$recur_date); //re-read the actually edited recurring event
1596
-				$this->send_update($status2msg[$status],$event['participants'],$event);
1593
+				if (isset($recur_date)) $event = $this->read($event['id'], $recur_date); //re-read the actually edited recurring event
1594
+				$this->send_update($status2msg[$status], $event['participants'], $event);
1597 1595
 			}
1598 1596
 
1599 1597
 			// Update history
@@ -1613,14 +1611,14 @@  discard block
 block discarded – undo
1613 1611
 	 * @param int $recur_date =0 date to change, or 0 = all since now
1614 1612
 	 * @param boolean $skip_notification Do not send notifications.  Parameter passed on to set_status().
1615 1613
 	 */
1616
-	function update_status($new_event, $old_event , $recur_date=0, $skip_notification=false)
1614
+	function update_status($new_event, $old_event, $recur_date = 0, $skip_notification = false)
1617 1615
 	{
1618 1616
 		if (!isset($new_event['participants'])) return;
1619 1617
 
1620 1618
 		// check the old list against the new list
1621 1619
 		foreach ($old_event['participants'] as $userid => $status)
1622 1620
   		{
1623
-            if (!isset($new_event['participants'][$userid])){
1621
+            if (!isset($new_event['participants'][$userid])) {
1624 1622
             	// Attendee will be deleted this way
1625 1623
             	$new_event['participants'][$userid] = 'G';
1626 1624
             }
@@ -1633,7 +1631,7 @@  discard block
 block discarded – undo
1633 1631
 		// write the changes
1634 1632
 		foreach ($new_event['participants'] as $userid => $status)
1635 1633
 		{
1636
-			$this->set_status($old_event, $userid, $status, $recur_date, true, false,$skip_notification);
1634
+			$this->set_status($old_event, $userid, $status, $recur_date, true, false, $skip_notification);
1637 1635
 		}
1638 1636
     }
1639 1637
 
@@ -1648,43 +1646,43 @@  discard block
 block discarded – undo
1648 1646
 	 * @param int &$exceptions_kept=null on return number of kept exceptions
1649 1647
 	 * @return boolean true on success, false on error (usually permission denied)
1650 1648
 	 */
1651
-	function delete($cal_id, $recur_date=0, $ignore_acl=false, $skip_notification=false,
1652
-		$delete_exceptions=true, &$exceptions_kept=null)
1649
+	function delete($cal_id, $recur_date = 0, $ignore_acl = false, $skip_notification = false,
1650
+		$delete_exceptions = true, &$exceptions_kept = null)
1653 1651
 	{
1654 1652
 		//error_log(__METHOD__."(cal_id=$cal_id, recur_date=$recur_date, ignore_acl=$ignore_acl, skip_notifications=$skip_notification)");
1655
-		if (!($event = $this->read($cal_id,$recur_date)) ||
1656
-			!$ignore_acl && !$this->check_perms(Acl::DELETE,$event))
1653
+		if (!($event = $this->read($cal_id, $recur_date)) ||
1654
+			!$ignore_acl && !$this->check_perms(Acl::DELETE, $event))
1657 1655
 		{
1658 1656
 			return false;
1659 1657
 		}
1660 1658
 
1661 1659
 		// Don't send notification if the event has already been deleted
1662
-		if(!$event['deleted'] && !$skip_notification)
1660
+		if (!$event['deleted'] && !$skip_notification)
1663 1661
 		{
1664
-			$this->send_update(MSG_DELETED,$event['participants'],$event);
1662
+			$this->send_update(MSG_DELETED, $event['participants'], $event);
1665 1663
 		}
1666 1664
 
1667 1665
 		if (!$recur_date || $event['recur_type'] == MCAL_RECUR_NONE)
1668 1666
 		{
1669 1667
 			$config = Api\Config::read('phpgwapi');
1670
-			if(!$config['calendar_delete_history'] || $event['deleted'])
1668
+			if (!$config['calendar_delete_history'] || $event['deleted'])
1671 1669
 			{
1672 1670
 				$this->so->delete($cal_id);
1673 1671
 
1674 1672
 				// delete all links to the event
1675
-				Link::unlink(0,'calendar',$cal_id);
1673
+				Link::unlink(0, 'calendar', $cal_id);
1676 1674
 			}
1677 1675
 			elseif ($config['calendar_delete_history'])
1678 1676
 			{
1679 1677
 				// mark all links to the event as deleted, but keep them
1680
-				Link::unlink(0,'calendar',$cal_id,'','','',true);
1678
+				Link::unlink(0, 'calendar', $cal_id, '', '', '', true);
1681 1679
 
1682 1680
 				$event['deleted'] = $this->now;
1683 1681
 				$this->save($event, $ignore_acl);
1684 1682
 				// Actually delete alarms
1685 1683
 				if (isset($event['alarm']) && is_array($event['alarm']))
1686 1684
 				{
1687
-					foreach($event['alarm'] as $id => $alarm)
1685
+					foreach ($event['alarm'] as $id => $alarm)
1688 1686
 					{
1689 1687
 						$this->delete_alarm($id);
1690 1688
 					}
@@ -1706,7 +1704,7 @@  discard block
 block discarded – undo
1706 1704
 						if (!($exception = $this->read($id))) continue;
1707 1705
 						$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
1708 1706
 						$exception['reference'] = $exception['recurrence'] = 0;
1709
-						$this->update($exception, true, true, false, true, $msg=null, true);
1707
+						$this->update($exception, true, true, false, true, $msg = null, true);
1710 1708
 						++$exceptions_kept;
1711 1709
 					}
1712 1710
 				}
@@ -1718,9 +1716,9 @@  discard block
 block discarded – undo
1718 1716
 			if ($event['alarm'])
1719 1717
 			{
1720 1718
 				$next_recurrance = null;
1721
-				foreach($event['alarm'] as &$alarm)
1719
+				foreach ($event['alarm'] as &$alarm)
1722 1720
 				{
1723
-					if (($alarm['time'] == $recur_date) || ($alarm['time']+$alarm['offset'] == $recur_date))
1721
+					if (($alarm['time'] == $recur_date) || ($alarm['time'] + $alarm['offset'] == $recur_date))
1724 1722
 					{
1725 1723
 						//error_log(__METHOD__.__LINE__.'->'.array2string($recur_date));
1726 1724
 						//error_log(__METHOD__.__LINE__.array2string($event));
@@ -1728,12 +1726,12 @@  discard block
 block discarded – undo
1728 1726
 						{
1729 1727
 							$checkdate = $recur_date;
1730 1728
 							//if ($alarm['time']+$alarm['offset'] == $recur_date) $checkdate = $recur_date + $alarm['offset'];
1731
-							if (($e = $this->read($cal_id,$checkdate+1)))
1729
+							if (($e = $this->read($cal_id, $checkdate + 1)))
1732 1730
 							{
1733 1731
 								$next_recurrance = $this->date2ts($e['start']);
1734 1732
 							}
1735 1733
 						}
1736
-						$alarm['time'] = $this->date2ts($next_recurrance, true);	// user to server-time
1734
+						$alarm['time'] = $this->date2ts($next_recurrance, true); // user to server-time
1737 1735
 						$alarm['cal_id'] = $cal_id;
1738 1736
 						unset($alarm['times']);
1739 1737
 						unset($alarm['next']);
@@ -1747,7 +1745,7 @@  discard block
 block discarded – undo
1747 1745
 			$event = $this->read($cal_id);
1748 1746
 			//if (isset($alarmbuffer)) $event['alarm'] = $alarmbuffer;
1749 1747
 			$event['recur_exception'][] = $recur_date;
1750
-			$this->save($event);// updates the content-history
1748
+			$this->save($event); // updates the content-history
1751 1749
 		}
1752 1750
 		if ($event['reference'])
1753 1751
 		{
@@ -1765,19 +1763,19 @@  discard block
 block discarded – undo
1765 1763
 	 * @param array $disinvited
1766 1764
 	 * @return array
1767 1765
 	 */
1768
-	function _get_event_details($event,$action,&$event_arr,$disinvited=array())
1766
+	function _get_event_details($event, $action, &$event_arr, $disinvited = array())
1769 1767
 	{
1770 1768
 		$details = array(			// event-details for the notify-msg
1771 1769
 			'id'          => $event['id'],
1772 1770
 			'action'      => lang($action),
1773 1771
 		);
1774 1772
 		$event_arr = $this->event2array($event);
1775
-		foreach($event_arr as $key => $val)
1773
+		foreach ($event_arr as $key => $val)
1776 1774
 		{
1777 1775
 			if ($key == 'recur_type') $key = 'repetition';
1778 1776
 			$details[$key] = $val['data'];
1779 1777
 		}
1780
-		$details['participants'] = $details['participants'] ? implode("\n",$details['participants']) : '';
1778
+		$details['participants'] = $details['participants'] ? implode("\n", $details['participants']) : '';
1781 1779
 
1782 1780
 		$event_arr['link']['field'] = lang('URL');
1783 1781
 		$eventStart_arr = $this->date2array($event['start']); // give this as 'date' to the link to pick the right recurrence for the participants state
@@ -1798,7 +1796,7 @@  discard block
 block discarded – undo
1798 1796
 		 */
1799 1797
 		$link_arr = array();
1800 1798
 		$link_arr['text'] = $event['title'];
1801
-		$link_arr['view'] = array(	'menuaction' => 'calendar.calendar_uiforms.edit',
1799
+		$link_arr['view'] = array('menuaction' => 'calendar.calendar_uiforms.edit',
1802 1800
 									'cal_id' => $event['id'],
1803 1801
 									'date' => $eventStart_arr['full'],
1804 1802
 									'ajax' => true
@@ -1807,11 +1805,11 @@  discard block
 block discarded – undo
1807 1805
 		$details['link_arr'] = $link_arr;
1808 1806
 
1809 1807
 		$dis = array();
1810
-		foreach($disinvited as $uid)
1808
+		foreach ($disinvited as $uid)
1811 1809
 		{
1812 1810
 			$dis[] = $this->participant_name($uid);
1813 1811
 		}
1814
-		$details['disinvited'] = implode(', ',$dis);
1812
+		$details['disinvited'] = implode(', ', $dis);
1815 1813
 		return $details;
1816 1814
 	}
1817 1815
 
@@ -1835,13 +1833,13 @@  discard block
 block discarded – undo
1835 1833
 			'data'	=> $event['description']
1836 1834
 		);
1837 1835
 
1838
-		foreach(explode(',',$event['category']) as $cat_id)
1836
+		foreach (explode(',', $event['category']) as $cat_id)
1839 1837
 		{
1840 1838
 			$cat_string[] = stripslashes(Api\Categories::id2name($cat_id));
1841 1839
 		}
1842 1840
 		$var['category'] = Array(
1843 1841
 			'field'	=> lang('Category'),
1844
-			'data'	=> implode(', ',$cat_string)
1842
+			'data'	=> implode(', ', $cat_string)
1845 1843
 		);
1846 1844
 
1847 1845
 		$var['location'] = Array(
@@ -1887,7 +1885,7 @@  discard block
 block discarded – undo
1887 1885
 
1888 1886
 		if (isset($event['participants']) && is_array($event['participants']) && !empty($event['participants']))
1889 1887
 		{
1890
-			$participants = $this->participants($event,true);
1888
+			$participants = $this->participants($event, true);
1891 1889
 		}
1892 1890
 		$var['participants'] = Array(
1893 1891
 			'field'	=> lang('Participants'),
@@ -1910,26 +1908,26 @@  discard block
 block discarded – undo
1910 1908
 	 * @param array $old_event =null event-data in the DB before calling save
1911 1909
 	 * @param string $type ='update'
1912 1910
 	 */
1913
-	function log2file($event2save,$event_saved,$old_event=null,$type='update')
1911
+	function log2file($event2save, $event_saved, $old_event = null, $type = 'update')
1914 1912
 	{
1915
-		if (!($f = fopen($this->log_file,'a')))
1913
+		if (!($f = fopen($this->log_file, 'a')))
1916 1914
 		{
1917 1915
 			echo "<p>error opening '$this->log_file' !!!</p>\n";
1918 1916
 			return false;
1919 1917
 		}
1920
-		fwrite($f,$type.': '.Api\Accounts::username($this->user).': '.date('r')."\n");
1921
-		fwrite($f,"Time: time to save / saved time read back / old time before save\n");
1922
-		foreach(array('start','end') as $name)
1918
+		fwrite($f, $type.': '.Api\Accounts::username($this->user).': '.date('r')."\n");
1919
+		fwrite($f, "Time: time to save / saved time read back / old time before save\n");
1920
+		foreach (array('start', 'end') as $name)
1923 1921
 		{
1924
-			fwrite($f,$name.': '.(isset($event2save[$name]) ? $this->format_date($event2save[$name]) : 'not set').' / '.
1925
-				$this->format_date($event_saved[$name]) .' / '.
1922
+			fwrite($f, $name.': '.(isset($event2save[$name]) ? $this->format_date($event2save[$name]) : 'not set').' / '.
1923
+				$this->format_date($event_saved[$name]).' / '.
1926 1924
 				(is_null($old_event) ? 'no old event' : $this->format_date($old_event[$name]))."\n");
1927 1925
 		}
1928
-		foreach(array('event2save','event_saved','old_event') as $name)
1926
+		foreach (array('event2save', 'event_saved', 'old_event') as $name)
1929 1927
 		{
1930
-			fwrite($f,$name.' = '.print_r($$name,true));
1928
+			fwrite($f, $name.' = '.print_r($$name, true));
1931 1929
 		}
1932
-		fwrite($f,"\n");
1930
+		fwrite($f, "\n");
1933 1931
 		fclose($f);
1934 1932
 
1935 1933
 		return true;
@@ -1950,14 +1948,14 @@  discard block
 block discarded – undo
1950 1948
 		if ($old_event !== null && $event['start'] == $old_event['start']) return;
1951 1949
 
1952 1950
 		$time = new Api\DateTime($event['start']);
1953
-		if(!is_array($event['alarm']))
1951
+		if (!is_array($event['alarm']))
1954 1952
 		{
1955 1953
 			$event['alarm'] = $this->so->read_alarms($event['id']);
1956 1954
 		}
1957 1955
 
1958
-		foreach($event['alarm'] as &$alarm)
1956
+		foreach ($event['alarm'] as &$alarm)
1959 1957
 		{
1960
-			if($event['recur_type'] != MCAL_RECUR_NONE && is_object($instance_date))
1958
+			if ($event['recur_type'] != MCAL_RECUR_NONE && is_object($instance_date))
1961 1959
 			{
1962 1960
 				calendar_so::shift_alarm($event, $alarm, $instance_date->format('ts'));
1963 1961
 			}
@@ -1977,14 +1975,14 @@  discard block
 block discarded – undo
1977 1975
 	 * @param boolean $update_modified =true call update modified, default true
1978 1976
 	 * @return string id of the alarm, or false on error (eg. no perms)
1979 1977
 	 */
1980
-	function save_alarm($cal_id, $alarm, $update_modified=true)
1978
+	function save_alarm($cal_id, $alarm, $update_modified = true)
1981 1979
 	{
1982
-		if (!$cal_id || !$this->check_perms(Acl::EDIT,$alarm['all'] ? $cal_id : 0,!$alarm['all'] ? $alarm['owner'] : 0))
1980
+		if (!$cal_id || !$this->check_perms(Acl::EDIT, $alarm['all'] ? $cal_id : 0, !$alarm['all'] ? $alarm['owner'] : 0))
1983 1981
 		{
1984 1982
 			//echo "<p>no rights to save the alarm=".print_r($alarm,true)." to event($cal_id)</p>";
1985
-			return false;	// no rights to add the alarm
1983
+			return false; // no rights to add the alarm
1986 1984
 		}
1987
-		$alarm['time'] = $this->date2ts($alarm['time'],true);	// user to server-time
1985
+		$alarm['time'] = $this->date2ts($alarm['time'], true); // user to server-time
1988 1986
 
1989 1987
 		return $this->so->save_alarm($cal_id, $alarm, $update_modified);
1990 1988
 	}
@@ -1997,11 +1995,11 @@  discard block
 block discarded – undo
1997 1995
 	 */
1998 1996
 	function delete_alarm($id)
1999 1997
 	{
2000
-		list(,$cal_id) = explode(':',$id);
1998
+		list(,$cal_id) = explode(':', $id);
2001 1999
 
2002
-		if (!($alarm = $this->so->read_alarm($id)) || !$cal_id || !$this->check_perms(Acl::EDIT,$alarm['all'] ? $cal_id : 0,!$alarm['all'] ? $alarm['owner'] : 0))
2000
+		if (!($alarm = $this->so->read_alarm($id)) || !$cal_id || !$this->check_perms(Acl::EDIT, $alarm['all'] ? $cal_id : 0, !$alarm['all'] ? $alarm['owner'] : 0))
2003 2001
 		{
2004
-			return false;	// no rights to delete the alarm
2002
+			return false; // no rights to delete the alarm
2005 2003
 		}
2006 2004
 
2007 2005
 		return $this->so->delete_alarm($id);
@@ -2016,13 +2014,13 @@  discard block
 block discarded – undo
2016 2014
 	 *  by the ones the user normally does not see due to category permissions - used to preserve categories
2017 2015
 	 * @return array category ids (found, added and preserved categories)
2018 2016
 	 */
2019
-	function find_or_add_categories($catname_list, $old_event=null)
2017
+	function find_or_add_categories($catname_list, $old_event = null)
2020 2018
 	{
2021 2019
 		if (is_array($old_event) || $old_event > 0)
2022 2020
 		{
2023 2021
 			// preserve categories without users read access
2024 2022
 			if (!is_array($old_event)) $old_event = $this->read($old_event);
2025
-			$old_categories = explode(',',$old_event['category']);
2023
+			$old_categories = explode(',', $old_event['category']);
2026 2024
 			$old_cats_preserve = array();
2027 2025
 			if (is_array($old_categories) && count($old_categories) > 0)
2028 2026
 			{
@@ -2076,7 +2074,7 @@  discard block
 block discarded – undo
2076 2074
 	{
2077 2075
 		if (!is_array($cat_id_list))
2078 2076
 		{
2079
-			$cat_id_list = explode(',',$cat_id_list);
2077
+			$cat_id_list = explode(',', $cat_id_list);
2080 2078
 		}
2081 2079
 		$cat_list = array();
2082 2080
 		foreach ($cat_id_list as $cat_id)
@@ -2101,7 +2099,7 @@  discard block
 block discarded – undo
2101 2099
 	 *                              master	-> try to find a releated series master
2102 2100
 	 * @return array calendar_ids of matching entries
2103 2101
 	 */
2104
-	function find_event($event, $filter='exact')
2102
+	function find_event($event, $filter = 'exact')
2105 2103
 	{
2106 2104
 		$matchingEvents = array();
2107 2105
 		$query = array();
@@ -2109,14 +2107,14 @@  discard block
 block discarded – undo
2109 2107
 		if ($this->log)
2110 2108
 		{
2111 2109
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2112
-				"($filter)[EVENT]:" . array2string($event)."\n",3,$this->logfile);
2110
+				"($filter)[EVENT]:".array2string($event)."\n", 3, $this->logfile);
2113 2111
 		}
2114 2112
 
2115 2113
 		if (!isset($event['recurrence'])) $event['recurrence'] = 0;
2116 2114
 
2117 2115
 		if ($filter == 'master')
2118 2116
 		{
2119
-			$query[] = 'recur_type!='. MCAL_RECUR_NONE;
2117
+			$query[] = 'recur_type!='.MCAL_RECUR_NONE;
2120 2118
 			$query['cal_recurrence'] = 0;
2121 2119
 		}
2122 2120
 		elseif ($filter == 'exact')
@@ -2137,14 +2135,14 @@  discard block
 block discarded – undo
2137 2135
 			if ($this->log)
2138 2136
 			{
2139 2137
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2140
-					'(' . $event['id'] . ")[EventID]\n",3,$this->logfile);
2138
+					'('.$event['id'].")[EventID]\n", 3, $this->logfile);
2141 2139
 			}
2142 2140
 			if (($egwEvent = $this->read($event['id'], 0, false, 'server')))
2143 2141
 			{
2144 2142
 				if ($this->log)
2145 2143
 				{
2146 2144
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2147
-						'()[FOUND]:' . array2string($egwEvent)."\n",3,$this->logfile);
2145
+						'()[FOUND]:'.array2string($egwEvent)."\n", 3, $this->logfile);
2148 2146
 				}
2149 2147
 				if ($egwEvent['recur_type'] != MCAL_RECUR_NONE &&
2150 2148
 					(empty($event['uid']) || $event['uid'] == $egwEvent['uid']))
@@ -2163,7 +2161,7 @@  discard block
 block discarded – undo
2163 2161
 						$exceptions = $this->so->get_recurrence_exceptions($egwEvent, $event['tzid']);
2164 2162
 						if (in_array($event['recurrence'], $exceptions))
2165 2163
 						{
2166
-							$matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['recurrence'];
2164
+							$matchingEvents[] = $egwEvent['id'].':'.(int)$event['recurrence'];
2167 2165
 						}
2168 2166
 					}
2169 2167
 				} elseif ($filter != 'master' && ($filter == 'exact' ||
@@ -2182,19 +2180,19 @@  discard block
 block discarded – undo
2182 2180
 
2183 2181
 		// only query calendars of users, we have READ-grants from
2184 2182
 		$users = array();
2185
-		foreach(array_keys($this->grants) as $user)
2183
+		foreach (array_keys($this->grants) as $user)
2186 2184
 		{
2187 2185
 			$user = trim($user);
2188
-			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY,0,$user))
2186
+			if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY, 0, $user))
2189 2187
 			{
2190
-				if ($user && !in_array($user,$users))	// already added?
2188
+				if ($user && !in_array($user, $users))	// already added?
2191 2189
 				{
2192 2190
 					$users[] = $user;
2193 2191
 				}
2194 2192
 			}
2195 2193
 			elseif ($GLOBALS['egw']->accounts->get_type($user) != 'g')
2196 2194
 			{
2197
-				continue;	// for non-groups (eg. users), we stop here if we have no read-rights
2195
+				continue; // for non-groups (eg. users), we stop here if we have no read-rights
2198 2196
 			}
2199 2197
 			// the further code is only for real users
2200 2198
 			if (!is_numeric($user)) continue;
@@ -2205,7 +2203,7 @@  discard block
 block discarded – undo
2205 2203
 				$members = $GLOBALS['egw']->accounts->members($user, true);
2206 2204
 				if (is_array($members))
2207 2205
 				{
2208
-					foreach($members as $member)
2206
+					foreach ($members as $member)
2209 2207
 					{
2210 2208
 						// use only members which gave the user a read-grant
2211 2209
 						if (!in_array($member, $users) &&
@@ -2221,7 +2219,7 @@  discard block
 block discarded – undo
2221 2219
 				$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
2222 2220
 				if (is_array($memberships))
2223 2221
 				{
2224
-					foreach($memberships as $group)
2222
+					foreach ($memberships as $group)
2225 2223
 					{
2226 2224
 						if (!in_array($group, $users))
2227 2225
 						{
@@ -2247,24 +2245,24 @@  discard block
 block discarded – undo
2247 2245
 
2248 2246
 				// check length with some tolerance
2249 2247
 				$length = $event['end'] - $event['start'] - $delta;
2250
-				$query[] = ('(cal_end-cal_start)>' . $length);
2248
+				$query[] = ('(cal_end-cal_start)>'.$length);
2251 2249
 				$length += 2 * $delta;
2252
-				$query[] = ('(cal_end-cal_start)<' . $length);
2253
-				$query[] = ('cal_start>' . ($event['start'] - 86400));
2254
-				$query[] = ('cal_start<' . ($event['start'] + 86400));
2250
+				$query[] = ('(cal_end-cal_start)<'.$length);
2251
+				$query[] = ('cal_start>'.($event['start'] - 86400));
2252
+				$query[] = ('cal_start<'.($event['start'] + 86400));
2255 2253
 			}
2256 2254
 			elseif (isset($event['start']))
2257 2255
 			{
2258 2256
 				if ($filter == 'relax')
2259 2257
 				{
2260
-					$query[] = ('cal_start>' . ($event['start'] - 3600));
2261
-					$query[] = ('cal_start<' . ($event['start'] + 3600));
2258
+					$query[] = ('cal_start>'.($event['start'] - 3600));
2259
+					$query[] = ('cal_start<'.($event['start'] + 3600));
2262 2260
 				}
2263 2261
 				else
2264 2262
 				{
2265 2263
 					// we accept a tiny tolerance
2266
-					$query[] = ('cal_start>' . ($event['start'] - 2));
2267
-					$query[] = ('cal_start<' . ($event['start'] + 2));
2264
+					$query[] = ('cal_start>'.($event['start'] - 2));
2265
+					$query[] = ('cal_start<'.($event['start'] + 2));
2268 2266
 				}
2269 2267
 			}
2270 2268
 			if ($filter == 'relax')
@@ -2287,14 +2285,14 @@  discard block
 block discarded – undo
2287 2285
 			if ($this->log)
2288 2286
 			{
2289 2287
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2290
-					'(' . $event['uid'] . ")[EventUID]\n",3,$this->logfile);
2288
+					'('.$event['uid'].")[EventUID]\n", 3, $this->logfile);
2291 2289
 			}
2292 2290
 		}
2293 2291
 
2294 2292
 		if ($this->log)
2295 2293
 		{
2296 2294
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2297
-				'[QUERY]: ' . array2string($query)."\n",3,$this->logfile);
2295
+				'[QUERY]: '.array2string($query)."\n", 3, $this->logfile);
2298 2296
 		}
2299 2297
 		if (!count($users) || !($foundEvents =
2300 2298
 			$this->so->search(null, null, $users, 0, 'owner', false, 0, array('query' => $query))))
@@ -2302,19 +2300,19 @@  discard block
 block discarded – undo
2302 2300
 			if ($this->log)
2303 2301
 			{
2304 2302
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2305
-				"[NO MATCH]\n",3,$this->logfile);
2303
+				"[NO MATCH]\n", 3, $this->logfile);
2306 2304
 			}
2307 2305
 			return $matchingEvents;
2308 2306
 		}
2309 2307
 
2310 2308
 		$pseudos = array();
2311 2309
 
2312
-		foreach($foundEvents as $egwEvent)
2310
+		foreach ($foundEvents as $egwEvent)
2313 2311
 		{
2314 2312
 			if ($this->log)
2315 2313
 			{
2316 2314
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2317
-					'[FOUND]: ' . array2string($egwEvent)."\n",3,$this->logfile);
2315
+					'[FOUND]: '.array2string($egwEvent)."\n", 3, $this->logfile);
2318 2316
 			}
2319 2317
 
2320 2318
 			if (in_array($egwEvent['id'], $matchingEvents)) continue;
@@ -2388,7 +2386,7 @@  discard block
 block discarded – undo
2388 2386
 						if (in_array($event['recurrence'], $exceptions))
2389 2387
 						{
2390 2388
 							// We found a pseudo exception
2391
-							$matchingEvents = array($egwEvent['id'] . ':' . (int)$event['recurrence']);
2389
+							$matchingEvents = array($egwEvent['id'].':'.(int)$event['recurrence']);
2392 2390
 							break;
2393 2391
 						}
2394 2392
 					}
@@ -2406,7 +2404,7 @@  discard block
 block discarded – undo
2406 2404
 						if ($this->log)
2407 2405
 						{
2408 2406
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2409
-							"() egwEvent length does not match!\n",3,$this->logfile);
2407
+							"() egwEvent length does not match!\n", 3, $this->logfile);
2410 2408
 						}
2411 2409
 						continue;
2412 2410
 					}
@@ -2418,7 +2416,7 @@  discard block
 block discarded – undo
2418 2416
 						if ($this->log)
2419 2417
 						{
2420 2418
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2421
-							"() egwEvent is not a whole-day event!\n",3,$this->logfile);
2419
+							"() egwEvent is not a whole-day event!\n", 3, $this->logfile);
2422 2420
 						}
2423 2421
 						continue;
2424 2422
 					}
@@ -2439,8 +2437,8 @@  discard block
 block discarded – undo
2439 2437
 					if ($this->log)
2440 2438
 					{
2441 2439
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2442
-							"() event[$key] differ: '" . $event[$key] .
2443
-							"' <> '" . $egwEvent[$key] . "'\n",3,$this->logfile);
2440
+							"() event[$key] differ: '".$event[$key].
2441
+							"' <> '".$egwEvent[$key]."'\n", 3, $this->logfile);
2444 2442
 					}
2445 2443
 					continue 2; // next foundEvent
2446 2444
 				}
@@ -2458,7 +2456,7 @@  discard block
 block discarded – undo
2458 2456
 						if ($this->log)
2459 2457
 						{
2460 2458
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2461
-							"() egwEvent category $cat_id is missing!\n",3,$this->logfile);
2459
+							"() egwEvent category $cat_id is missing!\n", 3, $this->logfile);
2462 2460
 						}
2463 2461
 						continue 2;
2464 2462
 					}
@@ -2470,7 +2468,7 @@  discard block
 block discarded – undo
2470 2468
 					{
2471 2469
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2472 2470
 							'() event has additional categories:'
2473
-							. array2string($newCategories)."\n",3,$this->logfile);
2471
+							. array2string($newCategories)."\n", 3, $this->logfile);
2474 2472
 					}
2475 2473
 					continue;
2476 2474
 				}
@@ -2490,7 +2488,7 @@  discard block
 block discarded – undo
2490 2488
 							if ($this->log)
2491 2489
 							{
2492 2490
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2493
-								"() additional event['participants']: $attendee\n",3,$this->logfile);
2491
+								"() additional event['participants']: $attendee\n", 3, $this->logfile);
2494 2492
 							}
2495 2493
 							continue 2;
2496 2494
 						}
@@ -2513,8 +2511,8 @@  discard block
 block discarded – undo
2513 2511
 						if ($this->log)
2514 2512
 						{
2515 2513
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2516
-								'() missing event[participants]: ' .
2517
-								array2string($egwEvent['participants'])."\n",3,$this->logfile);
2514
+								'() missing event[participants]: '.
2515
+								array2string($egwEvent['participants'])."\n", 3, $this->logfile);
2518 2516
 						}
2519 2517
 						continue;
2520 2518
 					}
@@ -2526,7 +2524,7 @@  discard block
 block discarded – undo
2526 2524
 				if ($egwEvent['recur_type'] != MCAL_RECUR_NONE)
2527 2525
 				{
2528 2526
 					// We found a pseudo Exception
2529
-					$pseudos[] = $egwEvent['id'] . ':' . $event['start'];
2527
+					$pseudos[] = $egwEvent['id'].':'.$event['start'];
2530 2528
 					continue;
2531 2529
 				}
2532 2530
 			}
@@ -2548,7 +2546,7 @@  discard block
 block discarded – undo
2548 2546
 							if ($this->log)
2549 2547
 							{
2550 2548
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2551
-								"() additional event['recur_exception']: $day\n",3,$this->logfile);
2549
+								"() additional event['recur_exception']: $day\n", 3, $this->logfile);
2552 2550
 							}
2553 2551
 							continue 2;
2554 2552
 						}
@@ -2558,8 +2556,8 @@  discard block
 block discarded – undo
2558 2556
 						if ($this->log)
2559 2557
 						{
2560 2558
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2561
-								'() missing event[recur_exception]: ' .
2562
-								array2string($event['recur_exception'])."\n",3,$this->logfile);
2559
+								'() missing event[recur_exception]: '.
2560
+								array2string($event['recur_exception'])."\n", 3, $this->logfile);
2563 2561
 						}
2564 2562
 						continue;
2565 2563
 					}
@@ -2574,8 +2572,8 @@  discard block
 block discarded – undo
2574 2572
 						if ($this->log)
2575 2573
 						{
2576 2574
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2577
-								"() events[$key] differ: " . $event[$key] .
2578
-								' <> ' . $egwEvent[$key]."\n",3,$this->logfile);
2575
+								"() events[$key] differ: ".$event[$key].
2576
+								' <> '.$egwEvent[$key]."\n", 3, $this->logfile);
2579 2577
 						}
2580 2578
 						continue 2;
2581 2579
 					}
@@ -2591,7 +2589,7 @@  discard block
 block discarded – undo
2591 2589
 			if ($this->log)
2592 2590
 			{
2593 2591
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2594
-					"() new exception for series found.\n",3,$this->logfile);
2592
+					"() new exception for series found.\n", 3, $this->logfile);
2595 2593
 			}
2596 2594
 			$matchingEvents = array();
2597 2595
 		}
@@ -2602,7 +2600,7 @@  discard block
 block discarded – undo
2602 2600
 		if ($this->log)
2603 2601
 		{
2604 2602
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2605
-				'[MATCHES]:' . array2string($matches)."\n",3,$this->logfile);
2603
+				'[MATCHES]:'.array2string($matches)."\n", 3, $this->logfile);
2606 2604
 		}
2607 2605
 		return $matches;
2608 2606
 	}
@@ -2675,7 +2673,7 @@  discard block
 block discarded – undo
2675 2673
 				if ($this->log)
2676 2674
 				{
2677 2675
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2678
-					"()[MASTER]: $eventID\n",3,$this->logfile);
2676
+					"()[MASTER]: $eventID\n", 3, $this->logfile);
2679 2677
 				}
2680 2678
 				$type = 'SERIES-EXCEPTION';
2681 2679
 				if (($master_event = $this->read($eventID, 0, false, 'server')))
@@ -2696,7 +2694,7 @@  discard block
 block discarded – undo
2696 2694
 					}
2697 2695
 					elseif (in_array($event['start'], $master_event['recur_exception']))
2698 2696
 					{
2699
-						$type='SERIES-PSEUDO-EXCEPTION'; // new pseudo exception?
2697
+						$type = 'SERIES-PSEUDO-EXCEPTION'; // new pseudo exception?
2700 2698
 						$recurrence_event = $master_event;
2701 2699
 						$recurrence_event['start'] = $event['start'];
2702 2700
 						$recurrence_event['end'] -= $master_event['start'] - $event['start'];
@@ -2713,8 +2711,8 @@  discard block
 block discarded – undo
2713 2711
 							if ($this->log)
2714 2712
 							{
2715 2713
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2716
-									'() try occurrence ' . $egw_rrule->current()
2717
-									. " ($occurrence)\n",3,$this->logfile);
2714
+									'() try occurrence '.$egw_rrule->current()
2715
+									. " ($occurrence)\n", 3, $this->logfile);
2718 2716
 							}
2719 2717
 							if ($event['start'] == $occurrence)
2720 2718
 							{
@@ -2747,8 +2745,8 @@  discard block
 block discarded – undo
2747 2745
 			// default if we cannot find a proof for a fundamental change
2748 2746
 			// the recurrence_event is the master event with start and end adjusted to the recurrence
2749 2747
 			// check for changed data
2750
-			foreach (array('start','end','uid','title','location','description',
2751
-				'priority','public','special','non_blocking') as $key)
2748
+			foreach (array('start', 'end', 'uid', 'title', 'location', 'description',
2749
+				'priority', 'public', 'special', 'non_blocking') as $key)
2752 2750
 			{
2753 2751
 				if (!empty($event[$key]) && $recurrence_event[$key] != $event[$key])
2754 2752
 				{
@@ -2806,10 +2804,10 @@  discard block
 block discarded – undo
2806 2804
      * @param &$event	the event we are working on
2807 2805
      *
2808 2806
      */
2809
-    function server2usertime (&$event)
2807
+    function server2usertime(&$event)
2810 2808
     {
2811 2809
 		// we run all dates through date2usertime, to adjust to user-time
2812
-		foreach(array('start','end','recur_enddate','recurrence') as $ts)
2810
+		foreach (array('start', 'end', 'recur_enddate', 'recurrence') as $ts)
2813 2811
 		{
2814 2812
 			// we convert here from server-time to timestamps in user-time!
2815 2813
 			if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
@@ -2817,7 +2815,7 @@  discard block
 block discarded – undo
2817 2815
 		// same with the recur exceptions
2818 2816
 		if (isset($event['recur_exception']) && is_array($event['recur_exception']))
2819 2817
 		{
2820
-			foreach($event['recur_exception'] as $n => $date)
2818
+			foreach ($event['recur_exception'] as $n => $date)
2821 2819
 			{
2822 2820
 				$event['recur_exception'][$n] = $this->date2usertime($date);
2823 2821
 			}
@@ -2825,7 +2823,7 @@  discard block
 block discarded – undo
2825 2823
 		// same with the alarms
2826 2824
 		if (isset($event['alarm']) && is_array($event['alarm']))
2827 2825
 		{
2828
-			foreach($event['alarm'] as $id => $alarm)
2826
+			foreach ($event['alarm'] as $id => $alarm)
2829 2827
 			{
2830 2828
 				$event['alarm'][$id]['time'] = $this->date2usertime($alarm['time']);
2831 2829
 			}
@@ -2842,7 +2840,7 @@  discard block
 block discarded – undo
2842 2840
 	{
2843 2841
 		if (is_numeric($age) && $age > 0)	// just make sure bogus values dont delete everything
2844 2842
 		{
2845
-			$this->so->purge(time() - 365*24*3600*(float)$age);
2843
+			$this->so->purge(time() - 365 * 24 * 3600 * (float)$age);
2846 2844
 		}
2847 2845
 	}
2848 2846
 }
Please login to merge, or discard this patch.
calendar/inc/class.calendar_export_csv.inc.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 	/**
28 28
 	 * Exports records as defined in $_definition
29 29
 	 *
30
-	 * @param egw_record $_definition
30
+	 * @param importexport_definition $_definition
31 31
 	 */
32 32
 	public function export( $_stream, importexport_definition $_definition) {
33 33
 		$options = $_definition->plugin_options;
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 */
367 367
 	protected function get_selects()
368 368
 	{
369
-		$this->selects['priority'] = Array(
369
+		$this->selects['priority'] = array(
370 370
 			0 => lang('None'),
371 371
 			1 => lang('Low'),
372 372
 			2 => lang('Normal'),
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 	/**
395 395
 	 * Adjust automatically generated field filters
396 396
 	 */
397
-	public function get_filter_fields(Array &$filters)
397
+	public function get_filter_fields(array &$filters)
398 398
 	{
399 399
 
400 400
 		// Calendar SO doesn't support filtering by column, so we have to remove pretty much everything
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -29,15 +29,15 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param egw_record $_definition
31 31
 	 */
32
-	public function export( $_stream, importexport_definition $_definition) {
32
+	public function export($_stream, importexport_definition $_definition) {
33 33
 		$options = $_definition->plugin_options;
34 34
 
35 35
 		$limit_exception = Api\Storage\Merge::is_export_limit_excepted();
36 36
 		if (!$limit_exception) $export_limit = Api\Storage\Merge::getExportLimit('calendar');
37 37
 		// Custom fields need to be specifically requested
38 38
 		$cfs = array();
39
-		foreach($options['mapping'] + (array)$_definition->filter as $key => $label) {
40
-			if($key[0] == '#') $cfs[] = substr($key,1);
39
+		foreach ($options['mapping'] + (array)$_definition->filter as $key => $label) {
40
+			if ($key[0] == '#') $cfs[] = substr($key, 1);
41 41
 		}
42 42
 
43 43
 		$query = array(
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 			'num_rows'	=> -1,
46 46
 			'csv_export'	=> true
47 47
 		);
48
-		switch($options['selection'])
48
+		switch ($options['selection'])
49 49
 		{
50 50
 			case 'criteria':
51 51
 				$query = array(
@@ -55,33 +55,33 @@  discard block
 block discarded – undo
55 55
 					'users'         => $options['criteria']['owner'],
56 56
 					'cfs'		=> $cfs // Otherwise we shouldn't get any custom fields
57 57
 				);
58
-				if($options['criteria']['start'])
58
+				if ($options['criteria']['start'])
59 59
 				{
60 60
 					$query['start'] = $options['criteria']['start'];
61 61
 				}
62
-				if($options['criteria']['end'])
62
+				if ($options['criteria']['end'])
63 63
 				{
64
-					$query['end'] = strtotime('+1 day',$options['criteria']['end'])-1;
64
+					$query['end'] = strtotime('+1 day', $options['criteria']['end']) - 1;
65 65
 				}
66
-				if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception) {
66
+				if (Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception) {
67 67
 					$query['offset'] = 0;
68 68
 					$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
69 69
 				}
70
-				$events =& $this->bo->search($query);
70
+				$events = & $this->bo->search($query);
71 71
 				break;
72 72
 			case 'search_results':
73 73
 				$states = $this->bo->cal_prefs['saved_states'];
74 74
 				$query = Api\Cache::getSession('calendar', 'calendar_list');
75
-				$query['num_rows'] = -1;        // all
76
-				$query['csv_export'] = true;	// so get_rows method _can_ produce different content or not store state in the session
75
+				$query['num_rows'] = -1; // all
76
+				$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
77 77
 				$query['start'] = 0;
78 78
 				$query['cfs'] = $cfs;
79
-				if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception)
79
+				if (Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception)
80 80
 				{
81 81
 					$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
82 82
 				}
83 83
 				$ui = new calendar_uilist();
84
-				if($states['view'] == 'listview')
84
+				if ($states['view'] == 'listview')
85 85
 				{
86 86
 					$ui->get_rows($query, $events, $unused);
87 87
 				} 
@@ -98,35 +98,35 @@  discard block
 block discarded – undo
98 98
 				$filter = $_definition->filter;
99 99
 
100 100
 				// Handle ranges
101
-				foreach($filter as $field => $value)
101
+				foreach ($filter as $field => $value)
102 102
 				{
103
-					if($field == 'filter' && $value)
103
+					if ($field == 'filter' && $value)
104 104
 					{
105 105
 						$query['filter'] = $value;
106 106
 						continue;
107 107
 					}
108
-					if(!is_array($value) || (!$value['from'] && !$value['to']))
108
+					if (!is_array($value) || (!$value['from'] && !$value['to']))
109 109
 					{
110 110
 						$query['query']["cal_$field"] = $value;
111 111
 						continue;
112 112
 					}
113 113
 
114 114
 					// Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10)
115
-					if($value['from']) $query['sql_filter'][] = "cal_$field >= " . (int)$value['from'];
116
-					if($value['to']) $query['sql_filter'][] = "cal_$field <= " . (int)$value['to'];
115
+					if ($value['from']) $query['sql_filter'][] = "cal_$field >= ".(int)$value['from'];
116
+					if ($value['to']) $query['sql_filter'][] = "cal_$field <= ".(int)$value['to'];
117 117
 
118 118
 				}
119
-				if($query['sql_filter'] && is_array($query['sql_filter']))
119
+				if ($query['sql_filter'] && is_array($query['sql_filter']))
120 120
 				{
121 121
 					// Set as an extra parameter
122
-					$sql_filter = implode(' AND ',$query['sql_filter']);
122
+					$sql_filter = implode(' AND ', $query['sql_filter']);
123 123
 				}
124 124
 
125 125
 			case 'all':
126 126
 				$events = $this->bo->search($query + array(
127 127
 					'offset' => 0,
128 128
 					'order' => 'cal_start',
129
-				),$sql_filter);
129
+				), $sql_filter);
130 130
 				break;
131 131
 		}
132 132
 
@@ -145,30 +145,30 @@  discard block
 block discarded – undo
145 145
 			// Get rid of yearly recurring events that don't belong
146 146
 			//if($options['selection']['select'] == 'criteria' && ($event['start'] > $query['end'] || $event['end'] < $query['start'])) continue;
147 147
 			// Add in participants
148
-			if($options['mapping']['participants'])
148
+			if ($options['mapping']['participants'])
149 149
 			{
150
-				$event['participants'] = implode(", ",$this->bo->participants($event,true));
150
+				$event['participants'] = implode(", ", $this->bo->participants($event, true));
151 151
 			}
152 152
 			if (is_array($event))
153 153
 			{
154 154
 				$record->set_record($event);
155
-				if($options['mapping']['recurrence'])
155
+				if ($options['mapping']['recurrence'])
156 156
 				{
157 157
 					$rrule = calendar_rrule::event2rrule($event);
158 158
 					$record->recurrence = $rrule->__toString();
159 159
 				}
160 160
 
161 161
 				// Standard stuff
162
-				if($options['convert'])
162
+				if ($options['convert'])
163 163
 				{
164 164
 					importexport_export_csv::convert($record, $convert_fields, 'calendar', $this->selects);
165 165
 				}
166 166
 				else
167 167
 				{
168 168
 					// Implode arrays, so they don't say 'Array'
169
-					foreach($record->get_record_array() as $key => $value)
169
+					foreach ($record->get_record_array() as $key => $value)
170 170
 					{
171
-						if(is_array($value)) $record->$key = implode(',', $value);
171
+						if (is_array($value)) $record->$key = implode(',', $value);
172 172
 					}
173 173
 	 			}
174 174
 				$export_object->export_record($record);
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		$states = $this->bo->cal_prefs['saved_states'];
231 231
 		$list = Api\Cache::getSession('calendar', 'calendar_list');
232 232
 		
233
-		$start= new Api\DateTime($list['startdate']);
233
+		$start = new Api\DateTime($list['startdate']);
234 234
 		$end = new Api\DateTime($list['enddate']);
235 235
 		
236 236
 		if ($states['view'] == 'listview')
@@ -239,24 +239,24 @@  discard block
 block discarded – undo
239 239
 
240 240
 			// Use UI to get dates
241 241
 			$ui = new calendar_uilist();
242
-			$list['csv_export'] = true;	// so get_rows method _can_ produce different content or not store state in the session
243
-			$ui->get_rows($list,$rows,$readonlys);
242
+			$list['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
243
+			$ui->get_rows($list, $rows, $readonlys);
244 244
 			$start = $ui->first ? $ui->first : new Api\DateTime($ui->date);
245 245
 			$end = $ui->last;
246 246
 
247 247
 			// Special handling
248
-			if($list['filter'] == 'all') $start = $end = null;
249
-			if($list['filter'] == 'before')
248
+			if ($list['filter'] == 'all') $start = $end = null;
249
+			if ($list['filter'] == 'before')
250 250
 			{
251 251
 				$end = $start;
252 252
 				$start = null;
253 253
 			}
254 254
 			$ui = null;
255 255
 		}
256
-		else if(!$end)
256
+		else if (!$end)
257 257
 		{
258
-			$end = '+1 ' . $states['view'];
259
-			$end = strtotime($end, $start->format('ts'))-1;
258
+			$end = '+1 '.$states['view'];
259
+			$end = strtotime($end, $start->format('ts')) - 1;
260 260
 		}
261 261
 		$prefs = unserialize($GLOBALS['egw_info']['user']['preferences']['importexport'][$definition->definition_id]);
262 262
 		$data = array(
@@ -322,17 +322,17 @@  discard block
 block discarded – undo
322 322
 		);
323 323
 		$filters = array_reverse($filters, true);
324 324
 
325
-		foreach($filters as $field_name => &$settings)
325
+		foreach ($filters as $field_name => &$settings)
326 326
 		{
327 327
 			// Can't filter on a custom field
328
-			if(strpos($field_name, '#') === 0)
328
+			if (strpos($field_name, '#') === 0)
329 329
 			{
330 330
 				unset($filters[$field_name]);
331 331
 				continue;
332 332
 			}
333 333
 
334 334
 			// Pass on select options
335
-			if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name];
335
+			if ($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name];
336 336
 		}
337 337
 
338 338
 	}
Please login to merge, or discard this patch.
Braces   +39 added lines, -13 removed lines patch added patch discarded remove patch
@@ -16,9 +16,11 @@  discard block
 block discarded – undo
16 16
 /**
17 17
  * export CSV plugin of calendar
18 18
  */
19
-class calendar_export_csv implements importexport_iface_export_plugin {
19
+class calendar_export_csv implements importexport_iface_export_plugin
20
+{
20 21
 
21
-	public function __construct() {
22
+	public function __construct()
23
+	{
22 24
 		Api\Translation::add_app('calendar');
23 25
 		$this->bo = new calendar_bo();
24 26
 		$this->get_selects();
@@ -29,15 +31,23 @@  discard block
 block discarded – undo
29 31
 	 *
30 32
 	 * @param egw_record $_definition
31 33
 	 */
32
-	public function export( $_stream, importexport_definition $_definition) {
34
+	public function export( $_stream, importexport_definition $_definition)
35
+	{
33 36
 		$options = $_definition->plugin_options;
34 37
 
35 38
 		$limit_exception = Api\Storage\Merge::is_export_limit_excepted();
36
-		if (!$limit_exception) $export_limit = Api\Storage\Merge::getExportLimit('calendar');
39
+		if (!$limit_exception)
40
+		{
41
+			$export_limit = Api\Storage\Merge::getExportLimit('calendar');
42
+		}
37 43
 		// Custom fields need to be specifically requested
38 44
 		$cfs = array();
39
-		foreach($options['mapping'] + (array)$_definition->filter as $key => $label) {
40
-			if($key[0] == '#') $cfs[] = substr($key,1);
45
+		foreach($options['mapping'] + (array)$_definition->filter as $key => $label)
46
+		{
47
+			if($key[0] == '#')
48
+			{
49
+				$cfs[] = substr($key,1);
50
+			}
41 51
 		}
42 52
 
43 53
 		$query = array(
@@ -63,7 +73,8 @@  discard block
 block discarded – undo
63 73
 				{
64 74
 					$query['end'] = strtotime('+1 day',$options['criteria']['end'])-1;
65 75
 				}
66
-				if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception) {
76
+				if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception)
77
+				{
67 78
 					$query['offset'] = 0;
68 79
 					$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
69 80
 				}
@@ -84,7 +95,7 @@  discard block
 block discarded – undo
84 95
 				if($states['view'] == 'listview')
85 96
 				{
86 97
 					$ui->get_rows($query, $events, $unused);
87
-				} 
98
+				}
88 99
 				else
89 100
 				{
90 101
 					$query['filter'] = 'custom';
@@ -112,8 +123,14 @@  discard block
 block discarded – undo
112 123
 					}
113 124
 
114 125
 					// Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10)
115
-					if($value['from']) $query['sql_filter'][] = "cal_$field >= " . (int)$value['from'];
116
-					if($value['to']) $query['sql_filter'][] = "cal_$field <= " . (int)$value['to'];
126
+					if($value['from'])
127
+					{
128
+						$query['sql_filter'][] = "cal_$field >= " . (int)$value['from'];
129
+					}
130
+					if($value['to'])
131
+					{
132
+						$query['sql_filter'][] = "cal_$field <= " . (int)$value['to'];
133
+					}
117 134
 
118 135
 				}
119 136
 				if($query['sql_filter'] && is_array($query['sql_filter']))
@@ -168,7 +185,10 @@  discard block
 block discarded – undo
168 185
 					// Implode arrays, so they don't say 'Array'
169 186
 					foreach($record->get_record_array() as $key => $value)
170 187
 					{
171
-						if(is_array($value)) $record->$key = implode(',', $value);
188
+						if(is_array($value))
189
+						{
190
+							$record->$key = implode(',', $value);
191
+						}
172 192
 					}
173 193
 	 			}
174 194
 				$export_object->export_record($record);
@@ -245,7 +265,10 @@  discard block
 block discarded – undo
245 265
 			$end = $ui->last;
246 266
 
247 267
 			// Special handling
248
-			if($list['filter'] == 'all') $start = $end = null;
268
+			if($list['filter'] == 'all')
269
+			{
270
+				$start = $end = null;
271
+			}
249 272
 			if($list['filter'] == 'before')
250 273
 			{
251 274
 				$end = $start;
@@ -332,7 +355,10 @@  discard block
 block discarded – undo
332 355
 			}
333 356
 
334 357
 			// Pass on select options
335
-			if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name];
358
+			if($this->selects[$field_name])
359
+			{
360
+				$settings['values'] = $this->selects[$field_name];
361
+			}
336 362
 		}
337 363
 
338 364
 	}
Please login to merge, or discard this patch.
calendar/inc/class.calendar_ical.inc.php 4 patches
Doc Comments   +11 added lines, -7 removed lines patch added patch discarded remove patch
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	 *                          default 0 => export whole series (or events, if not recurring)
195 195
 	 * @param string $principalURL ='' Used for CalDAV exports
196 196
 	 * @param string $charset ='UTF-8' encoding of the vcalendar, default UTF-8
197
-	 * @param int|string $current_user =0 uid of current user to only export that one as participant for method=REPLY
197
+	 * @param integer $current_user =0 uid of current user to only export that one as participant for method=REPLY
198 198
 	 * @return string|boolean string with iCal or false on error (e.g. no permission to read the event)
199 199
 	 */
200 200
 	function &exportVCal($events, $version='1.0', $method='PUBLISH', $recur_date=0, $principalURL='', $charset='UTF-8', $current_user=0)
@@ -1094,16 +1094,15 @@  discard block
 block discarded – undo
1094 1094
 	 * Import an iCal
1095 1095
 	 *
1096 1096
 	 * @param string|resource $_vcalData
1097
-	 * @param int $cal_id=-1 must be -1 for new entries!
1098
-	 * @param string $etag=null if an etag is given, it has to match the current etag or the import will fail
1099
-	 * @param boolean $merge=false	merge data with existing entry
1100
-	 * @param int $recur_date=0 if set, import the recurrence at this timestamp,
1097
+	 * @param int $cal_id must be -1 for new entries!
1098
+	 * @param int $recur_date if set, import the recurrence at this timestamp,
1101 1099
 	 *                          default 0 => import whole series (or events, if not recurring)
1102 1100
 	 * @param string $principalURL='' Used for CalDAV imports
1103
-	 * @param int $user=null account_id of owner, default null
1104 1101
 	 * @param string $charset  The encoding charset for $text. Defaults to
1105 1102
 	 *                         utf-8 for new format, iso-8859-1 for old format.
1106
-	 * @param string $caldav_name=null name from CalDAV client or null (to use default)
1103
+	 * @param string $caldav_name name from CalDAV client or null (to use default)
1104
+	 * @param integer $etag
1105
+	 * @param integer $user
1107 1106
 	 * @return int|boolean|null cal_id > 0 on success, false on failure or 0 for a failed etag|permission denied or null for "403 Forbidden"
1108 1107
 	 */
1109 1108
 	function importVCal($_vcalData, $cal_id=-1, $etag=null, $merge=false, $recur_date=0, $principalURL='', $user=null, $charset=null, $caldav_name=null,$skip_notification=false)
@@ -3182,6 +3181,10 @@  discard block
 block discarded – undo
3182 3181
 		return $event;
3183 3182
 	}
3184 3183
 
3184
+	/**
3185
+	 * @param integer $contentID
3186
+	 * @param string $charset
3187
+	 */
3185 3188
 	function search($_vcalData, $contentID=null, $relax=false, $charset=null)
3186 3189
 	{
3187 3190
 		if (($events = $this->icaltoegw($_vcalData, $charset)))
@@ -3221,6 +3224,7 @@  discard block
 block discarded – undo
3221 3224
 	 * @param string $method ='PUBLISH' or eg. 'REPLY'
3222 3225
 	 * @param array $extra =null extra attributes to add
3223 3226
 	 * 	X-CALENDARSERVER-MASK-UID can be used to not include an event specified by this uid as busy
3227
+	 * @return string|null
3224 3228
 	 */
3225 3229
 	function freebusy($user,$end=null,$utc=true, $charset='UTF-8', $start=null, $method='PUBLISH', array $extra=null)
3226 3230
 	{
Please login to merge, or discard this patch.
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -483,15 +483,15 @@  discard block
 block discarded – undo
483 483
 									{
484 484
 										$user = $this->resource_info($this->user);
485 485
 										$attributes['ATTENDEE'][] = 'mailto:' . $user['email'];
486
-			    						$parameters['ATTENDEE'][] = array(
487
-			    							'CN'		=>	$user['name'],
488
-			    							'ROLE'		=> 'REQ-PARTICIPANT',
486
+										$parameters['ATTENDEE'][] = array(
487
+											'CN'		=>	$user['name'],
488
+											'ROLE'		=> 'REQ-PARTICIPANT',
489 489
 											'PARTSTAT'	=> 'NEEDS-ACTION',
490 490
 											'CUTYPE'	=> 'INDIVIDUAL',
491 491
 											'RSVP'		=> 'TRUE',
492 492
 											'X-EGROUPWARE-UID'	=> (string)$this->user,
493
-			    						);
494
-			    						$event['participants'][$this->user] = true;
493
+										);
494
+										$event['participants'][$this->user] = true;
495 495
 									}
496 496
 									break;
497 497
 								case 'r':
@@ -543,24 +543,24 @@  discard block
 block discarded – undo
543 543
 						}
544 544
 						break;
545 545
 
546
-    				case 'ORGANIZER':
547
-	    				if (!$organizerURL)
548
-	    				{
549
-	    					$organizerCN = '"' . trim($GLOBALS['egw']->accounts->id2name($event['owner'],'account_firstname')
550
-			    				. ' ' . $GLOBALS['egw']->accounts->id2name($event['owner'],'account_lastname')) . '"';
551
-			    			$organizerEMail = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_email');
552
-			    			if ($version == '1.0')
553
-			    			{
554
-		    					$organizerURL = trim($organizerCN . (empty($organizerURL) ? '' : ' <' . $organizerURL .'>'));
555
-			    			}
556
-			    			else
557
-			    			{
558
-		    					$organizerURL = empty($organizerEMail) ? '' : 'mailto:' . $organizerEMail;
559
-			    			}
560
-			    			$organizerUID = $event['owner'];
561
-		    				if (!isset($event['participants'][$event['owner']]))
562
-		    				{
563
-			    				$options = array(
546
+					case 'ORGANIZER':
547
+						if (!$organizerURL)
548
+						{
549
+							$organizerCN = '"' . trim($GLOBALS['egw']->accounts->id2name($event['owner'],'account_firstname')
550
+								. ' ' . $GLOBALS['egw']->accounts->id2name($event['owner'],'account_lastname')) . '"';
551
+							$organizerEMail = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_email');
552
+							if ($version == '1.0')
553
+							{
554
+								$organizerURL = trim($organizerCN . (empty($organizerURL) ? '' : ' <' . $organizerURL .'>'));
555
+							}
556
+							else
557
+							{
558
+								$organizerURL = empty($organizerEMail) ? '' : 'mailto:' . $organizerEMail;
559
+							}
560
+							$organizerUID = $event['owner'];
561
+							if (!isset($event['participants'][$event['owner']]))
562
+							{
563
+								$options = array(
564 564
 									'ROLE'     => 'CHAIR',
565 565
 									'PARTSTAT' => 'DELEGATED',
566 566
 									'CUTYPE'   => 'INDIVIDUAL',
@@ -570,20 +570,20 @@  discard block
 block discarded – undo
570 570
 								if (!empty($organizerEMail)) $options['EMAIL'] = $organizerEMail;
571 571
 								if (!empty($event['owner'])) $options['X-EGROUPWARE-UID'] = $event['owner'];
572 572
 								$attributes['ATTENDEE'][] = $organizerURL;
573
-			    				$parameters['ATTENDEE'][] = $options;
574
-		    				}
575
-	    				}
576
-    					// do NOT use ORGANIZER for events without further participants or a different organizer
577
-	    				if (count($event['participants']) > 1 || !isset($event['participants'][$event['owner']]))
578
-	    				{
579
-		    				$attributes['ORGANIZER'] = $organizerURL;
580
-		    				$parameters['ORGANIZER']['CN'] = $organizerCN;
581
-		    				if (!empty($organizerUID))
582
-		    				{
583
-			    				$parameters['ORGANIZER']['X-EGROUPWARE-UID'] = $organizerUID;
584
-		    				}
585
-	    				}
586
-	    				break;
573
+								$parameters['ATTENDEE'][] = $options;
574
+							}
575
+						}
576
+						// do NOT use ORGANIZER for events without further participants or a different organizer
577
+						if (count($event['participants']) > 1 || !isset($event['participants'][$event['owner']]))
578
+						{
579
+							$attributes['ORGANIZER'] = $organizerURL;
580
+							$parameters['ORGANIZER']['CN'] = $organizerCN;
581
+							if (!empty($organizerUID))
582
+							{
583
+								$parameters['ORGANIZER']['X-EGROUPWARE-UID'] = $organizerUID;
584
+							}
585
+						}
586
+						break;
587 587
 
588 588
 					case 'DTSTART':
589 589
 						if (empty($event['whole_day']))
@@ -992,12 +992,12 @@  discard block
 block discarded – undo
992 992
 				foreach (is_array($value) && $parameters[$key]['VALUE']!='DATE' ? $value : array($value) as $valueID => $valueData)
993 993
 				{
994 994
 					$valueData = Api\Translation::convert($valueData,Api\Translation::charset(),$charset);
995
-                    $paramData = (array) Api\Translation::convert(is_array($value) ?
996
-                    		$parameters[$key][$valueID] : $parameters[$key],
997
-                            Api\Translation::charset(),$charset);
998
-                    $valuesData = (array) Api\Translation::convert($values[$key],
999
-                    		Api\Translation::charset(),$charset);
1000
-                    $content = $valueData . implode(';', $valuesData);
995
+					$paramData = (array) Api\Translation::convert(is_array($value) ?
996
+							$parameters[$key][$valueID] : $parameters[$key],
997
+							Api\Translation::charset(),$charset);
998
+					$valuesData = (array) Api\Translation::convert($values[$key],
999
+							Api\Translation::charset(),$charset);
1000
+					$content = $valueData . implode(';', $valuesData);
1001 1001
 
1002 1002
 					if ($version == '1.0' && (preg_match('/[^\x20-\x7F]/', $content) ||
1003 1003
 						($paramData['CN'] && preg_match('/[^\x20-\x7F]/', $paramData['CN']))))
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
 	 * @param string|resource $_vcalData
2234 2234
 	 * @param string $principalURL ='' Used for CalDAV imports
2235 2235
 	 * @param string $charset  The encoding charset for $text. Defaults to
2236
-     *                         utf-8 for new format, iso-8859-1 for old format.
2236
+	 *                         utf-8 for new format, iso-8859-1 for old format.
2237 2237
 	 * @return Iterator|array|boolean Iterator if resource given or array of events on success, false on failure
2238 2238
 	 */
2239 2239
 	function icaltoegw($_vcalData, $principalURL='', $charset=null)
@@ -2784,10 +2784,10 @@  discard block
 block discarded – undo
2784 2784
 					// fall throught
2785 2785
 				case 'ATTENDEE':
2786 2786
 					if (isset($attributes['params']['PARTSTAT']))
2787
-				    {
2788
-				    	$attributes['params']['STATUS'] = $attributes['params']['PARTSTAT'];
2789
-				    }
2790
-				    if (isset($attributes['params']['STATUS']))
2787
+					{
2788
+						$attributes['params']['STATUS'] = $attributes['params']['PARTSTAT'];
2789
+					}
2790
+					if (isset($attributes['params']['STATUS']))
2791 2791
 					{
2792 2792
 						$status = $this->status_ical2egw[strtoupper($attributes['params']['STATUS'])];
2793 2793
 						if (empty($status)) $status = 'X';
@@ -3178,7 +3178,7 @@  discard block
 block discarded – undo
3178 3178
 				array2string($event)."\n",3,$this->logfile);
3179 3179
 		}
3180 3180
 		//Horde::logMessage("vevent2egw:\n" . print_r($event, true),
3181
-        //    	__FILE__, __LINE__, PEAR_LOG_DEBUG);
3181
+		//    	__FILE__, __LINE__, PEAR_LOG_DEBUG);
3182 3182
 		return $event;
3183 3183
 	}
3184 3184
 
Please login to merge, or discard this patch.
Spacing   +269 added lines, -270 removed lines patch added patch discarded remove patch
@@ -64,39 +64,39 @@  discard block
 block discarded – undo
64 64
 	 * @var array $priority_egw2ical conversion of the priority egw => ical
65 65
 	 */
66 66
 	var $priority_egw2ical = array(
67
-		0 => 0,		// undefined
68
-		1 => 9,		// low
69
-		2 => 5,		// normal
70
-		3 => 1,		// high
67
+		0 => 0, // undefined
68
+		1 => 9, // low
69
+		2 => 5, // normal
70
+		3 => 1, // high
71 71
 	);
72 72
 
73 73
 	/**
74 74
 	 * @var array $priority_ical2egw conversion of the priority ical => egw
75 75
 	 */
76 76
 	var $priority_ical2egw = array(
77
-		0 => 0,		// undefined
78
-		9 => 1,	8 => 1, 7 => 1, 6 => 1,	// low
79
-		5 => 2,		// normal
80
-		4 => 3, 3 => 3, 2 => 3, 1 => 3,	// high
77
+		0 => 0, // undefined
78
+		9 => 1, 8 => 1, 7 => 1, 6 => 1, // low
79
+		5 => 2, // normal
80
+		4 => 3, 3 => 3, 2 => 3, 1 => 3, // high
81 81
 	);
82 82
 
83 83
 	/**
84 84
 	 * @var array $priority_egw2funambol conversion of the priority egw => funambol
85 85
 	 */
86 86
 	var $priority_egw2funambol = array(
87
-		0 => 1,		// undefined (mapped to normal since undefined does not exist)
88
-		1 => 0,		// low
89
-		2 => 1,		// normal
90
-		3 => 2,		// high
87
+		0 => 1, // undefined (mapped to normal since undefined does not exist)
88
+		1 => 0, // low
89
+		2 => 1, // normal
90
+		3 => 2, // high
91 91
 	);
92 92
 
93 93
 	/**
94 94
 	 * @var array $priority_funambol2egw conversion of the priority funambol => egw
95 95
 	 */
96 96
 	var $priority_funambol2egw = array(
97
-		0 => 1,		// low
98
-		1 => 2,		// normal
99
-		2 => 3,		// high
97
+		0 => 1, // low
98
+		1 => 2, // normal
99
+		2 => 3, // high
100 100
 	);
101 101
 
102 102
 	/**
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 * @var boolean
167 167
 	 */
168 168
 	var $log = false;
169
-	var $logfile="/tmp/log-vcal";
169
+	var $logfile = "/tmp/log-vcal";
170 170
 
171 171
 	/**
172 172
 	 * Conflict callback
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @param int|string $current_user =0 uid of current user to only export that one as participant for method=REPLY
204 204
 	 * @return string|boolean string with iCal or false on error (e.g. no permission to read the event)
205 205
 	 */
206
-	function &exportVCal($events, $version='1.0', $method='PUBLISH', $recur_date=0, $principalURL='', $charset='UTF-8', $current_user=0)
206
+	function &exportVCal($events, $version = '1.0', $method = 'PUBLISH', $recur_date = 0, $principalURL = '', $charset = 'UTF-8', $current_user = 0)
207 207
 	{
208 208
 		if ($this->log)
209 209
 		{
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 
235 235
 		if (!is_array($this->supportedFields)) $this->setSupportedFields();
236 236
 
237
-		if ($this->productManufacturer == '' )
237
+		if ($this->productManufacturer == '')
238 238
 		{	// syncevolution is broken
239 239
 			$version = '2.0';
240 240
 		}
241 241
 
242 242
 		$vcal = new Horde_Icalendar;
243
-		$vcal->setAttribute('PRODID','-//EGroupware//NONSGML EGroupware Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
243
+		$vcal->setAttribute('PRODID', '-//EGroupware//NONSGML EGroupware Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
244 244
 			strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
245 245
 		$vcal->setAttribute('VERSION', $version);
246 246
 		if ($method) $vcal->setAttribute('METHOD', $method);
@@ -270,15 +270,15 @@  discard block
 block discarded – undo
270 270
 						if ($this->log)
271 271
 						{
272 272
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
273
-								'() User does not have the permission to read event ' . $event['id']. "\n",
274
-								3,$this->logfile);
273
+								'() User does not have the permission to read event '.$event['id']."\n",
274
+								3, $this->logfile);
275 275
 						}
276 276
 						return -1; // Permission denied
277 277
 					}
278 278
 				}
279 279
 				else
280 280
 				{
281
-					$retval = false;  // Entry does not exist
281
+					$retval = false; // Entry does not exist
282 282
 					if ($this->log)
283 283
 					{
284 284
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 			if ($this->log)
293 293
 			{
294 294
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
295
-					'() export event UID: ' . $event['uid'] . ".\n",
295
+					'() export event UID: '.$event['uid'].".\n",
296 296
 					3, $this->logfile);
297 297
 			}
298 298
 
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
 			if ($this->log)
318 318
 			{
319 319
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
320
-					'(' . $event['id']. ',' . $recurrence . ")\n" .
321
-					array2string($event)."\n",3,$this->logfile);
320
+					'('.$event['id'].','.$recurrence.")\n".
321
+					array2string($event)."\n", 3, $this->logfile);
322 322
 			}
323 323
 
324 324
 			if ($recurrence)
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 						{
340 340
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
341 341
 								"(, $recurrence) Gratuitous pseudo exception, skipped ...\n",
342
-								3,$this->logfile);
342
+								3, $this->logfile);
343 343
 						}
344 344
 						continue; // unsupported status only exception
345 345
 					}
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 					$days = $this->so->get_recurrence_exceptions($master, $tzid, 0, 0, 'rrule');
350 350
 					if ($this->log)
351 351
 					{
352
-						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
353
-							array2string($days)."\n",3,$this->logfile);
352
+						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n".
353
+							array2string($days)."\n", 3, $this->logfile);
354 354
 					}
355 355
 					$recurrence = $days[$recurrence]; // use remote representation
356 356
 				}
357 357
 				// force single event
358
-				foreach (array('recur_enddate','recur_interval','recur_exception','recur_data','recur_date','id','etag') as $name)
358
+				foreach (array('recur_enddate', 'recur_interval', 'recur_exception', 'recur_data', 'recur_date', 'id', 'etag') as $name)
359 359
 				{
360 360
 					unset($event[$name]);
361 361
 				}
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 			}
364 364
 
365 365
 			// check if tzid of event (not only recuring ones) is already added to export
366
-			if ($tzid && $tzid != 'UTC' && !in_array($tzid,$vtimezones_added))
366
+			if ($tzid && $tzid != 'UTC' && !in_array($tzid, $vtimezones_added))
367 367
 			{
368 368
 				// check if we have vtimezone component data for tzid of event, if not default to user timezone (default to server tz)
369 369
 				if (calendar_timezones::add_vtimezone($vcal, $tzid) ||
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 			{
382 382
 				// Append UID to DESCRIPTION
383 383
 				if (!preg_match('/\[UID:.+\]/m', $event['description'])) {
384
-					$event['description'] .= "\n[UID:" . $event['uid'] . "]";
384
+					$event['description'] .= "\n[UID:".$event['uid']."]";
385 385
 				}
386 386
 			}
387 387
 
@@ -402,14 +402,14 @@  discard block
 block discarded – undo
402 402
 				$exceptions = array();
403 403
 
404 404
 				// dont use "virtual" exceptions created by participant status for GroupDAV or file export
405
-				if (!in_array($this->productManufacturer,array('file','groupdav')))
405
+				if (!in_array($this->productManufacturer, array('file', 'groupdav')))
406 406
 				{
407 407
 					$filter = isset($this->supportedFields['participants']) ? 'rrule' : 'tz_rrule';
408 408
 					$exceptions = $this->so->get_recurrence_exceptions($event, $tzid, 0, 0, $filter);
409 409
 					if ($this->log)
410 410
 					{
411
-						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."(EXCEPTIONS)\n" .
412
-							array2string($exceptions)."\n",3,$this->logfile);
411
+						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."(EXCEPTIONS)\n".
412
+							array2string($exceptions)."\n", 3, $this->logfile);
413 413
 					}
414 414
 				}
415 415
 				elseif (is_array($event['recur_exception']))
@@ -426,8 +426,8 @@  discard block
 block discarded – undo
426 426
 					if ($this->log)
427 427
 					{
428 428
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
429
-							'(' . $event['id'] . ") [$icalFieldName] not supported\n",
430
-							3,$this->logfile);
429
+							'('.$event['id'].") [$icalFieldName] not supported\n",
430
+							3, $this->logfile);
431 431
 					}
432 432
 					continue;
433 433
 				}
@@ -444,23 +444,23 @@  discard block
 block discarded – undo
444 444
 
445 445
 							if (!($info = $this->resource_info($uid))) continue;
446 446
 
447
-							if (in_array($status, array('X','E'))) continue;	// dont include deleted participants
447
+							if (in_array($status, array('X', 'E'))) continue; // dont include deleted participants
448 448
 
449 449
 							if ($this->log)
450 450
 							{
451
-								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
452
-									'()attendee:' . array2string($info) ."\n",3,$this->logfile);
451
+								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
452
+									'()attendee:'.array2string($info)."\n", 3, $this->logfile);
453 453
 							}
454 454
 							$participantCN = str_replace(array('\\', ',', ';', ':'),
455 455
 												array('\\\\', '\\,', '\\;', '\\:'),
456 456
 												trim(empty($info['cn']) ? $info['name'] : $info['cn']));
457 457
 							if ($version == '1.0')
458 458
 							{
459
-								$participantURL = trim('"' . $participantCN . '"' . (empty($info['email']) ? '' : ' <' . $info['email'] .'>'));
459
+								$participantURL = trim('"'.$participantCN.'"'.(empty($info['email']) ? '' : ' <'.$info['email'].'>'));
460 460
 							}
461 461
 							else
462 462
 							{
463
-								$participantURL = empty($info['email']) ? '' : 'mailto:' . $info['email'];
463
+								$participantURL = empty($info['email']) ? '' : 'mailto:'.$info['email'];
464 464
 							}
465 465
 							// RSVP={TRUE|FALSE}	// resonse expected, not set in eGW => status=U
466 466
 							$rsvp = $status == 'U' ? 'TRUE' : 'FALSE';
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 										($members = $GLOBALS['egw']->accounts->members($uid, true)) && in_array($this->user, $members))
489 489
 									{
490 490
 										$user = $this->resource_info($this->user);
491
-										$attributes['ATTENDEE'][] = 'mailto:' . $user['email'];
491
+										$attributes['ATTENDEE'][] = 'mailto:'.$user['email'];
492 492
 			    						$parameters['ATTENDEE'][] = array(
493 493
 			    							'CN'		=>	$user['name'],
494 494
 			    							'ROLE'		=> 'REQ-PARTICIPANT',
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 							if (!empty($rsvp)) $options['RSVP'] = $rsvp;
531 531
 							if (!empty($info['email']) && $participantURL != 'mailto:'.$info['email'])
532 532
 							{
533
-								$options['EMAIL'] = $info['email'];	// only add EMAIL attribute, if not already URL, as eg. Akonadi is reported to have problems with it
533
+								$options['EMAIL'] = $info['email']; // only add EMAIL attribute, if not already URL, as eg. Akonadi is reported to have problems with it
534 534
 							}
535 535
 							if ($info['type'] != 'e') $options['X-EGROUPWARE-UID'] = (string)$uid;
536 536
 							if ($quantity > 1) $options['X-EGROUPWARE-QUANTITY'] = (string)$quantity;
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 						break;
541 541
 
542 542
 					case 'CLASS':
543
-						if ($event['public']) continue;	// public is default, no need to export, fails CalDAVTester if added as default
543
+						if ($event['public']) continue; // public is default, no need to export, fails CalDAVTester if added as default
544 544
 						$attributes['CLASS'] = $event['public'] ? 'PUBLIC' : 'PRIVATE';
545 545
 						// Apple iCal on OS X uses X-CALENDARSERVER-ACCESS: CONFIDENTIAL on VCALANDAR (not VEVENT!)
546 546
 						if (!$event['public'] && $this->productManufacturer == 'groupdav')
@@ -552,16 +552,16 @@  discard block
 block discarded – undo
552 552
     				case 'ORGANIZER':
553 553
 	    				if (!$organizerURL)
554 554
 	    				{
555
-	    					$organizerCN = '"' . trim($GLOBALS['egw']->accounts->id2name($event['owner'],'account_firstname')
556
-			    				. ' ' . $GLOBALS['egw']->accounts->id2name($event['owner'],'account_lastname')) . '"';
557
-			    			$organizerEMail = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_email');
555
+	    					$organizerCN = '"'.trim($GLOBALS['egw']->accounts->id2name($event['owner'], 'account_firstname')
556
+			    				. ' '.$GLOBALS['egw']->accounts->id2name($event['owner'], 'account_lastname')).'"';
557
+			    			$organizerEMail = $GLOBALS['egw']->accounts->id2name($event['owner'], 'account_email');
558 558
 			    			if ($version == '1.0')
559 559
 			    			{
560
-		    					$organizerURL = trim($organizerCN . (empty($organizerURL) ? '' : ' <' . $organizerURL .'>'));
560
+		    					$organizerURL = trim($organizerCN.(empty($organizerURL) ? '' : ' <'.$organizerURL.'>'));
561 561
 			    			}
562 562
 			    			else
563 563
 			    			{
564
-		    					$organizerURL = empty($organizerEMail) ? '' : 'mailto:' . $organizerEMail;
564
+		    					$organizerURL = empty($organizerEMail) ? '' : 'mailto:'.$organizerEMail;
565 565
 			    			}
566 566
 			    			$organizerUID = $event['owner'];
567 567
 		    				if (!isset($event['participants'][$event['owner']]))
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 					case 'DTSTART':
595 595
 						if (empty($event['whole_day']))
596 596
 						{
597
-							$attributes['DTSTART'] = self::getDateTime($event['start'],$tzid,$parameters['DTSTART']);
597
+							$attributes['DTSTART'] = self::getDateTime($event['start'], $tzid, $parameters['DTSTART']);
598 598
 						}
599 599
 						break;
600 600
 
@@ -605,27 +605,27 @@  discard block
 block discarded – undo
605 605
 							if ($tzid == 'UTC' && $event['end'] - $event['start'] <= 86400)
606 606
 								$attributes['duration'] = $event['end'] - $event['start'];
607 607
 							else
608
-								$attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']);
608
+								$attributes['DTEND'] = self::getDateTime($event['end'], $tzid, $parameters['DTEND']);
609 609
 						}
610 610
 						else
611 611
 						{
612 612
 							// write start + end of whole day events as dates
613
-							$event['end-nextday'] = $event['end'] + 12*3600;	// we need the date of the next day, as DTEND is non-inclusive (= exclusive) in rfc2445
614
-							foreach (array('start' => 'DTSTART','end-nextday' => 'DTEND') as $f => $t)
613
+							$event['end-nextday'] = $event['end'] + 12 * 3600; // we need the date of the next day, as DTEND is non-inclusive (= exclusive) in rfc2445
614
+							foreach (array('start' => 'DTSTART', 'end-nextday' => 'DTEND') as $f => $t)
615 615
 							{
616
-								$time = new Api\DateTime($event[$f],Api\DateTime::$server_timezone);
617
-								$arr = Api\DateTime::to($time,'array');
618
-								$vevent->setAttribute($t, array('year' => $arr['year'],'month' => $arr['month'],'mday' => $arr['day']),
616
+								$time = new Api\DateTime($event[$f], Api\DateTime::$server_timezone);
617
+								$arr = Api\DateTime::to($time, 'array');
618
+								$vevent->setAttribute($t, array('year' => $arr['year'], 'month' => $arr['month'], 'mday' => $arr['day']),
619 619
 									array('VALUE' => 'DATE'));
620 620
 							}
621 621
 							unset($attributes['DTSTART']);
622 622
 							// Outlook does NOT care about type of DTSTART/END, only setting X-MICROSOFT-CDO-ALLDAYEVENT is used to determine an event is a whole-day event
623
-							$vevent->setAttribute('X-MICROSOFT-CDO-ALLDAYEVENT','TRUE');
623
+							$vevent->setAttribute('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE');
624 624
 						}
625 625
 						break;
626 626
 
627 627
 					case 'RRULE':
628
-						if ($event['recur_type'] == MCAL_RECUR_NONE) break;		// no recuring event
628
+						if ($event['recur_type'] == MCAL_RECUR_NONE) break; // no recuring event
629 629
 						$rriter = calendar_rrule::event2rrule($event, false, $tzid);
630 630
 						$rrule = $rriter->generate_rrule($version);
631 631
 						if ($event['recur_enddate'])
@@ -652,16 +652,16 @@  discard block
 block discarded – undo
652 652
 						{
653 653
 							if ($event['recur_enddate'] && $tzid)
654 654
 							{
655
-								$rrule['UNTIL'] = self::getDateTime($rrule['UNTIL'],$tzid);
655
+								$rrule['UNTIL'] = self::getDateTime($rrule['UNTIL'], $tzid);
656 656
 							}
657 657
 							$attributes['RRULE'] = $rrule['FREQ'].' '.$rrule['UNTIL'];
658 658
 						}
659 659
 						else // $version == '2.0'
660 660
 						{
661 661
 							$attributes['RRULE'] = '';
662
-							foreach($rrule as $n => $v)
662
+							foreach ($rrule as $n => $v)
663 663
 							{
664
-								$attributes['RRULE'] .= ($attributes['RRULE']?';':'').$n.'='.$v;
664
+								$attributes['RRULE'] .= ($attributes['RRULE'] ? ';' : '').$n.'='.$v;
665 665
 							}
666 666
 						}
667 667
 						break;
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 								{
677 677
 									// current Horde_Icalendar 2.1.4 exports EXDATE always in UTC, so we should not set a timezone here
678 678
 									// Apple calendar on OS X 10.11.4 uses a timezone, so does Horde eg. for Recurrence-ID
679
-									$event['recur_exception'][$key] = self::getDateTime($timestamp,$tzid);//,$parameters['EXDATE']);
679
+									$event['recur_exception'][$key] = self::getDateTime($timestamp, $tzid); //,$parameters['EXDATE']);
680 680
 								}
681 681
 							}
682 682
 							else
@@ -684,9 +684,9 @@  discard block
 block discarded – undo
684 684
 								// use 'DATE' instead of 'DATE-TIME' on whole day events
685 685
 								foreach ($event['recur_exception'] as $id => $timestamp)
686 686
 								{
687
-									$time = new Api\DateTime($timestamp,Api\DateTime::$server_timezone);
687
+									$time = new Api\DateTime($timestamp, Api\DateTime::$server_timezone);
688 688
 									$time->setTimezone(self::$tz_cache[$event['tzid']]);
689
-									$arr = Api\DateTime::to($time,'array');
689
+									$arr = Api\DateTime::to($time, 'array');
690 690
 									$days[$id] = array(
691 691
 										'year'  => $arr['year'],
692 692
 										'month' => $arr['month'],
@@ -701,21 +701,21 @@  discard block
 block discarded – undo
701 701
 						break;
702 702
 
703 703
 					case 'PRIORITY':
704
-						if (!$event['priority']) continue;	// 0=undefined is default, no need to export, fails CalDAVTester if our default is added
704
+						if (!$event['priority']) continue; // 0=undefined is default, no need to export, fails CalDAVTester if our default is added
705 705
 						if ($this->productManufacturer == 'funambol' &&
706 706
 							(strpos($this->productName, 'outlook') !== false
707 707
 								|| strpos($this->productName, 'pocket pc') !== false))
708 708
 						{
709
-							$attributes['PRIORITY'] = (int) $this->priority_egw2funambol[$event['priority']];
709
+							$attributes['PRIORITY'] = (int)$this->priority_egw2funambol[$event['priority']];
710 710
 						}
711 711
 						else
712 712
 						{
713
-							$attributes['PRIORITY'] = (int) $this->priority_egw2ical[$event['priority']];
713
+							$attributes['PRIORITY'] = (int)$this->priority_egw2ical[$event['priority']];
714 714
 						}
715 715
 						break;
716 716
 
717 717
 					case 'TRANSP':
718
-						if (!$event['non_blocking']) continue;	// OPAQUE is default, no need to export, fails CalDAVTester if added as default
718
+						if (!$event['non_blocking']) continue; // OPAQUE is default, no need to export, fails CalDAVTester if added as default
719 719
 						if ($version == '1.0')
720 720
 						{
721 721
 							$attributes['TRANSP'] = ($event['non_blocking'] ? 1 : 0);
@@ -754,13 +754,13 @@  discard block
 block discarded – undo
754 754
 							// We handle a pseudo exception
755 755
 							if (empty($event['whole_day']))
756 756
 							{
757
-								$attributes[$icalFieldName] = self::getDateTime($recur_date,$tzid,$parameters[$icalFieldName]);
757
+								$attributes[$icalFieldName] = self::getDateTime($recur_date, $tzid, $parameters[$icalFieldName]);
758 758
 							}
759 759
 							else
760 760
 							{
761
-								$time = new Api\DateTime($recur_date,Api\DateTime::$server_timezone);
761
+								$time = new Api\DateTime($recur_date, Api\DateTime::$server_timezone);
762 762
 								$time->setTimezone(self::$tz_cache[$event['tzid']]);
763
-								$arr = Api\DateTime::to($time,'array');
763
+								$arr = Api\DateTime::to($time, 'array');
764 764
 								$vevent->setAttribute($icalFieldName, array(
765 765
 									'year' => $arr['year'],
766 766
 									'month' => $arr['month'],
@@ -772,17 +772,17 @@  discard block
 block discarded – undo
772 772
 						elseif ($event['recurrence'] && $event['reference'])
773 773
 						{
774 774
 							// $event['reference'] is a calendar_id, not a timestamp
775
-							if (!($revent = $this->read($event['reference']))) break;	// referenced event does not exist
775
+							if (!($revent = $this->read($event['reference']))) break; // referenced event does not exist
776 776
 
777 777
 							if (empty($revent['whole_day']))
778 778
 							{
779
-								$attributes[$icalFieldName] = self::getDateTime($event['recurrence'],$tzid,$parameters[$icalFieldName]);
779
+								$attributes[$icalFieldName] = self::getDateTime($event['recurrence'], $tzid, $parameters[$icalFieldName]);
780 780
 							}
781 781
 							else
782 782
 							{
783
-								$time = new Api\DateTime($event['recurrence'],Api\DateTime::$server_timezone);
783
+								$time = new Api\DateTime($event['recurrence'], Api\DateTime::$server_timezone);
784 784
 								$time->setTimezone(self::$tz_cache[$event['tzid']]);
785
-								$arr = Api\DateTime::to($time,'array');
785
+								$arr = Api\DateTime::to($time, 'array');
786 786
 								$vevent->setAttribute($icalFieldName, array(
787 787
 									'year' => $arr['year'],
788 788
 									'month' => $arr['month'],
@@ -806,9 +806,9 @@  discard block
 block discarded – undo
806 806
 							$noTruncate = $this->clientProperties[$icalFieldName]['NoTruncate'];
807 807
 							if ($this->log && $size > 0)
808 808
 							{
809
-								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
810
-									"() $icalFieldName Size: $size, NoTruncate: " .
811
-									($noTruncate ? 'TRUE' : 'FALSE') . "\n",3,$this->logfile);
809
+								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
810
+									"() $icalFieldName Size: $size, NoTruncate: ".
811
+									($noTruncate ? 'TRUE' : 'FALSE')."\n", 3, $this->logfile);
812 812
 							}
813 813
 							//Horde::logMessage("vCalendar $icalFieldName Size: $size, NoTruncate: " .
814 814
 							//	($noTruncate ? 'TRUE' : 'FALSE'), __FILE__, __LINE__, PEAR_LOG_DEBUG);
@@ -826,8 +826,8 @@  discard block
 block discarded – undo
826 826
 							{
827 827
 								if ($this->log)
828 828
 								{
829
-									error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
830
-										"() $icalFieldName omitted due to maximum size $size\n",3,$this->logfile);
829
+									error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
830
+										"() $icalFieldName omitted due to maximum size $size\n", 3, $this->logfile);
831 831
 								}
832 832
 								//Horde::logMessage("vCalendar $icalFieldName omitted due to maximum size $size",
833 833
 								//	__FILE__, __LINE__, PEAR_LOG_WARNING);
@@ -837,8 +837,8 @@  discard block
 block discarded – undo
837 837
 							$value = substr($value, 0, $size - 1);
838 838
 							if ($this->log)
839 839
 							{
840
-								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
841
-									"() $icalFieldName truncated to maximum size $size\n",3,$this->logfile);
840
+								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
841
+									"() $icalFieldName truncated to maximum size $size\n", 3, $this->logfile);
842 842
 							}
843 843
 							//Horde::logMessage("vCalendar $icalFieldName truncated to maximum size $size",
844 844
 							//	__FILE__, __LINE__, PEAR_LOG_INFO);
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 			// for CalDAV add all X-Properties previously parsed
854 854
 			if ($this->productManufacturer == 'groupdav' || $this->productManufacturer == 'file')
855 855
 			{
856
-				foreach($event as $name => $value)
856
+				foreach ($event as $name => $value)
857 857
 				{
858 858
 					if (substr($name, 0, 2) == '##')
859 859
 					{
@@ -925,8 +925,8 @@  discard block
 block discarded – undo
925 925
 						$values['AALARM']['repeat count'] = '';
926 926
 						$values['AALARM']['display text'] = $description;
927 927
 					}
928
-					$attributes['DALARM'] = self::getDateTime($alarmData['time'],$tzid,$parameters['DALARM']);
929
-					$attributes['AALARM'] = self::getDateTime($alarmData['time'],$tzid,$parameters['AALARM']);
928
+					$attributes['DALARM'] = self::getDateTime($alarmData['time'], $tzid, $parameters['DALARM']);
929
+					$attributes['AALARM'] = self::getDateTime($alarmData['time'], $tzid, $parameters['AALARM']);
930 930
 					// lets take only the first alarm
931 931
 					break;
932 932
 				}
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 						$alarmData['offset'] = false;
964 964
 					}
965 965
 
966
-					$valarm = Horde_Icalendar::newComponent('VALARM',$vevent);
966
+					$valarm = Horde_Icalendar::newComponent('VALARM', $vevent);
967 967
 					if ($alarmData['offset'] !== false)
968 968
 					{
969 969
 						$valarm->setAttribute('TRIGGER', -$alarmData['offset'],
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
 					else
973 973
 					{
974 974
 						$params = array('VALUE' => 'DATE-TIME');
975
-						$value = self::getDateTime($alarmData['time'],$tzid,$params);
975
+						$value = self::getDateTime($alarmData['time'], $tzid, $params);
976 976
 						$valarm->setAttribute('TRIGGER', $value, $params);
977 977
 					}
978 978
 					if (!empty($alarmData['uid']))
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
 					// set evtl. existing attributes set by iCal clients not used by EGroupware
984 984
 					if (isset($alarmData['attrs']))
985 985
 					{
986
-						foreach($alarmData['attrs'] as $attr => $data)
986
+						foreach ($alarmData['attrs'] as $attr => $data)
987 987
 						{
988 988
 							$valarm->setAttribute($attr, $data['value'], $data['params']);
989 989
 						}
@@ -991,11 +991,11 @@  discard block
 block discarded – undo
991 991
 					// set default ACTION and DESCRIPTION, if not set by a client
992 992
 					if (!isset($alarmData['attrs']) || !isset($alarmData['attrs']['ACTION']))
993 993
 					{
994
-						$valarm->setAttribute('ACTION','DISPLAY');
994
+						$valarm->setAttribute('ACTION', 'DISPLAY');
995 995
 					}
996 996
 					if (!isset($alarmData['attrs']) || !isset($alarmData['attrs']['DESCRIPTION']))
997 997
 					{
998
-						$valarm->setAttribute('DESCRIPTION',$event['title'] ? $event['title'] : $description);
998
+						$valarm->setAttribute('DESCRIPTION', $event['title'] ? $event['title'] : $description);
999 999
 					}
1000 1000
 					$vevent->addComponent($valarm);
1001 1001
 				}
@@ -1003,15 +1003,15 @@  discard block
 block discarded – undo
1003 1003
 
1004 1004
 			foreach ($attributes as $key => $value)
1005 1005
 			{
1006
-				foreach (is_array($value) && $parameters[$key]['VALUE']!='DATE' ? $value : array($value) as $valueID => $valueData)
1006
+				foreach (is_array($value) && $parameters[$key]['VALUE'] != 'DATE' ? $value : array($value) as $valueID => $valueData)
1007 1007
 				{
1008
-					$valueData = Api\Translation::convert($valueData,Api\Translation::charset(),$charset);
1009
-                    $paramData = (array) Api\Translation::convert(is_array($value) ?
1008
+					$valueData = Api\Translation::convert($valueData, Api\Translation::charset(), $charset);
1009
+                    $paramData = (array)Api\Translation::convert(is_array($value) ?
1010 1010
                     		$parameters[$key][$valueID] : $parameters[$key],
1011
-                            Api\Translation::charset(),$charset);
1012
-                    $valuesData = (array) Api\Translation::convert($values[$key],
1013
-                    		Api\Translation::charset(),$charset);
1014
-                    $content = $valueData . implode(';', $valuesData);
1011
+                            Api\Translation::charset(), $charset);
1012
+                    $valuesData = (array)Api\Translation::convert($values[$key],
1013
+                    		Api\Translation::charset(), $charset);
1014
+                    $content = $valueData.implode(';', $valuesData);
1015 1015
 
1016 1016
 					if ($version == '1.0' && (preg_match('/[^\x20-\x7F]/', $content) ||
1017 1017
 						($paramData['CN'] && preg_match('/[^\x20-\x7F]/', $paramData['CN']))))
@@ -1061,10 +1061,10 @@  discard block
 block discarded – undo
1061 1061
 		$retval = $events_exported ? $vcal->exportvCalendar() : false;
1062 1062
  		if ($this->log)
1063 1063
  		{
1064
- 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
1065
-				"() '$this->productManufacturer','$this->productName'\n",3,$this->logfile);
1066
- 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
1067
-				"()\n".array2string($retval)."\n",3,$this->logfile);
1064
+ 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1065
+				"() '$this->productManufacturer','$this->productName'\n", 3, $this->logfile);
1066
+ 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1067
+				"()\n".array2string($retval)."\n", 3, $this->logfile);
1068 1068
  		}
1069 1069
 		return $retval;
1070 1070
 	}
@@ -1077,15 +1077,15 @@  discard block
 block discarded – undo
1077 1077
 	 * @param array &$params=null parameter array to set TZID
1078 1078
 	 * @return mixed attribute value to set: integer timestamp if $tzid == 'UTC' otherwise Ymd\THis string IN $tzid
1079 1079
 	 */
1080
-	static function getDateTime($time,$tzid,array &$params=null)
1080
+	static function getDateTime($time, $tzid, array &$params = null)
1081 1081
 	{
1082 1082
 		if (empty($tzid) || $tzid == 'UTC')
1083 1083
 		{
1084
-			return Api\DateTime::to($time,'ts');
1084
+			return Api\DateTime::to($time, 'ts');
1085 1085
 		}
1086
-		if (!is_a($time,'DateTime'))
1086
+		if (!is_a($time, 'DateTime'))
1087 1087
 		{
1088
-			$time = new Api\DateTime($time,Api\DateTime::$server_timezone);
1088
+			$time = new Api\DateTime($time, Api\DateTime::$server_timezone);
1089 1089
 		}
1090 1090
 		if (!isset(self::$tz_cache[$tzid]))
1091 1091
 		{
@@ -1120,11 +1120,11 @@  discard block
 block discarded – undo
1120 1120
 	 * @param string $caldav_name=null name from CalDAV client or null (to use default)
1121 1121
 	 * @return int|boolean|null cal_id > 0 on success, false on failure or 0 for a failed etag|permission denied or null for "403 Forbidden"
1122 1122
 	 */
1123
-	function importVCal($_vcalData, $cal_id=-1, $etag=null, $merge=false, $recur_date=0, $principalURL='', $user=null, $charset=null, $caldav_name=null,$skip_notification=false)
1123
+	function importVCal($_vcalData, $cal_id = -1, $etag = null, $merge = false, $recur_date = 0, $principalURL = '', $user = null, $charset = null, $caldav_name = null, $skip_notification = false)
1124 1124
 	{
1125 1125
 		//error_log(__METHOD__."(, $cal_id, $etag, $merge, $recur_date, $principalURL, $user, $charset, $caldav_name)");
1126 1126
 		$this->events_imported = 0;
1127
-		$replace = $delete_exceptions= false;
1127
+		$replace = $delete_exceptions = false;
1128 1128
 
1129 1129
 		if (!is_array($this->supportedFields)) $this->setSupportedFields();
1130 1130
 
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 		{
1133 1133
 			return false;
1134 1134
 		}
1135
-		if (!is_array($events)) $cal_id = -1;	// just to be sure, as iterator does NOT allow array access (eg. $events[0])
1135
+		if (!is_array($events)) $cal_id = -1; // just to be sure, as iterator does NOT allow array access (eg. $events[0])
1136 1136
 
1137 1137
 		if ($cal_id > 0)
1138 1138
 		{
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
 			{
1141 1141
 				$replace = $recur_date == 0;
1142 1142
 				$events[0]['id'] = $cal_id;
1143
-				if (!is_null($etag)) $events[0]['etag'] = (int) $etag;
1143
+				if (!is_null($etag)) $events[0]['etag'] = (int)$etag;
1144 1144
 				if ($recur_date) $events[0]['recurrence'] = $recur_date;
1145 1145
 			}
1146 1146
 			elseif (($foundEvent = $this->find_event(array('id' => $cal_id), 'exact')) &&
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
 			{
1193 1193
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
1194 1194
 					."($cal_id, $etag, $recur_date, $principalURL, $user, $charset)\n"
1195
-					. array2string($event)."\n",3,$this->logfile);
1195
+					. array2string($event)."\n", 3, $this->logfile);
1196 1196
 			}
1197 1197
 
1198 1198
 			$updated_id = false;
@@ -1215,14 +1215,14 @@  discard block
 block discarded – undo
1215 1215
 					{
1216 1216
 						if ($delete_exceptions)
1217 1217
 						{
1218
-							$this->delete($id,0,false,$skip_notification);
1218
+							$this->delete($id, 0, false, $skip_notification);
1219 1219
 						}
1220 1220
 						else
1221 1221
 						{
1222 1222
 							if (!($exception = $this->read($id))) continue;
1223 1223
 							$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
1224 1224
 							$exception['reference'] = $exception['recurrence'] = 0;
1225
-							$this->update($exception, true,true,false,true,$msg,$skip_notification);
1225
+							$this->update($exception, true, true, false, true, $msg, $skip_notification);
1226 1226
 						}
1227 1227
 					}
1228 1228
 				}
@@ -1239,7 +1239,7 @@  discard block
 block discarded – undo
1239 1239
 				{
1240 1240
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
1241 1241
 						. "(UPDATE Event)\n"
1242
-						. array2string($event_info['stored_event'])."\n",3,$this->logfile);
1242
+						. array2string($event_info['stored_event'])."\n", 3, $this->logfile);
1243 1243
 				}
1244 1244
 				if (empty($event['uid']))
1245 1245
 				{
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 								if ($this->log)
1262 1262
 								{
1263 1263
 									error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1264
-										"() Restore status for $uid\n",3,$this->logfile);
1264
+										"() Restore status for $uid\n", 3, $this->logfile);
1265 1265
 								}
1266 1266
 								$event['participants'][$uid] = $event_info['stored_event']['participants'][$uid];
1267 1267
 							}
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
 					if ($this->log)
1286 1286
 					{
1287 1287
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1288
-							"()[MERGE]\n",3,$this->logfile);
1288
+							"()[MERGE]\n", 3, $this->logfile);
1289 1289
 					}
1290 1290
 					// overwrite with server data for merge
1291 1291
 					foreach ($event_info['stored_event'] as $key => $value)
@@ -1315,7 +1315,7 @@  discard block
 block discarded – undo
1315 1315
 				else
1316 1316
 				{
1317 1317
 					// no merge
1318
-					if(!isset($this->supportedFields['category']) || !isset($event['category']))
1318
+					if (!isset($this->supportedFields['category']) || !isset($event['category']))
1319 1319
 					{
1320 1320
 						$event['category'] = $event_info['stored_event']['category'];
1321 1321
 					}
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
 						if ($this->log)
1328 1328
 						{
1329 1329
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1330
-							"() No participants\n",3,$this->logfile);
1330
+							"() No participants\n", 3, $this->logfile);
1331 1331
 						}
1332 1332
 
1333 1333
 						// If this is an updated meeting, and the client doesn't support
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
 								if ($this->log)
1347 1347
 								{
1348 1348
 									error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1349
-										"() Restore resource $uid to status $status\n",3,$this->logfile);
1349
+										"() Restore resource $uid to status $status\n", 3, $this->logfile);
1350 1350
 								}
1351 1351
 								// Add it back in
1352 1352
 								$event['participants'][$uid] = $status;
@@ -1434,8 +1434,7 @@  discard block
 block discarded – undo
1434 1434
 						}
1435 1435
 						// for resources check which new-status to give (eg. with direct booking permision 'A' instead 'U')
1436 1436
 						$event['participants'][$user] = calendar_so::combine_status(
1437
-							$user < 0 || !isset($this->resources[$user[0]]['new_status']) ? 'U' :
1438
-							ExecMethod($this->resources[$user[0]]['new_status'], substr($user, 1)));
1437
+							$user < 0 || !isset($this->resources[$user[0]]['new_status']) ? 'U' : ExecMethod($this->resources[$user[0]]['new_status'], substr($user, 1)));
1439 1438
 					}
1440 1439
 				}
1441 1440
 				// check if an owner is set and the current user has add rights
@@ -1500,9 +1499,9 @@  discard block
 block discarded – undo
1500 1499
 
1501 1500
 			if ($this->log)
1502 1501
 			{
1503
-				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '('
1504
-					. $event_info['type'] . ")\n"
1505
-					. array2string($event)."\n",3,$this->logfile);
1502
+				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.'('
1503
+					. $event_info['type'].")\n"
1504
+					. array2string($event)."\n", 3, $this->logfile);
1506 1505
 			}
1507 1506
 
1508 1507
 			// Android (any maybe others) delete recurrences by setting STATUS: CANCELLED
@@ -1510,10 +1509,10 @@  discard block
 block discarded – undo
1510 1509
 			if (in_array($event_info['type'], array('SERIES-EXCEPTION', 'SERIES-EXCEPTION-PROPAGATE', 'SERIES-PSEUDO-EXCEPTION')) &&
1511 1510
 				$event['status'] == 'CANCELLED')
1512 1511
 			{
1513
-				if (!$this->delete($event['id'] ? $event['id'] : $cal_id, $event['recurrence'],false,$skip_notification))
1512
+				if (!$this->delete($event['id'] ? $event['id'] : $cal_id, $event['recurrence'], false, $skip_notification))
1514 1513
 				{
1515 1514
 					// delete fails (because no rights), reject recurrence
1516
-					$this->set_status($event['id'] ? $event['id'] : $cal_id, $this->user, 'R', $event['recurrence'],false,true,$skip_notification);
1515
+					$this->set_status($event['id'] ? $event['id'] : $cal_id, $this->user, 'R', $event['recurrence'], false, true, $skip_notification);
1517 1516
 				}
1518 1517
 				continue;
1519 1518
 			}
@@ -1525,7 +1524,7 @@  discard block
 block discarded – undo
1525 1524
 					if ($this->log)
1526 1525
 					{
1527 1526
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1528
-							"(): event SINGLE\n",3,$this->logfile);
1527
+							"(): event SINGLE\n", 3, $this->logfile);
1529 1528
 					}
1530 1529
 
1531 1530
 					// update the event
@@ -1535,7 +1534,7 @@  discard block
 block discarded – undo
1535 1534
 						$event['reference'] = 0;
1536 1535
 						$event_to_store = $event; // prevent $event from being changed by the update method
1537 1536
 						$this->server2usertime($event_to_store);
1538
-						$updated_id = $this->update($event_to_store, true,true,false,true,$msg,$skip_notification);
1537
+						$updated_id = $this->update($event_to_store, true, true, false, true, $msg, $skip_notification);
1539 1538
 						unset($event_to_store);
1540 1539
 					}
1541 1540
 					break;
@@ -1544,7 +1543,7 @@  discard block
 block discarded – undo
1544 1543
 					if ($this->log)
1545 1544
 					{
1546 1545
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1547
-							"(): event SERIES-MASTER\n",3,$this->logfile);
1546
+							"(): event SERIES-MASTER\n", 3, $this->logfile);
1548 1547
 					}
1549 1548
 
1550 1549
 					// remove all known pseudo exceptions and update the event
@@ -1554,8 +1553,8 @@  discard block
 block discarded – undo
1554 1553
 						$days = $this->so->get_recurrence_exceptions($event_info['stored_event'], $this->tzid, 0, 0, $filter);
1555 1554
 						if ($this->log)
1556 1555
 						{
1557
-							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."(EXCEPTIONS MAPPING):\n" .
1558
-								array2string($days)."\n",3,$this->logfile);
1556
+							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."(EXCEPTIONS MAPPING):\n".
1557
+								array2string($days)."\n", 3, $this->logfile);
1559 1558
 						}
1560 1559
 						if (is_array($days))
1561 1560
 						{
@@ -1573,7 +1572,7 @@  discard block
 block discarded – undo
1573 1572
 
1574 1573
 						$event_to_store = $event; // prevent $event from being changed by the update method
1575 1574
 						$this->server2usertime($event_to_store);
1576
-						$updated_id = $this->update($event_to_store, true,true,false,true,$msg,$skip_notification);
1575
+						$updated_id = $this->update($event_to_store, true, true, false, true, $msg, $skip_notification);
1577 1576
 						unset($event_to_store);
1578 1577
 					}
1579 1578
 					break;
@@ -1583,7 +1582,7 @@  discard block
 block discarded – undo
1583 1582
 					if ($this->log)
1584 1583
 					{
1585 1584
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1586
-							"(): event SERIES-EXCEPTION\n",3,$this->logfile);
1585
+							"(): event SERIES-EXCEPTION\n", 3, $this->logfile);
1587 1586
 					}
1588 1587
 
1589 1588
 					// update event
@@ -1639,13 +1638,13 @@  discard block
 block discarded – undo
1639 1638
 							$event['owner'] = $event_info['master_event']['owner'];
1640 1639
 							$event_to_store = $event_info['master_event']; // prevent the master_event from being changed by the update method
1641 1640
 							$this->server2usertime($event_to_store);
1642
-							$this->update($event_to_store, true,true,false,true,$msg,$skip_notification);
1641
+							$this->update($event_to_store, true, true, false, true, $msg, $skip_notification);
1643 1642
 							unset($event_to_store);
1644 1643
 						}
1645 1644
 
1646 1645
 						$event_to_store = $event; // prevent $event from being changed by update method
1647 1646
 						$this->server2usertime($event_to_store);
1648
-						$updated_id = $this->update($event_to_store, true,true,false,true,$msg,$skip_notification);
1647
+						$updated_id = $this->update($event_to_store, true, true, false, true, $msg, $skip_notification);
1649 1648
 						unset($event_to_store);
1650 1649
 					}
1651 1650
 					break;
@@ -1654,7 +1653,7 @@  discard block
 block discarded – undo
1654 1653
 					if ($this->log)
1655 1654
 					{
1656 1655
 						error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
1657
-							"(): event SERIES-PSEUDO-EXCEPTION\n",3,$this->logfile);
1656
+							"(): event SERIES-PSEUDO-EXCEPTION\n", 3, $this->logfile);
1658 1657
 					}
1659 1658
 					//Horde::logMessage('importVCAL event SERIES-PSEUDO-EXCEPTION',
1660 1659
 					//	__FILE__, __LINE__, PEAR_LOG_DEBUG);
@@ -1675,7 +1674,7 @@  discard block
 block discarded – undo
1675 1674
 						// save the series master with the adjusted exceptions
1676 1675
 						$event_to_store = $event_info['master_event']; // prevent the master_event from being changed by the update method
1677 1676
 						$this->server2usertime($event_to_store);
1678
-						$updated_id = $this->update($event_to_store, true, true, false, false,$msg,$skip_notification);
1677
+						$updated_id = $this->update($event_to_store, true, true, false, false, $msg, $skip_notification);
1679 1678
 						unset($event_to_store);
1680 1679
 					}
1681 1680
 
@@ -1702,13 +1701,13 @@  discard block
 block discarded – undo
1702 1701
 							if ($event_info['acl_edit'])
1703 1702
 							{
1704 1703
 								// update all participants if we have the right to do that
1705
-								$this->update_status($event, $event_info['stored_event'],0,$skip_notification);
1704
+								$this->update_status($event, $event_info['stored_event'], 0, $skip_notification);
1706 1705
 							}
1707 1706
 							elseif (isset($event['participants'][$this->user]) || isset($event_info['stored_event']['participants'][$this->user]))
1708 1707
 							{
1709 1708
 								// update the users status only
1710 1709
 								$this->set_status($event_info['stored_event']['id'], $this->user,
1711
-									($event['participants'][$this->user] ? $event['participants'][$this->user] : 'R'), 0, true,true,$skip_notification);
1710
+									($event['participants'][$this->user] ? $event['participants'][$this->user] : 'R'), 0, true, true, $skip_notification);
1712 1711
 							}
1713 1712
 						}
1714 1713
 						break;
@@ -1720,13 +1719,13 @@  discard block
 block discarded – undo
1720 1719
 							if ($event_info['acl_edit'])
1721 1720
 							{
1722 1721
 								// update all participants if we have the right to do that
1723
-								$this->update_status($event, $event_info['stored_event'], $recurrence,$skip_notification);
1722
+								$this->update_status($event, $event_info['stored_event'], $recurrence, $skip_notification);
1724 1723
 							}
1725 1724
 							elseif (isset($event['participants'][$this->user]) || isset($event_info['master_event']['participants'][$this->user]))
1726 1725
 							{
1727 1726
 								// update the users status only
1728 1727
 								$this->set_status($event_info['master_event']['id'], $this->user,
1729
-									($event['participants'][$this->user] ? $event['participants'][$this->user] : 'R'), $recurrence, true,true,$skip_notification);
1728
+									($event['participants'][$this->user] ? $event['participants'][$this->user] : 'R'), $recurrence, true, true, $skip_notification);
1730 1729
 							}
1731 1730
 						}
1732 1731
 						break;
@@ -1743,7 +1742,7 @@  discard block
 block discarded – undo
1743 1742
 					break;
1744 1743
 
1745 1744
 				case 'SERIES-PSEUDO-EXCEPTION':
1746
-					$return_id = is_array($event_info['master_event']) ? $event_info['master_event']['id'] . ':' . $event['recurrence'] : false;
1745
+					$return_id = is_array($event_info['master_event']) ? $event_info['master_event']['id'].':'.$event['recurrence'] : false;
1747 1746
 					break;
1748 1747
 
1749 1748
 				case 'SERIES-EXCEPTION-PROPAGATE':
@@ -1756,7 +1755,7 @@  discard block
 block discarded – undo
1756 1755
 					{
1757 1756
 						// we did not have sufficient rights to propagate the status only exception to a real one
1758 1757
 						// we have to keep the SERIES-PSEUDO-EXCEPTION id and keep the event untouched
1759
-						$return_id = $event_info['master_event']['id'] . ':' . $event['recurrence'];
1758
+						$return_id = $event_info['master_event']['id'].':'.$event['recurrence'];
1760 1759
 					}
1761 1760
 					break;
1762 1761
 			}
@@ -1770,8 +1769,8 @@  discard block
 block discarded – undo
1770 1769
 			if ($this->log)
1771 1770
 			{
1772 1771
 				$event_info['stored_event'] = $this->read($event_info['stored_event']['id']);
1773
-				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()[$updated_id]\n" .
1774
-					array2string($event_info['stored_event'])."\n",3,$this->logfile);
1772
+				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()[$updated_id]\n".
1773
+					array2string($event_info['stored_event'])."\n", 3, $this->logfile);
1775 1774
 			}
1776 1775
 		}
1777 1776
 		date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
@@ -1793,19 +1792,19 @@  discard block
 block discarded – undo
1793 1792
 	 * @return mixed on success: int $cal_id > 0, on error or conflicts false.
1794 1793
 	 *	Conflicts are passed to $this->conflict_callback
1795 1794
 	 */
1796
-	public function update(&$event,$ignore_conflicts=false,$touch_modified=true,$ignore_acl=false,$updateTS=true,&$messages=null, $skip_notification=false)
1795
+	public function update(&$event, $ignore_conflicts = false, $touch_modified = true, $ignore_acl = false, $updateTS = true, &$messages = null, $skip_notification = false)
1797 1796
 	{
1798
-		if($this->conflict_callback !== null)
1797
+		if ($this->conflict_callback !== null)
1799 1798
 		{
1800 1799
 			// calendar_ical overrides search(), which breaks conflict checking
1801 1800
 			// so we make sure to use the original from parent
1802 1801
 			static $bo = null;
1803
-			if(!$bo)
1802
+			if (!$bo)
1804 1803
 			{
1805 1804
 				$bo = new calendar_boupdate();
1806 1805
 			}
1807 1806
 			$conflicts = $bo->conflicts($event);
1808
-			if(is_array($conflicts) && count($conflicts) > 0)
1807
+			if (is_array($conflicts) && count($conflicts) > 0)
1809 1808
 			{
1810 1809
 				call_user_func_array($this->conflict_callback, array(&$event, &$conflicts));
1811 1810
 				return false;
@@ -1826,11 +1825,11 @@  discard block
 block discarded – undo
1826 1825
 	{
1827 1826
 		if ($this->debug) error_log(__METHOD__."(".array2string($event).', old_alarms='.array2string($old_alarms).", $user,)");
1828 1827
 		$modified = 0;
1829
-		foreach($event['alarm'] as &$alarm)
1828
+		foreach ($event['alarm'] as &$alarm)
1830 1829
 		{
1831 1830
 			// check if alarm is already stored or from other users
1832 1831
 			$found = false;
1833
-			foreach($old_alarms as $id => $old_alarm)
1832
+			foreach ($old_alarms as $id => $old_alarm)
1834 1833
 			{
1835 1834
 				// not current users alarm --> ignore
1836 1835
 				if (!$old_alarm['all'] && $old_alarm['owner'] != $user)
@@ -1846,7 +1845,7 @@  discard block
 block discarded – undo
1846 1845
 					break;
1847 1846
 				}
1848 1847
 			}
1849
-			if ($this->debug) error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) processing ".($found?'existing':'new')." alarm ".array2string($alarm));
1848
+			if ($this->debug) error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) processing ".($found ? 'existing' : 'new')." alarm ".array2string($alarm));
1850 1849
 			if (!empty($alarm['attrs']['X-LIC-ERROR']))
1851 1850
 			{
1852 1851
 				if ($this->debug) error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) ignored X-LIC-ERROR=".array2string($alarm['X-LIC-ERROR']));
@@ -1874,7 +1873,7 @@  discard block
 block discarded – undo
1874 1873
 			}
1875 1874
 		}
1876 1875
 		// remove all old alarms left from current user
1877
-		foreach($old_alarms as $id => $old_alarm)
1876
+		foreach ($old_alarms as $id => $old_alarm)
1878 1877
 		{
1879 1878
 			// not current users alarm --> ignore
1880 1879
 			if (!$old_alarm['all'] && $old_alarm['owner'] != $user)
@@ -1897,7 +1896,7 @@  discard block
 block discarded – undo
1897 1896
 	 * @param string $what ='value'
1898 1897
 	 * @return mixed
1899 1898
 	 */
1900
-	static function _get_attribute($components,$name,$what='value')
1899
+	static function _get_attribute($components, $name, $what = 'value')
1901 1900
 	{
1902 1901
 		foreach ($components as $attribute)
1903 1902
 		{
@@ -1932,7 +1931,7 @@  discard block
 block discarded – undo
1932 1931
 						case 'DURATION':
1933 1932
 							if (isset($vattr['params']['RELATED']) && $vattr['params']['RELATED'] == 'END')
1934 1933
 							{
1935
-								$alarm['offset'] = $duration -$vattr['value'];
1934
+								$alarm['offset'] = $duration - $vattr['value'];
1936 1935
 							}
1937 1936
 							elseif (isset($vattr['params']['RELATED']) && $vattr['params']['RELATED'] != 'START')
1938 1937
 							{
@@ -1948,7 +1947,7 @@  discard block
 block discarded – undo
1948 1947
 							$alarm['time'] = $vattr['value'];
1949 1948
 							break;
1950 1949
 						default:
1951
-							error_log('VALARM/TRIGGER: unsupported value type:' . $vtype);
1950
+							error_log('VALARM/TRIGGER: unsupported value type:'.$vtype);
1952 1951
 					}
1953 1952
 					break;
1954 1953
 
@@ -1973,9 +1972,9 @@  discard block
 block discarded – undo
1973 1972
 		return 0;
1974 1973
 	}
1975 1974
 
1976
-	function setSupportedFields($_productManufacturer='', $_productName='')
1975
+	function setSupportedFields($_productManufacturer = '', $_productName = '')
1977 1976
 	{
1978
-		$state =& $_SESSION['SyncML.state'];
1977
+		$state = & $_SESSION['SyncML.state'];
1979 1978
 		if (isset($state))
1980 1979
 		{
1981 1980
 			$deviceInfo = $state->getClientDeviceInfo();
@@ -2272,10 +2271,10 @@  discard block
 block discarded – undo
2272 2271
 		if ($this->log)
2273 2272
 		{
2274 2273
 			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2275
-				'(' . $this->productManufacturer .
2276
-				', '. $this->productName .', ' .
2277
-				($this->tzid ? $this->tzid : Api\DateTime::$user_timezone->getName()) .
2278
-				', ' . $this->calendarOwner . ")\n" , 3, $this->logfile);
2274
+				'('.$this->productManufacturer.
2275
+				', '.$this->productName.', '.
2276
+				($this->tzid ? $this->tzid : Api\DateTime::$user_timezone->getName()).
2277
+				', '.$this->calendarOwner.")\n", 3, $this->logfile);
2279 2278
 		}
2280 2279
 
2281 2280
 		//Horde::logMessage('setSupportedFields(' . $this->productManufacturer . ', '
@@ -2293,12 +2292,12 @@  discard block
 block discarded – undo
2293 2292
      *                         utf-8 for new format, iso-8859-1 for old format.
2294 2293
 	 * @return Iterator|array|boolean Iterator if resource given or array of events on success, false on failure
2295 2294
 	 */
2296
-	function icaltoegw($_vcalData, $principalURL='', $charset=null)
2295
+	function icaltoegw($_vcalData, $principalURL = '', $charset = null)
2297 2296
 	{
2298 2297
 		if ($this->log)
2299 2298
 		{
2300
-			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($principalURL, $charset)\n" .
2301
-				array2string($_vcalData)."\n",3,$this->logfile);
2299
+			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($principalURL, $charset)\n".
2300
+				array2string($_vcalData)."\n", 3, $this->logfile);
2302 2301
 		}
2303 2302
 
2304 2303
 		if (!is_array($this->supportedFields)) $this->setSupportedFields();
@@ -2333,14 +2332,14 @@  discard block
 block discarded – undo
2333 2332
 			if ($this->log)
2334 2333
 			{
2335 2334
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
2336
-					"(): No vCalendar Container found!\n",3,$this->logfile);
2335
+					"(): No vCalendar Container found!\n", 3, $this->logfile);
2337 2336
 			}
2338 2337
 			date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
2339 2338
 			return false;
2340 2339
 		}
2341 2340
 		foreach ($vcal->getComponents() as $component)
2342 2341
 		{
2343
-			if (($event = $this->_ical2egw_callback($component,$this->tzid,$principalURL,$vcal)))
2342
+			if (($event = $this->_ical2egw_callback($component, $this->tzid, $principalURL, $vcal)))
2344 2343
 			{
2345 2344
 				$events[] = $event;
2346 2345
 			}
@@ -2385,13 +2384,13 @@  discard block
 block discarded – undo
2385 2384
 	 * @param Horde_Icalendar $container =null container to access attributes on container
2386 2385
 	 * @return array|boolean event array or false if $component is no Horde_Icalendar_Vevent
2387 2386
 	 */
2388
-	function _ical2egw_callback(Horde_Icalendar $component, $tzid, $principalURL='', Horde_Icalendar $container=null)
2387
+	function _ical2egw_callback(Horde_Icalendar $component, $tzid, $principalURL = '', Horde_Icalendar $container = null)
2389 2388
 	{
2390 2389
 		//unset($component->_container); _debug_array($component);
2391 2390
 
2392 2391
 		if ($this->log)
2393 2392
 		{
2394
-			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.'() '.get_class($component)." found\n",3,$this->logfile);
2393
+			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.'() '.get_class($component)." found\n", 3, $this->logfile);
2395 2394
 		}
2396 2395
 
2397 2396
 		// eg. Mozilla holiday calendars contain only a X-WR-TIMEZONE on vCalendar component
@@ -2451,16 +2450,16 @@  discard block
 block discarded – undo
2451 2450
 	 * @param Horde_Icalendar $container =null container to access attributes on container
2452 2451
 	 * @return array|boolean			event on success, false on failure
2453 2452
 	 */
2454
-	function vevent2egw($component, $version, $supportedFields, $principalURL='', $check_component='Horde_Icalendar_Vevent', Horde_Icalendar $container=null)
2453
+	function vevent2egw($component, $version, $supportedFields, $principalURL = '', $check_component = 'Horde_Icalendar_Vevent', Horde_Icalendar $container = null)
2455 2454
 	{
2456
-		unset($principalURL);	// not longer used, but required in function signature
2455
+		unset($principalURL); // not longer used, but required in function signature
2457 2456
 
2458 2457
 		if ($check_component && !is_a($component, $check_component))
2459 2458
 		{
2460 2459
 			if ($this->log)
2461 2460
 			{
2462
-				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.'()' .
2463
-					get_class($component)." found\n",3,$this->logfile);
2461
+				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.'()'.
2462
+					get_class($component)." found\n", 3, $this->logfile);
2464 2463
 			}
2465 2464
 			return false;
2466 2465
 		}
@@ -2476,11 +2475,11 @@  discard block
 block discarded – undo
2476 2475
 
2477 2476
 		$isDate = false;
2478 2477
 		$event		= array();
2479
-		$alarms		= array();
2480
-		$vcardData	= array(
2478
+		$alarms = array();
2479
+		$vcardData = array(
2481 2480
 			'recur_type'		=> MCAL_RECUR_NONE,
2482 2481
 			'recur_exception'	=> array(),
2483
-			'priority'          => 0,	// iCalendar default is 0=undefined, not EGroupware 5=normal
2482
+			'priority'          => 0, // iCalendar default is 0=undefined, not EGroupware 5=normal
2484 2483
 		);
2485 2484
 		// we need to parse DTSTART, DTEND or DURATION (in that order!) first
2486 2485
 		foreach (array_merge(
@@ -2497,7 +2496,7 @@  discard block
 block discarded – undo
2497 2496
 						$isDate = true;
2498 2497
 					}
2499 2498
 					$dtstart_ts = is_numeric($attributes['value']) ? $attributes['value'] : $this->date2ts($attributes['value']);
2500
-					$vcardData['start']	= $dtstart_ts;
2499
+					$vcardData['start'] = $dtstart_ts;
2501 2500
 
2502 2501
 					// set event timezone from dtstart, if specified there
2503 2502
 					if (!empty($attributes['params']['TZID']))
@@ -2515,18 +2514,18 @@  discard block
 block discarded – undo
2515 2514
 							}
2516 2515
 							else
2517 2516
 							{
2518
-								error_log(__METHOD__ . '() unknown TZID='
2519
-									. $attributes['params']['TZID'] . ', defaulting to timezone "'
2520
-									. date_default_timezone_get() . '".'.array2string($tz));
2521
-								$event['tzid'] = date_default_timezone_get();	// default to current timezone
2517
+								error_log(__METHOD__.'() unknown TZID='
2518
+									. $attributes['params']['TZID'].', defaulting to timezone "'
2519
+									. date_default_timezone_get().'".'.array2string($tz));
2520
+								$event['tzid'] = date_default_timezone_get(); // default to current timezone
2522 2521
 							}
2523 2522
 						}
2524
-						catch(Exception $e)
2523
+						catch (Exception $e)
2525 2524
 						{
2526
-							error_log(__METHOD__ . '() unknown TZID='
2527
-								. $attributes['params']['TZID'] . ', defaulting to timezone "'
2528
-								. date_default_timezone_get() . '".'.$e->getMessage());
2529
-							$event['tzid'] = date_default_timezone_get();	// default to current timezone
2525
+							error_log(__METHOD__.'() unknown TZID='
2526
+								. $attributes['params']['TZID'].', defaulting to timezone "'
2527
+								. date_default_timezone_get().'".'.$e->getMessage());
2528
+							$event['tzid'] = date_default_timezone_get(); // default to current timezone
2530 2529
 						}
2531 2530
 					}
2532 2531
 					// if no timezone given and one is specified in class (never the case for CalDAV)
@@ -2550,11 +2549,11 @@  discard block
 block discarded – undo
2550 2549
 
2551 2550
 				case 'DTEND':
2552 2551
 					$dtend_ts = is_numeric($attributes['value']) ? $attributes['value'] : $this->date2ts($attributes['value']);
2553
-					if (date('H:i:s',$dtend_ts) == '00:00:00')
2552
+					if (date('H:i:s', $dtend_ts) == '00:00:00')
2554 2553
 					{
2555 2554
 						$dtend_ts -= 1;
2556 2555
 					}
2557
-					$vcardData['end']	= $dtend_ts;
2556
+					$vcardData['end'] = $dtend_ts;
2558 2557
 					break;
2559 2558
 
2560 2559
 				case 'DURATION':	// clients can use DTSTART+DURATION, instead of DTSTART+DTEND
@@ -2574,7 +2573,7 @@  discard block
 block discarded – undo
2574 2573
 			if ($this->log)
2575 2574
 			{
2576 2575
 				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2577
-					. "() DTSTART missing!\n",3,$this->logfile);
2576
+					. "() DTSTART missing!\n", 3, $this->logfile);
2578 2577
 			}
2579 2578
 			return false; // not a valid entry
2580 2579
 		}
@@ -2593,7 +2592,7 @@  discard block
 block discarded – undo
2593 2592
 				case 'X-MICROSOFT-CDO-ALLDAYEVENT':
2594 2593
 					if (isset($supportedFields['whole_day']))
2595 2594
 					{
2596
-						$event['whole_day'] = (isset($attributes['value'])?strtoupper($attributes['value'])=='TRUE':true);
2595
+						$event['whole_day'] = (isset($attributes['value']) ?strtoupper($attributes['value']) == 'TRUE' : true);
2597 2596
 					}
2598 2597
 					break;
2599 2598
 				case 'AALARM':
@@ -2623,18 +2622,18 @@  discard block
 block discarded – undo
2623 2622
 					$vcardData['recurrence'] = $attributes['value'];
2624 2623
 					break;
2625 2624
 				case 'LOCATION':
2626
-					$vcardData['location']	= str_replace("\r\n", "\n", $attributes['value']);
2625
+					$vcardData['location'] = str_replace("\r\n", "\n", $attributes['value']);
2627 2626
 					break;
2628 2627
 				case 'RRULE':
2629 2628
 					$recurence = $attributes['value'];
2630 2629
 					$vcardData['recur_interval'] = 1;
2631
-					$type = preg_match('/FREQ=([^;: ]+)/i',$recurence,$matches) ? $matches[1] : $recurence[0];
2630
+					$type = preg_match('/FREQ=([^;: ]+)/i', $recurence, $matches) ? $matches[1] : $recurence[0];
2632 2631
 					// vCard 2.0 values for all types
2633
-					if (preg_match('/UNTIL=([0-9TZ]+)/',$recurence,$matches))
2632
+					if (preg_match('/UNTIL=([0-9TZ]+)/', $recurence, $matches))
2634 2633
 					{
2635 2634
 						$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($matches[1]);
2636 2635
 						// If it couldn't be parsed, treat it as not set
2637
-						if(is_string($vcardData['recur_enddate']))
2636
+						if (is_string($vcardData['recur_enddate']))
2638 2637
 						{
2639 2638
 							unset($vcardData['recur_enddate']);
2640 2639
 						}
@@ -2644,16 +2643,16 @@  discard block
 block discarded – undo
2644 2643
 							self::check_fix_endate($vcardData);
2645 2644
 						}
2646 2645
 					}
2647
-					elseif (preg_match('/COUNT=([0-9]+)/',$recurence,$matches))
2646
+					elseif (preg_match('/COUNT=([0-9]+)/', $recurence, $matches))
2648 2647
 					{
2649 2648
 						$vcardData['recur_count'] = (int)$matches[1];
2650 2649
 					}
2651
-					if (preg_match('/INTERVAL=([0-9]+)/',$recurence,$matches))
2650
+					if (preg_match('/INTERVAL=([0-9]+)/', $recurence, $matches))
2652 2651
 					{
2653
-						$vcardData['recur_interval'] = (int) $matches[1] ? (int) $matches[1] : 1;
2652
+						$vcardData['recur_interval'] = (int)$matches[1] ? (int)$matches[1] : 1;
2654 2653
 					}
2655 2654
 					$vcardData['recur_data'] = 0;
2656
-					switch($type)
2655
+					switch ($type)
2657 2656
 					{
2658 2657
 						case 'D':	// 1.0
2659 2658
 							$recurenceMatches = null;
@@ -2677,20 +2676,20 @@  discard block
 block discarded – undo
2677 2676
 						case 'W':
2678 2677
 						case 'WEEKLY':
2679 2678
 							$days = array();
2680
-							if (preg_match('/W(\d+) *((?i: [AEFHMORSTUW]{2})+)?( +([^ ]*))$/',$recurence, $recurenceMatches))		// 1.0
2679
+							if (preg_match('/W(\d+) *((?i: [AEFHMORSTUW]{2})+)?( +([^ ]*))$/', $recurence, $recurenceMatches))		// 1.0
2681 2680
 							{
2682 2681
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2683 2682
 								if (empty($recurenceMatches[2]))
2684 2683
 								{
2685
-									$days[0] = strtoupper(substr(date('D', $vcardData['start']),0,2));
2684
+									$days[0] = strtoupper(substr(date('D', $vcardData['start']), 0, 2));
2686 2685
 								}
2687 2686
 								else
2688 2687
 								{
2689
-									$days = explode(' ',trim($recurenceMatches[2]));
2688
+									$days = explode(' ', trim($recurenceMatches[2]));
2690 2689
 								}
2691 2690
 
2692 2691
 								$repeatMatches = null;
2693
-								if (preg_match('/#(\d+)/',$recurenceMatches[4],$repeatMatches))
2692
+								if (preg_match('/#(\d+)/', $recurenceMatches[4], $repeatMatches))
2694 2693
 								{
2695 2694
 									if ($repeatMatches[1]) $vcardData['recur_count'] = $repeatMatches[1];
2696 2695
 								}
@@ -2701,21 +2700,21 @@  discard block
 block discarded – undo
2701 2700
 
2702 2701
 								$recur_days = $this->recur_days_1_0;
2703 2702
 							}
2704
-							elseif (preg_match('/BYDAY=([^;: ]+)/',$recurence,$recurenceMatches))	// 2.0
2703
+							elseif (preg_match('/BYDAY=([^;: ]+)/', $recurence, $recurenceMatches))	// 2.0
2705 2704
 							{
2706
-								$days = explode(',',$recurenceMatches[1]);
2705
+								$days = explode(',', $recurenceMatches[1]);
2707 2706
 								$recur_days = $this->recur_days;
2708 2707
 							}
2709 2708
 							else	// no day given, use the day of dtstart
2710 2709
 							{
2711
-								$vcardData['recur_data'] |= 1 << (int)date('w',$vcardData['start']);
2710
+								$vcardData['recur_data'] |= 1 << (int)date('w', $vcardData['start']);
2712 2711
 								$vcardData['recur_type'] = MCAL_RECUR_WEEKLY;
2713 2712
 							}
2714 2713
 							if ($days)
2715 2714
 							{
2716 2715
 								foreach ($recur_days as $id => $day)
2717 2716
 								{
2718
-									if (in_array(strtoupper(substr($day,0,2)),$days))
2717
+									if (in_array(strtoupper(substr($day, 0, 2)), $days))
2719 2718
 									{
2720 2719
 										$vcardData['recur_data'] |= $id;
2721 2720
 									}
@@ -2731,17 +2730,17 @@  discard block
 block discarded – undo
2731 2730
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2732 2731
 								$vcardData['recur_count'] = $recurenceMatches[2];
2733 2732
 							}
2734
-							elseif (preg_match('/MD(\d+)(?: [^ ]+)? ([0-9TZ]+)/',$recurence, $recurenceMatches))
2733
+							elseif (preg_match('/MD(\d+)(?: [^ ]+)? ([0-9TZ]+)/', $recurence, $recurenceMatches))
2735 2734
 							{
2736 2735
 								$vcardData['recur_type'] = MCAL_RECUR_MONTHLY_MDAY;
2737 2736
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2738 2737
 								$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[2]);
2739 2738
 							}
2740
-							elseif (preg_match('/MP(\d+) (.*) (.*) (.*)/',$recurence, $recurenceMatches))
2739
+							elseif (preg_match('/MP(\d+) (.*) (.*) (.*)/', $recurence, $recurenceMatches))
2741 2740
 							{
2742 2741
 								$vcardData['recur_type'] = MCAL_RECUR_MONTHLY_WDAY;
2743 2742
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2744
-								if (preg_match('/#(\d+)/',$recurenceMatches[4],$recurenceMatches))
2743
+								if (preg_match('/#(\d+)/', $recurenceMatches[4], $recurenceMatches))
2745 2744
 								{
2746 2745
 									$vcardData['recur_count'] = $recurenceMatches[1];
2747 2746
 								}
@@ -2758,7 +2757,7 @@  discard block
 block discarded – undo
2758 2757
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2759 2758
 								$vcardData['recur_count'] = $recurenceMatches[2];
2760 2759
 							}
2761
-							elseif (preg_match('/YM(\d+)(?: [^ ]+)? ([0-9TZ]+)/',$recurence, $recurenceMatches))
2760
+							elseif (preg_match('/YM(\d+)(?: [^ ]+)? ([0-9TZ]+)/', $recurence, $recurenceMatches))
2762 2761
 							{
2763 2762
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2764 2763
 								$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[2]);
@@ -2772,11 +2771,11 @@  discard block
 block discarded – undo
2772 2771
 							}
2773 2772
 							// handle FREQ=YEARLY;BYDAY= as FREQ=MONTHLY;BYDAY= with 12*INTERVAL
2774 2773
 							$vcardData['recur_interval'] = $vcardData['recur_interval'] ?
2775
-								12*$vcardData['recur_interval'] : 12;
2774
+								12 * $vcardData['recur_interval'] : 12;
2776 2775
 							// fall-through
2777 2776
 						case 'MONTHLY':
2778 2777
 							// does currently NOT parse BYDAY or BYMONTH, it has to be specified/identical to DTSTART
2779
-							$vcardData['recur_type'] = strpos($recurence,'BYDAY') !== false ?
2778
+							$vcardData['recur_type'] = strpos($recurence, 'BYDAY') !== false ?
2780 2779
 								MCAL_RECUR_MONTHLY_WDAY : MCAL_RECUR_MONTHLY_MDAY;
2781 2780
 							break;
2782 2781
 					}
@@ -2832,11 +2831,11 @@  discard block
 block discarded – undo
2832 2831
 						(strpos($this->productName, 'outlook') !== false
2833 2832
 							|| strpos($this->productName, 'pocket pc') !== false))
2834 2833
 					{
2835
-						$vcardData['priority'] = (int) $this->priority_funambol2egw[$attributes['value']];
2834
+						$vcardData['priority'] = (int)$this->priority_funambol2egw[$attributes['value']];
2836 2835
 					}
2837 2836
 					else
2838 2837
 					{
2839
-						$vcardData['priority'] = (int) $this->priority_ical2egw[$attributes['value']];
2838
+						$vcardData['priority'] = (int)$this->priority_ical2egw[$attributes['value']];
2840 2839
 					}
2841 2840
 					break;
2842 2841
 				case 'CATEGORIES':
@@ -2850,10 +2849,10 @@  discard block
 block discarded – undo
2850 2849
 					}
2851 2850
 					break;
2852 2851
 				case 'ORGANIZER':
2853
-					$event['organizer'] = $attributes['value'];	// no egw field, but needed in AS
2854
-					if (strtolower(substr($event['organizer'],0,7)) == 'mailto:')
2852
+					$event['organizer'] = $attributes['value']; // no egw field, but needed in AS
2853
+					if (strtolower(substr($event['organizer'], 0, 7)) == 'mailto:')
2855 2854
 					{
2856
-						$event['organizer'] = substr($event['organizer'],7);
2855
+						$event['organizer'] = substr($event['organizer'], 7);
2857 2856
 					}
2858 2857
 					if (!empty($attributes['params']['CN']))
2859 2858
 					{
@@ -2890,19 +2889,19 @@  discard block
 block discarded – undo
2890 2889
 					}
2891 2890
 					// try parsing email and cn from attendee
2892 2891
 					elseif (preg_match('/mailto:([@.a-z0-9_-]+)|mailto:"?([.a-z0-9_ -]*)"?[ ]*<([@.a-z0-9_-]*)>/i',
2893
-						$attributes['value'],$matches))
2892
+						$attributes['value'], $matches))
2894 2893
 					{
2895 2894
 						$email = $matches[1] ? $matches[1] : $matches[3];
2896
-						$cn = isset($matches[2]) ? $matches[2]: '';
2895
+						$cn = isset($matches[2]) ? $matches[2] : '';
2897 2896
 					}
2898 2897
 					elseif (!empty($attributes['value']) &&
2899 2898
 						preg_match('/"?([.a-z0-9_ -]*)"?[ ]*<([@.a-z0-9_-]*)>/i',
2900
-						$attributes['value'],$matches))
2899
+						$attributes['value'], $matches))
2901 2900
 					{
2902 2901
 						$cn = $matches[1];
2903 2902
 						$email = $matches[2];
2904 2903
 					}
2905
-					elseif (strpos($attributes['value'],'@') !== false)
2904
+					elseif (strpos($attributes['value'], '@') !== false)
2906 2905
 					{
2907 2906
 						$email = $attributes['value'];
2908 2907
 					}
@@ -2919,7 +2918,7 @@  discard block
 block discarded – undo
2919 2918
 						if ($this->log)
2920 2919
 						{
2921 2920
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2922
-								. "(): Found X-EGROUPWARE-UID: '$uid'\n",3,$this->logfile);
2921
+								. "(): Found X-EGROUPWARE-UID: '$uid'\n", 3, $this->logfile);
2923 2922
 						}
2924 2923
 					}
2925 2924
 					elseif ($attributes['value'] == 'Unknown')
@@ -2937,7 +2936,7 @@  discard block
 block discarded – undo
2937 2936
 						if ($this->log)
2938 2937
 						{
2939 2938
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2940
-								. "() Found account: '$uid', '$cn', '$email'\n",3,$this->logfile);
2939
+								. "() Found account: '$uid', '$cn', '$email'\n", 3, $this->logfile);
2941 2940
 						}
2942 2941
 					}
2943 2942
 					if (!$uid)
@@ -2954,9 +2953,9 @@  discard block
 block discarded – undo
2954 2953
 							$cn = str_replace(array('\\,', '\\;', '\\:', '\\\\'),
2955 2954
 										array(',', ';', ':', '\\'),
2956 2955
 										$attributes['params']['CN']);
2957
-							if ($cn[0] == '"' && substr($cn,-1) == '"')
2956
+							if ($cn[0] == '"' && substr($cn, -1) == '"')
2958 2957
 							{
2959
-								$cn = substr($cn,1,-1);
2958
+								$cn = substr($cn, 1, -1);
2960 2959
 							}
2961 2960
 							// not searching for $cn, as match can be not unique or without an email address
2962 2961
 							// --> notification will fail, better store just as email
@@ -2965,19 +2964,19 @@  discard block
 block discarded – undo
2965 2964
 						if ($this->log)
2966 2965
 						{
2967 2966
 							error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2968
-								. "() Search participant: '$cn', '$email'\n",3,$this->logfile);
2967
+								. "() Search participant: '$cn', '$email'\n", 3, $this->logfile);
2969 2968
 						}
2970 2969
 
2971 2970
 						//elseif (//$attributes['params']['CUTYPE'] == 'GROUP'
2972
-						if (preg_match('/(.*) '. lang('Group') . '/', $cn, $matches))
2971
+						if (preg_match('/(.*) '.lang('Group').'/', $cn, $matches))
2973 2972
 						{
2974 2973
 							// we found a group
2975 2974
 							if ($this->log)
2976 2975
 							{
2977 2976
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
2978
-									. "() Found group: '$matches[1]', '$cn', '$email'\n",3,$this->logfile);
2977
+									. "() Found group: '$matches[1]', '$cn', '$email'\n", 3, $this->logfile);
2979 2978
 							}
2980
-							if (($uid =  $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g')))
2979
+							if (($uid = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g')))
2981 2980
 							{
2982 2981
 								//Horde::logMessage("vevent2egw: group participant $uid",
2983 2982
 								//			__FILE__, __LINE__, PEAR_LOG_DEBUG);
@@ -2991,7 +2990,7 @@  discard block
 block discarded – undo
2991 2990
 										//Horde::logMessage("vevent2egw: set status to " . $status,
2992 2991
 										//		__FILE__, __LINE__, PEAR_LOG_DEBUG);
2993 2992
 										$vcardData['participants'][$this->user] =
2994
-											calendar_so::combine_status($status,$quantity,$role);
2993
+											calendar_so::combine_status($status, $quantity, $role);
2995 2994
 									}
2996 2995
 								}
2997 2996
 								$status = 'U'; // keep the group
@@ -3000,36 +2999,36 @@  discard block
 block discarded – undo
3000 2999
 						}
3001 3000
 						elseif (empty($searcharray))
3002 3001
 						{
3003
-							continue;	// participants without email AND CN --> ignore it
3002
+							continue; // participants without email AND CN --> ignore it
3004 3003
 						}
3005 3004
 						elseif ((list($data) = $this->addressbook->search($searcharray,
3006
-							array('id','egw_addressbook.account_id as account_id','n_fn'),
3005
+							array('id', 'egw_addressbook.account_id as account_id', 'n_fn'),
3007 3006
 							'egw_addressbook.account_id IS NOT NULL DESC, n_fn IS NOT NULL DESC',
3008
-							'','',false,'OR')))
3007
+							'', '', false, 'OR')))
3009 3008
 						{
3010 3009
 							// found an addressbook entry
3011 3010
 							$uid = $data['account_id'] ? (int)$data['account_id'] : 'c'.$data['id'];
3012 3011
 							if ($this->log)
3013 3012
 							{
3014 3013
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
3015
-									. "() Found addressbook entry: '$uid', '$cn', '$email'\n",3,$this->logfile);
3014
+									. "() Found addressbook entry: '$uid', '$cn', '$email'\n", 3, $this->logfile);
3016 3015
 							}
3017 3016
 						}
3018 3017
 						else
3019 3018
 						{
3020 3019
 							if (!$email)
3021 3020
 							{
3022
-								$email = '[email protected]';	// set dummy email to store the CN
3021
+								$email = '[email protected]'; // set dummy email to store the CN
3023 3022
 							}
3024
-							$uid = 'e'. ($cn ? $cn . ' <' . $email . '>' : $email);
3023
+							$uid = 'e'.($cn ? $cn.' <'.$email.'>' : $email);
3025 3024
 							if ($this->log)
3026 3025
 							{
3027 3026
 								error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
3028
-									. "() Not Found, create dummy: '$uid', '$cn', '$email'\n",3,$this->logfile);
3027
+									. "() Not Found, create dummy: '$uid', '$cn', '$email'\n", 3, $this->logfile);
3029 3028
 							}
3030 3029
 						}
3031 3030
 					}
3032
-					switch($attributes['name'])
3031
+					switch ($attributes['name'])
3033 3032
 					{
3034 3033
 						case 'ATTENDEE':
3035 3034
 							if (!isset($attributes['params']['ROLE']) &&
@@ -3043,7 +3042,7 @@  discard block
 block discarded – undo
3043 3042
 								// keep role 'CHAIR' from an external organizer, even if he is a regular participant with a different role
3044 3043
 								// as this is currently the only way to store an external organizer and send him iMip responses
3045 3044
 								$q = $r = null;
3046
-								if (isset($vcardData['participants'][$uid]) && ($s=$vcardData['participants'][$uid]) &&
3045
+								if (isset($vcardData['participants'][$uid]) && ($s = $vcardData['participants'][$uid]) &&
3047 3046
 									calendar_so::split_status($s, $q, $r) && $r == 'CHAIR')
3048 3047
 								{
3049 3048
 									$role = 'CHAIR';
@@ -3057,7 +3056,7 @@  discard block
 block discarded – undo
3057 3056
 									if (!$this->calendarOwner && is_numeric($uid) && $role == 'CHAIR')
3058 3057
 										$component->getAttribute('ORGANIZER');
3059 3058
 								}
3060
-								catch(Horde_Icalendar_Exception $e)
3059
+								catch (Horde_Icalendar_Exception $e)
3061 3060
 								{
3062 3061
 									// we can store the ORGANIZER as event owner
3063 3062
 									$event['owner'] = $uid;
@@ -3113,7 +3112,7 @@  discard block
 block discarded – undo
3113 3112
 					break;
3114 3113
 
3115 3114
 				case 'ATTACH':
3116
-					if ($attributes['params'] && !empty($attributes['params']['FMTTYPE'])) break;	// handeled by managed attachment code
3115
+					if ($attributes['params'] && !empty($attributes['params']['FMTTYPE'])) break; // handeled by managed attachment code
3117 3116
 					// fall throught to store external attachment url
3118 3117
 				default:	// X- attribute or other by EGroupware unsupported property
3119 3118
 					//error_log(__METHOD__."() $attributes[name] = ".array2string($attributes));
@@ -3171,7 +3170,7 @@  discard block
 block discarded – undo
3171 3170
 					if ($event['recur_type'] != MCAL_RECUR_NONE)
3172 3171
 					{
3173 3172
 						$event['reference'] = 0;
3174
-						foreach (array('recur_interval','recur_enddate','recur_data','recur_exception','recur_count') as $r)
3173
+						foreach (array('recur_interval', 'recur_enddate', 'recur_data', 'recur_exception', 'recur_count') as $r)
3175 3174
 						{
3176 3175
 							if (isset($vcardData[$r]))
3177 3176
 							{
@@ -3194,12 +3193,12 @@  discard block
 block discarded – undo
3194 3193
 			// reset recure_enddate to 00:00:00 on the last day
3195 3194
 			$rriter = calendar_rrule::event2rrule($event, false);
3196 3195
 			$last = $rriter->normalize_enddate();
3197
-			if(!is_object($last))
3196
+			if (!is_object($last))
3198 3197
 			{
3199
-				if($this->log)
3198
+				if ($this->log)
3200 3199
 				{
3201
-					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
3202
-					" Unable to determine recurrence end date.  \n".array2string($event),3, $this->logfile);
3200
+					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
3201
+					" Unable to determine recurrence end date.  \n".array2string($event), 3, $this->logfile);
3203 3202
 				}
3204 3203
 				return false;
3205 3204
 			}
@@ -3208,16 +3207,16 @@  discard block
 block discarded – undo
3208 3207
 			$event['recur_enddate'] = Api\DateTime::to($last, 'server');
3209 3208
 		}
3210 3209
 		// translate COUNT into an enddate, as we only store enddates
3211
-		elseif($event['recur_count'])
3210
+		elseif ($event['recur_count'])
3212 3211
 		{
3213 3212
 			$rriter = calendar_rrule::event2rrule($event, false);
3214 3213
 			$last = $rriter->count2date($event['recur_count']);
3215
-			if(!is_object($last))
3214
+			if (!is_object($last))
3216 3215
 			{
3217
-				if($this->log)
3216
+				if ($this->log)
3218 3217
 				{
3219 3218
 					error_log(__FILE__.'['.__LINE__.'] '.__METHOD__,
3220
-					" Unable to determine recurrence end date.  \n".array2string($event),3, $this->logfile);
3219
+					" Unable to determine recurrence end date.  \n".array2string($event), 3, $this->logfile);
3221 3220
 				}
3222 3221
 				return false;
3223 3222
 			}
@@ -3231,7 +3230,7 @@  discard block
 block discarded – undo
3231 3230
 			if ($this->productManufacturer == 'groupdav' && $container &&
3232 3231
 				($x_calendarserver_access = $container->getAttribute('X-CALENDARSERVER-ACCESS')))
3233 3232
 			{
3234
-				$event['public'] =  (int)(strtoupper($x_calendarserver_access) == 'PUBLIC');
3233
+				$event['public'] = (int)(strtoupper($x_calendarserver_access) == 'PUBLIC');
3235 3234
 			}
3236 3235
 			//error_log(__METHOD__."() X-CALENDARSERVER-ACCESS=".array2string($x_calendarserver_access).' --> public='.array2string($event['public']));
3237 3236
 		}
@@ -3252,15 +3251,15 @@  discard block
 block discarded – undo
3252 3251
 
3253 3252
 		if ($this->log)
3254 3253
 		{
3255
-			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
3256
-				array2string($event)."\n",3,$this->logfile);
3254
+			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n".
3255
+				array2string($event)."\n", 3, $this->logfile);
3257 3256
 		}
3258 3257
 		//Horde::logMessage("vevent2egw:\n" . print_r($event, true),
3259 3258
         //    	__FILE__, __LINE__, PEAR_LOG_DEBUG);
3260 3259
 		return $event;
3261 3260
 	}
3262 3261
 
3263
-	function search($_vcalData, $contentID=null, $relax=false, $charset=null)
3262
+	function search($_vcalData, $contentID = null, $relax = false, $charset = null)
3264 3263
 	{
3265 3264
 		if (($events = $this->icaltoegw($_vcalData, $charset)))
3266 3265
 		{
@@ -3281,8 +3280,8 @@  discard block
 block discarded – undo
3281 3280
 			}
3282 3281
 			if ($this->log)
3283 3282
 			{
3284
-				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."() found:\n" .
3285
-					array2string($events)."\n",3,$this->logfile);
3283
+				error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."() found:\n".
3284
+					array2string($events)."\n", 3, $this->logfile);
3286 3285
 			}
3287 3286
 		}
3288 3287
 		return array();
@@ -3321,23 +3320,23 @@  discard block
 block discarded – undo
3321 3320
 	 * @param array $extra =null extra attributes to add
3322 3321
 	 * 	X-CALENDARSERVER-MASK-UID can be used to not include an event specified by this uid as busy
3323 3322
 	 */
3324
-	function freebusy($user,$end=null,$utc=true, $charset='UTF-8', $start=null, $method='PUBLISH', array $extra=null)
3323
+	function freebusy($user, $end = null, $utc = true, $charset = 'UTF-8', $start = null, $method = 'PUBLISH', array $extra = null)
3325 3324
 	{
3326
-		if (!$start) $start = time();	// default now
3327
-		if (!$end) $end = time() + 100*DAY_s;	// default next 100 days
3325
+		if (!$start) $start = time(); // default now
3326
+		if (!$end) $end = time() + 100 * DAY_s; // default next 100 days
3328 3327
 
3329 3328
 		$vcal = new Horde_Icalendar;
3330
-		$vcal->setAttribute('PRODID','-//EGroupware//NONSGML EGroupware Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
3329
+		$vcal->setAttribute('PRODID', '-//EGroupware//NONSGML EGroupware Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
3331 3330
 			strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
3332
-		$vcal->setAttribute('VERSION','2.0');
3333
-		$vcal->setAttribute('METHOD',$method);
3331
+		$vcal->setAttribute('VERSION', '2.0');
3332
+		$vcal->setAttribute('METHOD', $method);
3334 3333
 
3335
-		$vfreebusy = Horde_Icalendar::newComponent('VFREEBUSY',$vcal);
3334
+		$vfreebusy = Horde_Icalendar::newComponent('VFREEBUSY', $vcal);
3336 3335
 
3337 3336
 		$attributes = array(
3338 3337
 			'DTSTAMP' => time(),
3339
-			'DTSTART' => $this->date2ts($start,true),	// true = server-time
3340
-			'DTEND' => $this->date2ts($end,true),	// true = server-time
3338
+			'DTSTART' => $this->date2ts($start, true), // true = server-time
3339
+			'DTEND' => $this->date2ts($end, true), // true = server-time
3341 3340
 		);
3342 3341
 		if (!$utc)
3343 3342
 		{
@@ -3348,9 +3347,9 @@  discard block
 block discarded – undo
3348 3347
 		}
3349 3348
 		if (is_null($extra)) $extra = array(
3350 3349
 			'URL' => $this->freebusy_url($user),
3351
-			'ORGANIZER' => 'mailto:'.$GLOBALS['egw']->accounts->id2name($user,'account_email'),
3350
+			'ORGANIZER' => 'mailto:'.$GLOBALS['egw']->accounts->id2name($user, 'account_email'),
3352 3351
 		);
3353
-		foreach($attributes+$extra as $attr => $value)
3352
+		foreach ($attributes + $extra as $attr => $value)
3354 3353
 		{
3355 3354
 			$vfreebusy->setAttribute($attr, $value);
3356 3355
 		}
@@ -3376,16 +3375,16 @@  discard block
 block discarded – undo
3376 3375
 
3377 3376
 				if ($utc)
3378 3377
 				{
3379
-					$vfreebusy->setAttribute('FREEBUSY',array(array(
3378
+					$vfreebusy->setAttribute('FREEBUSY', array(array(
3380 3379
 						'start' => $event['start'],
3381 3380
 						'end' => $event['end'],
3382 3381
 					)), array('FBTYPE' => $fbtype));
3383 3382
 				}
3384 3383
 				else
3385 3384
 				{
3386
-					$vfreebusy->setAttribute('FREEBUSY',array(array(
3387
-						'start' => date('Ymd\THis',$event['start']),
3388
-						'end' => date('Ymd\THis',$event['end']),
3385
+					$vfreebusy->setAttribute('FREEBUSY', array(array(
3386
+						'start' => date('Ymd\THis', $event['start']),
3387
+						'end' => date('Ymd\THis', $event['end']),
3389 3388
 					)), array('FBTYPE' => $fbtype));
3390 3389
 				}
3391 3390
 			}
Please login to merge, or discard this patch.
Braces   +321 added lines, -82 removed lines patch added patch discarded remove patch
@@ -183,7 +183,10 @@  discard block
 block discarded – undo
183 183
 	function __construct(&$_clientProperties = array())
184 184
 	{
185 185
 		parent::__construct();
186
-		if ($this->log) $this->logfile = $GLOBALS['egw_info']['server']['temp_dir']."/log-vcal";
186
+		if ($this->log)
187
+		{
188
+			$this->logfile = $GLOBALS['egw_info']['server']['temp_dir']."/log-vcal";
189
+		}
187 190
 		$this->clientProperties = $_clientProperties;
188 191
 		$this->vCalendar = new Horde_Icalendar;
189 192
 		$this->addressbook = new Api\Contacts;
@@ -232,10 +235,14 @@  discard block
 block discarded – undo
232 235
 			'ATTACH'        => 'attachments',
233 236
 		);
234 237
 
235
-		if (!is_array($this->supportedFields)) $this->setSupportedFields();
238
+		if (!is_array($this->supportedFields))
239
+		{
240
+			$this->setSupportedFields();
241
+		}
236 242
 
237 243
 		if ($this->productManufacturer == '' )
238
-		{	// syncevolution is broken
244
+		{
245
+// syncevolution is broken
239 246
 			$version = '2.0';
240 247
 		}
241 248
 
@@ -243,10 +250,16 @@  discard block
 block discarded – undo
243 250
 		$vcal->setAttribute('PRODID','-//EGroupware//NONSGML EGroupware Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
244 251
 			strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
245 252
 		$vcal->setAttribute('VERSION', $version);
246
-		if ($method) $vcal->setAttribute('METHOD', $method);
253
+		if ($method)
254
+		{
255
+			$vcal->setAttribute('METHOD', $method);
256
+		}
247 257
 		$events_exported = false;
248 258
 
249
-		if (!is_array($events)) $events = array($events);
259
+		if (!is_array($events))
260
+		{
261
+			$events = array($events);
262
+		}
250 263
 
251 264
 		$vtimezones_added = array();
252 265
 		foreach ($events as $event)
@@ -312,7 +325,10 @@  discard block
 block discarded – undo
312 325
 				self::$tz_cache[$event['tzid']] = calendar_timezones::DateTimeZone($event['tzid']);
313 326
 			}
314 327
 
315
-			if ($this->so->isWholeDay($event)) $event['whole_day'] = true;
328
+			if ($this->so->isWholeDay($event))
329
+			{
330
+				$event['whole_day'] = true;
331
+			}
316 332
 
317 333
 			if ($this->log)
318 334
 			{
@@ -323,7 +339,10 @@  discard block
 block discarded – undo
323 339
 
324 340
 			if ($recurrence)
325 341
 			{
326
-				if (!($master = $this->read($event['id'], 0, true, 'server'))) continue;
342
+				if (!($master = $this->read($event['id'], 0, true, 'server')))
343
+				{
344
+					continue;
345
+				}
327 346
 
328 347
 				if (!isset($this->supportedFields['participants']))
329 348
 				{
@@ -380,7 +399,8 @@  discard block
 block discarded – undo
380 399
 			if ($this->productManufacturer != 'file' && $this->uidExtension)
381 400
 			{
382 401
 				// Append UID to DESCRIPTION
383
-				if (!preg_match('/\[UID:.+\]/m', $event['description'])) {
402
+				if (!preg_match('/\[UID:.+\]/m', $event['description']))
403
+				{
384 404
 					$event['description'] .= "\n[UID:" . $event['uid'] . "]";
385 405
 				}
386 406
 			}
@@ -440,11 +460,21 @@  discard block
 block discarded – undo
440 460
 							$quantity = $role = null;
441 461
 							calendar_so::split_status($status, $quantity, $role);
442 462
 							// do not include event owner/ORGANIZER as participant in his own calendar, if he is only participant
443
-							if (count($event['participants']) == 1 && $event['owner'] == $uid) continue;
463
+							if (count($event['participants']) == 1 && $event['owner'] == $uid)
464
+							{
465
+								continue;
466
+							}
444 467
 
445
-							if (!($info = $this->resource_info($uid))) continue;
468
+							if (!($info = $this->resource_info($uid)))
469
+							{
470
+								continue;
471
+							}
446 472
 
447
-							if (in_array($status, array('X','E'))) continue;	// dont include deleted participants
473
+							if (in_array($status, array('X','E')))
474
+							{
475
+								continue;
476
+							}
477
+							// dont include deleted participants
448 478
 
449 479
 							if ($this->log)
450 480
 							{
@@ -523,24 +553,49 @@  discard block
 block discarded – undo
523 553
 							}
524 554
 							// ROLE={CHAIR|REQ-PARTICIPANT|OPT-PARTICIPANT|NON-PARTICIPANT|X-*}
525 555
 							$options = array();
526
-							if (!empty($participantCN)) $options['CN'] = $participantCN;
527
-							if (!empty($role)) $options['ROLE'] = $role;
528
-							if (!empty($status)) $options['PARTSTAT'] = $status;
529
-							if (!empty($cutype)) $options['CUTYPE'] = $cutype;
530
-							if (!empty($rsvp)) $options['RSVP'] = $rsvp;
556
+							if (!empty($participantCN))
557
+							{
558
+								$options['CN'] = $participantCN;
559
+							}
560
+							if (!empty($role))
561
+							{
562
+								$options['ROLE'] = $role;
563
+							}
564
+							if (!empty($status))
565
+							{
566
+								$options['PARTSTAT'] = $status;
567
+							}
568
+							if (!empty($cutype))
569
+							{
570
+								$options['CUTYPE'] = $cutype;
571
+							}
572
+							if (!empty($rsvp))
573
+							{
574
+								$options['RSVP'] = $rsvp;
575
+							}
531 576
 							if (!empty($info['email']) && $participantURL != 'mailto:'.$info['email'])
532 577
 							{
533 578
 								$options['EMAIL'] = $info['email'];	// only add EMAIL attribute, if not already URL, as eg. Akonadi is reported to have problems with it
534 579
 							}
535
-							if ($info['type'] != 'e') $options['X-EGROUPWARE-UID'] = (string)$uid;
536
-							if ($quantity > 1) $options['X-EGROUPWARE-QUANTITY'] = (string)$quantity;
580
+							if ($info['type'] != 'e')
581
+							{
582
+								$options['X-EGROUPWARE-UID'] = (string)$uid;
583
+							}
584
+							if ($quantity > 1)
585
+							{
586
+								$options['X-EGROUPWARE-QUANTITY'] = (string)$quantity;
587
+							}
537 588
 							$attributes['ATTENDEE'][] = $participantURL;
538 589
 							$parameters['ATTENDEE'][] = $options;
539 590
 						}
540 591
 						break;
541 592
 
542 593
 					case 'CLASS':
543
-						if ($event['public']) continue;	// public is default, no need to export, fails CalDAVTester if added as default
594
+						if ($event['public'])
595
+						{
596
+							continue;
597
+						}
598
+						// public is default, no need to export, fails CalDAVTester if added as default
544 599
 						$attributes['CLASS'] = $event['public'] ? 'PUBLIC' : 'PRIVATE';
545 600
 						// Apple iCal on OS X uses X-CALENDARSERVER-ACCESS: CONFIDENTIAL on VCALANDAR (not VEVENT!)
546 601
 						if (!$event['public'] && $this->productManufacturer == 'groupdav')
@@ -572,9 +627,18 @@  discard block
 block discarded – undo
572 627
 									'CUTYPE'   => 'INDIVIDUAL',
573 628
 									//'RSVP'     => 'FALSE',
574 629
 									);
575
-								if (!empty($organizerCN)) $options['CN'] = $organizerCN;
576
-								if (!empty($organizerEMail)) $options['EMAIL'] = $organizerEMail;
577
-								if (!empty($event['owner'])) $options['X-EGROUPWARE-UID'] = $event['owner'];
630
+								if (!empty($organizerCN))
631
+								{
632
+									$options['CN'] = $organizerCN;
633
+								}
634
+								if (!empty($organizerEMail))
635
+								{
636
+									$options['EMAIL'] = $organizerEMail;
637
+								}
638
+								if (!empty($event['owner']))
639
+								{
640
+									$options['X-EGROUPWARE-UID'] = $event['owner'];
641
+								}
578 642
 								$attributes['ATTENDEE'][] = $organizerURL;
579 643
 			    				$parameters['ATTENDEE'][] = $options;
580 644
 		    				}
@@ -603,9 +667,12 @@  discard block
 block discarded – undo
603 667
 						{
604 668
 							// Hack for CalDAVTester to export duration instead of endtime
605 669
 							if ($tzid == 'UTC' && $event['end'] - $event['start'] <= 86400)
606
-								$attributes['duration'] = $event['end'] - $event['start'];
607
-							else
608
-								$attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']);
670
+							{
671
+															$attributes['duration'] = $event['end'] - $event['start'];
672
+							}
673
+							else {
674
+															$attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']);
675
+							}
609 676
 						}
610 677
 						else
611 678
 						{
@@ -625,7 +692,11 @@  discard block
 block discarded – undo
625 692
 						break;
626 693
 
627 694
 					case 'RRULE':
628
-						if ($event['recur_type'] == MCAL_RECUR_NONE) break;		// no recuring event
695
+						if ($event['recur_type'] == MCAL_RECUR_NONE)
696
+						{
697
+							break;
698
+						}
699
+						// no recuring event
629 700
 						$rriter = calendar_rrule::event2rrule($event, false, $tzid);
630 701
 						$rrule = $rriter->generate_rrule($version);
631 702
 						if ($event['recur_enddate'])
@@ -667,7 +738,10 @@  discard block
 block discarded – undo
667 738
 						break;
668 739
 
669 740
 					case 'EXDATE':
670
-						if ($event['recur_type'] == MCAL_RECUR_NONE) break;
741
+						if ($event['recur_type'] == MCAL_RECUR_NONE)
742
+						{
743
+							break;
744
+						}
671 745
 						if (!empty($event['recur_exception']))
672 746
 						{
673 747
 							if (empty($event['whole_day']))
@@ -694,14 +768,21 @@  discard block
 block discarded – undo
694 768
 									);
695 769
 								}
696 770
 								$event['recur_exception'] = $days;
697
-								if ($version != '1.0') $parameters['EXDATE']['VALUE'] = 'DATE';
771
+								if ($version != '1.0')
772
+								{
773
+									$parameters['EXDATE']['VALUE'] = 'DATE';
774
+								}
698 775
 							}
699 776
 							$vevent->setAttribute('EXDATE', $event['recur_exception'], $parameters['EXDATE']);
700 777
 						}
701 778
 						break;
702 779
 
703 780
 					case 'PRIORITY':
704
-						if (!$event['priority']) continue;	// 0=undefined is default, no need to export, fails CalDAVTester if our default is added
781
+						if (!$event['priority'])
782
+						{
783
+							continue;
784
+						}
785
+						// 0=undefined is default, no need to export, fails CalDAVTester if our default is added
705 786
 						if ($this->productManufacturer == 'funambol' &&
706 787
 							(strpos($this->productName, 'outlook') !== false
707 788
 								|| strpos($this->productName, 'pocket pc') !== false))
@@ -715,7 +796,11 @@  discard block
 block discarded – undo
715 796
 						break;
716 797
 
717 798
 					case 'TRANSP':
718
-						if (!$event['non_blocking']) continue;	// OPAQUE is default, no need to export, fails CalDAVTester if added as default
799
+						if (!$event['non_blocking'])
800
+						{
801
+							continue;
802
+						}
803
+						// OPAQUE is default, no need to export, fails CalDAVTester if added as default
719 804
 						if ($version == '1.0')
720 805
 						{
721 806
 							$attributes['TRANSP'] = ($event['non_blocking'] ? 1 : 0);
@@ -772,7 +857,11 @@  discard block
 block discarded – undo
772 857
 						elseif ($event['recurrence'] && $event['reference'])
773 858
 						{
774 859
 							// $event['reference'] is a calendar_id, not a timestamp
775
-							if (!($revent = $this->read($event['reference']))) break;	// referenced event does not exist
860
+							if (!($revent = $this->read($event['reference'])))
861
+							{
862
+								break;
863
+							}
864
+							// referenced event does not exist
776 865
 
777 866
 							if (empty($revent['whole_day']))
778 867
 							{
@@ -898,7 +987,10 @@  discard block
 block discarded – undo
898 987
 			foreach ((array)$event['alarm'] as $alarmData)
899 988
 			{
900 989
 				// skip over alarms that don't have the minimum required info
901
-				if (!isset($alarmData['offset']) && !isset($alarmData['time'])) continue;
990
+				if (!isset($alarmData['offset']) && !isset($alarmData['time']))
991
+				{
992
+					continue;
993
+				}
902 994
 
903 995
 				// skip alarms not being set for all users and alarms owned by other users
904 996
 				if ($alarmData['all'] != true && $alarmData['owner'] != $this->user)
@@ -915,7 +1007,10 @@  discard block
 block discarded – undo
915 1007
 
916 1008
 				if ($version == '1.0')
917 1009
 				{
918
-					if ($event['title']) $description = $event['title'];
1010
+					if ($event['title'])
1011
+					{
1012
+						$description = $event['title'];
1013
+					}
919 1014
 					if ($description)
920 1015
 					{
921 1016
 						$values['DALARM']['snooze_time'] = '';
@@ -935,7 +1030,10 @@  discard block
 block discarded – undo
935 1030
 					// VCalendar 2.0 / RFC 2445
936 1031
 
937 1032
 					// RFC requires DESCRIPTION for DISPLAY
938
-					if (!$event['title'] && !$description) $description = 'Alarm';
1033
+					if (!$event['title'] && !$description)
1034
+					{
1035
+						$description = 'Alarm';
1036
+					}
939 1037
 
940 1038
 					/* Disabling for now
941 1039
 					// Lightning infinitly pops up alarms for recuring events, if the only use an offset
@@ -1126,13 +1224,20 @@  discard block
 block discarded – undo
1126 1224
 		$this->events_imported = 0;
1127 1225
 		$replace = $delete_exceptions= false;
1128 1226
 
1129
-		if (!is_array($this->supportedFields)) $this->setSupportedFields();
1227
+		if (!is_array($this->supportedFields))
1228
+		{
1229
+			$this->setSupportedFields();
1230
+		}
1130 1231
 
1131 1232
 		if (!($events = $this->icaltoegw($_vcalData, $principalURL, $charset)))
1132 1233
 		{
1133 1234
 			return false;
1134 1235
 		}
1135
-		if (!is_array($events)) $cal_id = -1;	// just to be sure, as iterator does NOT allow array access (eg. $events[0])
1236
+		if (!is_array($events))
1237
+		{
1238
+			$cal_id = -1;
1239
+		}
1240
+		// just to be sure, as iterator does NOT allow array access (eg. $events[0])
1136 1241
 
1137 1242
 		if ($cal_id > 0)
1138 1243
 		{
@@ -1140,8 +1245,14 @@  discard block
 block discarded – undo
1140 1245
 			{
1141 1246
 				$replace = $recur_date == 0;
1142 1247
 				$events[0]['id'] = $cal_id;
1143
-				if (!is_null($etag)) $events[0]['etag'] = (int) $etag;
1144
-				if ($recur_date) $events[0]['recurrence'] = $recur_date;
1248
+				if (!is_null($etag))
1249
+				{
1250
+					$events[0]['etag'] = (int) $etag;
1251
+				}
1252
+				if ($recur_date)
1253
+				{
1254
+					$events[0]['recurrence'] = $recur_date;
1255
+				}
1145 1256
 			}
1146 1257
 			elseif (($foundEvent = $this->find_event(array('id' => $cal_id), 'exact')) &&
1147 1258
 					($eventId = array_shift($foundEvent)) &&
@@ -1149,7 +1260,10 @@  discard block
 block discarded – undo
1149 1260
 			{
1150 1261
 				foreach ($events as $k => $event)
1151 1262
 				{
1152
-					if (!isset($event['uid'])) $events[$k]['uid'] = $egwEvent['uid'];
1263
+					if (!isset($event['uid']))
1264
+					{
1265
+						$events[$k]['uid'] = $egwEvent['uid'];
1266
+					}
1153 1267
 				}
1154 1268
 			}
1155 1269
 		}
@@ -1179,10 +1293,17 @@  discard block
 block discarded – undo
1179 1293
 		$msg = null;
1180 1294
 		foreach ($events as $event)
1181 1295
 		{
1182
-			if (!is_array($event)) continue; // the iterator may return false
1296
+			if (!is_array($event))
1297
+			{
1298
+				continue;
1299
+			}
1300
+			// the iterator may return false
1183 1301
 			++$this->events_imported;
1184 1302
 
1185
-			if ($this->so->isWholeDay($event)) $event['whole_day'] = true;
1303
+			if ($this->so->isWholeDay($event))
1304
+			{
1305
+				$event['whole_day'] = true;
1306
+			}
1186 1307
 			if (is_array($event['category']))
1187 1308
 			{
1188 1309
 				$event['category'] = $this->find_or_add_categories($event['category'],
@@ -1219,7 +1340,10 @@  discard block
 block discarded – undo
1219 1340
 						}
1220 1341
 						else
1221 1342
 						{
1222
-							if (!($exception = $this->read($id))) continue;
1343
+							if (!($exception = $this->read($id)))
1344
+							{
1345
+								continue;
1346
+							}
1223 1347
 							$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
1224 1348
 							$exception['reference'] = $exception['recurrence'] = 0;
1225 1349
 							$this->update($exception, true,true,false,true,$msg,$skip_notification);
@@ -1308,7 +1432,10 @@  discard block
 block discarded – undo
1308 1432
 								break;
1309 1433
 
1310 1434
 							default:
1311
-								if (!empty($value)) $event[$key] = $value;
1435
+								if (!empty($value))
1436
+								{
1437
+									$event[$key] = $value;
1438
+								}
1312 1439
 						}
1313 1440
 					}
1314 1441
 				}
@@ -1406,7 +1533,10 @@  discard block
 block discarded – undo
1406 1533
 			else // common adjustments for new events
1407 1534
 			{
1408 1535
 				unset($event['id']);
1409
-				if ($caldav_name) $event['caldav_name'] = $caldav_name;
1536
+				if ($caldav_name)
1537
+				{
1538
+					$event['caldav_name'] = $caldav_name;
1539
+				}
1410 1540
 				// set non blocking all day depending on the user setting
1411 1541
 				if (!empty($event['whole_day']) && $this->nonBlockingAllday)
1412 1542
 				{
@@ -1454,7 +1584,10 @@  discard block
 block discarded – undo
1454 1584
 					|| !isset($event['participants'][$event['owner']]))
1455 1585
 				{
1456 1586
 					$status = calendar_so::combine_status($event['owner'] == $this->user ? 'A' : 'U', 1, 'CHAIR');
1457
-					if (!is_array($event['participants'])) $event['participants'] = array();
1587
+					if (!is_array($event['participants']))
1588
+					{
1589
+						$event['participants'] = array();
1590
+					}
1458 1591
 					$event['participants'][$event['owner']] = $status;
1459 1592
 				}
1460 1593
 				else
@@ -1607,7 +1740,10 @@  discard block
 block discarded – undo
1607 1740
 								$occurence = $exception = false;
1608 1741
 								foreach ($event_info['master_event']['recur_exception'] as $exception)
1609 1742
 								{
1610
-									if ($exception > $event['start']) break;
1743
+									if ($exception > $event['start'])
1744
+									{
1745
+										break;
1746
+									}
1611 1747
 									$occurence = $exception;
1612 1748
 								}
1613 1749
 								if (!$occurence)
@@ -1697,12 +1833,15 @@  discard block
 block discarded – undo
1697 1833
 					case 'SERIES-MASTER':
1698 1834
 					case 'SERIES-EXCEPTION':
1699 1835
 					case 'SERIES-EXCEPTION-PROPAGATE':
1700
-						if (is_array($event_info['stored_event'])) // status update requires a stored event
1836
+						if (is_array($event_info['stored_event']))
1837
+						{
1838
+							// status update requires a stored event
1701 1839
 						{
1702 1840
 							if ($event_info['acl_edit'])
1703 1841
 							{
1704 1842
 								// update all participants if we have the right to do that
1705 1843
 								$this->update_status($event, $event_info['stored_event'],0,$skip_notification);
1844
+						}
1706 1845
 							}
1707 1846
 							elseif (isset($event['participants'][$this->user]) || isset($event_info['stored_event']['participants'][$this->user]))
1708 1847
 							{
@@ -1714,9 +1853,12 @@  discard block
 block discarded – undo
1714 1853
 						break;
1715 1854
 
1716 1855
 					case 'SERIES-PSEUDO-EXCEPTION':
1717
-						if (is_array($event_info['master_event'])) // status update requires a stored master event
1856
+						if (is_array($event_info['master_event']))
1857
+						{
1858
+							// status update requires a stored master event
1718 1859
 						{
1719 1860
 							$recurrence = $this->date2usertime($event['recurrence']);
1861
+						}
1720 1862
 							if ($event_info['acl_edit'])
1721 1863
 							{
1722 1864
 								// update all participants if we have the right to do that
@@ -1824,7 +1966,10 @@  discard block
 block discarded – undo
1824 1966
 	 */
1825 1967
 	public function sync_alarms(array &$event, array $old_alarms, $user)
1826 1968
 	{
1827
-		if ($this->debug) error_log(__METHOD__."(".array2string($event).', old_alarms='.array2string($old_alarms).", $user,)");
1969
+		if ($this->debug)
1970
+		{
1971
+			error_log(__METHOD__."(".array2string($event).', old_alarms='.array2string($old_alarms).", $user,)");
1972
+		}
1828 1973
 		$modified = 0;
1829 1974
 		foreach($event['alarm'] as &$alarm)
1830 1975
 		{
@@ -1846,29 +1991,56 @@  discard block
 block discarded – undo
1846 1991
 					break;
1847 1992
 				}
1848 1993
 			}
1849
-			if ($this->debug) error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) processing ".($found?'existing':'new')." alarm ".array2string($alarm));
1994
+			if ($this->debug)
1995
+			{
1996
+				error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) processing ".($found?'existing':'new')." alarm ".array2string($alarm));
1997
+			}
1850 1998
 			if (!empty($alarm['attrs']['X-LIC-ERROR']))
1851 1999
 			{
1852
-				if ($this->debug) error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) ignored X-LIC-ERROR=".array2string($alarm['X-LIC-ERROR']));
2000
+				if ($this->debug)
2001
+				{
2002
+					error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) ignored X-LIC-ERROR=".array2string($alarm['X-LIC-ERROR']));
2003
+				}
1853 2004
 				unset($alarm['attrs']['X-LIC-ERROR']);
1854 2005
 			}
1855 2006
 			// alarm not found --> add it
1856 2007
 			if (!$found)
1857 2008
 			{
1858 2009
 				$alarm['owner'] = $user;
1859
-				if (!isset($alarm['time'])) $alarm['time'] = $event['start'] - $alarm['offset'];
1860
-				if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
1861
-				if ($this->debug) error_log(__METHOD__."() adding new alarm from client ".array2string($alarm));
1862
-				if ($event['id']) $alarm['id'] = $this->save_alarm($event['id'], $alarm);
2010
+				if (!isset($alarm['time']))
2011
+				{
2012
+					$alarm['time'] = $event['start'] - $alarm['offset'];
2013
+				}
2014
+				if ($alarm['time'] < time())
2015
+				{
2016
+					calendar_so::shift_alarm($event, $alarm);
2017
+				}
2018
+				if ($this->debug)
2019
+				{
2020
+					error_log(__METHOD__."() adding new alarm from client ".array2string($alarm));
2021
+				}
2022
+				if ($event['id'])
2023
+				{
2024
+					$alarm['id'] = $this->save_alarm($event['id'], $alarm);
2025
+				}
1863 2026
 				++$modified;
1864 2027
 			}
1865 2028
 			// existing alarm --> update it
1866 2029
 			else
1867 2030
 			{
1868
-				if (!isset($alarm['time'])) $alarm['time'] = $event['start'] - $alarm['offset'];
1869
-				if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
2031
+				if (!isset($alarm['time']))
2032
+				{
2033
+					$alarm['time'] = $event['start'] - $alarm['offset'];
2034
+				}
2035
+				if ($alarm['time'] < time())
2036
+				{
2037
+					calendar_so::shift_alarm($event, $alarm);
2038
+				}
1870 2039
 				$alarm = array_merge($old_alarm, $alarm);
1871
-				if ($this->debug) error_log(__METHOD__."() updating existing alarm from client ".array2string($alarm));
2040
+				if ($this->debug)
2041
+				{
2042
+					error_log(__METHOD__."() updating existing alarm from client ".array2string($alarm));
2043
+				}
1872 2044
 				$alarm['id'] = $this->save_alarm($event['id'], $alarm);
1873 2045
 				++$modified;
1874 2046
 			}
@@ -1882,7 +2054,10 @@  discard block
 block discarded – undo
1882 2054
 				unset($old_alarm[$id]);
1883 2055
 				continue;
1884 2056
 			}
1885
-			if ($this->debug) error_log(__METHOD__."() deleting alarm '$id' deleted on client ".array2string($old_alarm));
2057
+			if ($this->debug)
2058
+			{
2059
+				error_log(__METHOD__."() deleting alarm '$id' deleted on client ".array2string($old_alarm));
2060
+			}
1886 2061
 			$this->delete_alarm($id);
1887 2062
 			++$modified;
1888 2063
 		}
@@ -2301,7 +2476,10 @@  discard block
 block discarded – undo
2301 2476
 				array2string($_vcalData)."\n",3,$this->logfile);
2302 2477
 		}
2303 2478
 
2304
-		if (!is_array($this->supportedFields)) $this->setSupportedFields();
2479
+		if (!is_array($this->supportedFields))
2480
+		{
2481
+			$this->setSupportedFields();
2482
+		}
2305 2483
 
2306 2484
 		// we use Api\CalDAV\IcalIterator only on resources, as calling importVCal() accesses single events like an array (eg. $events[0])
2307 2485
 		if (is_resource($_vcalData))
@@ -2667,19 +2845,27 @@  discard block
 block discarded – undo
2667 2845
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2668 2846
 								$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime(trim($recurenceMatches[2]));
2669 2847
 							}
2670
-							else break;
2848
+							else {
2849
+								break;
2850
+							}
2671 2851
 							// fall-through
2672 2852
 						case 'DAILY':	// 2.0
2673 2853
 							$vcardData['recur_type'] = MCAL_RECUR_DAILY;
2674
-							if (stripos($recurence, 'BYDAY') === false) break;
2854
+							if (stripos($recurence, 'BYDAY') === false)
2855
+							{
2856
+								break;
2857
+							}
2675 2858
 							// hack to handle TYPE=DAILY;BYDAY= as WEEKLY, which is true as long as there's no interval
2676 2859
 							// fall-through
2677 2860
 						case 'W':
2678 2861
 						case 'WEEKLY':
2679 2862
 							$days = array();
2680
-							if (preg_match('/W(\d+) *((?i: [AEFHMORSTUW]{2})+)?( +([^ ]*))$/',$recurence, $recurenceMatches))		// 1.0
2863
+							if (preg_match('/W(\d+) *((?i: [AEFHMORSTUW]{2})+)?( +([^ ]*))$/',$recurence, $recurenceMatches))
2864
+							{
2865
+								// 1.0
2681 2866
 							{
2682 2867
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2868
+							}
2683 2869
 								if (empty($recurenceMatches[2]))
2684 2870
 								{
2685 2871
 									$days[0] = strtoupper(substr(date('D', $vcardData['start']),0,2));
@@ -2692,7 +2878,10 @@  discard block
 block discarded – undo
2692 2878
 								$repeatMatches = null;
2693 2879
 								if (preg_match('/#(\d+)/',$recurenceMatches[4],$repeatMatches))
2694 2880
 								{
2695
-									if ($repeatMatches[1]) $vcardData['recur_count'] = $repeatMatches[1];
2881
+									if ($repeatMatches[1])
2882
+									{
2883
+										$vcardData['recur_count'] = $repeatMatches[1];
2884
+									}
2696 2885
 								}
2697 2886
 								else
2698 2887
 								{
@@ -2701,9 +2890,12 @@  discard block
 block discarded – undo
2701 2890
 
2702 2891
 								$recur_days = $this->recur_days_1_0;
2703 2892
 							}
2704
-							elseif (preg_match('/BYDAY=([^;: ]+)/',$recurence,$recurenceMatches))	// 2.0
2893
+							elseif (preg_match('/BYDAY=([^;: ]+)/',$recurence,$recurenceMatches))
2894
+							{
2895
+								// 2.0
2705 2896
 							{
2706 2897
 								$days = explode(',',$recurenceMatches[1]);
2898
+							}
2707 2899
 								$recur_days = $this->recur_days;
2708 2900
 							}
2709 2901
 							else	// no day given, use the day of dtstart
@@ -2762,7 +2954,10 @@  discard block
 block discarded – undo
2762 2954
 							{
2763 2955
 								$vcardData['recur_interval'] = $recurenceMatches[1];
2764 2956
 								$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[2]);
2765
-							} else break;
2957
+							}
2958
+							else {
2959
+								break;
2960
+							}
2766 2961
 							// fall-through
2767 2962
 						case 'YEARLY':	// 2.0
2768 2963
 							if (strpos($recurence, 'BYDAY') === false)
@@ -2855,13 +3050,16 @@  discard block
 block discarded – undo
2855 3050
 					// fall throught
2856 3051
 				case 'ATTENDEE':
2857 3052
 					if (isset($attributes['params']['PARTSTAT']))
2858
-				    {
3053
+					{
2859 3054
 				    	$attributes['params']['STATUS'] = $attributes['params']['PARTSTAT'];
2860 3055
 				    }
2861 3056
 				    if (isset($attributes['params']['STATUS']))
2862
-					{
3057
+				    {
2863 3058
 						$status = $this->status_ical2egw[strtoupper($attributes['params']['STATUS'])];
2864
-						if (empty($status)) $status = 'X';
3059
+						if (empty($status))
3060
+						{
3061
+							$status = 'X';
3062
+						}
2865 3063
 					}
2866 3064
 					else
2867 3065
 					{
@@ -2921,7 +3119,10 @@  discard block
 block discarded – undo
2921 3119
 							$uid = $this->user;
2922 3120
 					}
2923 3121
 					// check principal url from CalDAV here after X-EGROUPWARE-UID and to get optional X-EGROUPWARE-QUANTITY
2924
-					if (!$uid) $uid = Api\CalDAV\Principals::url2uid($attributes['value'], null, $cn);
3122
+					if (!$uid)
3123
+					{
3124
+						$uid = Api\CalDAV\Principals::url2uid($attributes['value'], null, $cn);
3125
+					}
2925 3126
 
2926 3127
 					// try to find an email address
2927 3128
 					if (!$uid && $email && ($uid = $GLOBALS['egw']->accounts->name2id($email, 'account_email')))
@@ -2989,7 +3190,10 @@  discard block
 block discarded – undo
2989 3190
 								}
2990 3191
 								$status = 'U'; // keep the group
2991 3192
 							}
2992
-							else continue; // can't find this group
3193
+							else {
3194
+								continue;
3195
+							}
3196
+							// can't find this group
2993 3197
 						}
2994 3198
 						elseif (empty($searcharray))
2995 3199
 						{
@@ -3048,7 +3252,9 @@  discard block
 block discarded – undo
3048 3252
 
3049 3253
 								try {
3050 3254
 									if (!$this->calendarOwner && is_numeric($uid) && $role == 'CHAIR')
3051
-										$component->getAttribute('ORGANIZER');
3255
+									{
3256
+																			$component->getAttribute('ORGANIZER');
3257
+									}
3052 3258
 								}
3053 3259
 								catch(Horde_Icalendar_Exception $e)
3054 3260
 								{
@@ -3085,7 +3291,10 @@  discard block
 block discarded – undo
3085 3291
 					}
3086 3292
 					break;
3087 3293
 				case 'CREATED':		// will be written direct to the event
3088
-					if ($event['modified']) break;
3294
+					if ($event['modified'])
3295
+					{
3296
+						break;
3297
+					}
3089 3298
 					// fall through
3090 3299
 				case 'LAST-MODIFIED':	// will be written direct to the event
3091 3300
 					$event['modified'] = $attributes['value'];
@@ -3106,7 +3315,11 @@  discard block
 block discarded – undo
3106 3315
 					break;
3107 3316
 
3108 3317
 				case 'ATTACH':
3109
-					if ($attributes['params'] && !empty($attributes['params']['FMTTYPE'])) break;	// handeled by managed attachment code
3318
+					if ($attributes['params'] && !empty($attributes['params']['FMTTYPE']))
3319
+					{
3320
+						break;
3321
+					}
3322
+					// handeled by managed attachment code
3110 3323
 					// fall throught to store external attachment url
3111 3324
 				default:	// X- attribute or other by EGroupware unsupported property
3112 3325
 					//error_log(__METHOD__."() $attributes[name] = ".array2string($attributes));
@@ -3237,7 +3450,10 @@  discard block
 block discarded – undo
3237 3450
 			$event['end'] = $event['start'] + 60 * $this->cal_prefs['defaultlength'];
3238 3451
 		}
3239 3452
 
3240
-		if ($this->calendarOwner) $event['owner'] = $this->calendarOwner;
3453
+		if ($this->calendarOwner)
3454
+		{
3455
+			$event['owner'] = $this->calendarOwner;
3456
+		}
3241 3457
 
3242 3458
 		// parsing ATTACH attributes for managed attachments
3243 3459
 		$event['attach-delete-by-put'] = $component->getAttributeDefault('X-EGROUPWARE-ATTACH-INCLUDED', null) === 'TRUE';
@@ -3263,7 +3479,10 @@  discard block
 block discarded – undo
3263 3479
 				$filter = $relax ? 'relax' : 'check';
3264 3480
 				$event = array_shift($events);
3265 3481
 				$eventId = -1;
3266
-				if ($this->so->isWholeDay($event)) $event['whole_day'] = true;
3482
+				if ($this->so->isWholeDay($event))
3483
+				{
3484
+					$event['whole_day'] = true;
3485
+				}
3267 3486
 				if ($contentID)
3268 3487
 				{
3269 3488
 					$parts = preg_split('/:/', $contentID);
@@ -3316,8 +3535,16 @@  discard block
 block discarded – undo
3316 3535
 	 */
3317 3536
 	function freebusy($user,$end=null,$utc=true, $charset='UTF-8', $start=null, $method='PUBLISH', array $extra=null)
3318 3537
 	{
3319
-		if (!$start) $start = time();	// default now
3320
-		if (!$end) $end = time() + 100*DAY_s;	// default next 100 days
3538
+		if (!$start)
3539
+		{
3540
+			$start = time();
3541
+		}
3542
+		// default now
3543
+		if (!$end)
3544
+		{
3545
+			$end = time() + 100*DAY_s;
3546
+		}
3547
+		// default next 100 days
3321 3548
 
3322 3549
 		$vcal = new Horde_Icalendar;
3323 3550
 		$vcal->setAttribute('PRODID','-//EGroupware//NONSGML EGroupware Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
@@ -3339,10 +3566,13 @@  discard block
 block discarded – undo
3339 3566
 				$attributes[$attr] = date('Ymd\THis', $value);
3340 3567
 			}
3341 3568
 		}
3342
-		if (is_null($extra)) $extra = array(
3569
+		if (is_null($extra))
3570
+		{
3571
+			$extra = array(
3343 3572
 			'URL' => $this->freebusy_url($user),
3344 3573
 			'ORGANIZER' => 'mailto:'.$GLOBALS['egw']->accounts->id2name($user,'account_email'),
3345 3574
 		);
3575
+		}
3346 3576
 		foreach($attributes+$extra as $attr => $value)
3347 3577
 		{
3348 3578
 			$vfreebusy->setAttribute($attr, $value);
@@ -3358,12 +3588,21 @@  discard block
 block discarded – undo
3358 3588
 		{
3359 3589
 			foreach ($fbdata as $event)
3360 3590
 			{
3361
-				if ($event['non_blocking']) continue;
3362
-				if ($event['uid'] === $extra['X-CALENDARSERVER-MASK-UID']) continue;
3591
+				if ($event['non_blocking'])
3592
+				{
3593
+					continue;
3594
+				}
3595
+				if ($event['uid'] === $extra['X-CALENDARSERVER-MASK-UID'])
3596
+				{
3597
+					continue;
3598
+				}
3363 3599
 				$status = $event['participants'][$user];
3364 3600
 				$quantity = $role = null;
3365 3601
 				calendar_so::split_status($status, $quantity, $role);
3366
-				if ($status == 'R' || $role == 'NON-PARTICIPANT') continue;
3602
+				if ($status == 'R' || $role == 'NON-PARTICIPANT')
3603
+				{
3604
+					continue;
3605
+				}
3367 3606
 
3368 3607
 				$fbtype = $status == 'T' ? 'BUSY-TENTATIVE' : 'BUSY';
3369 3608
 
Please login to merge, or discard this patch.
calendar/inc/class.calendar_import_csv.inc.php 5 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 * @param importepport_iface_egw_record record The egw_record object being imported
75 75
 	 * @param importexport_iface_import_record import_csv Import object contains current state
76 76
 	 *
77
-	 * @return boolean success
77
+	 * @return null|boolean success
78 78
 	 */
79 79
 	public function import_record(\importexport_iface_egw_record &$record, &$import_csv)
80 80
 	{
@@ -254,7 +254,6 @@  discard block
 block discarded – undo
254 254
 	 * perform the required action
255 255
 	 *
256 256
 	 * @param int $_action one of $this->actions
257
-	 * @param array $_data record data for the action
258 257
 	 * @return bool success or not
259 258
 	 */
260 259
 	protected function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 )
@@ -343,7 +342,7 @@  discard block
 block discarded – undo
343 342
 	/**
344 343
 	 * Alter a row for preview to show multiple participants instead of Array
345 344
 	 *
346
-	 * @param egw_record $row_entry
345
+	 * @param importexport_iface_egw_record $row_entry
347 346
 	 */
348 347
 	protected function row_preview(importexport_iface_egw_record &$row_entry)
349 348
 	{
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@
 block discarded – undo
32 32
 	protected static $conditions = array('exists');
33 33
 
34 34
 	/**
35
-	* For figuring out if an entry has changed
36
-	*/
35
+	 * For figuring out if an entry has changed
36
+	 */
37 37
 	protected $tracking;
38 38
 
39 39
 	/**
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		$this->role_map = array_flip($this->bo->roles);
58 58
 
59 59
 		$this->lookups = array(
60
-			'priority'	=> Array(
60
+			'priority'	=> array(
61 61
 				0 => lang('None'),
62 62
 				1 => lang('Low'),
63 63
 				2 => lang('Normal'),
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @return boolean
239 239
 	 */
240
-	protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$records = array())
240
+	protected function exists(importexport_iface_egw_record &$record, array &$condition, &$records = array())
241 241
 	{
242 242
 		if($record->__get($condition['string']) && $condition['string'] == 'id') {
243 243
 			$event = $this->bo->read($record->__get($condition['string']));
Please login to merge, or discard this patch.
Braces   +75 added lines, -32 removed lines patch added patch discarded remove patch
@@ -17,7 +17,8 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * class import_csv for calendar
19 19
  */
20
-class calendar_import_csv extends importexport_basic_import_csv  {
20
+class calendar_import_csv extends importexport_basic_import_csv
21
+{
21 22
 
22 23
 	/**
23 24
 	 * actions wich could be done to data entries
@@ -83,8 +84,10 @@  discard block
 block discarded – undo
83 84
 		$options['owner'] = $options['owner'] ? $options['owner'] : $this->user;
84 85
 
85 86
 		// Set owner, unless it's supposed to come from CSV file
86
-		if($options['owner_from_csv']) {
87
-			if(!is_numeric($record['owner'])) {
87
+		if($options['owner_from_csv'])
88
+		{
89
+			if(!is_numeric($record['owner']))
90
+			{
88 91
 				$this->errors[$import_csv->get_current_position()] = lang(
89 92
 					'Invalid owner ID: %1.  Might be a bad field translation.  Used %2 instead.',
90 93
 					$record->owner,
@@ -106,14 +109,16 @@  discard block
 block discarded – undo
106 109
 		}
107 110
 
108 111
 		// Parse particpants
109
-		if ($record->participants && !is_array($record->participants)) {
112
+		if ($record->participants && !is_array($record->participants))
113
+		{
110 114
 			// Importing participants in human friendly format:
111 115
 			// Name (quantity)? (status) Role[, Name (quantity)? (status) Role]+
112 116
 			preg_match_all('/(([^(]+?)(?: \(([\d]+)\))? \(([^,)]+)\)(?: ([^ ,]+))?)(?:, )?/',$record->participants,$participants);
113 117
 			$p_participants = array();
114 118
 			$missing = array();
115 119
 			list($lines, $p, $names, $quantity, $status, $role) = $participants;
116
-			foreach($names as $key => $name) {
120
+			foreach($names as $key => $name)
121
+			{
117 122
 				//error_log("Name: $name Quantity: {$quantity[$key]} Status: {$status[$key]} Role: {$role[$key]}");
118 123
 
119 124
 				// Search for direct account name, then user in accounts first
@@ -121,9 +126,13 @@  discard block
 block discarded – undo
121 126
 				$id = importexport_helper_functions::account_name2id($name);
122 127
 
123 128
 				// If not found, or not an exact match to a user (account_name2id is pretty generous)
124
-				if(!$id || $names[$key] !== $this->bo->participant_name($id)) {
129
+				if(!$id || $names[$key] !== $this->bo->participant_name($id))
130
+				{
125 131
 					$contacts = ExecMethod2('addressbook.addressbook_bo.search', $search,array('contact_id','account_id'),'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR',array(0,1));
126
-					if($contacts) $id = $contacts[0]['account_id'] ? $contacts[0]['account_id'] : 'c'.$contacts[0]['contact_id'];
132
+					if($contacts)
133
+					{
134
+						$id = $contacts[0]['account_id'] ? $contacts[0]['account_id'] : 'c'.$contacts[0]['contact_id'];
135
+					}
127 136
 				}
128 137
 				if(!$id)
129 138
 				{
@@ -131,7 +140,10 @@  discard block
 block discarded – undo
131 140
 					foreach($this->bo->resources as $resource)
132 141
 					{
133 142
 						// Can't search for email
134
-						if($resource['app'] == 'email') continue;
143
+						if($resource['app'] == 'email')
144
+						{
145
+							continue;
146
+						}
135 147
 						// Special resource search, since it does special stuff in link_query
136 148
 						if($resource['app'] == 'resources')
137 149
 						{
@@ -140,7 +152,8 @@  discard block
 block discarded – undo
140 152
 								$this->resource_so = new resources_so();
141 153
 							}
142 154
 							$result = $this->resource_so->search($search,'res_id');
143
-							if(count($result) >= 1) {
155
+							if(count($result) >= 1)
156
+							{
144 157
 								$id = $resource['type'].$result[0]['res_id'];
145 158
 								break;
146 159
 							}
@@ -159,7 +172,8 @@  discard block
 block discarded – undo
159 172
 						}
160 173
 					}
161 174
 				}
162
-				if($id) {
175
+				if($id)
176
+				{
163 177
 					$p_participants[$id] = calendar_so::combine_status(
164 178
 						$this->status_map[lang($status[$key])] ? $this->status_map[lang($status[$key])] : $status[$key][0],
165 179
 						$quantity[$key] ? $quantity[$key] : 1,
@@ -188,27 +202,38 @@  discard block
 block discarded – undo
188 202
 		}
189 203
 		$record->tzid = calendar_timezones::id2tz($record->tz_id);
190 204
 
191
-		if ( $options['conditions'] ) {
192
-			foreach ( $options['conditions'] as $condition ) {
205
+		if ( $options['conditions'] )
206
+		{
207
+			foreach ( $options['conditions'] as $condition )
208
+			{
193 209
 				$records = array();
194
-				switch ( $condition['type'] ) {
210
+				switch ( $condition['type'] )
211
+				{
195 212
 					// exists
196 213
 					case 'exists' :
197 214
 						// Check for that record
198 215
 						$result = $this->exists($record, $condition, $records);
199 216
 
200
-						if ( is_array( $records ) && count( $records ) >= 1) {
217
+						if ( is_array( $records ) && count( $records ) >= 1)
218
+						{
201 219
 							// apply action to all records matching this exists condition
202 220
 							$action = $condition['true'];
203
-							foreach ( (array)$records as $event ) {
221
+							foreach ( (array)$records as $event )
222
+							{
204 223
 								$record->id = $event['id'];
205
-								if ( $this->definition->plugin_options['update_cats'] == 'add' ) {
206
-									if ( !is_array( $record->category ) ) $record->category = explode( ',', $record->category );
224
+								if ( $this->definition->plugin_options['update_cats'] == 'add' )
225
+								{
226
+									if ( !is_array( $record->category ) )
227
+									{
228
+										$record->category = explode( ',', $record->category );
229
+									}
207 230
 									$record->category = implode( ',', array_unique( array_merge( $record->category, $event['category'] ) ) );
208 231
 								}
209 232
 								$success = $this->action(  $action['action'], $record, $import_csv->get_current_position() );
210 233
 							}
211
-						} else {
234
+						}
235
+						else
236
+						{
212 237
 							$action = $condition['false'];
213 238
 							$success = ($this->action(  $action['action'], $record, $import_csv->get_current_position() ));
214 239
 						}
@@ -219,9 +244,14 @@  discard block
 block discarded – undo
219 244
 						die('condition / action not supported!!!');
220 245
 						break;
221 246
 				}
222
-				if ($action['last']) break;
247
+				if ($action['last'])
248
+				{
249
+					break;
250
+				}
223 251
 			}
224
-		} else {
252
+		}
253
+		else
254
+		{
225 255
 			// unconditional insert
226 256
 			$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
227 257
 		}
@@ -240,12 +270,14 @@  discard block
 block discarded – undo
240 270
 	 */
241 271
 	protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$records = array())
242 272
 	{
243
-		if($record->__get($condition['string']) && $condition['string'] == 'id') {
273
+		if($record->__get($condition['string']) && $condition['string'] == 'id')
274
+		{
244 275
 			$event = $this->bo->read($record->__get($condition['string']));
245 276
 			$records = array($event);
246 277
 		}
247 278
 
248
-		if ( is_array( $records ) && count( $records ) >= 1) {
279
+		if ( is_array( $records ) && count( $records ) >= 1)
280
+		{
249 281
 			return true;
250 282
 		}
251 283
 		return false;
@@ -261,7 +293,8 @@  discard block
 block discarded – undo
261 293
 	protected function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 )
262 294
 	{
263 295
 		$_data = $record->get_record_array();
264
-		switch ($_action) {
296
+		switch ($_action)
297
+		{
265 298
 			case 'none' :
266 299
 				return true;
267 300
 			case 'update' :
@@ -269,7 +302,8 @@  discard block
 block discarded – undo
269 302
 				$old = $this->bo->read($_data['id']);
270 303
 
271 304
 				// Don't change a user account into a record
272
-				if(!$this->definition->plugin_options['change_owner']) {
305
+				if(!$this->definition->plugin_options['change_owner'])
306
+				{
273 307
 					// Don't change owner of an existing record
274 308
 					unset($_data['owner']);
275 309
 				}
@@ -277,23 +311,27 @@  discard block
 block discarded – undo
277 311
 				// Merge to deal with fields not in import record
278 312
 				$_data = array_merge($old, $_data);
279 313
 				$changed = $this->tracking->changed_fields($_data, $old);
280
-				if(count($changed) == 0) {
314
+				if(count($changed) == 0)
315
+				{
281 316
 					return true;
282 317
 				}
283 318
 				// Fall through
284 319
 			case 'insert' :
285
-				if($_action == 'insert') {
320
+				if($_action == 'insert')
321
+				{
286 322
 					// Backend doesn't like inserting with ID specified, can overwrite existing
287 323
 					unset($_data['id']);
288 324
 				}
289 325
 				// Make sure participants are set
290
-				if(!$_data['participants']) {
326
+				if(!$_data['participants'])
327
+				{
291 328
 					$user = $_data['owner'] ? $_data['owner'] : $this->user;
292 329
 					$_data['participants'] = array(
293 330
 						$user => 'U'
294 331
 					);
295 332
 				}
296
-				if ( $this->dry_run ) {
333
+				if ( $this->dry_run )
334
+				{
297 335
 					//print_r($_data);
298 336
 					// User is interested in conflict checks, do so for dry run
299 337
 					// Otherwise, conflicts are just ignored and imported anyway
@@ -309,7 +347,9 @@  discard block
 block discarded – undo
309 347
 					}
310 348
 					$this->results[$_action]++;
311 349
 					return true;
312
-				} else {
350
+				}
351
+				else
352
+				{
313 353
 					$messages = null;
314 354
 					$result = $this->bo->update( $_data, 
315 355
 						!$this->definition->plugin_options['skip_conflicts'],
@@ -360,7 +400,8 @@  discard block
 block discarded – undo
360 400
 	 *
361 401
 	 * @return string name
362 402
 	 */
363
-	public static function get_name() {
403
+	public static function get_name()
404
+	{
364 405
 		return lang('Calendar CSV import');
365 406
 	}
366 407
 
@@ -369,7 +410,8 @@  discard block
 block discarded – undo
369 410
 	 *
370 411
 	 * @return string descriprion
371 412
 	 */
372
-	public static function get_description() {
413
+	public static function get_description()
414
+	{
373 415
 		return lang("Imports events into your Calendar from a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators.");
374 416
 	}
375 417
 
@@ -378,7 +420,8 @@  discard block
 block discarded – undo
378 420
 	 *
379 421
 	 * @return string suffix (comma seperated)
380 422
 	 */
381
-	public static function get_filesuffix() {
423
+	public static function get_filesuffix()
424
+	{
382 425
 		return 'csv';
383 426
 	}
384 427
 
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * class import_csv for calendar
19 19
  */
20
-class calendar_import_csv extends importexport_basic_import_csv  {
20
+class calendar_import_csv extends importexport_basic_import_csv {
21 21
 
22 22
 	/**
23 23
 	 * actions wich could be done to data entries
24 24
 	 */
25
-	protected static $actions = array( 'none', 'update', 'insert' );
25
+	protected static $actions = array('none', 'update', 'insert');
26 26
 
27 27
 	/**
28 28
 	 * conditions for actions
@@ -44,16 +44,16 @@  discard block
 block discarded – undo
44 44
 	/**
45 45
 	 * Set up tracker
46 46
 	 */
47
-	protected function init(importexport_definition &$definition)
47
+	protected function init(importexport_definition&$definition)
48 48
 	{
49 49
 		// fetch the addressbook bo
50
-		$this->bo= new calendar_boupdate();
50
+		$this->bo = new calendar_boupdate();
51 51
 
52 52
 		// Get the tracker for changes
53 53
 		$this->tracking = new calendar_tracking();
54 54
 
55 55
 		// Used for participants
56
-		$this->status_map = array_flip(array_map('lang',$this->bo->verbose_status));
56
+		$this->status_map = array_flip(array_map('lang', $this->bo->verbose_status));
57 57
 		$this->role_map = array_flip($this->bo->roles);
58 58
 
59 59
 		$this->lookups = array(
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return boolean success
78 78
 	 */
79
-	public function import_record(\importexport_iface_egw_record &$record, &$import_csv)
79
+	public function import_record(\importexport_iface_egw_record&$record, &$import_csv)
80 80
 	{
81 81
 		// set eventOwner
82
-		$options =& $this->definition->plugin_options;
82
+		$options = & $this->definition->plugin_options;
83 83
 		$options['owner'] = $options['owner'] ? $options['owner'] : $this->user;
84 84
 
85 85
 		// Set owner, unless it's supposed to come from CSV file
86
-		if($options['owner_from_csv']) {
87
-			if(!is_numeric($record['owner'])) {
86
+		if ($options['owner_from_csv']) {
87
+			if (!is_numeric($record['owner'])) {
88 88
 				$this->errors[$import_csv->get_current_position()] = lang(
89 89
 					'Invalid owner ID: %1.  Might be a bad field translation.  Used %2 instead.',
90 90
 					$record->owner,
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		}
100 100
 		
101 101
 		// Handle errors in length or start/end date
102
-		if($record->start > $record->end)
102
+		if ($record->start > $record->end)
103 103
 		{
104 104
 			$record->end = $record->start + $GLOBALS['egw_info']['user']['preferences']['calendar']['defaultlength'] * 60;
105 105
 			$this->warnings[$import_csv->get_current_position()] = lang('error: starttime has to be before the endtime !!!');
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 		if ($record->participants && !is_array($record->participants)) {
110 110
 			// Importing participants in human friendly format:
111 111
 			// Name (quantity)? (status) Role[, Name (quantity)? (status) Role]+
112
-			preg_match_all('/(([^(]+?)(?: \(([\d]+)\))? \(([^,)]+)\)(?: ([^ ,]+))?)(?:, )?/',$record->participants,$participants);
112
+			preg_match_all('/(([^(]+?)(?: \(([\d]+)\))? \(([^,)]+)\)(?: ([^ ,]+))?)(?:, )?/', $record->participants, $participants);
113 113
 			$p_participants = array();
114 114
 			$missing = array();
115 115
 			list($lines, $p, $names, $quantity, $status, $role) = $participants;
116
-			foreach($names as $key => $name) {
116
+			foreach ($names as $key => $name) {
117 117
 				//error_log("Name: $name Quantity: {$quantity[$key]} Status: {$status[$key]} Role: {$role[$key]}");
118 118
 
119 119
 				// Search for direct account name, then user in accounts first
@@ -121,26 +121,26 @@  discard block
 block discarded – undo
121 121
 				$id = importexport_helper_functions::account_name2id($name);
122 122
 
123 123
 				// If not found, or not an exact match to a user (account_name2id is pretty generous)
124
-				if(!$id || $names[$key] !== $this->bo->participant_name($id)) {
125
-					$contacts = ExecMethod2('addressbook.addressbook_bo.search', $search,array('contact_id','account_id'),'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR',array(0,1));
126
-					if($contacts) $id = $contacts[0]['account_id'] ? $contacts[0]['account_id'] : 'c'.$contacts[0]['contact_id'];
124
+				if (!$id || $names[$key] !== $this->bo->participant_name($id)) {
125
+					$contacts = ExecMethod2('addressbook.addressbook_bo.search', $search, array('contact_id', 'account_id'), 'org_name,n_family,n_given,cat_id,contact_email', '', '%', false, 'OR', array(0, 1));
126
+					if ($contacts) $id = $contacts[0]['account_id'] ? $contacts[0]['account_id'] : 'c'.$contacts[0]['contact_id'];
127 127
 				}
128
-				if(!$id)
128
+				if (!$id)
129 129
 				{
130 130
 					// Use calendar's registered resources to find participant
131
-					foreach($this->bo->resources as $resource)
131
+					foreach ($this->bo->resources as $resource)
132 132
 					{
133 133
 						// Can't search for email
134
-						if($resource['app'] == 'email') continue;
134
+						if ($resource['app'] == 'email') continue;
135 135
 						// Special resource search, since it does special stuff in link_query
136
-						if($resource['app'] == 'resources')
136
+						if ($resource['app'] == 'resources')
137 137
 						{
138
-							if(!$this->resource_so)
138
+							if (!$this->resource_so)
139 139
 							{
140 140
 								$this->resource_so = new resources_so();
141 141
 							}
142
-							$result = $this->resource_so->search($search,'res_id');
143
-							if(count($result) >= 1) {
142
+							$result = $this->resource_so->search($search, 'res_id');
143
+							if (count($result) >= 1) {
144 144
 								$id = $resource['type'].$result[0]['res_id'];
145 145
 								break;
146 146
 							}
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
 							$link_options = array();
152 152
 							$result = Link::query($resource['app'], $search, $link_options);
153 153
 
154
-							if($result)
154
+							if ($result)
155 155
 							{
156
-								$id = $resource['type'] . key($result);
156
+								$id = $resource['type'].key($result);
157 157
 								break;
158 158
 							}
159 159
 						}
160 160
 					}
161 161
 				}
162
-				if($id) {
162
+				if ($id) {
163 163
 					$p_participants[$id] = calendar_so::combine_status(
164 164
 						$this->status_map[lang($status[$key])] ? $this->status_map[lang($status[$key])] : $status[$key][0],
165 165
 						$quantity[$key] ? $quantity[$key] : 1,
@@ -170,16 +170,16 @@  discard block
 block discarded – undo
170 170
 				{
171 171
 					$missing[] = $name;
172 172
 				}
173
-				if(count($missing) > 0)
173
+				if (count($missing) > 0)
174 174
 				{
175
-					$this->warnings[$import_csv->get_current_position()] = $record->title . ' ' . lang('participants') . ': ' .
176
-						lang('Contact not found!') . '<br />'.implode(", ",$missing);
175
+					$this->warnings[$import_csv->get_current_position()] = $record->title.' '.lang('participants').': '.
176
+						lang('Contact not found!').'<br />'.implode(", ", $missing);
177 177
 				}
178 178
 			}
179 179
 			$record->participants = $p_participants;
180 180
 		}
181 181
 
182
-		if($record->recurrence)
182
+		if ($record->recurrence)
183 183
 		{
184 184
 			$start = new Api\DateTime($record->start);
185 185
 			try
@@ -194,37 +194,37 @@  discard block
 block discarded – undo
194 194
 			catch (Exception $e)
195 195
 			{
196 196
 				// Try old way from export using just recur_type / interval
197
-				list($record->recur_type, $record->recur_interval) = explode('/',$record->recurrence,2);
197
+				list($record->recur_type, $record->recur_interval) = explode('/', $record->recurrence, 2);
198 198
 				$record->recur_interval = trim($record->recur_interval);
199
-				$record->recur_type = array_search(strtolower(trim($record->recur_type)), array_map('strtolower',$this->lookups['recurrence']));
199
+				$record->recur_type = array_search(strtolower(trim($record->recur_type)), array_map('strtolower', $this->lookups['recurrence']));
200 200
 			}
201 201
 			unset($record->recurrence);
202 202
 		}
203 203
 		$record->tzid = calendar_timezones::id2tz($record->tz_id);
204 204
 
205
-		if ( $options['conditions'] ) {
206
-			foreach ( $options['conditions'] as $condition ) {
205
+		if ($options['conditions']) {
206
+			foreach ($options['conditions'] as $condition) {
207 207
 				$records = array();
208
-				switch ( $condition['type'] ) {
208
+				switch ($condition['type']) {
209 209
 					// exists
210 210
 					case 'exists' :
211 211
 						// Check for that record
212 212
 						$result = $this->exists($record, $condition, $records);
213 213
 
214
-						if ( is_array( $records ) && count( $records ) >= 1) {
214
+						if (is_array($records) && count($records) >= 1) {
215 215
 							// apply action to all records matching this exists condition
216 216
 							$action = $condition['true'];
217
-							foreach ( (array)$records as $event ) {
217
+							foreach ((array)$records as $event) {
218 218
 								$record->id = $event['id'];
219
-								if ( $this->definition->plugin_options['update_cats'] == 'add' ) {
220
-									if ( !is_array( $record->category ) ) $record->category = explode( ',', $record->category );
221
-									$record->category = implode( ',', array_unique( array_merge( $record->category, $event['category'] ) ) );
219
+								if ($this->definition->plugin_options['update_cats'] == 'add') {
220
+									if (!is_array($record->category)) $record->category = explode(',', $record->category);
221
+									$record->category = implode(',', array_unique(array_merge($record->category, $event['category'])));
222 222
 								}
223
-								$success = $this->action(  $action['action'], $record, $import_csv->get_current_position() );
223
+								$success = $this->action($action['action'], $record, $import_csv->get_current_position());
224 224
 							}
225 225
 						} else {
226 226
 							$action = $condition['false'];
227
-							$success = ($this->action(  $action['action'], $record, $import_csv->get_current_position() ));
227
+							$success = ($this->action($action['action'], $record, $import_csv->get_current_position()));
228 228
 						}
229 229
 						break;
230 230
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 			}
238 238
 		} else {
239 239
 			// unconditional insert
240
-			$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
240
+			$success = $this->action('insert', $record, $import_csv->get_current_position());
241 241
 		}
242 242
 
243 243
 		return $success;
@@ -252,14 +252,14 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @return boolean
254 254
 	 */
255
-	protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$records = array())
255
+	protected function exists(importexport_iface_egw_record&$record, Array &$condition, &$records = array())
256 256
 	{
257
-		if($record->__get($condition['string']) && $condition['string'] == 'id') {
257
+		if ($record->__get($condition['string']) && $condition['string'] == 'id') {
258 258
 			$event = $this->bo->read($record->__get($condition['string']));
259 259
 			$records = array($event);
260 260
 		}
261 261
 
262
-		if ( is_array( $records ) && count( $records ) >= 1) {
262
+		if (is_array($records) && count($records) >= 1) {
263 263
 			return true;
264 264
 		}
265 265
 		return false;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @param array $_data record data for the action
273 273
 	 * @return bool success or not
274 274
 	 */
275
-	protected function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 )
275
+	protected function action($_action, importexport_iface_egw_record&$record, $record_num = 0)
276 276
 	{
277 277
 		$_data = $record->get_record_array();
278 278
 		switch ($_action) {
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 				$old = $this->bo->read($_data['id']);
284 284
 
285 285
 				// Don't change a user account into a record
286
-				if(!$this->definition->plugin_options['change_owner']) {
286
+				if (!$this->definition->plugin_options['change_owner']) {
287 287
 					// Don't change owner of an existing record
288 288
 					unset($_data['owner']);
289 289
 				}
@@ -291,30 +291,30 @@  discard block
 block discarded – undo
291 291
 				// Merge to deal with fields not in import record
292 292
 				$_data = array_merge($old, $_data);
293 293
 				$changed = $this->tracking->changed_fields($_data, $old);
294
-				if(count($changed) == 0) {
294
+				if (count($changed) == 0) {
295 295
 					return true;
296 296
 				}
297 297
 				// Fall through
298 298
 			case 'insert' :
299
-				if($_action == 'insert') {
299
+				if ($_action == 'insert') {
300 300
 					// Backend doesn't like inserting with ID specified, can overwrite existing
301 301
 					unset($_data['id']);
302 302
 				}
303 303
 				// Make sure participants are set
304
-				if(!$_data['participants']) {
304
+				if (!$_data['participants']) {
305 305
 					$user = $_data['owner'] ? $_data['owner'] : $this->user;
306 306
 					$_data['participants'] = array(
307 307
 						$user => 'U'
308 308
 					);
309 309
 				}
310
-				if ( $this->dry_run ) {
310
+				if ($this->dry_run) {
311 311
 					//print_r($_data);
312 312
 					// User is interested in conflict checks, do so for dry run
313 313
 					// Otherwise, conflicts are just ignored and imported anyway
314
-					if($this->definition->plugin_options['skip_conflicts'] && !$_data['non_blocking'])
314
+					if ($this->definition->plugin_options['skip_conflicts'] && !$_data['non_blocking'])
315 315
 					{
316 316
 						$conflicts = $this->bo->conflicts($_data);
317
-						if($conflicts)
317
+						if ($conflicts)
318 318
 						{
319 319
 							$this->conflict_warning($record_num, $conflicts);
320 320
 							$this->results['skipped']++;
@@ -325,15 +325,15 @@  discard block
 block discarded – undo
325 325
 					return true;
326 326
 				} else {
327 327
 					$messages = null;
328
-					$result = $this->bo->update( $_data, 
328
+					$result = $this->bo->update($_data, 
329 329
 						!$this->definition->plugin_options['skip_conflicts'],
330 330
 						true, $this->is_admin, true, $messages,
331 331
 						$this->definition->plugin_options['no_notification']
332 332
 					);
333
-					if(!$result)
333
+					if (!$result)
334 334
 					{
335
-						$this->errors[$record_num] = lang('Unable to save') . "\n" .
336
-							implode("\n",$messages);
335
+						$this->errors[$record_num] = lang('Unable to save')."\n".
336
+							implode("\n", $messages);
337 337
 					}
338 338
 					else if (is_array($result))
339 339
 					{
@@ -363,10 +363,10 @@  discard block
 block discarded – undo
363 363
 	 */
364 364
 	protected function conflict_warning($record_num, &$conflicts)
365 365
 	{
366
-		$this->warnings[$record_num] = lang('Conflicts') . ':';
367
-		foreach($conflicts as $conflict)
366
+		$this->warnings[$record_num] = lang('Conflicts').':';
367
+		foreach ($conflicts as $conflict)
368 368
 		{
369
-			$this->warnings[$record_num] .= "<br />\n" . Api\DateTime::to($conflict['start']) . "\t" . $conflict['title'];
369
+			$this->warnings[$record_num] .= "<br />\n".Api\DateTime::to($conflict['start'])."\t".$conflict['title'];
370 370
 		}
371 371
 	}
372 372
 
@@ -402,9 +402,9 @@  discard block
 block discarded – undo
402 402
 	 *
403 403
 	 * @param egw_record $row_entry
404 404
 	 */
405
-	protected function row_preview(importexport_iface_egw_record &$row_entry)
405
+	protected function row_preview(importexport_iface_egw_record&$row_entry)
406 406
 	{
407
-		$row_entry->participants = implode('<br />', $this->bo->participants(array('participants' => $row_entry->participants),true));
407
+		$row_entry->participants = implode('<br />', $this->bo->participants(array('participants' => $row_entry->participants), true));
408 408
 	}
409 409
 
410 410
 }
411 411
\ No newline at end of file
Please login to merge, or discard this patch.