Completed
Push — master ( 9d054b...106a1b )
by Klaus
23:45 queued 04:19
created
api/src/Mailer.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	/**
252 252
 	 * Add one or multiple addresses to Cc
253 253
 	 *
254
-	 * @param string|array|Horde_Mail_Rfc822_List $address
254
+	 * @param string $address
255 255
 	 * @param string $personal ='' only used if $address is a string
256 256
 	 */
257 257
 	function addCc($address, $personal=null)
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	/**
271 271
 	 * Add one or multiple addresses to Bcc
272 272
 	 *
273
-	 * @param string|array|Horde_Mail_Rfc822_List $address
273
+	 * @param string $address
274 274
 	 * @param string $personal ='' only used if $address is a string
275 275
 	 */
276 276
 	function addBcc($address, $personal=null)
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 	/**
382 382
 	 * Adds an embedded image or other inline attachment
383 383
 	 *
384
-	 * @param string|resource $data Path to the attachment or open file-descriptor
384
+	 * @param string $data Path to the attachment or open file-descriptor
385 385
 	 * @param string $cid Content ID of the attachment.  Use this to identify
386 386
 	 *        the Id for accessing the image in an HTML form.
387 387
 	 * @param string $name Overrides the attachment name.
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -481,10 +481,10 @@  discard block
 block discarded – undo
481 481
 	 * Log mails to log file specified in $GLOBALS['egw_info']['server']['log_mail']
482 482
 	 * or regular error_log for true (can be set either in DB or header.inc.php).
483 483
 	 *
484
-     * @param Horde_Mail_Transport $transport =null using transport from mail-account
484
+	 * @param Horde_Mail_Transport $transport =null using transport from mail-account
485 485
 	 *		specified in construct, or default one, if not specified
486
-     * @param boolean $resend =true allways true in EGroupware!
487
-     * @param boolean $flowed =null send message in flowed text format,
486
+	 * @param boolean $resend =true allways true in EGroupware!
487
+	 * @param boolean $flowed =null send message in flowed text format,
488 488
 	 *		default null used flowed by default for everything but multipart/encrypted,
489 489
 	 *		unless disabled in site configuration ("disable_rfc3676_flowed")
490 490
 	 *
@@ -642,15 +642,15 @@  discard block
 block discarded – undo
642 642
 	}
643 643
 
644 644
 	/**
645
-     * Get the raw email data sent by this object.
646
-     *
645
+	 * Get the raw email data sent by this object.
646
+	 *
647 647
 	 * Reimplement to be able to call it for saveAsDraft by calling
648 648
 	 * $this->send(new Horde_Mail_Transport_Null()),
649 649
 	 * if no base-part is set, because send is not called before.
650 650
 	 *
651
-     * @param  boolean $stream  If true, return a stream resource, otherwise
652
-     * @return stream|string  The raw email data.
653
-     */
651
+	 * @param  boolean $stream  If true, return a stream resource, otherwise
652
+	 * @return stream|string  The raw email data.
653
+	 */
654 654
 	function getRaw($stream=true)
655 655
 	{
656 656
 		try {
@@ -663,20 +663,20 @@  discard block
 block discarded – undo
663 663
 		}
664 664
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
665 665
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
666
-        if ($stream) {
667
-            $hdr = new Horde_Stream();
668
-            $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
669
-            return Horde_Stream_Wrapper_Combine::getStream(
670
-                array($hdr->stream,
671
-                      $this->getBasePart()->toString(
672
-                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
673
-                )
674
-            );
675
-        }
676
-
677
-        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
666
+		if ($stream) {
667
+			$hdr = new Horde_Stream();
668
+			$hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
669
+			return Horde_Stream_Wrapper_Combine::getStream(
670
+				array($hdr->stream,
671
+					  $this->getBasePart()->toString(
672
+						array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
673
+				)
674
+			);
675
+		}
676
+
677
+		return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
678 678
 			$this->getBasePart()->toString(array('canonical' => true));
679
-    }
679
+	}
680 680
 
681 681
 	/**
682 682
 	 * Convert charset of text-parts of message to utf-8
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @param int|Mail\Account|boolean $account =null mail account to use, default use Mail\Account::get_default($smtp=true)
67 67
 	 *	false: no NOT initialise account and set other EGroupware specific headers, used to parse mails (not sending them!)
68 68
 	 */
69
-	function __construct($account=null)
69
+	function __construct($account = null)
70 70
 	{
71 71
 		// Horde use locale for translation of error messages
72 72
 		Preferences::setlocale(LC_MESSAGES);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @param int|Mail\Account $account =null mail account to use, default use Mail\Account::get_default($smtp=true)
106 106
 	 * @throws Exception\NotFound if account was not found (or not valid for current user)
107 107
 	 */
108
-	function  setAccount($account=null)
108
+	function  setAccount($account = null)
109 109
 	{
110 110
 		if (is_a($account, 'Mail\Account'))
111 111
 		{
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		{
128 128
 			$identity = Mail\Account::read_identity($this->account->ident_id, true, null, $this->account);
129 129
 		}
130
-		catch(Exception $e)
130
+		catch (Exception $e)
131 131
 		{
132 132
 			unset($e);
133 133
 			error_log(__METHOD__.__LINE__.' Could not read_identity for account:'.$account['acc_id'].' with IdentID:'.$account['ident_id']);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @param string $address
150 150
 	 * @param string $personal =''
151 151
 	 */
152
-	public function setFrom($address, $personal='')
152
+	public function setFrom($address, $personal = '')
153 153
 	{
154 154
 		$this->addHeader('From', self::add_personal($address, $personal));
155 155
 	}
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
 	 * @param string $personal ='' only used if $address is a string
162 162
 	 * @param string $type ='to' type of address to add "to", "cc", "bcc" or "replyto"
163 163
 	 */
164
-	function addAddress($address, $personal='', $type='to')
164
+	function addAddress($address, $personal = '', $type = 'to')
165 165
 	{
166 166
 		if (!isset(self::$type2header[$type]))
167 167
 		{
168 168
 			throw new Exception\WrongParameter("Unknown type '$type'!");
169 169
 		}
170
-		if ($personal) $address = self::add_personal ($address, $personal);
170
+		if ($personal) $address = self::add_personal($address, $personal);
171 171
 
172 172
 		// add to our local list
173 173
 		$this->$type->add($address);
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @param string $type ='to' type of address to add "to", "cc", "bcc" or "replyto"
183 183
 	 */
184
-	function clearAddresses($type='to')
184
+	function clearAddresses($type = 'to')
185 185
 	{
186 186
 		$this->$type = new Horde_Mail_Rfc822_List();
187 187
 
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
 	 * @param boolean $return_array =false true: return array of string, false: Horde_Mail_Rfc822_List
196 196
 	 * @return array|Horde_Mail_Rfc822_List supporting arrayAccess and Iterable
197 197
 	 */
198
-	function getAddresses($type='to', $return_array=false)
198
+	function getAddresses($type = 'to', $return_array = false)
199 199
 	{
200 200
 		if ($return_array)
201 201
 		{
202 202
 			$addresses = array();
203
-			foreach($this->$type as $addr)
203
+			foreach ($this->$type as $addr)
204 204
 			{
205 205
 				$addresses[] = (string)$addr;
206 206
 			}
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 			//if (!preg_match('/^[!#$%&\'*+/0-9=?A-Z^_`a-z{|}~-]+$/u', $personal))	// that's how I read the rfc(2)822
242 242
 			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))	// but quoting is never wrong, so quote more then necessary
243 243
 			{
244
-				$personal = '"'.str_replace(array('\\', '"'),array('\\\\', '\\"'), $personal).'"';
244
+				$personal = '"'.str_replace(array('\\', '"'), array('\\\\', '\\"'), $personal).'"';
245 245
 			}
246 246
 			$address = ($personal ? $personal.' <' : '').$address.($personal ? '>' : '');
247 247
 		}
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	 * @param string|array|Horde_Mail_Rfc822_List $address
255 255
 	 * @param string $personal ='' only used if $address is a string
256 256
 	 */
257
-	function addCc($address, $personal=null)
257
+	function addCc($address, $personal = null)
258 258
 	{
259 259
 		$this->addAddress($address, $personal, 'cc');
260 260
 	}
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 * @param string|array|Horde_Mail_Rfc822_List $address
274 274
 	 * @param string $personal ='' only used if $address is a string
275 275
 	 */
276
-	function addBcc($address, $personal=null)
276
+	function addBcc($address, $personal = null)
277 277
 	{
278 278
 		$this->addAddress($address, $personal, 'bcc');
279 279
 	}
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @param string|array|Horde_Mail_Rfc822_List $address
293 293
 	 * @param string $personal ='' only used if $address is a string
294 294
 	 */
295
-	function addReplyTo($address, $personal=null)
295
+	function addReplyTo($address, $personal = null)
296 296
 	{
297 297
 		$this->addAddress($address, $personal, 'replyto');
298 298
 	}
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	 * @return integer part-number
328 328
 	 * @throws Exception\NotFound if $file could not be opened for reading
329 329
 	 */
330
-	public function addAttachment($data, $name = null, $type = null, $old_type=null)
330
+	public function addAttachment($data, $name = null, $type = null, $old_type = null)
331 331
 	{
332 332
 		// deprecated PHPMailer::AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') call
333 333
 		if ($type === 'base64')
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 		// set content-type parameters, which get ignored by setType
361 361
 		if (preg_match_all('/;\s*([^=]+)=([^;]*)/', $type, $matches))
362 362
 		{
363
-			foreach($matches[1] as $n => $label)
363
+			foreach ($matches[1] as $n => $label)
364 364
 			{
365 365
 				$part->setContentTypeParameter($label, $matches[2][$n]);
366 366
 			}
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
 	 * @param array $parameters =array() eg. array('method' => 'REQUEST')
463 463
 	 * @param string $charset =null default to $this->_charset="utf-8"
464 464
 	 */
465
-	function setAlternativBody($content, $type, $parameters=array(), $charset=null)
465
+	function setAlternativBody($content, $type, $parameters = array(), $charset = null)
466 466
 	{
467 467
 		$this->_alternativBody = new Horde_Mime_Part();
468 468
 		$this->_alternativBody->setType($type);
469
-		foreach($parameters as $label => $data)
469
+		foreach ($parameters as $label => $data)
470 470
 		{
471 471
 			$this->_alternativBody->setContentTypeParameter($label, $data);
472 472
 		}
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 	 * @throws Exception\NotFound for no smtp account available
492 492
 	 * @throws Horde_Mime_Exception
493 493
 	 */
494
-	function send(Horde_Mail_Transport $transport=null, $resend=true, $flowed=null)
494
+	function send(Horde_Mail_Transport $transport = null, $resend = true, $flowed = null)
495 495
 	{
496
-		unset($resend);	// parameter is not used, but required by function signature
496
+		unset($resend); // parameter is not used, but required by function signature
497 497
 
498 498
 		if (!($message_id = $this->getHeader('Message-ID')) &&
499 499
 			class_exists('Horde_Mime_Headers_MessageId'))	// since 2.5.0
@@ -501,24 +501,24 @@  discard block
 block discarded – undo
501 501
 			$message_id = Horde_Mime_Headers_MessageId::create('EGroupware');
502 502
 			$this->addHeader('Message-ID', $message_id);
503 503
 		}
504
-		$body_sha1 = null;	// skip sha1, it requires whole mail in memory, which we traing to avoid now
504
+		$body_sha1 = null; // skip sha1, it requires whole mail in memory, which we traing to avoid now
505 505
 
506 506
 		$mail_id = Hooks::process(array(
507 507
 			'location' => 'send_mail',
508
-			'subject' => $subject=$this->getHeader('Subject'),
508
+			'subject' => $subject = $this->getHeader('Subject'),
509 509
 			'from' => $this->getHeader('Return-Path') ? $this->getHeader('Return-Path') : $this->getHeader('From'),
510
-			'to' => $to=$this->getAddresses('to', true),
511
-			'cc' => $cc=$this->getAddresses('cc', true),
512
-			'bcc' => $bcc=$this->getAddresses('bcc', true),
510
+			'to' => $to = $this->getAddresses('to', true),
511
+			'cc' => $cc = $this->getAddresses('cc', true),
512
+			'bcc' => $bcc = $this->getAddresses('bcc', true),
513 513
 			'body_sha1' => $body_sha1,
514 514
 			'message_id' => (string)$message_id,
515
-		), array(), true);	// true = call all apps
515
+		), array(), true); // true = call all apps
516 516
 
517 517
 		// check if we are sending an html mail with inline images
518 518
 		if (!empty($this->_htmlBody) && count($this->_parts))
519 519
 		{
520 520
 			$related = null;
521
-			foreach($this->_parts as $n => $part)
521
+			foreach ($this->_parts as $n => $part)
522 522
 			{
523 523
 				if ($part->getDisposition() == 'inline' && $part->getContentId())
524 524
 				{
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 				$this->_body = $body;
575 575
 				$flowed = false;
576 576
 			}
577
-			parent::send($transport ? $transport : $this->account->smtpTransport(), true,	$flowed);	// true: keep Message-ID
577
+			parent::send($transport ? $transport : $this->account->smtpTransport(), true, $flowed); // true: keep Message-ID
578 578
 		}
579 579
 		catch (\Exception $e) {
580 580
 			// in case of errors/exceptions call hook again with previous returned mail_id and error-message to log
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 				'message_id' => (string)$message_id,
590 590
 				'mail_id' => $mail_id,
591 591
 				'error' => $e->getMessage(),
592
-			), array(), true);	// true = call all apps
592
+			), array(), true); // true = call all apps
593 593
 		}
594 594
 
595 595
 		// log mails to file specified in $GLOBALS['egw_info']['server']['log_mail'] or error_log for true
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 			$msg .= ' from instance '.$GLOBALS['egw_info']['user']['domain'].' and IP '.Session::getuser_ip();
603 603
 			$msg .= ' from user #'.$GLOBALS['egw_info']['user']['account_id'];
604 604
 
605
-			if ($GLOBALS['egw_info']['user']['account_id'] && class_exists(__NAMESPACE__.'\\Accounts',false))
605
+			if ($GLOBALS['egw_info']['user']['account_id'] && class_exists(__NAMESPACE__.'\\Accounts', false))
606 606
 			{
607 607
 				$msg .= ' ('.Accounts::username($GLOBALS['egw_info']['user']['account_id']).')';
608 608
 			}
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 			$msg .= ' cc='.implode(', ', $cc).', bcc='.implode(', ', $bcc);
615 615
 			if ($GLOBALS['egw_info']['server']['log_mail'] !== true) $msg .= "\n\n";
616 616
 
617
-			error_log($msg,$GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
617
+			error_log($msg, $GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
618 618
 				$GLOBALS['egw_info']['server']['log_mail']);
619 619
 		}
620 620
 		// rethrow error
@@ -651,15 +651,15 @@  discard block
 block discarded – undo
651 651
      * @param  boolean $stream  If true, return a stream resource, otherwise
652 652
      * @return stream|string  The raw email data.
653 653
      */
654
-	function getRaw($stream=true)
654
+	function getRaw($stream = true)
655 655
 	{
656 656
 		try {
657 657
 			$this->getBasePart();
658 658
 		}
659
-		catch(Horde_Mail_Exception $e)
659
+		catch (Horde_Mail_Exception $e)
660 660
 		{
661 661
 			unset($e);
662
-			parent::send(new Horde_Mail_Transport_Null(), true);	// true: keep Message-ID
662
+			parent::send(new Horde_Mail_Transport_Null(), true); // true: keep Message-ID
663 663
 		}
664 664
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
665 665
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
@@ -669,12 +669,12 @@  discard block
 block discarded – undo
669 669
             return Horde_Stream_Wrapper_Combine::getStream(
670 670
                 array($hdr->stream,
671 671
                       $this->getBasePart()->toString(
672
-                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
672
+                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT|Horde_Mime_Part::ENCODE_8BIT|Horde_Mime_Part::ENCODE_BINARY))
673 673
                 )
674 674
             );
675 675
         }
676 676
 
677
-        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
677
+        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)).
678 678
 			$this->getBasePart()->toString(array('canonical' => true));
679 679
     }
680 680
 
@@ -687,23 +687,23 @@  discard block
 block discarded – undo
687 687
 	 * @param boolean &$converted =false on return if conversation was necessary
688 688
 	 * @return string|stream
689 689
 	 */
690
-	static function convert($message, $stream=false, $charset='utf-8', &$converted=false)
690
+	static function convert($message, $stream = false, $charset = 'utf-8', &$converted = false)
691 691
 	{
692
-		$mailer = new Mailer(false);	// false = no default headers and mail account
692
+		$mailer = new Mailer(false); // false = no default headers and mail account
693 693
 		$mailer->addHeaders(Horde_Mime_Headers::parseHeaders($message));
694 694
 		$base = Horde_Mime_Part::parseMessage($message);
695
-		foreach($base->partIterator() as $part)
695
+		foreach ($base->partIterator() as $part)
696 696
 		{
697
-			if ($part->getPrimaryType()== 'text')
697
+			if ($part->getPrimaryType() == 'text')
698 698
 			{
699 699
 				$charset = $part->getContentTypeParameter('charset');
700 700
 				if ($charset && $charset != 'utf-8')
701 701
 				{
702 702
 					$content = Translation::convert($part->toString(array(
703
-						'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
703
+						'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
704 704
 					)), $charset, 'utf-8');
705 705
 					$part->setContents($content, array(
706
-						'encode' => Horde_Mime_Part::ENCODE_BINARY,	// $content is NOT encoded
706
+						'encode' => Horde_Mime_Part::ENCODE_BINARY, // $content is NOT encoded
707 707
 					));
708 708
 					$part->setContentTypeParameter('charset', 'utf-8');
709 709
 					if ($part === $base)
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 	 * @param string $subtype =null
737 737
 	 * @return Horde_Mime_Part part with body or null
738 738
 	 */
739
-	function findBody($subtype=null)
739
+	function findBody($subtype = null)
740 740
 	{
741 741
 		try {
742 742
 			$base = $this->getBasePart();
@@ -768,11 +768,11 @@  discard block
 block discarded – undo
768 768
 			$this->_body = $this->_htmlBody = $this->_alternativBody = null;
769 769
 			$this->clearParts();
770 770
 
771
-			foreach($base->partIterator() as $part)
771
+			foreach ($base->partIterator() as $part)
772 772
 			{
773 773
 				$id = $part->getMimeId();
774 774
 				//error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType());
775
-				switch($id)
775
+				switch ($id)
776 776
 				{
777 777
 					case '0':	// base-part itself
778 778
 						continue 2;
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
 			$this->_body = $this->_htmlBody = $this->_alternativBody = null;
817 817
 			$this->clearParts();
818 818
 
819
-			foreach($base->partIterator() as $part)
819
+			foreach ($base->partIterator() as $part)
820 820
 			{
821 821
 				$id = $part->getMimeId();
822 822
 				//error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType());
823
-				switch($id)
823
+				switch ($id)
824 824
 				{
825 825
 					case '0':	// base-part itself
826 826
 						continue 2;
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
 	 */
893 893
 	function clearCustomHeaders()
894 894
 	{
895
-		foreach($this->_headers->toArray() as $header => $value)
895
+		foreach ($this->_headers->toArray() as $header => $value)
896 896
 		{
897 897
 			if (stripos($header, 'x-') === 0 || $header == 'Received')
898 898
 			{
Please login to merge, or discard this patch.
Braces   +50 added lines, -13 removed lines patch added patch discarded remove patch
@@ -117,10 +117,13 @@  discard block
 block discarded – undo
117 117
 		}
118 118
 		else
119 119
 		{
120
-			if (!($this->account = Mail\Account::get_default(true)))	// true = need an SMTP (not just IMAP) account
120
+			if (!($this->account = Mail\Account::get_default(true)))
121
+			{
122
+				// true = need an SMTP (not just IMAP) account
121 123
 			{
122 124
 				throw new Exception\NotFound('SMTP: '.lang('Account not found!'));
123 125
 			}
126
+			}
124 127
 		}
125 128
 
126 129
 		try
@@ -167,7 +170,10 @@  discard block
 block discarded – undo
167 170
 		{
168 171
 			throw new Exception\WrongParameter("Unknown type '$type'!");
169 172
 		}
170
-		if ($personal) $address = self::add_personal ($address, $personal);
173
+		if ($personal)
174
+		{
175
+			$address = self::add_personal ($address, $personal);
176
+		}
171 177
 
172 178
 		// add to our local list
173 179
 		$this->$type->add($address);
@@ -239,10 +245,13 @@  discard block
 block discarded – undo
239 245
 		if (is_string($address) && !empty($personal))
240 246
 		{
241 247
 			//if (!preg_match('/^[!#$%&\'*+/0-9=?A-Z^_`a-z{|}~-]+$/u', $personal))	// that's how I read the rfc(2)822
242
-			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))	// but quoting is never wrong, so quote more then necessary
248
+			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))
249
+			{
250
+				// but quoting is never wrong, so quote more then necessary
243 251
 			{
244 252
 				$personal = '"'.str_replace(array('\\', '"'),array('\\\\', '\\"'), $personal).'"';
245 253
 			}
254
+			}
246 255
 			$address = ($personal ? $personal.' <' : '').$address.($personal ? '>' : '');
247 256
 		}
248 257
 		return $address;
@@ -345,7 +354,10 @@  discard block
 block discarded – undo
345 354
 			throw new Exception\NotFound("File '$data' not found!");
346 355
 		}
347 356
 
348
-		if (empty($type) && !is_resource($data)) $type = Vfs::mime_content_type($data);
357
+		if (empty($type) && !is_resource($data))
358
+		{
359
+			$type = Vfs::mime_content_type($data);
360
+		}
349 361
 
350 362
 		// set "text/calendar; method=*" as alternativ body
351 363
 		$matches = null;
@@ -368,11 +380,17 @@  discard block
 block discarded – undo
368 380
 		$part->setContents($resource);
369 381
 
370 382
 		// setting name, also sets content-disposition attachment (!), therefore we have to do it after "text/calendar; method=" handling
371
-		if ($name || !is_resource($data)) $part->setName($name ? $name : Vfs::basename($data));
383
+		if ($name || !is_resource($data))
384
+		{
385
+			$part->setName($name ? $name : Vfs::basename($data));
386
+		}
372 387
 
373 388
 		// this should not be necessary, because binary data get detected by mime-type,
374 389
 		// but at least Cyrus complains about NUL characters
375
-		if (substr($type, 0, 5) != 'text/') $part->setTransferEncoding('base64', array('send' => true));
390
+		if (substr($type, 0, 5) != 'text/')
391
+		{
392
+			$part->setTransferEncoding('base64', array('send' => true));
393
+		}
376 394
 		$part->setDisposition('attachment');
377 395
 
378 396
 		return $this->addMimePart($part);
@@ -496,9 +514,12 @@  discard block
 block discarded – undo
496 514
 		unset($resend);	// parameter is not used, but required by function signature
497 515
 
498 516
 		if (!($message_id = $this->getHeader('Message-ID')) &&
499
-			class_exists('Horde_Mime_Headers_MessageId'))	// since 2.5.0
517
+			class_exists('Horde_Mime_Headers_MessageId'))
518
+		{
519
+			// since 2.5.0
500 520
 		{
501 521
 			$message_id = Horde_Mime_Headers_MessageId::create('EGroupware');
522
+		}
502 523
 			$this->addHeader('Message-ID', $message_id);
503 524
 		}
504 525
 		$body_sha1 = null;	// skip sha1, it requires whole mail in memory, which we traing to avoid now
@@ -538,7 +559,10 @@  discard block
 block discarded – undo
538 559
 
539 560
 		try {
540 561
 			// no flowed for encrypted messages
541
-			if (!isset($flowed)) $flowed = $this->_body && $this->_body->getType() != 'multipart/encrypted';
562
+			if (!isset($flowed))
563
+			{
564
+				$flowed = $this->_body && $this->_body->getType() != 'multipart/encrypted';
565
+			}
542 566
 
543 567
 			// check if flowed is disabled in mail site configuration
544 568
 			if (($config = Config::read('mail')) && $config['disable_rfc3676_flowed'])
@@ -612,13 +636,19 @@  discard block
 block discarded – undo
612 636
 				$msg .= 'ERROR '.$e->getMessage();
613 637
 			}
614 638
 			$msg .= ' cc='.implode(', ', $cc).', bcc='.implode(', ', $bcc);
615
-			if ($GLOBALS['egw_info']['server']['log_mail'] !== true) $msg .= "\n\n";
639
+			if ($GLOBALS['egw_info']['server']['log_mail'] !== true)
640
+			{
641
+				$msg .= "\n\n";
642
+			}
616 643
 
617 644
 			error_log($msg,$GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
618 645
 				$GLOBALS['egw_info']['server']['log_mail']);
619 646
 		}
620 647
 		// rethrow error
621
-		if (isset($e)) throw $e;
648
+		if (isset($e))
649
+		{
650
+			throw $e;
651
+		}
622 652
 	}
623 653
 
624 654
 
@@ -663,7 +693,8 @@  discard block
 block discarded – undo
663 693
 		}
664 694
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
665 695
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
666
-        if ($stream) {
696
+        if ($stream)
697
+        {
667 698
             $hdr = new Horde_Stream();
668 699
             $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
669 700
             return Horde_Stream_Wrapper_Combine::getStream(
@@ -740,7 +771,10 @@  discard block
 block discarded – undo
740 771
 	{
741 772
 		try {
742 773
 			$base = $this->getBasePart();
743
-			if (!($part_id = $base->findBody($subtype))) return null;
774
+			if (!($part_id = $base->findBody($subtype)))
775
+			{
776
+				return null;
777
+			}
744 778
 			return $base->getPart($part_id);
745 779
 		}
746 780
 		catch (Exception $e) {
@@ -854,7 +888,10 @@  discard block
 block discarded – undo
854 888
 	 */
855 889
 	public function addMimePart($part)
856 890
 	{
857
-		if ($this->_base) $this->parseBasePart();
891
+		if ($this->_base)
892
+		{
893
+			$this->parseBasePart();
894
+		}
858 895
 
859 896
 		return parent::addMimePart($part);
860 897
 	}
Please login to merge, or discard this patch.
api/src/Session.php 4 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -311,6 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * Encrypt the variables in the session
312 312
 	 *
313 313
 	 * Is called by self::__destruct().
314
+	 * @param string $kp3
314 315
 	 */
315 316
 	static function encrypt($kp3)
316 317
 	{
@@ -439,7 +440,7 @@  discard block
 block discarded – undo
439 440
 	 * @param boolean $no_session =false dont create a real session, eg. for GroupDAV clients using only basic auth, no cookie support
440 441
 	 * @param boolean $auth_check =true if false, the user is loged in without checking his password (eg. for single sign on), default = true
441 442
 	 * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested
442
-	 * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause
443
+	 * @return false|string session id or false if session was not created, $this->(cd_)reason contains cause
443 444
 	 */
444 445
 	function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false)
445 446
 	{
@@ -1021,7 +1022,7 @@  discard block
 block discarded – undo
1021 1022
 	/**
1022 1023
 	 * Terminate a session
1023 1024
 	 *
1024
-	 * @param int|string $sessionid nummeric or php session id of session to be terminated
1025
+	 * @param string $sessionid nummeric or php session id of session to be terminated
1025 1026
 	 * @param string $kp3
1026 1027
 	 * @return boolean true on success, false on error
1027 1028
 	 */
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -80,60 +80,60 @@  discard block
 block discarded – undo
80 80
 	const MCRYPT_MODE = MCRYPT_MODE_ECB;
81 81
 
82 82
 	/**
83
-	* current user login (account_lid@domain)
84
-	*
85
-	* @var string
86
-	*/
83
+	 * current user login (account_lid@domain)
84
+	 *
85
+	 * @var string
86
+	 */
87 87
 	var $login;
88 88
 
89 89
 	/**
90
-	* current user password
91
-	*
92
-	* @var string
93
-	*/
90
+	 * current user password
91
+	 *
92
+	 * @var string
93
+	 */
94 94
 	var $passwd;
95 95
 
96 96
 	/**
97
-	* current user db/ldap account id
98
-	*
99
-	* @var int
100
-	*/
97
+	 * current user db/ldap account id
98
+	 *
99
+	 * @var int
100
+	 */
101 101
 	var $account_id;
102 102
 
103 103
 	/**
104
-	* current user account login id (without the eGW-domain/-instance part
105
-	*
106
-	* @var string
107
-	*/
104
+	 * current user account login id (without the eGW-domain/-instance part
105
+	 *
106
+	 * @var string
107
+	 */
108 108
 	var $account_lid;
109 109
 
110 110
 	/**
111
-	* domain for current user
112
-	*
113
-	* @var string
114
-	*/
111
+	 * domain for current user
112
+	 *
113
+	 * @var string
114
+	 */
115 115
 	var $account_domain;
116 116
 
117 117
 	/**
118
-	* type flag, A - anonymous session, N - None, normal session
119
-	*
120
-	* @var string
121
-	*/
118
+	 * type flag, A - anonymous session, N - None, normal session
119
+	 *
120
+	 * @var string
121
+	 */
122 122
 	var $session_flags;
123 123
 
124 124
 	/**
125
-	* current user session id
126
-	*
127
-	* @var string
128
-	*/
125
+	 * current user session id
126
+	 *
127
+	 * @var string
128
+	 */
129 129
 	var $sessionid;
130 130
 
131 131
 	/**
132
-	* an other session specific id (md5 from a random string),
133
-	* used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled)
134
-	*
135
-	* @var string
136
-	*/
132
+	 * an other session specific id (md5 from a random string),
133
+	 * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled)
134
+	 *
135
+	 * @var string
136
+	 */
137 137
 	var $kp3;
138 138
 
139 139
 	/**
@@ -144,17 +144,17 @@  discard block
 block discarded – undo
144 144
 	var $sessionid_access_log;
145 145
 
146 146
 	/**
147
-	* name of XML-RPC/SOAP method called
148
-	*
149
-	* @var string
150
-	*/
147
+	 * name of XML-RPC/SOAP method called
148
+	 *
149
+	 * @var string
150
+	 */
151 151
 	var $xmlrpc_method_called;
152 152
 
153 153
 	/**
154
-	* Array with the name of the system domains
155
-	*
156
-	* @var array
157
-	*/
154
+	 * Array with the name of the system domains
155
+	 *
156
+	 * @var array
157
+	 */
158 158
 	private $egw_domains;
159 159
 
160 160
 	/**
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
 
249 249
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
250 250
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
251
-      	{
252
-      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
253
-      	}
251
+	  	{
252
+	  		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
253
+	  	}
254 254
 	}
255 255
 
256 256
 	/**
@@ -661,14 +661,14 @@  discard block
 block discarded – undo
661 661
 	const ACCESS_LOG_TABLE = 'egw_access_log';
662 662
 
663 663
 	/**
664
-    * Write or update (for logout) the access_log
665
-	*
666
-	* @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins
667
-	* @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time
668
-	* @param string $user_ip ='' ip to log
669
-	* @param int $account_id =0 numerical account_id
670
-	* @return int $sessionid primary key of egw_access_log for login, null otherwise
671
-	*/
664
+	 * Write or update (for logout) the access_log
665
+	 *
666
+	 * @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins
667
+	 * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time
668
+	 * @param string $user_ip ='' ip to log
669
+	 * @param int $account_id =0 numerical account_id
670
+	 * @return int $sessionid primary key of egw_access_log for login, null otherwise
671
+	 */
672 672
 	private function log_access($sessionid,$login='',$user_ip='',$account_id=0)
673 673
 	{
674 674
 		$now = time();
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 
717 717
 	/**
718 718
 	 * Protect against brute force attacks, block login if too many unsuccessful login attmepts
719
-     *
719
+	 *
720 720
 	 * @param string $login account_lid (evtl. with domain)
721 721
 	 * @param string $ip ip of the user
722 722
 	 * @returns bool login blocked?
Please login to merge, or discard this patch.
Spacing   +165 added lines, -168 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	const CD_BAD_LOGIN_OR_PASSWORD = 5;
174 174
 	const CD_FORCE_PASSWORD_CHANGE = 97;
175 175
 	const CD_ACCOUNT_EXPIRED = 98;
176
-	const CD_BLOCKED = 99;	// to many failed attempts to loing
176
+	const CD_BLOCKED = 99; // to many failed attempts to loing
177 177
 
178 178
 	/**
179 179
 	 * Verbose reason why session creation failed
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 *
188 188
 	 * @param array $domain_names =null domain-names used in this install
189 189
 	 */
190
-	function __construct(array $domain_names=null)
190
+	function __construct(array $domain_names = null)
191 191
 	{
192 192
 		$this->required_files = $_SESSION[self::EGW_REQUIRED_FILES];
193 193
 
@@ -203,27 +203,27 @@  discard block
 block discarded – undo
203 203
 			$save_rep = false;
204 204
 			if (!isset($GLOBALS['egw_info']['server']['max_access_log_age']))
205 205
 			{
206
-				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90;	// default 90 days
206
+				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days
207 207
 				$save_rep = true;
208 208
 			}
209 209
 			if (!isset($GLOBALS['egw_info']['server']['block_time']))
210 210
 			{
211
-				$GLOBALS['egw_info']['server']['block_time'] = 1;	// default 1min, its enough to slow down brute force attacks
211
+				$GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks
212 212
 				$save_rep = true;
213 213
 			}
214 214
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_id']))
215 215
 			{
216
-				$GLOBALS['egw_info']['server']['num_unsuccessful_id']  = 3;	// default 3 trys per id
216
+				$GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id
217 217
 				$save_rep = true;
218 218
 			}
219 219
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_ip']))
220 220
 			{
221
-				$GLOBALS['egw_info']['server']['num_unsuccessful_ip']  = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5;	// default is 5 times as high as the id default; since accessing via proxy is quite common
221
+				$GLOBALS['egw_info']['server']['num_unsuccessful_ip'] = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5; // default is 5 times as high as the id default; since accessing via proxy is quite common
222 222
 				$save_rep = true;
223 223
 			}
224 224
 			if (!isset($GLOBALS['egw_info']['server']['install_id']))
225 225
 			{
226
-				$GLOBALS['egw_info']['server']['install_id']  = md5(Auth::randomstring(15));
226
+				$GLOBALS['egw_info']['server']['install_id'] = md5(Auth::randomstring(15));
227 227
 			}
228 228
 			if (!isset($GLOBALS['egw_info']['server']['max_history']))
229 229
 			{
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
 			{
236 236
 				$config = new Config('phpgwapi');
237 237
 				$config->read_repository();
238
-				$config->value('max_access_log_age',$GLOBALS['egw_info']['server']['max_access_log_age']);
239
-				$config->value('block_time',$GLOBALS['egw_info']['server']['block_time']);
240
-				$config->value('num_unsuccessful_id',$GLOBALS['egw_info']['server']['num_unsuccessful_id']);
241
-				$config->value('num_unsuccessful_ip',$GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
242
-				$config->value('install_id',$GLOBALS['egw_info']['server']['install_id']);
243
-				$config->value('max_history',$GLOBALS['egw_info']['server']['max_history']);
238
+				$config->value('max_access_log_age', $GLOBALS['egw_info']['server']['max_access_log_age']);
239
+				$config->value('block_time', $GLOBALS['egw_info']['server']['block_time']);
240
+				$config->value('num_unsuccessful_id', $GLOBALS['egw_info']['server']['num_unsuccessful_id']);
241
+				$config->value('num_unsuccessful_ip', $GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
242
+				$config->value('install_id', $GLOBALS['egw_info']['server']['install_id']);
243
+				$config->value('max_history', $GLOBALS['egw_info']['server']['max_history']);
244 244
 				$config->save_repository();
245 245
 			}
246 246
 		}
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
250 250
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
251 251
       	{
252
-      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
252
+      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout'] = 14400);
253 253
       	}
254 254
 	}
255 255
 
@@ -319,15 +319,15 @@  discard block
 block discarded – undo
319 319
 
320 320
 		if (!isset($_SESSION[self::EGW_SESSION_ENCRYPTED]) && self::init_crypt($kp3))
321 321
 		{
322
-			foreach(self::$egw_session_vars as $name)
322
+			foreach (self::$egw_session_vars as $name)
323 323
 			{
324 324
 				if (isset($_SESSION[$name]))
325 325
 				{
326
-					$_SESSION[$name] = mcrypt_generic(self::$mcrypt,serialize($_SESSION[$name]));
326
+					$_SESSION[$name] = mcrypt_generic(self::$mcrypt, serialize($_SESSION[$name]));
327 327
 					//error_log(__METHOD__."() 'encrypting' session var: $name, len=".strlen($_SESSION[$name]));
328 328
 				}
329 329
 			}
330
-			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true;	// flag session as encrypted
330
+			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted
331 331
 
332 332
 			mcrypt_generic_deinit(self::$mcrypt);
333 333
 			self::$mcrypt = null;
@@ -342,24 +342,24 @@  discard block
 block discarded – undo
342 342
 	 * @param boolean $recursion =true if true call itself for every item > $limit
343 343
 	 * @param int $limit =1000 log only differences > $limit
344 344
 	 */
345
-	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
345
+	static function log_session_usage(&$arr, $label, $recursion = true, $limit = 1000)
346 346
 	{
347 347
 		if (!is_array($arr)) return;
348 348
 
349 349
 		$sizes = array();
350
-		foreach($arr as $key => &$data)
350
+		foreach ($arr as $key => &$data)
351 351
 		{
352 352
 			$sizes[$key] = strlen(serialize($data));
353 353
 		}
354
-		arsort($sizes,SORT_NUMERIC);
355
-		foreach($sizes as $key => $size)
354
+		arsort($sizes, SORT_NUMERIC);
355
+		foreach ($sizes as $key => $size)
356 356
 		{
357 357
 			$diff = $size - (int)$_SESSION[$label.'-sizes'][$key];
358 358
 			$_SESSION[$label.'-sizes'][$key] = $size;
359 359
 			if ($diff > $limit)
360 360
 			{
361 361
 				error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff));
362
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
362
+				if ($recursion) self::log_session_usage($arr[$key], $label.'['.$key.']', $recursion, $limit);
363 363
 			}
364 364
 		}
365 365
 	}
@@ -374,15 +374,15 @@  discard block
 block discarded – undo
374 374
 	{
375 375
 		if ($_SESSION[self::EGW_SESSION_ENCRYPTED] && self::init_crypt(self::get_request('kp3')))
376 376
 		{
377
-			foreach(self::$egw_session_vars as $name)
377
+			foreach (self::$egw_session_vars as $name)
378 378
 			{
379 379
 				if (isset($_SESSION[$name]))
380 380
 				{
381
-					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt,$_SESSION[$name])));
381
+					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt, $_SESSION[$name])));
382 382
 					//error_log(__METHOD__."() 'decrypting' session var $name: gettype($name) = ".gettype($_SESSION[$name]));
383 383
 				}
384 384
 			}
385
-			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]);	// delete encryption flag
385
+			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag
386 386
 		}
387 387
 	}
388 388
 
@@ -395,15 +395,15 @@  discard block
 block discarded – undo
395 395
 	 * @param string $mode =self::MCRYPT_MODE
396 396
 	 * @return boolean true if encryption is used, false otherwise
397 397
 	 */
398
-	static private function init_crypt($kp3,$algo=self::MCRYPT_ALGO,$mode=self::MCRYPT_MODE)
398
+	static private function init_crypt($kp3, $algo = self::MCRYPT_ALGO, $mode = self::MCRYPT_MODE)
399 399
 	{
400
-		if(!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
400
+		if (!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
401 401
 		{
402
-			return false;	// session encryption is switched off
402
+			return false; // session encryption is switched off
403 403
 		}
404 404
 		if ($GLOBALS['egw_info']['currentapp'] == 'syncml' || !$kp3)
405 405
 		{
406
-			$kp3 = 'staticsyncmlkp3';	// syncml has no kp3!
406
+			$kp3 = 'staticsyncmlkp3'; // syncml has no kp3!
407 407
 		}
408 408
 		if (is_null(self::$mcrypt))
409 409
 		{
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
 			}
420 420
 			$iv_size = mcrypt_enc_get_iv_size(self::$mcrypt);
421 421
 			$iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ?
422
-				mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size);
422
+				mcrypt_create_iv($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size);
423 423
 
424
-			if (mcrypt_generic_init(self::$mcrypt,$kp3, $iv) < 0)
424
+			if (mcrypt_generic_init(self::$mcrypt, $kp3, $iv) < 0)
425 425
 			{
426 426
 				error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!");
427 427
 				return self::$mcrypt = false;
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 	 * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested
442 442
 	 * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause
443 443
 	 */
444
-	function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false)
444
+	function create($login, $passwd = '', $passwd_type = '', $no_session = false, $auth_check = true, $fail_on_forced_password_change = false)
445 445
 	{
446 446
 		try {
447 447
 			if (is_array($login))
@@ -459,9 +459,9 @@  discard block
 block discarded – undo
459 459
 			}
460 460
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
461 461
 
462
-			self::split_login_domain($login,$this->account_lid,$this->account_domain);
462
+			self::split_login_domain($login, $this->account_lid, $this->account_domain);
463 463
 			// add domain to the login, if not already there
464
-			if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain)
464
+			if (substr($this->login, -strlen($this->account_domain) - 1) != '@'.$this->account_domain)
465 465
 			{
466 466
 				$this->login .= '@'.$this->account_domain;
467 467
 			}
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 			{
479 479
 				$this->account_domain = $GLOBALS['egw_info']['user']['domain'];
480 480
 			}
481
-			elseif($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
481
+			elseif ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
482 482
 			{
483 483
 				throw new Exception("Wrong domain! '$this->account_domain' != '{$GLOBALS['egw_info']['user']['domain']}'");
484 484
 			}
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
 
487 487
 			$user_ip = self::getuser_ip();
488 488
 
489
-			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
489
+			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
490 490
 
491
-			if (($blocked = $this->login_blocked($login,$user_ip)) ||	// too many unsuccessful attempts
491
+			if (($blocked = $this->login_blocked($login, $user_ip)) || // too many unsuccessful attempts
492 492
 				$GLOBALS['egw_info']['server']['global_denied_users'][$this->account_lid] ||
493 493
 				$auth_check && !$GLOBALS['egw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) ||
494 494
 				$this->account_id && $GLOBALS['egw']->accounts->get_type($this->account_id) == 'g')
@@ -497,9 +497,9 @@  discard block
 block discarded – undo
497 497
 				$this->cd_reason = $blocked ? self::CD_BLOCKED : self::CD_BAD_LOGIN_OR_PASSWORD;
498 498
 
499 499
 				// we dont log anon users as it would block the website
500
-				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id,'anonymous','phpgwapi'))
500
+				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id, 'anonymous', 'phpgwapi'))
501 501
 				{
502
-					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
502
+					$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
503 503
 				}
504 504
 				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
505 505
 				return false;
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 			if ($this->account_lid != ($lid = $GLOBALS['egw']->accounts->id2name($this->account_id)))
522 522
 			{
523 523
 				$this->account_lid = $lid;
524
-				$this->login = $lid.substr($this->login,strlen($lid));
524
+				$this->login = $lid.substr($this->login, strlen($lid));
525 525
 			}
526 526
 
527 527
 			$GLOBALS['egw_info']['user']['account_id'] = $this->account_id;
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 				}
544 544
 				$this->sessionid = session_id();
545 545
 			}
546
-			$this->kp3       = Auth::randomstring(24);
546
+			$this->kp3 = Auth::randomstring(24);
547 547
 
548 548
 			$GLOBALS['egw_info']['user'] = $this->read_repositories();
549 549
 			if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 
558 558
 			Cache::setSession('phpgwapi', 'password', base64_encode($this->passwd));
559 559
 
560
-			if ($GLOBALS['egw']->acl->check('anonymous',1,'phpgwapi'))
560
+			if ($GLOBALS['egw']->acl->check('anonymous', 1, 'phpgwapi'))
561 561
 			{
562 562
 				$this->session_flags = 'A';
563 563
 			}
@@ -575,46 +575,46 @@  discard block
 block discarded – undo
575 575
 				'passwd'         => $this->passwd,
576 576
 				'account_domain' => $this->account_domain,
577 577
 				'user_ip'        => $user_ip,
578
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
578
+			), '', true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
579 579
 			{
580
-				foreach($hook_result as $reason)
580
+				foreach ($hook_result as $reason)
581 581
 				{
582 582
 					if ($reason)	// called hook requests to deny the session
583 583
 					{
584 584
 						$this->reason = $this->cd_reason = $reason;
585
-						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
585
+						$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
586 586
 						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
587 587
 						return false;
588 588
 					}
589 589
 				}
590 590
 			}
591 591
 			$GLOBALS['egw']->db->transaction_begin();
592
-			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
592
+			$this->register_session($this->login, $user_ip, $now, $this->session_flags);
593 593
 			if ($this->session_flags != 'A')		// dont log anonymous sessions
594 594
 			{
595
-				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
595
+				$this->sessionid_access_log = $this->log_access($this->sessionid, $login, $user_ip, $this->account_id);
596 596
 			}
597 597
 			Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login);
598
-			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
598
+			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id, $user_ip);
599 599
 			$GLOBALS['egw']->db->transaction_commit();
600 600
 
601 601
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session)
602 602
 			{
603
-				self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
604
-				self::egw_setcookie('kp3',$this->kp3);
605
-				self::egw_setcookie('domain',$this->account_domain);
603
+				self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
604
+				self::egw_setcookie('kp3', $this->kp3);
605
+				self::egw_setcookie('domain', $this->account_domain);
606 606
 			}
607 607
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session || isset($_COOKIE['last_loginid']))
608 608
 			{
609
-				self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
610
-				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
609
+				self::egw_setcookie('last_loginid', $this->account_lid, $now + 1209600); /* For 2 weeks */
610
+				self::egw_setcookie('last_domain', $this->account_domain, $now + 1209600);
611 611
 			}
612 612
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
613 613
 
614 614
 			return $this->sessionid;
615 615
 		}
616 616
 		// catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password
617
-		catch(Exception $e) {
617
+		catch (Exception $e) {
618 618
 			$this->reason = $this->cd_reason = $e->getMessage();
619 619
 			error_log(__METHOD__."('$login', ".array2string(str_repeat('*', strlen($passwd))).
620 620
 				", '$passwd_type', no_session=".array2string($no_session).
@@ -633,13 +633,12 @@  discard block
 block discarded – undo
633 633
 	 * @param int $now
634 634
 	 * @param string $session_flags
635 635
 	 */
636
-	private function register_session($login,$user_ip,$now,$session_flags)
636
+	private function register_session($login, $user_ip, $now, $session_flags)
637 637
 	{
638 638
 		// restore session vars set before session was started
639 639
 		if (is_array($this->required_files))
640 640
 		{
641
-			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files :
642
-				array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES],$this->required_files));
641
+			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files : array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES], $this->required_files));
643 642
 			unset($this->required_files);
644 643
 		}
645 644
 		$_SESSION[self::EGW_SESSION_VAR] = array(
@@ -669,13 +668,13 @@  discard block
 block discarded – undo
669 668
 	* @param int $account_id =0 numerical account_id
670 669
 	* @return int $sessionid primary key of egw_access_log for login, null otherwise
671 670
 	*/
672
-	private function log_access($sessionid,$login='',$user_ip='',$account_id=0)
671
+	private function log_access($sessionid, $login = '', $user_ip = '', $account_id = 0)
673 672
 	{
674 673
 		$now = time();
675 674
 
676 675
 		if ($login)
677 676
 		{
678
-			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE,array(
677
+			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE, array(
679 678
 				'session_php' => $sessionid,
680 679
 				'loginid'   => $login,
681 680
 				'ip'        => $user_ip,
@@ -683,10 +682,10 @@  discard block
 block discarded – undo
683 682
 				'account_id'=> $account_id,
684 683
 				'user_agent'=> $_SERVER['HTTP_USER_AGENT'],
685 684
 				'session_dla'    => $now,
686
-				'session_action' => $this->update_dla(false),	// dont update egw_access_log
687
-			),false,__LINE__,__FILE__);
685
+				'session_action' => $this->update_dla(false), // dont update egw_access_log
686
+			), false, __LINE__, __FILE__);
688 687
 
689
-			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE,'sessionid');
688
+			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE, 'sessionid');
690 689
 		}
691 690
 		else
692 691
 		{
@@ -694,20 +693,20 @@  discard block
 block discarded – undo
694 693
 			{
695 694
 				$sessionid = $this->sessionid_access_log;
696 695
 			}
697
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
696
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
698 697
 				'lo' => $now
699
-			),is_numeric($sessionid) ? array(
698
+			), is_numeric($sessionid) ? array(
700 699
 				'sessionid' => $sessionid,
701 700
 			) : array(
702 701
 				'session_php' => $sessionid,
703
-			),__LINE__,__FILE__);
702
+			), __LINE__, __FILE__);
704 703
 
705 704
 			// run maintenance only on logout, to not delay login
706 705
 			if ($GLOBALS['egw_info']['server']['max_access_log_age'])
707 706
 			{
708 707
 				$max_age = $now - $GLOBALS['egw_info']['server']['max_access_log_age'] * 24 * 60 * 60;
709 708
 
710
-				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE,"li < $max_age",__LINE__,__FILE__);
709
+				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE, "li < $max_age", __LINE__, __FILE__);
711 710
 			}
712 711
 		}
713 712
 		//error_log(__METHOD__."('$sessionid', '$login', '$user_ip', $account_id) returning ".array2string($ret));
@@ -721,12 +720,12 @@  discard block
 block discarded – undo
721 720
 	 * @param string $ip ip of the user
722 721
 	 * @returns bool login blocked?
723 722
 	 */
724
-	private function login_blocked($login,$ip)
723
+	private function login_blocked($login, $ip)
725 724
 	{
726 725
 		$block_time = time() - $GLOBALS['egw_info']['server']['block_time'] * 60;
727 726
 
728 727
 		$false_id = $false_ip = 0;
729
-		foreach($GLOBALS['egw']->db->union(array(
728
+		foreach ($GLOBALS['egw']->db->union(array(
730 729
 			array(
731 730
 				'table' => self::ACCESS_LOG_TABLE,
732 731
 				'cols'  => "'false_ip' AS name,COUNT(*) AS num",
@@ -763,28 +762,28 @@  discard block
 block discarded – undo
763 762
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
764 763
 
765 764
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
766
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
765
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time() - 5 * 60)	// max. one mail every 5mins
767 766
 		{
768 767
 			try {
769 768
 				$mailer = new Mailer();
770 769
 				// notify admin(s) via email
771 770
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
772
-				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
773
-				$mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4",$false_id,$login,$false_ip,$ip));
774
-				foreach(preg_split('/,\s*/',$GLOBALS['egw_info']['server']['admin_mails']) as $mail)
771
+				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2", $login, $ip));
772
+				$mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4", $false_id, $login, $false_ip, $ip));
773
+				foreach (preg_split('/,\s*/', $GLOBALS['egw_info']['server']['admin_mails']) as $mail)
775 774
 				{
776 775
 					$mailer->addAddress($mail);
777 776
 				}
778 777
 				$mailer->send();
779 778
 			}
780
-			catch(Exception $e) {
779
+			catch (Exception $e) {
781 780
 				// ignore exception, but log it, to block the account and give a correct error-message to user
782 781
 				error_log(__METHOD__."('$login', '$ip') ".$e->getMessage());
783 782
 			}
784 783
 			// save time of mail, to not send to many mails
785 784
 			$config = new Config('phpgwapi');
786 785
 			$config->read_repository();
787
-			$config->value('login_blocked_mail_time',time());
786
+			$config->value('login_blocked_mail_time', time());
788 787
 			$config->save_repository();
789 788
 		}
790 789
 		return $blocked;
@@ -805,7 +804,7 @@  discard block
 block discarded – undo
805 804
 	 * @param boolean $only_basic_auth =false return only a basic auth pseudo sessionid, default no
806 805
 	 * @return string
807 806
 	 */
808
-	static function get_sessionid($only_basic_auth=false)
807
+	static function get_sessionid($only_basic_auth = false)
809 808
 	{
810 809
 		// for WebDAV and GroupDAV we use a pseudo sessionid created from md5(user:passwd)
811 810
 		// --> allows this stateless protocolls which use basic auth to use sessions!
@@ -832,11 +831,11 @@  discard block
 block discarded – undo
832 831
 				EGW_SERVER_ROOT.':'.self::getuser_ip().':'.filemtime(EGW_SERVER_ROOT.'/phpgwapi/setup/setup.inc.php').
833 832
 				':'.$_SERVER['HTTP_USER_AGENT']);
834 833
 		}
835
-		elseif(!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
834
+		elseif (!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
836 835
 		{
837 836
 			$sessionid = $_REQUEST[self::EGW_SESSION_NAME];
838 837
 		}
839
-		elseif(!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
838
+		elseif (!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
840 839
 		{
841 840
 			$sessionid = $_COOKIE[self::EGW_SESSION_NAME];
842 841
 		}
@@ -844,7 +843,7 @@  discard block
 block discarded – undo
844 843
 		{
845 844
 			$sessionid = false;
846 845
 		}
847
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
846
+		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid, true));
848 847
 		return $sessionid;
849 848
 	}
850 849
 
@@ -860,9 +859,7 @@  discard block
 block discarded – undo
860 859
 	 */
861 860
 	static function get_request($name)
862 861
 	{
863
-		return isset($_REQUEST[$name]) ? $_REQUEST[$name] :
864
-			(isset($_COOKIE[$name]) ? $_COOKIE[$name] :
865
-			(isset($_COOKIE[$name=ucfirst($name)]) ? $_COOKIE[$name] : null));
862
+		return isset($_REQUEST[$name]) ? $_REQUEST[$name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : (isset($_COOKIE[$name = ucfirst($name)]) ? $_COOKIE[$name] : null));
866 863
 	}
867 864
 
868 865
 	/**
@@ -872,13 +869,13 @@  discard block
 block discarded – undo
872 869
 	 * @param string $kp3 ?? to be verified
873 870
 	 * @return bool is the session valid?
874 871
 	 */
875
-	function verify($sessionid=null,$kp3=null)
872
+	function verify($sessionid = null, $kp3 = null)
876 873
 	{
877 874
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
878 875
 
879 876
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
880 877
 
881
-		if(!$sessionid)
878
+		if (!$sessionid)
882 879
 		{
883 880
 			$sessionid = self::get_sessionid();
884 881
 			$kp3       = self::get_request('kp3');
@@ -905,23 +902,23 @@  discard block
 block discarded – undo
905 902
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
906 903
 			return false;
907 904
 		}
908
-		$session =& $_SESSION[self::EGW_SESSION_VAR];
905
+		$session = & $_SESSION[self::EGW_SESSION_VAR];
909 906
 
910 907
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
911 908
 		{
912 909
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
913
-			$this->destroy($sessionid,$kp3);
910
+			$this->destroy($sessionid, $kp3);
914 911
 			return false;
915 912
 		}
916 913
 
917 914
 		$this->session_flags = $session['session_flags'];
918 915
 
919
-		$this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain);
916
+		$this->split_login_domain($session['session_lid'], $this->account_lid, $this->account_domain);
920 917
 
921 918
 		// This is to ensure that we authenticate to the correct domain (might not be default)
922
-		if($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
919
+		if ($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
923 920
 		{
924
-			return false;	// session not verified, domain changed
921
+			return false; // session not verified, domain changed
925 922
 		}
926 923
 		$GLOBALS['egw_info']['user']['kp3'] = $this->kp3;
927 924
 
@@ -934,7 +931,7 @@  discard block
 block discarded – undo
934 931
 		{
935 932
 			$this->update_notification_heartbeat();
936 933
 		}
937
-		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
934
+		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
938 935
 		if (!$this->account_id)
939 936
 		{
940 937
 			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
@@ -972,7 +969,7 @@  discard block
 block discarded – undo
972 969
 
973 970
 		if ($GLOBALS['egw_info']['server']['sessions_checkip'])
974 971
 		{
975
-			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
972
+			if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
976 973
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
977 974
 			{
978 975
 				if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP");
@@ -995,9 +992,9 @@  discard block
 block discarded – undo
995 992
 		// query accesslog-id, if not set in session (session is made persistent after login!)
996 993
 		if (!$this->sessionid_access_log && $this->session_flags != 'A')
997 994
 		{
998
-			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'sessionid',array(
995
+			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'sessionid', array(
999 996
 				'session_php' => $this->sessionid,
1000
-			),__LINE__,__FILE__)->fetchColumn();
997
+			), __LINE__, __FILE__)->fetchColumn();
1001 998
 			//error_log(__METHOD__."() sessionid=$this->sessionid --> sessionid_access_log=$this->sessionid_access_log");
1002 999
 		}
1003 1000
 
@@ -1008,9 +1005,9 @@  discard block
 block discarded – undo
1008 1005
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1009 1006
 		{
1010 1007
 			if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1011
-			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1012
-			self::egw_setcookie('kp3',$this->kp3);
1013
-			self::egw_setcookie('domain',$this->account_domain);
1008
+			self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
1009
+			self::egw_setcookie('kp3', $this->kp3);
1010
+			self::egw_setcookie('domain', $this->account_domain);
1014 1011
 		}
1015 1012
 
1016 1013
 		if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS");
@@ -1025,27 +1022,27 @@  discard block
 block discarded – undo
1025 1022
 	 * @param string $kp3
1026 1023
 	 * @return boolean true on success, false on error
1027 1024
 	 */
1028
-	function destroy($sessionid, $kp3='')
1025
+	function destroy($sessionid, $kp3 = '')
1029 1026
 	{
1030 1027
 		if (!$sessionid && $kp3)
1031 1028
 		{
1032 1029
 			return false;
1033 1030
 		}
1034
-		$this->log_access($sessionid);	// log logout-time
1031
+		$this->log_access($sessionid); // log logout-time
1035 1032
 
1036 1033
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1037 1034
 
1038 1035
 		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1039 1036
 		{
1040
-			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1037
+			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'session_php', array(
1041 1038
 					'sessionid' => $sessionid,
1042
-				),__LINE__,__FILE__)->fetchColumn();
1039
+				), __LINE__, __FILE__)->fetchColumn();
1043 1040
 		}
1044 1041
 
1045 1042
 		Hooks::process(array(
1046 1043
 			'location'  => 'session_destroyed',
1047 1044
 			'sessionid' => $sessionid,
1048
-		),'',true);	// true = run hooks from all apps, not just the ones the current user has perms to run
1045
+		), '', true); // true = run hooks from all apps, not just the ones the current user has perms to run
1049 1046
 
1050 1047
 		// Only do the following, if where working with the current user
1051 1048
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
@@ -1066,7 +1063,7 @@  discard block
 block discarded – undo
1066 1063
 		}
1067 1064
 		else
1068 1065
 		{
1069
-			$this->commit_session();	// close our own session
1066
+			$this->commit_session(); // close our own session
1070 1067
 
1071 1068
 			session_id($sessionid);
1072 1069
 			if (session_start())
@@ -1106,25 +1103,25 @@  discard block
 block discarded – undo
1106 1103
 		// as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html)
1107 1104
 		if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false))
1108 1105
 		{
1109
-			if($url[0] != '/' && substr($webserver_url,-1) != '/')
1106
+			if ($url[0] != '/' && substr($webserver_url, -1) != '/')
1110 1107
 			{
1111
-				$url = $webserver_url .'/'. $url;
1108
+				$url = $webserver_url.'/'.$url;
1112 1109
 			}
1113 1110
 			else
1114 1111
 			{
1115
-				$url = $webserver_url . $url;
1112
+				$url = $webserver_url.$url;
1116 1113
 			}
1117 1114
 		}
1118 1115
 
1119
-		if(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1116
+		if (isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1120 1117
 		{
1121
-			if(substr($url ,0,4) != 'http')
1118
+			if (substr($url, 0, 4) != 'http')
1122 1119
 			{
1123 1120
 				$url = 'https://'.$_SERVER['HTTP_HOST'].$url;
1124 1121
 			}
1125 1122
 			else
1126 1123
 			{
1127
-				$url = str_replace ( 'http:', 'https:', $url);
1124
+				$url = str_replace('http:', 'https:', $url);
1128 1125
 			}
1129 1126
 		}
1130 1127
 		$vars = array();
@@ -1137,7 +1134,7 @@  discard block
 block discarded – undo
1137 1134
 		}
1138 1135
 
1139 1136
 		// check if the url already contains a query and ensure that vars is an array and all strings are in extravars
1140
-		list($ret_url,$othervars) = explode('?', $url, 2);
1137
+		list($ret_url, $othervars) = explode('?', $url, 2);
1141 1138
 		if ($extravars && is_array($extravars))
1142 1139
 		{
1143 1140
 			$vars += $extravars;
@@ -1145,19 +1142,19 @@  discard block
 block discarded – undo
1145 1142
 		}
1146 1143
 		else
1147 1144
 		{
1148
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1145
+			if ($othervars) $extravars .= ($extravars ? '&' : '').$othervars;
1149 1146
 		}
1150 1147
 
1151 1148
 		// parse extravars string into the vars array
1152 1149
 		if ($extravars)
1153 1150
 		{
1154
-			foreach(explode('&',$extravars) as $expr)
1151
+			foreach (explode('&', $extravars) as $expr)
1155 1152
 			{
1156
-				list($var,$val) = explode('=', $expr,2);
1157
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1158
-				if (substr($var,-2) == '[]')
1153
+				list($var, $val) = explode('=', $expr, 2);
1154
+				if (strpos($val, '%26') != false) $val = str_replace('%26', '&', $val); // make sure to not double encode &
1155
+				if (substr($var, -2) == '[]')
1159 1156
 				{
1160
-					$vars[substr($var,0,-2)][] = $val;
1157
+					$vars[substr($var, 0, -2)][] = $val;
1161 1158
 				}
1162 1159
 				else
1163 1160
 				{
@@ -1170,11 +1167,11 @@  discard block
 block discarded – undo
1170 1167
 		if (count($vars))
1171 1168
 		{
1172 1169
 			$query = array();
1173
-			foreach($vars as $key => $value)
1170
+			foreach ($vars as $key => $value)
1174 1171
 			{
1175 1172
 				if (is_array($value))
1176 1173
 				{
1177
-					foreach($value as $val)
1174
+					foreach ($value as $val)
1178 1175
 					{
1179 1176
 						$query[] = $key.'[]='.urlencode($val);
1180 1177
 					}
@@ -1184,7 +1181,7 @@  discard block
 block discarded – undo
1184 1181
 					$query[] = $key.'='.urlencode($value);
1185 1182
 				}
1186 1183
 			}
1187
-			$ret_url .= '?' . implode('&',$query);
1184
+			$ret_url .= '?'.implode('&', $query);
1188 1185
 		}
1189 1186
 		return $ret_url;
1190 1187
 	}
@@ -1229,7 +1226,7 @@  discard block
 block discarded – undo
1229 1226
 	 * @param int $cookietime =0 when cookie should expire, 0 for session only (optional)
1230 1227
 	 * @param string $cookiepath =null optional path (eg. '/') if the eGW install-dir should not be used
1231 1228
 	 */
1232
-	public static function egw_setcookie($cookiename,$cookievalue='',$cookietime=0,$cookiepath=null)
1229
+	public static function egw_setcookie($cookiename, $cookievalue = '', $cookietime = 0, $cookiepath = null)
1233 1230
 	{
1234 1231
 		if (empty(self::$cookie_domain) || empty(self::$cookie_path))
1235 1232
 		{
@@ -1242,11 +1239,11 @@  discard block
 block discarded – undo
1242 1239
 		static $is_iOS = null;
1243 1240
 		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1244 1241
 
1245
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1242
+		if (!headers_sent())	// gives only a warning, but can not send the cookie anyway
1246 1243
 		{
1247 1244
 			setcookie($cookiename, $cookievalue,
1248
-				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1249
-				is_null($cookiepath) ? self::$cookie_path : $cookiepath,self::$cookie_domain,
1245
+				!$cookietime && $is_iOS ? time() + self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1246
+				is_null($cookiepath) ? self::$cookie_path : $cookiepath, self::$cookie_domain,
1250 1247
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1251 1248
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true);
1252 1249
 		}
@@ -1265,21 +1262,21 @@  discard block
 block discarded – undo
1265 1262
 		else
1266 1263
 		{
1267 1264
 			// Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy
1268
-			self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?  $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
1265
+			self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
1269 1266
 		}
1270 1267
 		// remove port from HTTP_HOST
1271 1268
 		$arr = null;
1272
-		if (preg_match("/^(.*):(.*)$/",self::$cookie_domain,$arr))
1269
+		if (preg_match("/^(.*):(.*)$/", self::$cookie_domain, $arr))
1273 1270
 		{
1274 1271
 			self::$cookie_domain = $arr[1];
1275 1272
 		}
1276
-		if (count(explode('.',self::$cookie_domain)) <= 1)
1273
+		if (count(explode('.', self::$cookie_domain)) <= 1)
1277 1274
 		{
1278 1275
 			// setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in
1279 1276
 			self::$cookie_domain = '';
1280 1277
 		}
1281 1278
 		if (!$GLOBALS['egw_info']['server']['cookiepath'] ||
1282
-			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH)))
1279
+			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH)))
1283 1280
 		{
1284 1281
 			self::$cookie_path = '/';
1285 1282
 		}
@@ -1299,7 +1296,7 @@  discard block
 block discarded – undo
1299 1296
 	 * @param array $domains =null defaults to $GLOBALS['egw_domain'] from the header
1300 1297
 	 * @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use
1301 1298
 	 */
1302
-	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1299
+	public static function search_instance($login, $domain_requested, &$default_domain, $server_names, array $domains = null)
1303 1300
 	{
1304 1301
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1305 1302
 
@@ -1307,10 +1304,10 @@  discard block
 block discarded – undo
1307 1304
 
1308 1305
 		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1309 1306
 		{
1310
-			foreach((array)$server_names as $server_name)
1307
+			foreach ((array)$server_names as $server_name)
1311 1308
 			{
1312
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1313
-				if(isset($domains[$server_name]))
1309
+				list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST
1310
+				if (isset($domains[$server_name]))
1314 1311
 				{
1315 1312
 					$default_domain = $server_name;
1316 1313
 					break;
@@ -1320,7 +1317,7 @@  discard block
 block discarded – undo
1320 1317
 					$parts = explode('.', $server_name);
1321 1318
 					array_shift($parts);
1322 1319
 					$domain_part = implode('.', $parts);
1323
-					if(isset($domains[$domain_part]))
1320
+					if (isset($domains[$domain_part]))
1324 1321
 					{
1325 1322
 						$default_domain = $domain_part;
1326 1323
 						break;
@@ -1336,11 +1333,11 @@  discard block
 block discarded – undo
1336 1333
 		}
1337 1334
 		if (isset($login))	// on login
1338 1335
 		{
1339
-			if (strpos($login,'@') === false || count($domains) == 1)
1336
+			if (strpos($login, '@') === false || count($domains) == 1)
1340 1337
 			{
1341
-				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1338
+				$login .= '@'.(isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1342 1339
 			}
1343
-			$parts = explode('@',$login);
1340
+			$parts = explode('@', $login);
1344 1341
 			$domain = array_pop($parts);
1345 1342
 			$GLOBALS['login'] = $login;
1346 1343
 		}
@@ -1363,7 +1360,7 @@  discard block
 block discarded – undo
1363 1360
 	 * @param boolean $update_access_log =true false: dont update egw_access_log table
1364 1361
 	 * @return string action as written to egw_access_log.session_action
1365 1362
 	 */
1366
-	private function update_dla($update_access_log=true)
1363
+	private function update_dla($update_access_log = true)
1367 1364
 	{
1368 1365
 		// This way XML-RPC users aren't always listed as xmlrpc.php
1369 1366
 		if ($this->xmlrpc_method_called)
@@ -1379,27 +1376,27 @@  discard block
 block discarded – undo
1379 1376
 			$action = $_SERVER['PHP_SELF'];
1380 1377
 			// remove EGroupware path, if not installed in webroot
1381 1378
 			$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1382
-			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1379
+			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path, PHP_URL_PATH);
1383 1380
 			if ($action == '/Microsoft-Server-ActiveSync')
1384 1381
 			{
1385 1382
 				$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
1386 1383
 			}
1387 1384
 			elseif ($egw_path)
1388 1385
 			{
1389
-				list(,$action) = explode($egw_path,$action,2);
1386
+				list(,$action) = explode($egw_path, $action, 2);
1390 1387
 			}
1391 1388
 		}
1392 1389
 
1393 1390
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1394 1391
 		if ($this->sessionid_access_log && $update_access_log)
1395 1392
 		{
1396
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1393
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1397 1394
 				'session_dla' => time(),
1398 1395
 				'session_action' => $action,
1399
-				'lo' => null,	// just in case it was (automatic) timed out before
1400
-			),array(
1396
+				'lo' => null, // just in case it was (automatic) timed out before
1397
+			), array(
1401 1398
 				'sessionid' => $this->sessionid_access_log,
1402
-			),__LINE__,__FILE__);
1399
+			), __LINE__, __FILE__);
1403 1400
 		}
1404 1401
 
1405 1402
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
@@ -1417,12 +1414,12 @@  discard block
 block discarded – undo
1417 1414
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1418 1415
 		if ($this->sessionid_access_log)
1419 1416
 		{
1420
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1417
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1421 1418
 				'notification_heartbeat' => time(),
1422
-			),array(
1419
+			), array(
1423 1420
 				'sessionid' => $this->sessionid_access_log,
1424 1421
 				'lo IS NULL',
1425
-			),__LINE__,__FILE__);
1422
+			), __LINE__, __FILE__);
1426 1423
 		}
1427 1424
 	}
1428 1425
 
@@ -1443,7 +1440,7 @@  discard block
 block discarded – undo
1443 1440
 		{
1444 1441
 			// authentication happens in login.php, which does NOT yet create egw-object in session
1445 1442
 			// --> need to store homedirectory in session
1446
-			if(isset($GLOBALS['auto_create_acct']['homedirectory']))
1443
+			if (isset($GLOBALS['auto_create_acct']['homedirectory']))
1447 1444
 			{
1448 1445
 				Cache::setSession(__CLASS__, 'homedirectory',
1449 1446
 					$user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']);
@@ -1456,7 +1453,7 @@  discard block
 block discarded – undo
1456 1453
 		$user['preferences'] = $GLOBALS['egw']->preferences->read_repository();
1457 1454
 		if (is_object($GLOBALS['egw']->datetime))
1458 1455
 		{
1459
-			$GLOBALS['egw']->datetime->__construct();		// to set tz_offset from the now read prefs
1456
+			$GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs
1460 1457
 		}
1461 1458
 		$user['apps']        = $GLOBALS['egw']->applications->read_repository();
1462 1459
 		$user['domain']      = $this->account_domain;
@@ -1479,9 +1476,9 @@  discard block
 block discarded – undo
1479 1476
 	 * @param string &$account_lid returned account_lid (ie. user)
1480 1477
 	 * @param string &$domain returned domain (ie. domain)
1481 1478
 	 */
1482
-	private function split_login_domain($login,&$account_lid,&$domain)
1479
+	private function split_login_domain($login, &$account_lid, &$domain)
1483 1480
 	{
1484
-		$parts = explode('@',$login);
1481
+		$parts = explode('@', $login);
1485 1482
 
1486 1483
 		//conference - for strings like [email protected]@default ,
1487 1484
 		//allows that user have a login that is his e-mail. (viniciuscb)
@@ -1489,11 +1486,11 @@  discard block
 block discarded – undo
1489 1486
 		{
1490 1487
 			$probable_domain = array_pop($parts);
1491 1488
 			//Last part of login string, when separated by @, is a domain name
1492
-			if (in_array($probable_domain,$this->egw_domains))
1489
+			if (in_array($probable_domain, $this->egw_domains))
1493 1490
 			{
1494 1491
 				$got_login = true;
1495 1492
 				$domain = $probable_domain;
1496
-				$account_lid = implode('@',$parts);
1493
+				$account_lid = implode('@', $parts);
1497 1494
 			}
1498 1495
 		}
1499 1496
 
@@ -1516,9 +1513,9 @@  discard block
 block discarded – undo
1516 1513
 	 * @param boolean $allow_password_md5 =false can password alread be an md5 hash
1517 1514
 	 * @return string
1518 1515
 	 */
1519
-	static function user_pw_hash($user,$password,$allow_password_md5=false)
1516
+	static function user_pw_hash($user, $password, $allow_password_md5 = false)
1520 1517
 	{
1521
-		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/',$password) ? $password : md5($password);
1518
+		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/', $password) ? $password : md5($password);
1522 1519
 
1523 1520
 		$hash = sha1(strtolower($user).$password_md5);
1524 1521
 
@@ -1532,7 +1529,7 @@  discard block
 block discarded – undo
1532 1529
 	{
1533 1530
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace());
1534 1531
 
1535
-		ini_set('session.use_cookies',0);	// disable the automatic use of cookies, as it uses the path / by default
1532
+		ini_set('session.use_cookies', 0); // disable the automatic use of cookies, as it uses the path / by default
1536 1533
 		session_name(self::EGW_SESSION_NAME);
1537 1534
 		if (($sessionid = self::get_sessionid()))
1538 1535
 		{
@@ -1559,7 +1556,7 @@  discard block
 block discarded – undo
1559 1556
 	 * @param int $expire =null expiration time in seconds, default $GLOBALS['egw_info']['flags']['nocachecontrol'] or php.ini session.cache_expire
1560 1557
 	 * @param int $private =null allows to set private caching with given expiration time, by setting it to true
1561 1558
 	 */
1562
-	public static function cache_control($expire=null, $private=null)
1559
+	public static function cache_control($expire = null, $private = null)
1563 1560
 	{
1564 1561
 		if (is_null($expire) && isset($GLOBALS['egw_info']['flags']['nocachecontrol']) && is_int($GLOBALS['egw_info']['flags']['nocachecontrol']))
1565 1562
 		{
@@ -1569,7 +1566,7 @@  discard block
 block discarded – undo
1569 1566
 		if (!isset($_SESSION))
1570 1567
 		{
1571 1568
 			// controling caching and expires header
1572
-			if(!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) ||
1569
+			if (!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) ||
1573 1570
 				!$GLOBALS['egw_info']['flags']['nocachecontrol']))
1574 1571
 			{
1575 1572
 				session_cache_limiter('nocache');
@@ -1579,7 +1576,7 @@  discard block
 block discarded – undo
1579 1576
 				// allow public caching: proxys, cdns, ...
1580 1577
 				if (isset($expire))
1581 1578
 				{
1582
-					session_cache_expire((int)ceil($expire/60));	// in minutes
1579
+					session_cache_expire((int)ceil($expire / 60)); // in minutes
1583 1580
 				}
1584 1581
 				session_cache_limiter($private ? 'private' : 'public');
1585 1582
 			}
@@ -1592,8 +1589,8 @@  discard block
 block discarded – undo
1592 1589
 		// session already started
1593 1590
 		if (isset($_SESSION))
1594 1591
 		{
1595
-			if ($expire && (session_cache_limiter() !== ($expire===true?'private_no_expire':'public') ||
1596
-				is_int($expire) && $expire/60 !== session_cache_expire()))
1592
+			if ($expire && (session_cache_limiter() !== ($expire === true ? 'private_no_expire' : 'public') ||
1593
+				is_int($expire) && $expire / 60 !== session_cache_expire()))
1597 1594
 			{
1598 1595
 				$file = $line = null;
1599 1596
 				if (headers_sent($file, $line))
@@ -1601,20 +1598,20 @@  discard block
 block discarded – undo
1601 1598
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
1602 1599
 					return;
1603 1600
 				}
1604
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1601
+				if ($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1605 1602
 				{
1606
-					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
1603
+					header('Cache-Control: private, max-age='.(60 * session_cache_expire()));
1607 1604
 					header_remove('Expires');
1608 1605
 				}
1609 1606
 				elseif ($private)
1610 1607
 				{
1611 1608
 					header('Cache-Control: private, max-age='.$expire);
1612
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1609
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
1613 1610
 				}
1614 1611
 				else
1615 1612
 				{
1616 1613
 					header('Cache-Control: public, max-age='.$expire);
1617
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1614
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
1618 1615
 				}
1619 1616
 				// remove Pragma header, might be set by old header
1620 1617
 				if (function_exists('header_remove'))	// PHP 5.3+
@@ -1639,10 +1636,10 @@  discard block
 block discarded – undo
1639 1636
 	 * @param array $filter =array() extra filter for sessions
1640 1637
 	 * @return array with sessions (values for keys as in $sort)
1641 1638
 	 */
1642
-	public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False,array $filter=array())
1639
+	public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False, array $filter = array())
1643 1640
 	{
1644 1641
 		$sessions = array();
1645
-		if (!preg_match('/^[a-z0-9_ ,]+$/i',$order_by=$order.' '.$sort) || $order_by == ' ')
1642
+		if (!preg_match('/^[a-z0-9_ ,]+$/i', $order_by = $order.' '.$sort) || $order_by == ' ')
1646 1643
 		{
1647 1644
 			$order_by = 'session_dla DESC';
1648 1645
 		}
@@ -1650,7 +1647,7 @@  discard block
 block discarded – undo
1650 1647
 		$filter[] = 'account_id>0';
1651 1648
 		$filter[] = 'session_dla > '.(int)(time() - $GLOBALS['egw_info']['server']['sessions_timeout']);
1652 1649
 		$filter[] = '(notification_heartbeat IS NULL OR notification_heartbeat > '.self::heartbeat_limit().')';
1653
-		foreach($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
1650
+		foreach ($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
1654 1651
 			$all_no_sort ? false : $start, 'ORDER BY '.$order_by) as $row)
1655 1652
 		{
1656 1653
 			$sessions[$row['sessionid']] = $row;
@@ -1664,7 +1661,7 @@  discard block
 block discarded – undo
1664 1661
 	 * @param array $filter =array() extra filter for sessions
1665 1662
 	 * @return int number of active sessions
1666 1663
 	 */
1667
-	public static function session_count(array $filter=array())
1664
+	public static function session_count(array $filter = array())
1668 1665
 	{
1669 1666
 		$filter['lo'] = null;
1670 1667
 		$filter[] = 'account_id>0';
@@ -1680,16 +1677,16 @@  discard block
 block discarded – undo
1680 1677
 	 */
1681 1678
 	public static function heartbeat_limit()
1682 1679
 	{
1683
-		static $limit=null;
1680
+		static $limit = null;
1684 1681
 
1685 1682
 		if (is_null($limit))
1686 1683
 		{
1687 1684
 			$config = Config::read('notifications');
1688
-			if (!($popup_poll_interval  = $config['popup_poll_interval']))
1685
+			if (!($popup_poll_interval = $config['popup_poll_interval']))
1689 1686
 			{
1690 1687
 				$popup_poll_interval = 60;
1691 1688
 			}
1692
-			$limit = (int)(time() - $popup_poll_interval-10);	// 10s grace periode
1689
+			$limit = (int)(time() - $popup_poll_interval - 10); // 10s grace periode
1693 1690
 		}
1694 1691
 		return $limit;
1695 1692
 	}
Please login to merge, or discard this patch.
Braces   +176 added lines, -45 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
250 250
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
251
-      	{
251
+		{
252 252
       		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
253 253
       	}
254 254
 	}
@@ -282,7 +282,10 @@  discard block
 block discarded – undo
282 282
 	 */
283 283
 	function commit_session()
284 284
 	{
285
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
285
+		if (self::ERROR_LOG_DEBUG)
286
+		{
287
+			error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
288
+		}
286 289
 		self::encrypt($this->kp3);
287 290
 
288 291
 		session_write_close();
@@ -344,7 +347,10 @@  discard block
 block discarded – undo
344 347
 	 */
345 348
 	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
346 349
 	{
347
-		if (!is_array($arr)) return;
350
+		if (!is_array($arr))
351
+		{
352
+			return;
353
+		}
348 354
 
349 355
 		$sizes = array();
350 356
 		foreach($arr as $key => &$data)
@@ -359,7 +365,10 @@  discard block
 block discarded – undo
359 365
 			if ($diff > $limit)
360 366
 			{
361 367
 				error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff));
362
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
368
+				if ($recursion)
369
+				{
370
+					self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
371
+				}
363 372
 			}
364 373
 		}
365 374
 	}
@@ -457,7 +466,10 @@  discard block
 block discarded – undo
457 466
 				$this->passwd      = $passwd;
458 467
 				$this->passwd_type = $passwd_type;
459 468
 			}
460
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
469
+			if (self::ERROR_LOG_DEBUG)
470
+			{
471
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
472
+			}
461 473
 
462 474
 			self::split_login_domain($login,$this->account_lid,$this->account_domain);
463 475
 			// add domain to the login, if not already there
@@ -501,7 +513,10 @@  discard block
 block discarded – undo
501 513
 				{
502 514
 					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
503 515
 				}
504
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
516
+				if (self::ERROR_LOG_DEBUG)
517
+				{
518
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
519
+				}
505 520
 				return false;
506 521
 			}
507 522
 			if ($fail_on_forced_password_change && Auth::check_password_change($this->reason) === false)
@@ -551,7 +566,10 @@  discard block
 block discarded – undo
551 566
 				$this->reason = 'account is expired';
552 567
 				$this->cd_reason = self::CD_ACCOUNT_EXPIRED;
553 568
 
554
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
569
+				if (self::ERROR_LOG_DEBUG)
570
+				{
571
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
572
+				}
555 573
 				return false;
556 574
 			}
557 575
 
@@ -575,25 +593,34 @@  discard block
 block discarded – undo
575 593
 				'passwd'         => $this->passwd,
576 594
 				'account_domain' => $this->account_domain,
577 595
 				'user_ip'        => $user_ip,
578
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
596
+			),'',true)))
597
+			{
598
+				// true = run hooks from all apps, not just the ones the current user has perms to run
579 599
 			{
580 600
 				foreach($hook_result as $reason)
581 601
 				{
582 602
 					if ($reason)	// called hook requests to deny the session
583 603
 					{
584 604
 						$this->reason = $this->cd_reason = $reason;
605
+			}
585 606
 						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
586
-						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
607
+						if (self::ERROR_LOG_DEBUG)
608
+						{
609
+							error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
610
+						}
587 611
 						return false;
588 612
 					}
589 613
 				}
590 614
 			}
591 615
 			$GLOBALS['egw']->db->transaction_begin();
592 616
 			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
593
-			if ($this->session_flags != 'A')		// dont log anonymous sessions
617
+			if ($this->session_flags != 'A')
618
+			{
619
+				// dont log anonymous sessions
594 620
 			{
595 621
 				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
596 622
 			}
623
+			}
597 624
 			Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login);
598 625
 			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
599 626
 			$GLOBALS['egw']->db->transaction_commit();
@@ -609,7 +636,10 @@  discard block
 block discarded – undo
609 636
 				self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
610 637
 				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
611 638
 			}
612
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
639
+			if (self::ERROR_LOG_DEBUG)
640
+			{
641
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
642
+			}
613 643
 
614 644
 			return $this->sessionid;
615 645
 		}
@@ -763,10 +793,13 @@  discard block
 block discarded – undo
763 793
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
764 794
 
765 795
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
766
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
796
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)
797
+		{
798
+			// max. one mail every 5mins
767 799
 		{
768 800
 			try {
769 801
 				$mailer = new Mailer();
802
+		}
770 803
 				// notify admin(s) via email
771 804
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
772 805
 				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
@@ -844,7 +877,10 @@  discard block
 block discarded – undo
844 877
 		{
845 878
 			$sessionid = false;
846 879
 		}
847
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
880
+		if (self::ERROR_LOG_DEBUG)
881
+		{
882
+			error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
883
+		}
848 884
 		return $sessionid;
849 885
 	}
850 886
 
@@ -874,7 +910,10 @@  discard block
 block discarded – undo
874 910
 	 */
875 911
 	function verify($sessionid=null,$kp3=null)
876 912
 	{
877
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
913
+		if (self::ERROR_LOG_DEBUG)
914
+		{
915
+			error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
916
+		}
878 917
 
879 918
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
880 919
 
@@ -890,7 +929,10 @@  discard block
 block discarded – undo
890 929
 
891 930
 		if (!$this->sessionid)
892 931
 		{
893
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
932
+			if (self::ERROR_LOG_DEBUG)
933
+			{
934
+				error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
935
+			}
894 936
 			return false;
895 937
 		}
896 938
 
@@ -902,14 +944,20 @@  discard block
 block discarded – undo
902 944
 		// check if we have a eGroupware session --> return false if not (but dont destroy it!)
903 945
 		if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR]))
904 946
 		{
905
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
947
+			if (self::ERROR_LOG_DEBUG)
948
+			{
949
+				error_log(__METHOD__."('$sessionid') session does NOT exist!");
950
+			}
906 951
 			return false;
907 952
 		}
908 953
 		$session =& $_SESSION[self::EGW_SESSION_VAR];
909 954
 
910 955
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
911 956
 		{
912
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
957
+			if (self::ERROR_LOG_DEBUG)
958
+			{
959
+				error_log(__METHOD__."('$sessionid') session timed out!");
960
+			}
913 961
 			$this->destroy($sessionid,$kp3);
914 962
 			return false;
915 963
 		}
@@ -937,7 +985,10 @@  discard block
 block discarded – undo
937 985
 		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
938 986
 		if (!$this->account_id)
939 987
 		{
940
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
988
+			if (self::ERROR_LOG_DEBUG)
989
+			{
990
+				error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
991
+			}
941 992
 			return false;
942 993
 		}
943 994
 
@@ -955,7 +1006,10 @@  discard block
 block discarded – undo
955 1006
 
956 1007
 		if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
957 1008
 		{
958
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) accounts is expired");
1009
+			if (self::ERROR_LOG_DEBUG)
1010
+			{
1011
+				error_log("*** Session::verify($sessionid) accounts is expired");
1012
+			}
959 1013
 			return false;
960 1014
 		}
961 1015
 		$this->passwd = base64_decode(Cache::getSession('phpgwapi', 'password'));
@@ -966,7 +1020,10 @@  discard block
 block discarded – undo
966 1020
 		}
967 1021
 		if ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
968 1022
 		{
969
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong domain");
1023
+			if (self::ERROR_LOG_DEBUG)
1024
+			{
1025
+				error_log("*** Session::verify($sessionid) wrong domain");
1026
+			}
970 1027
 			return false;
971 1028
 		}
972 1029
 
@@ -975,7 +1032,10 @@  discard block
 block discarded – undo
975 1032
 			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
976 1033
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
977 1034
 			{
978
-				if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP");
1035
+				if (self::ERROR_LOG_DEBUG)
1036
+				{
1037
+					error_log("*** Session::verify($sessionid) wrong IP");
1038
+				}
979 1039
 				return false;
980 1040
 			}
981 1041
 		}
@@ -988,7 +1048,10 @@  discard block
 block discarded – undo
988 1048
 		}
989 1049
 		if (!$this->account_lid)
990 1050
 		{
991
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !account_lid");
1051
+			if (self::ERROR_LOG_DEBUG)
1052
+			{
1053
+				error_log("*** Session::verify($sessionid) !account_lid");
1054
+			}
992 1055
 			return false;
993 1056
 		}
994 1057
 
@@ -1007,13 +1070,19 @@  discard block
 block discarded – undo
1007 1070
 			$_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid &&
1008 1071
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1009 1072
 		{
1010
-			if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1073
+			if (self::ERROR_LOG_DEBUG)
1074
+			{
1075
+				error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1076
+			}
1011 1077
 			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1012 1078
 			self::egw_setcookie('kp3',$this->kp3);
1013 1079
 			self::egw_setcookie('domain',$this->account_domain);
1014 1080
 		}
1015 1081
 
1016
-		if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS");
1082
+		if (self::ERROR_LOG_DEBUG)
1083
+		{
1084
+			error_log("--> Session::verify($sessionid) SUCCESS");
1085
+		}
1017 1086
 
1018 1087
 		return true;
1019 1088
 	}
@@ -1033,14 +1102,20 @@  discard block
 block discarded – undo
1033 1102
 		}
1034 1103
 		$this->log_access($sessionid);	// log logout-time
1035 1104
 
1036
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1105
+		if (self::ERROR_LOG_DEBUG)
1106
+		{
1107
+			error_log(__METHOD__."($sessionid,$kp3)");
1108
+		}
1037 1109
 
1038
-		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1110
+		if (is_numeric($sessionid))
1111
+		{
1112
+			// do we have a access-log-id --> get PHP session id
1039 1113
 		{
1040 1114
 			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1041 1115
 					'sessionid' => $sessionid,
1042 1116
 				),__LINE__,__FILE__)->fetchColumn();
1043 1117
 		}
1118
+		}
1044 1119
 
1045 1120
 		Hooks::process(array(
1046 1121
 			'location'  => 'session_destroyed',
@@ -1050,7 +1125,10 @@  discard block
 block discarded – undo
1050 1125
 		// Only do the following, if where working with the current user
1051 1126
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
1052 1127
 		{
1053
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!");
1128
+			if (self::ERROR_LOG_DEBUG)
1129
+			{
1130
+				error_log(__METHOD__." ********* about to call session_destroy!");
1131
+			}
1054 1132
 			session_unset();
1055 1133
 			@session_destroy();
1056 1134
 			// we need to (re-)load the eGW session-handler, as session_destroy unloads custom session-handlers
@@ -1145,7 +1223,10 @@  discard block
 block discarded – undo
1145 1223
 		}
1146 1224
 		else
1147 1225
 		{
1148
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1226
+			if ($othervars)
1227
+			{
1228
+				$extravars .= ($extravars?'&':'').$othervars;
1229
+			}
1149 1230
 		}
1150 1231
 
1151 1232
 		// parse extravars string into the vars array
@@ -1154,7 +1235,11 @@  discard block
 block discarded – undo
1154 1235
 			foreach(explode('&',$extravars) as $expr)
1155 1236
 			{
1156 1237
 				list($var,$val) = explode('=', $expr,2);
1157
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1238
+				if (strpos($val,'%26') != false)
1239
+				{
1240
+					$val = str_replace('%26','&',$val);
1241
+				}
1242
+				// make sure to not double encode &
1158 1243
 				if (substr($var,-2) == '[]')
1159 1244
 				{
1160 1245
 					$vars[substr($var,0,-2)][] = $val;
@@ -1235,14 +1320,22 @@  discard block
 block discarded – undo
1235 1320
 		{
1236 1321
 			self::set_cookiedomain();
1237 1322
 		}
1238
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1323
+		if (self::ERROR_LOG_DEBUG)
1324
+		{
1325
+			error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1326
+		}
1239 1327
 
1240 1328
 		// if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie),
1241 1329
 		// as every change between apps will cause the cookie to get lost
1242 1330
 		static $is_iOS = null;
1243
-		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1331
+		if (!$cookietime && !isset($is_iOS))
1332
+		{
1333
+			$is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1334
+		}
1244 1335
 
1245
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1336
+		if(!headers_sent())
1337
+		{
1338
+			// gives only a warning, but can not send the cookie anyway
1246 1339
 		{
1247 1340
 			setcookie($cookiename, $cookievalue,
1248 1341
 				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
@@ -1250,6 +1343,7 @@  discard block
 block discarded – undo
1250 1343
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1251 1344
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true);
1252 1345
 		}
1346
+		}
1253 1347
 	}
1254 1348
 
1255 1349
 	/**
@@ -1301,15 +1395,25 @@  discard block
 block discarded – undo
1301 1395
 	 */
1302 1396
 	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1303 1397
 	{
1304
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1398
+		if (self::ERROR_LOG_DEBUG)
1399
+		{
1400
+			error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1401
+		}
1305 1402
 
1306
-		if (is_null($domains)) $domains = $GLOBALS['egw_domain'];
1403
+		if (is_null($domains))
1404
+		{
1405
+			$domains = $GLOBALS['egw_domain'];
1406
+		}
1307 1407
 
1308
-		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1408
+		if (!isset($default_domain) || !isset($domains[$default_domain]))
1409
+		{
1410
+			// allow to overwrite the default domain
1309 1411
 		{
1310 1412
 			foreach((array)$server_names as $server_name)
1311 1413
 			{
1312
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1414
+				list($server_name) = explode(':', $server_name);
1415
+		}
1416
+		// remove port from HTTP_HOST
1313 1417
 				if(isset($domains[$server_name]))
1314 1418
 				{
1315 1419
 					$default_domain = $server_name;
@@ -1334,11 +1438,14 @@  discard block
 block discarded – undo
1334 1438
 				}
1335 1439
 			}
1336 1440
 		}
1337
-		if (isset($login))	// on login
1441
+		if (isset($login))
1442
+		{
1443
+			// on login
1338 1444
 		{
1339 1445
 			if (strpos($login,'@') === false || count($domains) == 1)
1340 1446
 			{
1341 1447
 				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1448
+		}
1342 1449
 			}
1343 1450
 			$parts = explode('@',$login);
1344 1451
 			$domain = array_pop($parts);
@@ -1352,7 +1459,10 @@  discard block
 block discarded – undo
1352 1459
 		{
1353 1460
 			$domain = $default_domain;
1354 1461
 		}
1355
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1462
+		if (self::ERROR_LOG_DEBUG)
1463
+		{
1464
+			error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1465
+		}
1356 1466
 
1357 1467
 		return $domain;
1358 1468
 	}
@@ -1379,7 +1489,10 @@  discard block
 block discarded – undo
1379 1489
 			$action = $_SERVER['PHP_SELF'];
1380 1490
 			// remove EGroupware path, if not installed in webroot
1381 1491
 			$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1382
-			if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1492
+			if ($egw_path[0] != '/')
1493
+			{
1494
+				$egw_path = parse_url($egw_path,PHP_URL_PATH);
1495
+			}
1383 1496
 			if ($action == '/Microsoft-Server-ActiveSync')
1384 1497
 			{
1385 1498
 				$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
@@ -1404,7 +1517,10 @@  discard block
 block discarded – undo
1404 1517
 
1405 1518
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
1406 1519
 		$_SESSION[self::EGW_SESSION_VAR]['session_action'] = $action;
1407
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1520
+		if (self::ERROR_LOG_DEBUG)
1521
+		{
1522
+			error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1523
+		}
1408 1524
 
1409 1525
 		return $action;
1410 1526
 	}
@@ -1530,7 +1646,10 @@  discard block
 block discarded – undo
1530 1646
 	 */
1531 1647
 	public static function init_handler()
1532 1648
 	{
1533
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace());
1649
+		if (self::ERROR_LOG_DEBUG)
1650
+		{
1651
+			error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace());
1652
+		}
1534 1653
 
1535 1654
 		ini_set('session.use_cookies',0);	// disable the automatic use of cookies, as it uses the path / by default
1536 1655
 		session_name(self::EGW_SESSION_NAME);
@@ -1540,10 +1659,16 @@  discard block
 block discarded – undo
1540 1659
 		 	self::cache_control();
1541 1660
 			$ok = session_start();
1542 1661
 			self::decrypt();
1543
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1662
+			if (self::ERROR_LOG_DEBUG)
1663
+			{
1664
+				error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1665
+			}
1544 1666
 			return $ok;
1545 1667
 		}
1546
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!");
1668
+		if (self::ERROR_LOG_DEBUG)
1669
+		{
1670
+			error_log(__METHOD__."() no active session!");
1671
+		}
1547 1672
 
1548 1673
 		return false;
1549 1674
 	}
@@ -1601,9 +1726,12 @@  discard block
 block discarded – undo
1601 1726
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
1602 1727
 					return;
1603 1728
 				}
1604
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1729
+				if($expire === true)
1730
+				{
1731
+					// same behavior as session_cache_limiter('private_no_expire')
1605 1732
 				{
1606 1733
 					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
1734
+				}
1607 1735
 					header_remove('Expires');
1608 1736
 				}
1609 1737
 				elseif ($private)
@@ -1617,10 +1745,13 @@  discard block
 block discarded – undo
1617 1745
 					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1618 1746
 				}
1619 1747
 				// remove Pragma header, might be set by old header
1620
-				if (function_exists('header_remove'))	// PHP 5.3+
1748
+				if (function_exists('header_remove'))
1749
+				{
1750
+					// PHP 5.3+
1621 1751
 				{
1622 1752
 					header_remove('Pragma');
1623 1753
 				}
1754
+				}
1624 1755
 				else
1625 1756
 				{
1626 1757
 					header('Pragma:');
Please login to merge, or discard this patch.
api/src/Storage.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
367 367
 	 *	"LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join!
368 368
 	 * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false
369
-	 * @param mixed $only_keys =false, see search
369
+	 * @param boolean $only_keys =false, see search
370 370
 	 * @param string|array $extra_cols =array()
371 371
 	 * @return int total number of rows
372 372
 	 */
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 	 * Check if cf is stored as 1:N relation in DB and array in memory
735 735
 	 *
736 736
 	 * @param string $name
737
-	 * @return string
737
+	 * @return boolean
738 738
 	 */
739 739
 	function is_multiple($name)
740 740
 	{
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -210,12 +210,12 @@
 block discarded – undo
210 210
 	}
211 211
 
212 212
 	/**
213
-	* saves custom field data
214
-	*
215
-	* @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #)
216
-	* @param array $extra_cols =array() extra-data to be saved
217
-	* @return bool false on success, errornumber on failure
218
-	*/
213
+	 * saves custom field data
214
+	 *
215
+	 * @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #)
216
+	 * @param array $extra_cols =array() extra-data to be saved
217
+	 * @return bool false on success, errornumber on failure
218
+	 */
219 219
 	function save_customfields($data, array $extra_cols=array())
220 220
 	{
221 221
 		foreach (array_keys((array)$this->customfields) as $name)
Please login to merge, or discard this patch.
Spacing   +100 added lines, -102 removed lines patch added patch discarded remove patch
@@ -118,41 +118,41 @@  discard block
 block discarded – undo
118 118
 	 * @param boolean $allow_multiple_values =false should we allow AND store multiple values (1:N relations)
119 119
 	 * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use DateTime objects
120 120
 	 */
121
-	function __construct($app,$table,$extra_table,$column_prefix='',
122
-		$extra_key='_name',$extra_value='_value',$extra_id='_id',
123
-		Db $db=null,$no_clone=true,$allow_multiple_values=false,$timestamp_type=null)
121
+	function __construct($app, $table, $extra_table, $column_prefix = '',
122
+		$extra_key = '_name', $extra_value = '_value', $extra_id = '_id',
123
+		Db $db = null, $no_clone = true, $allow_multiple_values = false, $timestamp_type = null)
124 124
 	{
125 125
 		// calling the Storage\Base constructor
126
-		parent::__construct($app,$table,$db,$column_prefix,$no_clone,$timestamp_type);
126
+		parent::__construct($app, $table, $db, $column_prefix, $no_clone, $timestamp_type);
127 127
 
128 128
 		$this->allow_multiple_values = $allow_multiple_values;
129 129
 		$this->extra_table = $extra_table;
130
-		if (!$this->extra_id) $this->extra_id = $this->autoinc_id;	// default to auto id of regular table
130
+		if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table
131 131
 
132 132
 		// if names from columns of extra table are only postfixes (starting with _), prepend column prefix
133
-		if (!($prefix=$column_prefix))
133
+		if (!($prefix = $column_prefix))
134 134
 		{
135
-			list($prefix) = explode('_',$this->autoinc_id);
135
+			list($prefix) = explode('_', $this->autoinc_id);
136 136
 		}
137
-		elseif(substr($prefix,-1) == '_')
137
+		elseif (substr($prefix, -1) == '_')
138 138
 		{
139
-			$prefix = substr($prefix,0,-1);	// remove trailing underscore from column prefix parameter
139
+			$prefix = substr($prefix, 0, -1); // remove trailing underscore from column prefix parameter
140 140
 		}
141
-		foreach(array(
141
+		foreach (array(
142 142
 			'extra_id' => $extra_id,
143 143
 			'extra_key' => $extra_key,
144 144
 			'extra_value' => $extra_value
145 145
 		) as $col => $val)
146 146
 		{
147 147
 			$this->$col = $col_name = $val;
148
-			if ($col_name[0] == '_') $this->$col = $prefix . $val;
148
+			if ($col_name[0] == '_') $this->$col = $prefix.$val;
149 149
 		}
150 150
 		// some sanity checks, maybe they should be active only for development
151
-		if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table)))
151
+		if (!($extra_defs = $this->db->get_table_definitions($app, $extra_table)))
152 152
 		{
153 153
 			throw new Exception\WrongParameter("extra table $extra_table is NOT defined!");
154 154
 		}
155
-		foreach(array('extra_id','extra_key','extra_value') as $col)
155
+		foreach (array('extra_id', 'extra_key', 'extra_value') as $col)
156 156
 		{
157 157
 			if (!$this->$col || !isset($extra_defs['fd'][$this->$col]))
158 158
 			{
@@ -177,23 +177,23 @@  discard block
 block discarded – undo
177 177
 	 * @param array $field_names =null custom fields to read, default all
178 178
 	 * @return array id => $this->cf_field(name) => value
179 179
 	 */
180
-	function read_customfields($ids,$field_names=null)
180
+	function read_customfields($ids, $field_names = null)
181 181
 	{
182 182
 		if (is_null($field_names)) $field_names = array_keys($this->customfields);
183 183
 
184
-		foreach((array)$ids as $key => $id)
184
+		foreach ((array)$ids as $key => $id)
185 185
 		{
186 186
 			if (!(int)$id && is_array($ids)) unset($ids[$key]);
187 187
 		}
188
-		if (!$ids || !$field_names) return array();	// nothing to do
188
+		if (!$ids || !$field_names) return array(); // nothing to do
189 189
 
190 190
 		$entries = array();
191
-		foreach($this->db->select($this->extra_table,'*',array(
191
+		foreach ($this->db->select($this->extra_table, '*', array(
192 192
 			$this->extra_id => $ids,
193 193
 			$this->extra_key => $field_names,
194
-		),__LINE__,__FILE__,false,'',$this->app) as $row)
194
+		), __LINE__, __FILE__, false, '', $this->app) as $row)
195 195
 		{
196
-			$entry =& $entries[$row[$this->extra_id]];
196
+			$entry = & $entries[$row[$this->extra_id]];
197 197
 			if (!is_array($entry)) $entry = array();
198 198
 			$field = $this->get_cf_field($row[$this->extra_key]);
199 199
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	* @param array $extra_cols =array() extra-data to be saved
217 217
 	* @return bool false on success, errornumber on failure
218 218
 	*/
219
-	function save_customfields($data, array $extra_cols=array())
219
+	function save_customfields($data, array $extra_cols = array())
220 220
 	{
221 221
 		foreach (array_keys((array)$this->customfields) as $name)
222 222
 		{
@@ -229,22 +229,21 @@  discard block
 block discarded – undo
229 229
 			$is_multiple = $this->is_multiple($name);
230 230
 
231 231
 			// we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index
232
-			if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
232
+			if (empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
233 233
 			{
234
-				$this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app);
235
-				if (empty($data[$field])) continue;	// nothing else to do for empty values
234
+				$this->db->delete($this->extra_table, $where, __LINE__, __FILE__, $this->app);
235
+				if (empty($data[$field])) continue; // nothing else to do for empty values
236 236
 			}
237
-			foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) :
238
-				// regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
237
+			foreach ($is_multiple && !is_array($data[$field]) ? explode(',', $data[$field]) : // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
239 238
 				(array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value)
240 239
 			{
241
-				if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app))
240
+				if (!$this->db->insert($this->extra_table, array($this->extra_value => $value) + $extra_cols, $where, __LINE__, __FILE__, $this->app))
242 241
 				{
243 242
 					return $this->db->Errno;
244 243
 				}
245 244
 			}
246 245
 		}
247
-		return false;	// no error
246
+		return false; // no error
248 247
 	}
249 248
 
250 249
 	/**
@@ -260,7 +259,7 @@  discard block
 block discarded – undo
260 259
 
261 260
 		if ($this->customfields)
262 261
 		{
263
-			foreach(array_keys($this->customfields) as $name)
262
+			foreach (array_keys($this->customfields) as $name)
264 263
 			{
265 264
 				if (isset($new[$field = $this->get_cf_field($name)]))
266 265
 				{
@@ -280,16 +279,16 @@  discard block
 block discarded – undo
280 279
 	 * @param string $join sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
281 280
 	 * @return array|boolean data if row could be retrived else False
282 281
 	 */
283
-	function read($keys,$extra_cols='',$join='')
282
+	function read($keys, $extra_cols = '', $join = '')
284 283
 	{
285
-		if (!parent::read($keys,$extra_cols,$join))
284
+		if (!parent::read($keys, $extra_cols, $join))
286 285
 		{
287 286
 			return false;
288 287
 		}
289 288
 		if (($id = (int)$this->data[$this->db_key_cols[$this->autoinc_id]]) && $this->customfields &&
290 289
 			($cfs = $this->read_customfields($id)))
291 290
 		{
292
-			$this->data = array_merge($this->data,$cfs[$id]);
291
+			$this->data = array_merge($this->data, $cfs[$id]);
293 292
 		}
294 293
 		return $this->data;
295 294
 	}
@@ -303,14 +302,14 @@  discard block
 block discarded – undo
303 302
 	 * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows!
304 303
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
305 304
 	 */
306
-	function save($keys=null,$extra_where=null)
305
+	function save($keys = null, $extra_where = null)
307 306
 	{
308 307
 		if (is_array($keys) && count($keys) && !isset($keys[0]))	// allow to use an etag, eg array('etag=etag+1')
309 308
 		{
310 309
 			$this->data_merge($keys);
311 310
 			$keys = null;
312 311
 		}
313
-		$ret = parent::save($keys,$extra_where);
312
+		$ret = parent::save($keys, $extra_where);
314 313
 
315 314
 		if ($ret == 0 && $this->customfields)
316 315
 		{
@@ -328,26 +327,26 @@  discard block
 block discarded – undo
328 327
 	 * @param boolean $only_return_ids =false return $ids of delete call to db object, but not run it (can be used by extending classes!)
329 328
 	 * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids
330 329
 	 */
331
-	function delete($keys=null,$only_return_ids=false)
330
+	function delete($keys = null, $only_return_ids = false)
332 331
 	{
333 332
 		if ($this->customfields || $only_return_ids)
334 333
 		{
335
-			$query = parent::delete($keys,true);
334
+			$query = parent::delete($keys, true);
336 335
 			// check if query contains more then the id's
337 336
 			if (!isset($query[$this->autoinc_id]) || count($query) != 1)
338 337
 			{
339
-				foreach($this->db->select($this->table_name,$this->autoinc_id,$query,__LINE__,__FILE__,false,'',$this->app) as $row)
338
+				foreach ($this->db->select($this->table_name, $this->autoinc_id, $query, __LINE__, __FILE__, false, '', $this->app) as $row)
340 339
 				{
341 340
 					$ids[] = $row[$this->autoinc_id];
342 341
 				}
343
-				if (!$ids) return 0;	// no rows affected
342
+				if (!$ids) return 0; // no rows affected
344 343
 			}
345 344
 			else
346 345
 			{
347 346
 				$ids = (array)$query[$this->autoinc_id];
348 347
 			}
349 348
 			if ($only_return_ids) return $ids;
350
-			$this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__);
349
+			$this->db->delete($this->extra_table, array($this->extra_id => $ids), __LINE__, __FILE__);
351 350
 		}
352 351
 		return parent::delete($keys);
353 352
 	}
@@ -370,32 +369,32 @@  discard block
 block discarded – undo
370 369
 	 * @param string|array $extra_cols =array()
371 370
 	 * @return int total number of rows
372 371
 	 */
373
-	function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array())
372
+	function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array())
374 373
 	{
375
-		parent::get_rows($query,$rows,$readonlys,$join,$need_full_no_count,$only_keys,$extra_cols);
374
+		parent::get_rows($query, $rows, $readonlys, $join, $need_full_no_count, $only_keys, $extra_cols);
376 375
 
377
-		$selectcols = $query['selectcols'] ? explode(',',$query['selectcols']) : array();
376
+		$selectcols = $query['selectcols'] ? explode(',', $query['selectcols']) : array();
378 377
 
379
-		if ($rows && $this->customfields && (!$selectcols || in_array('customfields',$selectcols)))
378
+		if ($rows && $this->customfields && (!$selectcols || in_array('customfields', $selectcols)))
380 379
 		{
381 380
 			$id2keys = array();
382
-			foreach($rows as $key => $row)
381
+			foreach ($rows as $key => $row)
383 382
 			{
384 383
 				$id2keys[$row[$this->db_key_cols[$this->autoinc_id]]] = $key;
385 384
 			}
386 385
 			// check if only certain cf's to show
387 386
 			if (!in_array('customfields', $selectcols))
388 387
 			{
389
-				foreach($selectcols as $col)
388
+				foreach ($selectcols as $col)
390 389
 				{
391 390
 					if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col);
392 391
 				}
393 392
 			}
394
-			if (($cfs = $this->read_customfields(array_keys($id2keys),$fields)))
393
+			if (($cfs = $this->read_customfields(array_keys($id2keys), $fields)))
395 394
 			{
396
-				foreach($cfs as $id => $data)
395
+				foreach ($cfs as $id => $data)
397 396
 				{
398
-					$rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]],$data);
397
+					$rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]], $data);
399 398
 				}
400 399
 			}
401 400
 		}
@@ -422,12 +421,12 @@  discard block
 block discarded – undo
422 421
 	 * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false
423 422
 	 * @return array|NULL array of matching rows (the row is an array of the cols) or NULL
424 423
 	 */
425
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
424
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false)
426 425
 	{
427 426
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
428 427
 		if (!$this->customfields)
429 428
 		{
430
-			return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
429
+			return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
431 430
 		}
432 431
 		if ($only_keys === false)
433 432
 		{
@@ -436,7 +435,7 @@  discard block
 block discarded – undo
436 435
 		// if string given as criteria --> search in all (or $this->columns_to_search) columns including custom fields
437 436
 		if ($criteria && is_string($criteria))
438 437
 		{
439
-			$criteria = $this->search2criteria($criteria,$wildcard,$op);
438
+			$criteria = $this->search2criteria($criteria, $wildcard, $op);
440 439
 		}
441 440
 		if ($criteria && is_array($criteria))
442 441
 		{
@@ -445,10 +444,10 @@  discard block
 block discarded – undo
445 444
 			{
446 445
 				if (($negate = $criteria[$this->extra_value][0] === '!'))
447 446
 				{
448
-					$criteria[$this->extra_value] = substr($criteria[$this->extra_value],1);
447
+					$criteria[$this->extra_value] = substr($criteria[$this->extra_value], 1);
449 448
 				}
450
-				$criteria[] = $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : '').
451
-					$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' .
449
+				$criteria[] = $this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : '').
450
+					$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.
452 451
 					$this->db->quote($wildcard.$criteria[$this->extra_value].$wildcard);
453 452
 				unset($criteria[$this->extra_value]);
454 453
 			}
@@ -457,14 +456,14 @@  discard block
 block discarded – undo
457 456
 			{
458 457
 				if ($criteria[$this->autoinc_id])
459 458
 				{
460
-					$criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',
459
+					$criteria[] = $this->db->expression($this->table_name, $this->table_name.'.',
461 460
 						array($this->autoinc_id => $criteria[$this->autoinc_id]));
462 461
 				}
463 462
 				unset($criteria[$this->autoinc_id]);
464 463
 			}
465 464
 			// replace ambiguous column with (an exact match of) table_name.column
466 465
 			$extra_join_added = $join && strpos($join, $this->extra_join) !== false;
467
-			foreach($criteria as $name => $val)
466
+			foreach ($criteria as $name => $val)
468 467
 			{
469 468
 				// only add extra_join, if we really need it
470 469
 				if (!$extra_join_added && (
@@ -476,9 +475,9 @@  discard block
 block discarded – undo
476 475
 					$extra_join_added = true;
477 476
 				}
478 477
 				$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
479
-				if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)])
478
+				if (is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)])
480 479
 				{
481
-					$criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
480
+					$criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
482 481
 						array_search($name, $this->db_cols) => $val,
483 482
 					));
484 483
 					unset($criteria[$name]);
@@ -490,12 +489,12 @@  discard block
 block discarded – undo
490 489
 						$name = substr($name, 1);
491 490
 						if (($negate = $criteria[$name][0] === '!'))
492 491
 						{
493
-							$val = substr($val,1);
492
+							$val = substr($val, 1);
494 493
 						}
495
-						$cfcriteria[] = '(' . $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : '').
496
-							$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' .
497
-							$this->db->quote($wildcard.$val.$wildcard) . ' AND ' .
498
-							$this->extra_table.'.'.$this->extra_key . ' = ' . $this->db->quote($name) .
494
+						$cfcriteria[] = '('.$this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : '').
495
+							$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.
496
+							$this->db->quote($wildcard.$val.$wildcard).' AND '.
497
+							$this->extra_table.'.'.$this->extra_key.' = '.$this->db->quote($name).
499 498
 							')';
500 499
 						unset($criteria[self::CF_PREFIX.$name]);
501 500
 					}
@@ -507,38 +506,38 @@  discard block
 block discarded – undo
507 506
 					}
508 507
 				}
509 508
 			}
510
-			if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria);
509
+			if ($cfcriteria && $op == 'OR') $criteria[] = implode(' OR ', $cfcriteria);
511 510
 		}
512
-		if($only_keys === true)
511
+		if ($only_keys === true)
513 512
 		{
514 513
 			// Expand to keys here, so table_name can be prepended below
515 514
 			$only_keys = array_values($this->db_key_cols);
516 515
 		}
517 516
 		// replace ambiguous column with (an exact match of) table_name.column
518
-		if(is_array($only_keys))
517
+		if (is_array($only_keys))
519 518
 		{
520
-			foreach($only_keys as $key => &$col)
519
+			foreach ($only_keys as $key => &$col)
521 520
 			{
522
-				if(is_numeric($key) && in_array($col, $this->db_cols, true))
521
+				if (is_numeric($key) && in_array($col, $this->db_cols, true))
523 522
 				{
524
-					$col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col;
523
+					$col = $this->table_name.'.'.array_search($col, $this->db_cols).' AS '.$col;
525 524
 				}
526 525
 			}
527 526
 		}
528 527
 		// check if we order by a custom field --> join cf table for given cf and order by it's value
529
-		if (strpos($order_by,self::CF_PREFIX) !== false)
528
+		if (strpos($order_by, self::CF_PREFIX) !== false)
530 529
 		{
531 530
 			// fields to order by, as cutomfields may have names with spaces, we examine each order by criteria
532
-			$fields2order = explode(',',$order_by);
533
-			foreach($fields2order as $v)
531
+			$fields2order = explode(',', $order_by);
532
+			foreach ($fields2order as $v)
534 533
 			{
535
-				if (strpos($v,self::CF_PREFIX) !== false)
534
+				if (strpos($v, self::CF_PREFIX) !== false)
536 535
 				{
537 536
 					// we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname
538
-					$buff = explode(' ',trim($v));
537
+					$buff = explode(' ', trim($v));
539 538
 					$orderDir = array_pop($buff);
540
-					$key = substr(trim(implode(' ',$buff)), 1);
541
-					switch($this->customfields[$key]['type'])
539
+					$key = substr(trim(implode(' ', $buff)), 1);
540
+					switch ($this->customfields[$key]['type'])
542 541
 					{
543 542
 						case 'int':
544 543
 							$order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'.
@@ -571,26 +570,26 @@  discard block
 block discarded – undo
571 570
 		{
572 571
 			$_cfnames = array_keys($this->customfields);
573 572
 			$extra_filter = null;
574
-			foreach($filter as $name => $val)
573
+			foreach ($filter as $name => $val)
575 574
 			{
576 575
 				// replace ambiguous auto-id with (an exact match of) table_name.autoid
577 576
 				if (is_string($name) && $name == $this->autoinc_id)
578 577
 				{
579 578
 					if ((int)$filter[$this->autoinc_id])
580 579
 					{
581
-						$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
580
+						$filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
582 581
 							$this->autoinc_id => $filter[$this->autoinc_id],
583 582
 						));
584 583
 					}
585 584
 					unset($filter[$this->autoinc_id]);
586 585
 				}
587 586
 				// replace ambiguous column with (an exact match of) table_name.column
588
-				elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols))
587
+				elseif (is_string($name) && $val != null && in_array($name, $this->db_cols))
589 588
 				{
590 589
 					$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
591 590
 					if ($extra_columns['fd'][array_search($name, $this->db_cols)])
592 591
 					{
593
-						$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
592
+						$filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
594 593
 							array_search($name, $this->db_cols) => $val,
595 594
 						));
596 595
 						unset($filter[$name]);
@@ -602,61 +601,61 @@  discard block
 block discarded – undo
602 601
 					{
603 602
 						if ($val[0] === '!')	// negative filter
604 603
 						{
605
-							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1));
604
+							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val, 1));
606 605
 						}
607 606
 						else	// using Db::expression to allow to use array() with possible values or NULL
608 607
 						{
609
-							if($this->customfields[$this->get_cf_name($name)]['type'] == 'select' &&
608
+							if ($this->customfields[$this->get_cf_name($name)]['type'] == 'select' &&
610 609
 								$this->customfields[$this->get_cf_name($name)]['rows'] > 1)
611 610
 							{
612 611
 								// Multi-select - any entry with the filter value selected matches
613
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.
614
-									$this->extra_value,$this->db->expression($this->extra_table,array(
615
-										$this->db->concat("','",$this->extra_value,"','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%')
612
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.
613
+									$this->extra_value, $this->db->expression($this->extra_table, array(
614
+										$this->db->concat("','", $this->extra_value, "','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%')
616 615
 									))
617 616
 								);
618 617
 							}
619 618
 							elseif ($this->customfields[$this->get_cf_name($name)]['type'] == 'text')
620 619
 							{
621
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.$this->extra_value,
622
-										$this->db->expression($this->extra_table,array(
620
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.$this->extra_value,
621
+										$this->db->expression($this->extra_table, array(
623 622
 										$this->extra_value.' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($wildcard.$val.$wildcard)
624 623
 									))
625 624
 								);
626 625
 							}
627 626
 							else
628 627
 							{
629
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.
630
-									$this->extra_value,$this->db->expression($this->extra_table,array($this->extra_value => $val)));
628
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.
629
+									$this->extra_value, $this->db->expression($this->extra_table, array($this->extra_value => $val)));
631 630
 							}
632 631
 						}
633 632
 						// need to use a LEFT JOIN for negative search or to allow NULL values
634
-						$need_left_join = $val[0] === '!' || strpos($sql_filter,'IS NULL') !== false ? ' LEFT ' : '';
635
-						$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$need_left_join.$this->extra_join_filter.
633
+						$need_left_join = $val[0] === '!' || strpos($sql_filter, 'IS NULL') !== false ? ' LEFT ' : '';
634
+						$join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $need_left_join.$this->extra_join_filter.
636 635
 							' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($name)).
637 636
 							' AND '.$sql_filter);
638 637
 						++$extra_filter;
639 638
 					}
640 639
 					unset($filter[$name]);
641 640
 				}
642
-				elseif(is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
641
+				elseif (is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
643 642
 				{
644
-					$_cf = explode(' ',$val);
645
-					foreach($_cf as $cf_np)
643
+					$_cf = explode(' ', $val);
644
+					foreach ($_cf as $cf_np)
646 645
 					{
647 646
 						// building cf_name by glueing parts together (, in case someone used whitespace in their custom field names)
648
-						$tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np;
647
+						$tcf_name = ($tcf_name ? $tcf_name.' ' : '').$cf_np;
649 648
 						// reacts on the first one found that matches an existing customfield, should be better then the old behavior of
650 649
 						// simply splitting by " " and using the first part
651
-						if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false )
650
+						if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn, (array)$_cfnames, true) !== false)
652 651
 						{
653 652
 							$cf = $tcf_name;
654 653
 							break;
655 654
 						}
656 655
 					}
657
-					$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter.
656
+					$join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $this->extra_join_filter.
658 657
 						' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($cf)).
659
-						' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val));
658
+						' AND '.str_replace($cf, 'extra_filter.'.$this->extra_value, $val));
660 659
 					++$extra_filter;
661 660
 					unset($filter[$name]);
662 661
 				}
@@ -668,15 +667,14 @@  discard block
 block discarded – undo
668 667
 			if (is_array($only_keys))
669 668
 			{
670 669
 				$only_keys = array_values($only_keys);
671
-				$only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] :
672
-					$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id);
670
+				$only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id);
673 671
 			}
674 672
 			else
675 673
 			{
676 674
 				$only_keys = 'DISTINCT '.$only_keys;
677 675
 			}
678 676
 		}
679
-		return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
677
+		return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
680 678
 	}
681 679
 
682 680
 	/**
@@ -716,7 +714,7 @@  discard block
 block discarded – undo
716 714
 	 */
717 715
 	function get_cf_name($field)
718 716
 	{
719
-		return substr($field,1);
717
+		return substr($field, 1);
720 718
 	}
721 719
 
722 720
 	/**
@@ -738,7 +736,7 @@  discard block
 block discarded – undo
738 736
 	 */
739 737
 	function is_multiple($name)
740 738
 	{
741
-		return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) &&
739
+		return $this->allow_multiple_values && in_array($this->customfields[$name]['type'], array('select', 'select-account')) &&
742 740
 			$this->customfields[$name]['rows'] > 1;
743 741
 	}
744 742
 }
Please login to merge, or discard this patch.
Braces   +64 added lines, -15 removed lines patch added patch discarded remove patch
@@ -127,7 +127,11 @@  discard block
 block discarded – undo
127 127
 
128 128
 		$this->allow_multiple_values = $allow_multiple_values;
129 129
 		$this->extra_table = $extra_table;
130
-		if (!$this->extra_id) $this->extra_id = $this->autoinc_id;	// default to auto id of regular table
130
+		if (!$this->extra_id)
131
+		{
132
+			$this->extra_id = $this->autoinc_id;
133
+		}
134
+		// default to auto id of regular table
131 135
 
132 136
 		// if names from columns of extra table are only postfixes (starting with _), prepend column prefix
133 137
 		if (!($prefix=$column_prefix))
@@ -145,7 +149,10 @@  discard block
 block discarded – undo
145 149
 		) as $col => $val)
146 150
 		{
147 151
 			$this->$col = $col_name = $val;
148
-			if ($col_name[0] == '_') $this->$col = $prefix . $val;
152
+			if ($col_name[0] == '_')
153
+			{
154
+				$this->$col = $prefix . $val;
155
+			}
149 156
 		}
150 157
 		// some sanity checks, maybe they should be active only for development
151 158
 		if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table)))
@@ -179,13 +186,23 @@  discard block
 block discarded – undo
179 186
 	 */
180 187
 	function read_customfields($ids,$field_names=null)
181 188
 	{
182
-		if (is_null($field_names)) $field_names = array_keys($this->customfields);
189
+		if (is_null($field_names))
190
+		{
191
+			$field_names = array_keys($this->customfields);
192
+		}
183 193
 
184 194
 		foreach((array)$ids as $key => $id)
185 195
 		{
186
-			if (!(int)$id && is_array($ids)) unset($ids[$key]);
196
+			if (!(int)$id && is_array($ids))
197
+			{
198
+				unset($ids[$key]);
199
+			}
187 200
 		}
188
-		if (!$ids || !$field_names) return array();	// nothing to do
201
+		if (!$ids || !$field_names)
202
+		{
203
+			return array();
204
+		}
205
+		// nothing to do
189 206
 
190 207
 		$entries = array();
191 208
 		foreach($this->db->select($this->extra_table,'*',array(
@@ -194,7 +211,10 @@  discard block
 block discarded – undo
194 211
 		),__LINE__,__FILE__,false,'',$this->app) as $row)
195 212
 		{
196 213
 			$entry =& $entries[$row[$this->extra_id]];
197
-			if (!is_array($entry)) $entry = array();
214
+			if (!is_array($entry))
215
+			{
216
+				$entry = array();
217
+			}
198 218
 			$field = $this->get_cf_field($row[$this->extra_key]);
199 219
 
200 220
 			if ($this->allow_multiple_values && $this->is_multiple($row[$this->extra_key]))
@@ -220,7 +240,10 @@  discard block
 block discarded – undo
220 240
 	{
221 241
 		foreach (array_keys((array)$this->customfields) as $name)
222 242
 		{
223
-			if (!isset($data[$field = $this->get_cf_field($name)])) continue;
243
+			if (!isset($data[$field = $this->get_cf_field($name)]))
244
+			{
245
+				continue;
246
+			}
224 247
 
225 248
 			$where = array(
226 249
 				$this->extra_id    => isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]],
@@ -232,7 +255,11 @@  discard block
 block discarded – undo
232 255
 			if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
233 256
 			{
234 257
 				$this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app);
235
-				if (empty($data[$field])) continue;	// nothing else to do for empty values
258
+				if (empty($data[$field]))
259
+				{
260
+					continue;
261
+				}
262
+				// nothing else to do for empty values
236 263
 			}
237 264
 			foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) :
238 265
 				// regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
@@ -305,9 +332,12 @@  discard block
 block discarded – undo
305 332
 	 */
306 333
 	function save($keys=null,$extra_where=null)
307 334
 	{
308
-		if (is_array($keys) && count($keys) && !isset($keys[0]))	// allow to use an etag, eg array('etag=etag+1')
335
+		if (is_array($keys) && count($keys) && !isset($keys[0]))
336
+		{
337
+			// allow to use an etag, eg array('etag=etag+1')
309 338
 		{
310 339
 			$this->data_merge($keys);
340
+		}
311 341
 			$keys = null;
312 342
 		}
313 343
 		$ret = parent::save($keys,$extra_where);
@@ -340,13 +370,20 @@  discard block
 block discarded – undo
340 370
 				{
341 371
 					$ids[] = $row[$this->autoinc_id];
342 372
 				}
343
-				if (!$ids) return 0;	// no rows affected
373
+				if (!$ids)
374
+				{
375
+					return 0;
376
+				}
377
+				// no rows affected
344 378
 			}
345 379
 			else
346 380
 			{
347 381
 				$ids = (array)$query[$this->autoinc_id];
348 382
 			}
349
-			if ($only_return_ids) return $ids;
383
+			if ($only_return_ids)
384
+			{
385
+				return $ids;
386
+			}
350 387
 			$this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__);
351 388
 		}
352 389
 		return parent::delete($keys);
@@ -388,7 +425,10 @@  discard block
 block discarded – undo
388 425
 			{
389 426
 				foreach($selectcols as $col)
390 427
 				{
391
-					if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col);
428
+					if ($this->is_cf($col))
429
+					{
430
+						$fields[] = $this->get_cf_name($col);
431
+					}
392 432
 				}
393 433
 			}
394 434
 			if (($cfs = $this->read_customfields(array_keys($id2keys),$fields)))
@@ -507,7 +547,10 @@  discard block
 block discarded – undo
507 547
 					}
508 548
 				}
509 549
 			}
510
-			if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria);
550
+			if ($cfcriteria && $op =='OR')
551
+			{
552
+				$criteria[] = implode(' OR ',$cfcriteria);
553
+			}
511 554
 		}
512 555
 		if($only_keys === true)
513 556
 		{
@@ -598,11 +641,14 @@  discard block
 block discarded – undo
598 641
 				}
599 642
 				elseif (is_string($name) && $this->is_cf($name))
600 643
 				{
601
-					if (!empty($val))	// empty -> dont filter
644
+					if (!empty($val))
645
+					{
646
+						// empty -> dont filter
602 647
 					{
603 648
 						if ($val[0] === '!')	// negative filter
604 649
 						{
605 650
 							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1));
651
+					}
606 652
 						}
607 653
 						else	// using Db::expression to allow to use array() with possible values or NULL
608 654
 						{
@@ -639,9 +685,12 @@  discard block
 block discarded – undo
639 685
 					}
640 686
 					unset($filter[$name]);
641 687
 				}
642
-				elseif(is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
688
+				elseif(is_int($name) && $this->is_cf($val))
689
+				{
690
+					// lettersearch: #cfname LIKE 's%'
643 691
 				{
644 692
 					$_cf = explode(' ',$val);
693
+				}
645 694
 					foreach($_cf as $cf_np)
646 695
 					{
647 696
 						// building cf_name by glueing parts together (, in case someone used whitespace in their custom field names)
Please login to merge, or discard this patch.
api/src/Storage/Base.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 	 *
705 705
 	 * @param array $_fields
706 706
 	 * @param boolean $merge =true if true $fields will be merged with $this->data (after update!), otherwise $this->data will be just $fields
707
-	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
707
+	 * @return integer 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
708 708
 	 */
709 709
 	function update($_fields,$merge=true)
710 710
 	{
@@ -1194,7 +1194,7 @@  discard block
 block discarded – undo
1194 1194
 	 * @param string &$wildcard ='' on return wildcard char to use, if pattern does not already contain wildcards!
1195 1195
 	 * @param string &$op ='AND' on return boolean operation to use, if pattern does not start with ! we use OR else AND
1196 1196
 	 * @param string $extra_col =null extra column to search
1197
-	 * @param array $search_cols =array() List of columns to search.  If not provided, all columns in $this->db_cols will be considered
1197
+	 * @param string[] $search_cols =array() List of columns to search.  If not provided, all columns in $this->db_cols will be considered
1198 1198
 	 * @return array or column => value pairs
1199 1199
 	 */
1200 1200
 	public function search2criteria($_pattern,&$wildcard='',&$op='AND',$extra_col=null, $search_cols = array())
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1367,14 +1367,14 @@
 block discarded – undo
1367 1367
 	}
1368 1368
 
1369 1369
 	/**
1370
-	* Get a default list of columns to search
1371
-	* This is to be used as a fallback, for when the extending class does not define
1372
-	* $this->columns_to_search.  All the columns are considered, and any with $skip_columns_with in
1373
-	* their name are discarded because these columns are expected to be foreign keys or other numeric
1374
-	* values with no meaning to the user.
1375
-	*
1376
-	* @return array of column names
1377
-	*/
1370
+	 * Get a default list of columns to search
1371
+	 * This is to be used as a fallback, for when the extending class does not define
1372
+	 * $this->columns_to_search.  All the columns are considered, and any with $skip_columns_with in
1373
+	 * their name are discarded because these columns are expected to be foreign keys or other numeric
1374
+	 * values with no meaning to the user.
1375
+	 *
1376
+	 * @return array of column names
1377
+	 */
1378 1378
 	protected function get_default_search_columns()
1379 1379
 	{
1380 1380
 		$skip_columns_with = array('_id', 'modified', 'modifier', 'status', 'cat_id', 'owner');
Please login to merge, or discard this patch.
Spacing   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps,
180 180
 	 * 	'object' use Api\DateTime objects or 'string' use DB timestamp (Y-m-d H:i:s) string
181 181
 	 */
182
-	function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false,$timestamp_type=null)
182
+	function __construct($app = '', $table = '', Api\Db $db = null, $column_prefix = '', $no_clone = false, $timestamp_type = null)
183 183
 	{
184 184
 		// ease the transition to api
185 185
 		if ($app == 'phpgwapi') $app = 'api';
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 
201 201
 			if (!$no_clone) $this->db->set_app($app);
202 202
 
203
-			if ($table) $this->setup_table($app,$table,$column_prefix);
203
+			if ($table) $this->setup_table($app, $table, $column_prefix);
204 204
 		}
205 205
 		$this->init();
206 206
 
207
-		if ((int) $this->debug >= 4)
207
+		if ((int)$this->debug >= 4)
208 208
 		{
209 209
 			echo "<p>".__METHOD__."('$app','$table')</p>\n";
210 210
 			_debug_array($this);
@@ -219,21 +219,21 @@  discard block
 block discarded – undo
219 219
 	 * 	null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use Api\DateTime objects,
220 220
 	 *  'string' use DB timestamp (Y-m-d H:i:s) string
221 221
 	 */
222
-	public function set_times($timestamp_type=false)
222
+	public function set_times($timestamp_type = false)
223 223
 	{
224 224
 		if ($timestamp_type !== false) $this->timestamp_type = $timestamp_type;
225 225
 
226 226
 		// set current time
227
-		switch($this->timestamp_type)
227
+		switch ($this->timestamp_type)
228 228
 		{
229 229
 			case 'object':
230 230
 				$this->now = new Api\DateTime('now');
231 231
 				break;
232 232
 			case 'string':
233
-				$this->now = Api\DateTime::to('now',Api\DateTime::DATABASE);
233
+				$this->now = Api\DateTime::to('now', Api\DateTime::DATABASE);
234 234
 				break;
235 235
 			default:
236
-				$this->now = Api\DateTime::to('now','ts');
236
+				$this->now = Api\DateTime::to('now', 'ts');
237 237
 		}
238 238
 		$this->tz_offset_s = Api\DateTime::tz_offset_s();
239 239
 	}
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
 	 * @param string $table table-name
248 248
 	 * @param string $colum_prefix ='' column prefix to automatic remove from the column-name, if the column name starts with it
249 249
 	 */
250
-	function setup_table($app,$table,$colum_prefix='')
250
+	function setup_table($app, $table, $colum_prefix = '')
251 251
 	{
252 252
 		$this->table_name = $table;
253
-		$this->table_def = $this->db->get_table_definitions($app,$table);
253
+		$this->table_def = $this->db->get_table_definitions($app, $table);
254 254
 		if (!$this->table_def || !is_array($this->table_def['fd']))
255 255
 		{
256 256
 			throw new Api\Exception\WrongParameter(__METHOD__."('$app','$table'): No table definition for '$table' found !!!");
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 		$this->db_key_cols = $this->db_data_cols = $this->db_cols = array();
259 259
 		$this->autoinc_id = '';
260 260
 		$len_prefix = strlen($colum_prefix);
261
-		foreach($this->table_def['fd'] as $col => $def)
261
+		foreach ($this->table_def['fd'] as $col => $def)
262 262
 		{
263 263
 			$name = $col;
264
-			if ($len_prefix && substr($name,0,$len_prefix) == $colum_prefix)
264
+			if ($len_prefix && substr($name, 0, $len_prefix) == $colum_prefix)
265 265
 			{
266
-				$name = substr($col,$len_prefix);
266
+				$name = substr($col, $len_prefix);
267 267
 			}
268
-			if (in_array($col,$this->table_def['pk']))
268
+			if (in_array($col, $this->table_def['pk']))
269 269
 			{
270 270
 				$this->db_key_cols[$col] = $name;
271 271
 			}
@@ -281,13 +281,13 @@  discard block
 block discarded – undo
281 281
 			}
282 282
 			if ($def['type'] == 'bool') $this->has_bools = true;
283 283
 
284
-			foreach($this->table_def['uc'] as $k => $uni_index)
284
+			foreach ($this->table_def['uc'] as $k => $uni_index)
285 285
 			{
286
-				if (is_array($uni_index) && in_array($name,$uni_index))
286
+				if (is_array($uni_index) && in_array($name, $uni_index))
287 287
 				{
288 288
 					$this->db_uni_cols[$k][$col] = $name;
289 289
 				}
290
-				elseif($name === $uni_index)
290
+				elseif ($name === $uni_index)
291 291
 				{
292 292
 					$this->db_uni_cols[$col] = $name;
293 293
 				}
@@ -302,9 +302,9 @@  discard block
 block discarded – undo
302 302
 	function convert_all_timestamps()
303 303
 	{
304 304
 		$check_already_included = !empty($this->timestamps);
305
-		foreach($this->table_def['fd'] as $name => $data)
305
+		foreach ($this->table_def['fd'] as $name => $data)
306 306
 		{
307
-			if ($data['type'] == 'timestamp' && (!$check_already_included || !in_array($name,$this->timestamps)))
307
+			if ($data['type'] == 'timestamp' && (!$check_already_included || !in_array($name, $this->timestamps)))
308 308
 			{
309 309
 				$this->timestamps[] = $name;
310 310
 			}
@@ -318,22 +318,22 @@  discard block
 block discarded – undo
318 318
 	 */
319 319
 	function data_merge($new)
320 320
 	{
321
-		if ((int) $this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
321
+		if ((int)$this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new, true).")</p>\n";
322 322
 
323 323
 		if (!is_array($new) || !count($new))
324 324
 		{
325 325
 			return;
326 326
 		}
327
-		foreach($this->db_cols as $db_col => $col)
327
+		foreach ($this->db_cols as $db_col => $col)
328 328
 		{
329
-			if (array_key_exists($col,$new))
329
+			if (array_key_exists($col, $new))
330 330
 			{
331 331
 				$this->data[$col] = $new[$col];
332 332
 			}
333 333
 		}
334
-		foreach($this->non_db_cols as $db_col => $col)
334
+		foreach ($this->non_db_cols as $db_col => $col)
335 335
 		{
336
-			if (array_key_exists($col,$new))
336
+			if (array_key_exists($col, $new))
337 337
 			{
338 338
 				$this->data[$col] = $new[$col];
339 339
 			}
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		{
343 343
 			$this->data[self::USER_TIMEZONE_READ] = $new[self::USER_TIMEZONE_READ];
344 344
 		}
345
-		if ((int) $this->debug >= 4) _debug_array($this->data);
345
+		if ((int)$this->debug >= 4) _debug_array($this->data);
346 346
 	}
347 347
 
348 348
 	/**
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 * @param array $data =null if given works on that array and returns result, else works on internal data-array
367 367
 	 * @return array
368 368
 	 */
369
-	function db2data($data=null)
369
+	function db2data($data = null)
370 370
 	{
371 371
 		if (!is_array($data))
372 372
 		{
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 		}
375 375
 		if ($this->timestamps)
376 376
 		{
377
-			foreach($this->timestamps as $name)
377
+			foreach ($this->timestamps as $name)
378 378
 			{
379 379
 				if (isset($data[$name]) && $data[$name])
380 380
 				{
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 					}
385 385
 					else
386 386
 					{
387
-						$data[$name] = Api\DateTime::server2user($data[$name],$this->timestamp_type);
387
+						$data[$name] = Api\DateTime::server2user($data[$name], $this->timestamp_type);
388 388
 					}
389 389
 				}
390 390
 			}
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 					throw new Api\Exception\WrongParameter(__METHOD__."(): No table definition for '$this->table' found !!!");
401 401
 				}
402 402
 			}
403
-			foreach($this->table_def['fd'] as $col => $def)
403
+			foreach ($this->table_def['fd'] as $col => $def)
404 404
 			{
405 405
 				if ($def['type'] == 'bool' && isset($data[$col]))
406 406
 				{
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	 * @param array $data =null if given works on that array and returns result, else works on internal data-array
433 433
 	 * @return array
434 434
 	 */
435
-	function data2db($data=null)
435
+	function data2db($data = null)
436 436
 	{
437 437
 		if (!is_array($data))
438 438
 		{
@@ -440,11 +440,11 @@  discard block
 block discarded – undo
440 440
 		}
441 441
 		if ($this->timestamps)
442 442
 		{
443
-			foreach($this->timestamps as $name)
443
+			foreach ($this->timestamps as $name)
444 444
 			{
445 445
 				if (isset($data[$name]) && $data[$name])
446 446
 				{
447
-					$data[$name] = Api\DateTime::user2server($data[$name],$this->timestamp_type);
447
+					$data[$name] = Api\DateTime::user2server($data[$name], $this->timestamp_type);
448 448
 				}
449 449
 			}
450 450
 		}
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	 * @param array $keys =array() array with keys in form internalName => value
458 458
 	 * @return array internal data after init
459 459
 	 */
460
-	function init($keys=array())
460
+	function init($keys = array())
461 461
 	{
462 462
 		$this->data = array();
463 463
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	 * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
482 482
 	 * @return array|boolean data if row could be retrived else False
483 483
 	 */
484
-	function read($keys,$extra_cols='',$join='')
484
+	function read($keys, $extra_cols = '', $join = '')
485 485
 	{
486 486
 		if (!is_array($keys))
487 487
 		{
@@ -502,16 +502,16 @@  discard block
 block discarded – undo
502 502
 		}
503 503
 		if (!$query)	// no primary key in keys, lets try the data_cols for a unique key
504 504
 		{
505
-			foreach($this->db_uni_cols as $db_col => $col)
505
+			foreach ($this->db_uni_cols as $db_col => $col)
506 506
 			{
507 507
 				if (!is_array($col) && $this->data[$col] != '')
508 508
 				{
509 509
 					$query[$db_col] = $this->data[$col];
510 510
 				}
511
-				elseif(is_array($col))
511
+				elseif (is_array($col))
512 512
 				{
513 513
 					$q = array();
514
-					foreach($col as $db_c => $c)
514
+					foreach ($col as $db_c => $c)
515 515
 					{
516 516
 						if ($this->data[$col] == '')
517 517
 						{
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 		}
527 527
 		if (!$query)	// no unique key in keys, lets try everything else
528 528
 		{
529
-			foreach($this->db_data_cols as $db_col => $col)
529
+			foreach ($this->db_data_cols as $db_col => $col)
530 530
 			{
531 531
 				if ($this->data[$col] != '')
532 532
 				{
@@ -542,22 +542,22 @@  discard block
 block discarded – undo
542 542
 		}
543 543
 		if ($join)	// Prefix the columns with the table-name, as they might exist in the join
544 544
 		{
545
-			foreach($query as $col => $val)
545
+			foreach ($query as $col => $val)
546 546
 			{
547
-				if (is_int($col) || strpos($join,$col) === false) continue;
548
-				$query[] = $this->db->expression($this->table_name,$this->table_name.'.',array($col=>$val));
547
+				if (is_int($col) || strpos($join, $col) === false) continue;
548
+				$query[] = $this->db->expression($this->table_name, $this->table_name.'.', array($col=>$val));
549 549
 				unset($query[$col]);
550 550
 			}
551 551
 		}
552
-		foreach($this->db->select($this->table_name,'*'.($extra_cols?','.(is_array($extra_cols)?implode(',',$extra_cols):$extra_cols):''),
553
-			$query,__LINE__,__FILE__,False,'',$this->app,0,$join) as $row)
552
+		foreach ($this->db->select($this->table_name, '*'.($extra_cols ? ','.(is_array($extra_cols) ? implode(',', $extra_cols) : $extra_cols) : ''),
553
+			$query, __LINE__, __FILE__, False, '', $this->app, 0, $join) as $row)
554 554
 		{
555 555
 			$cols = $this->db_cols;
556 556
 			if ($extra_cols)	// extra columns to report
557 557
 			{
558
-				foreach(is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
558
+				foreach (is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
559 559
 				{
560
-					if (FALSE!==stripos($col,' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i','\\1',$col);
560
+					if (FALSE !== stripos($col, ' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i', '\\1', $col);
561 561
 					$cols[$col] = $col;
562 562
 				}
563 563
 			}
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 			// store user timezone used for reading
571 571
 			$this->data[self::USER_TIMEZONE_READ] = Api\DateTime::$user_timezone->getName();
572 572
 
573
-			if ((int) $this->debug >= 4)
573
+			if ((int)$this->debug >= 4)
574 574
 			{
575 575
 				echo "data =\n"; _debug_array($this->data);
576 576
 			}
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 		{
581 581
 			unset($this->data[$this->db_key_cols[$this->autoinc_id]]);
582 582
 		}
583
-		if ((int) $this->debug >= 4) echo "nothing found !!!</p>\n";
583
+		if ((int)$this->debug >= 4) echo "nothing found !!!</p>\n";
584 584
 
585 585
 		$this->db2data();
586 586
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 	 * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows!
595 595
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
596 596
 	 */
597
-	function save($keys=null,$extra_where=null)
597
+	function save($keys = null, $extra_where = null)
598 598
 	{
599 599
 		if (is_array($keys) && count($keys)) $this->data_merge($keys);
600 600
 
@@ -613,65 +613,65 @@  discard block
 block discarded – undo
613 613
 		}
614 614
 		$this->data2db();
615 615
 
616
-		if ((int) $this->debug >= 4) { echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
616
+		if ((int)$this->debug >= 4) { echo "so_sql::save(".print_r($keys, true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
617 617
 
618 618
 		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])	// insert with auto id
619 619
 		{
620
-			foreach($this->db_cols as $db_col => $col)
620
+			foreach ($this->db_cols as $db_col => $col)
621 621
 			{
622 622
 				if (!$this->autoinc_id || $db_col != $this->autoinc_id)	// not write auto-inc-id
623 623
 				{
624
-					if (!array_key_exists($col,$this->data) && 	// handling of unset columns in $this->data
625
-						(isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value
624
+					if (!array_key_exists($col, $this->data) && // handling of unset columns in $this->data
625
+						(isset($this->table_def['fd'][$db_col]['default']) || // we have a default value
626 626
 						 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
627 627
 					{
628
-						continue;	// no need to write that (unset) column
628
+						continue; // no need to write that (unset) column
629 629
 					}
630 630
 					if ($this->table_def['fd'][$db_col]['type'] == 'varchar' &&
631 631
 						strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision'])
632 632
 					{
633 633
 						// truncate the field to mamimum length, if upper layers didn't care
634
-						$data[$db_col] = substr($this->data[$col],0,$this->table_def['fd'][$db_col]['precision']);
634
+						$data[$db_col] = substr($this->data[$col], 0, $this->table_def['fd'][$db_col]['precision']);
635 635
 					}
636 636
 					else
637 637
 					{
638
-						$data[$db_col] = (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
638
+						$data[$db_col] = (string)$this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
639 639
 					}
640 640
 				}
641 641
 			}
642
-			$this->db->insert($this->table_name,$data,false,__LINE__,__FILE__,$this->app);
642
+			$this->db->insert($this->table_name, $data, false, __LINE__, __FILE__, $this->app);
643 643
 
644 644
 			if ($this->autoinc_id)
645 645
 			{
646
-				$this->data[$this->db_key_cols[$this->autoinc_id]] = $this->db->get_last_insert_id($this->table_name,$this->autoinc_id);
646
+				$this->data[$this->db_key_cols[$this->autoinc_id]] = $this->db->get_last_insert_id($this->table_name, $this->autoinc_id);
647 647
 			}
648 648
 		}
649 649
 		else // insert in table without auto id or update of existing row, dont write colums unset in $this->data
650 650
 		{
651
-			foreach($this->db_data_cols as $db_col => $col)
651
+			foreach ($this->db_data_cols as $db_col => $col)
652 652
 			{
653 653
 				// we need to update columns set to null: after a $this->data[$col]=null:
654 654
 				// - array_key_exits($col,$this->data) === true
655 655
 				// - isset($this->data[$col]) === false
656
-				if (!array_key_exists($col,$this->data) &&	// handling of unset columns in $this->data
657
-					($this->autoinc_id ||			// update of table with auto id or
658
-					 isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value or
656
+				if (!array_key_exists($col, $this->data) && // handling of unset columns in $this->data
657
+					($this->autoinc_id || // update of table with auto id or
658
+					 isset($this->table_def['fd'][$db_col]['default']) || // we have a default value or
659 659
 					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
660 660
 				{
661
-					continue;	// no need to write that (unset) column
661
+					continue; // no need to write that (unset) column
662 662
 				}
663
-				$data[$db_col] = !is_object($this->data[$col]) && (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
663
+				$data[$db_col] = !is_object($this->data[$col]) && (string)$this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
664 664
 			}
665 665
 			// allow to add direct sql updates, eg. "etag=etag+1" with int keys
666 666
 			if (is_array($keys) && isset($keys[0]))
667 667
 			{
668
-				for($n=0; isset($keys[$n]); ++$n)
668
+				for ($n = 0; isset($keys[$n]); ++$n)
669 669
 				{
670 670
 					$data[] = $keys[$n];
671 671
 				}
672 672
 			}
673 673
 			$keys = $extra_where;
674
-			foreach($this->db_key_cols as $db_col => $col)
674
+			foreach ($this->db_key_cols as $db_col => $col)
675 675
 			{
676 676
 				$keys[$db_col] = $this->data[$col];
677 677
 			}
@@ -682,16 +682,16 @@  discard block
 block discarded – undo
682 682
 			}
683 683
 			if ($this->autoinc_id)
684 684
 			{
685
-				$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app);
685
+				$this->db->update($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app);
686 686
 				if (($nothing_affected = !$this->db->Errno && !$this->db->affected_rows()) && $extra_where)
687 687
 				{
688
-					return true;	// extra_where not met, eg. etag wrong
688
+					return true; // extra_where not met, eg. etag wrong
689 689
 				}
690 690
 			}
691 691
 			// always try an insert if we have no autoinc_id, as we dont know if the data exists
692 692
 			if (!$this->autoinc_id || $nothing_affected)
693 693
 			{
694
-				$this->db->insert($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app);
694
+				$this->db->insert($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app);
695 695
 			}
696 696
 		}
697 697
 		$this->db2data();
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 	 * @param boolean $merge =true if true $fields will be merged with $this->data (after update!), otherwise $this->data will be just $fields
707 707
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
708 708
 	 */
709
-	function update($_fields,$merge=true)
709
+	function update($_fields, $merge = true)
710 710
 	{
711 711
 		if ($merge) $this->data_merge($_fields);
712 712
 
@@ -714,23 +714,23 @@  discard block
 block discarded – undo
714 714
 
715 715
 		// extract the keys from $fields or - if not set there - from $this->data
716 716
 		$keys = array();
717
-		foreach($this->db_key_cols as $col => $name)
717
+		foreach ($this->db_key_cols as $col => $name)
718 718
 		{
719 719
 			$keys[$col] = isset($fields[$name]) ? $fields[$name] : $this->data[$name];
720 720
 			unset($fields[$name]);
721 721
 		}
722 722
 		// extract the data from $fields
723 723
 		$data = array();
724
-		foreach($this->db_data_cols as $col => $name)
724
+		foreach ($this->db_data_cols as $col => $name)
725 725
 		{
726
-			if (array_key_exists($name,$fields))
726
+			if (array_key_exists($name, $fields))
727 727
 			{
728 728
 				$data[$col] = $fields[$name];
729 729
 				unset($fields[$name]);
730 730
 			}
731 731
 		}
732 732
 		// add direct sql like 'etag=etag+1' (it has integer keys)
733
-		foreach($fields as $key => $value)
733
+		foreach ($fields as $key => $value)
734 734
 		{
735 735
 			if (is_int($key))
736 736
 			{
@@ -739,9 +739,9 @@  discard block
 block discarded – undo
739 739
 		}
740 740
 		if (!$data)
741 741
 		{
742
-			return 0;	// nothing to update
742
+			return 0; // nothing to update
743 743
 		}
744
-		if (!$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app))
744
+		if (!$this->db->update($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app))
745 745
 		{
746 746
 			return $this->db->Errno;
747 747
 		}
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 	 * @param boolean $only_return_query =false return $query of delete call to db object, but not run it (used by so_sql_cf!)
756 756
 	 * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids
757 757
 	 */
758
-	function delete($keys=null,$only_return_query=false)
758
+	function delete($keys = null, $only_return_query = false)
759 759
 	{
760 760
 		if ($this->autoinc_id && $keys && !is_array($keys))
761 761
 		{
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 		else	// data and keys are supplied in $keys
770 770
 		{
771 771
 			$data = $keys; $keys = array();
772
-			foreach($this->db_cols as $db_col => $col)
772
+			foreach ($this->db_cols as $db_col => $col)
773 773
 			{
774 774
 				if (isset($data[$col]))
775 775
 				{
@@ -779,13 +779,13 @@  discard block
 block discarded – undo
779 779
 		}
780 780
 		$data = $this->data2db($data);
781 781
 
782
-		foreach($keys as $db_col => $col)
782
+		foreach ($keys as $db_col => $col)
783 783
 		{
784 784
 			$query[$db_col] = $data[$col];
785 785
 		}
786 786
 		if ($only_return_query) return $query;
787 787
 
788
-		$this->db->delete($this->table_name,$query,__LINE__,__FILE__,$this->app);
788
+		$this->db->delete($this->table_name, $query, __LINE__, __FILE__, $this->app);
789 789
 
790 790
 		return $this->db->affected_rows();
791 791
 	}
@@ -813,15 +813,15 @@  discard block
 block discarded – undo
813 813
 	 * @todo return an interator instead of an array
814 814
 	 * @return array|NULL array of matching rows (the row is an array of the cols) or NULL
815 815
 	 */
816
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
816
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false)
817 817
 	{
818 818
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
819
-		if ((int) $this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
819
+		if ((int)$this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria, true).",'$only_keys','$order_by',".print_r($extra_cols, true).",'$wildcard','$empty','$op','$start',".print_r($filter, true).",'$join')</p>\n";
820 820
 
821 821
 		// if extending class or instanciator set columns to search, convert string criteria to array
822 822
 		if ($criteria && !is_array($criteria))
823 823
 		{
824
-			$search = $this->search2criteria($criteria,$wildcard,$op);
824
+			$search = $this->search2criteria($criteria, $wildcard, $op);
825 825
 			$criteria = array($search);
826 826
 		}
827 827
 		if (!is_array($criteria))
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 		else
832 832
 		{
833 833
 			$criteria = $this->data2db($criteria);
834
-			foreach($criteria as $col => $val)
834
+			foreach ($criteria as $col => $val)
835 835
 			{
836 836
 				if (is_int($col))
837 837
 				{
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 				}
840 840
 				elseif ($empty || $val != '')
841 841
 				{
842
-					if (!($db_col = array_search($col,$this->db_cols)))
842
+					if (!($db_col = array_search($col, $this->db_cols)))
843 843
 					{
844 844
 						$db_col = $col;
845 845
 					}
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 							$this->table_def['fd'][$db_col]['nullable'] !== false)
851 851
 						{
852 852
 							unset($criteria[$col]);
853
-							$query[] =  '(' . $db_col . ' IS NULL OR ' . $db_col . " = '')";
853
+							$query[] = '('.$db_col.' IS NULL OR '.$db_col." = '')";
854 854
 						}
855 855
 						else
856 856
 						{
@@ -858,10 +858,10 @@  discard block
 block discarded – undo
858 858
 						}
859 859
 					}
860 860
 					elseif ($wildcard || $criteria[$col][0] == '!' ||
861
-						is_string($criteria[$col]) && (strpos($criteria[$col],'*')!==false || strpos($criteria[$col],'?')!==false))
861
+						is_string($criteria[$col]) && (strpos($criteria[$col], '*') !== false || strpos($criteria[$col], '?') !== false))
862 862
 					{
863 863
 						// if search pattern alread contains a wildcard, do NOT add further ones automatic
864
-						if (is_string($criteria[$col]) && (strpos($criteria[$col],'*')!==false || strpos($criteria[$col],'?')!==false))
864
+						if (is_string($criteria[$col]) && (strpos($criteria[$col], '*') !== false || strpos($criteria[$col], '?') !== false))
865 865
 						{
866 866
 							$wildcard = '';
867 867
 						}
@@ -870,19 +870,19 @@  discard block
 block discarded – undo
870 870
 						if ($criteria[$col][0] == '!')
871 871
 						{
872 872
 							$cmp_op = ' NOT'.$cmp_op;
873
-							$criteria[$col] = substr($criteria[$col],1);
873
+							$criteria[$col] = substr($criteria[$col], 1);
874 874
 							$negate = true;
875 875
 						}
876
-						foreach(explode(' ',$criteria[$col]) as $crit)
876
+						foreach (explode(' ', $criteria[$col]) as $crit)
877 877
 						{
878 878
 							$query[] = ($negate ? ' ('.$db_col.' IS NULL OR ' : '').$db_col.$cmp_op.
879
-								$this->db->quote($wildcard.str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$crit).$wildcard).
879
+								$this->db->quote($wildcard.str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $crit).$wildcard).
880 880
 								($negate ? ') ' : '');
881 881
 						}
882 882
 					}
883
-					elseif (strpos($db_col,'.') !== false)	// we have a table-name specified
883
+					elseif (strpos($db_col, '.') !== false)	// we have a table-name specified
884 884
 					{
885
-						list($table,$only_col) = explode('.',$db_col);
885
+						list($table, $only_col) = explode('.', $db_col);
886 886
 						$type = $this->db->get_column_attribute($only_col, $table, true, 'type');
887 887
 						if (empty($type))
888 888
 						{
@@ -890,15 +890,15 @@  discard block
 block discarded – undo
890 890
 						}
891 891
 						if (is_array($val) && count($val) > 1)
892 892
 						{
893
-							foreach($val as &$v)
893
+							foreach ($val as &$v)
894 894
 							{
895 895
 								$v = $this->db->quote($v, $type);
896 896
 							}
897
-							$query[] = $sql = $db_col.' IN (' .implode(',',$val).')';
897
+							$query[] = $sql = $db_col.' IN ('.implode(',', $val).')';
898 898
 						}
899 899
 						else
900 900
 						{
901
-							$query[] = $db_col.'='.$this->db->quote(is_array($val)?array_shift($val):$val,$type);
901
+							$query[] = $db_col.'='.$this->db->quote(is_array($val) ? array_shift($val) : $val, $type);
902 902
 						}
903 903
 					}
904 904
 					else
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
 					}
908 908
 				}
909 909
 			}
910
-			if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query);
910
+			if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ', $query);
911 911
 		}
912 912
 		if (is_array($filter))
913 913
 		{
@@ -915,19 +915,19 @@  discard block
 block discarded – undo
915 915
 			$data2db_filter = $this->data2db($filter);
916 916
 			if (!is_array($data2db_filter)) {
917 917
 				echo function_backtrace()."<br/>\n";
918
-				echo "filter=";_debug_array($filter);
919
-				echo "data2db(filter)=";_debug_array($data2db_filter);
918
+				echo "filter="; _debug_array($filter);
919
+				echo "data2db(filter)="; _debug_array($data2db_filter);
920 920
 			}
921
-			foreach($data2db_filter as $col => $val)
921
+			foreach ($data2db_filter as $col => $val)
922 922
 			{
923 923
 				if ($val !== '')
924 924
 				{
925 925
 					// check if a db-internal name conversation necessary
926
-					if (!is_int($col) && ($c = array_search($col,$this->db_cols)))
926
+					if (!is_int($col) && ($c = array_search($col, $this->db_cols)))
927 927
 					{
928
-						$col = $this->table_name . '.' . $c;
928
+						$col = $this->table_name.'.'.$c;
929 929
 					}
930
-					if(is_int($col))
930
+					if (is_int($col))
931 931
 					{
932 932
 						$db_filter[] = $val;
933 933
 					}
@@ -945,35 +945,35 @@  discard block
 block discarded – undo
945 945
 			{
946 946
 				if ($op != 'AND')
947 947
 				{
948
-					$db_filter[] = '('.$this->db->column_data_implode(' '.$op.' ',$query).')';
948
+					$db_filter[] = '('.$this->db->column_data_implode(' '.$op.' ', $query).')';
949 949
 				}
950 950
 				else
951 951
 				{
952
-					$db_filter = array_merge($db_filter,$query);
952
+					$db_filter = array_merge($db_filter, $query);
953 953
 				}
954 954
 			}
955 955
 			$query = $db_filter;
956 956
 		}
957
-		if ((int) $this->debug >= 4)
957
+		if ((int)$this->debug >= 4)
958 958
 		{
959
-			echo "<p>so_sql::search(,only_keys=$only_keys,order_by='$order_by',wildcard='$wildcard',empty=$empty,$op,start='$start',".print_r($filter,true).") query=".print_r($query,true).", total='$this->total'</p>\n";
959
+			echo "<p>so_sql::search(,only_keys=$only_keys,order_by='$order_by',wildcard='$wildcard',empty=$empty,$op,start='$start',".print_r($filter, true).") query=".print_r($query, true).", total='$this->total'</p>\n";
960 960
 			echo "<br>criteria = "; _debug_array($criteria);
961 961
 		}
962 962
 		if ($only_keys === true)
963 963
 		{
964 964
 			$colums = array_keys($this->db_key_cols);
965
-			foreach($colums as &$column)
965
+			foreach ($colums as &$column)
966 966
 			{
967
-				$column = $this->table_name . '.' . $column;
967
+				$column = $this->table_name.'.'.$column;
968 968
 			}
969 969
 		}
970 970
 		elseif (is_array($only_keys))
971 971
 		{
972 972
 			$colums = array();
973
-			foreach($only_keys as $key => $col)
973
+			foreach ($only_keys as $key => $col)
974 974
 			{
975 975
 				//Convert ambiguous columns to prefixed tablename.column name
976
-				$colums[] = ($db_col = array_search($col,$this->db_cols)) ?  $this->table_name .'.'.$db_col.' AS '.$col :$col;
976
+				$colums[] = ($db_col = array_search($col, $this->db_cols)) ? $this->table_name.'.'.$db_col.' AS '.$col : $col;
977 977
 			}
978 978
 		}
979 979
 		elseif (!$only_keys)
@@ -1003,20 +1003,20 @@  discard block
 block discarded – undo
1003 1003
 			{
1004 1004
 				$colums[$key] = $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id;
1005 1005
 			}
1006
-			elseif (!is_array($colums) && strpos($colums,$this->autoinc_id) !== false)
1006
+			elseif (!is_array($colums) && strpos($colums, $this->autoinc_id) !== false)
1007 1007
 			{
1008
-				$colums = preg_replace('/(?<! AS)([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/','\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2',$colums);
1008
+				$colums = preg_replace('/(?<! AS)([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/', '\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2', $colums);
1009 1009
 			}
1010 1010
 		}
1011
-		$num_rows = 0;	// as spec. in max_matches in the user-prefs
1012
-		if (is_array($start)) list($start,$num_rows) = $start;
1011
+		$num_rows = 0; // as spec. in max_matches in the user-prefs
1012
+		if (is_array($start)) list($start, $num_rows) = $start;
1013 1013
 
1014 1014
 		// fix GROUP BY clause to contain all non-aggregate selected columns
1015
-		if ($order_by && stripos($order_by,'GROUP BY') !== false)
1015
+		if ($order_by && stripos($order_by, 'GROUP BY') !== false)
1016 1016
 		{
1017 1017
 			$order_by = $this->fix_group_by_columns($order_by, $colums, $this->table_name, $this->autoinc_id);
1018 1018
 		}
1019
-		elseif ($order_by && stripos($order_by,'ORDER BY')===false && stripos($order_by,'GROUP BY')===false && stripos($order_by,'HAVING')===false)
1019
+		elseif ($order_by && stripos($order_by, 'ORDER BY') === false && stripos($order_by, 'GROUP BY') === false && stripos($order_by, 'HAVING') === false)
1020 1020
 		{
1021 1021
 			$order_by = 'ORDER BY '.$order_by;
1022 1022
 		}
@@ -1039,9 +1039,9 @@  discard block
 block discarded – undo
1039 1039
 				);
1040 1040
 				if (!$union_cols)	// union used the colum-names of the first query
1041 1041
 				{
1042
-					$union_cols = $this->_get_columns($only_keys,$extra_cols);
1042
+					$union_cols = $this->_get_columns($only_keys, $extra_cols);
1043 1043
 				}
1044
-				return true;	// waiting for further calls, before running the union-query
1044
+				return true; // waiting for further calls, before running the union-query
1045 1045
 			}
1046 1046
 			// running the union query now
1047 1047
 			if ($start !== false)	// need to get the total too, saved in $this->total
@@ -1052,10 +1052,10 @@  discard block
 block discarded – undo
1052 1052
 				}
1053 1053
 				else	// cant do a count, have to run the query without limit
1054 1054
 				{
1055
-					$this->total = $this->db->union($union,__LINE__,__FILE__)->NumRows();
1055
+					$this->total = $this->db->union($union, __LINE__, __FILE__)->NumRows();
1056 1056
 				}
1057 1057
 			}
1058
-			$rs = $this->db->union($union,__LINE__,__FILE__,$order_by,$start,$num_rows);
1058
+			$rs = $this->db->union($union, __LINE__, __FILE__, $order_by, $start, $num_rows);
1059 1059
 			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1060 1060
 
1061 1061
 			$cols = $union_cols;
@@ -1069,21 +1069,21 @@  discard block
 block discarded – undo
1069 1069
 				{
1070 1070
 					$mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ';
1071 1071
 				}
1072
-				elseif (!$need_full_no_count && (!$join || stripos($join,'LEFT JOIN')!==false))
1072
+				elseif (!$need_full_no_count && (!$join || stripos($join, 'LEFT JOIN') !== false))
1073 1073
 				{
1074
-					$this->total = $this->db->select($this->table_name,'COUNT(*)',$query,__LINE__,__FILE__,false,'',$this->app,0,$join)->fetchColumn();
1074
+					$this->total = $this->db->select($this->table_name, 'COUNT(*)', $query, __LINE__, __FILE__, false, '', $this->app, 0, $join)->fetchColumn();
1075 1075
 				}
1076 1076
 				else	// cant do a count, have to run the query without limit
1077 1077
 				{
1078
-					$this->total = $this->db->select($this->table_name,$colums,$query,__LINE__,__FILE__,false,$order_by,false,0,$join)->NumRows();
1078
+					$this->total = $this->db->select($this->table_name, $colums, $query, __LINE__, __FILE__, false, $order_by, false, 0, $join)->NumRows();
1079 1079
 				}
1080 1080
 			}
1081
-			$rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__,
1082
-				$start,$order_by,$this->app,$num_rows,$join);
1081
+			$rs = $this->db->select($this->table_name, $mysql_calc_rows.$colums, $query, __LINE__, __FILE__,
1082
+				$start, $order_by, $this->app, $num_rows, $join);
1083 1083
 			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1084
-			$cols = $this->_get_columns($only_keys,$extra_cols);
1084
+			$cols = $this->_get_columns($only_keys, $extra_cols);
1085 1085
 		}
1086
-		if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1086
+		if ((int)$this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1087 1087
 
1088 1088
 		if ($mysql_calc_rows)
1089 1089
 		{
@@ -1092,14 +1092,14 @@  discard block
 block discarded – undo
1092 1092
 		// ToDo: Implement that as an iterator, as $rs is also an interator and we could return one instead of an array
1093 1093
 		if ($this->search_return_iterator)
1094 1094
 		{
1095
-			return new Db2DataIterator($this,$rs);
1095
+			return new Db2DataIterator($this, $rs);
1096 1096
 		}
1097 1097
 		$arr = array();
1098 1098
 		$n = 0;
1099
-		if ($rs) foreach($rs as $row)
1099
+		if ($rs) foreach ($rs as $row)
1100 1100
 		{
1101 1101
 			$data = array();
1102
-			foreach($cols as $db_col => $col)
1102
+			foreach ($cols as $db_col => $col)
1103 1103
 			{
1104 1104
 				$data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]);
1105 1105
 			}
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
 		$matches = null;
1130 1130
 		if (substr($GLOBALS['egw']->db->Type, 0, 5) == 'mysql' || !preg_match('/(GROUP BY .*)(HAVING.*|ORDER BY.*)?$/iU', $group_by, $matches))
1131 1131
 		{
1132
-			return $group_by;	// nothing to do
1132
+			return $group_by; // nothing to do
1133 1133
 		}
1134 1134
 		$changes = 0;
1135 1135
 		$group_by_cols = preg_split('/, */', trim(substr($matches[1], 9)));
@@ -1139,9 +1139,9 @@  discard block
 block discarded – undo
1139 1139
 			$columns = preg_split('/, */', $columns);
1140 1140
 
1141 1141
 			// fix columns containing commas as part of function calls
1142
-			for($n = 0; $n < count($columns); ++$n)
1142
+			for ($n = 0; $n < count($columns); ++$n)
1143 1143
 			{
1144
-				$col =& $columns[$n];
1144
+				$col = & $columns[$n];
1145 1145
 				while (substr_count($col, '(') > substr_count($col, ')') && ++$n < count($columns))
1146 1146
 				{
1147 1147
 					$col .= ','.$columns[$n];
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 			}
1151 1151
 			unset($col);
1152 1152
 		}
1153
-		foreach($columns as $n => $col)
1153
+		foreach ($columns as $n => $col)
1154 1154
 		{
1155 1155
 			if ($col == '*')
1156 1156
 			{
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
 			{
1164 1164
 				if (($pos = stripos($col, 'DISTINCT ')) !== false)
1165 1165
 				{
1166
-					$col = substr($col, $pos+9);
1166
+					$col = substr($col, $pos + 9);
1167 1167
 				}
1168 1168
 				$alias = $col;
1169 1169
 				if (stripos($col, ' AS ')) list($col, $alias) = preg_split('/ +AS +/i', $col);
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
 		$ret = $group_by;
1182 1182
 		if ($changes)
1183 1183
 		{
1184
-			$ret = str_replace($matches[1], 'GROUP BY '.implode(',', $group_by_cols).' ',  $group_by);
1184
+			$ret = str_replace($matches[1], 'GROUP BY '.implode(',', $group_by_cols).' ', $group_by);
1185 1185
 			//error_log(__METHOD__."('$group_by', ".array2string($columns).") group_by_cols=".array2string($group_by_cols)." changed to $ret");
1186 1186
 		}
1187 1187
 		return $ret;
@@ -1197,12 +1197,12 @@  discard block
 block discarded – undo
1197 1197
 	 * @param array $search_cols =array() List of columns to search.  If not provided, all columns in $this->db_cols will be considered
1198 1198
 	 * @return array or column => value pairs
1199 1199
 	 */
1200
-	public function search2criteria($_pattern,&$wildcard='',&$op='AND',$extra_col=null, $search_cols = array())
1200
+	public function search2criteria($_pattern, &$wildcard = '', &$op = 'AND', $extra_col = null, $search_cols = array())
1201 1201
 	{
1202 1202
 		$pattern = trim($_pattern);
1203 1203
 		// This function can get called multiple times.  Make sure it doesn't re-process.
1204 1204
 		if (empty($pattern) || is_array($pattern)) return $pattern;
1205
-		if(strpos($pattern, 'CAST(COALESCE(') !== false)
1205
+		if (strpos($pattern, 'CAST(COALESCE(') !== false)
1206 1206
 		{
1207 1207
 			return $pattern;
1208 1208
 		}
@@ -1218,20 +1218,20 @@  discard block
 block discarded – undo
1218 1218
 		$numeric_types = array('auto', 'int', 'float', 'double', 'decimal');
1219 1219
 		$numeric_columns = array();
1220 1220
 
1221
-		if(!$search_cols)
1221
+		if (!$search_cols)
1222 1222
 		{
1223 1223
 			$search_cols = $this->get_default_search_columns();
1224 1224
 		}
1225 1225
 		// Concat all fields to be searched together, so the conditions operate across the whole record
1226
-		foreach($search_cols as $col)
1226
+		foreach ($search_cols as $col)
1227 1227
 		{
1228 1228
 			$col_name = $col;
1229 1229
 			$table = $this->table_name;
1230
-			if (strpos($col,'.') !== false)
1230
+			if (strpos($col, '.') !== false)
1231 1231
 			{
1232
-				list($table,$col_name) = explode('.',$col);
1232
+				list($table, $col_name) = explode('.', $col);
1233 1233
 			}
1234
-			$table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true,$table);
1234
+			$table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true, $table);
1235 1235
 			if ($table_def['fd'][$col_name] && in_array($table_def['fd'][$col_name]['type'], $numeric_types))
1236 1236
 			{
1237 1237
 				$numeric_columns[] = $col;
@@ -1239,11 +1239,11 @@  discard block
 block discarded – undo
1239 1239
 			}
1240 1240
 			if ($this->db->Type == 'mysql' && $table_def['fd'][$col_name]['type'] === 'ascii' && preg_match('/[\x80-\xFF]/', $_pattern))
1241 1241
 			{
1242
-				continue;	// will only give sql error
1242
+				continue; // will only give sql error
1243 1243
 			}
1244
-			$columns[] = sprintf($this->db->capabilities[Api\Db::CAPABILITY_CAST_AS_VARCHAR],"COALESCE($col,'')");
1244
+			$columns[] = sprintf($this->db->capabilities[Api\Db::CAPABILITY_CAST_AS_VARCHAR], "COALESCE($col,'')");
1245 1245
 		}
1246
-		if(!$columns)
1246
+		if (!$columns)
1247 1247
 		{
1248 1248
 			return array();
1249 1249
 		}
@@ -1252,9 +1252,9 @@  discard block
 block discarded – undo
1252 1252
 		$break = ' ';
1253 1253
 		$token = strtok($pattern, $break);
1254 1254
 
1255
-		while($token)
1255
+		while ($token)
1256 1256
 		{
1257
-			if($token == strtoupper(lang('AND')) || $token == 'AND')
1257
+			if ($token == strtoupper(lang('AND')) || $token == 'AND')
1258 1258
 			{
1259 1259
 				$token = '+'.strtok($break);
1260 1260
 			}
@@ -1267,10 +1267,10 @@  discard block
 block discarded – undo
1267 1267
 			{
1268 1268
 				$token = '-'.strtok($break);
1269 1269
 			}
1270
-			if ($token[0]=='"')
1270
+			if ($token[0] == '"')
1271 1271
 			{
1272
-				$token = substr($token, 1,strlen($token));
1273
- 				if(substr($token, -1) != '"')
1272
+				$token = substr($token, 1, strlen($token));
1273
+ 				if (substr($token, -1) != '"')
1274 1274
 				{
1275 1275
 					$token .= ' '.strtok('"');
1276 1276
 				}
@@ -1281,16 +1281,16 @@  discard block
 block discarded – undo
1281 1281
 			}
1282 1282
 
1283 1283
 			// prepend and append extra wildcard %, if pattern does NOT already contain wildcards
1284
-			if (strpos($token,'*') === false && strpos($token,'?') === false)
1284
+			if (strpos($token, '*') === false && strpos($token, '?') === false)
1285 1285
 			{
1286
-				$wildcard = '%';	// if pattern contains no wildcards, add them before AND after the pattern
1286
+				$wildcard = '%'; // if pattern contains no wildcards, add them before AND after the pattern
1287 1287
 			}
1288 1288
 			else
1289 1289
 			{
1290
-				$wildcard = '';		// no extra wildcard, if pattern already contains some
1290
+				$wildcard = ''; // no extra wildcard, if pattern already contains some
1291 1291
 			}
1292 1292
 
1293
-			switch($token[0])
1293
+			switch ($token[0])
1294 1294
 			{
1295 1295
 				case '+':
1296 1296
 					$op = 'AND';
@@ -1305,32 +1305,32 @@  discard block
 block discarded – undo
1305 1305
 					$op = 'OR';
1306 1306
 					break;
1307 1307
 			}
1308
-			$token_filter = ' '.call_user_func_array(array($GLOBALS['egw']->db,'concat'),$columns).' '.
1309
-				$this->db->capabilities['case_insensitive_like'] . ' ' .
1310
-				$GLOBALS['egw']->db->quote($wildcard.str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$token).$wildcard);
1308
+			$token_filter = ' '.call_user_func_array(array($GLOBALS['egw']->db, 'concat'), $columns).' '.
1309
+				$this->db->capabilities['case_insensitive_like'].' '.
1310
+				$GLOBALS['egw']->db->quote($wildcard.str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $token).$wildcard);
1311 1311
 
1312 1312
 			// Compare numeric token as equality for numeric columns
1313 1313
 			// skip user-wildcards (*,?) in is_numeric test, but not SQL wildcards, which get escaped and give sql-error
1314
-			if (is_numeric(str_replace(array('*','?'), '', $token)))
1314
+			if (is_numeric(str_replace(array('*', '?'), '', $token)))
1315 1315
 			{
1316 1316
 				$numeric_filter = array();
1317
-				foreach($numeric_columns as $col)
1317
+				foreach ($numeric_columns as $col)
1318 1318
 				{
1319
-					if($wildcard == '')
1319
+					if ($wildcard == '')
1320 1320
 					{
1321 1321
 						// Token has a wildcard from user, use LIKE
1322
-						$numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) " .
1323
-							$this->db->capabilities['case_insensitive_like'] . ' ' .
1324
-							$GLOBALS['egw']->db->quote(str_replace(array('*','?'), array('%','_'), $token)) . ')';
1322
+						$numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) ".
1323
+							$this->db->capabilities['case_insensitive_like'].' '.
1324
+							$GLOBALS['egw']->db->quote(str_replace(array('*', '?'), array('%', '_'), $token)).')';
1325 1325
 					}
1326 1326
 					else
1327 1327
 					{
1328 1328
 						$numeric_filter[] = "($col IS NOT NULL AND $col = $token)";
1329 1329
 					}
1330 1330
 				}
1331
-				if(count($numeric_filter) > 0)
1331
+				if (count($numeric_filter) > 0)
1332 1332
 				{
1333
-					$token_filter = '(' . $token_filter . ' OR ' . implode(' OR ', $numeric_filter) . ')';
1333
+					$token_filter = '('.$token_filter.' OR '.implode(' OR ', $numeric_filter).')';
1334 1334
 				}
1335 1335
 			}
1336 1336
 			$criteria[$op][] = $token_filter;
@@ -1338,32 +1338,32 @@  discard block
 block discarded – undo
1338 1338
 			$token = strtok($break);
1339 1339
 		}
1340 1340
 
1341
-		if($criteria['NOT'])
1341
+		if ($criteria['NOT'])
1342 1342
 		{
1343
-			$filter[] = 'NOT (' . implode(' OR ', $criteria['NOT']) . ') ';
1343
+			$filter[] = 'NOT ('.implode(' OR ', $criteria['NOT']).') ';
1344 1344
 		}
1345
-		if($criteria['AND'])
1345
+		if ($criteria['AND'])
1346 1346
 		{
1347
-			$filter[] = implode(' AND ', $criteria['AND']) . ' ';
1347
+			$filter[] = implode(' AND ', $criteria['AND']).' ';
1348 1348
 		}
1349
-		if($criteria['OR'])
1349
+		if ($criteria['OR'])
1350 1350
 		{
1351
-			$filter[] = '(' . implode(' OR ', $criteria['OR']) . ') ';
1351
+			$filter[] = '('.implode(' OR ', $criteria['OR']).') ';
1352 1352
 		}
1353 1353
 
1354
-		if(count($filter))
1354
+		if (count($filter))
1355 1355
 		{
1356
-			$result = '(' . implode(' AND ', $filter) . ')';
1356
+			$result = '('.implode(' AND ', $filter).')';
1357 1357
 		}
1358 1358
 
1359 1359
 		// OR extra column on the end so a null or blank won't block a hit in the main columns
1360 1360
 		if ($extra_col)
1361 1361
 		{
1362
-			$result .= (strlen($result) ? ' OR ' : ' ') . "$extra_col = " . $GLOBALS['egw']->db->quote($pattern);
1362
+			$result .= (strlen($result) ? ' OR ' : ' ')."$extra_col = ".$GLOBALS['egw']->db->quote($pattern);
1363 1363
 		}
1364 1364
 
1365 1365
 		$op = 'OR';
1366
-		return array('(' . $result . ')');
1366
+		return array('('.$result.')');
1367 1367
 	}
1368 1368
 
1369 1369
 	/**
@@ -1382,21 +1382,21 @@  discard block
 block discarded – undo
1382 1382
 		$numeric_types = array('auto', 'int', 'float', 'double');
1383 1383
 
1384 1384
 		// Skip some numeric columns that don't make sense to search if we have to default to all columns
1385
-		if(is_null($this->columns_to_search))
1385
+		if (is_null($this->columns_to_search))
1386 1386
 		{
1387
-			foreach($search_cols as $key => &$col)
1387
+			foreach ($search_cols as $key => &$col)
1388 1388
 			{
1389 1389
 				// If the name as given isn't a real column name, and adding the prefix doesn't help, skip it
1390
-				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1390
+				if (!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1391 1391
 					// Can't search this column
1392 1392
 					unset($search_cols[$key]);
1393 1393
 					continue;
1394 1394
 				}
1395
-				if(in_array($this->table_def['fd'][$col]['type'], $numeric_types))
1395
+				if (in_array($this->table_def['fd'][$col]['type'], $numeric_types))
1396 1396
 				{
1397
-					foreach($skip_columns_with as $bad)
1397
+					foreach ($skip_columns_with as $bad)
1398 1398
 					{
1399
-						if(strpos($col, $bad) !== false)
1399
+						if (strpos($col, $bad) !== false)
1400 1400
 						{
1401 1401
 							unset($search_cols[$key]);
1402 1402
 							continue 2;
@@ -1418,7 +1418,7 @@  discard block
 block discarded – undo
1418 1418
 	 * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num"
1419 1419
 	 * @return array with columns as db-name => internal-name pairs
1420 1420
 	 */
1421
-	function _get_columns($only_keys,$extra_cols)
1421
+	function _get_columns($only_keys, $extra_cols)
1422 1422
 	{
1423 1423
 		//echo "_get_columns() only_keys="; _debug_array($only_keys); echo "extra_cols="; _debug_array($extra_cols);
1424 1424
 		if ($only_keys === true)	// only primary key
@@ -1429,7 +1429,7 @@  discard block
 block discarded – undo
1429 1429
 		{
1430 1430
 			$cols = array();
1431 1431
 			$distinct_checked = false;
1432
-			foreach(is_array($only_keys) ? $only_keys : explode(',', $only_keys) as $col)
1432
+			foreach (is_array($only_keys) ? $only_keys : explode(',', $only_keys) as $col)
1433 1433
 			{
1434 1434
 				if (!$distinct_checked)
1435 1435
 				{
@@ -1438,17 +1438,17 @@  discard block
 block discarded – undo
1438 1438
 				}
1439 1439
 				if (!$col || $col == '*' || $col == $this->table_name.'.*')	// all columns
1440 1440
 				{
1441
-					$cols = array_merge($cols,$this->db_cols);
1441
+					$cols = array_merge($cols, $this->db_cols);
1442 1442
 				}
1443 1443
 				else	// only the specified columns
1444 1444
 				{
1445
-					if (stripos($col,'as'))	// if there's already an explicit naming of the column, just use it
1445
+					if (stripos($col, 'as'))	// if there's already an explicit naming of the column, just use it
1446 1446
 					{
1447
-						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1447
+						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i', '\\1', $col);
1448 1448
 						$cols[$col] = $col;
1449 1449
 						continue;
1450 1450
 					}
1451
-					if (($db_col = array_search($col,$this->db_cols)) !== false)
1451
+					if (($db_col = array_search($col, $this->db_cols)) !== false)
1452 1452
 					{
1453 1453
 						$cols[$db_col] = $col;
1454 1454
 					}
@@ -1461,10 +1461,10 @@  discard block
 block discarded – undo
1461 1461
 		}
1462 1462
 		if ($extra_cols)	// extra columns to report
1463 1463
 		{
1464
-			foreach(is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols) as $col)
1464
+			foreach (is_array($extra_cols) ? $extra_cols : explode(',', $extra_cols) as $col)
1465 1465
 			{
1466
-				if (stripos($col,'as ')!==false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1467
-				if (($db_col = array_search($col,$this->db_cols)) !== false)
1466
+				if (stripos($col, 'as ') !== false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i', '\\1', $col);
1467
+				if (($db_col = array_search($col, $this->db_cols)) !== false)
1468 1468
 				{
1469 1469
 					$cols[$db_col] = $col;
1470 1470
 				}
@@ -1491,12 +1491,12 @@  discard block
 block discarded – undo
1491 1491
 	 * @param string|array $extra_cols =array()
1492 1492
 	 * @return int total number of rows
1493 1493
 	 */
1494
-	function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array())
1494
+	function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array())
1495 1495
 	{
1496
-		unset($readonlys);	// required by function signature, but not used in this default implementation
1497
-		if ((int) $this->debug >= 4)
1496
+		unset($readonlys); // required by function signature, but not used in this default implementation
1497
+		if ((int)$this->debug >= 4)
1498 1498
 		{
1499
-			echo "<p>so_sql::get_rows(".print_r($query,true).",,)</p>\n";
1499
+			echo "<p>so_sql::get_rows(".print_r($query, true).",,)</p>\n";
1500 1500
 		}
1501 1501
 		$criteria = array();
1502 1502
 		$op = 'AND';
@@ -1504,11 +1504,11 @@  discard block
 block discarded – undo
1504 1504
 		{
1505 1505
 			$criteria = $query['search'];
1506 1506
 		}
1507
-		$rows = $this->search($criteria,$only_keys,$query['order']?$query['order'].' '.$query['sort']:'',$extra_cols,
1508
-			'',false,$op,$query['num_rows']?array((int)$query['start'],$query['num_rows']):(int)$query['start'],
1509
-			$query['col_filter'],$join,$need_full_no_count);
1507
+		$rows = $this->search($criteria, $only_keys, $query['order'] ? $query['order'].' '.$query['sort'] : '', $extra_cols,
1508
+			'', false, $op, $query['num_rows'] ? array((int)$query['start'], $query['num_rows']) : (int)$query['start'],
1509
+			$query['col_filter'], $join, $need_full_no_count);
1510 1510
 
1511
-		if (!$rows) $rows = array();	// otherwise false returned from search would be returned as array(false)
1511
+		if (!$rows) $rows = array(); // otherwise false returned from search would be returned as array(false)
1512 1512
 
1513 1513
 		return $this->total;
1514 1514
 	}
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
 	 * @param array $data =null data-set to check, defaults to $this->data
1520 1520
 	 * @return int 0: all keys are unique, 1: first key not unique, 2: ...
1521 1521
 	 */
1522
-	function not_unique($data=null)
1522
+	function not_unique($data = null)
1523 1523
 	{
1524 1524
 		if (!is_array($data))
1525 1525
 		{
@@ -1532,12 +1532,12 @@  discard block
 block discarded – undo
1532 1532
 		{
1533 1533
 			$uni_keys[] = $this->db_key_cols;
1534 1534
 		}
1535
-		foreach($uni_keys as $db_col => $col)
1535
+		foreach ($uni_keys as $db_col => $col)
1536 1536
 		{
1537 1537
 			if (is_array($col))
1538 1538
 			{
1539 1539
 				$query = array();
1540
-				foreach($col as $db_c => $c)
1540
+				foreach ($col as $db_c => $c)
1541 1541
 				{
1542 1542
 					$query[$db_c] = $data[$c];
1543 1543
 				}
@@ -1546,17 +1546,17 @@  discard block
 block discarded – undo
1546 1546
 			{
1547 1547
 				$query = array($db_col => $data[$col]);
1548 1548
 			}
1549
-			foreach($this->db->select($this->table_name,$this->db_key_cols,$query,__LINE__,__FILE__,false,'',$this->app) as $other)
1549
+			foreach ($this->db->select($this->table_name, $this->db_key_cols, $query, __LINE__, __FILE__, false, '', $this->app) as $other)
1550 1550
 			{
1551
-				foreach($this->db_key_cols as $key_col)
1551
+				foreach ($this->db_key_cols as $key_col)
1552 1552
 				{
1553 1553
 					if ($data[$key_col] != $other[$key_col])
1554 1554
 					{
1555
-						if ((int) $this->debug >= 4)
1555
+						if ((int)$this->debug >= 4)
1556 1556
 						{
1557 1557
 							echo "<p>not_unique in ".array2string($col)." as for '$key_col': '${data[$key_col]}' != '${other[$key_col]}'</p>\n";
1558 1558
 						}
1559
-						return $n;	// different entry => $n not unique
1559
+						return $n; // different entry => $n not unique
1560 1560
 					}
1561 1561
 				}
1562 1562
 			}
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
 	 * @param string $order ='' order, default '' = same as (first) $value_col
1578 1578
 	 * @return array with key_col => value_col pairs or array if more then one value_col given (keys as in value_col)
1579 1579
 	 */
1580
-	function query_list($value_col,$key_col='',$filter=array(),$order='')
1580
+	function query_list($value_col, $key_col = '', $filter = array(), $order = '')
1581 1581
 	{
1582 1582
 		static $cache = array();
1583 1583
 
@@ -1590,16 +1590,16 @@  discard block
 block discarded – undo
1590 1590
 		if (!is_array($value_col)) $value_col = array($value_col);
1591 1591
 
1592 1592
 		$cols = $ret = array();
1593
-		foreach($value_col as $key => $col)
1593
+		foreach ($value_col as $key => $col)
1594 1594
 		{
1595 1595
 			$matches = null;
1596
-			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i',$col,$matches) ? $matches[1] : $col;
1596
+			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i', $col, $matches) ? $matches[1] : $col;
1597 1597
 		}
1598 1598
 		if (!$order) $order = current($cols);
1599 1599
 
1600
-		if (($search =& $this->search(array(),($key_col ? $key_col.',' : 'DISTINCT ').implode(',',$value_col),$order,'','',false,'AND',false,$filter)))
1600
+		if (($search = & $this->search(array(), ($key_col ? $key_col.',' : 'DISTINCT ').implode(',', $value_col), $order, '', '', false, 'AND', false, $filter)))
1601 1601
 		{
1602
-			if (preg_match('/AS ([a-z_0-9]+)$/i',$key_col,$matches))
1602
+			if (preg_match('/AS ([a-z_0-9]+)$/i', $key_col, $matches))
1603 1603
 			{
1604 1604
 				$key_col = $matches[1];
1605 1605
 			}
@@ -1607,12 +1607,12 @@  discard block
 block discarded – undo
1607 1607
 			{
1608 1608
 				$key_col = current($cols);
1609 1609
 			}
1610
-			foreach($search as $row)
1610
+			foreach ($search as $row)
1611 1611
 			{
1612 1612
 				if (count($cols) > 1)
1613 1613
 				{
1614 1614
 					$data = array();
1615
-					foreach($cols as $key => $col)
1615
+					foreach ($cols as $key => $col)
1616 1616
 					{
1617 1617
 						$data[$key] = $row[$col];
1618 1618
 					}
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
 				if ($data) $ret[$row[$key_col]] = $data;
1625 1625
 			}
1626 1626
 		}
1627
-		return $cache[$cache_key] =& $ret;
1627
+		return $cache[$cache_key] = & $ret;
1628 1628
 	}
1629 1629
 
1630 1630
 	/**
@@ -1633,13 +1633,13 @@  discard block
 block discarded – undo
1633 1633
 	 * @param string $column =null name of column or null for all (default)
1634 1634
 	 * @return array|string array with internal-name => comment pairs, or string with comment, if $column given
1635 1635
 	 */
1636
-	public function get_comments($column=null)
1636
+	public function get_comments($column = null)
1637 1637
 	{
1638
-		static $comments=null;
1638
+		static $comments = null;
1639 1639
 
1640 1640
 		if (is_null($comments))
1641 1641
 		{
1642
-			foreach($this->db_cols as $db_col => $col)
1642
+			foreach ($this->db_cols as $db_col => $col)
1643 1643
 			{
1644 1644
 				$comments[$col] = $this->table_def['fd'][$db_col]['comment'];
1645 1645
 			}
Please login to merge, or discard this patch.
Braces   +193 added lines, -51 removed lines patch added patch discarded remove patch
@@ -182,7 +182,10 @@  discard block
 block discarded – undo
182 182
 	function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false,$timestamp_type=null)
183 183
 	{
184 184
 		// ease the transition to api
185
-		if ($app == 'phpgwapi') $app = 'api';
185
+		if ($app == 'phpgwapi')
186
+		{
187
+			$app = 'api';
188
+		}
186 189
 
187 190
 		if ($no_clone)
188 191
 		{
@@ -198,9 +201,15 @@  discard block
 block discarded – undo
198 201
 		{
199 202
 			$this->app = $app;
200 203
 
201
-			if (!$no_clone) $this->db->set_app($app);
204
+			if (!$no_clone)
205
+			{
206
+				$this->db->set_app($app);
207
+			}
202 208
 
203
-			if ($table) $this->setup_table($app,$table,$column_prefix);
209
+			if ($table)
210
+			{
211
+				$this->setup_table($app,$table,$column_prefix);
212
+			}
204 213
 		}
205 214
 		$this->init();
206 215
 
@@ -221,7 +230,10 @@  discard block
 block discarded – undo
221 230
 	 */
222 231
 	public function set_times($timestamp_type=false)
223 232
 	{
224
-		if ($timestamp_type !== false) $this->timestamp_type = $timestamp_type;
233
+		if ($timestamp_type !== false)
234
+		{
235
+			$this->timestamp_type = $timestamp_type;
236
+		}
225 237
 
226 238
 		// set current time
227 239
 		switch($this->timestamp_type)
@@ -279,7 +291,10 @@  discard block
 block discarded – undo
279 291
 			{
280 292
 				$this->autoinc_id = $col;
281 293
 			}
282
-			if ($def['type'] == 'bool') $this->has_bools = true;
294
+			if ($def['type'] == 'bool')
295
+			{
296
+				$this->has_bools = true;
297
+			}
283 298
 
284 299
 			foreach($this->table_def['uc'] as $k => $uni_index)
285 300
 			{
@@ -318,7 +333,10 @@  discard block
 block discarded – undo
318 333
 	 */
319 334
 	function data_merge($new)
320 335
 	{
321
-		if ((int) $this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
336
+		if ((int) $this->debug >= 4)
337
+		{
338
+			echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
339
+		}
322 340
 
323 341
 		if (!is_array($new) || !count($new))
324 342
 		{
@@ -342,7 +360,10 @@  discard block
 block discarded – undo
342 360
 		{
343 361
 			$this->data[self::USER_TIMEZONE_READ] = $new[self::USER_TIMEZONE_READ];
344 362
 		}
345
-		if ((int) $this->debug >= 4) _debug_array($this->data);
363
+		if ((int) $this->debug >= 4)
364
+		{
365
+			_debug_array($this->data);
366
+		}
346 367
 	}
347 368
 
348 369
 	/**
@@ -486,7 +507,10 @@  discard block
 block discarded – undo
486 507
 		if (!is_array($keys))
487 508
 		{
488 509
 			$pk = array_values($this->db_key_cols);
489
-			if ($pk) $keys = array($pk[0] => $keys);
510
+			if ($pk)
511
+			{
512
+				$keys = array($pk[0] => $keys);
513
+			}
490 514
 		}
491 515
 
492 516
 		$this->init($keys);
@@ -500,13 +524,16 @@  discard block
 block discarded – undo
500 524
 				$query[$db_col] = $this->data[$col];
501 525
 			}
502 526
 		}
503
-		if (!$query)	// no primary key in keys, lets try the data_cols for a unique key
527
+		if (!$query)
528
+		{
529
+			// no primary key in keys, lets try the data_cols for a unique key
504 530
 		{
505 531
 			foreach($this->db_uni_cols as $db_col => $col)
506 532
 			{
507 533
 				if (!is_array($col) && $this->data[$col] != '')
508 534
 				{
509 535
 					$query[$db_col] = $this->data[$col];
536
+		}
510 537
 				}
511 538
 				elseif(is_array($col))
512 539
 				{
@@ -520,31 +547,43 @@  discard block
 block discarded – undo
520 547
 						}
521 548
 						$q[$db_c] = $this->data[$c];
522 549
 					}
523
-					if ($q) $query += $q;
550
+					if ($q)
551
+					{
552
+						$query += $q;
553
+					}
524 554
 				}
525 555
 			}
526 556
 		}
527
-		if (!$query)	// no unique key in keys, lets try everything else
557
+		if (!$query)
558
+		{
559
+			// no unique key in keys, lets try everything else
528 560
 		{
529 561
 			foreach($this->db_data_cols as $db_col => $col)
530 562
 			{
531 563
 				if ($this->data[$col] != '')
532 564
 				{
533 565
 					$query[$db_col] = $this->data[$col];
566
+		}
534 567
 				}
535 568
 			}
536 569
 		}
537
-		if (!$query)	// keys has no cols
570
+		if (!$query)
571
+		{
572
+			// keys has no cols
538 573
 		{
539 574
 			$this->db2data();
575
+		}
540 576
 
541 577
 			return False;
542 578
 		}
543
-		if ($join)	// Prefix the columns with the table-name, as they might exist in the join
579
+		if ($join)
580
+		{
581
+			// Prefix the columns with the table-name, as they might exist in the join
544 582
 		{
545 583
 			foreach($query as $col => $val)
546 584
 			{
547 585
 				if (is_int($col) || strpos($join,$col) === false) continue;
586
+		}
548 587
 				$query[] = $this->db->expression($this->table_name,$this->table_name.'.',array($col=>$val));
549 588
 				unset($query[$col]);
550 589
 			}
@@ -553,11 +592,14 @@  discard block
 block discarded – undo
553 592
 			$query,__LINE__,__FILE__,False,'',$this->app,0,$join) as $row)
554 593
 		{
555 594
 			$cols = $this->db_cols;
556
-			if ($extra_cols)	// extra columns to report
595
+			if ($extra_cols)
596
+			{
597
+				// extra columns to report
557 598
 			{
558 599
 				foreach(is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
559 600
 				{
560 601
 					if (FALSE!==stripos($col,' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i','\\1',$col);
602
+			}
561 603
 					$cols[$col] = $col;
562 604
 				}
563 605
 			}
@@ -580,7 +622,10 @@  discard block
 block discarded – undo
580 622
 		{
581 623
 			unset($this->data[$this->db_key_cols[$this->autoinc_id]]);
582 624
 		}
583
-		if ((int) $this->debug >= 4) echo "nothing found !!!</p>\n";
625
+		if ((int) $this->debug >= 4)
626
+		{
627
+			echo "nothing found !!!</p>\n";
628
+		}
584 629
 
585 630
 		$this->db2data();
586 631
 
@@ -596,7 +641,10 @@  discard block
 block discarded – undo
596 641
 	 */
597 642
 	function save($keys=null,$extra_where=null)
598 643
 	{
599
-		if (is_array($keys) && count($keys)) $this->data_merge($keys);
644
+		if (is_array($keys) && count($keys))
645
+		{
646
+			$this->data_merge($keys);
647
+		}
600 648
 
601 649
 		// check if data contains user timezone during read AND user changed timezone since then
602 650
 		// --> load old timezone for the rest of this request
@@ -613,9 +661,13 @@  discard block
 block discarded – undo
613 661
 		}
614 662
 		$this->data2db();
615 663
 
616
-		if ((int) $this->debug >= 4) { echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
664
+		if ((int) $this->debug >= 4)
665
+		{
666
+echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
617 667
 
618
-		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])	// insert with auto id
668
+		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])
669
+		{
670
+			// insert with auto id
619 671
 		{
620 672
 			foreach($this->db_cols as $db_col => $col)
621 673
 			{
@@ -625,7 +677,9 @@  discard block
 block discarded – undo
625 677
 						(isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value
626 678
 						 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
627 679
 					{
628
-						continue;	// no need to write that (unset) column
680
+						continue;
681
+		}
682
+		// no need to write that (unset) column
629 683
 					}
630 684
 					if ($this->table_def['fd'][$db_col]['type'] == 'varchar' &&
631 685
 						strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision'])
@@ -656,9 +710,13 @@  discard block
 block discarded – undo
656 710
 				if (!array_key_exists($col,$this->data) &&	// handling of unset columns in $this->data
657 711
 					($this->autoinc_id ||			// update of table with auto id or
658 712
 					 isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value or
659
-					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
713
+					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))
660 714
 				{
661
-					continue;	// no need to write that (unset) column
715
+					// column is nullable
716
+				{
717
+					continue;
718
+				}
719
+				// no need to write that (unset) column
662 720
 				}
663 721
 				$data[$db_col] = !is_object($this->data[$col]) && (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
664 722
 			}
@@ -675,9 +733,12 @@  discard block
 block discarded – undo
675 733
 			{
676 734
 				$keys[$db_col] = $this->data[$col];
677 735
 			}
678
-			if (!$data && !$this->autoinc_id)	// happens if all columns are in the primary key
736
+			if (!$data && !$this->autoinc_id)
737
+			{
738
+				// happens if all columns are in the primary key
679 739
 			{
680 740
 				$data = $keys;
741
+			}
681 742
 				$keys = False;
682 743
 			}
683 744
 			if ($this->autoinc_id)
@@ -708,7 +769,10 @@  discard block
 block discarded – undo
708 769
 	 */
709 770
 	function update($_fields,$merge=true)
710 771
 	{
711
-		if ($merge) $this->data_merge($_fields);
772
+		if ($merge)
773
+		{
774
+			$this->data_merge($_fields);
775
+		}
712 776
 
713 777
 		$fields = $this->data2db($_fields);
714 778
 
@@ -761,9 +825,12 @@  discard block
 block discarded – undo
761 825
 		{
762 826
 			$keys = array($this->autoinc_id => $keys);
763 827
 		}
764
-		if (!is_array($keys) || !count($keys))	// use internal data
828
+		if (!is_array($keys) || !count($keys))
829
+		{
830
+			// use internal data
765 831
 		{
766 832
 			$data = $this->data;
833
+		}
767 834
 			$keys = $this->db_key_cols;
768 835
 		}
769 836
 		else	// data and keys are supplied in $keys
@@ -783,7 +850,10 @@  discard block
 block discarded – undo
783 850
 		{
784 851
 			$query[$db_col] = $data[$col];
785 852
 		}
786
-		if ($only_return_query) return $query;
853
+		if ($only_return_query)
854
+		{
855
+			return $query;
856
+		}
787 857
 
788 858
 		$this->db->delete($this->table_name,$query,__LINE__,__FILE__,$this->app);
789 859
 
@@ -816,7 +886,10 @@  discard block
 block discarded – undo
816 886
 	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
817 887
 	{
818 888
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
819
-		if ((int) $this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
889
+		if ((int) $this->debug >= 4)
890
+		{
891
+			echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
892
+		}
820 893
 
821 894
 		// if extending class or instanciator set columns to search, convert string criteria to array
822 895
 		if ($criteria && !is_array($criteria))
@@ -880,9 +953,12 @@  discard block
 block discarded – undo
880 953
 								($negate ? ') ' : '');
881 954
 						}
882 955
 					}
883
-					elseif (strpos($db_col,'.') !== false)	// we have a table-name specified
956
+					elseif (strpos($db_col,'.') !== false)
957
+					{
958
+						// we have a table-name specified
884 959
 					{
885 960
 						list($table,$only_col) = explode('.',$db_col);
961
+					}
886 962
 						$type = $this->db->get_column_attribute($only_col, $table, true, 'type');
887 963
 						if (empty($type))
888 964
 						{
@@ -907,13 +983,17 @@  discard block
 block discarded – undo
907 983
 					}
908 984
 				}
909 985
 			}
910
-			if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query);
986
+			if (is_array($query) && $op != 'AND')
987
+			{
988
+				$query = $this->db->column_data_implode(' '.$op.' ',$query);
989
+			}
911 990
 		}
912 991
 		if (is_array($filter))
913 992
 		{
914 993
 			$db_filter = array();
915 994
 			$data2db_filter = $this->data2db($filter);
916
-			if (!is_array($data2db_filter)) {
995
+			if (!is_array($data2db_filter))
996
+			{
917 997
 				echo function_backtrace()."<br/>\n";
918 998
 				echo "filter=";_debug_array($filter);
919 999
 				echo "data2db(filter)=";_debug_array($data2db_filter);
@@ -1009,7 +1089,10 @@  discard block
 block discarded – undo
1009 1089
 			}
1010 1090
 		}
1011 1091
 		$num_rows = 0;	// as spec. in max_matches in the user-prefs
1012
-		if (is_array($start)) list($start,$num_rows) = $start;
1092
+		if (is_array($start))
1093
+		{
1094
+			list($start,$num_rows) = $start;
1095
+		}
1013 1096
 
1014 1097
 		// fix GROUP BY clause to contain all non-aggregate selected columns
1015 1098
 		if ($order_by && stripos($order_by,'GROUP BY') !== false)
@@ -1037,18 +1120,24 @@  discard block
 block discarded – undo
1037 1120
 					'append' => $order_by,
1038 1121
 					'join'   => $join,
1039 1122
 				);
1040
-				if (!$union_cols)	// union used the colum-names of the first query
1123
+				if (!$union_cols)
1124
+				{
1125
+					// union used the colum-names of the first query
1041 1126
 				{
1042 1127
 					$union_cols = $this->_get_columns($only_keys,$extra_cols);
1043 1128
 				}
1129
+				}
1044 1130
 				return true;	// waiting for further calls, before running the union-query
1045 1131
 			}
1046 1132
 			// running the union query now
1047
-			if ($start !== false)	// need to get the total too, saved in $this->total
1133
+			if ($start !== false)
1134
+			{
1135
+				// need to get the total too, saved in $this->total
1048 1136
 			{
1049 1137
 				if ($this->db->Type == 'mysql' && $this->db->ServerInfo['version'] >= 4.0)
1050 1138
 				{
1051 1139
 					$union[0]['cols'] = ($mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ').$union[0]['cols'];
1140
+			}
1052 1141
 				}
1053 1142
 				else	// cant do a count, have to run the query without limit
1054 1143
 				{
@@ -1056,18 +1145,24 @@  discard block
 block discarded – undo
1056 1145
 				}
1057 1146
 			}
1058 1147
 			$rs = $this->db->union($union,__LINE__,__FILE__,$order_by,$start,$num_rows);
1059
-			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1148
+			if ($this->debug)
1149
+			{
1150
+				error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1151
+			}
1060 1152
 
1061 1153
 			$cols = $union_cols;
1062 1154
 			$union = $union_cols = array();
1063 1155
 		}
1064 1156
 		else	// no UNION
1065 1157
 		{
1066
-			if ($start !== false)	// need to get the total too, saved in $this->total
1158
+			if ($start !== false)
1159
+			{
1160
+				// need to get the total too, saved in $this->total
1067 1161
 			{
1068 1162
 				if ($this->db->Type == 'mysql' && $this->db->ServerInfo['version'] >= 4.0)
1069 1163
 				{
1070 1164
 					$mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ';
1165
+			}
1071 1166
 				}
1072 1167
 				elseif (!$need_full_no_count && (!$join || stripos($join,'LEFT JOIN')!==false))
1073 1168
 				{
@@ -1080,10 +1175,16 @@  discard block
 block discarded – undo
1080 1175
 			}
1081 1176
 			$rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__,
1082 1177
 				$start,$order_by,$this->app,$num_rows,$join);
1083
-			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1178
+			if ($this->debug)
1179
+			{
1180
+				error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1181
+			}
1084 1182
 			$cols = $this->_get_columns($only_keys,$extra_cols);
1085 1183
 		}
1086
-		if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1184
+		if ((int) $this->debug >= 4)
1185
+		{
1186
+			echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1187
+		}
1087 1188
 
1088 1189
 		if ($mysql_calc_rows)
1089 1190
 		{
@@ -1096,9 +1197,12 @@  discard block
 block discarded – undo
1096 1197
 		}
1097 1198
 		$arr = array();
1098 1199
 		$n = 0;
1099
-		if ($rs) foreach($rs as $row)
1200
+		if ($rs)
1201
+		{
1202
+			foreach($rs as $row)
1100 1203
 		{
1101 1204
 			$data = array();
1205
+		}
1102 1206
 			foreach($cols as $db_col => $col)
1103 1207
 			{
1104 1208
 				$data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]);
@@ -1166,9 +1270,15 @@  discard block
 block discarded – undo
1166 1270
 					$col = substr($col, $pos+9);
1167 1271
 				}
1168 1272
 				$alias = $col;
1169
-				if (stripos($col, ' AS ')) list($col, $alias) = preg_split('/ +AS +/i', $col);
1273
+				if (stripos($col, ' AS '))
1274
+				{
1275
+					list($col, $alias) = preg_split('/ +AS +/i', $col);
1276
+				}
1170 1277
 				// do NOT group by constant expressions
1171
-				if (preg_match('/^ *(-?[0-9]+|".*"|\'.*\'|NULL) *$/i', $col)) continue;
1278
+				if (preg_match('/^ *(-?[0-9]+|".*"|\'.*\'|NULL) *$/i', $col))
1279
+				{
1280
+					continue;
1281
+				}
1172 1282
 				if (!in_array($col, $group_by_cols) && !in_array($alias, $group_by_cols))
1173 1283
 				{
1174 1284
 					// instead of aliased primary key, we have to use original column incl. table-name as alias is ambigues
@@ -1201,7 +1311,10 @@  discard block
 block discarded – undo
1201 1311
 	{
1202 1312
 		$pattern = trim($_pattern);
1203 1313
 		// This function can get called multiple times.  Make sure it doesn't re-process.
1204
-		if (empty($pattern) || is_array($pattern)) return $pattern;
1314
+		if (empty($pattern) || is_array($pattern))
1315
+		{
1316
+			return $pattern;
1317
+		}
1205 1318
 		if(strpos($pattern, 'CAST(COALESCE(') !== false)
1206 1319
 		{
1207 1320
 			return $pattern;
@@ -1271,7 +1384,7 @@  discard block
 block discarded – undo
1271 1384
 			{
1272 1385
 				$token = substr($token, 1,strlen($token));
1273 1386
  				if(substr($token, -1) != '"')
1274
-				{
1387
+ 				{
1275 1388
 					$token .= ' '.strtok('"');
1276 1389
 				}
1277 1390
 				else
@@ -1387,7 +1500,8 @@  discard block
 block discarded – undo
1387 1500
 			foreach($search_cols as $key => &$col)
1388 1501
 			{
1389 1502
 				// If the name as given isn't a real column name, and adding the prefix doesn't help, skip it
1390
-				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1503
+				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols)))
1504
+				{
1391 1505
 					// Can't search this column
1392 1506
 					unset($search_cols[$key]);
1393 1507
 					continue;
@@ -1421,10 +1535,13 @@  discard block
 block discarded – undo
1421 1535
 	function _get_columns($only_keys,$extra_cols)
1422 1536
 	{
1423 1537
 		//echo "_get_columns() only_keys="; _debug_array($only_keys); echo "extra_cols="; _debug_array($extra_cols);
1424
-		if ($only_keys === true)	// only primary key
1538
+		if ($only_keys === true)
1539
+		{
1540
+			// only primary key
1425 1541
 		{
1426 1542
 			$cols = $this->db_key_cols;
1427 1543
 		}
1544
+		}
1428 1545
 		else
1429 1546
 		{
1430 1547
 			$cols = array();
@@ -1433,18 +1550,27 @@  discard block
 block discarded – undo
1433 1550
 			{
1434 1551
 				if (!$distinct_checked)
1435 1552
 				{
1436
-					if (stripos($col, 'DISTINCT ') === 0) $col = substr($col, 9);
1553
+					if (stripos($col, 'DISTINCT ') === 0)
1554
+					{
1555
+						$col = substr($col, 9);
1556
+					}
1437 1557
 					$distinct_checked = true;
1438 1558
 				}
1439
-				if (!$col || $col == '*' || $col == $this->table_name.'.*')	// all columns
1559
+				if (!$col || $col == '*' || $col == $this->table_name.'.*')
1560
+				{
1561
+					// all columns
1440 1562
 				{
1441 1563
 					$cols = array_merge($cols,$this->db_cols);
1442 1564
 				}
1565
+				}
1443 1566
 				else	// only the specified columns
1444 1567
 				{
1445
-					if (stripos($col,'as'))	// if there's already an explicit naming of the column, just use it
1568
+					if (stripos($col,'as'))
1569
+					{
1570
+						// if there's already an explicit naming of the column, just use it
1446 1571
 					{
1447 1572
 						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1573
+					}
1448 1574
 						$cols[$col] = $col;
1449 1575
 						continue;
1450 1576
 					}
@@ -1459,11 +1585,14 @@  discard block
 block discarded – undo
1459 1585
 				}
1460 1586
 			}
1461 1587
 		}
1462
-		if ($extra_cols)	// extra columns to report
1588
+		if ($extra_cols)
1589
+		{
1590
+			// extra columns to report
1463 1591
 		{
1464 1592
 			foreach(is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols) as $col)
1465 1593
 			{
1466 1594
 				if (stripos($col,'as ')!==false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1595
+		}
1467 1596
 				if (($db_col = array_search($col,$this->db_cols)) !== false)
1468 1597
 				{
1469 1598
 					$cols[$db_col] = $col;
@@ -1508,7 +1637,11 @@  discard block
 block discarded – undo
1508 1637
 			'',false,$op,$query['num_rows']?array((int)$query['start'],$query['num_rows']):(int)$query['start'],
1509 1638
 			$query['col_filter'],$join,$need_full_no_count);
1510 1639
 
1511
-		if (!$rows) $rows = array();	// otherwise false returned from search would be returned as array(false)
1640
+		if (!$rows)
1641
+		{
1642
+			$rows = array();
1643
+		}
1644
+		// otherwise false returned from search would be returned as array(false)
1512 1645
 
1513 1646
 		return $this->total;
1514 1647
 	}
@@ -1587,7 +1720,10 @@  discard block
 block discarded – undo
1587 1720
 		{
1588 1721
 			return $cache[$cache_key];
1589 1722
 		}
1590
-		if (!is_array($value_col)) $value_col = array($value_col);
1723
+		if (!is_array($value_col))
1724
+		{
1725
+			$value_col = array($value_col);
1726
+		}
1591 1727
 
1592 1728
 		$cols = $ret = array();
1593 1729
 		foreach($value_col as $key => $col)
@@ -1595,7 +1731,10 @@  discard block
 block discarded – undo
1595 1731
 			$matches = null;
1596 1732
 			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i',$col,$matches) ? $matches[1] : $col;
1597 1733
 		}
1598
-		if (!$order) $order = current($cols);
1734
+		if (!$order)
1735
+		{
1736
+			$order = current($cols);
1737
+		}
1599 1738
 
1600 1739
 		if (($search =& $this->search(array(),($key_col ? $key_col.',' : 'DISTINCT ').implode(',',$value_col),$order,'','',false,'AND',false,$filter)))
1601 1740
 		{
@@ -1621,7 +1760,10 @@  discard block
 block discarded – undo
1621 1760
 				{
1622 1761
 					$data = $row[current($cols)];
1623 1762
 				}
1624
-				if ($data) $ret[$row[$key_col]] = $data;
1763
+				if ($data)
1764
+				{
1765
+					$ret[$row[$key_col]] = $data;
1766
+				}
1625 1767
 			}
1626 1768
 		}
1627 1769
 		return $cache[$cache_key] =& $ret;
Please login to merge, or discard this patch.
api/src/Storage/Customfields.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@
 block discarded – undo
159 159
 	 * @param string $app
160 160
 	 * @param boolean $all_private_too =false should all the private fields be returned too, default no
161 161
 	 * @param string $only_type2 =null if given only return fields of type2 == $only_type2
162
-	 * @return boolen true: if there is a custom field useing html, false if not
162
+	 * @return boolean true: if there is a custom field useing html, false if not
163 163
 	 */
164 164
 	public static function use_html($app, $all_private_too=false, $only_type2=null)
165 165
 	{
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @var boolean
44 44
 	 */
45
-	protected $all_private_too=false;
45
+	protected $all_private_too = false;
46 46
 
47 47
 	/**
48 48
 	 * Iterator initialised for custom fields
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param Api\Db $db =null reference to database instance to use
63 63
 	 * @return array with customfields
64 64
 	 */
65
-	function __construct($app, $all_private_too=false, $only_type2=null, $start=0, $num_rows=null, Api\Db $db=null)
65
+	function __construct($app, $all_private_too = false, $only_type2 = null, $start = 0, $num_rows = null, Api\Db $db = null)
66 66
 	{
67 67
 		$this->app = $app;
68 68
 		$this->all_private_too = $all_private_too;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	protected function commasep_match($column, $values)
117 117
 	{
118 118
 		$to_or = array($column.' IS NULL');
119
-		foreach((array) $values as $value)
119
+		foreach ((array)$values as $value)
120 120
 		{
121 121
 			$to_or[] = self::$db->concat("','", $column, "','").' LIKE '.self::$db->quote('%,'.$value.',%');
122 122
 		}
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
 	 * @param Api\Db $db =null reference to database to use
133 133
 	 * @return array with customfields
134 134
 	 */
135
-	public static function get($app, $all_private_too=false, $only_type2=null, Api\Db $db=null)
135
+	public static function get($app, $all_private_too = false, $only_type2 = null, Api\Db $db = null)
136 136
 	{
137
-		$cache_key = $app.':'.($all_private_too?'all':$GLOBALS['egw_info']['user']['account_id']).':'.$only_type2;
137
+		$cache_key = $app.':'.($all_private_too ? 'all' : $GLOBALS['egw_info']['user']['account_id']).':'.$only_type2;
138 138
 		$cfs = Api\Cache::getInstance(__CLASS__, $cache_key);
139 139
 
140 140
 		if (!isset($cfs))
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 	 * @param string $only_type2 =null if given only return fields of type2 == $only_type2
162 162
 	 * @return boolen true: if there is a custom field useing html, false if not
163 163
 	 */
164
-	public static function use_html($app, $all_private_too=false, $only_type2=null)
164
+	public static function use_html($app, $all_private_too = false, $only_type2 = null)
165 165
 	{
166
-		foreach(self::get($app, $all_private_too, $only_type2) as $data)
166
+		foreach (self::get($app, $all_private_too, $only_type2) as $data)
167 167
 		{
168 168
 			if ($data['type'] == 'htmlarea') return true;
169 169
 		}
@@ -186,17 +186,17 @@  discard block
 block discarded – undo
186 186
 	 */
187 187
 	public static function format(array $field, $value)
188 188
 	{
189
-		switch($field['type'])
189
+		switch ($field['type'])
190 190
 		{
191 191
 			case 'select-account':
192 192
 				if ($value)
193 193
 				{
194 194
 					$values = array();
195
-					foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
195
+					foreach ($field['rows'] > 1 ? explode(',', $value) : (array)$value as $value)
196 196
 					{
197 197
 						$values[] = Api\Accounts::username($value);
198 198
 					}
199
-					$value = implode(', ',$values);
199
+					$value = implode(', ', $values);
200 200
 				}
201 201
 				break;
202 202
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 					$field['values'] = self::get_options_from_file($field['values']['@']);
212 212
 				}
213 213
 				$values = array();
214
-				foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
214
+				foreach ($field['rows'] > 1 ? explode(',', $value) : (array)$value as $value)
215 215
 				{
216 216
 					$values[] = isset($field['values'][$value]) ? $field['values'][$value] : '#'.$value;
217 217
 				}
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
 	{
276 276
 		$options = array();
277 277
 
278
-		if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) ||	// file does not exist
279
-			substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' ||	// we are NOT inside the eGW root
280
-			basename($path,'.php').'.php' != basename($path) ||	// extension is NOT .php
278
+		if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist
279
+			substr($path, 0, strlen(EGW_SERVER_ROOT) + 1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root
280
+			basename($path, '.php').'.php' != basename($path) || // extension is NOT .php
281 281
 			basename($path) == 'header.inc.php')	// dont allow to include our header again
282 282
 		{
283
-			return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT));
283
+			return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path, $file, EGW_SERVER_ROOT));
284 284
 		}
285 285
 		include($path);
286 286
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 
299 299
 		if (is_null($link_types))
300 300
 		{
301
-			$link_types = array_keys(array_intersect(Api\Link::app_list('query'),Api\Link::app_list('title')));
301
+			$link_types = array_keys(array_intersect(Api\Link::app_list('query'), Api\Link::app_list('title')));
302 302
 			$link_types[] = 'link-entry';
303 303
 		}
304 304
 		return $link_types;
@@ -315,31 +315,31 @@  discard block
 block discarded – undo
315 315
 	 * @param array $old =null old values before the update, if existing
316 316
 	 * @param string $id_name ='id' name/key of the (link-)id in $values
317 317
 	 */
318
-	public static function update_links($own_app,array $values,array $old=null,$id_name='id')
318
+	public static function update_links($own_app, array $values, array $old = null, $id_name = 'id')
319 319
 	{
320 320
 		$link_types = self::get_link_types();
321 321
 
322
-		foreach(self::get($own_app) as $name => $data)
322
+		foreach (self::get($own_app) as $name => $data)
323 323
 		{
324
-			if (!in_array($data['type'],$link_types)) continue;
324
+			if (!in_array($data['type'], $link_types)) continue;
325 325
 
326 326
 			// do we have a different old value --> delete that link
327 327
 			if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name])
328 328
 			{
329 329
 				if ($data['type'] == 'link-entry')
330 330
 				{
331
-					list($app,$id) = explode(':',$old['#'.$name]);
331
+					list($app, $id) = explode(':', $old['#'.$name]);
332 332
 				}
333 333
 				else
334 334
 				{
335 335
 					$app = $data['type'];
336 336
 					$id = $old['#'.$name];
337 337
 				}
338
-				Api\Link::unlink(false,$own_app,$values[$id_name],'',$app,$id);
338
+				Api\Link::unlink(false, $own_app, $values[$id_name], '', $app, $id);
339 339
 			}
340 340
 			if ($data['type'] == 'link-entry')
341 341
 			{
342
-				list($app,$id) = explode(':',$values['#'.$name]);
342
+				list($app, $id) = explode(':', $values['#'.$name]);
343 343
 			}
344 344
 			else
345 345
 			{
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			}
349 349
 			if ($id)	// create new link, does nothing for already existing links
350 350
 			{
351
-				Api\Link::link($own_app,$values[$id_name],$app,$id);
351
+				Api\Link::link($own_app, $values[$id_name], $app, $id);
352 352
 			}
353 353
 		}
354 354
 	}
@@ -369,25 +369,25 @@  discard block
 block discarded – undo
369 369
 		$old = $cfs[$cf['name']];
370 370
 
371 371
 		// Add new one in for numbering
372
-		if(!$cf['id'])
372
+		if (!$cf['id'])
373 373
 		{
374 374
 			$cfs[$cf['name']] = $cf;
375 375
 		}
376 376
 
377
-		if($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0)
377
+		if ($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0)
378 378
 		{
379 379
 			$cfs[$cf['name']]['order'] = $cf['order'];
380
-			uasort($cfs, function($a1, $a2){
380
+			uasort($cfs, function($a1, $a2) {
381 381
 				return $a1['order'] - $a2['order'];
382 382
 			});
383 383
 			$n = 0;
384
-			foreach($cfs as $old_cf)
384
+			foreach ($cfs as $old_cf)
385 385
 			{
386 386
 				$n += 10;
387
-				if($old_cf['order'] != $n)
387
+				if ($old_cf['order'] != $n)
388 388
 				{
389 389
 					$old_cf['order'] = $n;
390
-					if($old_cf['name'] != $cf['name'])
390
+					if ($old_cf['name'] != $cf['name'])
391 391
 					{
392 392
 						$update[] = $old_cf;
393 393
 					}
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 			'cf_app' => $cf['app'],
418 418
 		), __LINE__, __FILE__);
419 419
 
420
-		foreach($update as $old_cf)
420
+		foreach ($update as $old_cf)
421 421
 		{
422 422
 			self::$db->$op(self::TABLE, array(
423 423
 				'cf_order' => $old_cf['order'],
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 		if ($cfs) $query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs)));
443 443
 		self::$db->delete(self::TABLE, $query, __LINE__, __FILE__);
444 444
 
445
-		foreach($cfs as $name => $cf)
445
+		foreach ($cfs as $name => $cf)
446 446
 		{
447 447
 			if (empty($cf['name'])) $cf['name'] = $name;
448 448
 			if (empty($cf['app']))  $cf['app'] = $app;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	{
462 462
 		if (($cached = Api\Cache::getInstance(__CLASS__, $app)))
463 463
 		{
464
-			foreach($cached as $key)
464
+			foreach ($cached as $key)
465 465
 			{
466 466
 				Api\Cache::unsetInstance(__CLASS__, $key);
467 467
 			}
@@ -481,12 +481,12 @@  discard block
 block discarded – undo
481 481
 		$total = 0;
482 482
 		if (($cfs = self::get($app, true)))
483 483
 		{
484
-			foreach($cfs as &$data)
484
+			foreach ($cfs as &$data)
485 485
 			{
486 486
 				if ($data['private'])
487 487
 				{
488 488
 					$changed = 0;
489
-					foreach($data['private'] as &$id)
489
+					foreach ($data['private'] as &$id)
490 490
 					{
491 491
 						if (isset($ids2change[$id]))
492 492
 						{
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 		$types = array();
517 517
 		if (($cfs = self::get($app, true)))
518 518
 		{
519
-			foreach($cfs as $name => $data)
519
+			foreach ($cfs as $name => $data)
520 520
 			{
521 521
 				if ($data['type'] == 'select-account' || $data['type'] == 'api-accounts')
522 522
 				{
Please login to merge, or discard this patch.
Braces   +42 added lines, -11 removed lines patch added patch discarded remove patch
@@ -80,7 +80,10 @@  discard block
 block discarded – undo
80 80
 		{
81 81
 			$query[] = $this->commasep_match('cf_type2', $only_type2);
82 82
 		}
83
-		if (!$db) $db = self::$db;
83
+		if (!$db)
84
+		{
85
+			$db = self::$db;
86
+		}
84 87
 		$this->iterator = $db->select(self::TABLE, '*', $query, __LINE__, __FILE__,
85 88
 			!isset($num_rows) ? false : $start, 'ORDER BY cf_order ASC', 'phpgwapi', $num_rows);
86 89
 	}
@@ -165,7 +168,10 @@  discard block
 block discarded – undo
165 168
 	{
166 169
 		foreach(self::get($app, $all_private_too, $only_type2) as $data)
167 170
 		{
168
-			if ($data['type'] == 'htmlarea') return true;
171
+			if ($data['type'] == 'htmlarea')
172
+			{
173
+				return true;
174
+			}
169 175
 		}
170 176
 		return false;
171 177
 	}
@@ -227,7 +233,10 @@  discard block
 block discarded – undo
227 233
 				break;
228 234
 
229 235
 			case 'htmlarea':	// ToDo: EMail probably has a nicer html2text method
230
-				if ($value) $value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value)));
236
+				if ($value)
237
+				{
238
+					$value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value)));
239
+				}
231 240
 				break;
232 241
 
233 242
 			case 'ajax_select':	// ToDo: returns unchanged value for now
@@ -245,7 +254,10 @@  discard block
 block discarded – undo
245 254
 					{
246 255
 						$app = $field['type'];
247 256
 					}
248
-					if ($value) $value = Api\Link::title($app, $value);
257
+					if ($value)
258
+					{
259
+						$value = Api\Link::title($app, $value);
260
+					}
249 261
 				}
250 262
 				break;
251 263
 		}
@@ -278,10 +290,13 @@  discard block
 block discarded – undo
278 290
 		if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) ||	// file does not exist
279 291
 			substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' ||	// we are NOT inside the eGW root
280 292
 			basename($path,'.php').'.php' != basename($path) ||	// extension is NOT .php
281
-			basename($path) == 'header.inc.php')	// dont allow to include our header again
293
+			basename($path) == 'header.inc.php')
294
+		{
295
+			// dont allow to include our header again
282 296
 		{
283 297
 			return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT));
284 298
 		}
299
+		}
285 300
 		include($path);
286 301
 
287 302
 		return $options;
@@ -321,7 +336,10 @@  discard block
 block discarded – undo
321 336
 
322 337
 		foreach(self::get($own_app) as $name => $data)
323 338
 		{
324
-			if (!in_array($data['type'],$link_types)) continue;
339
+			if (!in_array($data['type'],$link_types))
340
+			{
341
+				continue;
342
+			}
325 343
 
326 344
 			// do we have a different old value --> delete that link
327 345
 			if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name])
@@ -346,10 +364,13 @@  discard block
 block discarded – undo
346 364
 				$app = $data['type'];
347 365
 				$id = $values['#'.$name];
348 366
 			}
349
-			if ($id)	// create new link, does nothing for already existing links
367
+			if ($id)
368
+			{
369
+				// create new link, does nothing for already existing links
350 370
 			{
351 371
 				Api\Link::link($own_app,$values[$id_name],$app,$id);
352 372
 			}
373
+			}
353 374
 		}
354 375
 	}
355 376
 
@@ -377,7 +398,8 @@  discard block
 block discarded – undo
377 398
 		if($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0)
378 399
 		{
379 400
 			$cfs[$cf['name']]['order'] = $cf['order'];
380
-			uasort($cfs, function($a1, $a2){
401
+			uasort($cfs, function($a1, $a2)
402
+			{
381 403
 				return $a1['order'] - $a2['order'];
382 404
 			});
383 405
 			$n = 0;
@@ -439,13 +461,22 @@  discard block
 block discarded – undo
439 461
 	public static function save($app, array $cfs)
440 462
 	{
441 463
 		$query = array('cf_app' => $app);
442
-		if ($cfs) $query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs)));
464
+		if ($cfs)
465
+		{
466
+			$query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs)));
467
+		}
443 468
 		self::$db->delete(self::TABLE, $query, __LINE__, __FILE__);
444 469
 
445 470
 		foreach($cfs as $name => $cf)
446 471
 		{
447
-			if (empty($cf['name'])) $cf['name'] = $name;
448
-			if (empty($cf['app']))  $cf['app'] = $app;
472
+			if (empty($cf['name']))
473
+			{
474
+				$cf['name'] = $name;
475
+			}
476
+			if (empty($cf['app']))
477
+			{
478
+				$cf['app'] = $app;
479
+			}
449 480
 
450 481
 			self::update($cf);
451 482
 		}
Please login to merge, or discard this patch.
api/src/Storage/History.php 3 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -112,6 +112,8 @@
 block discarded – undo
112 112
 
113 113
 	/**
114 114
 	 * Static function to add a history record
115
+	 * @param string $field_code
116
+	 * @param string $new_value
115 117
 	 */
116 118
 	public static function static_add($appname, $id, $user, $field_code, $new_value, $old_value = '')
117 119
 	{
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param string $appname app name this instance operates on
52 52
 	 * @return historylog
53 53
 	 */
54
-	function __construct($appname='',$user=null)
54
+	function __construct($appname = '', $user = null)
55 55
 	{
56 56
 		$this->appname = $appname ? $appname : $GLOBALS['egw_info']['flags']['currentapp'];
57 57
 		$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 		{
81 81
 			$where['history_record_id'] = $record_id;
82 82
 		}
83
-		$this->db->delete(self::TABLE,$where,__LINE__,__FILE__);
83
+		$this->db->delete(self::TABLE, $where, __LINE__, __FILE__);
84 84
 
85 85
 		return $this->db->affected_rows();
86 86
 	}
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 	 * @param string $new_value new value
94 94
 	 * @param string $old_value old value
95 95
 	 */
96
-	function add($status,$record_id,$new_value,$old_value)
96
+	function add($status, $record_id, $new_value, $old_value)
97 97
 	{
98 98
 		if ($new_value != $old_value)
99 99
 		{
100
-			$this->db->insert(self::TABLE,array(
100
+			$this->db->insert(self::TABLE, array(
101 101
 				'history_record_id' => $record_id,
102 102
 				'history_appname'   => $this->appname,
103 103
 				'history_owner'     => $this->user,
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 				'history_old_value' => $old_value,
107 107
 				'history_timestamp' => time(),
108 108
 				'sessionid' => $GLOBALS['egw']->session->sessionid_access_log,
109
-			),false,__LINE__,__FILE__);
109
+			), false, __LINE__, __FILE__);
110 110
 		}
111 111
 	}
112 112
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	{
118 118
 		if ($new_value != $old_value)
119 119
 		{
120
-			$GLOBALS['egw']->db->insert(self::TABLE,array(
120
+			$GLOBALS['egw']->db->insert(self::TABLE, array(
121 121
 				'history_record_id' => $id,
122 122
 				'history_appname'   => $appname,
123 123
 				'history_owner'     => (int)$user,
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 				'history_old_value' => $old_value,
127 127
 				'history_timestamp' => time(),
128 128
 				'sessionid' => $GLOBALS['egw']->session->sessionid_access_log,
129
-			),false,__LINE__,__FILE__);
129
+			), false, __LINE__, __FILE__);
130 130
 		}
131 131
 	}
132 132
 
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 	 * @return array of arrays with keys id, record_id, appname, owner (account_id), status, new_value, old_value,
141 141
 	 * 	timestamp (Y-m-d H:i:s in servertime), user_ts (timestamp in user-time)
142 142
 	 */
143
-	function search($filter,$order='history_id',$sort='DESC',$limit=null)
143
+	function search($filter, $order = 'history_id', $sort = 'DESC', $limit = null)
144 144
 	{
145 145
 		if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
146 146
 
147
-		if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort))
147
+		if (!$order || !preg_match('/^[a-z0-9_]+$/i', $order) || !preg_match('/^(asc|desc)?$/i', $sort))
148 148
 		{
149 149
 			$orderby = 'ORDER BY history_id DESC';
150 150
 		}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 		{
153 153
 			$orderby = "ORDER BY $order $sort";
154 154
 		}
155
-		foreach($filter as $col => $value)
155
+		foreach ($filter as $col => $value)
156 156
 		{
157
-			if (!is_numeric($col) && substr($col,0,8) != 'history_')
157
+			if (!is_numeric($col) && substr($col, 0, 8) != 'history_')
158 158
 			{
159 159
 				$filter['history_'.$col] = $value;
160 160
 				unset($filter[$col]);
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 		if (!$filter['history_record_id']) return array();
167 167
 
168 168
 		$rows = array();
169
-		foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
169
+		foreach ($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
170 170
 			isset($limit) ? 0 : false, $orderby, 'phpgwapi', $limit) as $row)
171 171
 		{
172 172
 			$row['user_ts'] = $this->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
173
-			$rows[] = Api\Db::strip_array_keys($row,'history_');
173
+			$rows[] = Api\Db::strip_array_keys($row, 'history_');
174 174
 		}
175 175
 		return $rows;
176 176
 	}
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 		$rows = array();
189 189
 		$filter['history_appname'] = $query['appname'];
190 190
 		$filter['history_record_id'] = $query['record_id'];
191
-		if(is_array($query['colfilter'])) {
192
-			foreach($query['colfilter'] as $column => $value) {
191
+		if (is_array($query['colfilter'])) {
192
+			foreach ($query['colfilter'] as $column => $value) {
193 193
 				$filter[$column] = $value;
194 194
 			}
195 195
 		}
@@ -199,20 +199,20 @@  discard block
 block discarded – undo
199 199
 		}
200 200
 		else
201 201
 		{
202
-			$total = $GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',$filter,__LINE__,__FILE__,false,'','phpgwapi',0)->fetchColumn();
202
+			$total = $GLOBALS['egw']->db->select(self::TABLE, 'COUNT(*)', $filter, __LINE__, __FILE__, false, '', 'phpgwapi', 0)->fetchColumn();
203 203
 		}
204 204
 		// filter out private (or no longer defined) custom fields
205 205
 		if ($filter['history_appname'])
206 206
 		{
207 207
 			$to_or[] = "history_status NOT LIKE '#%'";
208 208
 			// explicitly allow "##" used to store iCal/vCard X-attributes
209
-			if (in_array($filter['history_appname'], array('calendar','infolog','addressbook')))
209
+			if (in_array($filter['history_appname'], array('calendar', 'infolog', 'addressbook')))
210 210
 			{
211 211
 				$to_or[] = "history_status LIKE '##%'";
212 212
 			}
213 213
 			if (($cfs = Customfields::get($filter['history_appname'])))
214 214
 			{
215
-				$to_or[] =  'history_status IN ('.implode(',', array_map(function($str)
215
+				$to_or[] = 'history_status IN ('.implode(',', array_map(function($str)
216 216
 				{
217 217
 					return $GLOBALS['egw']->db->quote('#'.$str);
218 218
 				}, array_keys($cfs))).')';
@@ -221,25 +221,25 @@  discard block
 block discarded – undo
221 221
 		}
222 222
 		$_query = array(array(
223 223
 			'table' => self::TABLE,
224
-			'cols' => array('history_id', 'history_record_id','history_appname','history_owner','history_status','history_new_value', 'history_timestamp','history_old_value'),
224
+			'cols' => array('history_id', 'history_record_id', 'history_appname', 'history_owner', 'history_status', 'history_new_value', 'history_timestamp', 'history_old_value'),
225 225
 			'where' => $filter,
226 226
 		));
227 227
 
228 228
 		// Add in files, if possible
229
-		if($GLOBALS['egw_info']['user']['apps']['filemanager'] &&
230
-			$file = Api\Vfs\Sqlfs\StreamWrapper::url_stat("/apps/{$query['appname']}/{$query['record_id']}",STREAM_URL_STAT_LINK))
229
+		if ($GLOBALS['egw_info']['user']['apps']['filemanager'] &&
230
+			$file = Api\Vfs\Sqlfs\StreamWrapper::url_stat("/apps/{$query['appname']}/{$query['record_id']}", STREAM_URL_STAT_LINK))
231 231
 		{
232 232
 			$_query[] = array(
233 233
 				'table' => Api\Vfs\Sqlfs\StreamWrapper::TABLE,
234
-				'cols' =>array('fs_id', 'fs_dir', "'filemanager'",'COALESCE(fs_modifier,fs_creator)',"'~file~'",'fs_name','fs_modified', 'fs_mime'),
234
+				'cols' =>array('fs_id', 'fs_dir', "'filemanager'", 'COALESCE(fs_modifier,fs_creator)', "'~file~'", 'fs_name', 'fs_modified', 'fs_mime'),
235 235
 				'where' => array('fs_dir' => $file['ino'])
236 236
 			);
237 237
 		}
238 238
 		$new_file_id = array();
239
-		foreach($GLOBALS['egw']->db->union(
239
+		foreach ($GLOBALS['egw']->db->union(
240 240
 			$_query,
241 241
 			__LINE__, __FILE__,
242
-			' ORDER BY ' . ($query['order'] ? $query['order'] : 'history_timestamp') . ' ' . ($query['sort'] ? $query['sort'] : 'DESC'),
242
+			' ORDER BY '.($query['order'] ? $query['order'] : 'history_timestamp').' '.($query['sort'] ? $query['sort'] : 'DESC'),
243 243
 			$query['start'],
244 244
 			$query['num_rows']
245 245
 		) as $row)
@@ -247,15 +247,15 @@  discard block
 block discarded – undo
247 247
 			$row['user_ts'] = $GLOBALS['egw']->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
248 248
 
249 249
 			// Explode multi-part values
250
-			foreach(array('history_new_value','history_old_value') as $field)
250
+			foreach (array('history_new_value', 'history_old_value') as $field)
251 251
 			{
252
-				if(strpos($row[$field],Tracking::ONE2N_SEPERATOR) !== false)
252
+				if (strpos($row[$field], Tracking::ONE2N_SEPERATOR) !== false)
253 253
 				{
254
-					$row[$field] = explode(Tracking::ONE2N_SEPERATOR,$row[$field]);
254
+					$row[$field] = explode(Tracking::ONE2N_SEPERATOR, $row[$field]);
255 255
 				}
256 256
 			}
257 257
 			// Get information needed for proper display
258
-			if($row['history_appname'] == 'filemanager')
258
+			if ($row['history_appname'] == 'filemanager')
259 259
 			{
260 260
 				$new_version = $new_file_id[$row['history_new_value']];
261 261
 				$new_file_id[$row['history_new_value']] = count($rows);
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
 					'mime' => $row['history_old_value']
272 272
 				);
273 273
 				$row['history_old_value'] = '';
274
-				if($new_version !== null)
274
+				if ($new_version !== null)
275 275
 				{
276 276
 					$rows[$new_version]['old_value'] = $row['history_new_value'];
277 277
 				}
278 278
 			}
279
-			$rows[] = Api\Db::strip_array_keys($row,'history_');
279
+			$rows[] = Api\Db::strip_array_keys($row, 'history_');
280 280
 		}
281 281
 		if ($mysql_calc_rows)
282 282
 		{
Please login to merge, or discard this patch.
Braces   +16 added lines, -5 removed lines patch added patch discarded remove patch
@@ -142,7 +142,10 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	function search($filter,$order='history_id',$sort='DESC',$limit=null)
144 144
 	{
145
-		if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
145
+		if (!is_array($filter))
146
+		{
147
+			$filter = is_numeric($filter) ? array('history_record_id' => $filter) : array();
148
+		}
146 149
 
147 150
 		if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort))
148 151
 		{
@@ -160,10 +163,16 @@  discard block
 block discarded – undo
160 163
 				unset($filter[$col]);
161 164
 			}
162 165
 		}
163
-		if (!isset($filter['history_appname'])) $filter['history_appname'] = $this->appname;
166
+		if (!isset($filter['history_appname']))
167
+		{
168
+			$filter['history_appname'] = $this->appname;
169
+		}
164 170
 
165 171
 		// do not try to read all history entries of an app
166
-		if (!$filter['history_record_id']) return array();
172
+		if (!$filter['history_record_id'])
173
+		{
174
+			return array();
175
+		}
167 176
 
168 177
 		$rows = array();
169 178
 		foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__,
@@ -188,8 +197,10 @@  discard block
 block discarded – undo
188 197
 		$rows = array();
189 198
 		$filter['history_appname'] = $query['appname'];
190 199
 		$filter['history_record_id'] = $query['record_id'];
191
-		if(is_array($query['colfilter'])) {
192
-			foreach($query['colfilter'] as $column => $value) {
200
+		if(is_array($query['colfilter']))
201
+		{
202
+			foreach($query['colfilter'] as $column => $value)
203
+			{
193 204
 				$filter[$column] = $value;
194 205
 			}
195 206
 		}
Please login to merge, or discard this patch.
api/src/Storage/Merge.php 4 patches
Doc Comments   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
 	 *
369 369
 	 * Calls get_links() repeatedly to get all the combinations for the content.
370 370
 	 *
371
-	 * @param $app String appname
371
+	 * @param string $app String appname
372 372
 	 * @param $id String ID of record
373
-	 * @param $prefix
373
+	 * @param string $prefix
374 374
 	 * @param $content String document content
375 375
 	 */
376 376
 	protected function get_all_links($app, $id, $prefix, &$content)
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 	 * @param mixed $app_limit app_limit, if not set checks the global limit
531 531
 	 * @param string $checkas [AND|ISALLOWED], AND default; if set to ISALLOWED it is checked if Export is allowed
532 532
 	 *
533
-	 * @return bool - true if no export is allowed or a limit is set, false if there is no restriction
533
+	 * @return boolean|null - true if no export is allowed or a limit is set, false if there is no restriction
534 534
 	 */
535 535
 	public static function hasExportLimit($app_limit,$checkas='AND')
536 536
 	{
@@ -579,6 +579,9 @@  discard block
 block discarded – undo
579 579
 		return $content;
580 580
 	}
581 581
 
582
+	/**
583
+	 * @param string $mimetype
584
+	 */
582 585
 	protected function apply_styles (&$content, $mimetype, $mso_application_progid=null)
583 586
 	{
584 587
 		if (!isset($mso_application_progid))
@@ -1169,6 +1172,8 @@  discard block
 block discarded – undo
1169 1172
 
1170 1173
 	/**
1171 1174
 	 * Convert numeric values in spreadsheets into actual numeric values
1175
+	 * @param string $content
1176
+	 * @param string $mimetype
1172 1177
 	 */
1173 1178
 	protected function format_spreadsheet_numbers(&$content, $names, $mimetype)
1174 1179
 	{
@@ -1238,6 +1243,7 @@  discard block
 block discarded – undo
1238 1243
 
1239 1244
 	/**
1240 1245
 	 * Convert date / timestamp values in spreadsheets into actual date / timestamp values
1246
+	 * @param string $mimetype
1241 1247
 	 */
1242 1248
 	protected function format_spreadsheet_dates(&$content, $names, &$values, $mimetype)
1243 1249
 	{
@@ -1342,6 +1348,7 @@  discard block
 block discarded – undo
1342 1348
 	/**
1343 1349
 	 * Expand link_to custom fields with the merge replacements from the app
1344 1350
 	 * but only if the template uses them.
1351
+	 * @param string $app
1345 1352
 	 */
1346 1353
 	public function cf_link_to_expand($values, $content, &$replacements, $app = null)
1347 1354
 	{
@@ -1407,7 +1414,7 @@  discard block
 block discarded – undo
1407 1414
 	/**
1408 1415
 	 * Process special flags, such as IF or NELF
1409 1416
 	 *
1410
-	 * @param content Text to be examined and changed
1417
+	 * @param content string to be examined and changed
1411 1418
 	 * @param replacements array of markers => replacement
1412 1419
 	 *
1413 1420
 	 * @return changed content
@@ -1720,8 +1727,7 @@  discard block
 block discarded – undo
1720 1727
 	 * Get a list of document actions / files from the given directory
1721 1728
 	 *
1722 1729
 	 * @param string $dirs Directory(s comma or space separated) to search
1723
-	 * @param string $prefix='document_' prefix for array keys
1724
-	 * @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
1730
+	 * @param array|string $mime_filter allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
1725 1731
 	 * @return array List of documents, suitable for a selectbox.  The key is document_<filename>.
1726 1732
 	 */
1727 1733
 	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
@@ -1988,7 +1994,8 @@  discard block
 block discarded – undo
1988 1994
 	 *
1989 1995
 	 * @param string &$document maybe relative path of document, on return true absolute path to existing document
1990 1996
 	 * @param string $dirs comma or whitespace separated directories
1991
-	 * @return string|boolean false if document exists, otherwise string with error-message
1997
+	 * @param string $document
1998
+	 * @return false|string false if document exists, otherwise string with error-message
1992 1999
 	 */
1993 2000
 	public static function check_document(&$document, $dirs)
1994 2001
 	{
Please login to merge, or discard this patch.
Upper-Lower-Casing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1417,19 +1417,19 @@  discard block
 block discarded – undo
1417 1417
 		if (strpos($content,'$$IF') !== false)
1418 1418
 		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1419 1419
 			$this->replacements =& $replacements;
1420
-			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1420
+			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',array($this,'replace_callback'),$content);
1421 1421
 			unset($this->replacements);
1422 1422
 		}
1423 1423
 		if (strpos($content,'$$NELF') !== false)
1424 1424
 		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1425 1425
 			$this->replacements =& $replacements;
1426
-			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1426
+			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',array($this,'replace_callback'),$content);
1427 1427
 			unset($this->replacements);
1428 1428
 		}
1429 1429
 		if (strpos($content,'$$NENVLF') !== false)
1430 1430
 		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1431 1431
 			$this->replacements =& $replacements;
1432
-			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1432
+			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',array($this,'replace_callback'),$content);
1433 1433
 			unset($this->replacements);
1434 1434
 		}
1435 1435
 		if (strpos($content,'$$LETTERPREFIX$$') !== false)
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
 		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1441 1441
 		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1442 1442
 			$this->replacements =& $replacements;
1443
-			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1443
+			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',array($this,'replace_callback'),$content);
1444 1444
 			unset($this->replacements);
1445 1445
 		}
1446 1446
 		return $content;
@@ -1958,7 +1958,7 @@  discard block
 block discarded – undo
1958 1958
 	 * @param Array $file Array of information about the document from Api\Vfs::find
1959 1959
 	 * @return void
1960 1960
 	 */
1961
-	private static function document_mail_action(Array &$action, $file)
1961
+	private static function document_mail_action(array &$action, $file)
1962 1962
 	{
1963 1963
 		unset($action['postSubmit']);
1964 1964
 
Please login to merge, or discard this patch.
Braces   +278 added lines, -77 removed lines patch added patch discarded remove patch
@@ -168,19 +168,28 @@  discard block
 block discarded – undo
168 168
 		switch ($mimetype)
169 169
 		{
170 170
 			case 'application/msword':
171
-				if (strtolower($extension) != '.rtf') break;
171
+				if (strtolower($extension) != '.rtf')
172
+				{
173
+					break;
174
+				}
172 175
 			case 'application/rtf':
173 176
 			case 'text/rtf':
174 177
 				return true;	// rtf files
175 178
 			case 'application/vnd.oasis.opendocument.text':	// oo text
176 179
 			case 'application/vnd.oasis.opendocument.spreadsheet':	// oo spreadsheet
177
-				if (!$zip_available) break;
180
+				if (!$zip_available)
181
+				{
182
+					break;
183
+				}
178 184
 				return true;	// open office write xml files
179 185
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':	// ms word 2007 xml format
180 186
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d':	// mimetypes in vfs are limited to 64 chars
181 187
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':	// ms excel 2007 xml format
182 188
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee':
183
-				if (!$zip_available) break;
189
+				if (!$zip_available)
190
+				{
191
+					break;
192
+				}
184 193
 				return true;	// ms word xml format
185 194
 			case 'application/xml':
186 195
 				return true;	// alias for text/xml, eg. ms office 2003 word format
@@ -215,7 +224,10 @@  discard block
 block discarded – undo
215 224
 		{
216 225
 			$contact = $this->contacts->read($contact, $ignore_acl);
217 226
 		}
218
-		if (!is_array($contact)) return array();
227
+		if (!is_array($contact))
228
+		{
229
+			return array();
230
+		}
219 231
 
220 232
 		$replacements = array();
221 233
 		foreach(array_keys($this->contacts->contact_fields) as $name)
@@ -224,7 +236,10 @@  discard block
 block discarded – undo
224 236
 			switch($name)
225 237
 			{
226 238
 				case 'created': case 'modified':
227
-					if($value) $value = Api\DateTime::to($value);
239
+					if($value)
240
+					{
241
+						$value = Api\DateTime::to($value);
242
+					}
228 243
 					break;
229 244
 				case 'bday':
230 245
 					if ($value)
@@ -274,7 +289,10 @@  discard block
 block discarded – undo
274 289
 					}
275 290
 					break;
276 291
 			}
277
-			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
292
+			if ($name != 'photo')
293
+			{
294
+				$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
295
+			}
278 296
 		}
279 297
 		// set custom fields, should probably go to a general method all apps can use
280 298
 		// need to load all cfs for $ignore_acl=true
@@ -291,17 +309,23 @@  discard block
 block discarded – undo
291 309
 		$cats = array();
292 310
 		foreach(is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',',$contact['cat_id']) as $cat_id)
293 311
 		{
294
-			if(!$cat_id) continue;
312
+			if(!$cat_id)
313
+			{
314
+				continue;
315
+			}
295 316
 			if($GLOBALS['egw']->categories->id2name($cat_id,'main') != $cat_id)
296 317
 			{
297 318
 				$path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path'));
298 319
 				unset($path[0]); // Drop main
299 320
 				$cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path);
300
-			} elseif($cat_id) {
321
+			}
322
+			elseif($cat_id)
323
+			{
301 324
 				$cats[$cat_id] = array();
302 325
 			}
303 326
 		}
304
-		foreach($cats as $main => $cat) {
327
+		foreach($cats as $main => $cat)
328
+		{
305 329
 			$replacements['$$'.($prefix ? $prefix.'/':'').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main,'name')
306 330
 				. (count($cat) > 0 ? ': ' : '') . implode(', ', $cats[$main]) . "\n";
307 331
 		}
@@ -336,7 +360,10 @@  discard block
 block discarded – undo
336 360
 					'id'	=> $link_info
337 361
 				);
338 362
 			}
339
-			if($exclude && in_array($link_info['id'], $exclude)) continue;
363
+			if($exclude && in_array($link_info['id'], $exclude))
364
+			{
365
+				continue;
366
+			}
340 367
 
341 368
 			$title = Api\Link::title($link_info['app'], $link_info['id']);
342 369
 			if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
@@ -455,7 +482,10 @@  discard block
 block discarded – undo
455 482
 	protected function format_datetime($time,$format=null)
456 483
 	{
457 484
 		trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
458
-		if (is_null($format)) $format = $this->datetime_format;
485
+		if (is_null($format))
486
+		{
487
+			$format = $this->datetime_format;
488
+		}
459 489
 
460 490
 		return Api\DateTime::to($time,$format);
461 491
 	}
@@ -497,7 +527,10 @@  discard block
 block discarded – undo
497 527
 	public static function getExportLimit($app='common')
498 528
 	{
499 529
 		static $exportLimitStore=array();
500
-		if (empty($app)) $app='common';
530
+		if (empty($app))
531
+		{
532
+			$app='common';
533
+		}
501 534
 		//error_log(__METHOD__.__LINE__.' called with app:'.$app);
502 535
 		if (!array_key_exists($app,$exportLimitStore))
503 536
 		{
@@ -506,7 +539,10 @@  discard block
 block discarded – undo
506 539
 			if ($app !='common')
507 540
 			{
508 541
 				$app_limit = Api\Hooks::single('export_limit',$app);
509
-				if ($app_limit) $exportLimitStore[$app] = $app_limit;
542
+				if ($app_limit)
543
+				{
544
+					$exportLimitStore[$app] = $app_limit;
545
+				}
510 546
 			}
511 547
 			//error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]);
512 548
 			if (empty($exportLimitStore[$app]))
@@ -539,10 +575,22 @@  discard block
 block discarded – undo
539 575
 	 */
540 576
 	public static function hasExportLimit($app_limit,$checkas='AND')
541 577
 	{
542
-		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
543
-		if (empty($app_limit)) return false;
544
-		if ($app_limit == 'no') return true;
545
-		if ($app_limit > 0) return true;
578
+		if (strtoupper($checkas) == 'ISALLOWED')
579
+		{
580
+			return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
581
+		}
582
+		if (empty($app_limit))
583
+		{
584
+			return false;
585
+		}
586
+		if ($app_limit == 'no')
587
+		{
588
+			return true;
589
+		}
590
+		if ($app_limit > 0)
591
+		{
592
+			return true;
593
+		}
546 594
 	}
547 595
 
548 596
 	/**
@@ -577,7 +625,8 @@  discard block
 block discarded – undo
577 625
 
578 626
 		try {
579 627
 			$content = $this->merge_string($content,$ids,$err,$mimetype,$fix);
580
-		} catch (\Exception $e) {
628
+		}
629
+		catch (\Exception $e) {
581 630
 			$err = $e->getMessage();
582 631
 			return false;
583 632
 		}
@@ -666,7 +715,8 @@  discard block
 block discarded – undo
666 715
 			$content = $xslt->transformToXml($element);
667 716
 
668 717
 			// Word 2003 needs two declarations, add extra declaration back in
669
-			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
718
+			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0)
719
+			{
670 720
 				$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;
671 721
 			}
672 722
 			// Validate
@@ -726,7 +776,10 @@  discard block
 block discarded – undo
726 776
 			// textdocuments are simple, they do not hold start and end, but they may have content before and after the $$pagerepeat$$ tag
727 777
 			// header and footer should not hold any $$ tags; if we find $$ tags with the header, we assume it is the pagerepeatcontent
728 778
 			$nohead = false;
729
-			if (stripos($contentstart,'$$') !== false) $nohead = true;
779
+			if (stripos($contentstart,'$$') !== false)
780
+			{
781
+				$nohead = true;
782
+			}
730 783
 			if ($nohead)
731 784
 			{
732 785
 				$contentend = $contentrepeat;
@@ -768,13 +821,19 @@  discard block
 block discarded – undo
768 821
 		preg_match_all('/\$\$labelplacement\$\$/',$contentrepeat,$countlables, PREG_SPLIT_NO_EMPTY);
769 822
 		$countlables = count($countlables[0]);
770 823
 		preg_replace('/\$\$labelplacement\$\$/','',$Labelrepeat,1);
771
-		if ($countlables > 1) $lableprint = true;
824
+		if ($countlables > 1)
825
+		{
826
+			$lableprint = true;
827
+		}
772 828
 		if (count($ids) > 1 && !$contentrepeat)
773 829
 		{
774 830
 			$err = lang('for more than one contact in a document use the tag pagerepeat!');
775 831
 			return false;
776 832
 		}
777
-		if ($this->report_memory_usage) error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat));
833
+		if ($this->report_memory_usage)
834
+		{
835
+			error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat));
836
+		}
778 837
 
779 838
 		if ($contentrepeat)
780 839
 		{
@@ -807,8 +866,15 @@  discard block
 block discarded – undo
807 866
 		}
808 867
 		foreach ((array)$ids as $n => $id)
809 868
 		{
810
-			if ($contentrepeat) $content = $contentrepeat;   //content to repeat
811
-			if ($lableprint) $content = $Labelrepeat;
869
+			if ($contentrepeat)
870
+			{
871
+				$content = $contentrepeat;
872
+			}
873
+			//content to repeat
874
+			if ($lableprint)
875
+			{
876
+				$content = $Labelrepeat;
877
+			}
812 878
 
813 879
 			// generate replacements; if exeption is thrown, catch it set error message and return false
814 880
 			try
@@ -825,7 +891,10 @@  discard block
 block discarded – undo
825 891
 				$err = $e->getMessage();
826 892
 				return false;
827 893
 			}
828
-			if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
894
+			if ($this->report_memory_usage)
895
+			{
896
+				error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
897
+			}
829 898
 			// some general replacements: current user, date and time
830 899
 			if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')))
831 900
 			{
@@ -883,9 +952,12 @@  discard block
 block discarded – undo
883 952
 			{
884 953
 				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/',$Label,$contentrepeatpages[$countpage],1);
885 954
 				$count=$count+1;
886
-				if (($count % $countlables) == 0 && count($contentrep)>$count)  //new page
955
+				if (($count % $countlables) == 0 && count($contentrep)>$count)
956
+				{
957
+					//new page
887 958
 				{
888 959
 					$countpage = $countpage+1;
960
+				}
889 961
 					$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
890 962
 				}
891 963
 			}
@@ -916,7 +988,10 @@  discard block
 block discarded – undo
916 988
 			rewind($content_stream);
917 989
 			return stream_get_contents($content_stream);
918 990
 		}
919
-		if ($this->report_memory_usage) error_log(__METHOD__."() returning ".Api\Vfs::hsize(memory_get_peak_usage(true)));
991
+		if ($this->report_memory_usage)
992
+		{
993
+			error_log(__METHOD__."() returning ".Api\Vfs::hsize(memory_get_peak_usage(true)));
994
+		}
920 995
 
921 996
 		return $content;
922 997
 	}
@@ -959,7 +1034,10 @@  discard block
 block discarded – undo
959 1034
 				break;
960 1035
 
961 1036
 			default:	// div. text files --> use our export-charset, defined in addressbook prefs
962
-				if (empty($charset)) $charset = $this->contacts->prefs['csv_charset'];
1037
+				if (empty($charset))
1038
+				{
1039
+					$charset = $this->contacts->prefs['csv_charset'];
1040
+				}
963 1041
 				break;
964 1042
 		}
965 1043
 		//error_log(__METHOD__."('$document', ... ,$mimetype) --> $charset (egw=".Api\Translation::charset().', export='.$this->contacts->prefs['csv_charset'].')');
@@ -982,10 +1060,13 @@  discard block
 block discarded – undo
982 1060
 				}
983 1061
 			}
984 1062
 		}
985
-		if ($is_xml)	// zip'ed xml document (eg. OO)
1063
+		if ($is_xml)
1064
+		{
1065
+			// zip'ed xml document (eg. OO)
986 1066
 		{
987 1067
 			// Numeric fields
988 1068
 			$names = array();
1069
+		}
989 1070
 
990 1071
 			// Tags we can replace with the target document's version
991 1072
 			$replace_tags = array();
@@ -1047,7 +1128,8 @@  discard block
 block discarded – undo
1047 1128
 				else if (is_string($value) && (strpos($value,'<') !== false))
1048 1129
 				{
1049 1130
 					// Clean HTML, if it's being kept
1050
-					if($replace_tags && extension_loaded('tidy')) {
1131
+					if($replace_tags && extension_loaded('tidy'))
1132
+					{
1051 1133
 						$tidy = new tidy();
1052 1134
 						$cleaned = $tidy->repairString($value, self::$tidy_config);
1053 1135
 						// Found errors. Strip it all so there's some output
@@ -1081,16 +1163,20 @@  discard block
 block discarded – undo
1081 1163
 				// replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space
1082 1164
 				// as they are not allowed in xml
1083 1165
 				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u',' ',$value);
1084
-				if(is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1166
+				if(is_numeric($value) && $name != '$$user/account_id$$')
1167
+				{
1168
+					// account_id causes problems with the preg_replace below
1085 1169
 				{
1086 1170
 					$names[] = preg_quote($name,'/');
1087 1171
 				}
1172
+				}
1088 1173
 			}
1089 1174
 
1090 1175
 			// Look for numbers, set their value if needed
1091 1176
 			if($this->numeric_fields || count($names))
1092 1177
 			{
1093
-				foreach((array)$this->numeric_fields as $fieldname) {
1178
+				foreach((array)$this->numeric_fields as $fieldname)
1179
+				{
1094 1180
 					$names[] = preg_quote($fieldname,'/');
1095 1181
 				}
1096 1182
 				$this->format_spreadsheet_numbers($content, $names, $mimetype.$mso_application_progid);
@@ -1100,7 +1186,8 @@  discard block
 block discarded – undo
1100 1186
 			if($this->date_fields || count($names))
1101 1187
 			{
1102 1188
 				$names = array();
1103
-				foreach((array)$this->date_fields as $fieldname) {
1189
+				foreach((array)$this->date_fields as $fieldname)
1190
+				{
1104 1191
 					$names[] = $fieldname;
1105 1192
 				}
1106 1193
 				$this->format_spreadsheet_dates($content, $names, $replacements, $mimetype.$mso_application_progid);
@@ -1177,7 +1264,8 @@  discard block
 block discarded – undo
1177 1264
 	 */
1178 1265
 	protected function format_spreadsheet_numbers(&$content, $names, $mimetype)
1179 1266
 	{
1180
-		foreach((array)$this->numeric_fields as $fieldname) {
1267
+		foreach((array)$this->numeric_fields as $fieldname)
1268
+		{
1181 1269
 			$names[] = preg_quote($fieldname,'/');
1182 1270
 		}
1183 1271
 		switch($mimetype)
@@ -1206,7 +1294,11 @@  discard block
 block discarded – undo
1206 1294
 			// try to increase/double pcre.backtrack_limit failure
1207 1295
 			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1208 1296
 
1209
-			if ($result) $content = $result;  // On failure $result would be NULL
1297
+			if ($result)
1298
+			{
1299
+				$content = $result;
1300
+			}
1301
+			// On failure $result would be NULL
1210 1302
 		}
1211 1303
 	}
1212 1304
 
@@ -1250,7 +1342,10 @@  discard block
 block discarded – undo
1250 1342
 			'application/vnd.oasis.opendocument.spreadsheet',		// open office calc
1251 1343
 			'application/xmlExcel.Sheet',					// Excel 2003
1252 1344
 			//'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF
1253
-		))) return;
1345
+		)))
1346
+		{
1347
+			return;
1348
+		}
1254 1349
 
1255 1350
 		// Some different formats dates could be in, depending what they've been through
1256 1351
 		$formats = array(
@@ -1279,8 +1374,12 @@  discard block
 block discarded – undo
1279 1374
 								$values[$key],
1280 1375
 								Api\DateTime::$user_timezone
1281 1376
 							);
1282
-							if($date) break;
1283
-						} catch (\Exception $e) {
1377
+							if($date)
1378
+							{
1379
+								break;
1380
+							}
1381
+						}
1382
+						catch (\Exception $e) {
1284 1383
 
1285 1384
 						}
1286 1385
 					}
@@ -1296,9 +1395,12 @@  discard block
 block discarded – undo
1296 1395
 				{
1297 1396
 					$date = new Api\DateTime($values[$key]);
1298 1397
 				}
1299
-				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')//Excel WTF
1398
+				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
1399
+				{
1400
+					//Excel WTF
1300 1401
 				{
1301 1402
 					$interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
1403
+				}
1302 1404
 					$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
1303 1405
 					// 1440 minutes in a day - fractional part
1304 1406
 					$values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440;
@@ -1340,7 +1442,11 @@  discard block
 block discarded – undo
1340 1442
 			// try to increase/double pcre.backtrack_limit failure
1341 1443
 			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1342 1444
 
1343
-			if ($result) $content = $result;  // On failure $result would be NULL
1445
+			if ($result)
1446
+			{
1447
+				$content = $result;
1448
+			}
1449
+			// On failure $result would be NULL
1344 1450
 		}
1345 1451
 	}
1346 1452
 
@@ -1404,7 +1510,10 @@  discard block
 block discarded – undo
1404 1510
 			}
1405 1511
 			else
1406 1512
 			{
1407
-				if ($cfs[$field]['type'] == 'date' || $cfs[$field]['type'] == 'date-time') $this->date_fields[] = '#'.$field;
1513
+				if ($cfs[$field]['type'] == 'date' || $cfs[$field]['type'] == 'date-time')
1514
+				{
1515
+					$this->date_fields[] = '#'.$field;
1516
+				}
1408 1517
 			}
1409 1518
 		}
1410 1519
 	}
@@ -1420,30 +1529,35 @@  discard block
 block discarded – undo
1420 1529
 	private function process_commands($content, $replacements)
1421 1530
 	{
1422 1531
 		if (strpos($content,'$$IF') !== false)
1423
-		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1532
+		{
1533
+//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1424 1534
 			$this->replacements =& $replacements;
1425 1535
 			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1426 1536
 			unset($this->replacements);
1427 1537
 		}
1428 1538
 		if (strpos($content,'$$NELF') !== false)
1429
-		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1539
+		{
1540
+//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1430 1541
 			$this->replacements =& $replacements;
1431 1542
 			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1432 1543
 			unset($this->replacements);
1433 1544
 		}
1434 1545
 		if (strpos($content,'$$NENVLF') !== false)
1435
-		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1546
+		{
1547
+//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1436 1548
 			$this->replacements =& $replacements;
1437 1549
 			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1438 1550
 			unset($this->replacements);
1439 1551
 		}
1440 1552
 		if (strpos($content,'$$LETTERPREFIX$$') !== false)
1441
-		{	//Example use to use: $$LETTERPREFIX$$
1553
+		{
1554
+//Example use to use: $$LETTERPREFIX$$
1442 1555
 			$LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$';
1443 1556
 			$content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content);
1444 1557
 		}
1445 1558
 		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1446
-		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1559
+		{
1560
+//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1447 1561
 			$this->replacements =& $replacements;
1448 1562
 			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1449 1563
 			unset($this->replacements);
@@ -1459,8 +1573,14 @@  discard block
 block discarded – undo
1459 1573
 	 */
1460 1574
 	private function replace_callback($param)
1461 1575
 	{
1462
-		if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1463
-		if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1576
+		if (array_key_exists('$$'.$param[4].'$$',$this->replacements))
1577
+		{
1578
+			$param[4] = $this->replacements['$$'.$param[4].'$$'];
1579
+		}
1580
+		if (array_key_exists('$$'.$param[3].'$$',$this->replacements))
1581
+		{
1582
+			$param[3] = $this->replacements['$$'.$param[3].'$$'];
1583
+		}
1464 1584
 
1465 1585
 		$pattern = '/'.preg_quote($param[2], '/').'/';
1466 1586
 		if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
@@ -1482,7 +1602,7 @@  discard block
 block discarded – undo
1482 1602
 		}
1483 1603
 
1484 1604
 		switch($this->mimetype)
1485
-			{
1605
+		{
1486 1606
 				case 'application/rtf':
1487 1607
 				case 'text/rtf':
1488 1608
 					$LF = '}\par \pard\plain{';
@@ -1506,25 +1626,38 @@  discard block
 block discarded – undo
1506 1626
 				default:
1507 1627
 					$LF = "\n";
1508 1628
 			}
1509
-		if($is_xml) {
1629
+		if($is_xml)
1630
+		{
1510 1631
 			$this->replacements = str_replace(array('&','&amp;amp;','<','>',"\r","\n"),array('&amp;','&amp;','&lt;','&gt;','',$LF),$this->replacements);
1511 1632
 		}
1512 1633
 		if (strpos($param[0],'$$NELF') === 0)
1513
-		{	//sets a Pagebreak and value, only if the field has a value
1514
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1634
+		{
1635
+//sets a Pagebreak and value, only if the field has a value
1636
+			if ($this->replacements['$$'.$param[1].'$$'] !='')
1637
+			{
1638
+				$replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1639
+			}
1515 1640
 		}
1516 1641
 		if (strpos($param[0],'$$NENVLF') === 0)
1517
-		{	//sets a Pagebreak without any value, only if the field has a value
1518
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF;
1642
+		{
1643
+//sets a Pagebreak without any value, only if the field has a value
1644
+			if ($this->replacements['$$'.$param[1].'$$'] !='')
1645
+			{
1646
+				$replace = $LF;
1647
+			}
1519 1648
 		}
1520 1649
 		if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0)
1521
-		{	//sets a Letterprefix
1650
+		{
1651
+//sets a Letterprefix
1522 1652
 			$replaceprefixsort = array();
1523 1653
 			// ToDo Stefan: $contentstart is NOT defined here!!!
1524 1654
 			$replaceprefix = explode(' ',substr($param[0],21,-2));
1525 1655
 			foreach ($replaceprefix as $nameprefix)
1526 1656
 			{
1527
-				if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1657
+				if ($this->replacements['$$'.$nameprefix.'$$'] !='')
1658
+				{
1659
+					$replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1660
+				}
1528 1661
 			}
1529 1662
 			$replace = implode($replaceprefixsort,' ');
1530 1663
 		}
@@ -1565,13 +1698,20 @@  discard block
 block discarded – undo
1565 1698
 				}
1566 1699
 				//error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs));
1567 1700
 				$retString = '';
1568
-				if (count($msgs['success'])>0) $retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));//implode('<br />',$msgs['success']);
1701
+				if (count($msgs['success'])>0)
1702
+				{
1703
+					$retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));
1704
+				}
1705
+				//implode('<br />',$msgs['success']);
1569 1706
 				//if (strlen($retString)>0) $retString .= '<br />';
1570 1707
 				foreach($msgs['failed'] as $c =>$e)
1571 1708
 				{
1572 1709
 					$errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.';
1573 1710
 				}
1574
-				if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1711
+				if (count($msgs['failed'])>0)
1712
+				{
1713
+					$retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1714
+				}
1575 1715
 				return $retString;
1576 1716
 			case 'application/vnd.oasis.opendocument.text':
1577 1717
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -1643,7 +1783,10 @@  discard block
 block discarded – undo
1643 1783
 					return $err;
1644 1784
 				}
1645 1785
 			}
1646
-			if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1786
+			if ($this->report_memory_usage)
1787
+			{
1788
+				error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1789
+			}
1647 1790
 		}
1648 1791
 		if(!empty($name))
1649 1792
 		{
@@ -1663,18 +1806,33 @@  discard block
 block discarded – undo
1663 1806
 			if ($zip->open($archive, ZipArchive::CHECKCONS) !== true)
1664 1807
 			{
1665 1808
 				error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
1666
-				if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1809
+				if ($zip->open($archive) !== true)
1810
+				{
1811
+					throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1812
+				}
1813
+			}
1814
+			if ($zip->addFromString($content_file,$merged) !== true)
1815
+			{
1816
+				throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1817
+			}
1818
+			if ($zip->close() !== true)
1819
+			{
1820
+				throw new Api\Exception("!ZipArchive::close()");
1667 1821
 			}
1668
-			if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1669
-			if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
1670 1822
 			unset($zip);
1671 1823
 			unset($merged);
1672 1824
 			if (substr($mimetype,0,35) == 'application/vnd.oasis.opendocument.' && 			// only open office archives need that, ms word files brake
1673
-				file_exists('/usr/bin/zip') && version_compare(PHP_VERSION,'5.3.1','<'))	// fix broken zip archives generated by current php
1825
+				file_exists('/usr/bin/zip') && version_compare(PHP_VERSION,'5.3.1','<'))
1826
+			{
1827
+				// fix broken zip archives generated by current php
1674 1828
 			{
1675 1829
 				exec('/usr/bin/zip -F '.escapeshellarg($archive));
1676 1830
 			}
1677
-			if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1831
+			}
1832
+			if ($this->report_memory_usage)
1833
+			{
1834
+				error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1835
+			}
1678 1836
 			Api\Header\Content::type($name,$mimetype,filesize($archive));
1679 1837
 			readfile($archive,'r');
1680 1838
 		}
@@ -1709,9 +1867,18 @@  discard block
 block discarded – undo
1709 1867
 	 */
1710 1868
 	public function download_by_request()
1711 1869
 	{
1712
-		if(empty($_POST['data_document_name'])) return false;
1713
-		if(empty($_POST['data_document_dir'])) return false;
1714
-		if(empty($_POST['data_checked'])) return false;
1870
+		if(empty($_POST['data_document_name']))
1871
+		{
1872
+			return false;
1873
+		}
1874
+		if(empty($_POST['data_document_dir']))
1875
+		{
1876
+			return false;
1877
+		}
1878
+		if(empty($_POST['data_checked']))
1879
+		{
1880
+			return false;
1881
+		}
1715 1882
 
1716 1883
 		return $this->download(
1717 1884
 			$_POST['data_document_name'],
@@ -1732,7 +1899,10 @@  discard block
 block discarded – undo
1732 1899
 	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
1733 1900
 	{
1734 1901
 		$export_limit=self::getExportLimit($app);
1735
-		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1902
+		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted()))
1903
+		{
1904
+			return array();
1905
+		}
1736 1906
 
1737 1907
 		// split multiple comma or whitespace separated directories
1738 1908
 		// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
@@ -1740,7 +1910,11 @@  discard block
 block discarded – undo
1740 1910
 		{
1741 1911
 			foreach($dirs as $n => &$d)
1742 1912
 			{
1743
-				if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1913
+				if ($n)
1914
+				{
1915
+					$d = '/'.$d;
1916
+				}
1917
+				// re-adding trailing slash removed by split
1744 1918
 			}
1745 1919
 		}
1746 1920
 		if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
@@ -1763,8 +1937,14 @@  discard block
 block discarded – undo
1763 1937
 				{
1764 1938
 					// return only the mime-types we support
1765 1939
 					$parts = explode('.',$file['name']);
1766
-					if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue;
1767
-					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue;
1940
+					if (!self::is_implemented($file['mime'],'.'.array_pop($parts)))
1941
+					{
1942
+						continue;
1943
+					}
1944
+					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter))
1945
+					{
1946
+						continue;
1947
+					}
1768 1948
 					$list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']);
1769 1949
 				}
1770 1950
 			}
@@ -1794,12 +1974,19 @@  discard block
 block discarded – undo
1794 1974
 		$export_limit=null)
1795 1975
 	{
1796 1976
 		$documents = array();
1797
-		if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
1798
-		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))	// put default document on top
1977
+		if ($export_limit == null)
1978
+		{
1979
+			$export_limit = self::getExportLimit();
1980
+		}
1981
+		// check if there is a globalsetting
1982
+		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))
1983
+		{
1984
+			// put default document on top
1799 1985
 		{
1800 1986
 			if(!$file['mime'])
1801 1987
 			{
1802 1988
 				$file['mime'] = Api\Vfs::mime_content_type($default_doc);
1989
+		}
1803 1990
 				$file['path'] = $default_doc;
1804 1991
 			}
1805 1992
 			$documents['document'] = array(
@@ -1823,7 +2010,11 @@  discard block
 block discarded – undo
1823 2010
 			{
1824 2011
 				foreach($dirs as $n => &$d)
1825 2012
 				{
1826
-					if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
2013
+					if ($n)
2014
+					{
2015
+						$d = '/'.$d;
2016
+					}
2017
+					// re-adding trailing slash removed by split
1827 2018
 				}
1828 2019
 			}
1829 2020
 			foreach($dirs as $dir)
@@ -1843,10 +2034,13 @@  discard block
 block discarded – undo
1843 2034
 			$parts = explode('.',$file['name']);
1844 2035
 			if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) ||
1845 2036
 				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) ||	// remove files not readable by user
1846
-				$file['path'] === $default_doc)	// default doc already added
2037
+				$file['path'] === $default_doc)
2038
+			{
2039
+				// default doc already added
1847 2040
 			{
1848 2041
 				unset($files[$key]);
1849 2042
 			}
2043
+			}
1850 2044
 			else
1851 2045
 			{
1852 2046
 				$dirname = Api\Vfs::dirname($file['path']);
@@ -2005,7 +2199,11 @@  discard block
 block discarded – undo
2005 2199
 			{
2006 2200
 				foreach($dirs as $n => $dir)
2007 2201
 				{
2008
-					if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
2202
+					if ($n)
2203
+					{
2204
+						$dir = '/'.$dir;
2205
+					}
2206
+					// re-adding trailing slash removed by split
2009 2207
 					if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document))
2010 2208
 					{
2011 2209
 						$document = $dir.'/'.$document;
@@ -2042,7 +2240,10 @@  discard block
 block discarded – undo
2042 2240
 	 */
2043 2241
 	static public function number_format($number,$num_decimal_places=2,$_mimetype='')
2044 2242
 	{
2045
-		if ((string)$number === '') return '';
2243
+		if ((string)$number === '')
2244
+		{
2245
+			return '';
2246
+		}
2046 2247
 		//error_log(__METHOD__.$_mimetype);
2047 2248
 		switch($_mimetype)
2048 2249
 		{
Please login to merge, or discard this patch.
Spacing   +363 added lines, -364 removed lines patch added patch discarded remove patch
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
 	 * Configuration for HTML Tidy to clean up any HTML content that is kept
83 83
 	 */
84 84
 	public static $tidy_config = array(
85
-		'output-xml'		=> true,	// Entity encoding
85
+		'output-xml'		=> true, // Entity encoding
86 86
 		'show-body-only'	=> true,
87 87
 		'output-encoding'	=> 'utf-8',
88 88
 		'input-encoding'	=> 'utf-8',
89
-		'quote-ampersand'	=> false,	// Prevent double encoding
90
-		'quote-nbsp'		=> true,	// XSLT can handle spaces easier
89
+		'quote-ampersand'	=> false, // Prevent double encoding
90
+		'quote-nbsp'		=> true, // XSLT can handle spaces easier
91 91
 		'preserve-entities'	=> true,
92
-		'wrap'			=> 0,		// Wrapping can break output
92
+		'wrap'			=> 0, // Wrapping can break output
93 93
 	);
94 94
 
95 95
 	/**
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		$this->contacts = new Api\Contacts();
121 121
 
122 122
 		$this->datetime_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.
123
-			($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']==12 ? 'h:i a' : 'H:i');
123
+			($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i');
124 124
 
125 125
 		$this->export_limit = self::getExportLimit();
126 126
 	}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		$accountsel = new uiaccountsel();
136 136
 
137 137
 		return '<input type="hidden" value="" name="newsettings[export_limit_excepted]" />'.
138
-			$accountsel->selection('newsettings[export_limit_excepted]','export_limit_excepted',$config['export_limit_excepted'],'both',4);
138
+			$accountsel->selection('newsettings[export_limit_excepted]', 'export_limit_excepted', $config['export_limit_excepted'], 'both', 4);
139 139
 	}
140 140
 
141 141
 	/**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @param string &$content=null content to create some replacements only if they are use
150 150
 	 * @return array|boolean array with replacements or false if entry not found
151 151
 	 */
152
-	abstract protected function get_replacements($id,&$content=null);
152
+	abstract protected function get_replacements($id, &$content = null);
153 153
 
154 154
 	/**
155 155
 	 * Return if merge-print is implemented for given mime-type (and/or extension)
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
 	 * @param string $mimetype eg. text/plain
158 158
 	 * @param string $extension only checked for applications/msword and .rtf
159 159
 	 */
160
-	static public function is_implemented($mimetype,$extension=null)
160
+	static public function is_implemented($mimetype, $extension = null)
161 161
 	{
162
-		static $zip_available=null;
162
+		static $zip_available = null;
163 163
 		if (is_null($zip_available))
164 164
 		{
165 165
 			$zip_available = check_load_extension('zip') &&
166
-				class_exists('ZipArchive');	// some PHP has zip extension, but no ZipArchive (eg. RHEL5!)
166
+				class_exists('ZipArchive'); // some PHP has zip extension, but no ZipArchive (eg. RHEL5!)
167 167
 		}
168 168
 		switch ($mimetype)
169 169
 		{
@@ -171,27 +171,27 @@  discard block
 block discarded – undo
171 171
 				if (strtolower($extension) != '.rtf') break;
172 172
 			case 'application/rtf':
173 173
 			case 'text/rtf':
174
-				return true;	// rtf files
174
+				return true; // rtf files
175 175
 			case 'application/vnd.oasis.opendocument.text':	// oo text
176 176
 			case 'application/vnd.oasis.opendocument.spreadsheet':	// oo spreadsheet
177 177
 				if (!$zip_available) break;
178
-				return true;	// open office write xml files
178
+				return true; // open office write xml files
179 179
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':	// ms word 2007 xml format
180 180
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d':	// mimetypes in vfs are limited to 64 chars
181 181
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':	// ms excel 2007 xml format
182 182
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee':
183 183
 				if (!$zip_available) break;
184
-				return true;	// ms word xml format
184
+				return true; // ms word xml format
185 185
 			case 'application/xml':
186
-				return true;	// alias for text/xml, eg. ms office 2003 word format
186
+				return true; // alias for text/xml, eg. ms office 2003 word format
187 187
 			case 'message/rfc822':
188 188
 				return true; // ToDo: check if you are theoretical able to send mail
189 189
 			case 'application/x-yaml':
190
-				return true;	// yaml file, plain text with marginal syntax support for multiline replacements
190
+				return true; // yaml file, plain text with marginal syntax support for multiline replacements
191 191
 			default:
192
-				if (substr($mimetype,0,5) == 'text/')
192
+				if (substr($mimetype, 0, 5) == 'text/')
193 193
 				{
194
-					return true;	// text files
194
+					return true; // text files
195 195
 				}
196 196
 				break;
197 197
 		}
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @param boolean $ignore_acl =false true: no acl check
210 210
 	 * @return array
211 211
 	 */
212
-	public function contact_replacements($contact,$prefix='',$ignore_acl=false)
212
+	public function contact_replacements($contact, $prefix = '', $ignore_acl = false)
213 213
 	{
214 214
 		if (!is_array($contact))
215 215
 		{
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
 		if (!is_array($contact)) return array();
219 219
 
220 220
 		$replacements = array();
221
-		foreach(array_keys($this->contacts->contact_fields) as $name)
221
+		foreach (array_keys($this->contacts->contact_fields) as $name)
222 222
 		{
223 223
 			$value = $contact[$name];
224
-			switch($name)
224
+			switch ($name)
225 225
 			{
226 226
 				case 'created': case 'modified':
227
-					if($value) $value = Api\DateTime::to($value);
227
+					if ($value) $value = Api\DateTime::to($value);
228 228
 					break;
229 229
 				case 'bday':
230 230
 					if ($value)
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 							$value = Api\DateTime::to($value, true);
234 234
 						}
235 235
 						catch (\Exception $e) {
236
-							unset($e);	// ignore exception caused by wrongly formatted date
236
+							unset($e); // ignore exception caused by wrongly formatted date
237 237
 						}
238 238
 					}
239 239
 					break;
@@ -246,11 +246,11 @@  discard block
 block discarded – undo
246 246
 						// if cat-tree is displayed, we return a full category path not just the name of the cat
247 247
 						$use = $GLOBALS['egw_info']['server']['cat_tab'] == 'Tree' ? 'path' : 'name';
248 248
 						$cats = array();
249
-						foreach(is_array($value) ? $value : explode(',',$value) as $cat_id)
249
+						foreach (is_array($value) ? $value : explode(',', $value) as $cat_id)
250 250
 						{
251
-							$cats[] = $GLOBALS['egw']->categories->id2name($cat_id,$use);
251
+							$cats[] = $GLOBALS['egw']->categories->id2name($cat_id, $use);
252 252
 						}
253
-						$value = implode(', ',$cats);
253
+						$value = implode(', ', $cats);
254 254
 					}
255 255
 					break;
256 256
 				case 'jpegphoto':	// returning a link might make more sense then the binary photo
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 					{
259 259
 						$value = ($GLOBALS['egw_info']['server']['webserver_url'][0] == '/' ?
260 260
 							($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['HTTP_HOST'] : '').
261
-							$GLOBALS['egw']->link('/index.php',$contact['photo']);
261
+							$GLOBALS['egw']->link('/index.php', $contact['photo']);
262 262
 					}
263 263
 					break;
264 264
 				case 'tel_prefer':
@@ -270,40 +270,39 @@  discard block
 block discarded – undo
270 270
 				case 'account_id':
271 271
 					if ($value)
272 272
 					{
273
-						$replacements['$$'.($prefix ? $prefix.'/':'').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value);
273
+						$replacements['$$'.($prefix ? $prefix.'/' : '').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value);
274 274
 					}
275 275
 					break;
276 276
 			}
277
-			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
277
+			if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] = $value;
278 278
 		}
279 279
 		// set custom fields, should probably go to a general method all apps can use
280 280
 		// need to load all cfs for $ignore_acl=true
281
-		foreach($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field)
281
+		foreach ($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field)
282 282
 		{
283 283
 			$name = '#'.$name;
284
-			$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] =
284
+			$replacements['$$'.($prefix ? $prefix.'/' : '').$name.'$$'] =
285 285
 				// use raw data for yaml, no user-preference specific formatting
286
-				$this->mimetype == 'application/x-yaml' ? (string)$contact[$name] :
287
-				Customfields::format($field, (string)$contact[$name]);
286
+				$this->mimetype == 'application/x-yaml' ? (string)$contact[$name] : Customfields::format($field, (string)$contact[$name]);
288 287
 		}
289 288
 
290 289
 		// Add in extra cat field
291 290
 		$cats = array();
292
-		foreach(is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',',$contact['cat_id']) as $cat_id)
291
+		foreach (is_array($contact['cat_id']) ? $contact['cat_id'] : explode(',', $contact['cat_id']) as $cat_id)
293 292
 		{
294
-			if(!$cat_id) continue;
295
-			if($GLOBALS['egw']->categories->id2name($cat_id,'main') != $cat_id)
293
+			if (!$cat_id) continue;
294
+			if ($GLOBALS['egw']->categories->id2name($cat_id, 'main') != $cat_id)
296 295
 			{
297 296
 				$path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path'));
298 297
 				unset($path[0]); // Drop main
299
-				$cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path);
300
-			} elseif($cat_id) {
298
+				$cats[$GLOBALS['egw']->categories->id2name($cat_id, 'main')][] = implode(' / ', $path);
299
+			} elseif ($cat_id) {
301 300
 				$cats[$cat_id] = array();
302 301
 			}
303 302
 		}
304
-		foreach($cats as $main => $cat) {
305
-			$replacements['$$'.($prefix ? $prefix.'/':'').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main,'name')
306
-				. (count($cat) > 0 ? ': ' : '') . implode(', ', $cats[$main]) . "\n";
303
+		foreach ($cats as $main => $cat) {
304
+			$replacements['$$'.($prefix ? $prefix.'/' : '').'categories$$'] .= $GLOBALS['egw']->categories->id2name($main, 'name')
305
+				. (count($cat) > 0 ? ': ' : '').implode(', ', $cats[$main])."\n";
307 306
 		}
308 307
 		return $replacements;
309 308
 	}
@@ -322,34 +321,34 @@  discard block
 block discarded – undo
322 321
 	 * 	'link' - URL to the entry
323 322
 	 * 	'href' - HREF tag wrapped around the title
324 323
 	 */
325
-	protected function get_links($app, $id, $only_app='', $exclude = array(), $style = 'title')
324
+	protected function get_links($app, $id, $only_app = '', $exclude = array(), $style = 'title')
326 325
 	{
327 326
 		$links = Api\Link::get_links($app, $id, $only_app);
328 327
 		$link_titles = array();
329
-		foreach($links as $link_info)
328
+		foreach ($links as $link_info)
330 329
 		{
331 330
 			// Using only_app only returns the ID
332
-			if(!is_array($link_info) && $only_app && $only_app[0] !== '!')
331
+			if (!is_array($link_info) && $only_app && $only_app[0] !== '!')
333 332
 			{
334 333
 				$link_info = array(
335 334
 					'app'	=> $only_app,
336 335
 					'id'	=> $link_info
337 336
 				);
338 337
 			}
339
-			if($exclude && in_array($link_info['id'], $exclude)) continue;
338
+			if ($exclude && in_array($link_info['id'], $exclude)) continue;
340 339
 
341 340
 			$title = Api\Link::title($link_info['app'], $link_info['id']);
342
-			if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
341
+			if (class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
343 342
 			{
344 343
 				$title = Stylite\Vfs\Links\StreamWrapper::entry2name($link_info['app'], $link_info['id'], $title);
345 344
 			}
346
-			if($style == 'href' || $style == 'link')
345
+			if ($style == 'href' || $style == 'link')
347 346
 			{
348 347
 				$link = Api\Link::view($link_info['app'], $link_info['id'], $link_info);
349
-				if($link_info['app'] != Api\Link::VFS_APPNAME)
348
+				if ($link_info['app'] != Api\Link::VFS_APPNAME)
350 349
 				{
351 350
 					// Set app to false so we always get an external link
352
-					$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php',$link, false));
351
+					$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php', $link, false));
353 352
 				}
354 353
 				else
355 354
 				{
@@ -365,7 +364,7 @@  discard block
 block discarded – undo
365 364
 			}
366 365
 			$link_titles[] = $title;
367 366
 		}
368
-		return implode("\n",$link_titles);
367
+		return implode("\n", $link_titles);
369 368
 	}
370 369
 
371 370
 	/**
@@ -382,33 +381,33 @@  discard block
 block discarded – undo
382 381
 	{
383 382
 		$array = array();
384 383
 		$pattern = '@\$(links_attachments|links|attachments|link)\/?(title|href|link)?\/?([a-z]*)\$@';
385
-		static $link_cache=null;
384
+		static $link_cache = null;
386 385
 		$matches = null;
387
-		if(preg_match_all($pattern, $content, $matches))
386
+		if (preg_match_all($pattern, $content, $matches))
388 387
 		{
389
-			foreach($matches[0] as $i => $placeholder)
388
+			foreach ($matches[0] as $i => $placeholder)
390 389
 			{
391 390
 				$placeholder = substr($placeholder, 1, -1);
392
-				if($link_cache[$id][$placeholder])
391
+				if ($link_cache[$id][$placeholder])
393 392
 				{
394 393
 					$array[$placeholder] = $link_cache[$id][$placeholder];
395 394
 					continue;
396 395
 				}
397
-				switch($matches[1][$i])
396
+				switch ($matches[1][$i])
398 397
 				{
399 398
 					case 'link':
400 399
 						// Link to current record
401 400
 						$title = Api\Link::title($app, $id);
402
-						if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME)
401
+						if (class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME)
403 402
 						{
404 403
 							$title = Stylite\Vfs\Links\StreamWrapper::entry2name($app, $id, $title);
405 404
 						}
406 405
 
407 406
 						$link = Api\Link::view($app, $id);
408
-						if($app != Api\Link::VFS_APPNAME)
407
+						if ($app != Api\Link::VFS_APPNAME)
409 408
 						{
410 409
 							// Set app to false so we always get an external link
411
-							$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php',$link, false));
410
+							$link = str_replace(',', '%2C', $GLOBALS['egw']->framework->link('/index.php', $link, false));
412 411
 						}
413 412
 						else
414 413
 						{
@@ -420,26 +419,26 @@  discard block
 block discarded – undo
420 419
 							$link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
421 420
 								($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link;
422 421
 						}
423
-						$array[($prefix?$prefix.'/':'').$placeholder] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link);
422
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = Api\Html::a_href(Api\Html::htmlspecialchars($title), $link);
424 423
 						break;
425 424
 					case 'links':
426
-						$link_app = $matches[3][$i] ? $matches[3][$i] :  '!'.Api\Link::VFS_APPNAME;
427
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, $link_app, array(),$matches[2][$i]);
425
+						$link_app = $matches[3][$i] ? $matches[3][$i] : '!'.Api\Link::VFS_APPNAME;
426
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, $link_app, array(), $matches[2][$i]);
428 427
 						break;
429 428
 					case 'attachments':
430
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, Api\Link::VFS_APPNAME,array(),$matches[2][$i]);
429
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, Api\Link::VFS_APPNAME, array(), $matches[2][$i]);
431 430
 						break;
432 431
 					default:
433
-						$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]);
432
+						$array[($prefix ? $prefix.'/' : '').$placeholder] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]);
434 433
 						break;
435 434
 				}
436 435
 				$link_cache[$id][$placeholder] = $array[$placeholder];
437 436
 			}
438 437
 		}
439 438
 		// Need to set each app, to make sure placeholders are removed
440
-		foreach(array_keys($GLOBALS['egw_info']['user']['apps']) as $_app)
439
+		foreach (array_keys($GLOBALS['egw_info']['user']['apps']) as $_app)
441 440
 		{
442
-			$array[($prefix?$prefix.'/':'')."links/$app"] = $this->get_links($app,$id,$_app);
441
+			$array[($prefix ? $prefix.'/' : '')."links/$app"] = $this->get_links($app, $id, $_app);
443 442
 		}
444 443
 		return $array;
445 444
 	}
@@ -452,12 +451,12 @@  discard block
 block discarded – undo
452 451
 	 * @deprecated use Api\DateTime::to($time='now',$format='')
453 452
 	 * @return string
454 453
 	 */
455
-	protected function format_datetime($time,$format=null)
454
+	protected function format_datetime($time, $format = null)
456 455
 	{
457
-		trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
456
+		trigger_error(__METHOD__.' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
458 457
 		if (is_null($format)) $format = $this->datetime_format;
459 458
 
460
-		return Api\DateTime::to($time,$format);
459
+		return Api\DateTime::to($time, $format);
461 460
 	}
462 461
 
463 462
 	/**
@@ -469,7 +468,7 @@  discard block
 block discarded – undo
469 468
 	 */
470 469
 	public static function is_export_limit_excepted()
471 470
 	{
472
-		static $is_excepted=null;
471
+		static $is_excepted = null;
473 472
 
474 473
 		if (is_null($is_excepted))
475 474
 		{
@@ -479,9 +478,9 @@  discard block
 block discarded – undo
479 478
 			if (!$is_excepted && (is_array($export_limit_excepted = $GLOBALS['egw_info']['server']['export_limit_excepted']) ||
480 479
 				is_array($export_limit_excepted = unserialize($export_limit_excepted))))
481 480
 			{
482
-				$id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
481
+				$id_and_memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true);
483 482
 				$id_and_memberships[] = $GLOBALS['egw_info']['user']['account_id'];
484
-				$is_excepted = (bool) array_intersect($id_and_memberships, $export_limit_excepted);
483
+				$is_excepted = (bool)array_intersect($id_and_memberships, $export_limit_excepted);
485 484
 			}
486 485
 		}
487 486
 		return $is_excepted;
@@ -494,18 +493,18 @@  discard block
 block discarded – undo
494 493
 	 * @return mixed - no if no export is allowed, false if there is no restriction and int as there is a valid restriction
495 494
 	 *		you may have to cast the returned value to int, if you want to use it as number
496 495
 	 */
497
-	public static function getExportLimit($app='common')
496
+	public static function getExportLimit($app = 'common')
498 497
 	{
499
-		static $exportLimitStore=array();
500
-		if (empty($app)) $app='common';
498
+		static $exportLimitStore = array();
499
+		if (empty($app)) $app = 'common';
501 500
 		//error_log(__METHOD__.__LINE__.' called with app:'.$app);
502
-		if (!array_key_exists($app,$exportLimitStore))
501
+		if (!array_key_exists($app, $exportLimitStore))
503 502
 		{
504 503
 			//error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace());
505 504
 			$exportLimitStore[$app] = $GLOBALS['egw_info']['server']['export_limit'];
506
-			if ($app !='common')
505
+			if ($app != 'common')
507 506
 			{
508
-				$app_limit = Api\Hooks::single('export_limit',$app);
507
+				$app_limit = Api\Hooks::single('export_limit', $app);
509 508
 				if ($app_limit) $exportLimitStore[$app] = $app_limit;
510 509
 			}
511 510
 			//error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]);
@@ -537,9 +536,9 @@  discard block
 block discarded – undo
537 536
 	 *
538 537
 	 * @return bool - true if no export is allowed or a limit is set, false if there is no restriction
539 538
 	 */
540
-	public static function hasExportLimit($app_limit,$checkas='AND')
539
+	public static function hasExportLimit($app_limit, $checkas = 'AND')
541 540
 	{
542
-		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
541
+		if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit != 'no' && $app_limit > 0));
543 542
 		if (empty($app_limit)) return false;
544 543
 		if ($app_limit == 'no') return true;
545 544
 		if ($app_limit > 0) return true;
@@ -555,28 +554,28 @@  discard block
 block discarded – undo
555 554
 	 * @param array $fix =null regular expression => replacement pairs eg. to fix garbled placeholders
556 555
 	 * @return string|boolean merged document or false on error
557 556
 	 */
558
-	public function &merge($document,$ids,&$err,$mimetype,array $fix=null)
557
+	public function &merge($document, $ids, &$err, $mimetype, array $fix = null)
559 558
 	{
560 559
 		if (!($content = file_get_contents($document)))
561 560
 		{
562
-			$err = lang("Document '%1' does not exist or is not readable for you!",$document);
561
+			$err = lang("Document '%1' does not exist or is not readable for you!", $document);
563 562
 			return false;
564 563
 		}
565 564
 
566 565
 		if (self::hasExportLimit($this->export_limit) && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit)
567 566
 		{
568
-			$err = lang('No rights to export more than %1 entries!',(int)$this->export_limit);
567
+			$err = lang('No rights to export more than %1 entries!', (int)$this->export_limit);
569 568
 			return false;
570 569
 		}
571 570
 
572 571
 		// fix application/msword mimetype for rtf files
573
-		if ($mimetype == 'application/msword' && strtolower(substr($document,-4)) == '.rtf')
572
+		if ($mimetype == 'application/msword' && strtolower(substr($document, -4)) == '.rtf')
574 573
 		{
575 574
 			$mimetype = 'application/rtf';
576 575
 		}
577 576
 
578 577
 		try {
579
-			$content = $this->merge_string($content,$ids,$err,$mimetype,$fix);
578
+			$content = $this->merge_string($content, $ids, $err, $mimetype, $fix);
580 579
 		} catch (\Exception $e) {
581 580
 			$err = $e->getMessage();
582 581
 			return false;
@@ -584,18 +583,18 @@  discard block
 block discarded – undo
584 583
 		return $content;
585 584
 	}
586 585
 
587
-	protected function apply_styles (&$content, $mimetype, $mso_application_progid=null)
586
+	protected function apply_styles(&$content, $mimetype, $mso_application_progid = null)
588 587
 	{
589 588
 		if (!isset($mso_application_progid))
590 589
 		{
591 590
 			$matches = null;
592 591
 			$mso_application_progid = $mimetype == 'application/xml' &&
593
-				preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($content,0,200),$matches) ?
592
+				preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/', substr($content, 0, 200), $matches) ?
594 593
 					$matches[1] : '';
595 594
 		}
596 595
 		// Tags we can replace with the target document's version
597 596
 		$replace_tags = array();
598
-		switch($mimetype.$mso_application_progid)
597
+		switch ($mimetype.$mso_application_progid)
599 598
 		{
600 599
 			case 'application/vnd.oasis.opendocument.text':		// open office
601 600
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -605,7 +604,7 @@  discard block
 block discarded – undo
605 604
 					'/<\/(ol|ul|table)>/' => '</$1><text:p>',
606 605
 					//'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3</$1>',
607 606
 				);
608
-				$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
607
+				$content = preg_replace(array_keys($replace_tags), array_values($replace_tags), $content);
609 608
 
610 609
 				$doc = new DOMDocument();
611 610
 				$xslt = new XSLTProcessor();
@@ -630,7 +629,7 @@  discard block
 block discarded – undo
630 629
 					// Remove spans with no attributes, linebreaks inside them cause problems
631 630
 					'/<span>(.*?)<\/span>/' => '$1'
632 631
 				);
633
-				$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
632
+				$content = preg_replace(array_keys($replace_tags), array_values($replace_tags), $content);
634 633
 
635 634
 				/*
636 635
 				In the case where you have something like <span><span></w:t><w:br/><w:t></span></span> (invalid - mismatched tags),
@@ -640,9 +639,9 @@  discard block
 block discarded – undo
640 639
 				$count = $i = 0;
641 640
 				do
642 641
 				{
643
-					$content = preg_replace('/<span>(.*?)<\/span>/','$1',$content, -1, $count);
642
+					$content = preg_replace('/<span>(.*?)<\/span>/', '$1', $content, -1, $count);
644 643
 					$i++;
645
-				} while($count > 0 && $i < 10);
644
+				} while ($count > 0 && $i < 10);
646 645
 
647 646
 				$doc = new DOMDocument();
648 647
 				$xslt = new XSLTProcessor();
@@ -653,20 +652,20 @@  discard block
 block discarded – undo
653 652
 		}
654 653
 
655 654
 		// XSLT transform known tags
656
-		if($xslt)
655
+		if ($xslt)
657 656
 		{
658 657
 			// does NOT work with php 5.2.6: Catchable fatal error: argument 1 to transformToXml() must be of type DOMDocument
659 658
 			//$element = new SimpleXMLelement($content);
660 659
 			$element = new DOMDocument('1.0', 'utf-8');
661 660
 			$result = $element->loadXML($content);
662
-			if(!$result)
661
+			if (!$result)
663 662
 			{
664 663
 				throw new Api\Exception('Unable to parse merged document for styles.  Check warnings in log for details.');
665 664
 			}
666 665
 			$content = $xslt->transformToXml($element);
667 666
 
668 667
 			// Word 2003 needs two declarations, add extra declaration back in
669
-			if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
668
+			if ($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
670 669
 				$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;
671 670
 			}
672 671
 			// Validate
@@ -689,11 +688,11 @@  discard block
 block discarded – undo
689 688
 	 * @param string $charset =null charset to override default set by mimetype or export charset
690 689
 	 * @return string|boolean merged document or false on error
691 690
 	 */
692
-	public function &merge_string($_content,$ids,&$err,$mimetype,array $fix=null,$charset=null)
691
+	public function &merge_string($_content, $ids, &$err, $mimetype, array $fix = null, $charset = null)
693 692
 	{
694 693
 		$matches = null;
695 694
 		if ($mimetype == 'application/xml' &&
696
-			preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($_content,0,200),$matches))
695
+			preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/', substr($_content, 0, 200), $matches))
697 696
 		{
698 697
 			$mso_application_progid = $matches[1];
699 698
 		}
@@ -708,9 +707,9 @@  discard block
 block discarded – undo
708 707
 			return '$$'.strip_tags(substr($matches[0], 2, -2)).'$$';
709 708
 		}, $_content);
710 709
 		// Handle escaped placeholder markers in RTF, they won't match when escaped
711
-		if($mimetype == 'application/rtf')
710
+		if ($mimetype == 'application/rtf')
712 711
 		{
713
-			$content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i','$$\1$$',$content);
712
+			$content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i', '$$\1$$', $content);
714 713
 		}
715 714
 
716 715
 		// make currently processed mimetype available to class methods;
@@ -719,16 +718,16 @@  discard block
 block discarded – undo
719 718
 		// fix garbled placeholders
720 719
 		if ($fix && is_array($fix))
721 720
 		{
722
-			$content = preg_replace(array_keys($fix),array_values($fix),$content);
721
+			$content = preg_replace(array_keys($fix), array_values($fix), $content);
723 722
 			//die("<pre>".htmlspecialchars($content)."</pre>\n");
724 723
 		}
725
-		list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
724
+		list($contentstart, $contentrepeat, $contentend) = preg_split('/\$\$pagerepeat\$\$/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
726 725
 		if ($mimetype == 'text/plain' && count($ids) > 1)
727 726
 		{
728 727
 			// textdocuments are simple, they do not hold start and end, but they may have content before and after the $$pagerepeat$$ tag
729 728
 			// header and footer should not hold any $$ tags; if we find $$ tags with the header, we assume it is the pagerepeatcontent
730 729
 			$nohead = false;
731
-			if (stripos($contentstart,'$$') !== false) $nohead = true;
730
+			if (stripos($contentstart, '$$') !== false) $nohead = true;
732 731
 			if ($nohead)
733 732
 			{
734 733
 				$contentend = $contentrepeat;
@@ -739,14 +738,14 @@  discard block
 block discarded – undo
739 738
 		}
740 739
 		if ($mimetype == 'application/vnd.oasis.opendocument.text' && count($ids) > 1)
741 740
 		{
742
-			if(strpos($content, '$$pagerepeat') === false)
741
+			if (strpos($content, '$$pagerepeat') === false)
743 742
 			{
744 743
 				//for odt files we have to split the content and add a style for page break to  the style area
745
-				list($contentstart,$contentrepeat,$contentend) = preg_split('/office:body>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
746
-				$contentstart = substr($contentstart,0,strlen($contentstart)-1);  //remove "<"
747
-				$contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2);  //remove "</";
744
+				list($contentstart, $contentrepeat, $contentend) = preg_split('/office:body>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
745
+				$contentstart = substr($contentstart, 0, strlen($contentstart) - 1); //remove "<"
746
+				$contentrepeat = substr($contentrepeat, 0, strlen($contentrepeat) - 2); //remove "</";
748 747
 				// need to add page-break style to the style list
749
-				list($stylestart,$stylerepeat,$styleend) = preg_split('/<\/office:automatic-styles>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document style sheets
748
+				list($stylestart, $stylerepeat, $styleend) = preg_split('/<\/office:automatic-styles>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document style sheets
750 749
 				$contentstart = $stylestart.'<style:style style:name="P200" style:family="paragraph" style:parent-style-name="Standard"><style:paragraph-properties fo:break-before="page"/></style:style></office:automatic-styles>';
751 750
 				$contentstart .= '<office:body>';
752 751
 				$contentend = '</office:body></office:document-content>';
@@ -754,22 +753,22 @@  discard block
 block discarded – undo
754 753
 			else
755 754
 			{
756 755
 				// Template specifies where to repeat
757
-				list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get different parts of document, seperated by pagerepeat
756
+				list($contentstart, $contentrepeat, $contentend) = preg_split('/\$\$pagerepeat\$\$/', $content, -1, PREG_SPLIT_NO_EMPTY); //get different parts of document, seperated by pagerepeat
758 757
 			}
759 758
 		}
760 759
 		if ($mimetype == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' && count($ids) > 1)
761 760
 		{
762 761
 			//for Word 2007 XML files we have to split the content and add a style for page break to  the style area
763
-			list($contentstart,$contentrepeat,$contentend) = preg_split('/w:body>/',$content,-1, PREG_SPLIT_NO_EMPTY);  //get differt parts of document, seperatet by Pagerepeat
764
-			$contentstart = substr($contentstart,0,strlen($contentstart)-1);  //remove "</"
765
-			$contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2);  //remove "</";
762
+			list($contentstart, $contentrepeat, $contentend) = preg_split('/w:body>/', $content, -1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
763
+			$contentstart = substr($contentstart, 0, strlen($contentstart) - 1); //remove "</"
764
+			$contentrepeat = substr($contentrepeat, 0, strlen($contentrepeat) - 2); //remove "</";
766 765
 			$contentstart .= '<w:body>';
767 766
 			$contentend = '</w:body></w:document>';
768 767
 		}
769
-		list($Labelstart,$Labelrepeat,$Labeltend) = preg_split('/\$\$label\$\$/',$contentrepeat,-1, PREG_SPLIT_NO_EMPTY);  //get the Lable content
770
-		preg_match_all('/\$\$labelplacement\$\$/',$contentrepeat,$countlables, PREG_SPLIT_NO_EMPTY);
768
+		list($Labelstart, $Labelrepeat, $Labeltend) = preg_split('/\$\$label\$\$/', $contentrepeat, -1, PREG_SPLIT_NO_EMPTY); //get the Lable content
769
+		preg_match_all('/\$\$labelplacement\$\$/', $contentrepeat, $countlables, PREG_SPLIT_NO_EMPTY);
771 770
 		$countlables = count($countlables[0]);
772
-		preg_replace('/\$\$labelplacement\$\$/','',$Labelrepeat,1);
771
+		preg_replace('/\$\$labelplacement\$\$/', '', $Labelrepeat, 1);
773 772
 		if ($countlables > 1) $lableprint = true;
774 773
 		if (count($ids) > 1 && !$contentrepeat)
775 774
 		{
@@ -780,10 +779,10 @@  discard block
 block discarded – undo
780 779
 
781 780
 		if ($contentrepeat)
782 781
 		{
783
-			$content_stream = fopen('php://temp','r+');
782
+			$content_stream = fopen('php://temp', 'r+');
784 783
 			fwrite($content_stream, $contentstart);
785 784
 			$joiner = '';
786
-			switch($mimetype)
785
+			switch ($mimetype)
787 786
 			{
788 787
 				case 'application/rtf':
789 788
 				case 'text/rtf':
@@ -803,19 +802,19 @@  discard block
 block discarded – undo
803 802
 					$joiner = "\r\n";
804 803
 					break;
805 804
 				default:
806
-					$err = lang('%1 not implemented for %2!','$$pagerepeat$$',$mimetype);
805
+					$err = lang('%1 not implemented for %2!', '$$pagerepeat$$', $mimetype);
807 806
 					return false;
808 807
 			}
809 808
 		}
810 809
 		foreach ((array)$ids as $n => $id)
811 810
 		{
812
-			if ($contentrepeat) $content = $contentrepeat;   //content to repeat
811
+			if ($contentrepeat) $content = $contentrepeat; //content to repeat
813 812
 			if ($lableprint) $content = $Labelrepeat;
814 813
 
815 814
 			// generate replacements; if exeption is thrown, catch it set error message and return false
816 815
 			try
817 816
 			{
818
-				if(!($replacements = $this->get_replacements($id,$content)))
817
+				if (!($replacements = $this->get_replacements($id, $content)))
819 818
 				{
820 819
 					$err = lang('Entry not found!');
821 820
 					return false;
@@ -829,86 +828,86 @@  discard block
 block discarded – undo
829 828
 			}
830 829
 			if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
831 830
 			// some general replacements: current user, date and time
832
-			if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')))
831
+			if (strpos($content, '$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')))
833 832
 			{
834
-				$replacements += $this->contact_replacements($user,'user');
835
-				$replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'account_primary_group'));
833
+				$replacements += $this->contact_replacements($user, 'user');
834
+				$replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'account_primary_group'));
836 835
 			}
837
-			$replacements['$$date$$'] = Api\DateTime::to('now',true);
836
+			$replacements['$$date$$'] = Api\DateTime::to('now', true);
838 837
 			$replacements['$$datetime$$'] = Api\DateTime::to('now');
839
-			$replacements['$$time$$'] = Api\DateTime::to('now',false);
838
+			$replacements['$$time$$'] = Api\DateTime::to('now', false);
840 839
 
841 840
 			// does our extending class registered table-plugins AND document contains table tags
842
-			if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s',$content,$matches,PREG_SET_ORDER))
841
+			if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s', $content, $matches, PREG_SET_ORDER))
843 842
 			{
844 843
 				// process each table
845
-				foreach($matches as $match)
844
+				foreach ($matches as $match)
846 845
 				{
847
-					$plugin   = $match[1];	// plugin name
846
+					$plugin   = $match[1]; // plugin name
848 847
 					$callback = $this->table_plugins[$plugin];
849
-					$repeat   = $match[2];	// line to repeat
848
+					$repeat   = $match[2]; // line to repeat
850 849
 					$repeats = '';
851 850
 					if (isset($callback))
852 851
 					{
853
-						for($n = 0; ($row_replacements = $this->$callback($plugin,$id,$n,$repeat)); ++$n)
852
+						for ($n = 0; ($row_replacements = $this->$callback($plugin, $id, $n, $repeat)); ++$n)
854 853
 						{
855 854
 							$_repeat = $this->process_commands($repeat, $row_replacements);
856
-							$repeats .= $this->replace($_repeat,$row_replacements,$mimetype,$mso_application_progid);
855
+							$repeats .= $this->replace($_repeat, $row_replacements, $mimetype, $mso_application_progid);
857 856
 						}
858 857
 					}
859
-					$content = str_replace($match[0],$repeats,$content);
858
+					$content = str_replace($match[0], $repeats, $content);
860 859
 				}
861 860
 			}
862
-			$content = $this->process_commands($this->replace($content,$replacements,$mimetype,$mso_application_progid,$charset), $replacements);
861
+			$content = $this->process_commands($this->replace($content, $replacements, $mimetype, $mso_application_progid, $charset), $replacements);
863 862
 
864 863
 			// remove not existing replacements (eg. from calendar array)
865
-			if (strpos($content,'$$') !== null)
864
+			if (strpos($content, '$$') !== null)
866 865
 			{
867
-				$content = preg_replace('/\$\$[a-z0-9_\/]+\$\$/i','',$content);
866
+				$content = preg_replace('/\$\$[a-z0-9_\/]+\$\$/i', '', $content);
868 867
 			}
869 868
 			if ($contentrepeat)
870 869
 			{
871
-				fwrite($content_stream, ($n == 0 ? '' : $joiner) . $content);
870
+				fwrite($content_stream, ($n == 0 ? '' : $joiner).$content);
872 871
 			}
873
-			if($lableprint)
872
+			if ($lableprint)
874 873
 			{
875
-				$contentrep[is_array($id) ? implode(':',$id) : $id] = $content;
874
+				$contentrep[is_array($id) ? implode(':', $id) : $id] = $content;
876 875
 			}
877 876
 		}
878 877
 		if ($Labelrepeat)
879 878
 		{
880
-			$countpage=0;
881
-			$count=0;
879
+			$countpage = 0;
880
+			$count = 0;
882 881
 			$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
883 882
 
884 883
 			foreach ($contentrep as $Label)
885 884
 			{
886
-				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/',$Label,$contentrepeatpages[$countpage],1);
887
-				$count=$count+1;
888
-				if (($count % $countlables) == 0 && count($contentrep)>$count)  //new page
885
+				$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/', $Label, $contentrepeatpages[$countpage], 1);
886
+				$count = $count + 1;
887
+				if (($count % $countlables) == 0 && count($contentrep) > $count)  //new page
889 888
 				{
890
-					$countpage = $countpage+1;
889
+					$countpage = $countpage + 1;
891 890
 					$contentrepeatpages[$countpage] = $Labelstart.$Labeltend;
892 891
 				}
893 892
 			}
894
-			$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/','',$contentrepeatpages[$countpage],-1);  //clean empty fields
893
+			$contentrepeatpages[$countpage] = preg_replace('/\$\$labelplacement\$\$/', '', $contentrepeatpages[$countpage], -1); //clean empty fields
895 894
 
896
-			switch($mimetype)
895
+			switch ($mimetype)
897 896
 			{
898 897
 				case 'application/rtf':
899 898
 				case 'text/rtf':
900
-					return $contentstart.implode('\\par \\page\\pard\\plain',$contentrepeatpages).$contentend;
899
+					return $contentstart.implode('\\par \\page\\pard\\plain', $contentrepeatpages).$contentend;
901 900
 				case 'application/vnd.oasis.opendocument.text':
902
-					return $contentstart.implode('<text:line-break />',$contentrepeatpages).$contentend;
901
+					return $contentstart.implode('<text:line-break />', $contentrepeatpages).$contentend;
903 902
 				case 'application/vnd.oasis.opendocument.spreadsheet':
904
-					return $contentstart.implode('</text:p><text:p>',$contentrepeatpages).$contentend;
903
+					return $contentstart.implode('</text:p><text:p>', $contentrepeatpages).$contentend;
905 904
 				case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
906 905
 				case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
907
-					return $contentstart.implode('<w:br w:type="page" />',$contentrepeatpages).$contentend;
906
+					return $contentstart.implode('<w:br w:type="page" />', $contentrepeatpages).$contentend;
908 907
 				case 'text/plain':
909
-					return $contentstart.implode("\r\n",$contentrep).$contentend;
908
+					return $contentstart.implode("\r\n", $contentrep).$contentend;
910 909
 			}
911
-			$err = lang('%1 not implemented for %2!','$$labelplacement$$',$mimetype);
910
+			$err = lang('%1 not implemented for %2!', '$$labelplacement$$', $mimetype);
912 911
 			return false;
913 912
 		}
914 913
 
@@ -933,9 +932,9 @@  discard block
 block discarded – undo
933 932
 	 * @param string $charset =null charset to override default set by mimetype or export charset
934 933
 	 * @return string
935 934
 	 */
936
-	protected function replace($content,array $replacements,$mimetype,$mso_application_progid='',$charset=null)
935
+	protected function replace($content, array $replacements, $mimetype, $mso_application_progid = '', $charset = null)
937 936
 	{
938
-		switch($mimetype)
937
+		switch ($mimetype)
939 938
 		{
940 939
 			case 'application/vnd.oasis.opendocument.text':		// open office
941 940
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -944,13 +943,13 @@  discard block
 block discarded – undo
944 943
 			case 'application/xml':
945 944
 			case 'text/xml':
946 945
 				$is_xml = true;
947
-				$charset = 'utf-8';	// xml files --> always use utf-8
946
+				$charset = 'utf-8'; // xml files --> always use utf-8
948 947
 				break;
949 948
 
950 949
 			case 'text/html':
951 950
 				$is_xml = true;
952 951
 				$matches = null;
953
-				if (preg_match('/<meta http-equiv="content-type".*charset=([^;"]+)/i',$content,$matches))
952
+				if (preg_match('/<meta http-equiv="content-type".*charset=([^;"]+)/i', $content, $matches))
954 953
 				{
955 954
 					$charset = $matches[1];
956 955
 				}
@@ -969,18 +968,18 @@  discard block
 block discarded – undo
969 968
 		// do we need to convert charset
970 969
 		if ($charset && $charset != Api\Translation::charset())
971 970
 		{
972
-			$replacements = Api\Translation::convert($replacements,Api\Translation::charset(),$charset);
971
+			$replacements = Api\Translation::convert($replacements, Api\Translation::charset(), $charset);
973 972
 		}
974 973
 
975 974
 		// Date only placeholders for timestamps
976
-		if(is_array($this->date_fields))
975
+		if (is_array($this->date_fields))
977 976
 		{
978
-			foreach($this->date_fields as $field)
977
+			foreach ($this->date_fields as $field)
979 978
 			{
980
-				if(($value = $replacements['$$'.$field.'$$']))
979
+				if (($value = $replacements['$$'.$field.'$$']))
981 980
 				{
982 981
 					$time = Api\DateTime::createFromFormat('+'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.'*', $value);
983
-					$replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat)  : '';
982
+					$replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat) : '';
984 983
 				}
985 984
 			}
986 985
 		}
@@ -994,66 +993,66 @@  discard block
 block discarded – undo
994 993
 			// only keep tags, if we have xsl extension available
995 994
 			if (class_exists(XSLTProcessor) && class_exists(DOMDocument) && $this->parse_html_styles)
996 995
 			{
997
-				switch($mimetype.$mso_application_progid)
996
+				switch ($mimetype.$mso_application_progid)
998 997
 				{
999 998
 					case 'text/html':
1000 999
 						$replace_tags = array(
1001
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
1002
-							'<table>','<tr>','<td>','<a>','<style>',
1000
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
1001
+							'<table>', '<tr>', '<td>', '<a>', '<style>',
1003 1002
 						);
1004 1003
 						break;
1005 1004
 					case 'application/vnd.oasis.opendocument.text':		// open office
1006 1005
 					case 'application/vnd.oasis.opendocument.spreadsheet':
1007 1006
 						$replace_tags = array(
1008
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
1009
-							'<table>','<tr>','<td>','<a>',
1007
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
1008
+							'<table>', '<tr>', '<td>', '<a>',
1010 1009
 						);
1011 1010
 						break;
1012 1011
 					case 'application/xmlWord.Document':	// Word 2003*/
1013 1012
 					case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':	// ms office 2007
1014 1013
 					case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1015 1014
 						$replace_tags = array(
1016
-							'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
1017
-							'<table>','<tr>','<td>',
1015
+							'<b>', '<strong>', '<i>', '<em>', '<u>', '<span>', '<ol>', '<ul>', '<li>',
1016
+							'<table>', '<tr>', '<td>',
1018 1017
 						);
1019 1018
 						break;
1020 1019
 				}
1021 1020
 			}
1022 1021
 			// clean replacements from array values and html or html-entities, which mess up xml
1023
-			foreach($replacements as $name => &$value)
1022
+			foreach ($replacements as $name => &$value)
1024 1023
 			{
1025 1024
 				// set unresolved array values to empty string
1026
-				if(is_array($value))
1025
+				if (is_array($value))
1027 1026
 				{
1028 1027
 					$value = '';
1029 1028
 					continue;
1030 1029
 				}
1031 1030
 				// decode html entities back to utf-8
1032 1031
 
1033
-				if (is_string($value) && (strpos($value,'&') !== false) && $this->parse_html_styles)
1032
+				if (is_string($value) && (strpos($value, '&') !== false) && $this->parse_html_styles)
1034 1033
 				{
1035
-					$value = html_entity_decode($value,ENT_QUOTES,$charset);
1034
+					$value = html_entity_decode($value, ENT_QUOTES, $charset);
1036 1035
 
1037 1036
 					// remove all non-decodable entities
1038
-					if (strpos($value,'&') !== false)
1037
+					if (strpos($value, '&') !== false)
1039 1038
 					{
1040
-						$value = preg_replace('/&[^; ]+;/','',$value);
1039
+						$value = preg_replace('/&[^; ]+;/', '', $value);
1041 1040
 					}
1042 1041
 				}
1043 1042
 
1044
-				if(!$this->parse_html_styles)
1043
+				if (!$this->parse_html_styles)
1045 1044
 				{
1046 1045
 					// Encode special chars so they don't break the file
1047
-					$value = htmlspecialchars($value,ENT_NOQUOTES);
1046
+					$value = htmlspecialchars($value, ENT_NOQUOTES);
1048 1047
 				}
1049
-				else if (is_string($value) && (strpos($value,'<') !== false))
1048
+				else if (is_string($value) && (strpos($value, '<') !== false))
1050 1049
 				{
1051 1050
 					// Clean HTML, if it's being kept
1052
-					if($replace_tags && extension_loaded('tidy')) {
1051
+					if ($replace_tags && extension_loaded('tidy')) {
1053 1052
 						$tidy = new tidy();
1054 1053
 						$cleaned = $tidy->repairString($value, self::$tidy_config);
1055 1054
 						// Found errors. Strip it all so there's some output
1056
-						if($tidy->getStatus() == 2)
1055
+						if ($tidy->getStatus() == 2)
1057 1056
 						{
1058 1057
 							error_log($tidy->errorBuffer);
1059 1058
 							$value = strip_tags($value);
@@ -1064,52 +1063,52 @@  discard block
 block discarded – undo
1064 1063
 						}
1065 1064
 					}
1066 1065
 					// replace </p> and <br /> with CRLF (remove <p> and CRLF)
1067
-					$value = strip_tags(str_replace(array("\r","\n",'<p>','</p>','<div>','</div>','<br />'),
1068
-						array('','','',"\r\n",'',"\r\n","\r\n"), $value),
1066
+					$value = strip_tags(str_replace(array("\r", "\n", '<p>', '</p>', '<div>', '</div>', '<br />'),
1067
+						array('', '', '', "\r\n", '', "\r\n", "\r\n"), $value),
1069 1068
 						implode('', $replace_tags));
1070 1069
 
1071 1070
 					// Change <tag>...\r\n</tag> to <tag>...</tag>\r\n or simplistic line break below will mangle it
1072 1071
 					// Loop to catch things like <b><span>Break:\r\n</span></b>
1073
-					if($mso_application_progid)
1072
+					if ($mso_application_progid)
1074 1073
 					{
1075 1074
 						$count = $i = 0;
1076 1075
 						do
1077 1076
 						{
1078
-							$value = preg_replace('/<(b|strong|i|em|u|span)\b([^>]*?)>(.*?)'."\r\n".'<\/\1>/u', '<$1$2>$3</$1>'."\r\n",$value,-1,$count);
1077
+							$value = preg_replace('/<(b|strong|i|em|u|span)\b([^>]*?)>(.*?)'."\r\n".'<\/\1>/u', '<$1$2>$3</$1>'."\r\n", $value, -1, $count);
1079 1078
 							$i++;
1080
-						} while($count > 0 && $i < 10); // Limit of 10 chosen arbitrarily just in case
1079
+						} while ($count > 0 && $i < 10); // Limit of 10 chosen arbitrarily just in case
1081 1080
 					}
1082 1081
 				}
1083 1082
 				// replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space
1084 1083
 				// as they are not allowed in xml
1085
-				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u',' ',$value);
1086
-				if(is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1084
+				$value = preg_replace('/[\000-\010\013\014\016-\037\177-\237]/u', ' ', $value);
1085
+				if (is_numeric($value) && $name != '$$user/account_id$$') // account_id causes problems with the preg_replace below
1087 1086
 				{
1088
-					$names[] = preg_quote($name,'/');
1087
+					$names[] = preg_quote($name, '/');
1089 1088
 				}
1090 1089
 			}
1091 1090
 
1092 1091
 			// Look for numbers, set their value if needed
1093
-			if($this->numeric_fields || count($names))
1092
+			if ($this->numeric_fields || count($names))
1094 1093
 			{
1095
-				foreach((array)$this->numeric_fields as $fieldname) {
1096
-					$names[] = preg_quote($fieldname,'/');
1094
+				foreach ((array)$this->numeric_fields as $fieldname) {
1095
+					$names[] = preg_quote($fieldname, '/');
1097 1096
 				}
1098 1097
 				$this->format_spreadsheet_numbers($content, $names, $mimetype.$mso_application_progid);
1099 1098
 			}
1100 1099
 
1101 1100
 			// Look for dates, set their value if needed
1102
-			if($this->date_fields || count($names))
1101
+			if ($this->date_fields || count($names))
1103 1102
 			{
1104 1103
 				$names = array();
1105
-				foreach((array)$this->date_fields as $fieldname) {
1104
+				foreach ((array)$this->date_fields as $fieldname) {
1106 1105
 					$names[] = $fieldname;
1107 1106
 				}
1108 1107
 				$this->format_spreadsheet_dates($content, $names, $replacements, $mimetype.$mso_application_progid);
1109 1108
 			}
1110 1109
 
1111 1110
 			// replace CRLF with linebreak tag of given type
1112
-			switch($mimetype.$mso_application_progid)
1111
+			switch ($mimetype.$mso_application_progid)
1113 1112
 			{
1114 1113
 				case 'application/vnd.oasis.opendocument.text':		// open office writer
1115 1114
 					$break = '<text:line-break/>';
@@ -1136,14 +1135,14 @@  discard block
 block discarded – undo
1136 1135
 			}
1137 1136
 			// now decode &, < and >, which need to be encoded as entities in xml
1138 1137
 			// Check for encoded >< getting double-encoded
1139
-			if($this->parse_html_styles)
1138
+			if ($this->parse_html_styles)
1140 1139
 			{
1141
-				$replacements = str_replace(array('&',"\r","\n",'&amp;lt;','&amp;gt;'),array('&amp;','',$break,'&lt;','&gt;'),$replacements);
1140
+				$replacements = str_replace(array('&', "\r", "\n", '&amp;lt;', '&amp;gt;'), array('&amp;', '', $break, '&lt;', '&gt;'), $replacements);
1142 1141
 			}
1143 1142
 			else
1144 1143
 			{
1145 1144
 				// Need to at least handle new lines, or it'll be run together on one line
1146
-				$replacements = str_replace(array("\r","\n"),array('',$break),$replacements);
1145
+				$replacements = str_replace(array("\r", "\n"), array('', $break), $replacements);
1147 1146
 			}
1148 1147
 		}
1149 1148
 		if ($mimetype == 'application/x-yaml')
@@ -1154,24 +1153,24 @@  discard block
 block discarded – undo
1154 1153
 				$parts = null;
1155 1154
 				if (preg_match('|^\$\$([^/]+)/([^/]+)/([^$]*)\$\$$|', $matches[3], $parts) && isset($replacements['$$'.$parts[1].'$$']))
1156 1155
 				{
1157
-					$replacement =& $replacements['$$'.$parts[1].'$$'];
1156
+					$replacement = & $replacements['$$'.$parts[1].'$$'];
1158 1157
 					$replacement = preg_replace('/'.$parts[2].'/', strtr($parts[3], array(
1159 1158
 						'\\n' => "\n", '\\r' => "\r", '\\t' => "\t", '\\v' => "\v", '\\\\' => '\\', '\\f' => "\f",
1160 1159
 					)), $replacement);
1161 1160
 				}
1162 1161
 				else
1163 1162
 				{
1164
-					$replacement =& $replacements[$matches[3]];
1163
+					$replacement = & $replacements[$matches[3]];
1165 1164
 				}
1166 1165
 				// replacement with multiple lines --> add same number of space as before placeholder
1167 1166
 				if (isset($replacement))
1168 1167
 				{
1169 1168
 					return $matches[1].$matches[2].implode("\n".$matches[1], preg_split("/\r?\n/", $replacement));
1170 1169
 				}
1171
-				return $matches[0];	// regular replacement below
1170
+				return $matches[0]; // regular replacement below
1172 1171
 			}, $content);
1173 1172
 		}
1174
-		return str_replace(array_keys($replacements),array_values($replacements),$content);
1173
+		return str_replace(array_keys($replacements), array_values($replacements), $content);
1175 1174
 	}
1176 1175
 
1177 1176
 	/**
@@ -1179,36 +1178,36 @@  discard block
 block discarded – undo
1179 1178
 	 */
1180 1179
 	protected function format_spreadsheet_numbers(&$content, $names, $mimetype)
1181 1180
 	{
1182
-		foreach((array)$this->numeric_fields as $fieldname) {
1183
-			$names[] = preg_quote($fieldname,'/');
1181
+		foreach ((array)$this->numeric_fields as $fieldname) {
1182
+			$names[] = preg_quote($fieldname, '/');
1184 1183
 		}
1185
-		switch($mimetype)
1184
+		switch ($mimetype)
1186 1185
 		{
1187 1186
 			case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1188
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>('.implode('|',$names).')<\/\3>.?<\/table:table-cell>/s';
1187
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)(?:calcext:value-type="[^"]+")?>.?<([a-z].*?)[^>]*>('.implode('|', $names).')<\/\3>.?<\/table:table-cell>/s';
1189 1188
 				$replacement = '<table:table-cell$1office:value-type="float" office:value="$4"$2 calcext:value-type="float"><$3>$4</$3></table:table-cell>';
1190 1189
 				break;
1191 1190
 			case 'application/vnd.oasis.opendocument.text':		// tables in open office writer
1192
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>('.implode('|',$names).')<\/\3>.?<\/table:table-cell>/s';
1191
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>('.implode('|', $names).')<\/\3>.?<\/table:table-cell>/s';
1193 1192
 				$replacement = '<table:table-cell$1office:value-type="float" office:value="$4"$2><text:p text:style-name="Standard">$4</text:p></table:table-cell>';
1194 1193
 				break;
1195 1194
 			case 'application/vnd.oasis.opendocument.text':		// open office writer
1196 1195
 			case 'application/xmlExcel.Sheet':	// Excel 2003
1197
-				$format = '/'.preg_quote('<Data ss:Type="String">','/').'('.implode('|',$names).')'.preg_quote('</Data>','/').'/';
1196
+				$format = '/'.preg_quote('<Data ss:Type="String">', '/').'('.implode('|', $names).')'.preg_quote('</Data>', '/').'/';
1198 1197
 				$replacement = '<Data ss:Type="Number">$1</Data>';
1199 1198
 
1200 1199
 				break;
1201 1200
 		}
1202
-		if($format && $names)
1201
+		if ($format && $names)
1203 1202
 		{
1204 1203
 			// Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs
1205 1204
 			do {
1206 1205
 				$result = preg_replace($format, $replacement, $content, -1);
1207 1206
 			}
1208 1207
 			// try to increase/double pcre.backtrack_limit failure
1209
-			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1208
+			while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1210 1209
 
1211
-			if ($result) $content = $result;  // On failure $result would be NULL
1210
+			if ($result) $content = $result; // On failure $result would be NULL
1212 1211
 		}
1213 1212
 	}
1214 1213
 
@@ -1219,7 +1218,7 @@  discard block
 block discarded – undo
1219 1218
 	 */
1220 1219
 	protected static function increase_backtrack_limit()
1221 1220
 	{
1222
-		static $backtrack_limit=null,$memory_limit=null;
1221
+		static $backtrack_limit = null, $memory_limit = null;
1223 1222
 		if (!isset($backtrack_limit))
1224 1223
 		{
1225 1224
 			$backtrack_limit = ini_get('pcre.backtrack_limit');
@@ -1227,16 +1226,16 @@  discard block
 block discarded – undo
1227 1226
 		if (!isset($memory_limit))
1228 1227
 		{
1229 1228
 			$memory_limit = ini_get('memory_limit');
1230
-			switch(strtoupper(substr($memory_limit, -1)))
1229
+			switch (strtoupper(substr($memory_limit, -1)))
1231 1230
 			{
1232 1231
 				case 'G': $memory_limit *= 1024;
1233 1232
 				case 'M': $memory_limit *= 1024;
1234 1233
 				case 'K': $memory_limit *= 1024;
1235 1234
 			}
1236 1235
 		}
1237
-		if ($backtrack_limit < $memory_limit/8)
1236
+		if ($backtrack_limit < $memory_limit / 8)
1238 1237
 		{
1239
-			ini_set( 'pcre.backtrack_limit', $backtrack_limit*=2);
1238
+			ini_set('pcre.backtrack_limit', $backtrack_limit *= 2);
1240 1239
 			return true;
1241 1240
 		}
1242 1241
 		error_log("pcre.backtrack_limit exceeded @ $backtrack_limit, some cells left as text.");
@@ -1248,32 +1247,32 @@  discard block
 block discarded – undo
1248 1247
 	 */
1249 1248
 	protected function format_spreadsheet_dates(&$content, $names, &$values, $mimetype)
1250 1249
 	{
1251
-		if(!in_array($mimetype, array(
1252
-			'application/vnd.oasis.opendocument.spreadsheet',		// open office calc
1253
-			'application/xmlExcel.Sheet',					// Excel 2003
1250
+		if (!in_array($mimetype, array(
1251
+			'application/vnd.oasis.opendocument.spreadsheet', // open office calc
1252
+			'application/xmlExcel.Sheet', // Excel 2003
1254 1253
 			//'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF
1255 1254
 		))) return;
1256 1255
 
1257 1256
 		// Some different formats dates could be in, depending what they've been through
1258 1257
 		$formats = array(
1259
-			'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat.':s',
1260
-			'!'.Api\DateTime::$user_dateformat . '*' .Api\DateTime::$user_timeformat.':s',
1261
-			'!'.Api\DateTime::$user_dateformat . '* ' .Api\DateTime::$user_timeformat,
1262
-			'!'.Api\DateTime::$user_dateformat . '*',
1258
+			'!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.':s',
1259
+			'!'.Api\DateTime::$user_dateformat.'*'.Api\DateTime::$user_timeformat.':s',
1260
+			'!'.Api\DateTime::$user_dateformat.'* '.Api\DateTime::$user_timeformat,
1261
+			'!'.Api\DateTime::$user_dateformat.'*',
1263 1262
 			'!'.Api\DateTime::$user_dateformat,
1264 1263
 		);
1265 1264
 
1266 1265
 		// Properly format values for spreadsheet
1267
-		foreach($names as $idx => &$field)
1266
+		foreach ($names as $idx => &$field)
1268 1267
 		{
1269 1268
 			$key = '$$'.$field.'$$';
1270 1269
 			$field = preg_quote($field, '/');
1271
-			if($values[$key])
1270
+			if ($values[$key])
1272 1271
 			{
1273
-				if(!is_numeric($values[$key]))
1272
+				if (!is_numeric($values[$key]))
1274 1273
 				{
1275 1274
 					// Try the different formats, stop when one works
1276
-					foreach($formats as $f)
1275
+					foreach ($formats as $f)
1277 1276
 					{
1278 1277
 						try {
1279 1278
 							$date = Api\DateTime::createFromFormat(
@@ -1281,12 +1280,12 @@  discard block
 block discarded – undo
1281 1280
 								$values[$key],
1282 1281
 								Api\DateTime::$user_timezone
1283 1282
 							);
1284
-							if($date) break;
1283
+							if ($date) break;
1285 1284
 						} catch (\Exception $e) {
1286 1285
 
1287 1286
 						}
1288 1287
 					}
1289
-					if(!$date)
1288
+					if (!$date)
1290 1289
 					{
1291 1290
 						// Couldn't get a date out of it... skip it
1292 1291
 						trigger_error("Unable to parse date $key = '{$values[$key]}' - left as text", E_USER_NOTICE);
@@ -1298,16 +1297,16 @@  discard block
 block discarded – undo
1298 1297
 				{
1299 1298
 					$date = new Api\DateTime($values[$key]);
1300 1299
 				}
1301
-				if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')//Excel WTF
1300
+				if ($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')//Excel WTF
1302 1301
 				{
1303 1302
 					$interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
1304
-					$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
1303
+					$values[$key] = $interval->format('%a') + 1; // 1900-02-29 did not exist
1305 1304
 					// 1440 minutes in a day - fractional part
1306
-					$values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440;
1305
+					$values[$key] += ($date->format('H') * 60 + $date->format('i')) / 1440;
1307 1306
 				}
1308 1307
 				else
1309 1308
 				{
1310
-					$values[$key] = date('Y-m-d\TH:i:s',Api\DateTime::to($date,'ts'));
1309
+					$values[$key] = date('Y-m-d\TH:i:s', Api\DateTime::to($date, 'ts'));
1311 1310
 				}
1312 1311
 			}
1313 1312
 			else
@@ -1316,33 +1315,33 @@  discard block
 block discarded – undo
1316 1315
 			}
1317 1316
 		}
1318 1317
 
1319
-		switch($mimetype)
1318
+		switch ($mimetype)
1320 1319
 		{
1321 1320
 			case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1322 1321
 				// Removing these forces calc to respect our set value-type
1323
-				$content = str_ireplace('calcext:value-type="string"','',$content);
1322
+				$content = str_ireplace('calcext:value-type="string"', '', $content);
1324 1323
 
1325
-				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|',$names).')\$\$<\/\3>.?<\/table:table-cell>/s';
1324
+				$format = '/<table:table-cell([^>]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|', $names).')\$\$<\/\3>.?<\/table:table-cell>/s';
1326 1325
 				$replacement = '<table:table-cell$1office:value-type="date" office:date-value="\$\$$4\$\$"$2><$3>\$\$$4\$\$</$3></table:table-cell>';
1327 1326
 				break;
1328 1327
 			case 'application/xmlExcel.Sheet':	// Excel 2003
1329
-				$format = '/'.preg_quote('<Data ss:Type="String">','/').'..('.implode('|',$names).')..'.preg_quote('</Data>','/').'/';
1328
+				$format = '/'.preg_quote('<Data ss:Type="String">', '/').'..('.implode('|', $names).')..'.preg_quote('</Data>', '/').'/';
1330 1329
 				$replacement = '<Data ss:Type="DateTime">\$\$$1\$\$</Data>';
1331 1330
 
1332 1331
 				break;
1333 1332
 			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1334 1333
 				break;
1335 1334
 		}
1336
-		if($format && $names)
1335
+		if ($format && $names)
1337 1336
 		{
1338 1337
 			// Dealing with backtrack limit per AmigoJack 10-Jul-2010 comment on php.net preg-replace docs
1339 1338
 			do {
1340 1339
 				$result = preg_replace($format, $replacement, $content, -1);
1341 1340
 			}
1342 1341
 			// try to increase/double pcre.backtrack_limit failure
1343
-			while(preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1342
+			while (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR && self::increase_backtrack_limit());
1344 1343
 
1345
-			if ($result) $content = $result;  // On failure $result would be NULL
1344
+			if ($result) $content = $result; // On failure $result would be NULL
1346 1345
 		}
1347 1346
 	}
1348 1347
 
@@ -1352,9 +1351,9 @@  discard block
 block discarded – undo
1352 1351
 	 */
1353 1352
 	public function cf_link_to_expand($values, $content, &$replacements, $app = null)
1354 1353
 	{
1355
-		if($app == null)
1354
+		if ($app == null)
1356 1355
 		{
1357
-			$app = str_replace('_merge','',get_class($this));
1356
+			$app = str_replace('_merge', '', get_class($this));
1358 1357
 		}
1359 1358
 		$cfs = Api\Storage\Customfields::get($app);
1360 1359
 
@@ -1365,13 +1364,13 @@  discard block
 block discarded – undo
1365 1364
 		// Placeholders that need expanded will look like {{#name/placeholder}}
1366 1365
 		$matches = null;
1367 1366
 		preg_match_all('/\${2}(([^\/#]*?\/)?)#([^$\/]+)\/(.*?)[$}]{2}/', $content, $matches);
1368
-		list($placeholders, , , $cf, $sub) = $matches;
1367
+		list($placeholders,,, $cf, $sub) = $matches;
1369 1368
 
1370
-		foreach($cf as $index => $field)
1369
+		foreach ($cf as $index => $field)
1371 1370
 		{
1372
-			if($cfs[$field])
1371
+			if ($cfs[$field])
1373 1372
 			{
1374
-				if(in_array($cfs[$field]['type'],array_keys($GLOBALS['egw_info']['apps'])))
1373
+				if (in_array($cfs[$field]['type'], array_keys($GLOBALS['egw_info']['apps'])))
1375 1374
 				{
1376 1375
 					$field_app = $cfs[$field]['type'];
1377 1376
 				}
@@ -1382,7 +1381,7 @@  discard block
 block discarded – undo
1382 1381
 					$account = $GLOBALS['egw']->accounts->read($values['#'.$field]);
1383 1382
 					$app_replacements[$field] = $this->contact_replacements($account['person_id']);
1384 1383
 				}
1385
-				else if (($list = explode('-',$cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps']))))
1384
+				else if (($list = explode('-', $cfs[$field]['type']) && in_array($list[0], array_keys($GLOBALS['egw_info']['apps']))))
1386 1385
 				{
1387 1386
 					// Sub-type - use app
1388 1387
 					$field_app = $list[0];
@@ -1393,7 +1392,7 @@  discard block
 block discarded – undo
1393 1392
 				}
1394 1393
 
1395 1394
 				// Get replacements for that application
1396
-				if(!$app_replacements[$field])
1395
+				if (!$app_replacements[$field])
1397 1396
 				{
1398 1397
 					$classname = "{$field_app}_merge";
1399 1398
 					$class = new $classname();
@@ -1421,33 +1420,33 @@  discard block
 block discarded – undo
1421 1420
 	 */
1422 1421
 	private function process_commands($content, $replacements)
1423 1422
 	{
1424
-		if (strpos($content,'$$IF') !== false)
1423
+		if (strpos($content, '$$IF') !== false)
1425 1424
 		{	//Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
1426
-			$this->replacements =& $replacements;
1427
-			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1425
+			$this->replacements = & $replacements;
1426
+			$content = preg_replace_callback('/\$\$IF ([#0-9a-z_\/-]+)~(.*)~(.*)~(.*)\$\$/imU', Array($this, 'replace_callback'), $content);
1428 1427
 			unset($this->replacements);
1429 1428
 		}
1430
-		if (strpos($content,'$$NELF') !== false)
1429
+		if (strpos($content, '$$NELF') !== false)
1431 1430
 		{	//Example: $$NEPBR org_unit$$ sets a LF and value of org_unit, only if there is a value
1432
-			$this->replacements =& $replacements;
1433
-			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1431
+			$this->replacements = & $replacements;
1432
+			$content = preg_replace_callback('/\$\$NELF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content);
1434 1433
 			unset($this->replacements);
1435 1434
 		}
1436
-		if (strpos($content,'$$NENVLF') !== false)
1435
+		if (strpos($content, '$$NENVLF') !== false)
1437 1436
 		{	//Example: $$NEPBRNV org_unit$$ sets only a LF if there is a value for org_units, but did not add any value
1438
-			$this->replacements =& $replacements;
1439
-			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU',Array($this,'replace_callback'),$content);
1437
+			$this->replacements = & $replacements;
1438
+			$content = preg_replace_callback('/\$\$NENVLF ([#0-9a-z_\/-]+)\$\$/imU', Array($this, 'replace_callback'), $content);
1440 1439
 			unset($this->replacements);
1441 1440
 		}
1442
-		if (strpos($content,'$$LETTERPREFIX$$') !== false)
1441
+		if (strpos($content, '$$LETTERPREFIX$$') !== false)
1443 1442
 		{	//Example use to use: $$LETTERPREFIX$$
1444 1443
 			$LETTERPREFIXCUSTOM = '$$LETTERPREFIXCUSTOM n_prefix title n_family$$';
1445
-			$content = str_replace('$$LETTERPREFIX$$',$LETTERPREFIXCUSTOM,$content);
1444
+			$content = str_replace('$$LETTERPREFIX$$', $LETTERPREFIXCUSTOM, $content);
1446 1445
 		}
1447
-		if (strpos($content,'$$LETTERPREFIXCUSTOM') !== false)
1446
+		if (strpos($content, '$$LETTERPREFIXCUSTOM') !== false)
1448 1447
 		{	//Example use to use for a custom Letter Prefix: $$LETTERPREFIX n_prefix title n_family$$
1449
-			$this->replacements =& $replacements;
1450
-			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU',Array($this,'replace_callback'),$content);
1448
+			$this->replacements = & $replacements;
1449
+			$content = preg_replace_callback('/\$\$LETTERPREFIXCUSTOM ([#0-9a-z_-]+)(.*)\$\$/imU', Array($this, 'replace_callback'), $content);
1451 1450
 			unset($this->replacements);
1452 1451
 		}
1453 1452
 		return $content;
@@ -1461,16 +1460,16 @@  discard block
 block discarded – undo
1461 1460
 	 */
1462 1461
 	private function replace_callback($param)
1463 1462
 	{
1464
-		if (array_key_exists('$$'.$param[4].'$$',$this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1465
-		if (array_key_exists('$$'.$param[3].'$$',$this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1463
+		if (array_key_exists('$$'.$param[4].'$$', $this->replacements)) $param[4] = $this->replacements['$$'.$param[4].'$$'];
1464
+		if (array_key_exists('$$'.$param[3].'$$', $this->replacements)) $param[3] = $this->replacements['$$'.$param[3].'$$'];
1466 1465
 
1467 1466
 		$pattern = '/'.preg_quote($param[2], '/').'/';
1468
-		if (strpos($param[0],'$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
1467
+		if (strpos($param[0], '$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === ''))
1469 1468
 		{
1470 1469
 			$pattern = '/^$/';
1471 1470
 		}
1472
-		$replace = preg_match($pattern,$this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4];
1473
-		switch($this->mimetype)
1471
+		$replace = preg_match($pattern, $this->replacements['$$'.$param[1].'$$']) ? $param[3] : $param[4];
1472
+		switch ($this->mimetype)
1474 1473
 		{
1475 1474
 			case 'application/vnd.oasis.opendocument.text':		// open office
1476 1475
 			case 'application/vnd.oasis.opendocument.spreadsheet':
@@ -1483,14 +1482,14 @@  discard block
 block discarded – undo
1483 1482
 				break;
1484 1483
 		}
1485 1484
 
1486
-		switch($this->mimetype)
1485
+		switch ($this->mimetype)
1487 1486
 			{
1488 1487
 				case 'application/rtf':
1489 1488
 				case 'text/rtf':
1490 1489
 					$LF = '}\par \pard\plain{';
1491 1490
 					break;
1492 1491
 				case 'application/vnd.oasis.opendocument.text':
1493
-					$LF ='<text:line-break/>';
1492
+					$LF = '<text:line-break/>';
1494 1493
 					break;
1495 1494
 				case 'application/vnd.oasis.opendocument.spreadsheet':		// open office calc
1496 1495
 					$LF = '</text:p><text:p>';
@@ -1500,35 +1499,35 @@  discard block
 block discarded – undo
1500 1499
 					break;
1501 1500
 				case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
1502 1501
 				case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
1503
-					$LF ='</w:t></w:r></w:p><w:p><w:r><w:t>';
1502
+					$LF = '</w:t></w:r></w:p><w:p><w:r><w:t>';
1504 1503
 					break;
1505 1504
 				case 'application/xml';
1506
-					$LF ='</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>';
1505
+					$LF = '</w:t></w:r><w:r><w:br w:type="text-wrapping" w:clear="all"/></w:r><w:r><w:t>';
1507 1506
 					break;
1508 1507
 				default:
1509 1508
 					$LF = "\n";
1510 1509
 			}
1511
-		if($is_xml) {
1512
-			$this->replacements = str_replace(array('&','&amp;amp;','<','>',"\r","\n"),array('&amp;','&amp;','&lt;','&gt;','',$LF),$this->replacements);
1510
+		if ($is_xml) {
1511
+			$this->replacements = str_replace(array('&', '&amp;amp;', '<', '>', "\r", "\n"), array('&amp;', '&amp;', '&lt;', '&gt;', '', $LF), $this->replacements);
1513 1512
 		}
1514
-		if (strpos($param[0],'$$NELF') === 0)
1513
+		if (strpos($param[0], '$$NELF') === 0)
1515 1514
 		{	//sets a Pagebreak and value, only if the field has a value
1516
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1515
+			if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF.$this->replacements['$$'.$param[1].'$$'];
1517 1516
 		}
1518
-		if (strpos($param[0],'$$NENVLF') === 0)
1517
+		if (strpos($param[0], '$$NENVLF') === 0)
1519 1518
 		{	//sets a Pagebreak without any value, only if the field has a value
1520
-			if ($this->replacements['$$'.$param[1].'$$'] !='') $replace = $LF;
1519
+			if ($this->replacements['$$'.$param[1].'$$'] != '') $replace = $LF;
1521 1520
 		}
1522
-		if (strpos($param[0],'$$LETTERPREFIXCUSTOM') === 0)
1521
+		if (strpos($param[0], '$$LETTERPREFIXCUSTOM') === 0)
1523 1522
 		{	//sets a Letterprefix
1524 1523
 			$replaceprefixsort = array();
1525 1524
 			// ToDo Stefan: $contentstart is NOT defined here!!!
1526
-			$replaceprefix = explode(' ',substr($param[0],21,-2));
1525
+			$replaceprefix = explode(' ', substr($param[0], 21, -2));
1527 1526
 			foreach ($replaceprefix as $nameprefix)
1528 1527
 			{
1529
-				if ($this->replacements['$$'.$nameprefix.'$$'] !='') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1528
+				if ($this->replacements['$$'.$nameprefix.'$$'] != '') $replaceprefixsort[] = $this->replacements['$$'.$nameprefix.'$$'];
1530 1529
 			}
1531
-			$replace = implode($replaceprefixsort,' ');
1530
+			$replace = implode($replaceprefixsort, ' ');
1532 1531
 		}
1533 1532
 		return $replace;
1534 1533
 	}
@@ -1542,7 +1541,7 @@  discard block
 block discarded – undo
1542 1541
 	 * @param string $dirs comma or whitespace separated directories, used if $document is a relative path
1543 1542
 	 * @return string with error-message on error, otherwise it does NOT return
1544 1543
 	 */
1545
-	public function download($document, $ids, $name='', $dirs='')
1544
+	public function download($document, $ids, $name = '', $dirs = '')
1546 1545
 	{
1547 1546
 		//error_log(__METHOD__."('$document', ".array2string($ids).", '$name', dirs='$dirs') ->".function_backtrace());
1548 1547
 		if (($error = $this->check_document($document, $dirs)))
@@ -1558,7 +1557,7 @@  discard block
 block discarded – undo
1558 1557
 				$mail_bo->openConnection();
1559 1558
 				try
1560 1559
 				{
1561
-					$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder='');
1560
+					$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder = '');
1562 1561
 				}
1563 1562
 				catch (Api\Exception\WrongUserinput $e)
1564 1563
 				{
@@ -1567,39 +1566,39 @@  discard block
 block discarded – undo
1567 1566
 				}
1568 1567
 				//error_log(__METHOD__.__LINE__.' Message after importMessageToMergeAndSend:'.array2string($msgs));
1569 1568
 				$retString = '';
1570
-				if (count($msgs['success'])>0) $retString .= count($msgs['success']).' '.(count($msgs['success'])+count($msgs['failed'])==1?lang('Message prepared for sending.'):lang('Message(s) send ok.'));//implode('<br />',$msgs['success']);
1569
+				if (count($msgs['success']) > 0) $retString .= count($msgs['success']).' '.(count($msgs['success']) + count($msgs['failed']) == 1 ? lang('Message prepared for sending.') : lang('Message(s) send ok.')); //implode('<br />',$msgs['success']);
1571 1570
 				//if (strlen($retString)>0) $retString .= '<br />';
1572
-				foreach($msgs['failed'] as $c =>$e)
1571
+				foreach ($msgs['failed'] as $c =>$e)
1573 1572
 				{
1574 1573
 					$errorString .= lang('contact').' '.lang('id').':'.$c.'->'.$e.'.';
1575 1574
 				}
1576
-				if (count($msgs['failed'])>0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1575
+				if (count($msgs['failed']) > 0) $retString .= count($msgs['failed']).' '.lang('Message(s) send failed!').'=>'.$errorString;
1577 1576
 				return $retString;
1578 1577
 			case 'application/vnd.oasis.opendocument.text':
1579 1578
 			case 'application/vnd.oasis.opendocument.spreadsheet':
1580 1579
 				$ext = $mimetype == 'application/vnd.oasis.opendocument.text' ? '.odt' : '.ods';
1581
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,$ext).'-').$ext;
1582
-				copy($content_url,$archive);
1580
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, $ext).'-').$ext;
1581
+				copy($content_url, $archive);
1583 1582
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'content.xml');
1584 1583
 				$this->parse_html_styles = true;
1585 1584
 				break;
1586 1585
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d':	// mimetypes in vfs are limited to 64 chars
1587 1586
 				$mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
1588 1587
 			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
1589
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.docx').'-').'.docx';
1590
-				copy($content_url,$archive);
1588
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.docx').'-').'.docx';
1589
+				copy($content_url, $archive);
1591 1590
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml');
1592 1591
 				$fix = array(		// regular expression to fix garbled placeholders
1593
-					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1594
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$$\\1$$',
1595
-					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="','/').
1596
-						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>','/').'([a-z0-9_]+)'.
1597
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="','/').
1598
-						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$','/').'/i' => '$$\\2$$',
1599
-					'/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1600
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$\\1$',
1601
-					'/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>','/').'([a-z0-9_]+)'.
1602
-						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>','/').'/i' => '$ $\\1$ $',
1592
+					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1593
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$$\\1$$',
1594
+					'/'.preg_quote('$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="', '/').
1595
+						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>', '/').'([a-z0-9_]+)'.
1596
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="', '/').
1597
+						'([a-z]{2}-[A-Z]{2})'.preg_quote('"/></w:rPr><w:t>$$', '/').'/i' => '$$\\2$$',
1598
+					'/'.preg_quote('$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1599
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$\\1$',
1600
+					'/'.preg_quote('$ $</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>', '/').'([a-z0-9_]+)'.
1601
+						preg_quote('</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>', '/').'/i' => '$ $\\1$ $',
1603 1602
 				);
1604 1603
 				break;
1605 1604
 			case 'application/xml':
@@ -1613,13 +1612,13 @@  discard block
 block discarded – undo
1613 1612
 				$fix = array(	// hack to get Excel 2007 to display additional rows in tables
1614 1613
 					'/ss:ExpandedRowCount="\d+"/' => 'ss:ExpandedRowCount="9999"',
1615 1614
 				);
1616
-				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.xlsx').'-').'.xlsx';
1617
-				copy($content_url,$archive);
1615
+				$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document, '.xlsx').'-').'.xlsx';
1616
+				copy($content_url, $archive);
1618 1617
 				$content_url = 'zip://'.$archive.'#'.($content_file = 'xl/sharedStrings.xml');
1619 1618
 				break;
1620 1619
 		}
1621 1620
 		$err = null;
1622
-		if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
1621
+		if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix)))
1623 1622
 		{
1624 1623
 			//error_log(__METHOD__."() !this->merge() err=$err");
1625 1624
 			return $err;
@@ -1636,22 +1635,22 @@  discard block
 block discarded – undo
1636 1635
 			{
1637 1636
 				// Error converting HTML styles over
1638 1637
 				error_log($e->getMessage());
1639
-				error_log("Target document: $content_url, IDs: ". array2string($ids));
1638
+				error_log("Target document: $content_url, IDs: ".array2string($ids));
1640 1639
 
1641 1640
 				// Try again, but strip HTML so user gets something
1642 1641
 				$this->parse_html_styles = false;
1643
-				if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
1642
+				if (!($merged = & $this->merge($content_url, $ids, $err, $mimetype, $fix)))
1644 1643
 				{
1645 1644
 					return $err;
1646 1645
 				}
1647 1646
 			}
1648 1647
 			if ($this->report_memory_usage) error_log(__METHOD__."() after HTML processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1649 1648
 		}
1650
-		if(!empty($name))
1649
+		if (!empty($name))
1651 1650
 		{
1652
-			if(empty($ext))
1651
+			if (empty($ext))
1653 1652
 			{
1654
-				$ext = '.'.pathinfo($document,PATHINFO_EXTENSION);
1653
+				$ext = '.'.pathinfo($document, PATHINFO_EXTENSION);
1655 1654
 			}
1656 1655
 			$name .= $ext;
1657 1656
 		}
@@ -1667,30 +1666,30 @@  discard block
 block discarded – undo
1667 1666
 				error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
1668 1667
 				if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
1669 1668
 			}
1670
-			if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1669
+			if ($zip->addFromString($content_file, $merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
1671 1670
 			if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
1672 1671
 			unset($zip);
1673 1672
 			unset($merged);
1674
-			if (substr($mimetype,0,35) == 'application/vnd.oasis.opendocument.' && 			// only open office archives need that, ms word files brake
1675
-				file_exists('/usr/bin/zip') && version_compare(PHP_VERSION,'5.3.1','<'))	// fix broken zip archives generated by current php
1673
+			if (substr($mimetype, 0, 35) == 'application/vnd.oasis.opendocument.' && // only open office archives need that, ms word files brake
1674
+				file_exists('/usr/bin/zip') && version_compare(PHP_VERSION, '5.3.1', '<'))	// fix broken zip archives generated by current php
1676 1675
 			{
1677 1676
 				exec('/usr/bin/zip -F '.escapeshellarg($archive));
1678 1677
 			}
1679 1678
 			if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
1680
-			Api\Header\Content::type($name,$mimetype,filesize($archive));
1681
-			readfile($archive,'r');
1679
+			Api\Header\Content::type($name, $mimetype, filesize($archive));
1680
+			readfile($archive, 'r');
1682 1681
 		}
1683 1682
 		else
1684 1683
 		{
1685 1684
 			if ($mimetype == 'application/xml')
1686 1685
 			{
1687
-				if (strpos($merged,'<?mso-application progid="Word.Document"?>') !== false)
1686
+				if (strpos($merged, '<?mso-application progid="Word.Document"?>') !== false)
1688 1687
 				{
1689
-					$mimetype = 'application/msword';	// to open it automatically in word or oowriter
1688
+					$mimetype = 'application/msword'; // to open it automatically in word or oowriter
1690 1689
 				}
1691
-				elseif (strpos($merged,'<?mso-application progid="Excel.Sheet"?>') !== false)
1690
+				elseif (strpos($merged, '<?mso-application progid="Excel.Sheet"?>') !== false)
1692 1691
 				{
1693
-					$mimetype = 'application/vnd.ms-excel';	// to open it automatically in excel or oocalc
1692
+					$mimetype = 'application/vnd.ms-excel'; // to open it automatically in excel or oocalc
1694 1693
 				}
1695 1694
 			}
1696 1695
 			Api\Header\Content::type($name, $mimetype);
@@ -1711,13 +1710,13 @@  discard block
 block discarded – undo
1711 1710
 	 */
1712 1711
 	public function download_by_request()
1713 1712
 	{
1714
-		if(empty($_POST['data_document_name'])) return false;
1715
-		if(empty($_POST['data_document_dir'])) return false;
1716
-		if(empty($_POST['data_checked'])) return false;
1713
+		if (empty($_POST['data_document_name'])) return false;
1714
+		if (empty($_POST['data_document_dir'])) return false;
1715
+		if (empty($_POST['data_checked'])) return false;
1717 1716
 
1718 1717
 		return $this->download(
1719 1718
 			$_POST['data_document_name'],
1720
-			explode(',',$_POST['data_checked']),
1719
+			explode(',', $_POST['data_checked']),
1721 1720
 			'',
1722 1721
 			$_POST['data_document_dir']
1723 1722
 		);
@@ -1731,18 +1730,18 @@  discard block
 block discarded – undo
1731 1730
 	 * @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
1732 1731
 	 * @return array List of documents, suitable for a selectbox.  The key is document_<filename>.
1733 1732
 	 */
1734
-	public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
1733
+	public static function get_documents($dirs, $prefix = 'document_', $mime_filter = null, $app = '')
1735 1734
 	{
1736
-		$export_limit=self::getExportLimit($app);
1737
-		if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1735
+		$export_limit = self::getExportLimit($app);
1736
+		if (!$dirs || (!self::hasExportLimit($export_limit, 'ISALLOWED') && !self::is_export_limit_excepted())) return array();
1738 1737
 
1739 1738
 		// split multiple comma or whitespace separated directories
1740 1739
 		// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1741 1740
 		if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1)
1742 1741
 		{
1743
-			foreach($dirs as $n => &$d)
1742
+			foreach ($dirs as $n => &$d)
1744 1743
 			{
1745
-				if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1744
+				if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
1746 1745
 			}
1747 1746
 		}
1748 1747
 		if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
@@ -1757,15 +1756,15 @@  discard block
 block discarded – undo
1757 1756
 			}
1758 1757
 		}
1759 1758
 		$list = array();
1760
-		foreach($dirs as $dir)
1759
+		foreach ($dirs as $dir)
1761 1760
 		{
1762
-			if (($files = Api\Vfs::find($dir,array('need_mime'=>true),true)))
1761
+			if (($files = Api\Vfs::find($dir, array('need_mime'=>true), true)))
1763 1762
 			{
1764
-				foreach($files as $file)
1763
+				foreach ($files as $file)
1765 1764
 				{
1766 1765
 					// return only the mime-types we support
1767
-					$parts = explode('.',$file['name']);
1768
-					if (!self::is_implemented($file['mime'],'.'.array_pop($parts))) continue;
1766
+					$parts = explode('.', $file['name']);
1767
+					if (!self::is_implemented($file['mime'], '.'.array_pop($parts))) continue;
1769 1768
 					if ($mime_filter && $negativ_filter === in_array($file['mime'], (array)$mime_filter)) continue;
1770 1769
 					$list[$prefix.$file['name']] = Api\Vfs::decodePath($file['name']);
1771 1770
 				}
@@ -1792,14 +1791,14 @@  discard block
 block discarded – undo
1792 1791
 	 * @param int|string $export_limit =null export-limit, default $GLOBALS['egw_info']['server']['export_limit']
1793 1792
 	 * @return array see nextmatch_widget::egw_actions
1794 1793
 	 */
1795
-	public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='',
1796
-		$export_limit=null)
1794
+	public static function document_action($dirs, $group = 0, $caption = 'Insert in document', $prefix = 'document_', $default_doc = '',
1795
+		$export_limit = null)
1797 1796
 	{
1798 1797
 		$documents = array();
1799 1798
 		if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
1800 1799
 		if ($default_doc && ($file = Api\Vfs::stat($default_doc)))	// put default document on top
1801 1800
 		{
1802
-			if(!$file['mime'])
1801
+			if (!$file['mime'])
1803 1802
 			{
1804 1803
 				$file['mime'] = Api\Vfs::mime_content_type($default_doc);
1805 1804
 				$file['path'] = $default_doc;
@@ -1808,7 +1807,7 @@  discard block
 block discarded – undo
1808 1807
 				'icon' => Api\Vfs::mime_icon($file['mime']),
1809 1808
 				'caption' => Api\Vfs::decodePath(Api\Vfs::basename($default_doc)),
1810 1809
 				'group' => 1,
1811
-				'postSubmit' => true,	// download needs post submit (not Ajax) to work
1810
+				'postSubmit' => true, // download needs post submit (not Ajax) to work
1812 1811
 			);
1813 1812
 			if ($file['mime'] == 'message/rfc822')
1814 1813
 			{
@@ -1823,28 +1822,28 @@  discard block
 block discarded – undo
1823 1822
 			// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
1824 1823
 			if (count($dirs = preg_split('/[,\s]+\//', $dirs)) > 1)
1825 1824
 			{
1826
-				foreach($dirs as $n => &$d)
1825
+				foreach ($dirs as $n => &$d)
1827 1826
 				{
1828
-					if ($n) $d = '/'.$d;	// re-adding trailing slash removed by split
1827
+					if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
1829 1828
 				}
1830 1829
 			}
1831
-			foreach($dirs as $dir)
1830
+			foreach ($dirs as $dir)
1832 1831
 			{
1833
-				$files += Api\Vfs::find($dir,array(
1832
+				$files += Api\Vfs::find($dir, array(
1834 1833
 					'need_mime' => true,
1835 1834
 					'order' => 'fs_name',
1836 1835
 					'sort' => 'ASC',
1837
-				),true);
1836
+				), true);
1838 1837
 			}
1839 1838
 		}
1840 1839
 
1841 1840
 		$dircount = array();
1842
-		foreach($files as $key => $file)
1841
+		foreach ($files as $key => $file)
1843 1842
 		{
1844 1843
 			// use only the mime-types we support
1845
-			$parts = explode('.',$file['name']);
1846
-			if (!self::is_implemented($file['mime'],'.'.array_pop($parts)) ||
1847
-				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) ||	// remove files not readable by user
1844
+			$parts = explode('.', $file['name']);
1845
+			if (!self::is_implemented($file['mime'], '.'.array_pop($parts)) ||
1846
+				!Api\Vfs::check_access($file['path'], Api\Vfs::READABLE, $file) || // remove files not readable by user
1848 1847
 				$file['path'] === $default_doc)	// default doc already added
1849 1848
 			{
1850 1849
 				unset($files[$key]);
@@ -1852,40 +1851,40 @@  discard block
 block discarded – undo
1852 1851
 			else
1853 1852
 			{
1854 1853
 				$dirname = Api\Vfs::dirname($file['path']);
1855
-				if(!isset($dircount[$dirname]))
1854
+				if (!isset($dircount[$dirname]))
1856 1855
 				{
1857 1856
 					$dircount[$dirname] = 1;
1858 1857
 				}
1859 1858
 				else
1860 1859
 				{
1861
-					$dircount[$dirname] ++;
1860
+					$dircount[$dirname]++;
1862 1861
 				}
1863 1862
 			}
1864 1863
 		}
1865
-		foreach($files as $file)
1864
+		foreach ($files as $file)
1866 1865
 		{
1867 1866
 			if (count($dircount) > 1)
1868 1867
 			{
1869 1868
 				$name_arr = explode('/', $file['name']);
1870 1869
 				$current_level = &$documents;
1871
-				for($count = 0; $count < count($name_arr); $count++)
1870
+				for ($count = 0; $count < count($name_arr); $count++)
1872 1871
 				{
1873
-					if($count == 0)
1872
+					if ($count == 0)
1874 1873
 					{
1875 1874
 						$current_level = &$documents;
1876 1875
 					}
1877 1876
 					else
1878 1877
 					{
1879
-						$current_level = &$current_level[$prefix.$name_arr[($count-1)]]['children'];
1878
+						$current_level = &$current_level[$prefix.$name_arr[($count - 1)]]['children'];
1880 1879
 					}
1881
-					switch($count)
1880
+					switch ($count)
1882 1881
 					{
1883
-						case (count($name_arr)-1):
1882
+						case (count($name_arr) - 1):
1884 1883
 							$current_level[$prefix.$file['name']] = array(
1885 1884
 								'icon'		=> Api\Vfs::mime_icon($file['mime']),
1886 1885
 								'caption'	=> Api\Vfs::decodePath($name_arr[$count]),
1887 1886
 								'group'		=> 2,
1888
-								'postSubmit' => true,	// download needs post submit (not Ajax) to work
1887
+								'postSubmit' => true, // download needs post submit (not Ajax) to work
1889 1888
 							);
1890 1889
 							if ($file['mime'] == 'message/rfc822')
1891 1890
 							{
@@ -1894,7 +1893,7 @@  discard block
 block discarded – undo
1894 1893
 							break;
1895 1894
 
1896 1895
 						default:
1897
-							if(!is_array($current_level[$prefix.$name_arr[$count]]))
1896
+							if (!is_array($current_level[$prefix.$name_arr[$count]]))
1898 1897
 							{
1899 1898
 								// create parent folder
1900 1899
 								$current_level[$prefix.$name_arr[$count]] = array(
@@ -1921,7 +1920,7 @@  discard block
 block discarded – undo
1921 1920
 				}
1922 1921
 				$documents[$file['mime']]['children'][$prefix.$file['name']] = array(
1923 1922
 					'caption' => Api\Vfs::decodePath($file['name']),
1924
-					'postSubmit' => true,	// download needs post submit (not Ajax) to work
1923
+					'postSubmit' => true, // download needs post submit (not Ajax) to work
1925 1924
 				);
1926 1925
 				if ($file['mime'] == 'message/rfc822')
1927 1926
 				{
@@ -1934,7 +1933,7 @@  discard block
 block discarded – undo
1934 1933
 					'icon' => Api\Vfs::mime_icon($file['mime']),
1935 1934
 					'caption' => Api\Vfs::decodePath($file['name']),
1936 1935
 					'group' => 2,
1937
-					'postSubmit' => true,	// download needs post submit (not Ajax) to work
1936
+					'postSubmit' => true, // download needs post submit (not Ajax) to work
1938 1937
 				);
1939 1938
 				if ($file['mime'] == 'message/rfc822')
1940 1939
 				{
@@ -1948,8 +1947,8 @@  discard block
 block discarded – undo
1948 1947
 			'caption' => $caption,
1949 1948
 			'children' => $documents,
1950 1949
 			// disable action if no document or export completly forbidden for non-admins
1951
-			'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit,'ISALLOWED') || self::is_export_limit_excepted()),
1952
-			'hideOnDisabled' => true,	// do not show 'Insert in document', if no documents defined or no export allowed
1950
+			'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit, 'ISALLOWED') || self::is_export_limit_excepted()),
1951
+			'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed
1953 1952
 			'group' => $group,
1954 1953
 		);
1955 1954
 	}
@@ -1980,14 +1979,14 @@  discard block
 block discarded – undo
1980 1979
 		);
1981 1980
 
1982 1981
 		// egw.open() used if only 1 row selected
1983
-		$action['egw_open'] = 'edit-mail--'.implode('&',$extra);
1984
-		$action['target'] = 'compose_' .$file['path'];
1982
+		$action['egw_open'] = 'edit-mail--'.implode('&', $extra);
1983
+		$action['target'] = 'compose_'.$file['path'];
1985 1984
 
1986 1985
 		// long_task runs menuaction once for each selected row
1987 1986
 		$action['nm_action'] = 'long_task';
1988 1987
 		$action['popup'] = Api\Link::get_registry('mail', 'edit_popup');
1989
-		$action['message'] = lang('insert in %1',Api\Vfs::decodePath($file['name']));
1990
-		$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='. get_called_class();
1988
+		$action['message'] = lang('insert in %1', Api\Vfs::decodePath($file['name']));
1989
+		$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='.get_called_class();
1991 1990
 	}
1992 1991
 
1993 1992
 	/**
@@ -1999,15 +1998,15 @@  discard block
 block discarded – undo
1999 1998
 	 */
2000 1999
 	public static function check_document(&$document, $dirs)
2001 2000
 	{
2002
-		if($document[0] !== '/')
2001
+		if ($document[0] !== '/')
2003 2002
 		{
2004 2003
 			// split multiple comma or whitespace separated directories
2005 2004
 			// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
2006 2005
 			if ($dirs && ($dirs = preg_split('/[,\s]+\//', $dirs)))
2007 2006
 			{
2008
-				foreach($dirs as $n => $dir)
2007
+				foreach ($dirs as $n => $dir)
2009 2008
 				{
2010
-					if ($n) $dir = '/'.$dir;	// re-adding trailing slash removed by split
2009
+					if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split
2011 2010
 					if (Api\Vfs::stat($dir.'/'.$document) && Api\Vfs::is_readable($dir.'/'.$document))
2012 2011
 					{
2013 2012
 						$document = $dir.'/'.$document;
@@ -2021,7 +2020,7 @@  discard block
 block discarded – undo
2021 2020
 			return false;
2022 2021
 		}
2023 2022
 		//error_log(__METHOD__."('$document', dirs='$dirs') returning 'Document '$document' does not exist or is not readable for you!'");
2024
-		return lang("Document '%1' does not exist or is not readable for you!",$document);
2023
+		return lang("Document '%1' does not exist or is not readable for you!", $document);
2025 2024
 	}
2026 2025
 
2027 2026
 	/**
@@ -2042,16 +2041,16 @@  discard block
 block discarded – undo
2042 2041
 	 * @param string $_mimetype =''
2043 2042
 	 * @return string
2044 2043
 	 */
2045
-	static public function number_format($number,$num_decimal_places=2,$_mimetype='')
2044
+	static public function number_format($number, $num_decimal_places = 2, $_mimetype = '')
2046 2045
 	{
2047 2046
 		if ((string)$number === '') return '';
2048 2047
 		//error_log(__METHOD__.$_mimetype);
2049
-		switch($_mimetype)
2048
+		switch ($_mimetype)
2050 2049
 		{
2051 2050
 			case 'application/xml':	// Excel 2003
2052 2051
 			case 'application/vnd.oasis.opendocument.spreadsheet': // OO.o spreadsheet
2053
-				return number_format(str_replace(' ','',$number),$num_decimal_places,'.','');
2052
+				return number_format(str_replace(' ', '', $number), $num_decimal_places, '.', '');
2054 2053
 		}
2055
-		return Api\Etemplate::number_format($number,$num_decimal_places);
2054
+		return Api\Etemplate::number_format($number, $num_decimal_places);
2056 2055
 	}
2057 2056
 }
Please login to merge, or discard this patch.
api/src/Storage/Tracking.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
 	 * @param array $data current entry
529 529
 	 * @param array $old = null old/last state of the entry or null for a new entry
530 530
 	 * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted
531
-	 * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified
531
+	 * @param array $email_notified if present will return the emails notified, if given emails in that list will not be notified
532 532
 	 * @return boolean true on success, false on error (error messages are in $this->errors)
533 533
 	 */
534 534
 	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
@@ -824,7 +824,6 @@  discard block
 block discarded – undo
824 824
 	 * The default implementation prefers depending on the prefer_user_as_sender class-var the user over
825 825
 	 * what is returned by get_config('sender').
826 826
 	 *
827
-	 * @param int $user account_lid of user
828 827
 	 * @param array $data
829 828
 	 * @param array $old
830 829
 	 * @param bool $prefer_id returns the userid rather than email
Please login to merge, or discard this patch.
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 	{
195 195
 		if ($cf_app)
196 196
 		{
197
-			$linkable_cf_types = array('link-entry')+array_keys(Api\Link::app_list());
198
-			foreach(Customfields::get($cf_app, true) as $cf_name => $cf_data)
197
+			$linkable_cf_types = array('link-entry') + array_keys(Api\Link::app_list());
198
+			foreach (Customfields::get($cf_app, true) as $cf_name => $cf_data)
199 199
 			{
200 200
 				$this->field2history['#'.$cf_name] = '#'.$cf_name;
201 201
 
202
-				if (in_array($cf_data['type'],$linkable_cf_types))
202
+				if (in_array($cf_data['type'], $linkable_cf_types))
203 203
 				{
204 204
 					$this->cf_link_fields['#'.$cf_name] = $cf_data['type'] == 'link-entry' ? '' : $cf_data['type'];
205 205
 				}
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 * @param int|string $receiver nummeric account_id or email address
217 217
 	 * @return array of details as array with values for keys 'label','value','type'
218 218
 	 */
219
-	function get_details($data,$receiver=null)
219
+	function get_details($data, $receiver = null)
220 220
 	{
221
-		unset($data, $receiver);	// not uses as just a stub
221
+		unset($data, $receiver); // not uses as just a stub
222 222
 
223 223
 		return array();
224 224
 	}
@@ -230,14 +230,14 @@  discard block
 block discarded – undo
230 230
 	 * @param string $only_type2 = null if given only return fields of type2 == $only_type2
231 231
 	 * @return array of details as array with values for keys 'label','value','type'
232 232
 	 */
233
-	function get_customfields($data, $only_type2=null)
233
+	function get_customfields($data, $only_type2 = null)
234 234
 	{
235 235
 		$details = array();
236 236
 
237
-		if (($cfs = Customfields::get($this->app, $all_private_too=false, $only_type2)))
237
+		if (($cfs = Customfields::get($this->app, $all_private_too = false, $only_type2)))
238 238
 		{
239 239
 			$header_done = false;
240
-			foreach($cfs as $name => $field)
240
+			foreach ($cfs as $name => $field)
241 241
 			{
242 242
 				if (in_array($field['type'], Customfields::$non_printable_fields)) continue;
243 243
 
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
 	 * @param array $old = null old/last state of the entry or null for a new entry
279 279
 	 * @return mixed
280 280
 	 */
281
-	protected function get_config($name,$data,$old=null)
281
+	protected function get_config($name, $data, $old = null)
282 282
 	{
283
-		unset($name, $data, $old);	// not used as just a stub
283
+		unset($name, $data, $old); // not used as just a stub
284 284
 
285 285
 		return null;
286 286
 	}
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 * @param boolean $skip_notification = false do NOT send any notification
297 297
 	 * @return int|boolean false on error, integer number of changes logged or true for new entries ($old == null)
298 298
 	 */
299
-	public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null,$skip_notification=false)
299
+	public function track(array $data, array $old = null, $user = null, $deleted = null, array $changed_fields = null, $skip_notification = false)
300 300
 	{
301 301
 		$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
302 302
 
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 		if ($old && $this->field2history)
306 306
 		{
307 307
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true));
308
-			$changes = $this->save_history($data,$old,$deleted,$changed_fields);
308
+			$changes = $this->save_history($data, $old, $deleted, $changed_fields);
309 309
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true));
310 310
 			//error_log(__METHOD__.__LINE__.' Changes:'.print_r($changes,true));
311 311
 		}
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
 		//error_log(__METHOD__.__LINE__.' LinkFields:'.array2string($this->cf_link_fields));
314 314
 		if ($changes && $this->cf_link_fields)
315 315
 		{
316
-			$this->update_links($data,(array)$old);
316
+			$this->update_links($data, (array)$old);
317 317
 		}
318 318
 		// do not run do_notifications if we have no changes
319
-		if ($changes && !$skip_notification && !$this->do_notifications($data,$old,$deleted))
319
+		if ($changes && !$skip_notification && !$this->do_notifications($data, $old, $deleted))
320 320
 		{
321 321
 			$changes = false;
322 322
 		}
@@ -333,45 +333,45 @@  discard block
 block discarded – undo
333 333
 	{
334 334
 		//error_log(__METHOD__.__LINE__.array2string($data).function_backtrace());
335 335
 		//error_log(__METHOD__.__LINE__.array2string($this->cf_link_fields));
336
-		foreach(array_keys((array)$this->cf_link_fields) as $name)
336
+		foreach (array_keys((array)$this->cf_link_fields) as $name)
337 337
 		{
338 338
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name]));
339 339
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name]));
340
-			if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id'];
341
-			if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id'];
340
+			if (is_array($data[$name]) && array_key_exists('id', $data[$name])) $data[$name] = $data[$name]['id'];
341
+			if (is_array($old[$name]) && array_key_exists('id', $old[$name])) $old[$name] = $old[$name]['id'];
342 342
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name]));
343 343
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name]));
344 344
 		}
345
-		$current_ids = array_unique(array_diff(array_intersect_key($data,$this->cf_link_fields),array('',0,NULL)));
346
-		$old_ids = $old ? array_unique(array_diff(array_intersect_key($old,$this->cf_link_fields),array('',0,NULL))) : array();
345
+		$current_ids = array_unique(array_diff(array_intersect_key($data, $this->cf_link_fields), array('', 0, NULL)));
346
+		$old_ids = $old ? array_unique(array_diff(array_intersect_key($old, $this->cf_link_fields), array('', 0, NULL))) : array();
347 347
 		//error_log(__METHOD__.__LINE__.array2string($current_ids));
348 348
 		//error_log(__METHOD__.__LINE__.array2string($old_ids));
349 349
 		// create links for added application entry
350
-		foreach(array_diff($current_ids,$old_ids) as $name => $id)
350
+		foreach (array_diff($current_ids, $old_ids) as $name => $id)
351 351
 		{
352 352
 			if (!($app = $this->cf_link_fields[$name]))
353 353
 			{
354
-				list($app,$id) = explode(':',$id);
355
-				if (!$id) continue;	// can be eg. 'addressbook:', if no contact selected
354
+				list($app, $id) = explode(':', $id);
355
+				if (!$id) continue; // can be eg. 'addressbook:', if no contact selected
356 356
 			}
357 357
 			$source_id = $data[$this->id_field];
358 358
 			//error_log(__METHOD__.__LINE__.array2string($source_id));
359
-			if ($source_id) Api\Link::link($this->app,$source_id,$app,$id);
359
+			if ($source_id) Api\Link::link($this->app, $source_id, $app, $id);
360 360
 			//error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);");
361 361
 			//echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n";
362 362
 		}
363 363
 
364 364
 		// unlink removed application entries
365
-		foreach(array_diff($old_ids,$current_ids) as $name => $id)
365
+		foreach (array_diff($old_ids, $current_ids) as $name => $id)
366 366
 		{
367
-			if (!isset($data[$name])) continue;	// ignore not set link cf's, eg. from sync clients
367
+			if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients
368 368
 			if (!($app = $this->cf_link_fields[$name]))
369 369
 			{
370
-				list($app,$id) = explode(':',$id);
370
+				list($app, $id) = explode(':', $id);
371 371
 				if (!$id) continue;
372 372
 			}
373 373
 			$source_id = $data[$this->id_field];
374
-			if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
374
+			if ($source_id) Api\Link::unlink(null, $this->app, $source_id, 0, $app, $id);
375 375
 			//echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n";
376 376
 		}
377 377
 	}
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
 	 * @param array $changed_fields = null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again
387 387
 	 * @return int number of log-entries made
388 388
 	 */
389
-	protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null)
389
+	protected function save_history(array $data, array $old = null, $deleted = null, array $changed_fields = null)
390 390
 	{
391
-		unset($deleted);	// not used, but required by function signature
391
+		unset($deleted); // not used, but required by function signature
392 392
 
393 393
 		//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
394 394
 		if (is_null($changed_fields))
395 395
 		{
396
-			$changed_fields = self::changed_fields($data,$old);
396
+			$changed_fields = self::changed_fields($data, $old);
397 397
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
398 398
 		}
399 399
 		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0;
@@ -408,30 +408,30 @@  discard block
 block discarded – undo
408 408
 			$this->historylog->add('user_agent_action', $data[$this->id_field],
409 409
 				$_SERVER['HTTP_USER_AGENT'], $_SESSION[Api\Session::EGW_SESSION_VAR]['session_action']);
410 410
 		}
411
-		foreach($changed_fields as $name)
411
+		foreach ($changed_fields as $name)
412 412
 		{
413 413
 			$status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name;
414 414
 			//error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status));
415 415
 			if (is_array($status))	// 1:N relation --> remove common rows
416 416
 			{
417 417
 				//error_log(__METHOD__.__LINE__.' is Array');
418
-				self::compact_1_N_relation($data[$name],$status);
419
-				self::compact_1_N_relation($old[$name],$status);
420
-				$added = array_values(array_diff($data[$name],$old[$name]));
421
-				$removed = array_values(array_diff($old[$name],$data[$name]));
422
-				$n = max(array(count($added),count($removed)));
423
-				for($i = 0; $i < $n; ++$i)
418
+				self::compact_1_N_relation($data[$name], $status);
419
+				self::compact_1_N_relation($old[$name], $status);
420
+				$added = array_values(array_diff($data[$name], $old[$name]));
421
+				$removed = array_values(array_diff($old[$name], $data[$name]));
422
+				$n = max(array(count($added), count($removed)));
423
+				for ($i = 0; $i < $n; ++$i)
424 424
 				{
425 425
 					//error_log(__METHOD__."() $i: historylog->add('$name',data['$this->id_field']={$data[$this->id_field]},".array2string($added[$i]).','.array2string($removed[$i]));
426
-					$this->historylog->add($name,$data[$this->id_field],$added[$i],$removed[$i]);
426
+					$this->historylog->add($name, $data[$this->id_field], $added[$i], $removed[$i]);
427 427
 				}
428 428
 			}
429 429
 			else
430 430
 			{
431 431
 				//error_log(__METHOD__.__LINE__.' IDField:'.array2string($this->id_field).' ->'.$data[$this->id_field].' New:'.$data[$name].' Old:'.$old[$name]);
432
-				$this->historylog->add($status,$data[$this->id_field],
433
-					is_array($data[$name]) ? implode(',',$data[$name]) : $data[$name],
434
-					is_array($old[$name]) ? implode(',',$old[$name]) : $old[$name]);
432
+				$this->historylog->add($status, $data[$this->id_field],
433
+					is_array($data[$name]) ? implode(',', $data[$name]) : $data[$name],
434
+					is_array($old[$name]) ? implode(',', $old[$name]) : $old[$name]);
435 435
 			}
436 436
 		}
437 437
 		//error_log(__METHOD__.__LINE__.' return:'.count($changed_fields));
@@ -447,28 +447,28 @@  discard block
 block discarded – undo
447 447
 	 * @param array $old = null
448 448
 	 * @return array of keys with different values in $data and $old
449 449
 	 */
450
-	public function changed_fields(array $data,array $old=null)
450
+	public function changed_fields(array $data, array $old = null)
451 451
 	{
452 452
 		if (is_null($old)) return array_keys($data);
453 453
 		$changed_fields = array();
454
-		foreach($this->field2history as $name => $status)
454
+		foreach ($this->field2history as $name => $status)
455 455
 		{
456
-			if (!$old[$name] && !$data[$name]) continue;	// treat all sorts of empty equally
456
+			if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally
457 457
 
458
-			if ($name[0] == '#' && !isset($data[$name])) continue;	// no set customfields are not stored, therefore not changed
458
+			if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed
459 459
 
460 460
 			if (is_array($status))	// 1:N relation
461 461
 			{
462
-				self::compact_1_N_relation($data[$name],$status);
463
-				self::compact_1_N_relation($old[$name],$status);
462
+				self::compact_1_N_relation($data[$name], $status);
463
+				self::compact_1_N_relation($old[$name], $status);
464 464
 			}
465 465
 			if ($old[$name] != $data[$name])
466 466
 			{
467 467
 				// normalize arrays, we do NOT care for the order of multiselections
468 468
 				if (is_array($data[$name]) || is_array($old[$name]))
469 469
 				{
470
-					if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]);
471
-					if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]);
470
+					if (!is_array($data[$name])) $data[$name] = explode(',', $data[$name]);
471
+					if (!is_array($old[$name])) $old[$name] = explode(',', $old[$name]);
472 472
 					if (count($data[$name]) == count($old[$name]))
473 473
 					{
474 474
 						sort($data[$name]);
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
 				}
479 479
 				elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name]))
480 480
 				{
481
-					continue;	// change only in CR (eg. different OS) --> ignore
481
+					continue; // change only in CR (eg. different OS) --> ignore
482 482
 				}
483 483
 				$changed_fields[] = $name;
484 484
 				//echo "<p>$name: ".array2string($data[$name]).' != '.array2string($old[$name])."</p>\n";
485 485
 			}
486 486
 		}
487
-		foreach($data as $name => $value)
487
+		foreach ($data as $name => $value)
488 488
 		{
489 489
 			if ($name[0] == '#' && $name[1] == '#' && $value !== $old[$name])
490 490
 			{
@@ -501,18 +501,18 @@  discard block
 block discarded – undo
501 501
 	 * @param array &$rows rows of the 1:N relation
502 502
 	 * @param array $cols field names as values
503 503
 	 */
504
-	private static function compact_1_N_relation(&$rows,array $cols)
504
+	private static function compact_1_N_relation(&$rows, array $cols)
505 505
 	{
506 506
 		if (is_array($rows))
507 507
 		{
508
-			foreach($rows as &$row)
508
+			foreach ($rows as &$row)
509 509
 			{
510 510
 				$values = array();
511
-				foreach($cols as $col)
511
+				foreach ($cols as $col)
512 512
 				{
513 513
 					$values[] = $row[$col];
514 514
 				}
515
-				$row = implode(self::ONE2N_SEPERATOR,$values);
515
+				$row = implode(self::ONE2N_SEPERATOR, $values);
516 516
 			}
517 517
 		}
518 518
 		else
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 	 * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified
532 532
 	 * @return boolean true on success, false on error (error messages are in $this->errors)
533 533
 	 */
534
-	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
534
+	public function do_notifications($data, $old, $deleted = null, &$email_notified = null)
535 535
 	{
536 536
 		$this->errors = $email_sent = array();
537 537
 		if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified;
@@ -539,19 +539,19 @@  discard block
 block discarded – undo
539 539
 		if (!$this->notify_current_user && $this->user)		// do we have a current user and should we notify the current user about his own changes
540 540
 		{
541 541
 			//error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him");
542
-			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email');
542
+			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email');
543 543
 		}
544
-		$skip_notify = $this->get_config('skip_notify',$data,$old);
545
-		if($skip_notify && is_array($skip_notify))
544
+		$skip_notify = $this->get_config('skip_notify', $data, $old);
545
+		if ($skip_notify && is_array($skip_notify))
546 546
 		{
547 547
 			$email_sent = array_merge($email_sent, $skip_notify);
548 548
 		}
549 549
 
550 550
 		// entry creator
551
-		if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field],'account_email')) &&
551
+		if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field], 'account_email')) &&
552 552
 			!in_array($email, $email_sent))
553 553
 		{
554
-			if ($this->send_notification($data,$old,$email,$data[$this->creator_field],'notify_creator'))
554
+			if ($this->send_notification($data, $old, $email, $data[$this->creator_field], 'notify_creator'))
555 555
 			{
556 556
 				$email_sent[] = $email;
557 557
 			}
@@ -560,12 +560,12 @@  discard block
 block discarded – undo
560 560
 		// members of group when entry owned by group
561 561
 		if ($this->creator_field && $GLOBALS['egw']->accounts->get_type($data[$this->creator_field]) == 'g')
562 562
 		{
563
-			foreach($GLOBALS['egw']->accounts->members($data[$this->creator_field],true) as $u)
563
+			foreach ($GLOBALS['egw']->accounts->members($data[$this->creator_field], true) as $u)
564 564
 			{
565
-				if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) &&
565
+				if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) &&
566 566
 					!in_array($email, $email_sent))
567 567
 				{
568
-					if ($this->send_notification($data,$old,$email,$u,'notify_owner_group_member'))
568
+					if ($this->send_notification($data, $old, $email, $u, 'notify_owner_group_member'))
569 569
 					{
570 570
 						$email_sent[] = $email;
571 571
 					}
@@ -582,14 +582,14 @@  discard block
 block discarded – undo
582 582
 			if ($data[$this->assigned_field])	// current assignments
583 583
 			{
584 584
 				$assignees = is_array($data[$this->assigned_field]) ?
585
-					$data[$this->assigned_field] : explode(',',$data[$this->assigned_field]);
585
+					$data[$this->assigned_field] : explode(',', $data[$this->assigned_field]);
586 586
 			}
587 587
 			if ($old && $old[$this->assigned_field])
588 588
 			{
589 589
 				$old_assignees = is_array($old[$this->assigned_field]) ?
590
-					$old[$this->assigned_field] : explode(',',$old[$this->assigned_field]);
590
+					$old[$this->assigned_field] : explode(',', $old[$this->assigned_field]);
591 591
 			}
592
-			foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee)
592
+			foreach (array_unique(array_merge($assignees, $old_assignees)) as $assignee)
593 593
 			{
594 594
 				//error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email'));
595 595
 				if (!$assignee) continue;
@@ -597,10 +597,10 @@  discard block
 block discarded – undo
597 597
 				// item assignee is a user
598 598
 				if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u')
599 599
 				{
600
-					if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent))
600
+					if (($email = $GLOBALS['egw']->accounts->id2name($assignee, 'account_email')) && !in_array($email, $email_sent))
601 601
 					{
602
-						if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned',
603
-							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))	// assignment changed
602
+						if ($this->send_notification($data, $old, $email, $assignee, 'notify_assigned',
603
+							in_array($assignee, $assignees) !== in_array($assignee, $old_assignees) || $deleted))	// assignment changed
604 604
 						{
605 605
 							$email_sent[] = $email;
606 606
 						}
@@ -608,12 +608,12 @@  discard block
 block discarded – undo
608 608
 				}
609 609
 				else	// item assignee is a group
610 610
 				{
611
-					foreach($GLOBALS['egw']->accounts->members($assignee,true) as $u)
611
+					foreach ($GLOBALS['egw']->accounts->members($assignee, true) as $u)
612 612
 					{
613
-						if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent))
613
+						if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) && !in_array($email, $email_sent))
614 614
 						{
615
-							if ($this->send_notification($data,$old,$email,$u,'notify_assigned',
616
-								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))	// assignment changed
615
+							if ($this->send_notification($data, $old, $email, $u, 'notify_assigned',
616
+								in_array($u, $assignees) !== in_array($u, $old_assignees) || $deleted))	// assignment changed
617 617
 							{
618 618
 								$email_sent[] = $email;
619 619
 							}
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
 		}
625 625
 
626 626
 		// notification copies
627
-		if (($copies = $this->get_config('copy',$data,$old)))
627
+		if (($copies = $this->get_config('copy', $data, $old)))
628 628
 		{
629
-			$lang = $this->get_config('lang',$data,$old);
630
-			foreach($copies as $email)
629
+			$lang = $this->get_config('lang', $data, $old);
630
+			foreach ($copies as $email)
631 631
 			{
632
-				if (strchr($email,'@') !== false && !in_array($email, $email_sent))
632
+				if (strchr($email, '@') !== false && !in_array($email, $email_sent))
633 633
 				{
634
-					if ($this->send_notification($data,$old,$email,$lang,'notify_copy'))
634
+					if ($this->send_notification($data, $old, $email, $lang, 'notify_copy'))
635 635
 					{
636 636
 						$email_sent[] = $email;
637 637
 					}
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 	 * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted
677 677
 	 * @return boolean true on success or false if notification not requested or error (error-message is in $this->errors)
678 678
 	 */
679
-	public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null)
679
+	public function send_notification($data, $old, $email, $user_or_lang, $check = null, $assignment_changed = true, $deleted = null)
680 680
 	{
681 681
 		//error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)");
682 682
 		if (!$email) return false;
@@ -688,16 +688,16 @@  discard block
 block discarded – undo
688 688
 		{
689 689
 			$GLOBALS['egw_info']['user']['account_id'] = $user_or_lang;
690 690
 			$GLOBALS['egw']->preferences->__construct($user_or_lang);
691
-			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
691
+			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
692 692
 
693 693
 			if ($check && $this->check2pref) $check = $this->check2pref[$check];
694 694
 
695
-			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] ||	// no notification requested
695
+			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested
696 696
 				// only notification about changed assignment requested
697 697
 				$check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed ||
698 698
 				$this->user == $user_or_lang && !$this->notify_current_user)  // no popup for own actions
699 699
 			{
700
-				$do_notify = false;	// no notification requested / necessary
700
+				$do_notify = false; // no notification requested / necessary
701 701
 			}
702 702
 		}
703 703
 		else
@@ -720,33 +720,33 @@  discard block
 block discarded – undo
720 720
 
721 721
 			// Cache message body to not have to re-generate it every time
722 722
 			$lang = Api\Translation::$userlang;
723
-			$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] .
723
+			$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].
724 724
 				$GLOBALS['egw_info']['user']['preferences']['common']['timeformat'];
725 725
 
726 726
 			// Cache text body
727
-			$body_cache =& $this->body_cache[$data[$this->id_field]][$lang][$date_format];
728
-			if(empty($data[$this->id_field]) || !isset($body_cache['text']))
727
+			$body_cache = & $this->body_cache[$data[$this->id_field]][$lang][$date_format];
728
+			if (empty($data[$this->id_field]) || !isset($body_cache['text']))
729 729
 			{
730
-				$body_cache['text'] = $this->get_body(false,$data,$old,false,$receiver);
730
+				$body_cache['text'] = $this->get_body(false, $data, $old, false, $receiver);
731 731
 			}
732 732
 			// Cache HTML body
733
-			if(empty($data[$this->id_field]) || !isset($body_cache['html']))
733
+			if (empty($data[$this->id_field]) || !isset($body_cache['html']))
734 734
 			{
735
-				$body_cache['html'] = $this->get_body(true,$data,$old,false,$receiver);
735
+				$body_cache['html'] = $this->get_body(true, $data, $old, false, $receiver);
736 736
 			}
737 737
 
738 738
 			// get rest of notification message
739
-			$sender = $this->get_sender($data,$old,true,$receiver);
740
-			$subject = $this->get_subject($data,$old,$deleted,$receiver);
741
-			$link = $this->get_notification_link($data,$old,$receiver);
742
-			$attachments = $this->get_attachments($data,$old,$receiver);
739
+			$sender = $this->get_sender($data, $old, true, $receiver);
740
+			$subject = $this->get_subject($data, $old, $deleted, $receiver);
741
+			$link = $this->get_notification_link($data, $old, $receiver);
742
+			$attachments = $this->get_attachments($data, $old, $receiver);
743 743
 		}
744 744
 
745 745
 		// restore user enviroment BEFORE calling notification class or returning
746 746
 		$GLOBALS['egw_info']['user'] = $save_user;
747 747
 		// need to call preferences constructor and read_repository, to set user timezone again
748 748
 		$GLOBALS['egw']->preferences->__construct($GLOBALS['egw_info']['user']['account_id']);
749
-		$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
749
+		$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
750 750
 
751 751
 		// Re-load date/time preferences
752 752
 		Api\DateTime::init();
@@ -801,11 +801,11 @@  discard block
 block discarded – undo
801 801
 	 *
802 802
 	 * @return string
803 803
 	 */
804
-	public function datetime($timestamp,$do_time=true)
804
+	public function datetime($timestamp, $do_time = true)
805 805
 	{
806
-		if (!is_a($timestamp,'DateTime'))
806
+		if (!is_a($timestamp, 'DateTime'))
807 807
 		{
808
-			$timestamp = new Api\DateTime($timestamp,Api\DateTime::$server_timezone);
808
+			$timestamp = new Api\DateTime($timestamp, Api\DateTime::$server_timezone);
809 809
 		}
810 810
 		$timestamp->setTimezone(Api\DateTime::$user_timezone);
811 811
 		if (is_null($do_time))
@@ -831,25 +831,25 @@  discard block
 block discarded – undo
831 831
 	 * @param int|string $receiver nummeric account_id or email address
832 832
 	 * @return string or userid
833 833
 	 */
834
-	protected function get_sender($data,$old,$prefer_id=false,$receiver=null)
834
+	protected function get_sender($data, $old, $prefer_id = false, $receiver = null)
835 835
 	{
836
-		unset($receiver);	// not used, but required by function signature
836
+		unset($receiver); // not used, but required by function signature
837 837
 
838
-		$sender = $this->get_config('sender',$data,$old);
838
+		$sender = $this->get_config('sender', $data, $old);
839 839
 		//echo "<p>".__METHOD__."() get_config('sender',...)='".htmlspecialchars($sender)."'</p>\n";
840 840
 
841 841
 		if (($this->prefer_user_as_sender || !$sender) && $this->user &&
842
-			($email = $GLOBALS['egw']->accounts->id2name($this->user,'account_email')))
842
+			($email = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email')))
843 843
 		{
844
-			$name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname');
844
+			$name = $GLOBALS['egw']->accounts->id2name($this->user, 'account_fullname');
845 845
 
846
-			if($prefer_id) {
846
+			if ($prefer_id) {
847 847
 				$sender = $this->user;
848 848
 			} else {
849 849
 				$sender = $name ? $name.' <'.$email.'>' : $email;
850 850
 			}
851 851
 		}
852
-		elseif(!$sender)
852
+		elseif (!$sender)
853 853
 		{
854 854
 			$sender = 'eGroupWare '.lang($this->app).' <noreply@'.$GLOBALS['egw_info']['server']['mail_suffix'].'>';
855 855
 		}
@@ -864,11 +864,11 @@  discard block
 block discarded – undo
864 864
 	 * @param array $old
865 865
 	 * @return string
866 866
 	 */
867
-	protected function get_title($data,$old)
867
+	protected function get_title($data, $old)
868 868
 	{
869
-		unset($old);	// not used, but required by function signature
869
+		unset($old); // not used, but required by function signature
870 870
 
871
-		return Api\Link::title($this->app,$data[$this->id_field]);
871
+		return Api\Link::title($this->app, $data[$this->id_field]);
872 872
 	}
873 873
 
874 874
 	/**
@@ -882,11 +882,11 @@  discard block
 block discarded – undo
882 882
 	 * @param int|string $receiver nummeric account_id or email address
883 883
 	 * @return string
884 884
 	 */
885
-	protected function get_subject($data,$old,$deleted=null,$receiver=null)
885
+	protected function get_subject($data, $old, $deleted = null, $receiver = null)
886 886
 	{
887
-		unset($old, $deleted, $receiver);	// not used, but required by function signature
887
+		unset($old, $deleted, $receiver); // not used, but required by function signature
888 888
 
889
-		return Api\Link::title($this->app,$data[$this->id_field]);
889
+		return Api\Link::title($this->app, $data[$this->id_field]);
890 890
 	}
891 891
 
892 892
 	/**
@@ -899,9 +899,9 @@  discard block
 block discarded – undo
899 899
 	 * @param int|string $receiver nummeric account_id or email address
900 900
 	 * @return string
901 901
 	 */
902
-	protected function get_message($data,$old,$receiver=null)
902
+	protected function get_message($data, $old, $receiver = null)
903 903
 	{
904
-		unset($data, $old, $receiver);	// not used, but required by function signature
904
+		unset($data, $old, $receiver); // not used, but required by function signature
905 905
 
906 906
 		return '';
907 907
 	}
@@ -917,24 +917,24 @@  discard block
 block discarded – undo
917 917
 	 * @param int|string $receiver nummeric account_id or email address
918 918
 	 * @return string|array string with link (!$allow_popup) or array(link,popup-size), popup size is something like '640x480'
919 919
 	 */
920
-	protected function get_link($data,$old,$allow_popup=false,$receiver=null)
920
+	protected function get_link($data, $old, $allow_popup = false, $receiver = null)
921 921
 	{
922
-		unset($receiver);	// not used, but required by function signature
922
+		unset($receiver); // not used, but required by function signature
923 923
 
924
-		if (($link = $this->get_config('link',$data,$old)))
924
+		if (($link = $this->get_config('link', $data, $old)))
925 925
 		{
926
-			if (!$this->get_config('link_no_id', $data) && strpos($link,$this->id_field.'=') === false && isset($data[$this->id_field]))
926
+			if (!$this->get_config('link_no_id', $data) && strpos($link, $this->id_field.'=') === false && isset($data[$this->id_field]))
927 927
 			{
928
-				$link .= strpos($link,'?') === false ? '?' : '&';
928
+				$link .= strpos($link, '?') === false ? '?' : '&';
929 929
 				$link .= $this->id_field.'='.$data[$this->id_field];
930 930
 			}
931 931
 		}
932 932
 		else
933 933
 		{
934
-			if (($view = Api\Link::view($this->app,$data[$this->id_field])))
934
+			if (($view = Api\Link::view($this->app, $data[$this->id_field])))
935 935
 			{
936
-				$link = $GLOBALS['egw']->link('/index.php',$view);
937
-				$popup = Api\Link::is_popup($this->app,'view');
936
+				$link = $GLOBALS['egw']->link('/index.php', $view);
937
+				$popup = Api\Link::is_popup($this->app, 'view');
938 938
 			}
939 939
 		}
940 940
 		if ($link[0] == '/')
@@ -945,12 +945,12 @@  discard block
 block discarded – undo
945 945
 		if (!$allow_popup)
946 946
 		{
947 947
 			// remove the session-id in the notification mail!
948
-			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link);
948
+			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/', '', $link);
949 949
 
950 950
 			if ($popup) $link .= '&nopopup=1';
951 951
 		}
952 952
 		//error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link));
953
-		return $allow_popup ? array($link,$popup) : $link;
953
+		return $allow_popup ? array($link, $popup) : $link;
954 954
 	}
955 955
 
956 956
 	/**
@@ -961,18 +961,18 @@  discard block
 block discarded – undo
961 961
 	 * @param int|string $receiver nummeric account_id or email address
962 962
 	 * @return array with link
963 963
 	 */
964
-	protected function get_notification_link($data,$old,$receiver=null)
964
+	protected function get_notification_link($data, $old, $receiver = null)
965 965
 	{
966
-		unset($receiver);	// not used, but required by function signature
966
+		unset($receiver); // not used, but required by function signature
967 967
 
968
-		if (($view = Api\Link::view($this->app,$data[$this->id_field])))
968
+		if (($view = Api\Link::view($this->app, $data[$this->id_field])))
969 969
 		{
970 970
 			return array(
971
-				'text' 	=> $this->get_title($data,$old),
971
+				'text' 	=> $this->get_title($data, $old),
972 972
 				'app'	=> $this->app,
973 973
 				'id'	=> $data[$this->id_field],
974 974
 				'view' 	=> $view,
975
-				'popup'	=> Api\Link::is_popup($this->app,'view'),
975
+				'popup'	=> Api\Link::is_popup($this->app, 'view'),
976 976
 			);
977 977
 		}
978 978
 		return false;
@@ -988,15 +988,15 @@  discard block
 block discarded – undo
988 988
 	 * @param int|string $receiver nummeric account_id or email address
989 989
 	 * @return string
990 990
 	 */
991
-	public function get_body($html_email,$data,$old,$integrate_link = true,$receiver=null)
991
+	public function get_body($html_email, $data, $old, $integrate_link = true, $receiver = null)
992 992
 	{
993 993
 		$body = '';
994
-		if($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old))
994
+		if ($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old))
995 995
 		{
996
-			$body = $this->get_custom_message($data,$old);
997
-			if(($sig = $this->get_signature($data,$old,$receiver)))
996
+			$body = $this->get_custom_message($data, $old);
997
+			if (($sig = $this->get_signature($data, $old, $receiver)))
998 998
 			{
999
-				$body .= ($html_email ? '<br />':'') . "\n$sig";
999
+				$body .= ($html_email ? '<br />' : '')."\n$sig";
1000 1000
 			}
1001 1001
 			return $body;
1002 1002
 		}
@@ -1005,35 +1005,35 @@  discard block
 block discarded – undo
1005 1005
 			$body = '<table cellspacing="2" cellpadding="0" border="0" width="100%">'."\n";
1006 1006
 		}
1007 1007
 		// new or modified message
1008
-		if (($message = $this->get_message($data,$old,$receiver)))
1008
+		if (($message = $this->get_message($data, $old, $receiver)))
1009 1009
 		{
1010 1010
 			foreach ((array)$message as $_message)
1011 1011
 			{
1012
-				$body .= $this->format_line($html_email,'message',false,($_message=='---'?($html_email?'<hr/>':$_message):$_message));
1012
+				$body .= $this->format_line($html_email, 'message', false, ($_message == '---' ? ($html_email ? '<hr/>' : $_message) : $_message));
1013 1013
 			}
1014 1014
 		}
1015
-		if ($integrate_link && ($link = $this->get_link($data,$old,false,$receiver)))
1015
+		if ($integrate_link && ($link = $this->get_link($data, $old, false, $receiver)))
1016 1016
 		{
1017
-			$body .= $this->format_line($html_email,'link',false,$integrate_link === true ? lang('You can respond by visiting:') : $integrate_link,$link);
1017
+			$body .= $this->format_line($html_email, 'link', false, $integrate_link === true ? lang('You can respond by visiting:') : $integrate_link, $link);
1018 1018
 		}
1019
-		foreach($this->get_details($data,$receiver) as $name => $detail)
1019
+		foreach ($this->get_details($data, $receiver) as $name => $detail)
1020 1020
 		{
1021 1021
 			// if there's no old entry, the entry is not modified by definition
1022 1022
 			// if both values are '', 0 or null, we count them as equal too
1023 1023
 			$modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]);
1024 1024
 			//if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified);
1025
-			if (empty($detail['value']) && !$modified) continue;	// skip unchanged, empty values
1025
+			if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values
1026 1026
 
1027
-			$body .= $this->format_line($html_email,$detail['type'],$modified,
1027
+			$body .= $this->format_line($html_email, $detail['type'], $modified,
1028 1028
 				$detail['label'] ? $detail['label'] : '', $detail['value']);
1029 1029
 		}
1030 1030
 		if ($html_email)
1031 1031
 		{
1032 1032
 			$body .= "</table>\n";
1033 1033
 		}
1034
-		if(($sig = $this->get_signature($data,$old,$receiver)))
1034
+		if (($sig = $this->get_signature($data, $old, $receiver)))
1035 1035
 		{
1036
-			$body .= ($html_email ? '<br />':'') . "\n$sig";
1036
+			$body .= ($html_email ? '<br />' : '')."\n$sig";
1037 1037
 		}
1038 1038
 		return $body;
1039 1039
 	}
@@ -1049,20 +1049,20 @@  discard block
 block discarded – undo
1049 1049
 	 * @param string $data = null data or null to display just $line over 2 columns
1050 1050
 	 * @return string
1051 1051
 	 */
1052
-	protected function format_line($html_mail,$type,$modified,$line,$data=null)
1052
+	protected function format_line($html_mail, $type, $modified, $line, $data = null)
1053 1053
 	{
1054 1054
 		//error_log(__METHOD__.'('.array2string($html_mail).",'$type',".array2string($modified).",'$line',".array2string($data).')');
1055 1055
 		$content = '';
1056 1056
 
1057 1057
 		if ($html_mail)
1058 1058
 		{
1059
-			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line);	// XSS
1059
+			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS
1060 1060
 
1061 1061
 			$color = $modified ? 'red' : false;
1062 1062
 			$size  = '110%';
1063 1063
 			$bold = false;
1064 1064
 			$background = '#FFFFF1';
1065
-			switch($type)
1065
+			switch ($type)
1066 1066
 			{
1067 1067
 				case 'message':
1068 1068
 					$background = '#D3DCE3;';
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
 					if (strpos($data, '<br') === false)
1081 1081
 					{
1082 1082
 						$data = nl2br($this->html_content_allow ? $data : Api\Html::htmlspecialchars($data));
1083
-						$this->html_content_allow = true;	// to NOT do htmlspecialchars again
1083
+						$this->html_content_allow = true; // to NOT do htmlspecialchars again
1084 1084
 					}
1085 1085
 					break;
1086 1086
 				case 'reply':
@@ -1089,13 +1089,13 @@  discard block
 block discarded – undo
1089 1089
 				default:
1090 1090
 					$size = false;
1091 1091
 			}
1092
-			$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color?'color:'.$color:'');
1092
+			$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color ? 'color:'.$color : '');
1093 1093
 
1094
-			$content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data?'" width="20%':'" colspan="2').'">';
1094
+			$content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data ? '" width="20%' : '" colspan="2').'">';
1095 1095
 		}
1096 1096
 		else	// text-mail
1097 1097
 		{
1098
-			if ($type == 'reply') $content = str_repeat('-',64)."\n";
1098
+			if ($type == 'reply') $content = str_repeat('-', 64)."\n";
1099 1099
 
1100 1100
 			if ($modified) $content .= '> ';
1101 1101
 		}
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
 			if ($type == 'link')
1108 1108
 			{
1109 1109
 				// the link is often too long for html boxes chunk-split allows to break lines if needed
1110
-				$content .= Api\Html::a_href(chunk_split(rawurldecode($data),40,'&#8203;'),$data,'','target="_blank"');
1110
+				$content .= Api\Html::a_href(chunk_split(rawurldecode($data), 40, '&#8203;'), $data, '', 'target="_blank"');
1111 1111
 			}
1112 1112
 			elseif ($this->html_content_allow)
1113 1113
 			{
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 		}
1121 1121
 		else
1122 1122
 		{
1123
-			$content .= ($content&&$data?': ':'').$data;
1123
+			$content .= ($content && $data ? ': ' : '').$data;
1124 1124
 		}
1125 1125
 		if ($html_mail) $content .= '</td></tr>';
1126 1126
 
@@ -1137,9 +1137,9 @@  discard block
 block discarded – undo
1137 1137
 	 * @param int|string $receiver nummeric account_id or email address
1138 1138
 	 * @return array or array with values for either 'string' or 'path' and optionally (mime-)'type', 'filename' and 'encoding'
1139 1139
 	 */
1140
-	protected function get_attachments($data,$old,$receiver=null)
1140
+	protected function get_attachments($data, $old, $receiver = null)
1141 1141
 	{
1142
-		unset($data, $old, $receiver);	// not used, but required by function signature
1142
+		unset($data, $old, $receiver); // not used, but required by function signature
1143 1143
 
1144 1144
 	 	return array();
1145 1145
 	}
@@ -1152,20 +1152,20 @@  discard block
 block discarded – undo
1152 1152
 	 */
1153 1153
 	protected function get_signature($data, $old, $receiver)
1154 1154
 	{
1155
-		unset($old, $receiver);	// not used, but required by function signature
1155
+		unset($old, $receiver); // not used, but required by function signature
1156 1156
 
1157 1157
 		$config = Api\Config::read('notifications');
1158
-		if(!isset($data[$this->id_field]))
1158
+		if (!isset($data[$this->id_field]))
1159 1159
 		{
1160
-			error_log($this->app . ' did not properly implement bo_tracking->id_field.  Merge skipped.');
1160
+			error_log($this->app.' did not properly implement bo_tracking->id_field.  Merge skipped.');
1161 1161
 		}
1162
-		elseif(class_exists($this->app. '_merge'))
1162
+		elseif (class_exists($this->app.'_merge'))
1163 1163
 		{
1164 1164
 			$merge_class = $this->app.'_merge';
1165 1165
 			$merge = new $merge_class();
1166 1166
 			$error = null;
1167 1167
 			$sig = $merge->merge_string($config['signature'], array($data[$this->id_field]), $error, 'text/html');
1168
-			if($error)
1168
+			if ($error)
1169 1169
 			{
1170 1170
 				error_log($error);
1171 1171
 				return $config['signature'];
@@ -1182,27 +1182,27 @@  discard block
 block discarded – undo
1182 1182
 	protected function get_custom_message($data, $old, $merge_class = null)
1183 1183
 	{
1184 1184
 		$message = $this->get_config(self::CUSTOM_NOTIFICATION, $data, $old);
1185
-		if(!$message)
1185
+		if (!$message)
1186 1186
 		{
1187 1187
 			return '';
1188 1188
 		}
1189 1189
 
1190 1190
 		// Automatically set merge class from naming conventions
1191
-		if($merge_class == null)
1191
+		if ($merge_class == null)
1192 1192
 		{
1193 1193
 			$merge_class = $this->app.'_merge';
1194 1194
 		}
1195
-		if(!isset($data[$this->id_field]))
1195
+		if (!isset($data[$this->id_field]))
1196 1196
 		{
1197
-			error_log($this->app . ' did not properly implement bo_tracking->id_field.  Merge skipped.');
1197
+			error_log($this->app.' did not properly implement bo_tracking->id_field.  Merge skipped.');
1198 1198
 			return $message;
1199 1199
 		}
1200
-		elseif(class_exists($merge_class))
1200
+		elseif (class_exists($merge_class))
1201 1201
 		{
1202 1202
 			$merge = new $merge_class();
1203 1203
 			$error = null;
1204 1204
 			$merged_message = $merge->merge_string($message, array($data[$this->id_field]), $error, 'text/html');
1205
-			if($error)
1205
+			if ($error)
1206 1206
 			{
1207 1207
 				error_log($error);
1208 1208
 				return $message;
Please login to merge, or discard this patch.
Braces   +157 added lines, -39 removed lines patch added patch discarded remove patch
@@ -239,7 +239,10 @@  discard block
 block discarded – undo
239 239
 			$header_done = false;
240 240
 			foreach($cfs as $name => $field)
241 241
 			{
242
-				if (in_array($field['type'], Customfields::$non_printable_fields)) continue;
242
+				if (in_array($field['type'], Customfields::$non_printable_fields))
243
+				{
244
+					continue;
245
+				}
243 246
 
244 247
 				if (!$header_done)
245 248
 				{
@@ -337,8 +340,14 @@  discard block
 block discarded – undo
337 340
 		{
338 341
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name]));
339 342
 			//error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name]));
340
-			if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id'];
341
-			if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id'];
343
+			if (is_array($data[$name]) && array_key_exists('id',$data[$name]))
344
+			{
345
+				$data[$name] = $data[$name]['id'];
346
+			}
347
+			if (is_array($old[$name]) && array_key_exists('id',$old[$name]))
348
+			{
349
+				$old[$name] = $old[$name]['id'];
350
+			}
342 351
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name]));
343 352
 			//error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name]));
344 353
 		}
@@ -352,11 +361,18 @@  discard block
 block discarded – undo
352 361
 			if (!($app = $this->cf_link_fields[$name]))
353 362
 			{
354 363
 				list($app,$id) = explode(':',$id);
355
-				if (!$id) continue;	// can be eg. 'addressbook:', if no contact selected
364
+				if (!$id)
365
+				{
366
+					continue;
367
+				}
368
+				// can be eg. 'addressbook:', if no contact selected
356 369
 			}
357 370
 			$source_id = $data[$this->id_field];
358 371
 			//error_log(__METHOD__.__LINE__.array2string($source_id));
359
-			if ($source_id) Api\Link::link($this->app,$source_id,$app,$id);
372
+			if ($source_id)
373
+			{
374
+				Api\Link::link($this->app,$source_id,$app,$id);
375
+			}
360 376
 			//error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);");
361 377
 			//echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n";
362 378
 		}
@@ -364,14 +380,24 @@  discard block
 block discarded – undo
364 380
 		// unlink removed application entries
365 381
 		foreach(array_diff($old_ids,$current_ids) as $name => $id)
366 382
 		{
367
-			if (!isset($data[$name])) continue;	// ignore not set link cf's, eg. from sync clients
383
+			if (!isset($data[$name]))
384
+			{
385
+				continue;
386
+			}
387
+			// ignore not set link cf's, eg. from sync clients
368 388
 			if (!($app = $this->cf_link_fields[$name]))
369 389
 			{
370 390
 				list($app,$id) = explode(':',$id);
371
-				if (!$id) continue;
391
+				if (!$id)
392
+				{
393
+					continue;
394
+				}
372 395
 			}
373 396
 			$source_id = $data[$this->id_field];
374
-			if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
397
+			if ($source_id)
398
+			{
399
+				Api\Link::unlink(null,$this->app,$source_id,0,$app,$id);
400
+			}
375 401
 			//echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n";
376 402
 		}
377 403
 	}
@@ -396,7 +422,10 @@  discard block
 block discarded – undo
396 422
 			$changed_fields = self::changed_fields($data,$old);
397 423
 			//error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields));
398 424
 		}
399
-		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0;
425
+		if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action']))
426
+		{
427
+			return 0;
428
+		}
400 429
 
401 430
 		if (!is_object($this->historylog) || $this->historylog->user != $this->user)
402 431
 		{
@@ -412,10 +441,13 @@  discard block
 block discarded – undo
412 441
 		{
413 442
 			$status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name;
414 443
 			//error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status));
415
-			if (is_array($status))	// 1:N relation --> remove common rows
444
+			if (is_array($status))
445
+			{
446
+				// 1:N relation --> remove common rows
416 447
 			{
417 448
 				//error_log(__METHOD__.__LINE__.' is Array');
418 449
 				self::compact_1_N_relation($data[$name],$status);
450
+			}
419 451
 				self::compact_1_N_relation($old[$name],$status);
420 452
 				$added = array_values(array_diff($data[$name],$old[$name]));
421 453
 				$removed = array_values(array_diff($old[$name],$data[$name]));
@@ -449,17 +481,31 @@  discard block
 block discarded – undo
449 481
 	 */
450 482
 	public function changed_fields(array $data,array $old=null)
451 483
 	{
452
-		if (is_null($old)) return array_keys($data);
484
+		if (is_null($old))
485
+		{
486
+			return array_keys($data);
487
+		}
453 488
 		$changed_fields = array();
454 489
 		foreach($this->field2history as $name => $status)
455 490
 		{
456
-			if (!$old[$name] && !$data[$name]) continue;	// treat all sorts of empty equally
491
+			if (!$old[$name] && !$data[$name])
492
+			{
493
+				continue;
494
+			}
495
+			// treat all sorts of empty equally
457 496
 
458
-			if ($name[0] == '#' && !isset($data[$name])) continue;	// no set customfields are not stored, therefore not changed
497
+			if ($name[0] == '#' && !isset($data[$name]))
498
+			{
499
+				continue;
500
+			}
501
+			// no set customfields are not stored, therefore not changed
459 502
 
460
-			if (is_array($status))	// 1:N relation
503
+			if (is_array($status))
504
+			{
505
+				// 1:N relation
461 506
 			{
462 507
 				self::compact_1_N_relation($data[$name],$status);
508
+			}
463 509
 				self::compact_1_N_relation($old[$name],$status);
464 510
 			}
465 511
 			if ($old[$name] != $data[$name])
@@ -467,13 +513,22 @@  discard block
 block discarded – undo
467 513
 				// normalize arrays, we do NOT care for the order of multiselections
468 514
 				if (is_array($data[$name]) || is_array($old[$name]))
469 515
 				{
470
-					if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]);
471
-					if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]);
516
+					if (!is_array($data[$name]))
517
+					{
518
+						$data[$name] = explode(',',$data[$name]);
519
+					}
520
+					if (!is_array($old[$name]))
521
+					{
522
+						$old[$name] = explode(',',$old[$name]);
523
+					}
472 524
 					if (count($data[$name]) == count($old[$name]))
473 525
 					{
474 526
 						sort($data[$name]);
475 527
 						sort($old[$name]);
476
-						if ($data[$name] == $old[$name]) continue;
528
+						if ($data[$name] == $old[$name])
529
+						{
530
+							continue;
531
+						}
477 532
 					}
478 533
 				}
479 534
 				elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name]))
@@ -534,13 +589,19 @@  discard block
 block discarded – undo
534 589
 	public function do_notifications($data,$old,$deleted=null,&$email_notified=null)
535 590
 	{
536 591
 		$this->errors = $email_sent = array();
537
-		if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified;
592
+		if (!empty($email_notified) && is_array($email_notified))
593
+		{
594
+			$email_sent = $email_notified;
595
+		}
538 596
 
539
-		if (!$this->notify_current_user && $this->user)		// do we have a current user and should we notify the current user about his own changes
597
+		if (!$this->notify_current_user && $this->user)
598
+		{
599
+			// do we have a current user and should we notify the current user about his own changes
540 600
 		{
541 601
 			//error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him");
542 602
 			$email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email');
543 603
 		}
604
+		}
544 605
 		$skip_notify = $this->get_config('skip_notify',$data,$old);
545 606
 		if($skip_notify && is_array($skip_notify))
546 607
 		{
@@ -579,11 +640,14 @@  discard block
 block discarded – undo
579 640
 			//error_log(__METHOD__."() data[$this->assigned_field]=".print_r($data[$this->assigned_field],true).", old[$this->assigned_field]=".print_r($old[$this->assigned_field],true));
580 641
 			$old_assignees = array();
581 642
 			$assignees = $assigned ? $assigned : array();
582
-			if ($data[$this->assigned_field])	// current assignments
643
+			if ($data[$this->assigned_field])
644
+			{
645
+				// current assignments
583 646
 			{
584 647
 				$assignees = is_array($data[$this->assigned_field]) ?
585 648
 					$data[$this->assigned_field] : explode(',',$data[$this->assigned_field]);
586 649
 			}
650
+			}
587 651
 			if ($old && $old[$this->assigned_field])
588 652
 			{
589 653
 				$old_assignees = is_array($old[$this->assigned_field]) ?
@@ -592,7 +656,10 @@  discard block
 block discarded – undo
592 656
 			foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee)
593 657
 			{
594 658
 				//error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email'));
595
-				if (!$assignee) continue;
659
+				if (!$assignee)
660
+				{
661
+					continue;
662
+				}
596 663
 
597 664
 				// item assignee is a user
598 665
 				if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u')
@@ -600,10 +667,13 @@  discard block
 block discarded – undo
600 667
 					if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent))
601 668
 					{
602 669
 						if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned',
603
-							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))	// assignment changed
670
+							in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted))
671
+						{
672
+							// assignment changed
604 673
 						{
605 674
 							$email_sent[] = $email;
606 675
 						}
676
+						}
607 677
 					}
608 678
 				}
609 679
 				else	// item assignee is a group
@@ -613,10 +683,13 @@  discard block
 block discarded – undo
613 683
 						if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent))
614 684
 						{
615 685
 							if ($this->send_notification($data,$old,$email,$u,'notify_assigned',
616
-								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))	// assignment changed
686
+								in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted))
687
+							{
688
+								// assignment changed
617 689
 							{
618 690
 								$email_sent[] = $email;
619 691
 							}
692
+							}
620 693
 						}
621 694
 					}
622 695
 				}
@@ -679,25 +752,38 @@  discard block
 block discarded – undo
679 752
 	public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null)
680 753
 	{
681 754
 		//error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)");
682
-		if (!$email) return false;
755
+		if (!$email)
756
+		{
757
+			return false;
758
+		}
683 759
 
684 760
 		$save_user = $GLOBALS['egw_info']['user'];
685 761
 		$do_notify = true;
686 762
 
687
-		if (is_numeric($user_or_lang))	// user --> read everything from his prefs
763
+		if (is_numeric($user_or_lang))
764
+		{
765
+			// user --> read everything from his prefs
688 766
 		{
689 767
 			$GLOBALS['egw_info']['user']['account_id'] = $user_or_lang;
768
+		}
690 769
 			$GLOBALS['egw']->preferences->__construct($user_or_lang);
691 770
 			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false);	// no session prefs!
692 771
 
693
-			if ($check && $this->check2pref) $check = $this->check2pref[$check];
772
+			if ($check && $this->check2pref)
773
+			{
774
+				$check = $this->check2pref[$check];
775
+			}
694 776
 
695 777
 			if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] ||	// no notification requested
696 778
 				// only notification about changed assignment requested
697 779
 				$check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed ||
698
-				$this->user == $user_or_lang && !$this->notify_current_user)  // no popup for own actions
780
+				$this->user == $user_or_lang && !$this->notify_current_user)
699 781
 			{
700
-				$do_notify = false;	// no notification requested / necessary
782
+				// no popup for own actions
783
+			{
784
+				$do_notify = false;
785
+			}
786
+			// no notification requested / necessary
701 787
 			}
702 788
 		}
703 789
 		else
@@ -706,10 +792,13 @@  discard block
 block discarded – undo
706 792
 			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->default_prefs();
707 793
 			$GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $user_or_lang;
708 794
 		}
709
-		if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang)	// load the right language if needed
795
+		if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang)
796
+		{
797
+			// load the right language if needed
710 798
 		{
711 799
 			Api\Translation::init();
712 800
 		}
801
+		}
713 802
 
714 803
 		$receiver = is_numeric($user_or_lang) ? $user_or_lang : $email;
715 804
 
@@ -813,7 +902,10 @@  discard block
 block discarded – undo
813 902
 			$do_time = ($timestamp->format('Hi') != '0000');
814 903
 		}
815 904
 		$format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
816
-		if ($do_time) $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a');
905
+		if ($do_time)
906
+		{
907
+			$format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a');
908
+		}
817 909
 
818 910
 		return $timestamp->format($format);
819 911
 	}
@@ -843,9 +935,12 @@  discard block
 block discarded – undo
843 935
 		{
844 936
 			$name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname');
845 937
 
846
-			if($prefer_id) {
938
+			if($prefer_id)
939
+			{
847 940
 				$sender = $this->user;
848
-			} else {
941
+			}
942
+			else
943
+			{
849 944
 				$sender = $name ? $name.' <'.$email.'>' : $email;
850 945
 			}
851 946
 		}
@@ -947,7 +1042,10 @@  discard block
 block discarded – undo
947 1042
 			// remove the session-id in the notification mail!
948 1043
 			$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link);
949 1044
 
950
-			if ($popup) $link .= '&nopopup=1';
1045
+			if ($popup)
1046
+			{
1047
+				$link .= '&nopopup=1';
1048
+			}
951 1049
 		}
952 1050
 		//error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link));
953 1051
 		return $allow_popup ? array($link,$popup) : $link;
@@ -1022,7 +1120,11 @@  discard block
 block discarded – undo
1022 1120
 			// if both values are '', 0 or null, we count them as equal too
1023 1121
 			$modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]);
1024 1122
 			//if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified);
1025
-			if (empty($detail['value']) && !$modified) continue;	// skip unchanged, empty values
1123
+			if (empty($detail['value']) && !$modified)
1124
+			{
1125
+				continue;
1126
+			}
1127
+			// skip unchanged, empty values
1026 1128
 
1027 1129
 			$body .= $this->format_line($html_email,$detail['type'],$modified,
1028 1130
 				$detail['label'] ? $detail['label'] : '', $detail['value']);
@@ -1056,7 +1158,11 @@  discard block
 block discarded – undo
1056 1158
 
1057 1159
 		if ($html_mail)
1058 1160
 		{
1059
-			if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line);	// XSS
1161
+			if (!$this->html_content_allow)
1162
+			{
1163
+				$line = Api\Html::htmlspecialchars($line);
1164
+			}
1165
+			// XSS
1060 1166
 
1061 1167
 			$color = $modified ? 'red' : false;
1062 1168
 			$size  = '110%';
@@ -1095,15 +1201,24 @@  discard block
 block discarded – undo
1095 1201
 		}
1096 1202
 		else	// text-mail
1097 1203
 		{
1098
-			if ($type == 'reply') $content = str_repeat('-',64)."\n";
1204
+			if ($type == 'reply')
1205
+			{
1206
+				$content = str_repeat('-',64)."\n";
1207
+			}
1099 1208
 
1100
-			if ($modified) $content .= '> ';
1209
+			if ($modified)
1210
+			{
1211
+				$content .= '> ';
1212
+			}
1101 1213
 		}
1102 1214
 		$content .= $line;
1103 1215
 
1104 1216
 		if ($html_mail)
1105 1217
 		{
1106
-			if ($line && $data) $content .= '</td><td style="'.$style.'">';
1218
+			if ($line && $data)
1219
+			{
1220
+				$content .= '</td><td style="'.$style.'">';
1221
+			}
1107 1222
 			if ($type == 'link')
1108 1223
 			{
1109 1224
 				// the link is often too long for html boxes chunk-split allows to break lines if needed
@@ -1122,7 +1237,10 @@  discard block
 block discarded – undo
1122 1237
 		{
1123 1238
 			$content .= ($content&&$data?': ':'').$data;
1124 1239
 		}
1125
-		if ($html_mail) $content .= '</td></tr>';
1240
+		if ($html_mail)
1241
+		{
1242
+			$content .= '</td></tr>';
1243
+		}
1126 1244
 
1127 1245
 		$content .= "\n";
1128 1246
 
Please login to merge, or discard this patch.
api/src/Translation.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -742,7 +742,7 @@
 block discarded – undo
742 742
 	 *
743 743
 	 * @param string $app application name
744 744
 	 * @param string $lang language code
745
-	 * @return the full path of the filename for the requested app and language
745
+	 * @return string full path of the filename for the requested app and language
746 746
 	 */
747 747
 	static function get_lang_file($app,$lang)
748 748
 	{
Please login to merge, or discard this patch.
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -738,12 +738,12 @@  discard block
 block discarded – undo
738 738
 	}
739 739
 
740 740
  	/**
741
-	 * provides centralization and compatibility to locate the lang files
742
-	 *
743
-	 * @param string $app application name
744
-	 * @param string $lang language code
745
-	 * @return the full path of the filename for the requested app and language
746
-	 */
741
+ 	 * provides centralization and compatibility to locate the lang files
742
+ 	 *
743
+ 	 * @param string $app application name
744
+ 	 * @param string $lang language code
745
+ 	 * @return the full path of the filename for the requested app and language
746
+ 	 */
747 747
 	static function get_lang_file($app,$lang)
748 748
 	{
749 749
 		if ($app == 'common') $app = 'phpgwapi';
@@ -1074,13 +1074,13 @@  discard block
 block discarded – undo
1074 1074
 	}
1075 1075
 
1076 1076
  	/**
1077
-	 * detect_encoding - try to detect the encoding
1078
-	 *    only to be used if the string in question has no structure that determines his encoding
1079
-	 *
1080
-	 * @param string - to be evaluated
1081
-	 * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available
1082
-	 * @return string - encoding
1083
-	 */
1077
+ 	 * detect_encoding - try to detect the encoding
1078
+ 	 *    only to be used if the string in question has no structure that determines his encoding
1079
+ 	 *
1080
+ 	 * @param string - to be evaluated
1081
+ 	 * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available
1082
+ 	 * @return string - encoding
1083
+ 	 */
1084 1084
 	static function detect_encoding($string, $verify=null)
1085 1085
 	{
1086 1086
 		if (function_exists('iconv'))
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 * @var array
101 101
 	 */
102
-	static $instance_specific_translations = array('loginscreen','mainscreen','custom');
102
+	static $instance_specific_translations = array('loginscreen', 'mainscreen', 'custom');
103 103
 
104 104
 	/**
105 105
 	 * returns the charset to use (!$lang) or the charset of the lang-files or $lang
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 * @param string|boolean $lang =False return charset of the active user-lang, or $lang if specified
108 108
 	 * @return string charset
109 109
 	 */
110
-	static function charset($lang=False)
110
+	static function charset($lang = False)
111 111
 	{
112 112
 		static $charsets = array();
113 113
 
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 		{
116 116
 			if (!isset($charsets[$lang]))
117 117
 			{
118
-				if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE,'content',array(
118
+				if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE, 'content', array(
119 119
 					'lang'		=> $lang,
120 120
 					'message_id'=> 'charset',
121 121
 					'app_name'	=> 'common',
122
-				),__LINE__,__FILE__)->fetchColumn()))
122
+				), __LINE__, __FILE__)->fetchColumn()))
123 123
 				{
124 124
 					$charsets[$lang] = 'utf-8';
125 125
 				}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 *
154 154
 	 * @param boolean $load_translations =true should we also load translations for common and currentapp
155 155
 	 */
156
-	static function init($load_translations=true)
156
+	static function init($load_translations = true)
157 157
 	{
158 158
 		if (!isset(self::$db))
159 159
 		{
@@ -165,11 +165,11 @@  discard block
 block discarded – undo
165 165
 		}
166 166
 		else
167 167
 		{
168
-			self::$system_charset =& $GLOBALS['egw_setup']->system_charset;
168
+			self::$system_charset = & $GLOBALS['egw_setup']->system_charset;
169 169
 		}
170 170
 		if ((self::$mbstring = check_load_extension('mbstring')))
171 171
 		{
172
-			if(!empty(self::$system_charset))
172
+			if (!empty(self::$system_charset))
173 173
 			{
174 174
 				$ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset';
175 175
 				ini_set($ini_default_charset, self::$system_charset);
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 
179 179
 		// try loading load_via from tree-wide cache and check if it contains more rules
180 180
 		if (($load_via = Cache::getTree(__CLASS__, 'load_via')) &&
181
-			$load_via >= self::$load_via && 	// > for array --> contains more elements
181
+			$load_via >= self::$load_via && // > for array --> contains more elements
182 182
 			// little sanity check: cached array contains all stock keys, otherwise ignore it
183 183
 			!array_diff_key(self::$load_via, $load_via))
184 184
 		{
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 	 * @param string $not_found ='*' what to add to not found phrases, default '*'
218 218
 	 * @return string with translation
219 219
 	 */
220
-	static function translate($key, $vars=null, $not_found='' )
220
+	static function translate($key, $vars = null, $not_found = '')
221 221
 	{
222 222
 		if (!self::$lang_arr)
223 223
 		{
224 224
 			self::init();
225 225
 		}
226
-		$ret = $key;				// save key if we dont find a translation
226
+		$ret = $key; // save key if we dont find a translation
227 227
 		if ($not_found) $ret .= $not_found;
228 228
 
229 229
 		if (isset(self::$lang_arr[$key]))
@@ -243,16 +243,16 @@  discard block
 block discarded – undo
243 243
 		{
244 244
 			if (count($vars) > 1)
245 245
 			{
246
-				static $placeholders = array('%3','%2','%1','|%2|','|%3|','%4','%5','%6','%7','%8','%9','%10');
246
+				static $placeholders = array('%3', '%2', '%1', '|%2|', '|%3|', '%4', '%5', '%6', '%7', '%8', '%9', '%10');
247 247
 				// to cope with $vars[0] containing '%2' (eg. an urlencoded path like a referer),
248 248
 				// we first replace '%2' in $ret with '|%2|' and then use that as 2. placeholder
249 249
 				// we do that for %3 as well, ...
250
-				$vars = array_merge(array('|%3|','|%2|'),$vars);	// push '|%2|' (and such) as first replacement on $vars
251
-				$ret = str_replace($placeholders,$vars,$ret);
250
+				$vars = array_merge(array('|%3|', '|%2|'), $vars); // push '|%2|' (and such) as first replacement on $vars
251
+				$ret = str_replace($placeholders, $vars, $ret);
252 252
 			}
253 253
 			else
254 254
 			{
255
-				$ret = str_replace('%1',$vars[0],$ret);
255
+				$ret = str_replace('%1', $vars[0], $ret);
256 256
 			}
257 257
 		}
258 258
 		return $ret;
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
 	 * 	if multiple names given, they are requested in one request from cache and loaded in given order
268 268
 	 * @param string $lang =false 2 or 5 char lang-code or false for the users language
269 269
 	 */
270
-	static function add_app($apps, $lang=null)
270
+	static function add_app($apps, $lang = null)
271 271
 	{
272 272
 		//error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr));
273 273
 		//$start = microtime(true);
274 274
 		if (!$lang) $lang = self::$userlang;
275 275
 		$tree_level = $instance_level = array();
276 276
 		if (!is_array($apps)) $apps = (array)$apps;
277
-		foreach($apps as $key => $app)
277
+		foreach ($apps as $key => $app)
278 278
 		{
279 279
 			if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common')
280 280
 			{
@@ -298,26 +298,26 @@  discard block
 block discarded – undo
298 298
 
299 299
 		// merging loaded translations together
300 300
 		$updated_load_via = false;
301
-		foreach((array)$apps as $app)
301
+		foreach ((array)$apps as $app)
302 302
 		{
303 303
 			$l = $app == 'custom' ? 'en' : $lang;
304 304
 			if (isset($tree_level[$app.':'.$l]))
305 305
 			{
306
-				$loaded =& $tree_level[$app.':'.$l];
306
+				$loaded = & $tree_level[$app.':'.$l];
307 307
 			}
308 308
 			elseif (isset($instance_level[$app.':'.$l]))
309 309
 			{
310
-				$loaded =& $instance_level[$app.':'.$l];
310
+				$loaded = & $instance_level[$app.':'.$l];
311 311
 			}
312 312
 			else
313 313
 			{
314 314
 				if (($instance_specific = in_array($app, self::$instance_specific_translations)))
315 315
 				{
316
-					$loaded =& self::load_app($app, $l);
316
+					$loaded = & self::load_app($app, $l);
317 317
 				}
318 318
 				else
319 319
 				{
320
-					$loaded =& self::load_app_files($app, $l, null, $updated_load_via);
320
+					$loaded = & self::load_app_files($app, $l, null, $updated_load_via);
321 321
 				}
322 322
 				//error_log(__METHOD__."('$app', '$lang') instance_specific=$instance_specific, load_app(_files)() returned ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded)));
323 323
 				if ($loaded || $instance_specific)
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
 			if ($loaded)
331 331
 			{
332 332
 				self::$lang_arr = array_merge(self::$lang_arr, $loaded);
333
-				self::$loaded_apps[$app] = $l;	// dont set something not existing to $loaded_apps, no need to load client-side
333
+				self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side
334 334
 			}
335 335
 		}
336 336
 		// Re-merge custom over instance level, they have higher precidence
337
-		if($tree_level && !$instance_level && self::$instance_specific_translations)
337
+		if ($tree_level && !$instance_level && self::$instance_specific_translations)
338 338
 		{
339 339
 			$custom = Cache::getInstance(__CLASS__, 'custom:en');
340
-			if($custom)
340
+			if ($custom)
341 341
 			{
342 342
 				self::$lang_arr = array_merge(self::$lang_arr, $custom);
343 343
 			}
@@ -358,15 +358,15 @@  discard block
 block discarded – undo
358 358
 	 * @param string $lang =false 2 or 5 char lang-code or false for the users language
359 359
 	 * @return array the loaded strings
360 360
 	 */
361
-	static function &load_app($app,$lang)
361
+	static function &load_app($app, $lang)
362 362
 	{
363 363
 		//$start = microtime(true);
364 364
 		if (is_null(self::$db)) self::init(false);
365 365
 		$loaded = array();
366
-		foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array(
366
+		foreach (self::$db->select(self::LANG_TABLE, 'message_id,content', array(
367 367
 			'lang'		=> $lang,
368 368
 			'app_name'	=> $app,
369
-		),__LINE__,__FILE__) as $row)
369
+		), __LINE__, __FILE__) as $row)
370 370
 		{
371 371
 			$loaded[strtolower($row['message_id'])] = $row['content'];
372 372
 		}
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 		'sitemgr-link' => array('sitemgr'),
391 391
 		'groupdav' => array('api'),
392 392
 		'developer_tools' => array('etemplate'),
393
-		'login' => array('api','registration'),
393
+		'login' => array('api', 'registration'),
394 394
 	);
395 395
 
396 396
 	/**
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 	{
403 403
 		$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
404 404
 		$apps = array_keys($GLOBALS['egw_info']['apps']);
405
-		foreach($apps as $app)
405
+		foreach ($apps as $app)
406 406
 		{
407 407
 			$file = self::get_lang_file($app, $lang);
408 408
 			// check if file has changed compared to what's cached
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 		Cache::unsetTree(__CLASS__, $app.':'.$lang);
433 433
 		Cache::unsetTree(__CLASS__, self::get_lang_file($app, $lang));
434 434
 
435
-		foreach(self::$load_via as $load => $via)
435
+		foreach (self::$load_via as $load => $via)
436 436
 		{
437 437
 			//error_log("load_via[load='$load'] = via = ".array2string($via));
438 438
 			if ($via === 'all-apps' || in_array($app, (array)$via))
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 * @param string $_lang =null
455 455
 	 * @return array $lang or $app => number pairs
456 456
 	 */
457
-	static function statistics($_lang=null)
457
+	static function statistics($_lang = null)
458 458
 	{
459 459
 		$cache = Cache::getTree(__CLASS__, 'statistics');
460 460
 
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 			{
466 466
 				$en_phrases = array_keys(self::load_app_files(null, 'en', 'all-apps'));
467 467
 				$cache['']['en'] = count($en_phrases);
468
-				foreach(array_keys(self::get_available_langs()) as $lang)
468
+				foreach (array_keys(self::get_available_langs()) as $lang)
469 469
 				{
470 470
 					if ($lang == 'en') continue;
471 471
 					$lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps'));
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 			else
477 477
 			{
478 478
 				$cache['en'] = array();
479
-				foreach(scandir(EGW_SERVER_ROOT) as $app)
479
+				foreach (scandir(EGW_SERVER_ROOT) as $app)
480 480
 				{
481 481
 					if ($app[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app) ||
482 482
 						!file_exists(self::get_lang_file($app, 'en')))
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 		if (!in_array($_app, self::$instance_specific_translations))
515 515
 		{
516 516
 			// check if cache is NOT invalided by checking if we have a modification time for concerned lang-file
517
-			$time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang));
517
+			$time = Cache::getTree(__CLASS__, $file = self::get_lang_file($_app, $_lang));
518 518
 			// if we dont have one, cache has been invalidated and we need to load translations
519 519
 			if (!isset($time)) self::add_app($_app, $_lang);
520 520
 
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 	 * @param type $time
535 535
 	 * @return type
536 536
 	 */
537
-	static function max_lang_time($time=null)
537
+	static function max_lang_time($time = null)
538 538
 	{
539 539
 		static $max_lang_time = null;
540 540
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 		if (isset($time) && $time > $max_lang_time)
546 546
 		{
547 547
 			//error_log(__METHOD__."($time) updating previous max_lang_time=$max_lang_time to $time");
548
-			Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time=$time);
548
+			Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time = $time);
549 549
 		}
550 550
 		return $max_lang_time;
551 551
 	}
@@ -561,34 +561,34 @@  discard block
 block discarded – undo
561 561
 	 * @param boolean $updated_load_via =false on return true if self::$load_via was updated
562 562
 	 * @return array the loaded strings
563 563
 	 */
564
-	static function &load_app_files($app, $lang, $just_app_file=null, &$updated_load_via=false)
564
+	static function &load_app_files($app, $lang, $just_app_file = null, &$updated_load_via = false)
565 565
 	{
566 566
 		//$start = microtime(true);
567 567
 		$load_app = isset($just_app_file) ? $just_app_file : (isset(self::$load_via[$app]) ? self::$load_via[$app] : $app);
568 568
 		$loaded = array();
569
-		foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
569
+		foreach ($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
570 570
 		{
571
-			if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root
571
+			if ($load_app == 'all-apps' && $app_dir == '..') continue; // do not try to break out of egw server root
572 572
 			if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) ||
573
-				!@file_exists($file=self::get_lang_file($app_dir, $lang)) ||
573
+				!@file_exists($file = self::get_lang_file($app_dir, $lang)) ||
574 574
 				!($f = fopen($file, 'r')))
575 575
 			{
576 576
 				continue;
577 577
 			}
578 578
 			// store ctime of file we parse
579
-			Cache::setTree(__CLASS__, $file, $time=filemtime($file));
579
+			Cache::setTree(__CLASS__, $file, $time = filemtime($file));
580 580
 			self::max_lang_time($time);
581 581
 
582 582
 			$line_nr = 0;
583 583
 			//use fgets and split the line, as php5.3.3 with squeeze does not support splitting lines with fgetcsv while reading properly
584 584
 			//if the first letter after the delimiter is a german umlaut (UTF8 representation thereoff)
585 585
 			//while(($line = fgetcsv($f, 1024, "\t")))
586
-			while(($read = fgets($f)))
586
+			while (($read = fgets($f)))
587 587
 			{
588 588
 				$line = explode("\t", trim($read));
589 589
 				++$line_nr;
590 590
 				if (count($line) != 4) continue;
591
-				list($l_id,$l_app,$l_lang,$l_translation) = $line;
591
+				list($l_id, $l_app, $l_lang, $l_translation) = $line;
592 592
 				if ($l_lang != $lang) continue;
593 593
 				if (!isset($just_app_file) && $l_app != $app)
594 594
 				{
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 			// little sanity check: cached array contains all stock keys, otherwise ignore it
630 630
 			!array_diff_key(self::$load_via, $load_via))
631 631
 		{
632
-			foreach($load_via as $app => $via)
632
+			foreach ($load_via as $app => $via)
633 633
 			{
634 634
 				if (self::$load_via[$app] != $via)
635 635
 				{
@@ -655,15 +655,15 @@  discard block
 block discarded – undo
655 655
 	 * @param boolean $force_read =false force a re-read of the languages
656 656
 	 * @return array with lang-code => descriptiv lang-name pairs
657 657
 	 */
658
-	static function get_available_langs($translate=true, $force_read=false)
658
+	static function get_available_langs($translate = true, $force_read = false)
659 659
 	{
660 660
 		if (!is_array(self::$langs) || $force_read)
661 661
 		{
662
-			if (!($f = fopen($file=EGW_SERVER_ROOT.'/setup/lang/languages','rb')))
662
+			if (!($f = fopen($file = EGW_SERVER_ROOT.'/setup/lang/languages', 'rb')))
663 663
 			{
664 664
 				throw new Exception("List of available languages (%1) missing!", $file);
665 665
 			}
666
-			while(($line = fgetcsv($f, null, "\t")))
666
+			while (($line = fgetcsv($f, null, "\t")))
667 667
 			{
668 668
 				self::$langs[$line[0]] = $line[1];
669 669
 			}
@@ -673,12 +673,12 @@  discard block
 block discarded – undo
673 673
 			{
674 674
 				if (is_null(self::$db)) self::init(false);
675 675
 
676
-				foreach(self::$langs as $lang => $name)
676
+				foreach (self::$langs as $lang => $name)
677 677
 				{
678
-					self::$langs[$lang] = self::translate($name,False,'');
678
+					self::$langs[$lang] = self::translate($name, False, '');
679 679
 				}
680 680
 			}
681
-			uasort(self::$langs,'strcasecmp');
681
+			uasort(self::$langs, 'strcasecmp');
682 682
 		}
683 683
 		return self::$langs;
684 684
 	}
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 	 * @param boolean $force_read =false force a re-read of the languages
692 692
 	 * @return array with lang-code => descriptiv lang-name pairs
693 693
 	 */
694
-	static function get_installed_langs($force_read=false)
694
+	static function get_installed_langs($force_read = false)
695 695
 	{
696 696
 		return self::get_available_langs($force_read);
697 697
 	}
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 		{
709 709
 			return self::$langs[$lang];
710 710
 		}
711
-		return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn();
711
+		return self::$db->select(self::LANGUAGES_TABLE, 'lang_name', array('lang_id' => $lang), __LINE__, __FILE__)->fetchColumn();
712 712
 	}
713 713
 
714 714
 	/**
@@ -717,20 +717,20 @@  discard block
 block discarded – undo
717 717
 	 * @param boolean $force_read =false
718 718
 	 * @return array with lang_id => lang_name pairs
719 719
 	 */
720
-	static function list_langs($force_read=false)
720
+	static function list_langs($force_read = false)
721 721
 	{
722 722
 		if (!$force_read)
723 723
 		{
724
-			return Cache::getInstance(__CLASS__,'list_langs',array(__CLASS__,'list_langs'),array(true));
724
+			return Cache::getInstance(__CLASS__, 'list_langs', array(__CLASS__, 'list_langs'), array(true));
725 725
 		}
726
-		$languages = self::get_installed_langs();	// available languages
727
-		$availible = "('".implode("','",array_keys($languages))."')";
726
+		$languages = self::get_installed_langs(); // available languages
727
+		$availible = "('".implode("','", array_keys($languages))."')";
728 728
 
729 729
 		// this shows first the installed, then the available and then the rest
730
-		foreach(self::$db->select(self::LANGUAGES_TABLE,array(
731
-			'lang_id','lang_name',
730
+		foreach (self::$db->select(self::LANGUAGES_TABLE, array(
731
+			'lang_id', 'lang_name',
732 732
 			"CASE WHEN lang_id IN $availible THEN 1 ELSE 0 END AS availible",
733
-		),"lang_id NOT IN ('".implode("','",array_keys($languages))."')",__LINE__,__FILE__,false,' ORDER BY availible DESC,lang_name') as $row)
733
+		), "lang_id NOT IN ('".implode("','", array_keys($languages))."')", __LINE__, __FILE__, false, ' ORDER BY availible DESC,lang_name') as $row)
734 734
 		{
735 735
 			$languages[$row['lang_id']] = $row['lang_name'];
736 736
 		}
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	 * @param string $lang language code
745 745
 	 * @return the full path of the filename for the requested app and language
746 746
 	 */
747
-	static function get_lang_file($app,$lang)
747
+	static function get_lang_file($app, $lang)
748 748
 	{
749 749
 		if ($app == 'common') $app = 'phpgwapi';
750 750
 		return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION;
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 	 */
758 758
 	static function get_installed_charsets()
759 759
 	{
760
-		static $charsets=null;
760
+		static $charsets = null;
761 761
 
762 762
 		if (!isset($charsets))
763 763
 		{
@@ -787,13 +787,13 @@  discard block
 block discarded – undo
787 787
 		static $extra = array(
788 788
 			'&szlig;' => 'ss',
789 789
 		);
790
-		$entities = htmlentities($_str,ENT_QUOTES,self::charset());
790
+		$entities = htmlentities($_str, ENT_QUOTES, self::charset());
791 791
 
792
-		$estr = str_replace(array_keys($extra),array_values($extra), $entities);
793
-		$ustr = preg_replace('/&([aAuUoO])uml;/','\\1e', $estr);	// replace german umlauts with the letter plus one 'e'
794
-		$astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/','\\1', $ustr);	// remove all types of accents
792
+		$estr = str_replace(array_keys($extra), array_values($extra), $entities);
793
+		$ustr = preg_replace('/&([aAuUoO])uml;/', '\\1e', $estr); // replace german umlauts with the letter plus one 'e'
794
+		$astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/', '\\1', $ustr); // remove all types of accents
795 795
 
796
-		return preg_replace('/&([a-zA-Z]+|#[0-9]+|);/','', $astr);	// remove all other entities
796
+		return preg_replace('/&([a-zA-Z]+|#[0-9]+|);/', '', $astr); // remove all other entities
797 797
 	}
798 798
 
799 799
 	/**
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 	 * @param boolean $check_to_from =true internal to bypass all charset replacements
806 806
 	 * @return string|array converted string(s) from $data
807 807
 	 */
808
-	static function convert($data,$from=False,$to=False,$check_to_from=true)
808
+	static function convert($data, $from = False, $to = False, $check_to_from = true)
809 809
 	{
810 810
 		if ($check_to_from)
811 811
 		{
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 			if (!$from)
817 817
 			{
818 818
 				$from = self::$mbstring ? strtolower(mb_detect_encoding($data)) : 'iso-8859-1';
819
-				if($from == 'ascii')
819
+				if ($from == 'ascii')
820 820
 				{
821 821
 					$from = 'iso-8859-1';
822 822
 				}
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 				 php does not seem to support gb2312
827 827
 				 but seems to be able to decode it as EUC-CN
828 828
 			*/
829
-			switch($from)
829
+			switch ($from)
830 830
 			{
831 831
 				case 'ks_c_5601-1987':
832 832
 					$from = 'CP949';
@@ -872,9 +872,9 @@  discard block
 block discarded – undo
872 872
 		}
873 873
 		if (is_array($data))
874 874
 		{
875
-			foreach($data as $key => $str)
875
+			foreach ($data as $key => $str)
876 876
 			{
877
-				$ret[$key] = self::convert($str,$from,$to,false);	// false = bypass the above checks, as they are already done
877
+				$ret[$key] = self::convert($str, $from, $to, false); // false = bypass the above checks, as they are already done
878 878
 			}
879 879
 			return $ret;
880 880
 		}
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 		{
887 887
 			return utf8_decode($data);
888 888
 		}
889
-		if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data,$to,$from)) != '')
889
+		if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data, $to, $from)) != '')
890 890
 		{
891 891
 			return $data;
892 892
 		}
@@ -914,12 +914,12 @@  discard block
 block discarded – undo
914 914
 			// in an email on the first Traditional/Japanese/Korean character,
915 915
 			// but in reality when people send mails in GB2312, UMA mostly use
916 916
 			// extended GB13000/GB18030 which allow T/Jap/Korean characters.
917
-			if($from == 'euc-cn')
917
+			if ($from == 'euc-cn')
918 918
 			{
919 919
 				$from = 'gb18030';
920 920
 			}
921 921
 
922
-			if (($convertedData = iconv($from,$to,$data)))
922
+			if (($convertedData = iconv($from, $to, $data)))
923 923
 			{
924 924
 				return $convertedData;
925 925
 			}
@@ -934,9 +934,9 @@  discard block
 block discarded – undo
934 934
 	 * @param string|boolean $from charset $data is in or False if it should be detected
935 935
 	 * @return string|array converted string(s) from $data
936 936
 	 */
937
-	static function convert_jsonsafe($_data,$from=False)
937
+	static function convert_jsonsafe($_data, $from = False)
938 938
 	{
939
-		if ($from===false) $from = self::detect_encoding($_data);
939
+		if ($from === false) $from = self::detect_encoding($_data);
940 940
 
941 941
 		$data = self::convert($_data, strtolower($from));
942 942
 
@@ -945,12 +945,12 @@  discard block
 block discarded – undo
945 945
 		{
946 946
 			$test = @json_encode($data);
947 947
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($data).' Error:'.json_last_error().'<- data:#'.$test.'#');
948
-			if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
948
+			if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0)
949 949
 			{
950 950
 				// try to fix broken utf8
951
-				$x = (function_exists('mb_convert_encoding')?mb_convert_encoding($data,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$data):$data));
951
+				$x = (function_exists('mb_convert_encoding') ? mb_convert_encoding($data, 'UTF-8', 'UTF-8') : (function_exists('iconv') ? @iconv("UTF-8", "UTF-8//IGNORE", $data) : $data));
952 952
 				$test = @json_encode($x);
953
-				if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
953
+				if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0)
954 954
 				{
955 955
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
956 956
 					error_log(__METHOD__.__LINE__.' Charset Reported:'.$from.' Charset Detected:'.self::detect_encoding($data));
@@ -973,36 +973,36 @@  discard block
 block discarded – undo
973 973
 	 * @param string $message_id
974 974
 	 * @param string $content translation or null to delete translation
975 975
 	 */
976
-	static function write($lang,$app,$message_id,$content)
976
+	static function write($lang, $app, $message_id, $content)
977 977
 	{
978 978
 		if ($content)
979 979
 		{
980
-			self::$db->insert(self::LANG_TABLE,array(
980
+			self::$db->insert(self::LANG_TABLE, array(
981 981
 				'content' => $content,
982
-			),array(
982
+			), array(
983 983
 				'lang' => $lang,
984 984
 				'app_name' => $app,
985 985
 				'message_id' => $message_id,
986
-			),__LINE__,__FILE__);
986
+			), __LINE__, __FILE__);
987 987
 		}
988 988
 		else
989 989
 		{
990
-			self::$db->delete(self::LANG_TABLE,array(
990
+			self::$db->delete(self::LANG_TABLE, array(
991 991
 				'lang' => $lang,
992 992
 				'app_name' => $app,
993 993
 				'message_id' => $message_id,
994
-			),__LINE__,__FILE__);
994
+			), __LINE__, __FILE__);
995 995
 		}
996 996
 		// invalidate the cache
997
-		if(!in_array($app,self::$instance_specific_translations))
997
+		if (!in_array($app, self::$instance_specific_translations))
998 998
 		{
999
-			Cache::unsetCache(Cache::TREE,__CLASS__,$app.':'.$lang);
999
+			Cache::unsetCache(Cache::TREE, __CLASS__, $app.':'.$lang);
1000 1000
 		}
1001 1001
 		else
1002 1002
 		{
1003
-			foreach(array_keys((array)self::get_installed_langs()) as $key)
1003
+			foreach (array_keys((array)self::get_installed_langs()) as $key)
1004 1004
 			{
1005
-				Cache::unsetCache(Cache::INSTANCE,__CLASS__,$app.':'.$key);
1005
+				Cache::unsetCache(Cache::INSTANCE, __CLASS__, $app.':'.$key);
1006 1006
 			}
1007 1007
 		}
1008 1008
  	}
@@ -1015,13 +1015,13 @@  discard block
 block discarded – undo
1015 1015
 	 * @param string $message_id
1016 1016
 	 * @return string|boolean content or false if not found
1017 1017
 	 */
1018
-	static function read($lang,$app_name,$message_id)
1018
+	static function read($lang, $app_name, $message_id)
1019 1019
 	{
1020
-		return self::$db->select(self::LANG_TABLE,'content',array(
1020
+		return self::$db->select(self::LANG_TABLE, 'content', array(
1021 1021
 			'lang' => $lang,
1022 1022
 			'app_name' => $app_name,
1023 1023
 			'message_id' => $message_id,
1024
-		),__LINE__,__FILE__)->fetchColumn();
1024
+		), __LINE__, __FILE__)->fetchColumn();
1025 1025
 	}
1026 1026
 
1027 1027
 	/**
@@ -1032,22 +1032,22 @@  discard block
 block discarded – undo
1032 1032
 	 * @param string $lang ='' default check all langs
1033 1033
 	 * @return string
1034 1034
 	 */
1035
-	static function get_message_id($translation,$app=null,$lang=null)
1035
+	static function get_message_id($translation, $app = null, $lang = null)
1036 1036
 	{
1037 1037
 		$where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation));
1038 1038
 		if ($app) $where['app_name'] = $app;
1039 1039
 		if ($lang) $where['lang'] = $lang;
1040 1040
 
1041
-		$id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn();
1041
+		$id = self::$db->select(self::LANG_TABLE, 'message_id', $where, __LINE__, __FILE__)->fetchColumn();
1042 1042
 
1043 1043
 		// Check cache, since most things aren't in the DB anymore
1044
-		if(!$id)
1044
+		if (!$id)
1045 1045
 		{
1046 1046
 			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) {
1047
-				return stripos(self::$lang_arr[$haystack],$translation) !== false;
1047
+				return stripos(self::$lang_arr[$haystack], $translation) !== false;
1048 1048
 			});
1049 1049
 			$id = array_shift($ids);
1050
-			if(!$id && ($lang && $lang !== 'en' || self::$userlang != 'en'))
1050
+			if (!$id && ($lang && $lang !== 'en' || self::$userlang != 'en'))
1051 1051
 			{
1052 1052
 				// Try english
1053 1053
 				if (in_array($app, self::$instance_specific_translations))
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 				if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1065 1065
 				$lang_arr = $lang_arr[$app.':en'];
1066 1066
 				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) {
1067
-					return stripos($lang_arr[$haystack],$translation) !== false;
1067
+					return stripos($lang_arr[$haystack], $translation) !== false;
1068 1068
 				});
1069 1069
 				$id = array_shift($ids);
1070 1070
 			}
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
 	 * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available
1082 1082
 	 * @return string - encoding
1083 1083
 	 */
1084
-	static function detect_encoding($string, $verify=null)
1084
+	static function detect_encoding($string, $verify = null)
1085 1085
 	{
1086 1086
 		if (function_exists('iconv'))
1087 1087
 		{
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
 		}
1105 1105
 		if ($verify && (!isset($detected) || $detected === 'ascii'))
1106 1106
 		{
1107
-			return $verify;	// ascii matches all charsets
1107
+			return $verify; // ascii matches all charsets
1108 1108
 		}
1109 1109
 		return isset($detected) ? $detected : 'iso-8859-1'; // we choose to return iso-8859-1 as default
1110 1110
 	}
Please login to merge, or discard this patch.
Braces   +121 added lines, -31 removed lines patch added patch discarded remove patch
@@ -126,17 +126,23 @@  discard block
 block discarded – undo
126 126
 			}
127 127
 			return $charsets[$lang];
128 128
 		}
129
-		if (self::$system_charset)	// do we have a system-charset ==> return it
129
+		if (self::$system_charset)
130
+		{
131
+			// do we have a system-charset ==> return it
130 132
 		{
131 133
 			$charset = self::$system_charset;
132 134
 		}
135
+		}
133 136
 		else
134 137
 		{
135 138
 			// if no translations are loaded (system-startup) use a default, else lang('charset')
136 139
 			$charset = !self::$lang_arr ? 'utf-8' : strtolower(self::translate('charset'));
137 140
 		}
138 141
 		// in case no charset is set, default to utf-8
139
-		if (empty($charset) || $charset == 'charset') $charset = 'utf-8';
142
+		if (empty($charset) || $charset == 'charset')
143
+		{
144
+			$charset = 'utf-8';
145
+		}
140 146
 
141 147
 		// we need to set our charset as mbstring.internal_encoding if mbstring.func_overlaod > 0
142 148
 		// else we get problems for a charset is different from the default utf-8
@@ -195,8 +201,14 @@  discard block
 block discarded – undo
195 201
 			}
196 202
 			$apps = array('common');
197 203
 			// for eTemplate apps, load etemplate before app itself (allowing app to overwrite etemplate translations)
198
-			if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) $apps[] = 'etemplate';
199
-			if ($GLOBALS['egw_info']['flags']['currentapp']) $apps[] = $GLOBALS['egw_info']['flags']['currentapp'];
204
+			if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false))
205
+			{
206
+				$apps[] = 'etemplate';
207
+			}
208
+			if ($GLOBALS['egw_info']['flags']['currentapp'])
209
+			{
210
+				$apps[] = $GLOBALS['egw_info']['flags']['currentapp'];
211
+			}
200 212
 			// load instance specific translations last, so they can overwrite everything
201 213
 			$apps[] = 'custom';
202 214
 			self::add_app($apps);
@@ -224,7 +236,10 @@  discard block
 block discarded – undo
224 236
 			self::init();
225 237
 		}
226 238
 		$ret = $key;				// save key if we dont find a translation
227
-		if ($not_found) $ret .= $not_found;
239
+		if ($not_found)
240
+		{
241
+			$ret .= $not_found;
242
+		}
228 243
 
229 244
 		if (isset(self::$lang_arr[$key]))
230 245
 		{
@@ -271,9 +286,15 @@  discard block
 block discarded – undo
271 286
 	{
272 287
 		//error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr));
273 288
 		//$start = microtime(true);
274
-		if (!$lang) $lang = self::$userlang;
289
+		if (!$lang)
290
+		{
291
+			$lang = self::$userlang;
292
+		}
275 293
 		$tree_level = $instance_level = array();
276
-		if (!is_array($apps)) $apps = (array)$apps;
294
+		if (!is_array($apps))
295
+		{
296
+			$apps = (array)$apps;
297
+		}
277 298
 		foreach($apps as $key => $app)
278 299
 		{
279 300
 			if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common')
@@ -293,8 +314,14 @@  discard block
 block discarded – undo
293 314
 			}
294 315
 		}
295 316
 		// load all translations from cache at once
296
-		if ($tree_level) $tree_level = Cache::getTree(__CLASS__, $tree_level);
297
-		if ($instance_level) $instance_level = Cache::getInstance(__CLASS__, $instance_level);
317
+		if ($tree_level)
318
+		{
319
+			$tree_level = Cache::getTree(__CLASS__, $tree_level);
320
+		}
321
+		if ($instance_level)
322
+		{
323
+			$instance_level = Cache::getInstance(__CLASS__, $instance_level);
324
+		}
298 325
 
299 326
 		// merging loaded translations together
300 327
 		$updated_load_via = false;
@@ -361,7 +388,10 @@  discard block
 block discarded – undo
361 388
 	static function &load_app($app,$lang)
362 389
 	{
363 390
 		//$start = microtime(true);
364
-		if (is_null(self::$db)) self::init(false);
391
+		if (is_null(self::$db))
392
+		{
393
+			self::init(false);
394
+		}
365 395
 		$loaded = array();
366 396
 		foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array(
367 397
 			'lang'		=> $lang,
@@ -467,7 +497,10 @@  discard block
 block discarded – undo
467 497
 				$cache['']['en'] = count($en_phrases);
468 498
 				foreach(array_keys(self::get_available_langs()) as $lang)
469 499
 				{
470
-					if ($lang == 'en') continue;
500
+					if ($lang == 'en')
501
+					{
502
+						continue;
503
+					}
471 504
 					$lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps'));
472 505
 					$valid_phrases = array_intersect($lang_phrases, $en_phrases);
473 506
 					$cache[''][$lang] = count($valid_phrases);
@@ -484,7 +517,10 @@  discard block
 block discarded – undo
484 517
 						continue;
485 518
 					}
486 519
 					$en_phrases = array_keys(self::load_app_files(null, 'en', $app));
487
-					if (count($en_phrases) <= 2) continue;
520
+					if (count($en_phrases) <= 2)
521
+					{
522
+						continue;
523
+					}
488 524
 					$cache['en'][$app] = count($en_phrases);
489 525
 					$lang_phrases = array_keys(self::load_app_files(null, $_lang, $app));
490 526
 					$valid_phrases = array_intersect($lang_phrases, $en_phrases);
@@ -516,7 +552,10 @@  discard block
 block discarded – undo
516 552
 			// check if cache is NOT invalided by checking if we have a modification time for concerned lang-file
517 553
 			$time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang));
518 554
 			// if we dont have one, cache has been invalidated and we need to load translations
519
-			if (!isset($time)) self::add_app($_app, $_lang);
555
+			if (!isset($time))
556
+			{
557
+				self::add_app($_app, $_lang);
558
+			}
520 559
 
521 560
 			$etag = self::max_lang_time();
522 561
 		}
@@ -568,7 +607,11 @@  discard block
 block discarded – undo
568 607
 		$loaded = array();
569 608
 		foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
570 609
 		{
571
-			if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root
610
+			if ($load_app == 'all-apps' && $app_dir=='..')
611
+			{
612
+				continue;
613
+			}
614
+			// do not try to break out of egw server root
572 615
 			if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) ||
573 616
 				!@file_exists($file=self::get_lang_file($app_dir, $lang)) ||
574 617
 				!($f = fopen($file, 'r')))
@@ -587,9 +630,15 @@  discard block
 block discarded – undo
587 630
 			{
588 631
 				$line = explode("\t", trim($read));
589 632
 				++$line_nr;
590
-				if (count($line) != 4) continue;
633
+				if (count($line) != 4)
634
+				{
635
+					continue;
636
+				}
591 637
 				list($l_id,$l_app,$l_lang,$l_translation) = $line;
592
-				if ($l_lang != $lang) continue;
638
+				if ($l_lang != $lang)
639
+				{
640
+					continue;
641
+				}
593 642
 				if (!isset($just_app_file) && $l_app != $app)
594 643
 				{
595 644
 					// check if $l_app contained in file in $app_dir is mentioned in $load_via
@@ -603,8 +652,14 @@  discard block
 block discarded – undo
603 652
 						}
604 653
 						// if not update load_via accordingly and store it as config
605 654
 						//error_log(__METHOD__."() load_via does not contain $l_app => $app_dir");
606
-						if (!isset(self::$load_via[$l_app])) self::$load_via[$l_app] = array($l_app);
607
-						if (!is_array(self::$load_via[$l_app])) self::$load_via[$l_app] = array(self::$load_via[$l_app]);
655
+						if (!isset(self::$load_via[$l_app]))
656
+						{
657
+							self::$load_via[$l_app] = array($l_app);
658
+						}
659
+						if (!is_array(self::$load_via[$l_app]))
660
+						{
661
+							self::$load_via[$l_app] = array(self::$load_via[$l_app]);
662
+						}
608 663
 						self::$load_via[$l_app][] = $app_dir;
609 664
 						$updated_load_via = true;
610 665
 					}
@@ -671,7 +726,10 @@  discard block
 block discarded – undo
671 726
 
672 727
 			if ($translate)
673 728
 			{
674
-				if (is_null(self::$db)) self::init(false);
729
+				if (is_null(self::$db))
730
+				{
731
+					self::init(false);
732
+				}
675 733
 
676 734
 				foreach(self::$langs as $lang => $name)
677 735
 				{
@@ -704,10 +762,13 @@  discard block
 block discarded – undo
704 762
 	 */
705 763
 	static function lang2language($lang)
706 764
 	{
707
-		if (isset(self::$langs[$lang]))	// no need to query the DB
765
+		if (isset(self::$langs[$lang]))
766
+		{
767
+			// no need to query the DB
708 768
 		{
709 769
 			return self::$langs[$lang];
710 770
 		}
771
+		}
711 772
 		return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn();
712 773
 	}
713 774
 
@@ -746,7 +807,10 @@  discard block
 block discarded – undo
746 807
 	 */
747 808
 	static function get_lang_file($app,$lang)
748 809
 	{
749
-		if ($app == 'common') $app = 'phpgwapi';
810
+		if ($app == 'common')
811
+		{
812
+			$app = 'phpgwapi';
813
+		}
750 814
 		return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION;
751 815
 	}
752 816
 
@@ -809,9 +873,15 @@  discard block
 block discarded – undo
809 873
 	{
810 874
 		if ($check_to_from)
811 875
 		{
812
-			if ($from) $from = strtolower($from);
876
+			if ($from)
877
+			{
878
+				$from = strtolower($from);
879
+			}
813 880
 
814
-			if ($to) $to = strtolower($to);
881
+			if ($to)
882
+			{
883
+				$to = strtolower($to);
884
+			}
815 885
 
816 886
 			if (!$from)
817 887
 			{
@@ -936,7 +1006,10 @@  discard block
 block discarded – undo
936 1006
 	 */
937 1007
 	static function convert_jsonsafe($_data,$from=False)
938 1008
 	{
939
-		if ($from===false) $from = self::detect_encoding($_data);
1009
+		if ($from===false)
1010
+		{
1011
+			$from = self::detect_encoding($_data);
1012
+		}
940 1013
 
941 1014
 		$data = self::convert($_data, strtolower($from));
942 1015
 
@@ -1035,15 +1108,22 @@  discard block
 block discarded – undo
1035 1108
 	static function get_message_id($translation,$app=null,$lang=null)
1036 1109
 	{
1037 1110
 		$where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation));
1038
-		if ($app) $where['app_name'] = $app;
1039
-		if ($lang) $where['lang'] = $lang;
1111
+		if ($app)
1112
+		{
1113
+			$where['app_name'] = $app;
1114
+		}
1115
+		if ($lang)
1116
+		{
1117
+			$where['lang'] = $lang;
1118
+		}
1040 1119
 
1041 1120
 		$id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn();
1042 1121
 
1043 1122
 		// Check cache, since most things aren't in the DB anymore
1044 1123
 		if(!$id)
1045 1124
 		{
1046
-			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) {
1125
+			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation)
1126
+			{
1047 1127
 				return stripos(self::$lang_arr[$haystack],$translation) !== false;
1048 1128
 			});
1049 1129
 			$id = array_shift($ids);
@@ -1060,10 +1140,17 @@  discard block
 block discarded – undo
1060 1140
 				}
1061 1141
 
1062 1142
 				// load all translations from cache at once
1063
-				if ($tree_level) $lang_arr = Cache::getTree(__CLASS__, $tree_level);
1064
-				if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1143
+				if ($tree_level)
1144
+				{
1145
+					$lang_arr = Cache::getTree(__CLASS__, $tree_level);
1146
+				}
1147
+				if ($instance_level)
1148
+				{
1149
+					$lang_arr = Cache::getInstance(__CLASS__, $instance_level);
1150
+				}
1065 1151
 				$lang_arr = $lang_arr[$app.':en'];
1066
-				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) {
1152
+				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr)
1153
+				{
1067 1154
 					return stripos($lang_arr[$haystack],$translation) !== false;
1068 1155
 				});
1069 1156
 				$id = array_shift($ids);
@@ -1087,7 +1174,10 @@  discard block
 block discarded – undo
1087 1174
 		{
1088 1175
 			$list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended
1089 1176
 
1090
-			if ($verify) array_unshift($list, $verify);
1177
+			if ($verify)
1178
+			{
1179
+				array_unshift($list, $verify);
1180
+			}
1091 1181
 
1092 1182
 			foreach ($list as $item)
1093 1183
 			{
Please login to merge, or discard this patch.