Completed
Push — 14.2 ( 8c75f3...7aeda4 )
by Ralf
108:06 queued 84:21
created
phpgwapi/inc/class.mailDomainSigner.inc.php 4 patches
Doc Comments   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -309,10 +309,8 @@
 block discarded – undo
309 309
    * @param string $h Signed header fields, A colon-separated list of header field names that identify the header fields presented to the signing algorithm
310 310
    * @param array $_h Array of headers in same order with $h (Signed header fields)
311 311
    * @param string $body Raw Email Body String
312
-   * @param string $_c='relaxed/relaxed' header/body canonicalzation algorithm, default "relaxed/relaxed", can also be any combination of "relaxed" or "simple"
313
-   * @param string $_a='rsa-sha1' could also be eg. 'rsa/sha256' and other hashes supported by openssl for rsa signing
314
-   * @param string $_dkim=null template for creating DKIM signature, default as for email appropriate
315
-   * @return string|boolean DKIM-Signature Header String, or false if an error happend, eg. unimplemented canonicalization requested
312
+   * @param string $_dkim
313
+   * @return false|string DKIM-Signature Header String, or false if an error happend, eg. unimplemented canonicalization requested
316 314
    * @access public
317 315
    * @author Ahmad Amarullah
318 316
    */
Please login to merge, or discard this patch.
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
    * @author Ahmad Amarullah
53 53
    */
54 54
   public function __construct($private_key,$d,$s){
55
-    // Get a private key
56
-    $this->pkid = openssl_pkey_get_private($private_key);
55
+	// Get a private key
56
+	$this->pkid = openssl_pkey_get_private($private_key);
57 57
 
58
-    // Save Domain and Selector
59
-    $this->d    = $d;
60
-    $this->s    = $s;
58
+	// Save Domain and Selector
59
+	$this->d    = $d;
60
+	$this->s    = $s;
61 61
   }
62 62
 
63 63
   ///////////////////////
@@ -76,35 +76,35 @@  discard block
 block discarded – undo
76 76
    * @author Ahmad Amarullah
77 77
    */
78 78
   public function nofws($raw_headers,$raw_body){
79
-    // nofws-ed headers
80
-    $headers = array();
81
-
82
-    // Loop the raw_headers
83
-    foreach ($raw_headers as $header){
84
-      // Replace all Folding Whitespace
85
-      $headers[] = preg_replace('/[\r\t\n ]++/','',$header);
86
-    }
87
-
88
-    // Join headers with LF then Add it into data
89
-    $data = implode("\n",$headers)."\n";
90
-
91
-    // Loop Body Lines
92
-    foreach(explode("\n","\n".str_replace("\r","",$raw_body)) as $line)
93
-    {
94
-      // Replace all Folding Whitespace from current line
95
-      // then Add it into data
96
-      $data .= preg_replace('/[\t\n ]++/','',$line)."\n";
97
-    }
98
-
99
-    // Remove Trailing empty lines then split it with LF
100
-    $data = explode("\n",rtrim($data,"\n"));
101
-
102
-    // Join array of data with CRLF and Append CRLF
103
-    // to the resulting line
104
-    $data = implode("\r\n",$data)."\r\n";
105
-
106
-    // Return Canonicalizated Data
107
-    return $data;
79
+	// nofws-ed headers
80
+	$headers = array();
81
+
82
+	// Loop the raw_headers
83
+	foreach ($raw_headers as $header){
84
+	  // Replace all Folding Whitespace
85
+	  $headers[] = preg_replace('/[\r\t\n ]++/','',$header);
86
+	}
87
+
88
+	// Join headers with LF then Add it into data
89
+	$data = implode("\n",$headers)."\n";
90
+
91
+	// Loop Body Lines
92
+	foreach(explode("\n","\n".str_replace("\r","",$raw_body)) as $line)
93
+	{
94
+	  // Replace all Folding Whitespace from current line
95
+	  // then Add it into data
96
+	  $data .= preg_replace('/[\t\n ]++/','',$line)."\n";
97
+	}
98
+
99
+	// Remove Trailing empty lines then split it with LF
100
+	$data = explode("\n",rtrim($data,"\n"));
101
+
102
+	// Join array of data with CRLF and Append CRLF
103
+	// to the resulting line
104
+	$data = implode("\r\n",$data)."\r\n";
105
+
106
+	// Return Canonicalizated Data
107
+	return $data;
108 108
   }
109 109
 
110 110
   /**
@@ -123,32 +123,32 @@  discard block
 block discarded – undo
123 123
    * @author Eric Vyncke
124 124
    */
125 125
   public function headRelaxCanon($s) {
126
-    // Replace CR,LF and spaces into single SP
127
-    $s=preg_replace("/\r\n\s+/"," ",$s) ;
126
+	// Replace CR,LF and spaces into single SP
127
+	$s=preg_replace("/\r\n\s+/"," ",$s) ;
128 128
 
129
-    // Explode Header Line
130
-    $lines=explode("\r\n",$s) ;
129
+	// Explode Header Line
130
+	$lines=explode("\r\n",$s) ;
131 131
 
132
-    // Loop the lines
133
-    foreach ($lines as $key=>$line) {
134
-      // Split the key and value
135
-      list($heading,$value)=explode(":",$line,2) ;
132
+	// Loop the lines
133
+	foreach ($lines as $key=>$line) {
134
+	  // Split the key and value
135
+	  list($heading,$value)=explode(":",$line,2) ;
136 136
 
137
-      // Lowercase heading key
138
-      $heading=strtolower($heading);
137
+	  // Lowercase heading key
138
+	  $heading=strtolower($heading);
139 139
 
140
-      // Compress useless spaces
141
-      $value=preg_replace("/\s+/"," ",$value);
140
+	  // Compress useless spaces
141
+	  $value=preg_replace("/\s+/"," ",$value);
142 142
 
143
-      // Don't forget to remove WSP around the value
144
-      $lines[$key]=$heading.":".trim($value);
145
-    }
143
+	  // Don't forget to remove WSP around the value
144
+	  $lines[$key]=$heading.":".trim($value);
145
+	}
146 146
 
147
-    // Implode it again
148
-    $s=implode("\r\n",$lines);
147
+	// Implode it again
148
+	$s=implode("\r\n",$lines);
149 149
 
150
-    // Return Canonicalizated Headers
151
-    return $s;
150
+	// Return Canonicalizated Headers
151
+	return $s;
152 152
   }
153 153
 
154 154
   /**
@@ -168,40 +168,40 @@  discard block
 block discarded – undo
168 168
    * @author Ralf Becker
169 169
    */
170 170
   public function headIScheduleRelaxCanon($s) {
171
-    // Replace CR,LF and spaces into single SP
172
-    $s=preg_replace("/\r\n\s+/"," ",$s) ;
171
+	// Replace CR,LF and spaces into single SP
172
+	$s=preg_replace("/\r\n\s+/"," ",$s) ;
173 173
 
174
-    // Loop exploded header lines
175
-    $lines=array();
176
-    foreach (explode("\r\n",$s) as $line) {
177
-      // Split the key and value
178
-      list($heading,$value)=explode(":",$line,2) ;
174
+	// Loop exploded header lines
175
+	$lines=array();
176
+	foreach (explode("\r\n",$s) as $line) {
177
+	  // Split the key and value
178
+	  list($heading,$value)=explode(":",$line,2) ;
179 179
 
180
-      // Lowercase heading key
181
-      $heading=strtolower($heading);
180
+	  // Lowercase heading key
181
+	  $heading=strtolower($heading);
182 182
 
183
-      // Compress useless spaces
184
-      $value=preg_replace("/\s+/"," ",$value);
183
+	  // Compress useless spaces
184
+	  $value=preg_replace("/\s+/"," ",$value);
185 185
 
186
-      // Don't forget to remove WSP around the value
187
-      $value = trim($value);
186
+	  // Don't forget to remove WSP around the value
187
+	  $value = trim($value);
188 188
 
189
-      // remove whitespace after comma in values
190
-      $value = preg_replace("/,\s+/",",",$value);
189
+	  // remove whitespace after comma in values
190
+	  $value = preg_replace("/,\s+/",",",$value);
191 191
 
192
-      // for multiple headers, add them comma-separated to existing headers
193
-      if (isset($lines[$heading])) {
194
-      	$lines[$heading] .= ','.$value;
195
-      } else {
196
-      	$lines[$heading] = $heading.':'.$value;
197
-      }
198
-    }
192
+	  // for multiple headers, add them comma-separated to existing headers
193
+	  if (isset($lines[$heading])) {
194
+	  	$lines[$heading] .= ','.$value;
195
+	  } else {
196
+	  	$lines[$heading] = $heading.':'.$value;
197
+	  }
198
+	}
199 199
 
200
-    // Implode it again
201
-    $s=implode("\r\n",$lines);
200
+	// Implode it again
201
+	$s=implode("\r\n",$lines);
202 202
 
203
-    // Return Canonicalizated Headers
204
-    return $s;
203
+	// Return Canonicalizated Headers
204
+	return $s;
205 205
   }
206 206
 
207 207
   /**
@@ -231,32 +231,32 @@  discard block
 block discarded – undo
231 231
    * @author Ahmad Amarullah
232 232
    */
233 233
   public function bodyRelaxCanon($body) {
234
-    // Return CRLF for empty body
235
-    if ($body == ''){
236
-      return "\r\n";
237
-    }
234
+	// Return CRLF for empty body
235
+	if ($body == ''){
236
+	  return "\r\n";
237
+	}
238 238
 
239
-    // Replace all CRLF to LF
240
-    $body = str_replace("\r\n","\n",$body);
239
+	// Replace all CRLF to LF
240
+	$body = str_replace("\r\n","\n",$body);
241 241
 
242
-    // Replace LF to CRLF
243
-    $body = str_replace("\n","\r\n",$body);
242
+	// Replace LF to CRLF
243
+	$body = str_replace("\n","\r\n",$body);
244 244
 
245
-    // Ignores all whitespace at the end of lines
246
-    $body=rtrim($body,"\r\n");
245
+	// Ignores all whitespace at the end of lines
246
+	$body=rtrim($body,"\r\n");
247 247
 
248
-    // Canonicalizated String Variable
249
-    $canon_body = '';
248
+	// Canonicalizated String Variable
249
+	$canon_body = '';
250 250
 
251
-    // Split the body into lines
252
-    foreach(explode("\r\n",$body) as $line){
253
-      // Reduces all sequences of White Space within a line
254
-      // to a single SP character
255
-      $canon_body.= rtrim(preg_replace('/[\t\n ]++/',' ',$line))."\r\n";
256
-    }
251
+	// Split the body into lines
252
+	foreach(explode("\r\n",$body) as $line){
253
+	  // Reduces all sequences of White Space within a line
254
+	  // to a single SP character
255
+	  $canon_body.= rtrim(preg_replace('/[\t\n ]++/',' ',$line))."\r\n";
256
+	}
257 257
 
258
-    // Return the Canonicalizated Body
259
-    return $canon_body;
258
+	// Return the Canonicalizated Body
259
+	return $canon_body;
260 260
   }
261 261
 
262 262
   /**
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
   	// add a single CRLF at the end
279 279
   	$body .= "\r\n";
280 280
 
281
-    // Return the Canonicalizated Body
282
-    return $body;
281
+	// Return the Canonicalizated Body
282
+	return $body;
283 283
   }
284 284
 
285 285
   //////////////////////
@@ -318,47 +318,47 @@  discard block
 block discarded – undo
318 318
    */
319 319
   public function getDKIM($h,$_h,$body,$_c='relaxed/relaxed',$_a='rsa-sha1',$_dkim=null) {
320 320
 
321
-    // Relax Canonicalization for Body
321
+	// Relax Canonicalization for Body
322 322
  	list($header_canon,$body_canon) = explode('/',$_c);
323 323
   	switch($body_canon)
324 324
   	{
325 325
   		case 'relaxed':
326
-    		$_b = $this->bodyRelaxCanon($body);
327
-    		break;
326
+			$_b = $this->bodyRelaxCanon($body);
327
+			break;
328 328
 
329 329
   		case 'simple':
330
-    		$_b = $this->bodySimpleCanon($body);
331
-    		break;
330
+			$_b = $this->bodySimpleCanon($body);
331
+			break;
332 332
 
333 333
   		default:
334 334
   			return false;	// unknown/unimplemented canonicalzation algorithm
335 335
   	}
336 336
 
337
-    // Canonicalizated Body Length [tag:l]
338
-    // use mb_strlen if availble to get length in bytes/octets, to kope with evtl. set mbstring.func_overload!
339
-    $_l = function_exists('mb_strlen') ? mb_strlen($_b, '8bit') : strlen($_b);
340
-
341
-    // Signature Timestamp [tag:t]
342
-    $_t = time();
343
-
344
-    // Hash of the canonicalized body [tag:bh]
345
-    list(,$hash_algo) = explode('-', $_a);
346
-    $_bh = base64_encode(hash($hash_algo,$_b,true));
347
-
348
-    // Creating DKIM-Signature
349
-    if (is_null($_dkim)) {
350
-	    $_dkim = "DKIM-Signature: ".
351
-	                "v=1; ".          // DKIM Version
352
-	                "a=\$a; ".        // The algorithm used to generate the signature "rsa-sha1"
353
-	                "s=\$s; ".        // The selector subdividing the namespace for the "d=" (domain) tag
354
-	                "d=\$d; ".        // The domain of the signing entity
355
-	                "l=\$l; ".        // Canonicalizated Body length count
356
-	                "t=\$t; ".        // Signature Timestamp
357
-	                "c=\$c; ".        // Message (Headers/Body) Canonicalization "relaxed/relaxed"
358
-	                "h=\$h; ".        // Signed header fields
359
-	                "bh=\$bh;\r\n\t". // The hash of the canonicalized body part of the message
360
-	                "b=";             // The signature data (Empty because we will calculate it later)
361
-    }
337
+	// Canonicalizated Body Length [tag:l]
338
+	// use mb_strlen if availble to get length in bytes/octets, to kope with evtl. set mbstring.func_overload!
339
+	$_l = function_exists('mb_strlen') ? mb_strlen($_b, '8bit') : strlen($_b);
340
+
341
+	// Signature Timestamp [tag:t]
342
+	$_t = time();
343
+
344
+	// Hash of the canonicalized body [tag:bh]
345
+	list(,$hash_algo) = explode('-', $_a);
346
+	$_bh = base64_encode(hash($hash_algo,$_b,true));
347
+
348
+	// Creating DKIM-Signature
349
+	if (is_null($_dkim)) {
350
+		$_dkim = "DKIM-Signature: ".
351
+					"v=1; ".          // DKIM Version
352
+					"a=\$a; ".        // The algorithm used to generate the signature "rsa-sha1"
353
+					"s=\$s; ".        // The selector subdividing the namespace for the "d=" (domain) tag
354
+					"d=\$d; ".        // The domain of the signing entity
355
+					"l=\$l; ".        // Canonicalizated Body length count
356
+					"t=\$t; ".        // Signature Timestamp
357
+					"c=\$c; ".        // Message (Headers/Body) Canonicalization "relaxed/relaxed"
358
+					"h=\$h; ".        // Signed header fields
359
+					"bh=\$bh;\r\n\t". // The hash of the canonicalized body part of the message
360
+					"b=";             // The signature data (Empty because we will calculate it later)
361
+	}
362 362
 	$_dkim = strtr($_dkim, array(
363 363
 		'$a' => $_a,
364 364
 		'$s' => $this->s,
@@ -369,39 +369,39 @@  discard block
 block discarded – undo
369 369
 		'$h' => $h,
370 370
 		'$bh' => $_bh,
371 371
 	));
372
-    // Wrap DKIM Header
373
-    $_dkim = wordwrap($_dkim,76,"\r\n\t");
372
+	// Wrap DKIM Header
373
+	$_dkim = wordwrap($_dkim,76,"\r\n\t");
374 374
 
375
-    // Canonicalization Header Data
375
+	// Canonicalization Header Data
376 376
   	switch($header_canon)
377 377
   	{
378 378
   		case 'relaxed':
379
-    		$_unsigned  = $this->headRelaxCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
380
-    		break;
379
+			$_unsigned  = $this->headRelaxCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
380
+			break;
381 381
 
382 382
   		case 'ischedule-relaxed':
383
-    		$_unsigned  = $this->headIScheduleRelaxCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
384
-    		break;
383
+			$_unsigned  = $this->headIScheduleRelaxCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
384
+			break;
385 385
 
386
-    	case 'simple':
387
-    		$_unsigned  = $this->headSimpleCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
388
-     		break;
386
+		case 'simple':
387
+			$_unsigned  = $this->headSimpleCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
388
+	 		break;
389 389
 
390 390
   		default:
391 391
   			return false;	// unknown/unimplemented canonicalzation algorithm
392 392
   	}
393 393
 error_log(__METHOD__."() unsigned='".str_replace(array("\r","\n"),array('\\r','\\n'),$_unsigned)."'");
394 394
 
395
-    // Sign Canonicalization Header Data with Private Key
396
-    openssl_sign($_unsigned, $_signed, $this->pkid, $hash_algo);
395
+	// Sign Canonicalization Header Data with Private Key
396
+	openssl_sign($_unsigned, $_signed, $this->pkid, $hash_algo);
397 397
 
398
-    // Base64 encoded signed data
399
-    // Chunk Split it
400
-    // Then Append it $_dkim
401
-    $_dkim   .= chunk_split(base64_encode($_signed),76,"\r\n\t");
398
+	// Base64 encoded signed data
399
+	// Chunk Split it
400
+	// Then Append it $_dkim
401
+	$_dkim   .= chunk_split(base64_encode($_signed),76,"\r\n\t");
402 402
 
403
-    // Return trimmed $_dkim
404
-    return trim($_dkim);
403
+	// Return trimmed $_dkim
404
+	return trim($_dkim);
405 405
   }
406 406
 
407 407
   /**
@@ -428,34 +428,34 @@  discard block
 block discarded – undo
428 428
    * @author Ahmad Amarullah
429 429
    */
430 430
   public function getDomainKey($h,$_h,$body){
431
-    // If $h = empty, dont add h tag into DomainKey-Signature
432
-    $hval = '';
433
-    if ($h)
434
-      $hval= "h={$h}; ";
435
-
436
-    // Creating DomainKey-Signature
437
-    $_dk = "DomainKey-Signature: ".
438
-              "a=rsa-sha1; ".           // The algorithm used to generate the signature "rsa-sha1"
439
-              "c=nofws; ".              // Canonicalization Alghoritm "nofws"
440
-              "d={$this->d}; ".         // The domain of the signing entity
441
-              "s={$this->s}; ".         // The selector subdividing the namespace for the "d=" (domain) tag
442
-              "{$hval}";                // If Exists - Signed header fields
443
-
444
-    // nofws Canonicalization for headers and body data
445
-    $_unsigned  = $this->nofws($_h,$body);
446
-
447
-    // Sign nofws Canonicalizated Data with Private Key
448
-    openssl_sign($_unsigned, $_signed, $this->pkid, OPENSSL_ALGO_SHA1);
449
-
450
-    // Base64 encoded signed data
451
-    // Chunk Split it
452
-    $b = chunk_split(base64_encode($_signed),76,"\r\n\t");
453
-
454
-    // Append sign data into b tag in $_dk
455
-    $_dk.="b={$b}";
456
-
457
-    // Return Wrapped and trimmed $_dk
458
-    return trim(wordwrap($_dk,76,"\r\n\t"));
431
+	// If $h = empty, dont add h tag into DomainKey-Signature
432
+	$hval = '';
433
+	if ($h)
434
+	  $hval= "h={$h}; ";
435
+
436
+	// Creating DomainKey-Signature
437
+	$_dk = "DomainKey-Signature: ".
438
+			  "a=rsa-sha1; ".           // The algorithm used to generate the signature "rsa-sha1"
439
+			  "c=nofws; ".              // Canonicalization Alghoritm "nofws"
440
+			  "d={$this->d}; ".         // The domain of the signing entity
441
+			  "s={$this->s}; ".         // The selector subdividing the namespace for the "d=" (domain) tag
442
+			  "{$hval}";                // If Exists - Signed header fields
443
+
444
+	// nofws Canonicalization for headers and body data
445
+	$_unsigned  = $this->nofws($_h,$body);
446
+
447
+	// Sign nofws Canonicalizated Data with Private Key
448
+	openssl_sign($_unsigned, $_signed, $this->pkid, OPENSSL_ALGO_SHA1);
449
+
450
+	// Base64 encoded signed data
451
+	// Chunk Split it
452
+	$b = chunk_split(base64_encode($_signed),76,"\r\n\t");
453
+
454
+	// Append sign data into b tag in $_dk
455
+	$_dk.="b={$b}";
456
+
457
+	// Return Wrapped and trimmed $_dk
458
+	return trim(wordwrap($_dk,76,"\r\n\t"));
459 459
   }
460 460
 
461 461
   /**
@@ -480,107 +480,107 @@  discard block
 block discarded – undo
480 480
    * @author Ahmad Amarullah
481 481
    */
482 482
   public function sign(
483
-      $mail_data,                                 // Raw Mail Data
484
-      $suggested_h = "from:to:subject",           // Suggested Signed Header Fields
485
-      $create_dkim = true,                        // Create DKIM-Signature Header
486
-      $create_domainkey = true,                   // Create DomainKey-Signature Header
487
-      $out_sign_header_only = false               // Return Signature Header Only without original data
488
-    ){
489
-
490
-    if (!$suggested_h) $suggested_h = "from:to:subject"; // Default Suggested Signed Header Fields
491
-
492
-    // Remove all space and Lowercase Suggested Signed header fields then split it into array
493
-    $_h = explode(":",strtolower(preg_replace('/[\r\t\n ]++/','',$suggested_h)));
494
-
495
-    // Split Raw Mail data into $raw_headers and $body
496
-    list($raw_headers, $body) = explode("\r\n\r\n",$mail_data,2);
497
-
498
-    // Explode $raw_header into $header_list
499
-    $header_list = preg_split("/\r\n(?![\t ])/", $raw_headers);
500
-
501
-    // Empty Header Array
502
-    $headers = array();
503
-
504
-    // Loop $header_list
505
-    foreach($header_list as $header){
506
-      // Find Header Key for Array Key
507
-      list($key) = explode(':',$header, 2);
508
-
509
-      // Trim and Lowercase It
510
-      $key = strtolower(trim($key));
511
-
512
-      // If header with current key was exists
513
-      // Change it into array
514
-      if (isset($headers[$key])){
515
-        // If header not yet array set as Array
516
-        if (!is_array($headers[$key]))
517
-          $headers[$key] = array($headers[$key]);
518
-
519
-        // Add Current Header as next element
520
-        $headers[$key][] = $header;
521
-      }
522
-
523
-      // If header with current key not exists
524
-      // Insert header as string
525
-      else{
526
-        $headers[$key] = $header;
527
-      }
528
-    }
529
-
530
-    // Now, lets find accepted Suggested Signed header fields
531
-    // and reorder it to match headers position
532
-
533
-    $accepted_h = array();          // For Accepted Signed header fields
534
-    $accepted_headers = array();    // For Accepted Header
535
-
536
-    // Loop the Headers Array
537
-    foreach ($headers as $key=>$val){
538
-      // Check if $val wasn't array
539
-      // We don't want to include multiple headers as Signed header fields
540
-      if (!is_array($val)){
541
-        // Check if this header exists in Suggested Signed header fields
542
-        if (in_array($key,$_h)){
543
-          // If Exists, add it into accepted headers and accepted header fields
544
-          $accepted_h[] = $key;
545
-          $accepted_headers[] = $val;
546
-        }
547
-      }
548
-    }
549
-
550
-    // If it doesn't contain any $accepted_h
551
-    // return false, because we don't have enough data
552
-    // for signing email
553
-    if (count($accepted_h)==0)
554
-      return false;
555
-
556
-    // Create $_hdata for Signed header fields
557
-    // by imploding it with colon
558
-    $_hdata = implode(":",$accepted_h);
559
-
560
-    // New Headers Variable
561
-    $_nh = array("x-domain-signer"=>"X-Domain-Signer: {$this->__app_name} {$this->__app_ver} <$this->__app_url>");
562
-
563
-    // Create DKIM First
564
-    if ($create_dkim)
565
-      $_nh['dkim-signature'] = $this->getDKIM($_hdata,$accepted_headers,$body);
566
-
567
-    // Now Create Domain-Signature
568
-    if ($create_domainkey)
569
-      $_nh['domainKey-signature'] = $this->getDomainKey($_hdata,$accepted_headers,$body);
570
-
571
-    // Implode $_nh with \r\n
572
-    $to_be_appended_headers = implode("\r\n",$_nh);
573
-
574
-    // Return Immediately if
575
-    // * $out_sign_header_only=true (as headers string)
576
-    // * $out_sign_header_only=2    (as headers array)
577
-    if ($out_sign_header_only===2)
578
-      return $_nh;
579
-    elseif ($out_sign_header_only)
580
-      return "{$to_be_appended_headers}\r\n";
581
-
582
-    // Return signed headers with original data
583
-    return "{$to_be_appended_headers}\r\n{$mail_data}";
483
+	  $mail_data,                                 // Raw Mail Data
484
+	  $suggested_h = "from:to:subject",           // Suggested Signed Header Fields
485
+	  $create_dkim = true,                        // Create DKIM-Signature Header
486
+	  $create_domainkey = true,                   // Create DomainKey-Signature Header
487
+	  $out_sign_header_only = false               // Return Signature Header Only without original data
488
+	){
489
+
490
+	if (!$suggested_h) $suggested_h = "from:to:subject"; // Default Suggested Signed Header Fields
491
+
492
+	// Remove all space and Lowercase Suggested Signed header fields then split it into array
493
+	$_h = explode(":",strtolower(preg_replace('/[\r\t\n ]++/','',$suggested_h)));
494
+
495
+	// Split Raw Mail data into $raw_headers and $body
496
+	list($raw_headers, $body) = explode("\r\n\r\n",$mail_data,2);
497
+
498
+	// Explode $raw_header into $header_list
499
+	$header_list = preg_split("/\r\n(?![\t ])/", $raw_headers);
500
+
501
+	// Empty Header Array
502
+	$headers = array();
503
+
504
+	// Loop $header_list
505
+	foreach($header_list as $header){
506
+	  // Find Header Key for Array Key
507
+	  list($key) = explode(':',$header, 2);
508
+
509
+	  // Trim and Lowercase It
510
+	  $key = strtolower(trim($key));
511
+
512
+	  // If header with current key was exists
513
+	  // Change it into array
514
+	  if (isset($headers[$key])){
515
+		// If header not yet array set as Array
516
+		if (!is_array($headers[$key]))
517
+		  $headers[$key] = array($headers[$key]);
518
+
519
+		// Add Current Header as next element
520
+		$headers[$key][] = $header;
521
+	  }
522
+
523
+	  // If header with current key not exists
524
+	  // Insert header as string
525
+	  else{
526
+		$headers[$key] = $header;
527
+	  }
528
+	}
529
+
530
+	// Now, lets find accepted Suggested Signed header fields
531
+	// and reorder it to match headers position
532
+
533
+	$accepted_h = array();          // For Accepted Signed header fields
534
+	$accepted_headers = array();    // For Accepted Header
535
+
536
+	// Loop the Headers Array
537
+	foreach ($headers as $key=>$val){
538
+	  // Check if $val wasn't array
539
+	  // We don't want to include multiple headers as Signed header fields
540
+	  if (!is_array($val)){
541
+		// Check if this header exists in Suggested Signed header fields
542
+		if (in_array($key,$_h)){
543
+		  // If Exists, add it into accepted headers and accepted header fields
544
+		  $accepted_h[] = $key;
545
+		  $accepted_headers[] = $val;
546
+		}
547
+	  }
548
+	}
549
+
550
+	// If it doesn't contain any $accepted_h
551
+	// return false, because we don't have enough data
552
+	// for signing email
553
+	if (count($accepted_h)==0)
554
+	  return false;
555
+
556
+	// Create $_hdata for Signed header fields
557
+	// by imploding it with colon
558
+	$_hdata = implode(":",$accepted_h);
559
+
560
+	// New Headers Variable
561
+	$_nh = array("x-domain-signer"=>"X-Domain-Signer: {$this->__app_name} {$this->__app_ver} <$this->__app_url>");
562
+
563
+	// Create DKIM First
564
+	if ($create_dkim)
565
+	  $_nh['dkim-signature'] = $this->getDKIM($_hdata,$accepted_headers,$body);
566
+
567
+	// Now Create Domain-Signature
568
+	if ($create_domainkey)
569
+	  $_nh['domainKey-signature'] = $this->getDomainKey($_hdata,$accepted_headers,$body);
570
+
571
+	// Implode $_nh with \r\n
572
+	$to_be_appended_headers = implode("\r\n",$_nh);
573
+
574
+	// Return Immediately if
575
+	// * $out_sign_header_only=true (as headers string)
576
+	// * $out_sign_header_only=2    (as headers array)
577
+	if ($out_sign_header_only===2)
578
+	  return $_nh;
579
+	elseif ($out_sign_header_only)
580
+	  return "{$to_be_appended_headers}\r\n";
581
+
582
+	// Return signed headers with original data
583
+	return "{$to_be_appended_headers}\r\n{$mail_data}";
584 584
   }
585 585
 }
586 586
 
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
  * @package mailDomainSigner
29 29
  * @author Ahmad Amarullah
30 30
  */
31
-class mailDomainSigner{
31
+class mailDomainSigner {
32 32
 
33 33
   ///////////////////////
34 34
   // PRIVATE VARIABLES //
35 35
   ///////////////////////
36
-  private $pkid=null;
36
+  private $pkid = null;
37 37
   private $s;
38 38
   private $d;
39 39
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
    * @param string $s The selector used to form the query for the public key
52 52
    * @author Ahmad Amarullah
53 53
    */
54
-  public function __construct($private_key,$d,$s){
54
+  public function __construct($private_key, $d, $s) {
55 55
     // Get a private key
56 56
     $this->pkid = openssl_pkey_get_private($private_key);
57 57
 
@@ -75,33 +75,33 @@  discard block
 block discarded – undo
75 75
    * @access public
76 76
    * @author Ahmad Amarullah
77 77
    */
78
-  public function nofws($raw_headers,$raw_body){
78
+  public function nofws($raw_headers, $raw_body) {
79 79
     // nofws-ed headers
80 80
     $headers = array();
81 81
 
82 82
     // Loop the raw_headers
83
-    foreach ($raw_headers as $header){
83
+    foreach ($raw_headers as $header) {
84 84
       // Replace all Folding Whitespace
85
-      $headers[] = preg_replace('/[\r\t\n ]++/','',$header);
85
+      $headers[] = preg_replace('/[\r\t\n ]++/', '', $header);
86 86
     }
87 87
 
88 88
     // Join headers with LF then Add it into data
89
-    $data = implode("\n",$headers)."\n";
89
+    $data = implode("\n", $headers)."\n";
90 90
 
91 91
     // Loop Body Lines
92
-    foreach(explode("\n","\n".str_replace("\r","",$raw_body)) as $line)
92
+    foreach (explode("\n", "\n".str_replace("\r", "", $raw_body)) as $line)
93 93
     {
94 94
       // Replace all Folding Whitespace from current line
95 95
       // then Add it into data
96
-      $data .= preg_replace('/[\t\n ]++/','',$line)."\n";
96
+      $data .= preg_replace('/[\t\n ]++/', '', $line)."\n";
97 97
     }
98 98
 
99 99
     // Remove Trailing empty lines then split it with LF
100
-    $data = explode("\n",rtrim($data,"\n"));
100
+    $data = explode("\n", rtrim($data, "\n"));
101 101
 
102 102
     // Join array of data with CRLF and Append CRLF
103 103
     // to the resulting line
104
-    $data = implode("\r\n",$data)."\r\n";
104
+    $data = implode("\r\n", $data)."\r\n";
105 105
 
106 106
     // Return Canonicalizated Data
107 107
     return $data;
@@ -124,28 +124,28 @@  discard block
 block discarded – undo
124 124
    */
125 125
   public function headRelaxCanon($s) {
126 126
     // Replace CR,LF and spaces into single SP
127
-    $s=preg_replace("/\r\n\s+/"," ",$s) ;
127
+    $s = preg_replace("/\r\n\s+/", " ", $s);
128 128
 
129 129
     // Explode Header Line
130
-    $lines=explode("\r\n",$s) ;
130
+    $lines = explode("\r\n", $s);
131 131
 
132 132
     // Loop the lines
133 133
     foreach ($lines as $key=>$line) {
134 134
       // Split the key and value
135
-      list($heading,$value)=explode(":",$line,2) ;
135
+      list($heading, $value) = explode(":", $line, 2);
136 136
 
137 137
       // Lowercase heading key
138
-      $heading=strtolower($heading);
138
+      $heading = strtolower($heading);
139 139
 
140 140
       // Compress useless spaces
141
-      $value=preg_replace("/\s+/"," ",$value);
141
+      $value = preg_replace("/\s+/", " ", $value);
142 142
 
143 143
       // Don't forget to remove WSP around the value
144
-      $lines[$key]=$heading.":".trim($value);
144
+      $lines[$key] = $heading.":".trim($value);
145 145
     }
146 146
 
147 147
     // Implode it again
148
-    $s=implode("\r\n",$lines);
148
+    $s = implode("\r\n", $lines);
149 149
 
150 150
     // Return Canonicalizated Headers
151 151
     return $s;
@@ -169,25 +169,25 @@  discard block
 block discarded – undo
169 169
    */
170 170
   public function headIScheduleRelaxCanon($s) {
171 171
     // Replace CR,LF and spaces into single SP
172
-    $s=preg_replace("/\r\n\s+/"," ",$s) ;
172
+    $s = preg_replace("/\r\n\s+/", " ", $s);
173 173
 
174 174
     // Loop exploded header lines
175
-    $lines=array();
176
-    foreach (explode("\r\n",$s) as $line) {
175
+    $lines = array();
176
+    foreach (explode("\r\n", $s) as $line) {
177 177
       // Split the key and value
178
-      list($heading,$value)=explode(":",$line,2) ;
178
+      list($heading, $value) = explode(":", $line, 2);
179 179
 
180 180
       // Lowercase heading key
181
-      $heading=strtolower($heading);
181
+      $heading = strtolower($heading);
182 182
 
183 183
       // Compress useless spaces
184
-      $value=preg_replace("/\s+/"," ",$value);
184
+      $value = preg_replace("/\s+/", " ", $value);
185 185
 
186 186
       // Don't forget to remove WSP around the value
187 187
       $value = trim($value);
188 188
 
189 189
       // remove whitespace after comma in values
190
-      $value = preg_replace("/,\s+/",",",$value);
190
+      $value = preg_replace("/,\s+/", ",", $value);
191 191
 
192 192
       // for multiple headers, add them comma-separated to existing headers
193 193
       if (isset($lines[$heading])) {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     }
199 199
 
200 200
     // Implode it again
201
-    $s=implode("\r\n",$lines);
201
+    $s = implode("\r\n", $lines);
202 202
 
203 203
     // Return Canonicalizated Headers
204 204
     return $s;
@@ -232,27 +232,27 @@  discard block
 block discarded – undo
232 232
    */
233 233
   public function bodyRelaxCanon($body) {
234 234
     // Return CRLF for empty body
235
-    if ($body == ''){
235
+    if ($body == '') {
236 236
       return "\r\n";
237 237
     }
238 238
 
239 239
     // Replace all CRLF to LF
240
-    $body = str_replace("\r\n","\n",$body);
240
+    $body = str_replace("\r\n", "\n", $body);
241 241
 
242 242
     // Replace LF to CRLF
243
-    $body = str_replace("\n","\r\n",$body);
243
+    $body = str_replace("\n", "\r\n", $body);
244 244
 
245 245
     // Ignores all whitespace at the end of lines
246
-    $body=rtrim($body,"\r\n");
246
+    $body = rtrim($body, "\r\n");
247 247
 
248 248
     // Canonicalizated String Variable
249 249
     $canon_body = '';
250 250
 
251 251
     // Split the body into lines
252
-    foreach(explode("\r\n",$body) as $line){
252
+    foreach (explode("\r\n", $body) as $line) {
253 253
       // Reduces all sequences of White Space within a line
254 254
       // to a single SP character
255
-      $canon_body.= rtrim(preg_replace('/[\t\n ]++/',' ',$line))."\r\n";
255
+      $canon_body .= rtrim(preg_replace('/[\t\n ]++/', ' ', $line))."\r\n";
256 256
     }
257 257
 
258 258
     // Return the Canonicalizated Body
@@ -316,11 +316,11 @@  discard block
 block discarded – undo
316 316
    * @access public
317 317
    * @author Ahmad Amarullah
318 318
    */
319
-  public function getDKIM($h,$_h,$body,$_c='relaxed/relaxed',$_a='rsa-sha1',$_dkim=null) {
319
+  public function getDKIM($h, $_h, $body, $_c = 'relaxed/relaxed', $_a = 'rsa-sha1', $_dkim = null) {
320 320
 
321 321
     // Relax Canonicalization for Body
322
- 	list($header_canon,$body_canon) = explode('/',$_c);
323
-  	switch($body_canon)
322
+ 	list($header_canon, $body_canon) = explode('/', $_c);
323
+  	switch ($body_canon)
324 324
   	{
325 325
   		case 'relaxed':
326 326
     		$_b = $this->bodyRelaxCanon($body);
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
     		break;
332 332
 
333 333
   		default:
334
-  			return false;	// unknown/unimplemented canonicalzation algorithm
334
+  			return false; // unknown/unimplemented canonicalzation algorithm
335 335
   	}
336 336
 
337 337
     // Canonicalizated Body Length [tag:l]
@@ -343,21 +343,21 @@  discard block
 block discarded – undo
343 343
 
344 344
     // Hash of the canonicalized body [tag:bh]
345 345
     list(,$hash_algo) = explode('-', $_a);
346
-    $_bh = base64_encode(hash($hash_algo,$_b,true));
346
+    $_bh = base64_encode(hash($hash_algo, $_b, true));
347 347
 
348 348
     // Creating DKIM-Signature
349 349
     if (is_null($_dkim)) {
350 350
 	    $_dkim = "DKIM-Signature: ".
351
-	                "v=1; ".          // DKIM Version
352
-	                "a=\$a; ".        // The algorithm used to generate the signature "rsa-sha1"
353
-	                "s=\$s; ".        // The selector subdividing the namespace for the "d=" (domain) tag
354
-	                "d=\$d; ".        // The domain of the signing entity
355
-	                "l=\$l; ".        // Canonicalizated Body length count
356
-	                "t=\$t; ".        // Signature Timestamp
357
-	                "c=\$c; ".        // Message (Headers/Body) Canonicalization "relaxed/relaxed"
358
-	                "h=\$h; ".        // Signed header fields
359
-	                "bh=\$bh;\r\n\t". // The hash of the canonicalized body part of the message
360
-	                "b=";             // The signature data (Empty because we will calculate it later)
351
+	                "v=1; ".// DKIM Version
352
+	                "a=\$a; ".// The algorithm used to generate the signature "rsa-sha1"
353
+	                "s=\$s; ".// The selector subdividing the namespace for the "d=" (domain) tag
354
+	                "d=\$d; ".// The domain of the signing entity
355
+	                "l=\$l; ".// Canonicalizated Body length count
356
+	                "t=\$t; ".// Signature Timestamp
357
+	                "c=\$c; ".// Message (Headers/Body) Canonicalization "relaxed/relaxed"
358
+	                "h=\$h; ".// Signed header fields
359
+	                "bh=\$bh;\r\n\t".// The hash of the canonicalized body part of the message
360
+	                "b="; // The signature data (Empty because we will calculate it later)
361 361
     }
362 362
 	$_dkim = strtr($_dkim, array(
363 363
 		'$a' => $_a,
@@ -370,27 +370,27 @@  discard block
 block discarded – undo
370 370
 		'$bh' => $_bh,
371 371
 	));
372 372
     // Wrap DKIM Header
373
-    $_dkim = wordwrap($_dkim,76,"\r\n\t");
373
+    $_dkim = wordwrap($_dkim, 76, "\r\n\t");
374 374
 
375 375
     // Canonicalization Header Data
376
-  	switch($header_canon)
376
+  	switch ($header_canon)
377 377
   	{
378 378
   		case 'relaxed':
379
-    		$_unsigned  = $this->headRelaxCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
379
+    		$_unsigned = $this->headRelaxCanon(implode("\r\n", $_h)."\r\n{$_dkim}");
380 380
     		break;
381 381
 
382 382
   		case 'ischedule-relaxed':
383
-    		$_unsigned  = $this->headIScheduleRelaxCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
383
+    		$_unsigned = $this->headIScheduleRelaxCanon(implode("\r\n", $_h)."\r\n{$_dkim}");
384 384
     		break;
385 385
 
386 386
     	case 'simple':
387
-    		$_unsigned  = $this->headSimpleCanon(implode("\r\n",$_h)."\r\n{$_dkim}");
387
+    		$_unsigned = $this->headSimpleCanon(implode("\r\n", $_h)."\r\n{$_dkim}");
388 388
      		break;
389 389
 
390 390
   		default:
391
-  			return false;	// unknown/unimplemented canonicalzation algorithm
391
+  			return false; // unknown/unimplemented canonicalzation algorithm
392 392
   	}
393
-error_log(__METHOD__."() unsigned='".str_replace(array("\r","\n"),array('\\r','\\n'),$_unsigned)."'");
393
+error_log(__METHOD__."() unsigned='".str_replace(array("\r", "\n"), array('\\r', '\\n'), $_unsigned)."'");
394 394
 
395 395
     // Sign Canonicalization Header Data with Private Key
396 396
     openssl_sign($_unsigned, $_signed, $this->pkid, $hash_algo);
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
     // Base64 encoded signed data
399 399
     // Chunk Split it
400 400
     // Then Append it $_dkim
401
-    $_dkim   .= chunk_split(base64_encode($_signed),76,"\r\n\t");
401
+    $_dkim .= chunk_split(base64_encode($_signed), 76, "\r\n\t");
402 402
 
403 403
     // Return trimmed $_dkim
404 404
     return trim($_dkim);
@@ -427,35 +427,35 @@  discard block
 block discarded – undo
427 427
    * @access public
428 428
    * @author Ahmad Amarullah
429 429
    */
430
-  public function getDomainKey($h,$_h,$body){
430
+  public function getDomainKey($h, $_h, $body) {
431 431
     // If $h = empty, dont add h tag into DomainKey-Signature
432 432
     $hval = '';
433 433
     if ($h)
434
-      $hval= "h={$h}; ";
434
+      $hval = "h={$h}; ";
435 435
 
436 436
     // Creating DomainKey-Signature
437 437
     $_dk = "DomainKey-Signature: ".
438
-              "a=rsa-sha1; ".           // The algorithm used to generate the signature "rsa-sha1"
439
-              "c=nofws; ".              // Canonicalization Alghoritm "nofws"
440
-              "d={$this->d}; ".         // The domain of the signing entity
441
-              "s={$this->s}; ".         // The selector subdividing the namespace for the "d=" (domain) tag
442
-              "{$hval}";                // If Exists - Signed header fields
438
+              "a=rsa-sha1; ".// The algorithm used to generate the signature "rsa-sha1"
439
+              "c=nofws; ".// Canonicalization Alghoritm "nofws"
440
+              "d={$this->d}; ".// The domain of the signing entity
441
+              "s={$this->s}; ".// The selector subdividing the namespace for the "d=" (domain) tag
442
+              "{$hval}"; // If Exists - Signed header fields
443 443
 
444 444
     // nofws Canonicalization for headers and body data
445
-    $_unsigned  = $this->nofws($_h,$body);
445
+    $_unsigned = $this->nofws($_h, $body);
446 446
 
447 447
     // Sign nofws Canonicalizated Data with Private Key
448 448
     openssl_sign($_unsigned, $_signed, $this->pkid, OPENSSL_ALGO_SHA1);
449 449
 
450 450
     // Base64 encoded signed data
451 451
     // Chunk Split it
452
-    $b = chunk_split(base64_encode($_signed),76,"\r\n\t");
452
+    $b = chunk_split(base64_encode($_signed), 76, "\r\n\t");
453 453
 
454 454
     // Append sign data into b tag in $_dk
455
-    $_dk.="b={$b}";
455
+    $_dk .= "b={$b}";
456 456
 
457 457
     // Return Wrapped and trimmed $_dk
458
-    return trim(wordwrap($_dk,76,"\r\n\t"));
458
+    return trim(wordwrap($_dk, 76, "\r\n\t"));
459 459
   }
460 460
 
461 461
   /**
@@ -480,20 +480,20 @@  discard block
 block discarded – undo
480 480
    * @author Ahmad Amarullah
481 481
    */
482 482
   public function sign(
483
-      $mail_data,                                 // Raw Mail Data
484
-      $suggested_h = "from:to:subject",           // Suggested Signed Header Fields
485
-      $create_dkim = true,                        // Create DKIM-Signature Header
486
-      $create_domainkey = true,                   // Create DomainKey-Signature Header
483
+      $mail_data, // Raw Mail Data
484
+      $suggested_h = "from:to:subject", // Suggested Signed Header Fields
485
+      $create_dkim = true, // Create DKIM-Signature Header
486
+      $create_domainkey = true, // Create DomainKey-Signature Header
487 487
       $out_sign_header_only = false               // Return Signature Header Only without original data
488
-    ){
488
+    ) {
489 489
 
490 490
     if (!$suggested_h) $suggested_h = "from:to:subject"; // Default Suggested Signed Header Fields
491 491
 
492 492
     // Remove all space and Lowercase Suggested Signed header fields then split it into array
493
-    $_h = explode(":",strtolower(preg_replace('/[\r\t\n ]++/','',$suggested_h)));
493
+    $_h = explode(":", strtolower(preg_replace('/[\r\t\n ]++/', '', $suggested_h)));
494 494
 
495 495
     // Split Raw Mail data into $raw_headers and $body
496
-    list($raw_headers, $body) = explode("\r\n\r\n",$mail_data,2);
496
+    list($raw_headers, $body) = explode("\r\n\r\n", $mail_data, 2);
497 497
 
498 498
     // Explode $raw_header into $header_list
499 499
     $header_list = preg_split("/\r\n(?![\t ])/", $raw_headers);
@@ -502,16 +502,16 @@  discard block
 block discarded – undo
502 502
     $headers = array();
503 503
 
504 504
     // Loop $header_list
505
-    foreach($header_list as $header){
505
+    foreach ($header_list as $header) {
506 506
       // Find Header Key for Array Key
507
-      list($key) = explode(':',$header, 2);
507
+      list($key) = explode(':', $header, 2);
508 508
 
509 509
       // Trim and Lowercase It
510 510
       $key = strtolower(trim($key));
511 511
 
512 512
       // If header with current key was exists
513 513
       // Change it into array
514
-      if (isset($headers[$key])){
514
+      if (isset($headers[$key])) {
515 515
         // If header not yet array set as Array
516 516
         if (!is_array($headers[$key]))
517 517
           $headers[$key] = array($headers[$key]);
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 
523 523
       // If header with current key not exists
524 524
       // Insert header as string
525
-      else{
525
+      else {
526 526
         $headers[$key] = $header;
527 527
       }
528 528
     }
@@ -530,16 +530,16 @@  discard block
 block discarded – undo
530 530
     // Now, lets find accepted Suggested Signed header fields
531 531
     // and reorder it to match headers position
532 532
 
533
-    $accepted_h = array();          // For Accepted Signed header fields
534
-    $accepted_headers = array();    // For Accepted Header
533
+    $accepted_h = array(); // For Accepted Signed header fields
534
+    $accepted_headers = array(); // For Accepted Header
535 535
 
536 536
     // Loop the Headers Array
537
-    foreach ($headers as $key=>$val){
537
+    foreach ($headers as $key=>$val) {
538 538
       // Check if $val wasn't array
539 539
       // We don't want to include multiple headers as Signed header fields
540
-      if (!is_array($val)){
540
+      if (!is_array($val)) {
541 541
         // Check if this header exists in Suggested Signed header fields
542
-        if (in_array($key,$_h)){
542
+        if (in_array($key, $_h)) {
543 543
           // If Exists, add it into accepted headers and accepted header fields
544 544
           $accepted_h[] = $key;
545 545
           $accepted_headers[] = $val;
@@ -550,31 +550,31 @@  discard block
 block discarded – undo
550 550
     // If it doesn't contain any $accepted_h
551 551
     // return false, because we don't have enough data
552 552
     // for signing email
553
-    if (count($accepted_h)==0)
553
+    if (count($accepted_h) == 0)
554 554
       return false;
555 555
 
556 556
     // Create $_hdata for Signed header fields
557 557
     // by imploding it with colon
558
-    $_hdata = implode(":",$accepted_h);
558
+    $_hdata = implode(":", $accepted_h);
559 559
 
560 560
     // New Headers Variable
561 561
     $_nh = array("x-domain-signer"=>"X-Domain-Signer: {$this->__app_name} {$this->__app_ver} <$this->__app_url>");
562 562
 
563 563
     // Create DKIM First
564 564
     if ($create_dkim)
565
-      $_nh['dkim-signature'] = $this->getDKIM($_hdata,$accepted_headers,$body);
565
+      $_nh['dkim-signature'] = $this->getDKIM($_hdata, $accepted_headers, $body);
566 566
 
567 567
     // Now Create Domain-Signature
568 568
     if ($create_domainkey)
569
-      $_nh['domainKey-signature'] = $this->getDomainKey($_hdata,$accepted_headers,$body);
569
+      $_nh['domainKey-signature'] = $this->getDomainKey($_hdata, $accepted_headers, $body);
570 570
 
571 571
     // Implode $_nh with \r\n
572
-    $to_be_appended_headers = implode("\r\n",$_nh);
572
+    $to_be_appended_headers = implode("\r\n", $_nh);
573 573
 
574 574
     // Return Immediately if
575 575
     // * $out_sign_header_only=true (as headers string)
576 576
     // * $out_sign_header_only=2    (as headers array)
577
-    if ($out_sign_header_only===2)
577
+    if ($out_sign_header_only === 2)
578 578
       return $_nh;
579 579
     elseif ($out_sign_header_only)
580 580
       return "{$to_be_appended_headers}\r\n";
Please login to merge, or discard this patch.
Braces   +78 added lines, -34 removed lines patch added patch discarded remove patch
@@ -28,7 +28,8 @@  discard block
 block discarded – undo
28 28
  * @package mailDomainSigner
29 29
  * @author Ahmad Amarullah
30 30
  */
31
-class mailDomainSigner{
31
+class mailDomainSigner
32
+{
32 33
 
33 34
   ///////////////////////
34 35
   // PRIVATE VARIABLES //
@@ -51,7 +52,8 @@  discard block
 block discarded – undo
51 52
    * @param string $s The selector used to form the query for the public key
52 53
    * @author Ahmad Amarullah
53 54
    */
54
-  public function __construct($private_key,$d,$s){
55
+  public function __construct($private_key,$d,$s)
56
+  {
55 57
     // Get a private key
56 58
     $this->pkid = openssl_pkey_get_private($private_key);
57 59
 
@@ -75,12 +77,14 @@  discard block
 block discarded – undo
75 77
    * @access public
76 78
    * @author Ahmad Amarullah
77 79
    */
78
-  public function nofws($raw_headers,$raw_body){
80
+  public function nofws($raw_headers,$raw_body)
81
+  {
79 82
     // nofws-ed headers
80 83
     $headers = array();
81 84
 
82 85
     // Loop the raw_headers
83
-    foreach ($raw_headers as $header){
86
+    foreach ($raw_headers as $header)
87
+    {
84 88
       // Replace all Folding Whitespace
85 89
       $headers[] = preg_replace('/[\r\t\n ]++/','',$header);
86 90
     }
@@ -122,7 +126,8 @@  discard block
 block discarded – undo
122 126
    * @access public
123 127
    * @author Eric Vyncke
124 128
    */
125
-  public function headRelaxCanon($s) {
129
+  public function headRelaxCanon($s)
130
+  {
126 131
     // Replace CR,LF and spaces into single SP
127 132
     $s=preg_replace("/\r\n\s+/"," ",$s) ;
128 133
 
@@ -130,7 +135,8 @@  discard block
 block discarded – undo
130 135
     $lines=explode("\r\n",$s) ;
131 136
 
132 137
     // Loop the lines
133
-    foreach ($lines as $key=>$line) {
138
+    foreach ($lines as $key=>$line)
139
+    {
134 140
       // Split the key and value
135 141
       list($heading,$value)=explode(":",$line,2) ;
136 142
 
@@ -167,13 +173,15 @@  discard block
 block discarded – undo
167 173
    * @access public
168 174
    * @author Ralf Becker
169 175
    */
170
-  public function headIScheduleRelaxCanon($s) {
176
+  public function headIScheduleRelaxCanon($s)
177
+  {
171 178
     // Replace CR,LF and spaces into single SP
172 179
     $s=preg_replace("/\r\n\s+/"," ",$s) ;
173 180
 
174 181
     // Loop exploded header lines
175 182
     $lines=array();
176
-    foreach (explode("\r\n",$s) as $line) {
183
+    foreach (explode("\r\n",$s) as $line)
184
+    {
177 185
       // Split the key and value
178 186
       list($heading,$value)=explode(":",$line,2) ;
179 187
 
@@ -190,9 +198,12 @@  discard block
 block discarded – undo
190 198
       $value = preg_replace("/,\s+/",",",$value);
191 199
 
192 200
       // for multiple headers, add them comma-separated to existing headers
193
-      if (isset($lines[$heading])) {
201
+      if (isset($lines[$heading]))
202
+      {
194 203
       	$lines[$heading] .= ','.$value;
195
-      } else {
204
+      }
205
+      else
206
+      {
196 207
       	$lines[$heading] = $heading.':'.$value;
197 208
       }
198 209
     }
@@ -215,7 +226,8 @@  discard block
 block discarded – undo
215 226
    * @return string Simple Header Canonicalizated data
216 227
    * @access public
217 228
    */
218
-  public function headSimpleCanon($s) {
229
+  public function headSimpleCanon($s)
230
+  {
219 231
   	return $s;
220 232
   }
221 233
 
@@ -230,9 +242,11 @@  discard block
 block discarded – undo
230 242
    * @access public
231 243
    * @author Ahmad Amarullah
232 244
    */
233
-  public function bodyRelaxCanon($body) {
245
+  public function bodyRelaxCanon($body)
246
+  {
234 247
     // Return CRLF for empty body
235
-    if ($body == ''){
248
+    if ($body == '')
249
+    {
236 250
       return "\r\n";
237 251
     }
238 252
 
@@ -249,7 +263,8 @@  discard block
 block discarded – undo
249 263
     $canon_body = '';
250 264
 
251 265
     // Split the body into lines
252
-    foreach(explode("\r\n",$body) as $line){
266
+    foreach(explode("\r\n",$body) as $line)
267
+    {
253 268
       // Reduces all sequences of White Space within a line
254 269
       // to a single SP character
255 270
       $canon_body.= rtrim(preg_replace('/[\t\n ]++/',' ',$line))."\r\n";
@@ -269,9 +284,11 @@  discard block
 block discarded – undo
269 284
    * @return string Simple Body Canonicalizated data
270 285
    * @access public
271 286
    */
272
-  public function bodySimpleCanon($body) {
287
+  public function bodySimpleCanon($body)
288
+  {
273 289
   	// remove all empty lines (CRLF pairs) at the end of the body
274
-  	while (substr($body, -2) === "\r\n") {
290
+  	while (substr($body, -2) === "\r\n")
291
+  	{
275 292
   		$body = substr($body, 0, -2);
276 293
   	}
277 294
 
@@ -316,7 +333,8 @@  discard block
 block discarded – undo
316 333
    * @access public
317 334
    * @author Ahmad Amarullah
318 335
    */
319
-  public function getDKIM($h,$_h,$body,$_c='relaxed/relaxed',$_a='rsa-sha1',$_dkim=null) {
336
+  public function getDKIM($h,$_h,$body,$_c='relaxed/relaxed',$_a='rsa-sha1',$_dkim=null)
337
+  {
320 338
 
321 339
     // Relax Canonicalization for Body
322 340
  	list($header_canon,$body_canon) = explode('/',$_c);
@@ -346,7 +364,8 @@  discard block
 block discarded – undo
346 364
     $_bh = base64_encode(hash($hash_algo,$_b,true));
347 365
 
348 366
     // Creating DKIM-Signature
349
-    if (is_null($_dkim)) {
367
+    if (is_null($_dkim))
368
+    {
350 369
 	    $_dkim = "DKIM-Signature: ".
351 370
 	                "v=1; ".          // DKIM Version
352 371
 	                "a=\$a; ".        // The algorithm used to generate the signature "rsa-sha1"
@@ -427,11 +446,14 @@  discard block
 block discarded – undo
427 446
    * @access public
428 447
    * @author Ahmad Amarullah
429 448
    */
430
-  public function getDomainKey($h,$_h,$body){
449
+  public function getDomainKey($h,$_h,$body)
450
+  {
431 451
     // If $h = empty, dont add h tag into DomainKey-Signature
432 452
     $hval = '';
433 453
     if ($h)
434
-      $hval= "h={$h}; ";
454
+    {
455
+          $hval= "h={$h}; ";
456
+    }
435 457
 
436 458
     // Creating DomainKey-Signature
437 459
     $_dk = "DomainKey-Signature: ".
@@ -485,9 +507,13 @@  discard block
 block discarded – undo
485 507
       $create_dkim = true,                        // Create DKIM-Signature Header
486 508
       $create_domainkey = true,                   // Create DomainKey-Signature Header
487 509
       $out_sign_header_only = false               // Return Signature Header Only without original data
488
-    ){
510
+    ) {
489 511
 
490
-    if (!$suggested_h) $suggested_h = "from:to:subject"; // Default Suggested Signed Header Fields
512
+    if (!$suggested_h)
513
+    {
514
+    	$suggested_h = "from:to:subject";
515
+    }
516
+    // Default Suggested Signed Header Fields
491 517
 
492 518
     // Remove all space and Lowercase Suggested Signed header fields then split it into array
493 519
     $_h = explode(":",strtolower(preg_replace('/[\r\t\n ]++/','',$suggested_h)));
@@ -502,7 +528,8 @@  discard block
 block discarded – undo
502 528
     $headers = array();
503 529
 
504 530
     // Loop $header_list
505
-    foreach($header_list as $header){
531
+    foreach($header_list as $header)
532
+    {
506 533
       // Find Header Key for Array Key
507 534
       list($key) = explode(':',$header, 2);
508 535
 
@@ -511,10 +538,13 @@  discard block
 block discarded – undo
511 538
 
512 539
       // If header with current key was exists
513 540
       // Change it into array
514
-      if (isset($headers[$key])){
541
+      if (isset($headers[$key]))
542
+      {
515 543
         // If header not yet array set as Array
516 544
         if (!is_array($headers[$key]))
517
-          $headers[$key] = array($headers[$key]);
545
+        {
546
+                  $headers[$key] = array($headers[$key]);
547
+        }
518 548
 
519 549
         // Add Current Header as next element
520 550
         $headers[$key][] = $header;
@@ -522,7 +552,8 @@  discard block
 block discarded – undo
522 552
 
523 553
       // If header with current key not exists
524 554
       // Insert header as string
525
-      else{
555
+      else
556
+      {
526 557
         $headers[$key] = $header;
527 558
       }
528 559
     }
@@ -534,12 +565,15 @@  discard block
 block discarded – undo
534 565
     $accepted_headers = array();    // For Accepted Header
535 566
 
536 567
     // Loop the Headers Array
537
-    foreach ($headers as $key=>$val){
568
+    foreach ($headers as $key=>$val)
569
+    {
538 570
       // Check if $val wasn't array
539 571
       // We don't want to include multiple headers as Signed header fields
540
-      if (!is_array($val)){
572
+      if (!is_array($val))
573
+      {
541 574
         // Check if this header exists in Suggested Signed header fields
542
-        if (in_array($key,$_h)){
575
+        if (in_array($key,$_h))
576
+        {
543 577
           // If Exists, add it into accepted headers and accepted header fields
544 578
           $accepted_h[] = $key;
545 579
           $accepted_headers[] = $val;
@@ -551,7 +585,9 @@  discard block
 block discarded – undo
551 585
     // return false, because we don't have enough data
552 586
     // for signing email
553 587
     if (count($accepted_h)==0)
554
-      return false;
588
+    {
589
+          return false;
590
+    }
555 591
 
556 592
     // Create $_hdata for Signed header fields
557 593
     // by imploding it with colon
@@ -562,11 +598,15 @@  discard block
 block discarded – undo
562 598
 
563 599
     // Create DKIM First
564 600
     if ($create_dkim)
565
-      $_nh['dkim-signature'] = $this->getDKIM($_hdata,$accepted_headers,$body);
601
+    {
602
+          $_nh['dkim-signature'] = $this->getDKIM($_hdata,$accepted_headers,$body);
603
+    }
566 604
 
567 605
     // Now Create Domain-Signature
568 606
     if ($create_domainkey)
569
-      $_nh['domainKey-signature'] = $this->getDomainKey($_hdata,$accepted_headers,$body);
607
+    {
608
+          $_nh['domainKey-signature'] = $this->getDomainKey($_hdata,$accepted_headers,$body);
609
+    }
570 610
 
571 611
     // Implode $_nh with \r\n
572 612
     $to_be_appended_headers = implode("\r\n",$_nh);
@@ -575,9 +615,13 @@  discard block
 block discarded – undo
575 615
     // * $out_sign_header_only=true (as headers string)
576 616
     // * $out_sign_header_only=2    (as headers array)
577 617
     if ($out_sign_header_only===2)
578
-      return $_nh;
618
+    {
619
+          return $_nh;
620
+    }
579 621
     elseif ($out_sign_header_only)
580
-      return "{$to_be_appended_headers}\r\n";
622
+    {
623
+          return "{$to_be_appended_headers}\r\n";
624
+    }
581 625
 
582 626
     // Return signed headers with original data
583 627
     return "{$to_be_appended_headers}\r\n{$mail_data}";
Please login to merge, or discard this patch.
phpgwapi/inc/class.network.inc.php 2 patches
Doc Comments   +11 added lines patch added patch discarded remove patch
@@ -36,6 +36,9 @@  discard block
 block discarded – undo
36 36
 			$this->set_addcrlf($addcrlf);
37 37
 		}
38 38
 
39
+		/**
40
+		 * @param boolean $value
41
+		 */
39 42
 		function set_addcrlf($value)
40 43
 		{
41 44
 			$this->addcrlf = $value;
@@ -50,6 +53,11 @@  discard block
 block discarded – undo
50 53
 			return $str;
51 54
 		}
52 55
 
56
+		/**
57
+		 * @param string $code
58
+		 * @param string $msg
59
+		 * @param string $desc
60
+		 */
53 61
 		function set_error($code,$msg,$desc)
54 62
 		{
55 63
 			$this->error = array('code','msg','desc');
@@ -61,6 +69,9 @@  discard block
 block discarded – undo
61 69
 			return 0;
62 70
 		}
63 71
 
72
+		/**
73
+		 * @param integer $port
74
+		 */
64 75
 		function open_port($server,$port,$timeout=15)
65 76
 		{
66 77
 			switch($port)
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 		var $error;
31 31
 		var $errorset = 0;
32 32
 
33
-		function network($addcrlf=true)
33
+		function network($addcrlf = true)
34 34
 		{
35 35
 			$this->errorset = 0;
36 36
 			$this->set_addcrlf($addcrlf);
@@ -43,16 +43,16 @@  discard block
 block discarded – undo
43 43
 
44 44
 		function add_crlf($str)
45 45
 		{
46
-			if($this->addcrlf)
46
+			if ($this->addcrlf)
47 47
 			{
48 48
 				$str .= "\r\n";
49 49
 			}
50 50
 			return $str;
51 51
 		}
52 52
 
53
-		function set_error($code,$msg,$desc)
53
+		function set_error($code, $msg, $desc)
54 54
 		{
55
-			$this->error = array('code','msg','desc');
55
+			$this->error = array('code', 'msg', 'desc');
56 56
 			$this->error['code'] = $code;
57 57
 			$this->error['msg'] = $msg;
58 58
 			$this->error['desc'] = $desc;
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
 			return 0;
62 62
 		}
63 63
 
64
-		function open_port($server,$port,$timeout=15)
64
+		function open_port($server, $port, $timeout = 15)
65 65
 		{
66
-			switch($port)
66
+			switch ($port)
67 67
 			{
68 68
 				case 80:
69 69
 				case 443:
70
-					if((isset($GLOBALS['egw_info']['server']['httpproxy_server']) && $GLOBALS['egw_info']['server']['httpproxy_server']) &&
70
+					if ((isset($GLOBALS['egw_info']['server']['httpproxy_server']) && $GLOBALS['egw_info']['server']['httpproxy_server']) &&
71 71
 						(isset($GLOBALS['egw_info']['server']['httpproxy_port']) && $GLOBALS['egw_info']['server']['httpproxy_port']))
72 72
 					{
73 73
 						$server = $GLOBALS['egw_info']['server']['httpproxy_server'];
@@ -75,21 +75,21 @@  discard block
 block discarded – undo
75 75
 					}
76 76
 					break;
77 77
 			}
78
-			if(version_compare(phpversion(),'4.3.0') >= 0)
78
+			if (version_compare(phpversion(), '4.3.0') >= 0)
79 79
 			{
80
-				$this->socket = @fsockopen($server,$port,$errcode,$errmsg,$timeout);
81
-				if($this->socket)
80
+				$this->socket = @fsockopen($server, $port, $errcode, $errmsg, $timeout);
81
+				if ($this->socket)
82 82
 				{
83
-					stream_set_timeout($this->socket,$timeout,0);
83
+					stream_set_timeout($this->socket, $timeout, 0);
84 84
 				}
85 85
 			}
86 86
 			else
87 87
 			{
88
-				$this->socket = @fsockopen($server,$port,$errcode,$errmsg);
88
+				$this->socket = @fsockopen($server, $port, $errcode, $errmsg);
89 89
 			}
90
-			if(!$this->socket)
90
+			if (!$this->socket)
91 91
 			{
92
-				return $this->set_error('Error',$errcode.':'.$errmsg,'Connection to '.$server.':'.$port.' failed - could not open socket.');
92
+				return $this->set_error('Error', $errcode.':'.$errmsg, 'Connection to '.$server.':'.$port.' failed - could not open socket.');
93 93
 			}
94 94
 			else
95 95
 			{
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
 
115 115
 		function write_port($str)
116 116
 		{
117
-			$ok = fputs($this->socket,$this->add_crlf($str));
118
-			if(!$ok)
117
+			$ok = fputs($this->socket, $this->add_crlf($str));
118
+			if (!$ok)
119 119
 			{
120
-				return $this->set_error('Error','Connection Lost','lost connection to server');
120
+				return $this->set_error('Error', 'Connection Lost', 'lost connection to server');
121 121
 			}
122 122
 			else
123 123
 			{
@@ -125,19 +125,19 @@  discard block
 block discarded – undo
125 125
 			}
126 126
 		}
127 127
 
128
-		function bs_write_port($str,$bytes=0)
128
+		function bs_write_port($str, $bytes = 0)
129 129
 		{
130
-			if($bytes)
130
+			if ($bytes)
131 131
 			{
132
-				$ok = fwrite($this->socket,$this->add_crlf($str),$bytes);
132
+				$ok = fwrite($this->socket, $this->add_crlf($str), $bytes);
133 133
 			}
134 134
 			else
135 135
 			{
136
-				$ok = fwrite($this->socket,$this->add_crlf($str));
136
+				$ok = fwrite($this->socket, $this->add_crlf($str));
137 137
 			}
138
-			if(!$ok)
138
+			if (!$ok)
139 139
 			{
140
-				return $this->set_error('Error','Connection Lost','lost connection to server');
140
+				return $this->set_error('Error', 'Connection Lost', 'lost connection to server');
141 141
 			}
142 142
 			else
143 143
 			{
@@ -145,18 +145,18 @@  discard block
 block discarded – undo
145 145
 			}
146 146
 		}
147 147
 
148
-		function msg2socket($str,$expected_response,&$response)
148
+		function msg2socket($str, $expected_response, &$response)
149 149
 		{
150
-			if(!$this->socket)
150
+			if (!$this->socket)
151 151
 			{
152
-				return $this->set_error('521','socket does not exist',
152
+				return $this->set_error('521', 'socket does not exist',
153 153
 					'The required socket does not exist.  The settings for your mail server may be wrong.');
154 154
 			}
155
-			if(!$this->write_port($str))
155
+			if (!$this->write_port($str))
156 156
 			{
157
-				if(substr($expected_response,1,1) == '+')
157
+				if (substr($expected_response, 1, 1) == '+')
158 158
 				{
159
-					return $this->set_error('420','lost connection','Lost connection to pop server.');
159
+					return $this->set_error('420', 'lost connection', 'Lost connection to pop server.');
160 160
 				}
161 161
 				else
162 162
 				{
@@ -164,16 +164,16 @@  discard block
 block discarded – undo
164 164
 				}
165 165
 			}
166 166
 			$response = $this->read_port();
167
-			if(!ereg(strtoupper($expected_response),strtoupper($response)))
167
+			if (!ereg(strtoupper($expected_response), strtoupper($response)))
168 168
 			{
169
-				if(substr($expected_response,1,1) == '+')
169
+				if (substr($expected_response, 1, 1) == '+')
170 170
 				{
171
-					return $this->set_error('550','','');
171
+					return $this->set_error('550', '', '');
172 172
 				}
173
-				$pos = strpos(' ',$response);
174
-				return $this->set_error(substr($response,0,$pos),
173
+				$pos = strpos(' ', $response);
174
+				return $this->set_error(substr($response, 0, $pos),
175 175
 					'invalid response('.$expected_response.')',
176
-					substr($response,($pos + 1),(strlen($response)-$pos)));
176
+					substr($response, ($pos + 1), (strlen($response) - $pos)));
177 177
 			}
178 178
 			else
179 179
 			{
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 		}
183 183
 
184 184
 		// return contents of a web url as an array (or string) or false if timeout
185
-		function gethttpsocketfile($file,$user='',$passwd='',$string=False)
185
+		function gethttpsocketfile($file, $user = '', $passwd = '', $string = False)
186 186
 		{
187
-			$server = str_replace('http://','',$file);
188
-			$file = @strstr($server,'/');
189
-			$server = str_replace($file,'',$server);
187
+			$server = str_replace('http://', '', $file);
188
+			$file = @strstr($server, '/');
189
+			$server = str_replace($file, '', $server);
190 190
 
191 191
 			//allows for access to http-auth pages - added by Dave Hall <[email protected]>
192
-			if(!((empty($user))&&(empty($passwd))))
192
+			if (!((empty($user)) && (empty($passwd))))
193 193
 			{
194 194
 				$auth = 'Authorization: Basic '.base64_encode("$user:$passwd")."\r\n";
195 195
 			}
@@ -198,25 +198,25 @@  discard block
 block discarded – undo
198 198
 				$auth = '';
199 199
 			}
200 200
 
201
-			if($GLOBALS['egw_info']['server']['httpproxy_server'])
201
+			if ($GLOBALS['egw_info']['server']['httpproxy_server'])
202 202
 			{
203 203
 				$proxyAuth = '';
204
-				if(!empty($GLOBALS['egw_info']['server']['httpproxy_server_username']))
204
+				if (!empty($GLOBALS['egw_info']['server']['httpproxy_server_username']))
205 205
 				{
206 206
 					$proxyUsername = $GLOBALS['egw_info']['server']['httpproxy_server_username'];
207 207
 					$proxyPassword = $GLOBALS['egw_info']['server']['httpproxy_server_password'];
208 208
 					$proxyAuth = 'Proxy-Authorization: Basic '.base64_encode("$proxyUsername:$proxyPassword")."\r\n";
209 209
 				}
210
-				if($this->open_port($server,80, 15))
210
+				if ($this->open_port($server, 80, 15))
211 211
 				{
212
-					if(!$this->write_port('GET http://' . $server . $file . ' HTTP/1.0'."\r\n".$proxyAuth.$auth."\r\n\r\n"))
212
+					if (!$this->write_port('GET http://'.$server.$file.' HTTP/1.0'."\r\n".$proxyAuth.$auth."\r\n\r\n"))
213 213
 					{
214 214
 						return False;
215 215
 					}
216 216
 					$i = 0;
217
-					while($line = $this->read_port())
217
+					while ($line = $this->read_port())
218 218
 					{
219
-						if(feof($this->socket))
219
+						if (feof($this->socket))
220 220
 						{
221 221
 							break;
222 222
 						}
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
 						$i++;
225 225
 					}
226 226
 					$this->close_port();
227
-					if($string)
227
+					if ($string)
228 228
 					{
229
-						return implode("\n",$lines);
229
+						return implode("\n", $lines);
230 230
 					}
231 231
 					return $lines;
232 232
 				}
@@ -237,21 +237,21 @@  discard block
 block discarded – undo
237 237
 			}
238 238
 			else
239 239
 			{
240
-				if($this->open_port($server, 80, 30))
240
+				if ($this->open_port($server, 80, 30))
241 241
 				{
242 242
 					$lines = array();
243
-					if(!$this->write_port('GET '.$file.' HTTP/1.0'."\r\n".'Host: '.$server."\r\nAccept: */*".($auth?"\r\n".$auth:'')."\r\n\r\n"))
243
+					if (!$this->write_port('GET '.$file.' HTTP/1.0'."\r\n".'Host: '.$server."\r\nAccept: */*".($auth ? "\r\n".$auth : '')."\r\n\r\n"))
244 244
 					{
245 245
 						return 0;
246 246
 					}
247
-					while($line = $this->read_port())
247
+					while ($line = $this->read_port())
248 248
 					{
249 249
 						$lines[] = $line;
250 250
 					}
251 251
 					$this->close_port();
252
-					if($string)
252
+					if ($string)
253 253
 					{
254
-						return implode("\n",$lines);
254
+						return implode("\n", $lines);
255 255
 					}
256 256
 					return $lines;
257 257
 				}
Please login to merge, or discard this patch.
phpgwapi/inc/class.nextmatchs.inc.php 3 patches
Doc Comments   +36 added lines patch added patch discarded remove patch
@@ -89,6 +89,11 @@  discard block
 block discarded – undo
89 89
 		@param $img_src ?
90 90
 		@param $label ?
91 91
 		*/
92
+
93
+		/**
94
+		 * @param string $align
95
+		 * @param string $img
96
+		 */
92 97
 		function set_icon($align,$img,$label)
93 98
 		{
94 99
 			$var = array(
@@ -134,6 +139,11 @@  discard block
 block discarded – undo
134 139
 		@param $link ?
135 140
 		@param $extravars ?
136 141
 		*/
142
+
143
+		/**
144
+		 * @param string $align
145
+		 * @param string $img
146
+		 */
137 147
 		function set_link($align,$img,$link,$alt,$extravars)
138 148
 		{
139 149
 			$var = Array(
@@ -244,6 +254,10 @@  discard block
 block discarded – undo
244 254
 		@param $total ?
245 255
 		@param $extradate ?
246 256
 		*/
257
+
258
+		/**
259
+		 * @param integer $start
260
+		 */
247 261
 		function left($scriptname,$start,$total,$extradata = '')
248 262
 		{
249 263
 			$extravars = Array(
@@ -290,6 +304,10 @@  discard block
 block discarded – undo
290 304
 		@param $total ?
291 305
 		@param $extradate ?
292 306
 		*/
307
+
308
+		/**
309
+		 * @param integer $start
310
+		 */
293 311
 		function right($scriptname,$start,$total,$extradata = '')
294 312
 		{
295 313
 			$extravars = Array(
@@ -470,6 +488,10 @@  discard block
 block discarded – undo
470 488
 		@abstract ?
471 489
 		@param $filter_obj
472 490
 		*/
491
+
492
+		/**
493
+		 * @param integer $filter_obj
494
+		 */
473 495
 		function filter($filter_obj,$yours=0)
474 496
 		{
475 497
 			if (is_array($yours))
@@ -654,6 +676,11 @@  discard block
 block discarded – undo
654 676
 		@param $text ?
655 677
 		@param $extra default ''
656 678
 		*/
679
+
680
+		/**
681
+		 * @param string $var
682
+		 * @param string $program
683
+		 */
657 684
 		function show_sort_order($sort,$var,$order,$program,$text,$extra='',$build_a_href=True)
658 685
 		{
659 686
 			if ($order == $var)
@@ -848,6 +875,11 @@  discard block
 block discarded – undo
848 875
 		@param $link ?
849 876
 		@param $extravars ?
850 877
 		*/
878
+
879
+		/**
880
+		 * @param string $align
881
+		 * @param string $img
882
+		 */
851 883
 		function set_link_imap($align,$img,$alt_text,$out_vars)
852 884
 		{
853 885
 			$img_full = $GLOBALS['egw']->common->image('phpgwapi',$img);
@@ -855,6 +887,10 @@  discard block
 block discarded – undo
855 887
 			return '<a href="'.$out_vars['common_uri'].'&start='.$out_vars['start'].'">'.$image_part.'</a>';
856 888
 		}
857 889
 
890
+		/**
891
+		 * @param string $align
892
+		 * @param string $img
893
+		 */
858 894
 		function set_icon_imap($align,$img,$alt_text)
859 895
 		{
860 896
 			$img_full = $GLOBALS['egw']->common->image('phpgwapi',$img);
Please login to merge, or discard this patch.
Spacing   +164 added lines, -170 removed lines patch added patch discarded remove patch
@@ -36,26 +36,26 @@  discard block
 block discarded – undo
36 36
 		var $template;
37 37
 		var $extra_filters = array();
38 38
 
39
-		function nextmatchs($website=False)
39
+		function nextmatchs($website = False)
40 40
 		{
41
-			if(!$website)
41
+			if (!$website)
42 42
 			{
43
-				$this->template = createobject('phpgwapi.Template',EGW_TEMPLATE_DIR);
43
+				$this->template = createobject('phpgwapi.Template', EGW_TEMPLATE_DIR);
44 44
 				$this->template->set_file(array(
45 45
 					'_nextmatchs' => 'nextmatchs.tpl'
46 46
 				));
47
-				$this->template->set_block('_nextmatchs','nextmatchs');
48
-				$this->template->set_block('_nextmatchs','filter');
49
-				$this->template->set_block('_nextmatchs','form');
50
-				$this->template->set_block('_nextmatchs','icon');
51
-				$this->template->set_block('_nextmatchs','link');
52
-				$this->template->set_block('_nextmatchs','search');
53
-				$this->template->set_block('_nextmatchs','cats');
54
-				$this->template->set_block('_nextmatchs','search_filter');
55
-				$this->template->set_block('_nextmatchs','cats_search_filter');
56
-			}
57
-
58
-			if(isset($GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) &&
47
+				$this->template->set_block('_nextmatchs', 'nextmatchs');
48
+				$this->template->set_block('_nextmatchs', 'filter');
49
+				$this->template->set_block('_nextmatchs', 'form');
50
+				$this->template->set_block('_nextmatchs', 'icon');
51
+				$this->template->set_block('_nextmatchs', 'link');
52
+				$this->template->set_block('_nextmatchs', 'search');
53
+				$this->template->set_block('_nextmatchs', 'cats');
54
+				$this->template->set_block('_nextmatchs', 'search_filter');
55
+				$this->template->set_block('_nextmatchs', 'cats_search_filter');
56
+			}
57
+
58
+			if (isset($GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']) &&
59 59
 				(int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] > 0)
60 60
 			{
61 61
 				$this->maxmatches = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
@@ -65,13 +65,13 @@  discard block
 block discarded – undo
65 65
 				$this->maxmatches = 15;
66 66
 			}
67 67
 
68
-			$this->_start = (int) get_var('start',array('GLOBAL','POST','GET'));
68
+			$this->_start = (int)get_var('start', array('GLOBAL', 'POST', 'GET'));
69 69
 
70
-			foreach(array('menuaction','filter','qfield','order','sort') as $name)
70
+			foreach (array('menuaction', 'filter', 'qfield', 'order', 'sort') as $name)
71 71
 			{
72 72
 				$var = '_'.$name;
73
-				$this->$var = get_var($name,array('GLOBAL','POST','GET'));
74
-				if (!preg_match('/^[a-z0-9_. -]*$/i',$this->$var))
73
+				$this->$var = get_var($name, array('GLOBAL', 'POST', 'GET'));
74
+				if (!preg_match('/^[a-z0-9_. -]*$/i', $this->$var))
75 75
 				{
76 76
 					$this->$var = '';
77 77
 				}
@@ -89,41 +89,41 @@  discard block
 block discarded – undo
89 89
 		@param $img_src ?
90 90
 		@param $label ?
91 91
 		*/
92
-		function set_icon($align,$img,$label)
92
+		function set_icon($align, $img, $label)
93 93
 		{
94 94
 			$var = array(
95 95
 				'align'  => $align,
96
-				'img'    => $GLOBALS['egw']->common->image('phpgwapi',$img),
96
+				'img'    => $GLOBALS['egw']->common->image('phpgwapi', $img),
97 97
 				'label'  => lang($label),
98 98
 				'border' => 0
99 99
 			);
100 100
 			$this->template->set_var($var);
101
-			return $this->template->fp('out','link');
101
+			return $this->template->fp('out', 'link');
102 102
 		}
103 103
 
104 104
 		/*!
105 105
 		@function page
106 106
 		@abstract ?
107 107
 		*/
108
-		function page($extravars='')
108
+		function page($extravars = '')
109 109
 		{
110
-			if($extravars && is_string($extravars) && substr($extravars,0,1)!='&')
110
+			if ($extravars && is_string($extravars) && substr($extravars, 0, 1) != '&')
111 111
 			{
112 112
 				$extras = '&'.$extravars;
113 113
 			}
114
-			elseif($extravars && is_array($extravars))
114
+			elseif ($extravars && is_array($extravars))
115 115
 			{
116
-				foreach($extravars as $var => $value)
116
+				foreach ($extravars as $var => $value)
117 117
 				{
118
-					if($var != 'menuaction')
118
+					if ($var != 'menuaction')
119 119
 					{
120 120
 						$t_extras[] = $var.'='.$value;
121 121
 					}
122 122
 				}
123
-				$extras = implode($t_extras,'&');
123
+				$extras = implode($t_extras, '&');
124 124
 			}
125 125
 
126
-			return $GLOBALS['egw']->link('/index.php','menuaction='.$this->_menuaction.$extras);
126
+			return $GLOBALS['egw']->link('/index.php', 'menuaction='.$this->_menuaction.$extras);
127 127
 		}
128 128
 
129 129
 		/*!
@@ -134,20 +134,20 @@  discard block
 block discarded – undo
134 134
 		@param $link ?
135 135
 		@param $extravars ?
136 136
 		*/
137
-		function set_link($align,$img,$link,$alt,$extravars)
137
+		function set_link($align, $img, $link, $alt, $extravars)
138 138
 		{
139 139
 			$var = Array(
140 140
 				'align'     => $align,
141
-				'action'    => ($this->_menuaction?$this->page():$GLOBALS['egw']->link($link)),
141
+				'action'    => ($this->_menuaction ? $this->page() : $GLOBALS['egw']->link($link)),
142 142
 				'form_name' => $img,
143 143
 				'hidden'    => $GLOBALS['egw']->html->input_hidden($extravars),
144
-				'img'       => $GLOBALS['egw']->common->image('phpgwapi',$img),
144
+				'img'       => $GLOBALS['egw']->common->image('phpgwapi', $img),
145 145
 				'label'     => $alt,
146 146
 				'border'    => 0,
147 147
 				'start'     => $extravars['start']
148 148
 			);
149 149
 			$this->template->set_var($var);
150
-			return $this->template->fp('out','form');
150
+			return $this->template->fp('out', 'form');
151 151
 		}
152 152
 
153 153
 		/*!
@@ -163,21 +163,21 @@  discard block
 block discarded – undo
163 163
 		@param $filter_obj ?
164 164
 		@param $showsearch ?
165 165
 		*/
166
-		function show_tpl($sn,$localstart,$total,$extra, $twidth, $bgtheme,$search_obj=0,$filter_obj=1,$showsearch=1,$yours=0,$cat_id=0,$cat_field='fcat_id')
166
+		function show_tpl($sn, $localstart, $total, $extra, $twidth, $bgtheme, $search_obj = 0, $filter_obj = 1, $showsearch = 1, $yours = 0, $cat_id = 0, $cat_field = 'fcat_id')
167 167
 		{
168 168
 			if (!is_object($GLOBALS['egw']->categories))
169 169
 			{
170 170
 				$GLOBALS['egw']->categories = CreateObject('phpgwapi.categories');
171 171
 			}
172
-			$extravars = $this->split_extras($extravars,$extra);
172
+			$extravars = $this->split_extras($extravars, $extra);
173 173
 
174 174
 			$var = array(
175
-				'form_action'   => ($this->_menuaction?$this->page($extra):$GLOBALS['egw']->link($sn, $extra)),
175
+				'form_action'   => ($this->_menuaction ? $this->page($extra) : $GLOBALS['egw']->link($sn, $extra)),
176 176
 				'lang_category' => lang('Category'),
177 177
 				'lang_all'      => lang('All'),
178 178
 				'lang_select'   => lang('Select'),
179 179
 				'cat_field'     => $cat_field,
180
-				'categories'    => $GLOBALS['egw']->categories->formatted_list('select','all',$cat_id,'True'),
180
+				'categories'    => $GLOBALS['egw']->categories->formatted_list('select', 'all', $cat_id, 'True'),
181 181
 				'hidden'       => $GLOBALS['egw']->html->input_hidden(array(
182 182
 					'filter' => $this->_filter,
183 183
 					'qfield' => $this->_qfield,
@@ -189,28 +189,28 @@  discard block
 block discarded – undo
189 189
 				'query_value'   => $GLOBALS['egw']->html->htmlspecialchars($GLOBALS['query']),
190 190
 				'table_width'   => $twidth,
191 191
 				'th_bg'         => $GLOBALS['egw_info']['theme']['th_bg'],
192
-				'left'          => $this->left($sn,(int)$localstart,$total,$extra),
193
-				'search'        => ($showsearch?$this->search($search_obj):''),
194
-				'filter'        => ($filter_obj?$this->filter($filter_obj,$yours):''),
195
-				'right'         => $this->right($sn,(int)$localstart,$total,$extra)
192
+				'left'          => $this->left($sn, (int)$localstart, $total, $extra),
193
+				'search'        => ($showsearch ? $this->search($search_obj) : ''),
194
+				'filter'        => ($filter_obj ? $this->filter($filter_obj, $yours) : ''),
195
+				'right'         => $this->right($sn, (int)$localstart, $total, $extra)
196 196
 			);
197 197
 			$this->template->set_var($var);
198
-			$this->template->parse('cats','cats');
199
-			$this->template->parse('cats_search_filter_data','cats_search_filter');
200
-			return $this->template->fp('out','nextmatchs');
198
+			$this->template->parse('cats', 'cats');
199
+			$this->template->parse('cats_search_filter_data', 'cats_search_filter');
200
+			return $this->template->fp('out', 'nextmatchs');
201 201
 		}
202 202
 
203
-		function split_extras($extravars,$extradata)
203
+		function split_extras($extravars, $extradata)
204 204
 		{
205
-			if($extradata)
205
+			if ($extradata)
206 206
 			{
207
-				if(!is_array($extradata))
207
+				if (!is_array($extradata))
208 208
 				{
209
-					parse_str($extradata,$extradata);
209
+					parse_str($extradata, $extradata);
210 210
 				}
211
-				foreach($extradata as $var => $value)
211
+				foreach ($extradata as $var => $value)
212 212
 				{
213
-					if($var != 'menuaction')
213
+					if ($var != 'menuaction')
214 214
 					{
215 215
 						$extravars[$var] = $value;
216 216
 					}
@@ -225,13 +225,13 @@  discard block
 block discarded – undo
225 225
 
226 226
 		function extras_to_string($extra)
227 227
 		{
228
-			if(is_array($extra))
228
+			if (is_array($extra))
229 229
 			{
230
-				foreach($extra as $var => $value)
230
+				foreach ($extra as $var => $value)
231 231
 				{
232
-					$t_extras[] = $var . '=' . urlencode($value);
232
+					$t_extras[] = $var.'='.urlencode($value);
233 233
 				}
234
-				$extra_s = '&' . implode('&',$t_extras);
234
+				$extra_s = '&'.implode('&', $t_extras);
235 235
 			}
236 236
 			return $extra_s;
237 237
 		}
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 		@param $total ?
245 245
 		@param $extradate ?
246 246
 		*/
247
-		function left($scriptname,$start,$total,$extradata = '')
247
+		function left($scriptname, $start, $total, $extradata = '')
248 248
 		{
249 249
 			$extravars = Array(
250 250
 				'order'   => $this->_order,
@@ -254,15 +254,15 @@  discard block
 block discarded – undo
254 254
 				'query'   => stripslashes(@$GLOBALS['query'])
255 255
 			);
256 256
 
257
-			$extravars = $this->split_extras($extravars,$extradata);
257
+			$extravars = $this->split_extras($extravars, $extradata);
258 258
 			$ret_str = '';
259 259
 
260
-			$start = (int) $start;
260
+			$start = (int)$start;
261 261
 
262 262
 			if ($start != 0)
263 263
 			{
264 264
 				$extravars['start'] = 0;
265
-				$ret_str .= $this->set_link('left','first.png',$scriptname,lang('First page'),$extravars);
265
+				$ret_str .= $this->set_link('left', 'first.png', $scriptname, lang('First page'), $extravars);
266 266
 				// Changing the sorting order screaws up the starting number
267 267
 				if (($start - $this->maxmatches) < 0)
268 268
 				{
@@ -272,12 +272,12 @@  discard block
 block discarded – undo
272 272
 				{
273 273
 					$extravars['start'] = ($start - $this->maxmatches);
274 274
 				}
275
-				$ret_str .= $this->set_link('left','left.png',$scriptname,lang('Previous page'),$extravars);
275
+				$ret_str .= $this->set_link('left', 'left.png', $scriptname, lang('Previous page'), $extravars);
276 276
 			}
277 277
 			else
278 278
 			{
279
-				$ret_str .= $this->set_icon('left','first-grey.png',lang('First page'));
280
-				$ret_str .= $this->set_icon('left','left-grey.png',lang('Previous page'));
279
+				$ret_str .= $this->set_icon('left', 'first-grey.png', lang('First page'));
280
+				$ret_str .= $this->set_icon('left', 'left-grey.png', lang('Previous page'));
281 281
 			}
282 282
 			return $ret_str;
283 283
 		} /* left() */
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 		@param $total ?
291 291
 		@param $extradate ?
292 292
 		*/
293
-		function right($scriptname,$start,$total,$extradata = '')
293
+		function right($scriptname, $start, $total, $extradata = '')
294 294
 		{
295 295
 			$extravars = Array(
296 296
 				'order'   => $this->_order,
@@ -300,23 +300,23 @@  discard block
 block discarded – undo
300 300
 				'query'   => stripslashes(@$GLOBALS['query'])
301 301
 			);
302 302
 
303
-			$extravars = $this->split_extras($extravars,$extradata);
303
+			$extravars = $this->split_extras($extravars, $extradata);
304 304
 			$ret_str = '';
305 305
 
306
-			$start = (int) $start;
306
+			$start = (int)$start;
307 307
 
308 308
 			if (($total > $this->maxmatches) &&
309 309
 				($total > $start + $this->maxmatches))
310 310
 			{
311 311
 				$extravars['start'] = ($start + $this->maxmatches);
312
-				$ret_str .= $this->set_link('right','right.png',$scriptname,lang('Next page'),$extravars);
312
+				$ret_str .= $this->set_link('right', 'right.png', $scriptname, lang('Next page'), $extravars);
313 313
 				$extravars['start'] = ($total - $this->maxmatches);
314
-				$ret_str .= $this->set_link('right','last.png',$scriptname,lang('Last page'),$extravars);
314
+				$ret_str .= $this->set_link('right', 'last.png', $scriptname, lang('Last page'), $extravars);
315 315
 			}
316 316
 			else
317 317
 			{
318
-				$ret_str .= $this->set_icon('right','right-grey.png',lang('Next page'));
319
-				$ret_str .= $this->set_icon('right','last-grey.png',lang('Last page'));
318
+				$ret_str .= $this->set_icon('right', 'right-grey.png', lang('Next page'));
319
+				$ret_str .= $this->set_icon('right', 'last-grey.png', lang('Last page'));
320 320
 			}
321 321
 			return $ret_str;
322 322
 		} /* right() */
@@ -326,10 +326,10 @@  discard block
 block discarded – undo
326 326
 		@abstract ?
327 327
 		@param $search_obj default 0
328 328
 		*/
329
-		function search_filter($search_obj=0,$filter_obj=1,$yours=0,$link='',$extra='')
329
+		function search_filter($search_obj = 0, $filter_obj = 1, $yours = 0, $link = '', $extra = '')
330 330
 		{
331 331
 			$var = array(
332
-				'form_action'  => ($this->_menuaction?$this->page($extra):$GLOBALS['egw']->link($sn, $extra)),
332
+				'form_action'  => ($this->_menuaction ? $this->page($extra) : $GLOBALS['egw']->link($sn, $extra)),
333 333
 				'th_bg'        => $GLOBALS['egw_info']['theme']['th_bg'],
334 334
 				'hidden'       => $GLOBALS['egw']->html->input_hidden(array(
335 335
 					'filter' => $this->_filter,
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 					'query'  => $GLOBALS['query'],
341 341
 				)),
342 342
 				'search'       => $this->search($search_obj),
343
-				'filter'       => ($filter_obj?$this->filter($filter_obj,$yours):'')
343
+				'filter'       => ($filter_obj ? $this->filter($filter_obj, $yours) : '')
344 344
 			);
345 345
 			$this->template->set_var($var);
346
-			return $this->template->fp('out','search_filter');
346
+			return $this->template->fp('out', 'search_filter');
347 347
 		}
348 348
 
349 349
 		/*!
@@ -351,19 +351,19 @@  discard block
 block discarded – undo
351 351
 		@abstract ?
352 352
 		@param $search_obj default 0
353 353
 		*/
354
-		function cats_search_filter($search_obj=0,$filter_obj=1,$yours=0,$cat_id=0,$cat_field='fcat_id',$link='',$extra='')
354
+		function cats_search_filter($search_obj = 0, $filter_obj = 1, $yours = 0, $cat_id = 0, $cat_field = 'fcat_id', $link = '', $extra = '')
355 355
 		{
356 356
 			if (!is_object($GLOBALS['egw']->categories))
357 357
 			{
358
-				$GLOBALS['egw']->categories  = CreateObject('phpgwapi.categories');
358
+				$GLOBALS['egw']->categories = CreateObject('phpgwapi.categories');
359 359
 			}
360 360
 			$var = array(
361
-				'form_action'   => ($this->_menuaction?$this->page($extra):$GLOBALS['egw']->link($sn, $extra)),
361
+				'form_action'   => ($this->_menuaction ? $this->page($extra) : $GLOBALS['egw']->link($sn, $extra)),
362 362
 				'lang_category' => lang('Category'),
363 363
 				'lang_all'      => lang('All'),
364 364
 				'lang_select'   => lang('Select'),
365 365
 				'cat_field'     => $cat_field,
366
-				'categories'    => $GLOBALS['egw']->categories->formatted_list('select','all',(int)$cat_id,'True'),
366
+				'categories'    => $GLOBALS['egw']->categories->formatted_list('select', 'all', (int)$cat_id, 'True'),
367 367
 				'hidden'       => $GLOBALS['egw']->html->input_hidden(array(
368 368
 					'filter' => $this->_filter,
369 369
 					'qfield' => $this->_qfield,
@@ -374,10 +374,10 @@  discard block
 block discarded – undo
374 374
 				)),
375 375
 				'th_bg'         => $GLOBALS['egw_info']['theme']['th_bg'],
376 376
 				'search'        => $this->search($search_obj),
377
-				'filter'        => ($filter_obj?$this->filter($filter_obj,$yours):'')
377
+				'filter'        => ($filter_obj ? $this->filter($filter_obj, $yours) : '')
378 378
 			);
379 379
 			$this->template->set_var($var);
380
-			return $this->template->fp('out','cats_search_filter');
380
+			return $this->template->fp('out', 'cats_search_filter');
381 381
 		}
382 382
 
383 383
 		/*!
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
 		@abstract ?
386 386
 		@param $search_obj default 0
387 387
 		*/
388
-		function search($search_obj=0)
388
+		function search($search_obj = 0)
389 389
 		{
390
-			if(is_array($search_obj))
390
+			if (is_array($search_obj))
391 391
 			{
392
-				$_query    = stripslashes($search_obj['query']);
392
+				$_query = stripslashes($search_obj['query']);
393 393
 				$search_obj = $search_obj['search_obj'];
394 394
 			}
395 395
 			else
@@ -399,12 +399,11 @@  discard block
 block discarded – undo
399 399
 
400 400
 			// If they place a '"' in their search, it will mess everything up
401 401
 			// Our only option is to remove it
402
-			if(strpos($_query,'"')!==false)
402
+			if (strpos($_query, '"') !== false)
403 403
 			{
404
-				$_query = str_replace('"','',$_query);
404
+				$_query = str_replace('"', '', $_query);
405 405
 			}
406
-			$var = array
407
-			(
406
+			$var = array(
408 407
 				'query_value'   => $GLOBALS['egw']->html->htmlspecialchars($_query),
409 408
 				'lang_search' => lang('Search')
410 409
 			);
@@ -415,7 +414,7 @@  discard block
 block discarded – undo
415 414
 			}
416 415
 
417 416
 			$this->template->set_var($var);
418
-			return $this->template->fp('out','search');
417
+			return $this->template->fp('out', 'search');
419 418
 		} /* search() */
420 419
 
421 420
 		/*!
@@ -427,11 +426,11 @@  discard block
 block discarded – undo
427 426
 		*/
428 427
 		function filterobj($filtertable, $idxfieldname, $strfieldname)
429 428
 		{
430
-			$filter_obj = array(array('none','show all'));
429
+			$filter_obj = array(array('none', 'show all'));
431 430
 			$index = 0;
432 431
 
433
-			$GLOBALS['egw']->db->query("SELECT $idxfieldname, $strfieldname FROM $filtertable",__LINE__,__FILE__);
434
-			while($GLOBALS['egw']->db->next_record())
432
+			$GLOBALS['egw']->db->query("SELECT $idxfieldname, $strfieldname FROM $filtertable", __LINE__, __FILE__);
433
+			while ($GLOBALS['egw']->db->next_record())
435 434
 			{
436 435
 				$index++;
437 436
 				$filter_obj[$index][0] = $GLOBALS['egw']->db->f($idxfieldname);
@@ -452,15 +451,15 @@  discard block
 block discarded – undo
452 451
 			if (is_array($search_obj))
453 452
 			{
454 453
 				$indexlimit = count($search_obj);
455
-				for ($index=0; $index<$indexlimit; $index++)
454
+				for ($index = 0; $index < $indexlimit; $index++)
456 455
 				{
457 456
 					if ($this->_qfield == '')
458 457
 					{
459 458
 						$this->_qfield = $search_obj[$index][0];
460 459
 					}
461
-					$str .= '<option value="' . $search_obj[$index][0] . '"' . ($this->_qfield == $search_obj[$index][0]?' selected':'') . '>' . lang($search_obj[$index][1]) . '</option>';
460
+					$str .= '<option value="'.$search_obj[$index][0].'"'.($this->_qfield == $search_obj[$index][0] ? ' selected' : '').'>'.lang($search_obj[$index][1]).'</option>';
462 461
 				}
463
-				$str = '<select name="qfield">' . $str . '</select>' . "\n";
462
+				$str = '<select name="qfield">'.$str.'</select>'."\n";
464 463
 			}
465 464
 			return $str;
466 465
 		} /* searchby() */
@@ -470,7 +469,7 @@  discard block
 block discarded – undo
470 469
 		@abstract ?
471 470
 		@param $filter_obj
472 471
 		*/
473
-		function filter($filter_obj,$yours=0)
472
+		function filter($filter_obj, $yours = 0)
474 473
 		{
475 474
 			if (is_array($yours))
476 475
 			{
@@ -488,19 +487,17 @@  discard block
 block discarded – undo
488 487
 
489 488
 					if ($yours)
490 489
 					{
491
-						$filter_obj = array
492
-						(
493
-							array('none',lang('Show all')),
494
-							array('yours',lang('Only yours')),
495
-							array('private',lang('private'))
490
+						$filter_obj = array(
491
+							array('none', lang('Show all')),
492
+							array('yours', lang('Only yours')),
493
+							array('private', lang('private'))
496 494
 						);
497 495
 					}
498 496
 					else
499 497
 					{
500
-						$filter_obj = array
501
-						(
502
-							array('none',lang('Show all')),
503
-							array('private',lang('private'))
498
+						$filter_obj = array(
499
+							array('none', lang('Show all')),
500
+							array('private', lang('private'))
504 501
 						);
505 502
 					}
506 503
 
@@ -509,10 +506,10 @@  discard block
 block discarded – undo
509 506
 						$filter_obj[] = $efilter;
510 507
 					}
511 508
 
512
-					for ($index=0; $index<$indexlimit; $index++)
509
+					for ($index = 0; $index < $indexlimit; $index++)
513 510
 					{
514
-						$filter_obj[2+$index][0] = $user_groups[$index]['account_id'];
515
-						$filter_obj[2+$index][1] = 'Group - ' . $user_groups[$index]['account_name'];
511
+						$filter_obj[2 + $index][0] = $user_groups[$index]['account_id'];
512
+						$filter_obj[2 + $index][1] = 'Group - '.$user_groups[$index]['account_name'];
516 513
 					}
517 514
 				}
518 515
 			}
@@ -522,30 +519,30 @@  discard block
 block discarded – undo
522 519
 				$str = '';
523 520
 				$indexlimit = count($filter_obj);
524 521
 
525
-				for ($index=0; $index<$indexlimit; $index++)
522
+				for ($index = 0; $index < $indexlimit; $index++)
526 523
 				{
527 524
 					if ($this->_filter == '')
528 525
 					{
529 526
 						$this->_filter = $filter_obj[$index][0];
530 527
 					}
531
-					$str .= '         <option value="' . $filter_obj[$index][0] . '"'.($this->_filter == $filter_obj[$index][0]?' selected="1"':'') . '>' . $filter_obj[$index][1] . '</option>'."\n";
528
+					$str .= '         <option value="'.$filter_obj[$index][0].'"'.($this->_filter == $filter_obj[$index][0] ? ' selected="1"' : '').'>'.$filter_obj[$index][1].'</option>'."\n";
532 529
 				}
533 530
 
534
-				$str = '        <select name="filter" onChange="this.form.submit()">'."\n" . $str . '        </select>';
535
-				$this->template->set_var('select',$str);
536
-				$this->template->set_var('lang_filter',lang('Filter'));
531
+				$str = '        <select name="filter" onChange="this.form.submit()">'."\n".$str.'        </select>';
532
+				$this->template->set_var('select', $str);
533
+				$this->template->set_var('lang_filter', lang('Filter'));
537 534
 			}
538 535
 
539
-			return $this->template->fp('out','filter');
536
+			return $this->template->fp('out', 'filter');
540 537
 		} /* filter() */
541 538
 
542 539
 		/* replacement for function filter */
543
-		function new_filter($data=0)
540
+		function new_filter($data = 0)
544 541
 		{
545
-			if(is_array($data))
542
+			if (is_array($data))
546 543
 			{
547
-				$filter = (isset($data['filter'])?$data['filter']:'');
548
-				$format = (isset($data['format'])?$data['format']:'all');
544
+				$filter = (isset($data['filter']) ? $data['filter'] : '');
545
+				$format = (isset($data['format']) ? $data['format'] : 'all');
549 546
 			}
550 547
 			else
551 548
 			{
@@ -554,48 +551,45 @@  discard block
 block discarded – undo
554 551
 				$format = 'all';
555 552
 			}
556 553
 
557
-			switch($format)
554
+			switch ($format)
558 555
 			{
559 556
 				case 'yours':
560
-					$filter_obj = array
561
-					(
562
-						array('none',lang('show all')),
563
-						array('yours',lang('only yours'))
557
+					$filter_obj = array(
558
+						array('none', lang('show all')),
559
+						array('yours', lang('only yours'))
564 560
 					);
565 561
 					break;
566 562
 				case 'private':
567
-					$filter_obj = array
568
-					(
569
-						array('none',lang('show all')),
570
-						array('private',lang('only private'))
563
+					$filter_obj = array(
564
+						array('none', lang('show all')),
565
+						array('private', lang('only private'))
571 566
 					);
572 567
 					break;
573 568
 				default:
574
-					$filter_obj = array
575
-					(
576
-						array('none',lang('show all')),
577
-						array('yours',lang('only yours')),
578
-						array('private',lang('only private'))
569
+					$filter_obj = array(
570
+						array('none', lang('show all')),
571
+						array('yours', lang('only yours')),
572
+						array('private', lang('only private'))
579 573
 					);
580 574
 			}
581 575
 
582 576
 			$str = '';
583 577
 			$indexlimit = count($filter_obj);
584 578
 
585
-			for($index=0; $index<$indexlimit; $index++)
579
+			for ($index = 0; $index < $indexlimit; $index++)
586 580
 			{
587
-				if($filter == '')
581
+				if ($filter == '')
588 582
 				{
589 583
 					$filter = $filter_obj[$index][0];
590 584
 				}
591
-				$str .= '         <option value="' . $filter_obj[$index][0] . '"'.($filter == $filter_obj[$index][0]?' selected="1"':'') . '>' . $filter_obj[$index][1] . '</option>'."\n";
585
+				$str .= '         <option value="'.$filter_obj[$index][0].'"'.($filter == $filter_obj[$index][0] ? ' selected="1"' : '').'>'.$filter_obj[$index][1].'</option>'."\n";
592 586
 			}
593 587
 
594
-			$str = '        <select name="filter" onChange="this.form.submit()">'."\n" . $str . '        </select>';
595
-			$this->template->set_var('select',$str);
596
-			$this->template->set_var('lang_filter',lang('Filter'));
588
+			$str = '        <select name="filter" onChange="this.form.submit()">'."\n".$str.'        </select>';
589
+			$this->template->set_var('select', $str);
590
+			$this->template->set_var('lang_filter', lang('Filter'));
597 591
 
598
-			return $this->template->fp('out','filter');
592
+			return $this->template->fp('out', 'filter');
599 593
 		} /* filter() */
600 594
 
601 595
 		/*!
@@ -604,9 +598,9 @@  discard block
 block discarded – undo
604 598
 		@param $currentcolor default ''
605 599
 		@param $do_class boolean default False return the color-value or just the class-name
606 600
 		*/
607
-		function alternate_row_color($currentcolor = '',$do_class=False)
601
+		function alternate_row_color($currentcolor = '', $do_class = False)
608 602
 		{
609
-			if (! $currentcolor)
603
+			if (!$currentcolor)
610 604
 			{
611 605
 				$currentcolor = @$GLOBALS['tr_color'];
612 606
 			}
@@ -641,7 +635,7 @@  discard block
 block discarded – undo
641 635
 		*/
642 636
 		function template_alternate_row_color(&$tpl)
643 637
 		{
644
-			$tpl->set_var('tr_color',$this->alternate_row_color());
638
+			$tpl->set_var('tr_color', $this->alternate_row_color());
645 639
 		}
646 640
 
647 641
 		/*!
@@ -654,13 +648,13 @@  discard block
 block discarded – undo
654 648
 		@param $text ?
655 649
 		@param $extra default ''
656 650
 		*/
657
-		function show_sort_order($sort,$var,$order,$program,$text,$extra='',$build_a_href=True)
651
+		function show_sort_order($sort, $var, $order, $program, $text, $extra = '', $build_a_href = True)
658 652
 		{
659 653
 			if ($order == $var)
660 654
 			{
661 655
 				$sort = $sort == 'ASC' ? 'DESC' : 'ASC';
662 656
 
663
-				$text = '<b>'.$text.'</b> <img border="0" src="'.$GLOBALS['egw']->common->image('phpgwapi',$sort=='ASC'?'up':'down').'">';
657
+				$text = '<b>'.$text.'</b> <img border="0" src="'.$GLOBALS['egw']->common->image('phpgwapi', $sort == 'ASC' ? 'up' : 'down').'">';
664 658
 			}
665 659
 			else
666 660
 			{
@@ -674,11 +668,11 @@  discard block
 block discarded – undo
674 668
 
675 669
 			$extravar = 'order='.$var.'&sort='.$sort.'&filter='.$this->_filter.'&qfield='.$this->_qfield.'&start='.$this->_start.'&query='.urlencode(stripslashes(@$GLOBALS['query'])).$extra;
676 670
 
677
-			$link = ($this->_menuaction?$this->page($extravar):$GLOBALS['egw']->link($program,$extravar));
671
+			$link = ($this->_menuaction ? $this->page($extravar) : $GLOBALS['egw']->link($program, $extravar));
678 672
 
679 673
 			if ($build_a_href)
680 674
 			{
681
-				return '<a href="' . $link . '">' . $text . '</a>';
675
+				return '<a href="'.$link.'">'.$text.'</a>';
682 676
 			}
683 677
 			else
684 678
 			{
@@ -686,7 +680,7 @@  discard block
 block discarded – undo
686 680
 			}
687 681
 		}
688 682
 
689
-		function show_hits($total_records='',$start=0)
683
+		function show_hits($total_records = '', $start = 0)
690 684
 		{
691 685
 			if ($total_records > $this->maxmatches)
692 686
 			{
@@ -698,11 +692,11 @@  discard block
 block discarded – undo
698 692
 				{
699 693
 					$end = $start + $this->maxmatches;
700 694
 				}
701
-				return lang('showing %1 - %2 of %3',($start + 1),$end,$total_records);
695
+				return lang('showing %1 - %2 of %3', ($start + 1), $end, $total_records);
702 696
 			}
703 697
 			else
704 698
 			{
705
-				return lang('showing %1',$total_records);
699
+				return lang('showing %1', $total_records);
706 700
 			}
707 701
 		}
708 702
 
@@ -717,20 +711,20 @@  discard block
 block discarded – undo
717 711
 		@param $text : Text the link will show
718 712
 		@param $extra : any extra stuff you want to pass, url style
719 713
 		*/
720
-		function show_sort_order_imap($old_sort,$new_sort,$default_order,$order,$program,$text,$extra='')
714
+		function show_sort_order_imap($old_sort, $new_sort, $default_order, $order, $program, $text, $extra = '')
721 715
 		{
722
-			if(is_array($extra))
716
+			if (is_array($extra))
723 717
 			{
724 718
 				$extra = $this->extras_to_string($extra);
725 719
 			}
726
-			if($old_sort == $new_sort)
720
+			if ($old_sort == $new_sort)
727 721
 			{
728 722
 				// alternate order, like on outkrook, click on present sorting reverses order
729
-				if((int)$order == 1)
723
+				if ((int)$order == 1)
730 724
 				{
731 725
 					$our_order = 0;
732 726
 				}
733
-				elseif((int)$order == 0)
727
+				elseif ((int)$order == 0)
734 728
 				{
735 729
 					$our_order = 1;
736 730
 				}
@@ -748,8 +742,8 @@  discard block
 block discarded – undo
748 742
 
749 743
 			$extravar = 'order='.$our_order.'&sort='.$new_sort.$extra;
750 744
 
751
-			$link = ($this->_menuaction?$this->page($extravar):$GLOBALS['egw']->link($program,$extravar));
752
-			return '<a href="' .$link .'">' .$text .'</a>';
745
+			$link = ($this->_menuaction ? $this->page($extravar) : $GLOBALS['egw']->link($program, $extravar));
746
+			return '<a href="'.$link.'">'.$text.'</a>';
753 747
 		}
754 748
 
755 749
 		/*!
@@ -783,21 +777,21 @@  discard block
 block discarded – undo
783 777
 			$out_vars['total'] = $feed_vars['total'];
784 778
 
785 779
 			// first page
786
-			if(($feed_vars['start'] != 0) &&
780
+			if (($feed_vars['start'] != 0) &&
787 781
 				($feed_vars['start'] > $this->maxmatches))
788 782
 			{
789 783
 				$out_vars['start'] = 0;
790
-				$return_array['first_page'] = $this->set_link_imap('left','first.png',lang('First page'),$out_vars);
784
+				$return_array['first_page'] = $this->set_link_imap('left', 'first.png', lang('First page'), $out_vars);
791 785
 			}
792 786
 			else
793 787
 			{
794
-				$return_array['first_page'] = $this->set_icon_imap('left','first-grey.png',lang('First page'));
788
+				$return_array['first_page'] = $this->set_icon_imap('left', 'first-grey.png', lang('First page'));
795 789
 			}
796 790
 			// previous page
797
-			if($feed_vars['start'] != 0)
791
+			if ($feed_vars['start'] != 0)
798 792
 			{
799 793
 				// Changing the sorting order screaws up the starting number
800
-				if(($feed_vars['start'] - $this->maxmatches) < 0)
794
+				if (($feed_vars['start'] - $this->maxmatches) < 0)
801 795
 				{
802 796
 					$out_vars['start'] = 0;
803 797
 				}
@@ -805,37 +799,37 @@  discard block
 block discarded – undo
805 799
 				{
806 800
 					$out_vars['start'] = ($feed_vars['start'] - $this->maxmatches);
807 801
 				}
808
-				$return_array['prev_page'] = $this->set_link_imap('left','left.png',lang('Previous page'),$out_vars);
802
+				$return_array['prev_page'] = $this->set_link_imap('left', 'left.png', lang('Previous page'), $out_vars);
809 803
 			}
810 804
 			else
811 805
 			{
812
-				$return_array['prev_page'] = $this->set_icon_imap('left','left-grey.png',lang('Previous page'));
806
+				$return_array['prev_page'] = $this->set_icon_imap('left', 'left-grey.png', lang('Previous page'));
813 807
 			}
814 808
 
815 809
 			// re-initialize the out_vars
816 810
 			// things that might change
817 811
 			$out_vars['start'] = $feed_vars['start'];
818 812
 			// next page
819
-			if(($feed_vars['total'] > $this->maxmatches) &&
813
+			if (($feed_vars['total'] > $this->maxmatches) &&
820 814
 				($feed_vars['total'] > $feed_vars['start'] + $this->maxmatches))
821 815
 			{
822 816
 				$out_vars['start'] = ($feed_vars['start'] + $this->maxmatches);
823
-				$return_array['next_page'] = $this->set_link_imap('right','right.png',lang('Next page'),$out_vars);
817
+				$return_array['next_page'] = $this->set_link_imap('right', 'right.png', lang('Next page'), $out_vars);
824 818
 			}
825 819
 			else
826 820
 			{
827
-				$return_array['next_page'] = $this->set_icon_imap('right','right-grey.png',lang('Next page'));
821
+				$return_array['next_page'] = $this->set_icon_imap('right', 'right-grey.png', lang('Next page'));
828 822
 			}
829 823
 			// last page
830
-			if(($feed_vars['start'] != $feed_vars['total'] - $this->maxmatches) &&
824
+			if (($feed_vars['start'] != $feed_vars['total'] - $this->maxmatches) &&
831 825
 				(($feed_vars['total'] - $this->maxmatches) > ($feed_vars['start'] + $this->maxmatches)))
832 826
 			{
833 827
 				$out_vars['start'] = ($feed_vars['total'] - $this->maxmatches);
834
-				$return_array['last_page'] = $this->set_link_imap('right','last.png',lang('Last page'),$out_vars);
828
+				$return_array['last_page'] = $this->set_link_imap('right', 'last.png', lang('Last page'), $out_vars);
835 829
 			}
836 830
 			else
837 831
 			{
838
-				$return_array['last_page'] = $this->set_icon_imap('right','last-grey.png',lang('Last page'));
832
+				$return_array['last_page'] = $this->set_icon_imap('right', 'last-grey.png', lang('Last page'));
839 833
 			}
840 834
 			return $return_array;
841 835
 		}
@@ -848,16 +842,16 @@  discard block
 block discarded – undo
848 842
 		@param $link ?
849 843
 		@param $extravars ?
850 844
 		*/
851
-		function set_link_imap($align,$img,$alt_text,$out_vars)
845
+		function set_link_imap($align, $img, $alt_text, $out_vars)
852 846
 		{
853
-			$img_full = $GLOBALS['egw']->common->image('phpgwapi',$img);
847
+			$img_full = $GLOBALS['egw']->common->image('phpgwapi', $img);
854 848
 			$image_part = '<img src="'.$img_full.'" border="0" alt="'.$alt_text.'" width="12" height="12">';
855 849
 			return '<a href="'.$out_vars['common_uri'].'&start='.$out_vars['start'].'">'.$image_part.'</a>';
856 850
 		}
857 851
 
858
-		function set_icon_imap($align,$img,$alt_text)
852
+		function set_icon_imap($align, $img, $alt_text)
859 853
 		{
860
-			$img_full = $GLOBALS['egw']->common->image('phpgwapi',$img);
854
+			$img_full = $GLOBALS['egw']->common->image('phpgwapi', $img);
861 855
 			return '<img src="'.$img_full.'" border="0" width="12" height="12" alt="'.$alt_text.'">'."\r\n";
862 856
 		}
863 857
 	} // End of nextmatchs class
Please login to merge, or discard this patch.
Upper-Lower-Casing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		*/
137 137
 		function set_link($align,$img,$link,$alt,$extravars)
138 138
 		{
139
-			$var = Array(
139
+			$var = array(
140 140
 				'align'     => $align,
141 141
 				'action'    => ($this->_menuaction?$this->page():$GLOBALS['egw']->link($link)),
142 142
 				'form_name' => $img,
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 		*/
247 247
 		function left($scriptname,$start,$total,$extradata = '')
248 248
 		{
249
-			$extravars = Array(
249
+			$extravars = array(
250 250
 				'order'   => $this->_order,
251 251
 				'filter'  => $this->_filter,
252 252
 				'q_field' => $this->_qfield,
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 		*/
293 293
 		function right($scriptname,$start,$total,$extradata = '')
294 294
 		{
295
-			$extravars = Array(
295
+			$extravars = array(
296 296
 				'order'   => $this->_order,
297 297
 				'filter'  => $this->_filter,
298 298
 				'q_field' => $this->_qfield,
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 			$filter_obj = array(array('none','show all'));
431 431
 			$index = 0;
432 432
 
433
-			$GLOBALS['egw']->db->query("SELECT $idxfieldname, $strfieldname FROM $filtertable",__LINE__,__FILE__);
433
+			$GLOBALS['egw']->db->query("select $idxfieldname, $strfieldname FROM $filtertable",__LINE__,__FILE__);
434 434
 			while($GLOBALS['egw']->db->next_record())
435 435
 			{
436 436
 				$index++;
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 		*/
770 770
 		function nav_left_right_imap($feed_vars)
771 771
 		{
772
-			$return_array = Array(
772
+			$return_array = array(
773 773
 				'first_page' => '',
774 774
 				'prev_page'  => '',
775 775
 				'next_page'  => '',
Please login to merge, or discard this patch.
phpgwapi/inc/class.schema_proc.inc.php 5 patches
Doc Comments   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -92,7 +92,6 @@  discard block
 block discarded – undo
92 92
 	 * Constructor of schema-processor
93 93
 	 *
94 94
 	 * @param string $dbms type of the database: 'mysql','pgsql','mssql','maxdb'
95
-	 * @param object $db=null database class, if null we use $GLOBALS['egw']->db
96 95
 	 * @return schema_proc
97 96
 	 */
98 97
 	function __construct($dbms=False,$db=null)
@@ -416,7 +415,7 @@  discard block
 block discarded – undo
416 415
 	/**
417 416
 	 * Check if we have an old, not automaticaly droped sequence and drop it
418 417
 	 *
419
-	 * @param $sTableName
418
+	 * @param string $sTableName
420 419
 	 * @param bool $preserveValue
421 420
 	 */
422 421
 	function _PostgresTestDropOldSequence($sTableName,$preserveValue=False)
@@ -529,9 +528,9 @@  discard block
 block discarded – undo
529 528
 	/**
530 529
 	 * Create an (unique) Index over one or more columns
531 530
 	 *
532
-	 * @param string $sTablename table-name
531
+	 * @param string $sTableName table-name
533 532
 	 * @param array $aColumnNames columns for the index
534
-	 * @param boolean $bUnique=false true for a unique index, default false
533
+	 * @param boolean $bUnique true for a unique index, default false
535 534
 	 * @param array/string $options='' db-sepecific options, default '' = none
536 535
 	 * @param string $sIdxName='' name of the index, if not given (default) its created automaticaly
537 536
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
@@ -789,7 +788,7 @@  discard block
 block discarded – undo
789 788
 	 * Creates all tables for one application
790 789
 	 *
791 790
 	 * @param array $aTables array of eGW table-definitions
792
-	 * @param boolean $bOutputHTML=false should we give diagnostics, default False
791
+	 * @param boolean $bOutputHTML should we give diagnostics, default False
793 792
 	 * @return boolean True on success, False if an (fatal) error occured
794 793
 	 */
795 794
 	function ExecuteScripts($aTables, $bOutputHTML=False)
@@ -827,9 +826,6 @@  discard block
 block discarded – undo
827 826
 	/**
828 827
 	* Return the value of a column
829 828
 	*
830
-	* @param string/integer $Name name of field or positional index starting from 0
831
-	* @param bool $strip_slashes string escape chars from field(optional), default false
832
-	* @return string the field value
833 829
 	*/
834 830
 	function f($value,$strip_slashes=False)
835 831
 	{
@@ -859,12 +855,7 @@  discard block
 block discarded – undo
859 855
 	/**
860 856
 	* Execute a query
861 857
 	*
862
-	* @param string $Query_String the query to be executed
863
-	* @param mixed $line the line method was called from - use __LINE__
864
-	* @param string $file the file method was called from - use __FILE__
865
-	* @param int $offset row to start from
866
-	* @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
867
-	* @return ADORecordSet or false, if the query fails
858
+	* @param integer $line
868 859
 	*/
869 860
 	function query($sQuery, $line='', $file='')
870 861
 	{
@@ -880,8 +871,6 @@  discard block
 block discarded – undo
880 871
 	*	if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence)
881 872
 	* @param int $line line-number to pass to query
882 873
 	* @param string $file file-name to pass to query
883
-	* @param string $app=false string with name of app, this need to be set in setup anyway!!!
884
-	* @return ADORecordSet or false, if the query fails
885 874
 	*/
886 875
 	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false)
887 876
 	{
@@ -892,8 +881,8 @@  discard block
 block discarded – undo
892 881
 	 * Execute the Sql statements in an array and give diagnostics, if any error occures
893 882
 	 *
894 883
 	 * @param $aSql array of SQL strings to execute
895
-	 * @param $debug_level int for which debug_level (and higher) should the diagnostics always been printed
896
-	 * @param $debug string variable number of arguments for the debug_message functions in case of an error
884
+	 * @param integer $debug_level int for which debug_level (and higher) should the diagnostics always been printed
885
+	 * @param string $debug string variable number of arguments for the debug_message functions in case of an error
897 886
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
898 887
 	 */
899 888
 	function ExecuteSqlArray($aSql,$debug_level,$debug)
@@ -935,7 +924,7 @@  discard block
 block discarded – undo
935 924
 	 * b) we use the table-names plus all column-names and remove dublicate parts
936 925
 	 *
937 926
 	 * @internal
938
-	 * @param $sTableName string name of the table
927
+	 * @param string $sTableName string name of the table
939 928
 	 * @param $aColumnNames array of column-names or string with a single column-name
940 929
 	 * @return string the index-name
941 930
 	 */
@@ -992,6 +981,7 @@  discard block
 block discarded – undo
992 981
 
993 982
 	/**
994 983
 	 * Giving a non-fatal error-message
984
+	 * @param string $str
995 985
 	 */
996 986
 	function error($str)
997 987
 	{
@@ -1020,7 +1010,7 @@  discard block
 block discarded – undo
1020 1010
 	 *
1021 1011
 	 * The parameters get formated depending on their type.
1022 1012
 	 *
1023
-	 * @param $msg string message with parameters/variables like lang(), eg. '%1'
1013
+	 * @param string $msg string message with parameters/variables like lang(), eg. '%1'
1024 1014
 	 * @param $backtrace include a function-backtrace, default True=On
1025 1015
 	 *	should only be set to False=Off, if your code ensures a call with backtrace=On was made before !!!
1026 1016
 	 * @param $param mixed a variable number of parameters, to be inserted in $msg
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -97,19 +97,19 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	function __construct($dbms=False,$db=null)
99 99
 	{
100
-	    if(is_object($db))
100
+		if(is_object($db))
101 101
 		{
102 102
 			$this->m_odb = $db;
103
-	    }
104
-	    else
105
-	    {
103
+		}
104
+		else
105
+		{
106 106
 			$this->m_odb = isset($GLOBALS['egw']->db) && is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db;
107
-	    }
108
-	    if (!($this->m_odb instanceof egw_db))
109
-	    {
110
-	    	throw new egw_exception_assertion_failed('no egw_db object!');
111
-	    }
112
-	    $this->m_odb->connect();
107
+		}
108
+		if (!($this->m_odb instanceof egw_db))
109
+		{
110
+			throw new egw_exception_assertion_failed('no egw_db object!');
111
+		}
112
+		$this->m_odb->connect();
113 113
 		$this->capabilities =& $this->m_odb->capabilities;
114 114
 
115 115
 		$this->sType = $dbms ? $dbms : $this->m_odb->Type;
@@ -825,64 +825,64 @@  discard block
 block discarded – undo
825 825
 	}
826 826
 
827 827
 	/**
828
-	* Return the value of a column
829
-	*
830
-	* @param string/integer $Name name of field or positional index starting from 0
831
-	* @param bool $strip_slashes string escape chars from field(optional), default false
832
-	* @return string the field value
833
-	*/
828
+	 * Return the value of a column
829
+	 *
830
+	 * @param string/integer $Name name of field or positional index starting from 0
831
+	 * @param bool $strip_slashes string escape chars from field(optional), default false
832
+	 * @return string the field value
833
+	 */
834 834
 	function f($value,$strip_slashes=False)
835 835
 	{
836 836
 		return $this->m_odb->f($value,$strip_slashes);
837 837
 	}
838 838
 
839 839
 	/**
840
-	* Number of rows in current result set
841
-	*
842
-	* @return int number of rows
843
-	*/
840
+	 * Number of rows in current result set
841
+	 *
842
+	 * @return int number of rows
843
+	 */
844 844
 	function num_rows()
845 845
 	{
846 846
 		return $this->m_odb->num_rows();
847 847
 	}
848 848
 
849 849
 	/**
850
-	* Move to the next row in the results set
851
-	*
852
-	* @return bool was another row found?
853
-	*/
850
+	 * Move to the next row in the results set
851
+	 *
852
+	 * @return bool was another row found?
853
+	 */
854 854
 	function next_record()
855 855
 	{
856 856
 		return $this->m_odb->next_record();
857 857
 	}
858 858
 
859 859
 	/**
860
-	* Execute a query
861
-	*
862
-	* @param string $Query_String the query to be executed
863
-	* @param mixed $line the line method was called from - use __LINE__
864
-	* @param string $file the file method was called from - use __FILE__
865
-	* @param int $offset row to start from
866
-	* @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
867
-	* @return ADORecordSet or false, if the query fails
868
-	*/
860
+	 * Execute a query
861
+	 *
862
+	 * @param string $Query_String the query to be executed
863
+	 * @param mixed $line the line method was called from - use __LINE__
864
+	 * @param string $file the file method was called from - use __FILE__
865
+	 * @param int $offset row to start from
866
+	 * @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
867
+	 * @return ADORecordSet or false, if the query fails
868
+	 */
869 869
 	function query($sQuery, $line='', $file='')
870 870
 	{
871 871
 		return $this->m_odb->query($sQuery, $line, $file);
872 872
 	}
873 873
 
874 874
 	/**
875
-	* Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type
876
-	*
877
-	* @param string $table name of the table
878
-	* @param array $data with column-name / value pairs
879
-	* @param mixed $where string with where clause or array with column-name / values pairs to check if a row with that keys already exists, or false for an unconditional insert
880
-	*	if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence)
881
-	* @param int $line line-number to pass to query
882
-	* @param string $file file-name to pass to query
883
-	* @param string $app=false string with name of app, this need to be set in setup anyway!!!
884
-	* @return ADORecordSet or false, if the query fails
885
-	*/
875
+	 * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type
876
+	 *
877
+	 * @param string $table name of the table
878
+	 * @param array $data with column-name / value pairs
879
+	 * @param mixed $where string with where clause or array with column-name / values pairs to check if a row with that keys already exists, or false for an unconditional insert
880
+	 *	if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence)
881
+	 * @param int $line line-number to pass to query
882
+	 * @param string $file file-name to pass to query
883
+	 * @param string $app=false string with name of app, this need to be set in setup anyway!!!
884
+	 * @return ADORecordSet or false, if the query fails
885
+	 */
886 886
 	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false)
887 887
 	{
888 888
 		return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement);
Please login to merge, or discard this patch.
Spacing   +185 added lines, -186 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @var array
55 55
 	 */
56
-	var $max_index_length=array(
56
+	var $max_index_length = array(
57 57
 		'maxdb'  => 32,
58 58
 		'oracle' => 30,
59 59
 	);
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 	 * @param object $db=null database class, if null we use $GLOBALS['egw']->db
96 96
 	 * @return schema_proc
97 97
 	 */
98
-	function __construct($dbms=False,$db=null)
98
+	function __construct($dbms = False, $db = null)
99 99
 	{
100
-	    if(is_object($db))
100
+	    if (is_object($db))
101 101
 		{
102 102
 			$this->m_odb = $db;
103 103
 	    }
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	    	throw new egw_exception_assertion_failed('no egw_db object!');
111 111
 	    }
112 112
 	    $this->m_odb->connect();
113
-		$this->capabilities =& $this->m_odb->capabilities;
113
+		$this->capabilities = & $this->m_odb->capabilities;
114 114
 
115 115
 		$this->sType = $dbms ? $dbms : $this->m_odb->Type;
116 116
 		$this->adodb = &$this->m_odb->Link_ID;
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		// to allow some of the former translator-functions to be called, we assign ourself as the translator
123 123
 		$this->m_oTranslator = &$this;
124 124
 
125
-		switch($this->sType)
125
+		switch ($this->sType)
126 126
 		{
127 127
 			case 'maxdb':
128 128
 				$this->max_varchar_length = 8000;
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 		}
139 139
 		if (is_object($GLOBALS['egw_setup']))
140 140
 		{
141
-			$this->system_charset =& $GLOBALS['egw_setup']->system_charset;
141
+			$this->system_charset = & $GLOBALS['egw_setup']->system_charset;
142 142
 		}
143 143
 		elseif (isset($GLOBALS['egw_info']['server']['system_charset']))
144 144
 		{
@@ -154,20 +154,20 @@  discard block
 block discarded – undo
154 154
 	 * @param boolean $ignore_length_limit =false should we take lenght-limits of indexes into account or not
155 155
 	 * @return boolean true if index over $columns exist in the $indexes array
156 156
 	 */
157
-	function _in_index($columns, $indexs, $ignore_length_limit=false)
157
+	function _in_index($columns, $indexs, $ignore_length_limit = false)
158 158
 	{
159 159
 		if (is_array($columns))
160 160
 		{
161 161
 			unset($columns['options']);
162
-			$columns = implode('-',$columns);
162
+			$columns = implode('-', $columns);
163 163
 			if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns);
164 164
 		}
165
-		foreach($indexs as $index)
165
+		foreach ($indexs as $index)
166 166
 		{
167 167
 			if (is_array($index))
168 168
 			{
169 169
 				unset($index['options']);
170
-				$index = implode('-',$index);
170
+				$index = implode('-', $index);
171 171
 			}
172 172
 			if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index);
173 173
 			if ($columns == $index) return true;
@@ -183,21 +183,21 @@  discard block
 block discarded – undo
183 183
 	 * @param bool $preserveSequence
184 184
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
185 185
 	 */
186
-	function CreateTable($sTableName, $aTableDef, $preserveSequence=False)
186
+	function CreateTable($sTableName, $aTableDef, $preserveSequence = False)
187 187
 	{
188 188
 		if ($this->debug)
189 189
 		{
190
-			$this->debug_message('schema_proc::CreateTable(%1,%2)',False,$sTableName, $aTableDef);
190
+			$this->debug_message('schema_proc::CreateTable(%1,%2)', False, $sTableName, $aTableDef);
191 191
 		}
192 192
 		// for mysql 4.0+ we set the charset for the table
193
-		if ($this->system_charset && substr($this->sType,0,5) == 'mysql' &&
194
-			(float) $this->m_odb->ServerInfo['version'] >= 4.0 && $this->m_odb->Link_ID->charset2mysql[$this->system_charset])
193
+		if ($this->system_charset && substr($this->sType, 0, 5) == 'mysql' &&
194
+			(float)$this->m_odb->ServerInfo['version'] >= 4.0 && $this->m_odb->Link_ID->charset2mysql[$this->system_charset])
195 195
 		{
196 196
 			$set_table_charset = array($this->sType => 'CHARACTER SET '.$this->m_odb->Link_ID->charset2mysql[$this->system_charset]);
197 197
 		}
198 198
 		// creating the table
199
-		$aSql = $this->dict->CreateTableSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef($aTableDef),$set_table_charset);
200
-		if (!($retVal = $this->ExecuteSQLArray($aSql,2,'CreateTableSQL(%1,%2) sql=%3',False,$sTableName,$ado_cols,$aSql)))
199
+		$aSql = $this->dict->CreateTableSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef($aTableDef), $set_table_charset);
200
+		if (!($retVal = $this->ExecuteSQLArray($aSql, 2, 'CreateTableSQL(%1,%2) sql=%3', False, $sTableName, $ado_cols, $aSql)))
201 201
 		{
202 202
 			return $retVal;
203 203
 		}
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
 		{
207 207
 			if (empty($mFields))
208 208
 			{
209
-				continue;	// cant create an index without fields (was observed in broken backups)
209
+				continue; // cant create an index without fields (was observed in broken backups)
210 210
 			}
211
-			if ($this->_in_index($mFields,array($aTableDef['pk'])))
211
+			if ($this->_in_index($mFields, array($aTableDef['pk'])))
212 212
 			{
213
-				continue;	// is already created as primary key
213
+				continue; // is already created as primary key
214 214
 			}
215
-			if (!($retVal = $this->CreateIndex($sTableName,$mFields,true,'',$name)))
215
+			if (!($retVal = $this->CreateIndex($sTableName, $mFields, true, '', $name)))
216 216
 			{
217 217
 				return $retVal;
218 218
 			}
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
 		{
223 223
 			if (empty($mFields))
224 224
 			{
225
-				continue;	// cant create an index without fields (was observed in broken backups)
225
+				continue; // cant create an index without fields (was observed in broken backups)
226 226
 			}
227
-			if ($this->_in_index($mFields,array($aTableDef['pk'])) ||
228
-				$this->_in_index($mFields,$aTableDef['uc']))
227
+			if ($this->_in_index($mFields, array($aTableDef['pk'])) ||
228
+				$this->_in_index($mFields, $aTableDef['uc']))
229 229
 			{
230
-				continue;	// is already created as primary key or unique index
230
+				continue; // is already created as primary key or unique index
231 231
 			}
232 232
 			$options = False;
233 233
 			if (is_array($mFields))
@@ -236,21 +236,21 @@  discard block
 block discarded – undo
236 236
 				{
237 237
 					if (isset($mFields['options'][$this->sType]))
238 238
 					{
239
-						$options = $mFields['options'][$this->sType];	// db-specific options, eg. index-type
240
-						if (!$options) continue;	// no index for our db-type
239
+						$options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type
240
+						if (!$options) continue; // no index for our db-type
241 241
 					}
242 242
 					unset($mFields['options']);
243 243
 				}
244 244
 			}
245
-			foreach((array)$mFields as $k => $col)
245
+			foreach ((array)$mFields as $k => $col)
246 246
 			{
247 247
 				// only create indexes on text-columns, if (db-)specifiy options are given or FULLTEXT for mysql
248 248
 				// most DB's cant do them and give errors
249
-				if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext')))
249
+				if (in_array($aTableDef['fd'][$col]['type'], array('text', 'longtext')))
250 250
 				{
251 251
 					if (is_array($mFields))	// index over multiple columns including a text column
252 252
 					{
253
-						$mFields[$k] .= '(32)';	// 32=limit of egw_addressbook_extra.extra_value to fix old backups
253
+						$mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups
254 254
 					}
255 255
 					elseif (!$options)	// index over a single text column and no options given
256 256
 					{
@@ -260,12 +260,12 @@  discard block
 block discarded – undo
260 260
 						}
261 261
 						else
262 262
 						{
263
-							continue 2;	// ignore that index, 2=not just column but whole index!
263
+							continue 2; // ignore that index, 2=not just column but whole index!
264 264
 						}
265 265
 					}
266 266
 				}
267 267
 			}
268
-			if (!($retVal = $this->CreateIndex($sTableName,$mFields,false,$options,$name)))
268
+			if (!($retVal = $this->CreateIndex($sTableName, $mFields, false, $options, $name)))
269 269
 			{
270 270
 				return $retVal;
271 271
 			}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 			if ($seq = $this->_PostgresHasOldSequence($sTableName))
277 277
 			{
278 278
 				$this->pgsql_old_seq = $this->pgsql_old_seq + 1;
279
-				$this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH " . $this->pgsql_old_seq,__LINE__,__FILE__);
279
+				$this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH ".$this->pgsql_old_seq, __LINE__, __FILE__);
280 280
 			}
281 281
 			$this->pgsql_old_seq = 0;
282 282
 		}
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
 	 * @param boolean $bOutputHTML should we give diagnostics, default False
291 291
 	 * @return boolean True if no error, else False
292 292
 	 */
293
-	function DropAllTables($aTables, $bOutputHTML=False)
293
+	function DropAllTables($aTables, $bOutputHTML = False)
294 294
 	{
295
-		if(!is_array($aTables) || !isset($this->m_odb))
295
+		if (!is_array($aTables) || !isset($this->m_odb))
296 296
 		{
297 297
 			return False;
298 298
 		}
@@ -300,13 +300,13 @@  discard block
 block discarded – undo
300 300
 		if ($this->debug) $bOutputHTML = True;
301 301
 		if ($bOutputHTML && !$this->debug) $this->debug = 2;
302 302
 
303
-		foreach($aTables as $sTableName => $aTableDef)
303
+		foreach ($aTables as $sTableName => $aTableDef)
304 304
 		{
305
-			if($this->DropTable($sTableName))
305
+			if ($this->DropTable($sTableName))
306 306
 			{
307
-				if($bOutputHTML)
307
+				if ($bOutputHTML)
308 308
 				{
309
-					echo '<br>Drop Table <b>' . $sTableSQL . '</b>';
309
+					echo '<br>Drop Table <b>'.$sTableSQL.'</b>';
310 310
 				}
311 311
 			}
312 312
 			else
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 
330 330
 		$aSql = $this->dict->DropTableSql($sTableName);
331 331
 
332
-		return $this->ExecuteSQLArray($aSql,2,'DropTable(%1) sql=%2',False,$sTableName,$aSql);
332
+		return $this->ExecuteSQLArray($aSql, 2, 'DropTable(%1) sql=%2', False, $sTableName, $aSql);
333 333
 	}
334 334
 
335 335
 	/**
@@ -346,9 +346,9 @@  discard block
 block discarded – undo
346 346
 		$table_def = $this->GetTableDefinition($sTableName);
347 347
 		unset($table_def['fd'][$sColumnName]);
348 348
 
349
-		$aSql = $this->dict->DropColumnSql($sTableName,$sColumnName,$ado_table=$this->_egw2adodb_columndef($table_def));
349
+		$aSql = $this->dict->DropColumnSql($sTableName, $sColumnName, $ado_table = $this->_egw2adodb_columndef($table_def));
350 350
 
351
-		return $this->ExecuteSQLArray($aSql,2,'DropColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName,$ado_table,$aSql);
351
+		return $this->ExecuteSQLArray($aSql, 2, 'DropColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $ado_table, $aSql);
352 352
 	}
353 353
 
354 354
 	/**
@@ -366,12 +366,12 @@  discard block
 block discarded – undo
366 366
 		{
367 367
 			$table_def = $this->GetTableDefinition($sOldTableName);
368 368
 
369
-			if ($this->_PostgresHasOldSequence($sOldTableName,True) || count($table_def['pk']) ||
369
+			if ($this->_PostgresHasOldSequence($sOldTableName, True) || count($table_def['pk']) ||
370 370
 				count($table_def['ix']) || count($table_def['uc']))
371 371
 			{
372 372
 				if ($this->adodb->BeginTrans() &&
373
-					$this->CreateTable($sNewTableName,$table_def,True) &&
374
-					$this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName",__LINE__,__FILE__) &&
373
+					$this->CreateTable($sNewTableName, $table_def, True) &&
374
+					$this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName", __LINE__, __FILE__) &&
375 375
 					$this->DropTable($sOldTableName))
376 376
 				{
377 377
 					$this->adodb->CommitTrans();
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 		}
384 384
 		$aSql = $this->dict->RenameTableSQL($sOldTableName, $sNewTableName);
385 385
 
386
-		return $this->ExecuteSQLArray($aSql,2,'RenameTableSQL(%1,%2) sql=%3',False,$sOldTableName,$sNewTableName,$aSql);
386
+		return $this->ExecuteSQLArray($aSql, 2, 'RenameTableSQL(%1,%2) sql=%3', False, $sOldTableName, $sNewTableName, $aSql);
387 387
 	}
388 388
 
389 389
 	/**
@@ -393,21 +393,21 @@  discard block
 block discarded – undo
393 393
 	 * @param bool $preserveValue
394 394
 	 * @return boolean/string sequence-name or false
395 395
 	 */
396
-	function _PostgresHasOldSequence($sTableName,$preserveValue=False)
396
+	function _PostgresHasOldSequence($sTableName, $preserveValue = False)
397 397
 	{
398 398
 		if ($this->sType != 'pgsql') return false;
399 399
 
400 400
 		$seq = $this->adodb->GetOne("SELECT d.adsrc FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$sTableName' AND c.oid=d.adrelid AND d.adsrc LIKE '%seq_$sTableName''::text)' AND a.attrelid=c.oid AND d.adnum=a.attnum");
401 401
 		$seq2 = $this->adodb->GetOne("SELECT d.adsrc FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$sTableName' AND c.oid=d.adrelid AND d.adsrc LIKE '%$sTableName%_seq''::text)' AND a.attrelid=c.oid AND d.adnum=a.attnum");
402 402
 
403
-		if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches))
403
+		if ($seq && preg_match('/^nextval\(\'(.*)\'/', $seq, $matches))
404 404
 		{
405
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
405
+			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]);
406 406
 			return $matches[1];
407 407
 		}
408
-		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches))
408
+		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/', $seq2, $matches))
409 409
 		{
410
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
410
+			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]);
411 411
 			return $matches[1];
412 412
 		}
413 413
 		return false;
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * @param $sTableName
420 420
 	 * @param bool $preserveValue
421 421
 	 */
422
-	function _PostgresTestDropOldSequence($sTableName,$preserveValue=False)
422
+	function _PostgresTestDropOldSequence($sTableName, $preserveValue = False)
423 423
 	{
424 424
 		$this->pgsql_old_seq = 0;
425 425
 		if ($this->sType == 'pgsql' && ($seq = $this->_PostgresHasOldSequence($sTableName)))
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 			// only drop sequence, if there is no dependency on it
428 428
 			if (!$this->adodb->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'"))
429 429
 			{
430
-				$this->query('DROP SEQUENCE '.$seq,__LINE__,__FILE__);
430
+				$this->query('DROP SEQUENCE '.$seq, __LINE__, __FILE__);
431 431
 			}
432 432
 		}
433 433
 	}
@@ -441,12 +441,12 @@  discard block
 block discarded – undo
441 441
 	 * @param boolean $bCopyData ???
442 442
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
443 443
 	 */
444
-	function AlterColumn($sTableName, $sColumnName, $aColumnDef, $bCopyData=True)
444
+	function AlterColumn($sTableName, $sColumnName, $aColumnDef, $bCopyData = True)
445 445
 	{
446 446
 		$table_def = $this->GetTableDefinition($sTableName);
447 447
 
448 448
 		// PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long
449
-		if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
449
+		if ($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
450 450
 			in_array($aColumnDef['type'], array('varchar', 'ascii')) &&
451 451
 			$table_def['fd'][$sColumnName]['precision'] > $aColumnDef['precision'])
452 452
 		{
@@ -461,12 +461,12 @@  discard block
 block discarded – undo
461 461
 		}
462 462
 		$table_def['fd'][$sColumnName] = $aColumnDef;
463 463
 
464
-		$aSql = $this->dict->AlterColumnSQL($sTableName,$ado_col = $this->_egw2adodb_columndef(array(
464
+		$aSql = $this->dict->AlterColumnSQL($sTableName, $ado_col = $this->_egw2adodb_columndef(array(
465 465
 				'fd' => array($sColumnName => $aColumnDef),
466 466
 				'pk' => array(),
467
-			)),$ado_table=$this->_egw2adodb_columndef($table_def));
467
+			)), $ado_table = $this->_egw2adodb_columndef($table_def));
468 468
 
469
-		return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$ado_col,$ado_table,$aSql);
469
+		return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $ado_col, $ado_table, $aSql);
470 470
 	}
471 471
 
472 472
 	/**
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 	 * @param boolean $bCopyData ???
479 479
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
480 480
 	 */
481
-	function RenameColumn($sTableName, $sOldColumnName, $sNewColumnName, $bCopyData=True)
481
+	function RenameColumn($sTableName, $sOldColumnName, $sNewColumnName, $bCopyData = True)
482 482
 	{
483 483
 		$table_def = $this->GetTableDefinition($sTableName);
484 484
 		$old_def = array();
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 		}
490 490
 		else
491 491
 		{
492
-			foreach($table_def['fd'] as $col => $def)
492
+			foreach ($table_def['fd'] as $col => $def)
493 493
 			{
494 494
 				if (strtolower($col) == strtolower($sOldColumnName))
495 495
 				{
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
 				'pk' => array(),
504 504
 			));
505 505
 
506
-		$aSql = $this->dict->RenameColumnSQL($sTableName,$sOldColumnName,$sNewColumnName,$col_def);
506
+		$aSql = $this->dict->RenameColumnSQL($sTableName, $sOldColumnName, $sNewColumnName, $col_def);
507 507
 
508
-		return $this->ExecuteSQLArray($aSql,2,'RenameColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sOldColumnName, $sNewColumnName,$aSql);
508
+		return $this->ExecuteSQLArray($aSql, 2, 'RenameColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sOldColumnName, $sNewColumnName, $aSql);
509 509
 	}
510 510
 
511 511
 	/**
@@ -518,12 +518,12 @@  discard block
 block discarded – undo
518 518
 	 */
519 519
 	function AddColumn($sTableName, $sColumnName, $aColumnDef)
520 520
 	{
521
-		$aSql = $this->dict->AddColumnSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef(array(
521
+		$aSql = $this->dict->AddColumnSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef(array(
522 522
 				'fd' => array($sColumnName => $aColumnDef),
523 523
 				'pk' => array(),
524 524
 			)));
525 525
 
526
-		return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName, $aColumnDef,$aSql);
526
+		return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $aColumnDef, $aSql);
527 527
 	}
528 528
 
529 529
 	/**
@@ -536,23 +536,23 @@  discard block
 block discarded – undo
536 536
 	 * @param string $sIdxName='' name of the index, if not given (default) its created automaticaly
537 537
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
538 538
 	 */
539
-	function CreateIndex($sTableName,$aColumnNames,$bUnique=false,$options='',$sIdxName='')
539
+	function CreateIndex($sTableName, $aColumnNames, $bUnique = false, $options = '', $sIdxName = '')
540 540
 	{
541 541
 		// remove length limits from column names, if DB type is NOT MySQL
542 542
 		if ($this->sType != 'mysql')
543 543
 		{
544
-			$aColumnNames = preg_replace('/ *\(\d+\)$/','',$aColumnNames);
544
+			$aColumnNames = preg_replace('/ *\(\d+\)$/', '', $aColumnNames);
545 545
 		}
546 546
 		if (!$sIdxName || is_numeric($sIdxName))
547 547
 		{
548
-			$sIdxName = $this->_index_name($sTableName,$aColumnNames);
548
+			$sIdxName = $this->_index_name($sTableName, $aColumnNames);
549 549
 		}
550 550
 		if (!is_array($options)) $options = $options ? array($options) : array();
551 551
 		if ($bUnique) $options[] = 'UNIQUE';
552 552
 
553
-		$aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options);
553
+		$aSql = $this->dict->CreateIndexSQL($sIdxName, $sTableName, $aColumnNames, $options);
554 554
 
555
-		return $this->ExecuteSQLArray($aSql,2,'CreateIndexSQL(%1,%2,%3,%4) sql=%5',False,$sTableName,$aColumnNames,$options,$sIdxName,$aSql);
555
+		return $this->ExecuteSQLArray($aSql, 2, 'CreateIndexSQL(%1,%2,%3,%4) sql=%5', False, $sTableName, $aColumnNames, $options, $sIdxName, $aSql);
556 556
 	}
557 557
 
558 558
 	/**
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 	 * @param array/string $aColumnNames columns of the index or the name of the index
563 563
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
564 564
 	 */
565
-	function DropIndex($sTableName,$aColumnNames)
565
+	function DropIndex($sTableName, $aColumnNames)
566 566
 	{
567 567
 		if (is_array($aColumnNames))
568 568
 		{
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
 			{
573 573
 				// if MetaIndexes is not availible for the DB, we try the name the index was created with
574 574
 				// this fails if one of the columns have been renamed
575
-				$sIdxName = $this->_index_name($sTableName,$aColumnNames);
575
+				$sIdxName = $this->_index_name($sTableName, $aColumnNames);
576 576
 			}
577 577
 			else
578 578
 			{
579
-				foreach($indexes as $idx => $idx_data)
579
+				foreach ($indexes as $idx => $idx_data)
580 580
 				{
581
-					if (strtolower(implode(':',$idx_data['columns'])) == implode(':',$aColumnNames))
581
+					if (strtolower(implode(':', $idx_data['columns'])) == implode(':', $aColumnNames))
582 582
 					{
583 583
 						$sIdxName = $idx;
584 584
 						break;
@@ -590,13 +590,13 @@  discard block
 block discarded – undo
590 590
 		{
591 591
 			$sIdxName = $aColumnNames;
592 592
 		}
593
-		if(!$sIdxName)
593
+		if (!$sIdxName)
594 594
 		{
595 595
 			return True;
596 596
 		}
597
-		$aSql = $this->dict->DropIndexSQL($sIdxName,$sTableName);
597
+		$aSql = $this->dict->DropIndexSQL($sIdxName, $sTableName);
598 598
 
599
-		return $this->ExecuteSQLArray($aSql,2,'DropIndexSQL(%1(%2),%3) sql=%4',False,$sIdxName,$aColumnNames,$sTableName,$aSql);
599
+		return $this->ExecuteSQLArray($aSql, 2, 'DropIndexSQL(%1(%2),%3) sql=%4', False, $sIdxName, $aColumnNames, $sTableName, $aSql);
600 600
 	}
601 601
 
602 602
 	/**
@@ -604,21 +604,21 @@  discard block
 block discarded – undo
604 604
 	 * @param string $sTableName table-name
605 605
 	 * @param string $sColumnName column-name, which default is set to nextval()
606 606
 	 */
607
-	function UpdateSequence($sTableName,$sColumnName)
607
+	function UpdateSequence($sTableName, $sColumnName)
608 608
 	{
609
-		switch($this->sType)
609
+		switch ($this->sType)
610 610
 		{
611 611
 			case 'pgsql':
612 612
 				// identify the sequence name, ADOdb uses a different name or it might be renamed
613 613
 				$columns = $this->dict->MetaColumns($sTableName);
614 614
 				$seq_name = 'seq_'.$sTableName;
615
-				if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$columns[strtoupper($sColumnName)]->default_value,$matches))
615
+				if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $columns[strtoupper($sColumnName)]->default_value, $matches))
616 616
 				{
617 617
 					$seq_name = $matches[1];
618 618
 				}
619 619
 				$sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName";
620
-				if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
621
-				return $this->query($sql,__LINE__,__FILE__);
620
+				if ($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
621
+				return $this->query($sql, __LINE__, __FILE__);
622 622
 		}
623 623
 		return True;
624 624
 	}
@@ -635,9 +635,9 @@  discard block
 block discarded – undo
635 635
 	 * @param array $aTableDef eGW table-defintion
636 636
 	 * @param array/boolean $aDefaults array with default for the colums during copying, values are either (old) column-names or quoted string-literals
637 637
 	 */
638
-	function RefreshTable($sTableName, $aTableDef, $aDefaults=False)
638
+	function RefreshTable($sTableName, $aTableDef, $aDefaults = False)
639 639
 	{
640
-		if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")<p>$sTableName="._debug_array($old_table_def,False)."\n"; }
640
+		if ($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef, False).")<p>$sTableName="._debug_array($old_table_def, False)."\n"; }
641 641
 
642 642
 		$old_table_def = $this->GetTableDefinition($sTableName);
643 643
 
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
 
647 647
 		$select = array();
648 648
 		$blob_column_included = $auto_column_included = False;
649
-		foreach($aTableDef['fd'] as $name => $data)
649
+		foreach ($aTableDef['fd'] as $name => $data)
650 650
 		{
651 651
 			// new auto column with no default or explicit NULL as default (can be an existing column too!)
652 652
 			if ($data['type'] == 'auto' &&
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 				$aDefaults && strtoupper($aDefaults[$name]) == 'NULL'))
655 655
 			{
656 656
 				$sequence_name = $sTableName.'_'.$name.'_seq';
657
-				switch($GLOBALS['egw_setup']->db->Type)
657
+				switch ($GLOBALS['egw_setup']->db->Type)
658 658
 				{
659 659
 					case 'mysql':
660 660
 						$value = 'NULL'; break;
@@ -675,25 +675,25 @@  discard block
 block discarded – undo
675 675
 				if ($this->sType == 'pgsql')			// some postgres specific code
676 676
 				{
677 677
 					// this is eg. necessary to change a varchar into an int column under postgres
678
-					if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) &&
679
-						in_array($data['type'],array('int','decimal')))
678
+					if (in_array($old_table_def['fd'][$name]['type'], array('char', 'varchar', 'text', 'blob')) &&
679
+						in_array($data['type'], array('int', 'decimal')))
680 680
 					{
681 681
 						$value = "to_number($name,'S9999999999999D99')";
682 682
 					}
683 683
 					// blobs cant be casted to text
684
-					elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
684
+					elseif ($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
685 685
 					{
686 686
 						$value = "ENCODE($value,'escape')";
687 687
 					}
688 688
 					// varchar or ascii column shortened, use substring to avoid error if current content is to long
689
-					elseif(in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) &&
689
+					elseif (in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) &&
690 690
 						in_array($data['type'], array('varchar', 'ascii')) &&
691 691
 						$old_table_def['fd'][$name]['precision'] > $data['precision'])
692 692
 					{
693 693
 						$value = "SUBSTRING($value FROM 1 FOR ".(int)$data['precision'].')';
694 694
 					}
695 695
 					// cast everything which is a different type
696
-					elseif($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type'])))
696
+					elseif ($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type'])))
697 697
 					{
698 698
 						$value = "CAST($value AS $type_translated)";
699 699
 					}
@@ -706,43 +706,43 @@  discard block
 block discarded – undo
706 706
 					$value = 'NULL';
707 707
 				}
708 708
 				// some stuff is NOT to be quoted
709
-				elseif (in_array(strtoupper($data['default']),array('CURRENT_TIMESTAMP','CURRENT_DATE','NULL','NOW()')))
709
+				elseif (in_array(strtoupper($data['default']), array('CURRENT_TIMESTAMP', 'CURRENT_DATE', 'NULL', 'NOW()')))
710 710
 				{
711 711
 					$value = $data['default'];
712 712
 				}
713 713
 				else
714 714
 				{
715
-					$value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '',$data['type']);
715
+					$value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '', $data['type']);
716 716
 				}
717 717
 				if ($this->sType == 'pgsql')
718 718
 				{
719 719
 					// fix for postgres error "no '<' operator for type 'unknown'"
720
-					if(($type_translated = $this->TranslateType($data['type'])))
720
+					if (($type_translated = $this->TranslateType($data['type'])))
721 721
 					{
722 722
 						$value = "CAST($value AS $type_translated)";
723 723
 					}
724 724
 				}
725 725
 			}
726
-			$blob_column_included = $blob_column_included || in_array($data['type'],array('blob','text','longtext'));
726
+			$blob_column_included = $blob_column_included || in_array($data['type'], array('blob', 'text', 'longtext'));
727 727
 			$auto_column_included = $auto_column_included || $data['type'] == 'auto';
728 728
 			$select[] = $value;
729 729
 		}
730
-		$select = implode(',',$select);
730
+		$select = implode(',', $select);
731 731
 
732 732
 		$extra = '';
733 733
 		$distinct = 'DISTINCT';
734
-		switch($this->sType)
734
+		switch ($this->sType)
735 735
 		{
736 736
 			case 'mssql':
737 737
 				if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n";
738
-				if ($blob_column_included) $distinct = '';	// no distinct on blob-columns
738
+				if ($blob_column_included) $distinct = ''; // no distinct on blob-columns
739 739
 				break;
740 740
 		}
741 741
 		// because of all the trouble with sequences and indexes in the global namespace,
742 742
 		// we use an additional temp. table for postgres and not rename the existing one, but drop it.
743 743
 		if ($this->sType == 'pgsql')
744 744
 		{
745
-			$Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName",__LINE__,__FILE__) &&
745
+			$Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName", __LINE__, __FILE__) &&
746 746
 				$this->DropTable($sTableName);
747 747
 		}
748 748
 		else
@@ -752,12 +752,12 @@  discard block
 block discarded – undo
752 752
 			{
753 753
 				$this->DropTable($tmp_name);
754 754
 			}
755
-			$Ok = $this->RenameTable($sTableName,$tmp_name);
755
+			$Ok = $this->RenameTable($sTableName, $tmp_name);
756 756
 		}
757
-		$Ok = $Ok && $this->CreateTable($sTableName,$aTableDef) &&
758
-			$this->m_odb->query($sql_copy_data="$extra INSERT INTO $sTableName (".
759
-				implode(',',array_keys($aTableDef['fd'])).
760
-				") SELEcT $distinct $select FROM $tmp_name",__LINE__,__FILE__) &&
757
+		$Ok = $Ok && $this->CreateTable($sTableName, $aTableDef) &&
758
+			$this->m_odb->query($sql_copy_data = "$extra INSERT INTO $sTableName (".
759
+				implode(',', array_keys($aTableDef['fd'])).
760
+				") SELEcT $distinct $select FROM $tmp_name", __LINE__, __FILE__) &&
761 761
 			$this->DropTable($tmp_name);
762 762
 		//error_log($sql_copy_data);
763 763
 
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 		// do we need to update the new sequences value ?
770 770
 		if (count($aTableDef['pk']) == 1 && $aTableDef['fd'][$aTableDef['pk'][0]]['type'] == 'auto')
771 771
 		{
772
-			$this->UpdateSequence($sTableName,$aTableDef['pk'][0]);
772
+			$this->UpdateSequence($sTableName, $aTableDef['pk'][0]);
773 773
 		}
774 774
 		$this->m_odb->transaction_commit();
775 775
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
 	 * depricated Function does nothing any more
781 781
 	 * @depricated
782 782
 	 */
783
-	function GenerateScripts($aTables, $bOutputHTML=False)
783
+	function GenerateScripts($aTables, $bOutputHTML = False)
784 784
 	{
785 785
 		return True;
786 786
 	}
@@ -792,9 +792,9 @@  discard block
 block discarded – undo
792 792
 	 * @param boolean $bOutputHTML=false should we give diagnostics, default False
793 793
 	 * @return boolean True on success, False if an (fatal) error occured
794 794
 	 */
795
-	function ExecuteScripts($aTables, $bOutputHTML=False)
795
+	function ExecuteScripts($aTables, $bOutputHTML = False)
796 796
 	{
797
-		if(!is_array($aTables) || !IsSet($this->m_odb))
797
+		if (!is_array($aTables) || !IsSet($this->m_odb))
798 798
 		{
799 799
 			return False;
800 800
 		}
@@ -802,20 +802,20 @@  discard block
 block discarded – undo
802 802
 		if ($this->debug) $bOutputHTML = True;
803 803
 		if ($bOutputHTML && !$this->debug) $this->debug = 2;
804 804
 
805
-		foreach($aTables as $sTableName => $aTableDef)
805
+		foreach ($aTables as $sTableName => $aTableDef)
806 806
 		{
807
-			if($this->CreateTable($sTableName, $aTableDef))
807
+			if ($this->CreateTable($sTableName, $aTableDef))
808 808
 			{
809
-				if($bOutputHTML)
809
+				if ($bOutputHTML)
810 810
 				{
811
-					echo '<br>Create Table <b>' . $sTableName . '</b>';
811
+					echo '<br>Create Table <b>'.$sTableName.'</b>';
812 812
 				}
813 813
 			}
814 814
 			else
815 815
 			{
816
-				if($bOutputHTML)
816
+				if ($bOutputHTML)
817 817
 				{
818
-					echo '<br>Create Table Failed For <b>' . $sTableName . '</b>';
818
+					echo '<br>Create Table Failed For <b>'.$sTableName.'</b>';
819 819
 				}
820 820
 
821 821
 				return False;
@@ -831,9 +831,9 @@  discard block
 block discarded – undo
831 831
 	* @param bool $strip_slashes string escape chars from field(optional), default false
832 832
 	* @return string the field value
833 833
 	*/
834
-	function f($value,$strip_slashes=False)
834
+	function f($value, $strip_slashes = False)
835 835
 	{
836
-		return $this->m_odb->f($value,$strip_slashes);
836
+		return $this->m_odb->f($value, $strip_slashes);
837 837
 	}
838 838
 
839 839
 	/**
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 	* @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
867 867
 	* @return ADORecordSet or false, if the query fails
868 868
 	*/
869
-	function query($sQuery, $line='', $file='')
869
+	function query($sQuery, $line = '', $file = '')
870 870
 	{
871 871
 		return $this->m_odb->query($sQuery, $line, $file);
872 872
 	}
@@ -883,9 +883,9 @@  discard block
 block discarded – undo
883 883
 	* @param string $app=false string with name of app, this need to be set in setup anyway!!!
884 884
 	* @return ADORecordSet or false, if the query fails
885 885
 	*/
886
-	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false)
886
+	function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false)
887 887
 	{
888
-		return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement);
888
+		return $this->m_odb->insert($table, $data, $where, $line, $file, $app, $use_prepared_statement);
889 889
 	}
890 890
 
891 891
 	/**
@@ -896,14 +896,14 @@  discard block
 block discarded – undo
896 896
 	 * @param $debug string variable number of arguments for the debug_message functions in case of an error
897 897
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
898 898
 	 */
899
-	function ExecuteSqlArray($aSql,$debug_level,$debug)
899
+	function ExecuteSqlArray($aSql, $debug_level, $debug)
900 900
 	{
901 901
 		if ($this->m_odb->query_log)	// we use egw_db::query to log the queries
902 902
 		{
903 903
 			$retval = 2;
904
-			foreach($aSql as $sql)
904
+			foreach ($aSql as $sql)
905 905
 			{
906
-				if (!$this->m_odb->query($sql,__LINE__,__FILE__))
906
+				if (!$this->m_odb->query($sql, __LINE__, __FILE__))
907 907
 				{
908 908
 					$retval = 1;
909 909
 				}
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 			$debug_params = func_get_args();
919 919
 			array_shift($debug_params);
920 920
 			array_shift($debug_params);
921
-			call_user_func_array(array($this,'debug_message'),$debug_params);
921
+			call_user_func_array(array($this, 'debug_message'), $debug_params);
922 922
 			if ($retval < 2 && !$this->dict->debug)
923 923
 			{
924 924
 				echo '<p><b>'.$this->adodb->ErrorMsg()."</b></p>\n";
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 	 * @param $aColumnNames array of column-names or string with a single column-name
940 940
 	 * @return string the index-name
941 941
 	 */
942
-	function _index_name($sTableName,$aColumnNames)
942
+	function _index_name($sTableName, $aColumnNames)
943 943
 	{
944 944
 		// this code creates extrem short index-names, eg. for MaxDB
945 945
 //			if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32)
@@ -964,28 +964,28 @@  discard block
 block discarded – undo
964 964
 //				return $name;
965 965
 //			}
966 966
 		// This code creates longer index-names incl. the table-names and the used columns
967
-		$table = str_replace(array('phpgw_','egw_'),'',$sTableName);
967
+		$table = str_replace(array('phpgw_', 'egw_'), '', $sTableName);
968 968
 		// if the table-name or a part of it is repeated in the column-name, remove it there
969 969
 		$remove[] = $table.'_';
970 970
 		// also remove 3 or 4 letter shortcuts of the table- or app-name
971
-		$remove[] = substr($table,0,3).'_';
972
-		$remove[] = substr($table,0,4).'_';
971
+		$remove[] = substr($table, 0, 3).'_';
972
+		$remove[] = substr($table, 0, 4).'_';
973 973
 		// if the table-name consists of '_' limtied parts, remove occurences of these parts too
974
-		foreach (explode('_',$table) as $part)
974
+		foreach (explode('_', $table) as $part)
975 975
 		{
976 976
 			$remove[] = $part.'_';
977 977
 		}
978
-		$aColumnNames = str_replace($remove,'',$aColumnNames);
978
+		$aColumnNames = str_replace($remove, '', $aColumnNames);
979 979
 
980
-		$name = $sTableName.'_'.(is_array($aColumnNames) ? implode('_',$aColumnNames) : $aColumnNames);
980
+		$name = $sTableName.'_'.(is_array($aColumnNames) ? implode('_', $aColumnNames) : $aColumnNames);
981 981
 		// remove length limits from column names
982
-		$name = preg_replace('/ *\(\d+\)/','',$name);
982
+		$name = preg_replace('/ *\(\d+\)/', '', $name);
983 983
 
984 984
 		// this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle
985 985
 		if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 ||
986 986
 			strlen($name) >= 64)	// even mysql has a limit here ;-)
987 987
 		{
988
-			$name = "i".substr(md5($name),0,29);
988
+			$name = "i".substr(md5($name), 0, 29);
989 989
 		}
990 990
 		return $name;
991 991
 	}
@@ -1026,19 +1026,19 @@  discard block
 block discarded – undo
1026 1026
 	 * @param $param mixed a variable number of parameters, to be inserted in $msg
1027 1027
 	 *	arrays get serialized with print_r() !
1028 1028
 	 */
1029
-	function debug_message($msg,$backtrace=True)
1029
+	function debug_message($msg, $backtrace = True)
1030 1030
 	{
1031
-		for($i = 2; $i < func_num_args(); ++$i)
1031
+		for ($i = 2; $i < func_num_args(); ++$i)
1032 1032
 		{
1033 1033
 			$param = func_get_arg($i);
1034 1034
 
1035 1035
 			if (is_null($param))
1036 1036
 			{
1037
-				$param='NULL';
1037
+				$param = 'NULL';
1038 1038
 			}
1039 1039
 			else
1040 1040
 			{
1041
-				switch(gettype($param))
1041
+				switch (gettype($param))
1042 1042
 				{
1043 1043
 					case 'string':
1044 1044
 						$param = "'$param'";
@@ -1046,15 +1046,15 @@  discard block
 block discarded – undo
1046 1046
 					case 'array':
1047 1047
 					case 'object':
1048 1048
 						list(,$content) = @each($param);
1049
-						$do_pre = is_array($param) ? count($param) > 6 || is_array($content)&&count($content) : True;
1050
-						$param = ($do_pre ? '<pre>' : '').print_r($param,True).($do_pre ? '</pre>' : '');
1049
+						$do_pre = is_array($param) ? count($param) > 6 || is_array($content) && count($content) : True;
1050
+						$param = ($do_pre ? '<pre>' : '').print_r($param, True).($do_pre ? '</pre>' : '');
1051 1051
 						break;
1052 1052
 					case 'boolean':
1053 1053
 						$param = $param ? 'True' : 'False';
1054 1054
 						break;
1055 1055
 				}
1056 1056
 			}
1057
-			$msg = str_replace('%'.($i-1),$param,$msg);
1057
+			$msg = str_replace('%'.($i - 1), $param, $msg);
1058 1058
 		}
1059 1059
 		echo '<p>'.$msg."<br>\n".($backtrace ? 'Backtrace: '.function_backtrace(1)."</p>\n" : '');
1060 1060
 	}
@@ -1069,15 +1069,15 @@  discard block
 block discarded – undo
1069 1069
 	function _egw2adodb_columndef($aTableDef)
1070 1070
 	{
1071 1071
 		$ado_defs = array();
1072
-		foreach($aTableDef['fd'] as $col => $col_data)
1072
+		foreach ($aTableDef['fd'] as $col => $col_data)
1073 1073
 		{
1074 1074
 			$ado_col = False;
1075 1075
 
1076
-			switch($col_data['type'])
1076
+			switch ($col_data['type'])
1077 1077
 			{
1078 1078
 				case 'auto':
1079 1079
 					$ado_col = 'I AUTOINCREMENT NOTNULL';
1080
-					unset($col_data['nullable']);	// else we set it twice
1080
+					unset($col_data['nullable']); // else we set it twice
1081 1081
 					break;
1082 1082
 				case 'blob':
1083 1083
 					$ado_col = 'B';
@@ -1090,11 +1090,11 @@  discard block
 block discarded – undo
1090 1090
 				case 'ascii':
1091 1091
 				case 'varchar':
1092 1092
 					$ado_col = "C";
1093
-					if(0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length)
1093
+					if (0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length)
1094 1094
 					{
1095 1095
 						$ado_col .= "($col_data[precision])";
1096 1096
 					}
1097
-					if($col_data['precision'] > $this->max_varchar_length)
1097
+					if ($col_data['precision'] > $this->max_varchar_length)
1098 1098
 					{
1099 1099
 						$ado_col = 'X';
1100 1100
 					}
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
 				case 'date':
1107 1107
 					$ado_col = 'D';
1108 1108
 					// allow to use now() beside current_date, as Postgres backups contain it and it's easier to remember anyway
1109
-					if (in_array($col_data['default'],array('current_date','now()')))
1109
+					if (in_array($col_data['default'], array('current_date', 'now()')))
1110 1110
 					{
1111 1111
 						$ado_col .= ' DEFDATE';
1112 1112
 						unset($col_data['default']);
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
 					break;
1123 1123
 				case 'int':
1124 1124
 					$ado_col = 'I';
1125
-					switch($col_data['precision'])
1125
+					switch ($col_data['precision'])
1126 1126
 					{
1127 1127
 						case 1:
1128 1128
 						case 2:
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
 				case 'timestamp':
1142 1142
 					$ado_col = 'T';
1143 1143
 					// allow to use now() beside current_timestamp, as Postgres backups contain it and it's easier to remember anyway
1144
-					if (in_array($col_data['default'],array('current_timestamp','now()')))
1144
+					if (in_array($col_data['default'], array('current_timestamp', 'now()')))
1145 1145
 					{
1146 1146
 						$ado_col .= ' DEFTIMESTAMP';
1147 1147
 						unset($col_data['default']);
@@ -1159,17 +1159,17 @@  discard block
 block discarded – undo
1159 1159
 			}
1160 1160
 			if (isset($col_data['default']))
1161 1161
 			{
1162
-				$ado_col .= (in_array($col_data['type'],array('bool','int','decimal','float','double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : '').
1163
-					' DEFAULT '.$this->m_odb->quote($col_data['default'],$col_data['type']);
1162
+				$ado_col .= (in_array($col_data['type'], array('bool', 'int', 'decimal', 'float', 'double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : '').
1163
+					' DEFAULT '.$this->m_odb->quote($col_data['default'], $col_data['type']);
1164 1164
 			}
1165
-			if (in_array($col,$aTableDef['pk']))
1165
+			if (in_array($col, $aTableDef['pk']))
1166 1166
 			{
1167 1167
 				$ado_col .= ' PRIMARY';
1168 1168
 			}
1169
-			$ado_defs[] = $col . ' ' . $ado_col;
1169
+			$ado_defs[] = $col.' '.$ado_col;
1170 1170
 		}
1171 1171
 		//print_r($aTableDef); echo implode(",\n",$ado_defs)."\n";
1172
-		return implode(",\n",$ado_defs);
1172
+		return implode(",\n", $ado_defs);
1173 1173
 	}
1174 1174
 
1175 1175
 	/**
@@ -1184,7 +1184,7 @@  discard block
 block discarded – undo
1184 1184
 			'fd' => array('test' => array('type' => $egw_type)),
1185 1185
 			'pk' => array(),
1186 1186
 		));
1187
-		return preg_match('/test ([A-Z0-9]+)/i',$ado_col,$matches) ? $this->dict->ActualType($matches[1]) : false;
1187
+		return preg_match('/test ([A-Z0-9]+)/i', $ado_col, $matches) ? $this->dict->ActualType($matches[1]) : false;
1188 1188
 	}
1189 1189
 
1190 1190
 	/**
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 		// MetaType returns all varchar >= blobSize as blob, it's by default 100, which is wrong
1201 1201
 		$this->dict->blobSize = $this->max_varchar_length;
1202 1202
 
1203
-		if (!method_exists($this->dict,'MetaColumns') ||
1203
+		if (!method_exists($this->dict, 'MetaColumns') ||
1204 1204
 			!($columns = $this->dict->MetaColumns($sTableName)))
1205 1205
 		{
1206 1206
 			return False;
@@ -1213,11 +1213,11 @@  discard block
 block discarded – undo
1213 1213
 			'uc' => array(),
1214 1214
 		);
1215 1215
 		//echo "$sTableName: <pre>".print_r($columns,true)."</pre>";
1216
-		foreach($columns as $column)
1216
+		foreach ($columns as $column)
1217 1217
 		{
1218 1218
 			$name = $this->capabilities['name_case'] == 'upper' ? strtolower($column->name) : $column->name;
1219 1219
 
1220
-			$type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1220
+			$type = method_exists($this->dict, 'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1221 1221
 
1222 1222
 			// fix longtext not correctly handled by ADOdb
1223 1223
 			if ($type == 'X' && $column->type == 'longtext') $type = 'XL';
@@ -1239,11 +1239,11 @@  discard block
 block discarded – undo
1239 1239
 			);
1240 1240
 			$definition['fd'][$name]['type'] = $ado_type2egw[$type];
1241 1241
 
1242
-			switch($type)
1242
+			switch ($type)
1243 1243
 			{
1244 1244
 				case 'D': case 'T':
1245 1245
 					// detecting the automatic timestamps again
1246
-					if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i',$column->default_value))
1246
+					if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i', $column->default_value))
1247 1247
 					{
1248 1248
 						$column->default_value = $type == 'D' ? 'current_date' : 'current_timestamp';
1249 1249
 					}
@@ -1270,10 +1270,10 @@  discard block
 block discarded – undo
1270 1270
 					$column->auto_increment = true;
1271 1271
 					// fall-through
1272 1272
 				case 'I': case 'I1': case 'I2': case 'I4': case 'I8':
1273
-					switch($type)
1273
+					switch ($type)
1274 1274
 					{
1275 1275
 						case 'I1': case 'I2': case 'I4': case 'I8':
1276
-							$definition['fd'][$name]['precision'] = (int) $type[1];
1276
+							$definition['fd'][$name]['precision'] = (int)$type[1];
1277 1277
 							break;
1278 1278
 						default:
1279 1279
 							if ($column->max_length > 11)
@@ -1308,7 +1308,7 @@  discard block
 block discarded – undo
1308 1308
 					{
1309 1309
 						$definition['fd'][$name]['type'] = 'int';
1310 1310
 						// detect postgres type-spec and remove it
1311
-						if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/',$column->default_value,$matches))
1311
+						if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/', $column->default_value, $matches))
1312 1312
 						{
1313 1313
 							$definition['fd'][$name]['default'] = $matches[1];
1314 1314
 							$column->has_default = False;
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 			}
1327 1327
 			if ($column->has_default)
1328 1328
 			{
1329
-				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))	// postgres
1329
+				if (preg_match("/^'(.*)'::.*$/", $column->default_value, $matches))	// postgres
1330 1330
 				{
1331 1331
 					$column->default_value = $matches[1];
1332 1332
 				}
@@ -1336,27 +1336,27 @@  discard block
 block discarded – undo
1336 1336
 			{
1337 1337
 				$definition['fd'][$name]['nullable'] = False;
1338 1338
 			}
1339
-			if ($column->primary_key && !in_array($name,$definition['pk']))
1339
+			if ($column->primary_key && !in_array($name, $definition['pk']))
1340 1340
 			{
1341 1341
 				$definition['pk'][] = $name;
1342 1342
 			}
1343 1343
 		}
1344
-		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1344
+		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2", False, $sTableName, $columns);
1345 1345
 
1346 1346
 		// not all DB's (odbc) return the primary keys via MetaColumns
1347
-		if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') &&
1347
+		if (!count($definition['pk']) && method_exists($this->dict, 'MetaPrimaryKeys') &&
1348 1348
 			is_array($primary = $this->dict->MetaPrimaryKeys($sTableName)) && count($primary))
1349 1349
 		{
1350
-			if($this->capabilities['name_case'] == 'upper')
1350
+			if ($this->capabilities['name_case'] == 'upper')
1351 1351
 			{
1352
-				array_walk($primary,create_function('&$s','$s = strtolower($s);'));
1352
+				array_walk($primary, create_function('&$s', '$s = strtolower($s);'));
1353 1353
 			}
1354 1354
 			$definition['pk'] = $primary;
1355 1355
 		}
1356
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1356
+		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2", False, $sTableName, $primary);
1357 1357
 
1358 1358
 		$this->GetIndexes($sTableName, $definition);
1359
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1359
+		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2", False, $sTableName, $definition);
1360 1360
 
1361 1361
 		return $definition;
1362 1362
 	}
@@ -1368,27 +1368,27 @@  discard block
 block discarded – undo
1368 1368
 	 * @param array& $definition=array()
1369 1369
 	 * @return array of arrays with keys 'ix' and 'uc'
1370 1370
 	 */
1371
-	public function GetIndexes($sTableName, array &$definition=array())
1371
+	public function GetIndexes($sTableName, array &$definition = array())
1372 1372
 	{
1373
-		if (method_exists($this->dict,'MetaIndexes') &&
1373
+		if (method_exists($this->dict, 'MetaIndexes') &&
1374 1374
 			is_array($indexes = $this->dict->MetaIndexes($sTableName)) && count($indexes))
1375 1375
 		{
1376
-			foreach($indexes as $index)
1376
+			foreach ($indexes as $index)
1377 1377
 			{
1378
-				if($this->capabilities['name_case'] == 'upper')
1378
+				if ($this->capabilities['name_case'] == 'upper')
1379 1379
 				{
1380
-					array_walk($index['columns'],create_function('&$s','$s = strtolower($s);'));
1380
+					array_walk($index['columns'], create_function('&$s', '$s = strtolower($s);'));
1381 1381
 				}
1382
-				if (count($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) ||
1383
-					$index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk'])))
1382
+				if (count($definition['pk']) && (implode(':', $definition['pk']) == implode(':', $index['columns']) ||
1383
+					$index['unique'] && count(array_intersect($definition['pk'], $index['columns'])) == count($definition['pk'])))
1384 1384
 				{
1385
-					continue;	// is already the primary key => ignore it
1385
+					continue; // is already the primary key => ignore it
1386 1386
 				}
1387 1387
 				$kind = $index['unique'] ? 'uc' : 'ix';
1388 1388
 
1389 1389
 				$definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0];
1390 1390
 			}
1391
-			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1391
+			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2", False, $sTableName, $indexes);
1392 1392
 		}
1393 1393
 		return $definition;
1394 1394
 	}
@@ -1400,7 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 	 */
1401 1401
 	function CheckCreateIndexes()
1402 1402
 	{
1403
-		foreach($this->adodb->MetaTables('TABLES') as $table)
1403
+		foreach ($this->adodb->MetaTables('TABLES') as $table)
1404 1404
 		{
1405 1405
 			if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue;
1406 1406
 
@@ -1408,9 +1408,9 @@  discard block
 block discarded – undo
1408 1408
 			$this->GetIndexes($table, $definition);
1409 1409
 
1410 1410
 			// iterate though indexes we should have according to tables_current
1411
-			foreach(array('uc', 'ix') as $type)
1411
+			foreach (array('uc', 'ix') as $type)
1412 1412
 			{
1413
-				foreach($table_def[$type] as $columns)
1413
+				foreach ($table_def[$type] as $columns)
1414 1414
 				{
1415 1415
 					// sometimes primary key is listed as (unique) index too --> ignore it
1416 1416
 					if ($this->_in_index($columns, array($table_def['pk']), true)) continue;
@@ -1441,26 +1441,25 @@  discard block
 block discarded – undo
1441 1441
 	 * old translator function, use GetTableDefition() instead
1442 1442
 	 * @depricated
1443 1443
 	 */
1444
-	function _GetColumns($oProc,$sTableName,&$sColumns)
1444
+	function _GetColumns($oProc, $sTableName, &$sColumns)
1445 1445
 	{
1446 1446
 		$this->sCol = $this->pk = $this->fk = $this->ix = $this->uc = array();
1447 1447
 
1448 1448
 		$tabledef = $this->GetTableDefinition($sTableName);
1449 1449
 
1450
-		$sColumns = implode(',',array_keys($tabledef['fd']));
1450
+		$sColumns = implode(',', array_keys($tabledef['fd']));
1451 1451
 
1452
-		foreach($tabledef['fd'] as $column => $data)
1452
+		foreach ($tabledef['fd'] as $column => $data)
1453 1453
 		{
1454 1454
 			$col_def = "'type' => '$data[type]'";
1455 1455
 			unset($data['type']);
1456
-			foreach($data as $key => $val)
1456
+			foreach ($data as $key => $val)
1457 1457
 			{
1458
-				$col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') :
1459
-					(is_int($val) ? $val : "'$val'"));
1458
+				$col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : (is_int($val) ? $val : "'$val'"));
1460 1459
 			}
1461 1460
 			$this->sCol[] = "\t\t\t\t'$column' => array($col_def),\n";
1462 1461
 		}
1463
-		foreach(array('pk','fk','ix','uc') as $kind)
1462
+		foreach (array('pk', 'fk', 'ix', 'uc') as $kind)
1464 1463
 		{
1465 1464
 			$this->$kind = $tabledef[$kind];
1466 1465
 		}
Please login to merge, or discard this patch.
Braces   +149 added lines, -39 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	function __construct($dbms=False,$db=null)
99 99
 	{
100 100
 	    if(is_object($db))
101
-		{
101
+	    {
102 102
 			$this->m_odb = $db;
103 103
 	    }
104 104
 	    else
@@ -117,7 +117,10 @@  discard block
 block discarded – undo
117 117
 		$this->dict = NewDataDictionary($this->adodb);
118 118
 
119 119
 		// enable the debuging in ADOdb's datadictionary if the debug-level is greater then 1
120
-		if ($this->debug > 1) $this->dict->debug = True;
120
+		if ($this->debug > 1)
121
+		{
122
+			$this->dict->debug = True;
123
+		}
121 124
 
122 125
 		// to allow some of the former translator-functions to be called, we assign ourself as the translator
123 126
 		$this->m_oTranslator = &$this;
@@ -160,7 +163,10 @@  discard block
 block discarded – undo
160 163
 		{
161 164
 			unset($columns['options']);
162 165
 			$columns = implode('-',$columns);
163
-			if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns);
166
+			if ($ignore_length_limit)
167
+			{
168
+				$columns = preg_replace('/\(\d+\)/', '', $columns);
169
+			}
164 170
 		}
165 171
 		foreach($indexs as $index)
166 172
 		{
@@ -169,8 +175,14 @@  discard block
 block discarded – undo
169 175
 				unset($index['options']);
170 176
 				$index = implode('-',$index);
171 177
 			}
172
-			if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index);
173
-			if ($columns == $index) return true;
178
+			if ($ignore_length_limit)
179
+			{
180
+				$index = preg_replace('/\(\d+\)/', '', $index);
181
+			}
182
+			if ($columns == $index)
183
+			{
184
+				return true;
185
+			}
174 186
 		}
175 187
 		return false;
176 188
 	}
@@ -232,12 +244,20 @@  discard block
 block discarded – undo
232 244
 			$options = False;
233 245
 			if (is_array($mFields))
234 246
 			{
235
-				if (isset($mFields['options']))		// array sets additional options
247
+				if (isset($mFields['options']))
248
+				{
249
+					// array sets additional options
236 250
 				{
237 251
 					if (isset($mFields['options'][$this->sType]))
238 252
 					{
239
-						$options = $mFields['options'][$this->sType];	// db-specific options, eg. index-type
240
-						if (!$options) continue;	// no index for our db-type
253
+						$options = $mFields['options'][$this->sType];
254
+				}
255
+				// db-specific options, eg. index-type
256
+						if (!$options)
257
+						{
258
+							continue;
259
+						}
260
+						// no index for our db-type
241 261
 					}
242 262
 					unset($mFields['options']);
243 263
 				}
@@ -248,15 +268,22 @@  discard block
 block discarded – undo
248 268
 				// most DB's cant do them and give errors
249 269
 				if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext')))
250 270
 				{
251
-					if (is_array($mFields))	// index over multiple columns including a text column
271
+					if (is_array($mFields))
272
+					{
273
+						// index over multiple columns including a text column
252 274
 					{
253
-						$mFields[$k] .= '(32)';	// 32=limit of egw_addressbook_extra.extra_value to fix old backups
275
+						$mFields[$k] .= '(32)';
254 276
 					}
255
-					elseif (!$options)	// index over a single text column and no options given
277
+					// 32=limit of egw_addressbook_extra.extra_value to fix old backups
278
+					}
279
+					elseif (!$options)
280
+					{
281
+						// index over a single text column and no options given
256 282
 					{
257 283
 						if ($this->sType == 'mysql')
258 284
 						{
259 285
 							$options = 'FULLTEXT';
286
+					}
260 287
 						}
261 288
 						else
262 289
 						{
@@ -297,8 +324,14 @@  discard block
 block discarded – undo
297 324
 			return False;
298 325
 		}
299 326
 		// set our debug-mode or $bOutputHTML is the other one is set
300
-		if ($this->debug) $bOutputHTML = True;
301
-		if ($bOutputHTML && !$this->debug) $this->debug = 2;
327
+		if ($this->debug)
328
+		{
329
+			$bOutputHTML = True;
330
+		}
331
+		if ($bOutputHTML && !$this->debug)
332
+		{
333
+			$this->debug = 2;
334
+		}
302 335
 
303 336
 		foreach($aTables as $sTableName => $aTableDef)
304 337
 		{
@@ -325,7 +358,10 @@  discard block
 block discarded – undo
325 358
 	 */
326 359
 	function DropTable($sTableName)
327 360
 	{
328
-		if ($this->sType == 'pgsql') $this->_PostgresTestDropOldSequence($sTableName);
361
+		if ($this->sType == 'pgsql')
362
+		{
363
+			$this->_PostgresTestDropOldSequence($sTableName);
364
+		}
329 365
 
330 366
 		$aSql = $this->dict->DropTableSql($sTableName);
331 367
 
@@ -395,19 +431,28 @@  discard block
 block discarded – undo
395 431
 	 */
396 432
 	function _PostgresHasOldSequence($sTableName,$preserveValue=False)
397 433
 	{
398
-		if ($this->sType != 'pgsql') return false;
434
+		if ($this->sType != 'pgsql')
435
+		{
436
+			return false;
437
+		}
399 438
 
400 439
 		$seq = $this->adodb->GetOne("SELECT d.adsrc FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$sTableName' AND c.oid=d.adrelid AND d.adsrc LIKE '%seq_$sTableName''::text)' AND a.attrelid=c.oid AND d.adnum=a.attnum");
401 440
 		$seq2 = $this->adodb->GetOne("SELECT d.adsrc FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$sTableName' AND c.oid=d.adrelid AND d.adsrc LIKE '%$sTableName%_seq''::text)' AND a.attrelid=c.oid AND d.adnum=a.attnum");
402 441
 
403 442
 		if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches))
404 443
 		{
405
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
444
+			if ($preserveValue)
445
+			{
446
+				$this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
447
+			}
406 448
 			return $matches[1];
407 449
 		}
408 450
 		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches))
409 451
 		{
410
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
452
+			if ($preserveValue)
453
+			{
454
+				$this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
455
+			}
411 456
 			return $matches[1];
412 457
 		}
413 458
 		return false;
@@ -547,8 +592,14 @@  discard block
 block discarded – undo
547 592
 		{
548 593
 			$sIdxName = $this->_index_name($sTableName,$aColumnNames);
549 594
 		}
550
-		if (!is_array($options)) $options = $options ? array($options) : array();
551
-		if ($bUnique) $options[] = 'UNIQUE';
595
+		if (!is_array($options))
596
+		{
597
+			$options = $options ? array($options) : array();
598
+		}
599
+		if ($bUnique)
600
+		{
601
+			$options[] = 'UNIQUE';
602
+		}
552 603
 
553 604
 		$aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options);
554 605
 
@@ -617,7 +668,9 @@  discard block
 block discarded – undo
617 668
 					$seq_name = $matches[1];
618 669
 				}
619 670
 				$sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName";
620
-				if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
671
+				if($this->debug)
672
+				{
673
+echo "<br>Updating sequence '$seq_name using: $sql"; }
621 674
 				return $this->query($sql,__LINE__,__FILE__);
622 675
 		}
623 676
 		return True;
@@ -637,7 +690,9 @@  discard block
 block discarded – undo
637 690
 	 */
638 691
 	function RefreshTable($sTableName, $aTableDef, $aDefaults=False)
639 692
 	{
640
-		if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")<p>$sTableName="._debug_array($old_table_def,False)."\n"; }
693
+		if($this->debug)
694
+		{
695
+echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")<p>$sTableName="._debug_array($old_table_def,False)."\n"; }
641 696
 
642 697
 		$old_table_def = $this->GetTableDefinition($sTableName);
643 698
 
@@ -664,21 +719,30 @@  discard block
 block discarded – undo
664 719
 						$value = "nextval('$sequence_name')"; break;
665 720
 				}
666 721
 			}
667
-			elseif ($aDefaults && isset($aDefaults[$name]))	// use given default
722
+			elseif ($aDefaults && isset($aDefaults[$name]))
723
+			{
724
+				// use given default
668 725
 			{
669 726
 				$value = $aDefaults[$name];
670 727
 			}
671
-			elseif (isset($old_table_def['fd'][$name]))	// existing column, use its value => column-name in query
728
+			}
729
+			elseif (isset($old_table_def['fd'][$name]))
730
+			{
731
+				// existing column, use its value => column-name in query
672 732
 			{
673 733
 				$value = $name;
734
+			}
674 735
 
675
-				if ($this->sType == 'pgsql')			// some postgres specific code
736
+				if ($this->sType == 'pgsql')
737
+				{
738
+					// some postgres specific code
676 739
 				{
677 740
 					// this is eg. necessary to change a varchar into an int column under postgres
678 741
 					if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) &&
679 742
 						in_array($data['type'],array('int','decimal')))
680 743
 					{
681 744
 						$value = "to_number($name,'S9999999999999D99')";
745
+				}
682 746
 					}
683 747
 					// blobs cant be casted to text
684 748
 					elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
@@ -734,8 +798,15 @@  discard block
 block discarded – undo
734 798
 		switch($this->sType)
735 799
 		{
736 800
 			case 'mssql':
737
-				if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n";
738
-				if ($blob_column_included) $distinct = '';	// no distinct on blob-columns
801
+				if ($auto_column_included)
802
+				{
803
+					$extra = "SET IDENTITY_INSERT $sTableName ON\n";
804
+				}
805
+				if ($blob_column_included)
806
+				{
807
+					$distinct = '';
808
+				}
809
+				// no distinct on blob-columns
739 810
 				break;
740 811
 		}
741 812
 		// because of all the trouble with sequences and indexes in the global namespace,
@@ -799,8 +870,14 @@  discard block
 block discarded – undo
799 870
 			return False;
800 871
 		}
801 872
 		// set our debug-mode or $bOutputHTML is the other one is set
802
-		if ($this->debug) $bOutputHTML = True;
803
-		if ($bOutputHTML && !$this->debug) $this->debug = 2;
873
+		if ($this->debug)
874
+		{
875
+			$bOutputHTML = True;
876
+		}
877
+		if ($bOutputHTML && !$this->debug)
878
+		{
879
+			$this->debug = 2;
880
+		}
804 881
 
805 882
 		foreach($aTables as $sTableName => $aTableDef)
806 883
 		{
@@ -898,9 +975,12 @@  discard block
 block discarded – undo
898 975
 	 */
899 976
 	function ExecuteSqlArray($aSql,$debug_level,$debug)
900 977
 	{
901
-		if ($this->m_odb->query_log)	// we use egw_db::query to log the queries
978
+		if ($this->m_odb->query_log)
979
+		{
980
+			// we use egw_db::query to log the queries
902 981
 		{
903 982
 			$retval = 2;
983
+		}
904 984
 			foreach($aSql as $sql)
905 985
 			{
906 986
 				if (!$this->m_odb->query($sql,__LINE__,__FILE__))
@@ -983,10 +1063,13 @@  discard block
 block discarded – undo
983 1063
 
984 1064
 		// this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle
985 1065
 		if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 ||
986
-			strlen($name) >= 64)	// even mysql has a limit here ;-)
1066
+			strlen($name) >= 64)
1067
+		{
1068
+			// even mysql has a limit here ;-)
987 1069
 		{
988 1070
 			$name = "i".substr(md5($name),0,29);
989 1071
 		}
1072
+		}
990 1073
 		return $name;
991 1074
 	}
992 1075
 
@@ -1220,7 +1303,10 @@  discard block
 block discarded – undo
1220 1303
 			$type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1221 1304
 
1222 1305
 			// fix longtext not correctly handled by ADOdb
1223
-			if ($type == 'X' && $column->type == 'longtext') $type = 'XL';
1306
+			if ($type == 'X' && $column->type == 'longtext')
1307
+			{
1308
+				$type = 'XL';
1309
+			}
1224 1310
 
1225 1311
 			static $ado_type2egw = array(
1226 1312
 				'C'		=> 'varchar',
@@ -1326,10 +1412,13 @@  discard block
 block discarded – undo
1326 1412
 			}
1327 1413
 			if ($column->has_default)
1328 1414
 			{
1329
-				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))	// postgres
1415
+				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))
1416
+				{
1417
+					// postgres
1330 1418
 				{
1331 1419
 					$column->default_value = $matches[1];
1332 1420
 				}
1421
+				}
1333 1422
 				$definition['fd'][$name]['default'] = $column->default_value;
1334 1423
 			}
1335 1424
 			if ($column->not_null)
@@ -1341,7 +1430,10 @@  discard block
 block discarded – undo
1341 1430
 				$definition['pk'][] = $name;
1342 1431
 			}
1343 1432
 		}
1344
-		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1433
+		if ($this->debug > 2)
1434
+		{
1435
+			$this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1436
+		}
1345 1437
 
1346 1438
 		// not all DB's (odbc) return the primary keys via MetaColumns
1347 1439
 		if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') &&
@@ -1353,10 +1445,16 @@  discard block
 block discarded – undo
1353 1445
 			}
1354 1446
 			$definition['pk'] = $primary;
1355 1447
 		}
1356
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1448
+		if ($this->debug > 1)
1449
+		{
1450
+			$this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1451
+		}
1357 1452
 
1358 1453
 		$this->GetIndexes($sTableName, $definition);
1359
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1454
+		if ($this->debug > 1)
1455
+		{
1456
+			$this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1457
+		}
1360 1458
 
1361 1459
 		return $definition;
1362 1460
 	}
@@ -1388,7 +1486,10 @@  discard block
 block discarded – undo
1388 1486
 
1389 1487
 				$definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0];
1390 1488
 			}
1391
-			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1489
+			if ($this->debug > 2)
1490
+			{
1491
+				$this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1492
+			}
1392 1493
 		}
1393 1494
 		return $definition;
1394 1495
 	}
@@ -1402,7 +1503,10 @@  discard block
 block discarded – undo
1402 1503
 	{
1403 1504
 		foreach($this->adodb->MetaTables('TABLES') as $table)
1404 1505
 		{
1405
-			if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue;
1506
+			if (!($table_def = $this->m_odb->get_table_definitions(true, $table)))
1507
+			{
1508
+				continue;
1509
+			}
1406 1510
 
1407 1511
 			$definition = array();
1408 1512
 			$this->GetIndexes($table, $definition);
@@ -1413,7 +1517,10 @@  discard block
 block discarded – undo
1413 1517
 				foreach($table_def[$type] as $columns)
1414 1518
 				{
1415 1519
 					// sometimes primary key is listed as (unique) index too --> ignore it
1416
-					if ($this->_in_index($columns, array($table_def['pk']), true)) continue;
1520
+					if ($this->_in_index($columns, array($table_def['pk']), true))
1521
+					{
1522
+						continue;
1523
+					}
1417 1524
 
1418 1525
 					// check if they exist in real table and create them if not
1419 1526
 					if (!$this->_in_index($columns, $definition[$type]) &&
@@ -1424,7 +1531,10 @@  discard block
 block discarded – undo
1424 1531
 						if ($this->_in_index($columns, $definition[$type], true))
1425 1532
 						{
1426 1533
 							// for PostgreSQL we dont use length-limited indexes --> nothing to do
1427
-							if ($this->m_odb->Type == 'pgsql') continue;
1534
+							if ($this->m_odb->Type == 'pgsql')
1535
+							{
1536
+								continue;
1537
+							}
1428 1538
 							// for MySQL we drop current index and create it with correct length
1429 1539
 							$this->DropIndex($table, $columns);
1430 1540
 						}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -797,7 +797,7 @@
 block discarded – undo
797 797
 	 */
798 798
 	function ExecuteScripts($aTables, $bOutputHTML=False)
799 799
 	{
800
-		if(!is_array($aTables) || !IsSet($this->m_odb))
800
+		if(!is_array($aTables) || !isset($this->m_odb))
801 801
 		{
802 802
 			return False;
803 803
 		}
Please login to merge, or discard this patch.
phpgwapi/inc/class.solink.inc.php 5 patches
Doc Comments   +7 added lines, -2 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @param int $link_id link to update
96 96
 	 * @param string $remark new text for the remark
97
-	 * @return boolean true on success, else false
97
+	 * @return ADORecordSet true on success, else false
98 98
 	 */
99 99
 	static function update_remark($link_id,$remark)
100 100
 	{
@@ -172,6 +172,11 @@  discard block
 block discarded – undo
172 172
 		return is_array($id) ? $links : ($links[$id] ? $links[$id] : array());
173 173
 	}
174 174
 
175
+	/**
176
+	 * @param boolean $left
177
+	 * @param string $only_app
178
+	 * @param boolean $not_only
179
+	 */
175 180
 	private function _add2links($row,$left,$only_app,$not_only,array &$links)
176 181
 	{
177 182
 		$linked_app = $left ? $row['link_app2'] : $row['link_app1'];
@@ -202,7 +207,7 @@  discard block
 block discarded – undo
202 207
 	 * @param string $id ='' id in $app, if no integer link_id given in $app_link_id
203 208
 	 * @param string $app2 ='' appname of 2. endpoint of the link, if no integer link_id given in $app_link_id
204 209
 	 * @param string $id2 ='' id in $app2, if no integer link_id given in $app_link_id
205
-	 * @return array with link-data or False
210
+	 * @return boolean with link-data or False
206 211
 	 */
207 212
 	static function get_link($app_link_id,$id='',$app2='',$id2='')
208 213
 	{
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 			echo "<p>solink.link('$app1',$id1,'$app2',$id2,'$remark',$owner)</p>\n";
67 67
 		}
68 68
 		if ($app1 == $app2 && $id1 == $id2 ||
69
-		    $id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
69
+			$id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
70 70
 		{
71 71
 			return False;	// dont link to self or other nosense
72 72
 		}
@@ -412,26 +412,26 @@  discard block
 block discarded – undo
412 412
 			array('table'=>self::TABLE,
413 413
 				'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3',
414 414
 				'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app).
415
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
416
-                        	'join'=>" a
415
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
416
+							'join'=>" a
417 417
                         		JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1
418 418
                        			JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2",
419 419
 			),
420 420
 			// retrieve the type of links, where the relation is realized as timesheet->infolog/tracker and projectmanager->timesheet
421 421
 			array('table'=>self::TABLE,
422 422
 				'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,b.deleted,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
423
-                       		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
425
-                        	'join'=>" a
423
+					   		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
425
+							'join'=>" a
426 426
                         		JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
427 427
                         		JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1",
428 428
 			),
429 429
 			// retrieve the type of links, where the relation is realized as timesheet->projectmanager and infolog->timesheet
430 430
 			array('table'=>self::TABLE,
431 431
 				'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
432
-                     		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
434
-                       		'join'=>" a
432
+					 		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
434
+					   		'join'=>" a
435 435
                        			JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
436 436
                         		JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1",
437 437
 			),
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 * @param int $lastmod =0 timestamp of last modification (defaults to now=time())
56 56
 	 * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1)
57 57
 	 */
58
-	static function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0 )
58
+	static function link($app1, &$id1, $app2, $id2 = '', $remark = '', $owner = 0, $lastmod = 0)
59 59
 	{
60 60
 		if (self::DEBUG)
61 61
 		{
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
 		if ($app1 == $app2 && $id1 == $id2 ||
65 65
 		    $id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
66 66
 		{
67
-			return False;	// dont link to self or other nosense
67
+			return False; // dont link to self or other nosense
68 68
 		}
69
-		if (($link = self::get_link($app1,$id1,$app2,$id2)))
69
+		if (($link = self::get_link($app1, $id1, $app2, $id2)))
70 70
 		{
71 71
 			if ($link['link_remark'] != $remark)
72 72
 			{
73
-				self::update_remark($link['link_id'],$remark);
73
+				self::update_remark($link['link_id'], $remark);
74 74
 			}
75
-			return $link['link_id'];	// link alread exist
75
+			return $link['link_id']; // link alread exist
76 76
 		}
77 77
 		if (!$owner)
78 78
 		{
79 79
 			$owner = $GLOBALS['egw_info']['user']['account_id'];
80 80
 		}
81
-		return self::$db->insert(self::TABLE,array(
81
+		return self::$db->insert(self::TABLE, array(
82 82
 				'link_app1'		=> $app1,
83 83
 				'link_id1'		=> $id1,
84 84
 				'link_app2'		=> $app2,
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 				'link_remark'	=> $remark,
87 87
 				'link_lastmod'	=> $lastmod ? $lastmod : time(),
88 88
 				'link_owner'	=> $owner,
89
-			),False,__LINE__,__FILE__) ? self::$db->get_last_insert_id(self::TABLE,'link_id') : false;
89
+			), False, __LINE__, __FILE__) ? self::$db->get_last_insert_id(self::TABLE, 'link_id') : false;
90 90
 	}
91 91
 
92 92
 	/**
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
 	 * @param string $remark new text for the remark
97 97
 	 * @return boolean true on success, else false
98 98
 	 */
99
-	static function update_remark($link_id,$remark)
99
+	static function update_remark($link_id, $remark)
100 100
 	{
101
-		return self::$db->update(self::TABLE,array(
101
+		return self::$db->update(self::TABLE, array(
102 102
 				'link_remark'	=> $remark,
103 103
 				'link_lastmod'	=> time(),
104
-			),array(
104
+			), array(
105 105
 				'link_id'	=> $link_id,
106
-			),__LINE__,__FILE__);
106
+			), __LINE__, __FILE__);
107 107
 	}
108 108
 
109 109
 	/**
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
 	 * @param int|array $limit =null number of entries to return, default null = all or array(offset, num_rows) to return num_rows starting from offset
118 118
 	 * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found
119 119
 	 */
120
-	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC', $deleted=false, $limit=null)
120
+	static function get_links($app, $id, $only_app = '', $order = 'link_lastmod DESC', $deleted = false, $limit = null)
121 121
 	{
122 122
 		if (self::DEBUG)
123 123
 		{
124
-			echo "<p>solink.get_links($app,".print_r($id,true).",$only_app,$order,$deleted)</p>\n";
124
+			echo "<p>solink.get_links($app,".print_r($id, true).",$only_app,$order,$deleted)</p>\n";
125 125
 		}
126 126
 		if (($not_only = $only_app[0] == '!'))
127 127
 		{
128
-			$only_app = substr($only_app,1);
128
+			$only_app = substr($only_app, 1);
129 129
 		}
130 130
 
131 131
 		$offset = false;
@@ -133,32 +133,32 @@  discard block
 block discarded – undo
133 133
 		{
134 134
 			list($offset, $limit) = $limit;
135 135
 		}
136
-		elseif($limit)
136
+		elseif ($limit)
137 137
 		{
138 138
 			$offset = 0;
139 139
 		}
140 140
 
141 141
 		$links = array();
142 142
 		try {
143
-			foreach(self::$db->select(self::TABLE, '*', self::$db->expression(self::TABLE, '((', array(
143
+			foreach (self::$db->select(self::TABLE, '*', self::$db->expression(self::TABLE, '((', array(
144 144
 						'link_app1'	=> $app,
145 145
 						'link_id1'	=> $id,
146
-					),') OR (',array(
146
+					), ') OR (', array(
147 147
 						'link_app2'	=> $app,
148 148
 						'link_id2'	=> $id,
149
-					),'))',
149
+					), '))',
150 150
 					$deleted ? '' : ' AND deleted IS NULL'
151 151
 				), __LINE__, __FILE__, $offset, $order ? " ORDER BY $order" : '', 'phpgwapi', $limit) as $row)
152 152
 			{
153 153
 				// check if left side (1) is one of our targets --> add it
154
-				if ($row['link_app1'] == $app && in_array($row['link_id1'],(array)$id))
154
+				if ($row['link_app1'] == $app && in_array($row['link_id1'], (array)$id))
155 155
 				{
156
-					self::_add2links($row,true,$only_app,$not_only,$links);
156
+					self::_add2links($row, true, $only_app, $not_only, $links);
157 157
 				}
158 158
 				// check if right side (2) is one of our targets --> add it (both can be true for multiple targets!)
159
-				if ($row['link_app2'] == $app && in_array($row['link_id2'],(array)$id))
159
+				if ($row['link_app2'] == $app && in_array($row['link_id2'], (array)$id))
160 160
 				{
161
-					self::_add2links($row,false,$only_app,$not_only,$links);
161
+					self::_add2links($row, false, $only_app, $not_only, $links);
162 162
 				}
163 163
 			}
164 164
 			// if query returns exactly limit rows, we assume there are more and therefore set self::$limit_exceeded
@@ -166,18 +166,18 @@  discard block
 block discarded – undo
166 166
 		}
167 167
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
168 168
 		// caused by non-ascii chars compared with ascii field uid
169
-		catch(egw_exception_db $e) {
169
+		catch (egw_exception_db $e) {
170 170
 			_egw_log_exception($e);
171 171
 		}
172 172
 		return is_array($id) ? $links : ($links[$id] ? $links[$id] : array());
173 173
 	}
174 174
 
175
-	private function _add2links($row,$left,$only_app,$not_only,array &$links)
175
+	private function _add2links($row, $left, $only_app, $not_only, array &$links)
176 176
 	{
177 177
 		$linked_app = $left ? $row['link_app2'] : $row['link_app1'];
178 178
 		$linked_id  = $left ? $row['link_id2'] : $row['link_id1'];
179 179
 		$app_id = $left ? $row['link_id1'] : $row['link_id2'];
180
-		list($app) = explode('-',$linked_app);
180
+		list($app) = explode('-', $linked_app);
181 181
 		if ($only_app && $not_only == ($linked_app == $only_app) || !$GLOBALS['egw_info']['user']['apps'][$app])
182 182
 		{
183 183
 			#echo "$linked_app == $only_app, ";var_dump($linked_app == $only_app);echo "	->dont return a link<br>";
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
 	 * @param string $id2 ='' id in $app2, if no integer link_id given in $app_link_id
205 205
 	 * @return array with link-data or False
206 206
 	 */
207
-	static function get_link($app_link_id,$id='',$app2='',$id2='')
207
+	static function get_link($app_link_id, $id = '', $app2 = '', $id2 = '')
208 208
 	{
209 209
 		if (self::DEBUG)
210 210
 		{
211 211
 			echo "<p>solink.get_link('$app_link_id',$id,'$app2','$id2')</p>\n";
212 212
 		}
213
-		if ((int) $app_link_id > 0)
213
+		if ((int)$app_link_id > 0)
214 214
 		{
215 215
 			$where = array('link_id' => $app_link_id);
216 216
 		}
@@ -220,24 +220,24 @@  discard block
 block discarded – undo
220 220
 			{
221 221
 				return False;
222 222
 			}
223
-			$where = self::$db->expression(self::TABLE,'(',array(
223
+			$where = self::$db->expression(self::TABLE, '(', array(
224 224
 					'link_app1'	=> $app_link_id,
225 225
 					'link_id1'	=> $id,
226 226
 					'link_app2'	=> $app2,
227 227
 					'link_id2'	=> $id2,
228
-				),') OR (',array(
228
+				), ') OR (', array(
229 229
 					'link_app2'	=> $app_link_id,
230 230
 					'link_id2'	=> $id,
231 231
 					'link_app1'	=> $app2,
232 232
 					'link_id1'	=> $id2,
233
-				),')');
233
+				), ')');
234 234
 		}
235 235
 		try {
236
-			return self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__)->fetch(ADODB_FETCH_ASSOC);
236
+			return self::$db->select(self::TABLE, '*', $where, __LINE__, __FILE__)->fetch(ADODB_FETCH_ASSOC);
237 237
 		}
238 238
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
239 239
 		// caused by non-ascii chars compared with ascii field uid
240
-		catch(egw_exception_db $e) {
240
+		catch (egw_exception_db $e) {
241 241
 			_egw_log_exception($e);
242 242
 		}
243 243
 		return false;
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete of linked entry
256 256
 	 * @return array with deleted links
257 257
 	 */
258
-	static function unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='',$hold_for_purge=false)
258
+	static function unlink($link_id, $app = '', $id = '', $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
259 259
 	{
260 260
 		if (self::DEBUG)
261 261
 		{
@@ -280,21 +280,21 @@  discard block
 block discarded – undo
280 280
 					$check1['link_id1'] = $id;
281 281
 					$check2['link_id2'] = $id;
282 282
 				}
283
-				$where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))');
283
+				$where = self::$db->expression(self::TABLE, '((', $check1, ') OR (', $check2, '))');
284 284
 			}
285 285
 			elseif ($app != '' && $app2 != '')
286 286
 			{
287
-				$where = self::$db->expression(self::TABLE,'(',array(
287
+				$where = self::$db->expression(self::TABLE, '(', array(
288 288
 						'link_app1'	=> $app,
289 289
 						'link_id1'	=> $id,
290 290
 						'link_app2'	=> $app2,
291 291
 						'link_id2'	=> $id2,
292
-					),') OR (',array(
292
+					), ') OR (', array(
293 293
 						'link_app1'	=> $app2,
294 294
 						'link_id1'	=> $id2,
295 295
 						'link_app2'	=> $app,
296 296
 						'link_id2'	=> $id,
297
-					),')');
297
+					), ')');
298 298
 			}
299 299
 			if ($owner)
300 300
 			{
@@ -304,25 +304,25 @@  discard block
 block discarded – undo
304 304
 		}
305 305
 		$deleted = array();
306 306
 		try {
307
-			foreach(self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__) as $row)
307
+			foreach (self::$db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row)
308 308
 			{
309 309
 				$deleted[] = $row;
310 310
 			}
311
-			if($hold_for_purge)
311
+			if ($hold_for_purge)
312 312
 			{
313
-				self::$db->update(self::TABLE,array(
313
+				self::$db->update(self::TABLE, array(
314 314
 					'deleted' => time(),
315 315
 					'link_lastmod' => time(),
316
-				), $where, __LINE__,__FILE__);
316
+				), $where, __LINE__, __FILE__);
317 317
 			}
318 318
 			else
319 319
 			{
320
-				self::$db->delete(self::TABLE,$where,__LINE__,__FILE__);
320
+				self::$db->delete(self::TABLE, $where, __LINE__, __FILE__);
321 321
 			}
322 322
 		}
323 323
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
324 324
 		// caused by non-ascii chars compared with ascii field uid
325
-		catch(egw_exception_db $e) {
325
+		catch (egw_exception_db $e) {
326 326
 			_egw_log_exception($e);
327 327
 		}
328 328
 
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 			$check1['link_id1'] = $id;
354 354
 			$check2['link_id2'] = $id;
355 355
 		}
356
-		$where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))');
357
-		self::$db->update(self::TABLE,array('deleted'=> null), $where, __LINE__,__FILE__);
356
+		$where = self::$db->expression(self::TABLE, '((', $check1, ') OR (', $check2, '))');
357
+		self::$db->update(self::TABLE, array('deleted'=> null), $where, __LINE__, __FILE__);
358 358
 	}
359 359
 
360 360
 	/**
@@ -367,13 +367,13 @@  discard block
 block discarded – undo
367 367
 	 * @param int $new_owner account_id of new owner
368 368
 	 * @return int number of links changed
369 369
 	 */
370
-	static function chown($owner,$new_owner)
370
+	static function chown($owner, $new_owner)
371 371
 	{
372
-		if ((int)$owner <= 0 || (int) $new_owner <= 0)
372
+		if ((int)$owner <= 0 || (int)$new_owner <= 0)
373 373
 		{
374 374
 			return 0;
375 375
 		}
376
-		self::$db->update(self::TABLE,array('owner'=>$new_owner),array('owner'=>$owner),__LINE__,__FILE__);
376
+		self::$db->update(self::TABLE, array('owner'=>$new_owner), array('owner'=>$owner), __LINE__, __FILE__);
377 377
 
378 378
 		return self::$db->affected_rows();
379 379
 	}
@@ -400,15 +400,15 @@  discard block
 block discarded – undo
400 400
 	 * @param int|array $limit =null number of entries to return, default null = all or array(offset, num_rows) to return num_rows starting from offset
401 401
 	 * @return array with links from entries from $app to $target_app/$target_id plus the other (b) link_id/app/id in the keys 'link3'/'app3'/'id3'
402 402
 	 */
403
-	static function get_3links($app, $target_app, $target_id=null, $just_app_ids=false, $order='link_lastmod DESC', $limit=null)
403
+	static function get_3links($app, $target_app, $target_id = null, $just_app_ids = false, $order = 'link_lastmod DESC', $limit = null)
404 404
 	{
405 405
 		$table = self::TABLE;
406
-		$arrayofselects=array(
406
+		$arrayofselects = array(
407 407
 			// retrieve the type of links, where the relation is realized as timesheet->infolog/tracker via infolog->projectmanager to timesheet->projectmanager
408 408
 			array('table'=>self::TABLE,
409 409
 				'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3',
410 410
 				'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app).
411
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
411
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND c.', array('link_id2' => $target_id))),
412 412
                         	'join'=>" a
413 413
                         		JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1
414 414
                        			JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2",
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 			array('table'=>self::TABLE,
418 418
 				'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,b.deleted,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
419 419
                        		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
420
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
420
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND b.', array('link_id1' => $target_id))),
421 421
                         	'join'=>" a
422 422
                         		JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
423 423
                         		JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1",
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 			array('table'=>self::TABLE,
427 427
 				'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
428 428
                      		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
429
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
429
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND a.', array('link_id2' => $target_id))),
430 430
                        		'join'=>" a
431 431
                        			JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
432 432
                         		JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1",
@@ -438,17 +438,17 @@  discard block
 block discarded – undo
438 438
 		{
439 439
 			list($offset, $limit) = $limit;
440 440
 		}
441
-		elseif($limit)
441
+		elseif ($limit)
442 442
 		{
443 443
 			$offset = 0;
444 444
 		}
445 445
 
446 446
 		$links = array();
447
-		foreach(self::$db->union($arrayofselects, __LINE__, __FILE__, $order, $offset, $limit) as $row)
447
+		foreach (self::$db->union($arrayofselects, __LINE__, __FILE__, $order, $offset, $limit) as $row)
448 448
 		{
449 449
 			if ($just_app_ids)
450 450
 			{
451
-				if ($row['link_app1'] == $target_app && (is_null($target_id) || in_array($row['link_id1'],(array)$target_id)))
451
+				if ($row['link_app1'] == $target_app && (is_null($target_id) || in_array($row['link_id1'], (array)$target_id)))
452 452
 				{
453 453
 					$links[$row['link_id']] = $row['link_id2'];
454 454
 				}
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 			}
460 460
 			else
461 461
 			{
462
-				$links[] = egw_db::strip_array_keys($row,'link_');
462
+				$links[] = egw_db::strip_array_keys($row, 'link_');
463 463
 			}
464 464
 		}
465 465
 		// if query returns exactly limit rows, we assume there are more and therefore set self::$limit_exceeded
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	 */
474 474
 	static function init_static( )
475 475
 	{
476
-		self::$db     = $GLOBALS['egw']->db;
476
+		self::$db = $GLOBALS['egw']->db;
477 477
 	}
478 478
 }
479 479
 solink::init_static();
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -302,7 +302,10 @@
 block discarded – undo
302 302
 			}
303 303
 			if ($owner)
304 304
 			{
305
-				if ($app) $where = array($where);
305
+				if ($app)
306
+				{
307
+					$where = array($where);
308
+				}
306 309
 				$where['link_owner'] = $owner;
307 310
 			}
308 311
 		}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -269,7 +269,7 @@
 block discarded – undo
269 269
 		{
270 270
 			$where = array('link_id' => $link_id);
271 271
 		}
272
-		elseif ($app == '' AND $owner == '')
272
+		elseif ($app == '' and $owner == '')
273 273
 		{
274 274
 			return 0;
275 275
 		}
Please login to merge, or discard this patch.
phpgwapi/inc/class.Template.inc.php 3 patches
Doc Comments   +32 added lines patch added patch discarded remove patch
@@ -64,6 +64,10 @@  discard block
 block discarded – undo
64 64
 		/* public: setroot(pathname $root)
65 65
 		 * root:   new template directory.
66 66
 		 */
67
+
68
+		/**
69
+		 * @param string $root
70
+		 */
67 71
 		function set_root($root)
68 72
 		{
69 73
 			if ($this->debug && $this->check_debug('set_root'))
@@ -127,6 +131,11 @@  discard block
 block discarded – undo
127 131
 		 * extract the template $handle from $parent,
128 132
 		 * place variable {$name} instead.
129 133
 		 */
134
+
135
+		/**
136
+		 * @param string $parent
137
+		 * @param string $handle
138
+		 */
130 139
 		function set_block($parent, $handle, $name = '')
131 140
 		{
132 141
 			if ($this->debug && $this->check_debug('set_block',$parent,$handle,$name))
@@ -253,6 +262,10 @@  discard block
 block discarded – undo
253 262
 			return $str;
254 263
 		}
255 264
 
265
+		/**
266
+		 * @param string $target
267
+		 * @param string $handle
268
+		 */
256 269
 		function pparse($target, $handle, $append = false)
257 270
 		{
258 271
 			print $this->parse($target, $handle, $append);
@@ -260,12 +273,24 @@  discard block
 block discarded – undo
260 273
 		}
261 274
 
262 275
 		/* This is short for finish parse */
276
+
277
+		/**
278
+		 * @param string $target
279
+		 * @param string $handle
280
+		 *
281
+		 * @return string
282
+		 */
263 283
 		function fp($target, $handle, $append = False)
264 284
 		{
265 285
 			return $this->finish($this->parse($target, $handle, $append));
266 286
 		}
267 287
 
268 288
 		/* This is a short cut for print finish parse */
289
+
290
+		/**
291
+		 * @param string $target
292
+		 * @param string $handle
293
+		 */
269 294
 		function pfp($target, $handle, $append = False)
270 295
 		{
271 296
 			echo $this->finish($this->parse($target, $handle, $append));
@@ -307,6 +332,10 @@  discard block
 block discarded – undo
307 332
 		/* public: get_undefined($handle)
308 333
 		 * handle: handle of a template.
309 334
 		 */
335
+
336
+		/**
337
+		 * @param string $handle
338
+		 */
310 339
 		function get_undefined($handle)
311 340
 		{
312 341
 			if (!$this->loadfile($handle))
@@ -476,6 +505,9 @@  discard block
 block discarded – undo
476 505
 			}
477 506
 		}
478 507
 
508
+		/**
509
+		 * @param string $str
510
+		 */
479 511
 		function check_debug($str)
480 512
 		{
481 513
 			if (!$this->debug) return False;
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 		 *	- function-name like set_var to get eg. all assignments or
24 24
 		 *	- handle- / variable-names - if you are only interested in some variables ;-)
25 25
 		 */
26
-		var $debug = False;	// array('cat_list','cat_list_t');
26
+		var $debug = False; // array('cat_list','cat_list_t');
27 27
 
28 28
 		/* $file[handle] = 'filename'; */
29 29
 		var $file = array();
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 		 */
102 102
 		function set_file($handle, $filename = '')
103 103
 		{
104
-			if ($this->debug && $this->check_debug('set_file',$handle,$filename))
104
+			if ($this->debug && $this->check_debug('set_file', $handle, $filename))
105 105
 			{
106
-				echo "<p>Template::set_file('".print_r($handle,true)."','$filename')</p>\n";
106
+				echo "<p>Template::set_file('".print_r($handle, true)."','$filename')</p>\n";
107 107
 			}
108 108
 			if (!is_array($handle))
109 109
 			{
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 			}
117 117
 			else
118 118
 			{
119
-				foreach($handle as $h => $f)
119
+				foreach ($handle as $h => $f)
120 120
 				{
121 121
 					$this->file[$h] = $this->filename($f);
122 122
 				}
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		 */
130 130
 		function set_block($parent, $handle, $name = '')
131 131
 		{
132
-			if ($this->debug && $this->check_debug('set_block',$parent,$handle,$name))
132
+			if ($this->debug && $this->check_debug('set_block', $parent, $handle, $name))
133 133
 			{
134 134
 				echo "<p>Template::set_block('$parent','$handle','$name')</p>\n";
135 135
 			}
@@ -145,14 +145,14 @@  discard block
 block discarded – undo
145 145
 			$str = $this->get_var($parent);
146 146
 			$qhandle = preg_quote($handle);
147 147
 			$reg = "/<!--\\s+BEGIN $qhandle\\s+-->(.*)\n\\s*<!--\\s+END $qhandle\\s+-->/s";
148
-			if (!preg_match($reg,$str,$match))
148
+			if (!preg_match($reg, $str, $match))
149 149
 			{
150 150
 				// unfortunaly some apps set non-existing blocks, therefor I have to disable this diagnostics again for now
151 151
 				$this->halt("set_block: unable to find block '$handle' in '$parent'=<pre>".htmlspecialchars($str)."</pre> this->root=$this->root");
152 152
 				// return False;
153 153
 			}
154
-			$this->set_var($handle,$match[1]);
155
-			$this->set_var($parent,preg_replace($reg, '{' . "$name}",$str));
154
+			$this->set_var($handle, $match[1]);
155
+			$this->set_var($parent, preg_replace($reg, '{'."$name}", $str));
156 156
 		}
157 157
 
158 158
 		/* public: set_var(array $values)
@@ -174,18 +174,18 @@  discard block
 block discarded – undo
174 174
 					$varname => $value
175 175
 				);
176 176
 			}
177
-			foreach($varname as $k => $v)
177
+			foreach ($varname as $k => $v)
178 178
 			{
179 179
 				if (!empty($k))
180 180
 				{
181
-					if ($this->debug && $this->check_debug('set_var',$k))
181
+					if ($this->debug && $this->check_debug('set_var', $k))
182 182
 					{
183 183
 						echo "<p>Template::set_var('$k','$v')</p>\n";
184 184
 					}
185 185
 					$this->varkeys[$k] = $this->varname($k);
186 186
 					$this->varvals[$k] = $this->egroupware_hack ? str_replace(
187
-						array('phpGroupWare','www.phpgroupware.org'),
188
-						array('eGroupWare','www.eGroupWare.org'),$v
187
+						array('phpGroupWare', 'www.phpgroupware.org'),
188
+						array('eGroupWare', 'www.eGroupWare.org'), $v
189 189
 					) : $v;
190 190
 				}
191 191
 			}
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		 */
197 197
 		function subst($handle)
198 198
 		{
199
-			if ($this->debug && $this->check_debug('subst',$handle))
199
+			if ($this->debug && $this->check_debug('subst', $handle))
200 200
 			{
201 201
 				echo "<p>Template::subst('$handle')</p>\n";
202 202
 			}
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 			}
208 208
 
209 209
 			$str = $this->get_var($handle);
210
-			foreach($this->varkeys as $k => $v)
210
+			foreach ($this->varkeys as $k => $v)
211 211
 			{
212 212
 				$str = str_replace($v, $this->varvals[$k], $str);
213 213
 			}
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 				$str = $this->subst($handle);
236 236
 				if ($append)
237 237
 				{
238
-					$this->set_var($target, $this->get_var($target) . $str);
238
+					$this->set_var($target, $this->get_var($target).$str);
239 239
 				}
240 240
 				else
241 241
 				{
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 			}
245 245
 			else
246 246
 			{
247
-				foreach($handle as $i => $h)
247
+				foreach ($handle as $i => $h)
248 248
 				{
249 249
 					$str = $this->subst($h);
250 250
 					$this->set_var($target, $str);
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		 */
276 276
 		function get_vars()
277 277
 		{
278
-			foreach($this->varkeys as $k => $v)
278
+			foreach ($this->varkeys as $k => $v)
279 279
 			{
280 280
 				$result[$k] = $this->varvals[$k];
281 281
 			}
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 			}
297 297
 			else
298 298
 			{
299
-				foreach($varname as $k => $v)
299
+				foreach ($varname as $k => $v)
300 300
 				{
301 301
 					$result[$k] = $this->varvals[$k];
302 302
 				}
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 			{
322 322
 				return false;
323 323
 			}
324
-			foreach($m as $k => $v)
324
+			foreach ($m as $k => $v)
325 325
 			{
326 326
 				if (!isset($this->varkeys[$v]))
327 327
 				{
@@ -376,15 +376,15 @@  discard block
 block discarded – undo
376 376
 		/* private: filename($filename)
377 377
 		 * filename: name to be completed.
378 378
 		 */
379
-		function filename($filename,$root='',$time=1)
379
+		function filename($filename, $root = '', $time = 1)
380 380
 		{
381
-			if($root == '')
381
+			if ($root == '')
382 382
 			{
383 383
 				$root = $this->root;
384 384
 			}
385
-			if(substr($filename, 0, 1) != '/')
385
+			if (substr($filename, 0, 1) != '/')
386 386
 			{
387
-				$new_filename = $root . '/' . $filename;
387
+				$new_filename = $root.'/'.$filename;
388 388
 			}
389 389
 			else
390 390
 			{
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 
394 394
 			if (!file_exists($new_filename))
395 395
 			{
396
-				if($time==2)
396
+				if ($time == 2)
397 397
 				{
398 398
 					$this->halt("filename: file $new_filename does not exist.");
399 399
 				}
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
 //					$new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$root);
403 403
 //					$new_root = substr($root, 0, strrpos($root, $GLOBALS['phpgw_info']['server']['template_set'])).'default';
404 404
 //					$new_root = substr($root, 0, strlen($root) - strlen($GLOBALS['phpgw_info']['server']['template_set'])) . 'default';
405
-					$new_root = dirname($root) . DIRECTORY_SEPARATOR . 'default';
406
-					$new_filename = $this->filename(str_replace($root.'/','',$new_filename),$new_root,2);
405
+					$new_root = dirname($root).DIRECTORY_SEPARATOR.'default';
406
+					$new_filename = $this->filename(str_replace($root.'/', '', $new_filename), $new_root, 2);
407 407
 				}
408 408
 			}
409 409
 			return $new_filename;
@@ -422,9 +422,9 @@  discard block
 block discarded – undo
422 422
 		 */
423 423
 		function loadfile($handle)
424 424
 		{
425
-			if ($this->debug && $this->check_debug('loadfile',$handle))
425
+			if ($this->debug && $this->check_debug('loadfile', $handle))
426 426
 			{
427
-				echo "<p>Template::loadfile('$handle') file=<pre>\n".print_r($this->file,True)."</pre>\n";
427
+				echo "<p>Template::loadfile('$handle') file=<pre>\n".print_r($this->file, True)."</pre>\n";
428 428
 				echo "<p>backtrace: ".function_backtrace()."</p>\n";
429 429
 			}
430 430
 			if (isset($this->varkeys[$handle]) && !empty($this->varvals[$handle]))
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
 			}
434 434
 			if (!isset($this->file[$handle]))
435 435
 			{
436
-				if ($this->debug && $this->check_debug('loadfile',$handle))
436
+				if ($this->debug && $this->check_debug('loadfile', $handle))
437 437
 				{
438
-					echo "varkeys =<pre>".print_r($this->varkeys,True)."</pre>varvals =<pre>".print_r($this->varvals,True)."</pre>\n";
438
+					echo "varkeys =<pre>".print_r($this->varkeys, True)."</pre>varvals =<pre>".print_r($this->varvals, True)."</pre>\n";
439 439
 				}
440 440
 				$this->halt("loadfile: $handle is not a valid handle.");
441 441
 				return false;
@@ -480,10 +480,10 @@  discard block
 block discarded – undo
480 480
 		{
481 481
 			if (!$this->debug) return False;
482 482
 
483
-			foreach(func_get_args() as $arg)
483
+			foreach (func_get_args() as $arg)
484 484
 			{
485 485
 				if (!is_array($this->debug) && $this->debug === $arg ||
486
-					(is_array($this->debug) && (@$this->debug[$arg] || in_array($arg,$this->debug,True))))
486
+					(is_array($this->debug) && (@$this->debug[$arg] || in_array($arg, $this->debug, True))))
487 487
 				{
488 488
 					return True;
489 489
 				}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -478,7 +478,10 @@
 block discarded – undo
478 478
 
479 479
 		function check_debug($str)
480 480
 		{
481
-			if (!$this->debug) return False;
481
+			if (!$this->debug)
482
+			{
483
+				return False;
484
+			}
482 485
 
483 486
 			foreach(func_get_args() as $arg)
484 487
 			{
Please login to merge, or discard this patch.
phpgwapi/inc/class.tplsavant2.inc.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@
 block discarded – undo
120 120
 	   * @param bool $fallback if true the default fallback template dir is returned
121 121
 	   * @param string $appname appication name optional can be derived from $GLOBALS['egw_info']['flags']['currentapp'];
122 122
 	   * @access public
123
-	   * @return void
123
+	   * @return string|false
124 124
 	   */
125 125
 	  function get_tpl_dir($fallback=false,$appname = '')
126 126
 	  {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 	  @function version_check
69 69
 	  @abstract check version of this wrapper with installed savant2 version and halts when version differs
70 70
 	  @return void
71
-	  */
71
+	   */
72 72
 	  function version_check()
73 73
 	  {
74 74
 		 $Sav2Version = @file_get_contents(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/VERSION',"rb");
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
    /* $Id$ */
26 26
 
27
-   if(is_file(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/Savant2.php'))
27
+   if (is_file(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/Savant2.php'))
28 28
    {
29 29
 	  include_once(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/Savant2.php');
30 30
    }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		 // run constructor of the Savant2 class
57 57
 		 $this->Savant2();
58 58
 
59
-		 if($this->do_version_check)
59
+		 if ($this->do_version_check)
60 60
 		 {
61 61
 			$this->version_check();
62 62
 		 }
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 	  */
72 72
 	  function version_check()
73 73
 	  {
74
-		 $Sav2Version = @file_get_contents(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/VERSION',"rb");
74
+		 $Sav2Version = @file_get_contents(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/VERSION', "rb");
75 75
 
76
-		 if(trim($Sav2Version) != trim($this->version))
76
+		 if (trim($Sav2Version) != trim($this->version))
77 77
 		 { 
78
-			$this->halt(lang('Savant2 version differs from Savant2 wrapper. <br/>This version: %1 <br/>Savants version: %2',$this->version, $Sav2Version));					
78
+			$this->halt(lang('Savant2 version differs from Savant2 wrapper. <br/>This version: %1 <br/>Savants version: %2', $this->version, $Sav2Version));					
79 79
 		 }
80 80
 	  }
81 81
 
@@ -86,30 +86,30 @@  discard block
 block discarded – undo
86 86
 	   * @access public
87 87
 	   * @return void
88 88
 	   */
89
-	  function set_tpl_path($man_dir=null)
89
+	  function set_tpl_path($man_dir = null)
90 90
 	  {
91
-		 $preferred_dir=$this->get_tpl_dir(); 
92
-		 $fallback_dir=$this->get_tpl_dir(true); 
91
+		 $preferred_dir = $this->get_tpl_dir(); 
92
+		 $fallback_dir = $this->get_tpl_dir(true); 
93 93
 
94
-		 if(!$preferred_dir && $man_dir && $fallback_dir)
94
+		 if (!$preferred_dir && $man_dir && $fallback_dir)
95 95
 		 {
96 96
 			$this->halt(lang('No Savant2 template directories were found in:'.EGW_APP_ROOT)); 
97 97
 		 }
98 98
 		 else
99 99
 		 {
100
-			if($fallback_dir)
100
+			if ($fallback_dir)
101 101
 			{
102
-			   $this->addPath('template',$fallback_dir);
102
+			   $this->addPath('template', $fallback_dir);
103 103
 			}
104 104
 			// add preferred tpl dir last because savant set the last added first in the search array  
105
-			if($preferred_dir)
105
+			if ($preferred_dir)
106 106
 			{
107
-			   $this->addPath('template',$preferred_dir);
107
+			   $this->addPath('template', $preferred_dir);
108 108
 			}
109 109
 
110
-			if($man_dir)
110
+			if ($man_dir)
111 111
 			{
112
-			   $this->addPath('template',$man_dir);
112
+			   $this->addPath('template', $man_dir);
113 113
 			}
114 114
 		 }
115 115
 	  }
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	   * @access public
123 123
 	   * @return void
124 124
 	   */
125
-	  function get_tpl_dir($fallback=false,$appname = '')
125
+	  function get_tpl_dir($fallback = false, $appname = '')
126 126
 	  {
127
-		 if (! $appname)
127
+		 if (!$appname)
128 128
 		 {
129 129
 			$appname = $GLOBALS['egw_info']['flags']['currentapp'];
130 130
 		 }
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 			$GLOBALS['egw_info']['server']['template_set'] = 'default';
157 157
 		 }
158 158
 
159
-		 $tpldir         = EGW_SERVER_ROOT . '/' . $appname . '/templatesSavant2/' . $GLOBALS['egw_info']['server']['template_set'];
160
-		 $tpldir_default = EGW_SERVER_ROOT . '/' . $appname . '/templatesSavant2/default';
159
+		 $tpldir         = EGW_SERVER_ROOT.'/'.$appname.'/templatesSavant2/'.$GLOBALS['egw_info']['server']['template_set'];
160
+		 $tpldir_default = EGW_SERVER_ROOT.'/'.$appname.'/templatesSavant2/default';
161 161
 
162 162
 		 if (!$fallback && @is_dir($tpldir))
163 163
 		 {
@@ -205,12 +205,12 @@  discard block
 block discarded – undo
205 205
 
206 206
 	  function fetch_string($string)
207 207
 	  {
208
-		 $tmpfname = tempnam ("/tmp", "sav");
208
+		 $tmpfname = tempnam("/tmp", "sav");
209 209
 		 $fp = fopen($tmpfname, "w");
210 210
 		 fwrite($fp, $string);
211 211
 		 fclose($fp);
212
-		 $this->addPath('template','/tmp');
213
-		 $file_arr= explode('/',$tmpfname);
212
+		 $this->addPath('template', '/tmp');
213
+		 $file_arr = explode('/', $tmpfname);
214 214
 		 return $this->fetch($file_arr[2]);
215 215
 		 unlink($tmpfname);
216 216
 	  }
@@ -223,9 +223,9 @@  discard block
 block discarded – undo
223 223
 	   * @access public
224 224
 	   * @return void
225 225
 	   */
226
-	  function set_var($tplvar,$val='')
226
+	  function set_var($tplvar, $val = '')
227 227
 	  {
228
-		 $this->assign($tplvar,$val);
228
+		 $this->assign($tplvar, $val);
229 229
 	  }
230 230
 
231 231
    }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@
 block discarded – undo
74 74
 		 $Sav2Version = @file_get_contents(EGW_INCLUDE_ROOT.'/phpgwapi/inc/savant2/VERSION',"rb");
75 75
 
76 76
 		 if(trim($Sav2Version) != trim($this->version))
77
-		 { 
77
+		 {
78 78
 			$this->halt(lang('Savant2 version differs from Savant2 wrapper. <br/>This version: %1 <br/>Savants version: %2',$this->version, $Sav2Version));					
79 79
 		 }
80 80
 	  }
Please login to merge, or discard this patch.
phpgwapi/inc/class.translation.inc.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 	 *
741 741
 	 * @param string $app application name
742 742
 	 * @param string $lang language code
743
-	 * @return the full path of the filename for the requested app and language
743
+	 * @return string full path of the filename for the requested app and language
744 744
 	 */
745 745
 	static function get_lang_file($app,$lang)
746 746
 	{
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
1305 1305
 	 * @param string $displayCharset : charset to use; should be a valid charset
1306 1306
 	 * @param bool $stripcrl :  flag to indicate for the removal of all crlf \r\n
1307 1307
 	 * @param bool $stripalltags : flag to indicate wether or not to strip $_html from all remaining tags
1308
-	 * @return text $_html : the modified text.
1308
+	 * @return string $_html : the modified text.
1309 1309
 	 */
1310 1310
 	static function convertHTMLToText($_html,$displayCharset=false,$stripcrl=false,$stripalltags=true)
1311 1311
 	{
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   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @var array
99 99
 	 */
100
-	static $instance_specific_translations = array('loginscreen','mainscreen','custom');
100
+	static $instance_specific_translations = array('loginscreen', 'mainscreen', 'custom');
101 101
 
102 102
 	/**
103 103
 	 * returns the charset to use (!$lang) or the charset of the lang-files or $lang
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @param string/boolean $lang =False return charset of the active user-lang, or $lang if specified
106 106
 	 * @return string charset
107 107
 	 */
108
-	static function charset($lang=False)
108
+	static function charset($lang = False)
109 109
 	{
110 110
 		static $charsets = array();
111 111
 
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
 		{
114 114
 			if (!isset($charsets[$lang]))
115 115
 			{
116
-				if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE,'content',array(
116
+				if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE, 'content', array(
117 117
 					'lang'		=> $lang,
118 118
 					'message_id'=> 'charset',
119 119
 					'app_name'	=> 'common',
120
-				),__LINE__,__FILE__)->fetchColumn()))
120
+				), __LINE__, __FILE__)->fetchColumn()))
121 121
 				{
122 122
 					$charsets[$lang] = 'utf-8';
123 123
 				}
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 *
152 152
 	 * @param boolean $load_translations =true should we also load translations for common and currentapp
153 153
 	 */
154
-	static function init($load_translations=true)
154
+	static function init($load_translations = true)
155 155
 	{
156 156
 		if (!isset(self::$db))
157 157
 		{
@@ -163,11 +163,11 @@  discard block
 block discarded – undo
163 163
 		}
164 164
 		else
165 165
 		{
166
-			self::$system_charset =& $GLOBALS['egw_setup']->system_charset;
166
+			self::$system_charset = & $GLOBALS['egw_setup']->system_charset;
167 167
 		}
168 168
 		if ((self::$mbstring = check_load_extension('mbstring')))
169 169
 		{
170
-			if(!empty(self::$system_charset))
170
+			if (!empty(self::$system_charset))
171 171
 			{
172 172
 				$ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset';
173 173
 				ini_set($ini_default_charset, self::$system_charset);
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
 		// try loading load_via from tree-wide cache and check if it contains more rules
178 178
 		if (($load_via = egw_cache::getTree(__CLASS__, 'load_via')) &&
179
-			$load_via >= self::$load_via && 	// > for array --> contains more elements
179
+			$load_via >= self::$load_via && // > for array --> contains more elements
180 180
 			// little sanity check: cached array contains all stock keys, otherwise ignore it
181 181
 			!array_diff_key(self::$load_via, $load_via))
182 182
 		{
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
 	 * @param string $not_found ='*' what to add to not found phrases, default '*'
216 216
 	 * @return string with translation
217 217
 	 */
218
-	static function translate($key, $vars=null, $not_found='' )
218
+	static function translate($key, $vars = null, $not_found = '')
219 219
 	{
220 220
 		if (!self::$lang_arr)
221 221
 		{
222 222
 			self::init();
223 223
 		}
224
-		$ret = $key;				// save key if we dont find a translation
224
+		$ret = $key; // save key if we dont find a translation
225 225
 		if ($not_found) $ret .= $not_found;
226 226
 
227 227
 		if (isset(self::$lang_arr[$key]))
@@ -241,16 +241,16 @@  discard block
 block discarded – undo
241 241
 		{
242 242
 			if (count($vars) > 1)
243 243
 			{
244
-				static $placeholders = array('%3','%2','%1','|%2|','|%3|','%4','%5','%6','%7','%8','%9','%10');
244
+				static $placeholders = array('%3', '%2', '%1', '|%2|', '|%3|', '%4', '%5', '%6', '%7', '%8', '%9', '%10');
245 245
 				// to cope with $vars[0] containing '%2' (eg. an urlencoded path like a referer),
246 246
 				// we first replace '%2' in $ret with '|%2|' and then use that as 2. placeholder
247 247
 				// we do that for %3 as well, ...
248
-				$vars = array_merge(array('|%3|','|%2|'),$vars);	// push '|%2|' (and such) as first replacement on $vars
249
-				$ret = str_replace($placeholders,$vars,$ret);
248
+				$vars = array_merge(array('|%3|', '|%2|'), $vars); // push '|%2|' (and such) as first replacement on $vars
249
+				$ret = str_replace($placeholders, $vars, $ret);
250 250
 			}
251 251
 			else
252 252
 			{
253
-				$ret = str_replace('%1',$vars[0],$ret);
253
+				$ret = str_replace('%1', $vars[0], $ret);
254 254
 			}
255 255
 		}
256 256
 		return $ret;
@@ -265,14 +265,14 @@  discard block
 block discarded – undo
265 265
 	 * 	if multiple names given, they are requested in one request from cache and loaded in given order
266 266
 	 * @param string $lang =false 2 or 5 char lang-code or false for the users language
267 267
 	 */
268
-	static function add_app($apps, $lang=null)
268
+	static function add_app($apps, $lang = null)
269 269
 	{
270 270
 		//error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr));
271 271
 		//$start = microtime(true);
272 272
 		if (!$lang) $lang = self::$userlang;
273 273
 		$tree_level = $instance_level = array();
274 274
 		if (!is_array($apps)) $apps = (array)$apps;
275
-		foreach($apps as $key => $app)
275
+		foreach ($apps as $key => $app)
276 276
 		{
277 277
 			if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common')
278 278
 			{
@@ -296,26 +296,26 @@  discard block
 block discarded – undo
296 296
 
297 297
 		// merging loaded translations together
298 298
 		$updated_load_via = false;
299
-		foreach((array)$apps as $app)
299
+		foreach ((array)$apps as $app)
300 300
 		{
301 301
 			$l = $app == 'custom' ? 'en' : $lang;
302 302
 			if (isset($tree_level[$app.':'.$l]))
303 303
 			{
304
-				$loaded =& $tree_level[$app.':'.$l];
304
+				$loaded = & $tree_level[$app.':'.$l];
305 305
 			}
306 306
 			elseif (isset($instance_level[$app.':'.$l]))
307 307
 			{
308
-				$loaded =& $instance_level[$app.':'.$l];
308
+				$loaded = & $instance_level[$app.':'.$l];
309 309
 			}
310 310
 			else
311 311
 			{
312 312
 				if (($instance_specific = in_array($app, self::$instance_specific_translations)))
313 313
 				{
314
-					$loaded =& self::load_app($app, $l);
314
+					$loaded = & self::load_app($app, $l);
315 315
 				}
316 316
 				else
317 317
 				{
318
-					$loaded =& self::load_app_files($app, $l, null, $updated_load_via);
318
+					$loaded = & self::load_app_files($app, $l, null, $updated_load_via);
319 319
 				}
320 320
 				//error_log(__METHOD__."('$app', '$lang') instance_specific=$instance_specific, load_app(_files)() returned ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded)));
321 321
 				if ($loaded || $instance_specific)
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
 			if ($loaded)
329 329
 			{
330 330
 				self::$lang_arr = array_merge(self::$lang_arr, $loaded);
331
-				self::$loaded_apps[$app] = $l;	// dont set something not existing to $loaded_apps, no need to load client-side
331
+				self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side
332 332
 			}
333 333
 		}
334 334
 		// Re-merge custom over instance level, they have higher precidence
335
-		if($tree_level && !$instance_level && self::$instance_specific_translations)
335
+		if ($tree_level && !$instance_level && self::$instance_specific_translations)
336 336
 		{
337 337
 			$custom = egw_cache::getInstance(__CLASS__, 'custom:en');
338
-			if($custom)
338
+			if ($custom)
339 339
 			{
340 340
 				self::$lang_arr = array_merge(self::$lang_arr, $custom);
341 341
 			}
@@ -356,15 +356,15 @@  discard block
 block discarded – undo
356 356
 	 * @param string $lang =false 2 or 5 char lang-code or false for the users language
357 357
 	 * @return array the loaded strings
358 358
 	 */
359
-	static function &load_app($app,$lang)
359
+	static function &load_app($app, $lang)
360 360
 	{
361 361
 		//$start = microtime(true);
362 362
 		if (is_null(self::$db)) self::init(false);
363 363
 		$loaded = array();
364
-		foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array(
364
+		foreach (self::$db->select(self::LANG_TABLE, 'message_id,content', array(
365 365
 			'lang'		=> $lang,
366 366
 			'app_name'	=> $app,
367
-		),__LINE__,__FILE__) as $row)
367
+		), __LINE__, __FILE__) as $row)
368 368
 		{
369 369
 			$loaded[strtolower($row['message_id'])] = $row['content'];
370 370
 		}
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 		'sitemgr-link' => array('sitemgr'),
389 389
 		'groupdav' => array('phpgwapi'),
390 390
 		'developer_tools' => array('etemplate'),
391
-		'login' => array('phpgwapi','registration'),
391
+		'login' => array('phpgwapi', 'registration'),
392 392
 	);
393 393
 
394 394
 	/**
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	{
401 401
 		$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
402 402
 		$apps = array_keys($GLOBALS['egw_info']['apps']);
403
-		foreach($apps as $app)
403
+		foreach ($apps as $app)
404 404
 		{
405 405
 			$file = self::get_lang_file($app, $lang);
406 406
 			// check if file has changed compared to what's cached
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 		egw_cache::unsetTree(__CLASS__, $app.':'.$lang);
431 431
 		egw_cache::unsetTree(__CLASS__, self::get_lang_file($app, $lang));
432 432
 
433
-		foreach(self::$load_via as $load => $via)
433
+		foreach (self::$load_via as $load => $via)
434 434
 		{
435 435
 			//error_log("load_via[load='$load'] = via = ".array2string($via));
436 436
 			if ($via === 'all-apps' || in_array($app, (array)$via))
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 	 * @param string $_lang =null
453 453
 	 * @return array $lang or $app => number pairs
454 454
 	 */
455
-	static function statistics($_lang=null)
455
+	static function statistics($_lang = null)
456 456
 	{
457 457
 		$cache = egw_cache::getTree(__CLASS__, 'statistics');
458 458
 
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 			{
464 464
 				$en_phrases = array_keys(self::load_app_files(null, 'en', 'all-apps'));
465 465
 				$cache['']['en'] = count($en_phrases);
466
-				foreach(array_keys(self::get_available_langs()) as $lang)
466
+				foreach (array_keys(self::get_available_langs()) as $lang)
467 467
 				{
468 468
 					if ($lang == 'en') continue;
469 469
 					$lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps'));
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 			else
475 475
 			{
476 476
 				$cache['en'] = array();
477
-				foreach(scandir(EGW_SERVER_ROOT) as $app)
477
+				foreach (scandir(EGW_SERVER_ROOT) as $app)
478 478
 				{
479 479
 					if ($app[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app) ||
480 480
 						!file_exists(self::get_lang_file($app, 'en')))
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 		if (!in_array($_app, translation::$instance_specific_translations))
513 513
 		{
514 514
 			// check if cache is NOT invalided by checking if we have a modification time for concerned lang-file
515
-			$time = egw_cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang));
515
+			$time = egw_cache::getTree(__CLASS__, $file = self::get_lang_file($_app, $_lang));
516 516
 			// if we dont have one, cache has been invalidated and we need to load translations
517 517
 			if (!isset($time)) self::add_app($_app, $_lang);
518 518
 
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 	 * @param type $time
533 533
 	 * @return type
534 534
 	 */
535
-	static function max_lang_time($time=null)
535
+	static function max_lang_time($time = null)
536 536
 	{
537 537
 		static $max_lang_time = null;
538 538
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 		if (isset($time) && $time > $max_lang_time)
544 544
 		{
545 545
 			//error_log(__METHOD__."($time) updating previous max_lang_time=$max_lang_time to $time");
546
-			egw_cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time=$time);
546
+			egw_cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time = $time);
547 547
 		}
548 548
 		return $max_lang_time;
549 549
 	}
@@ -559,34 +559,34 @@  discard block
 block discarded – undo
559 559
 	 * @param boolean $updated_load_via =false on return true if self::$load_via was updated
560 560
 	 * @return array the loaded strings
561 561
 	 */
562
-	static function &load_app_files($app, $lang, $just_app_file=null, &$updated_load_via=false)
562
+	static function &load_app_files($app, $lang, $just_app_file = null, &$updated_load_via = false)
563 563
 	{
564 564
 		//$start = microtime(true);
565 565
 		$load_app = isset($just_app_file) ? $just_app_file : (isset(self::$load_via[$app]) ? self::$load_via[$app] : $app);
566 566
 		$loaded = array();
567
-		foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
567
+		foreach ($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
568 568
 		{
569
-			if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root
569
+			if ($load_app == 'all-apps' && $app_dir == '..') continue; // do not try to break out of egw server root
570 570
 			if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) ||
571
-				!@file_exists($file=self::get_lang_file($app_dir, $lang)) ||
571
+				!@file_exists($file = self::get_lang_file($app_dir, $lang)) ||
572 572
 				!($f = fopen($file, 'r')))
573 573
 			{
574 574
 				continue;
575 575
 			}
576 576
 			// store ctime of file we parse
577
-			egw_cache::setTree(__CLASS__, $file, $time=filemtime($file));
577
+			egw_cache::setTree(__CLASS__, $file, $time = filemtime($file));
578 578
 			self::max_lang_time($time);
579 579
 
580 580
 			$line_nr = 0;
581 581
 			//use fgets and split the line, as php5.3.3 with squeeze does not support splitting lines with fgetcsv while reading properly
582 582
 			//if the first letter after the delimiter is a german umlaut (UTF8 representation thereoff)
583 583
 			//while(($line = fgetcsv($f, 1024, "\t")))
584
-			while(($read = fgets($f)))
584
+			while (($read = fgets($f)))
585 585
 			{
586 586
 				$line = explode("\t", trim($read));
587 587
 				++$line_nr;
588 588
 				if (count($line) != 4) continue;
589
-				list($l_id,$l_app,$l_lang,$l_translation) = $line;
589
+				list($l_id, $l_app, $l_lang, $l_translation) = $line;
590 590
 				if ($l_lang != $lang) continue;
591 591
 				if (!isset($just_app_file) && $l_app != $app)
592 592
 				{
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 			// little sanity check: cached array contains all stock keys, otherwise ignore it
628 628
 			!array_diff_key(self::$load_via, $load_via))
629 629
 		{
630
-			foreach($load_via as $app => $via)
630
+			foreach ($load_via as $app => $via)
631 631
 			{
632 632
 				if (self::$load_via[$app] != $via)
633 633
 				{
@@ -653,15 +653,15 @@  discard block
 block discarded – undo
653 653
 	 * @param boolean $force_read =false force a re-read of the languages
654 654
 	 * @return array with lang-code => descriptiv lang-name pairs
655 655
 	 */
656
-	static function get_available_langs($translate=true, $force_read=false)
656
+	static function get_available_langs($translate = true, $force_read = false)
657 657
 	{
658 658
 		if (!is_array(self::$langs) || $force_read)
659 659
 		{
660
-			if (!($f = fopen($file=EGW_SERVER_ROOT.'/setup/lang/languages','rb')))
660
+			if (!($f = fopen($file = EGW_SERVER_ROOT.'/setup/lang/languages', 'rb')))
661 661
 			{
662 662
 				throw new egw_exception("List of available languages (%1) missing!", $file);
663 663
 			}
664
-			while(($line = fgetcsv($f, null, "\t")))
664
+			while (($line = fgetcsv($f, null, "\t")))
665 665
 			{
666 666
 				self::$langs[$line[0]] = $line[1];
667 667
 			}
@@ -671,12 +671,12 @@  discard block
 block discarded – undo
671 671
 			{
672 672
 				if (is_null(self::$db)) self::init(false);
673 673
 
674
-				foreach(self::$langs as $lang => $name)
674
+				foreach (self::$langs as $lang => $name)
675 675
 				{
676
-					self::$langs[$lang] = self::translate($name,False,'');
676
+					self::$langs[$lang] = self::translate($name, False, '');
677 677
 				}
678 678
 			}
679
-			uasort(self::$langs,'strcasecmp');
679
+			uasort(self::$langs, 'strcasecmp');
680 680
 		}
681 681
 		return self::$langs;
682 682
 	}
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 	 * @param boolean $force_read =false force a re-read of the languages
690 690
 	 * @return array with lang-code => descriptiv lang-name pairs
691 691
 	 */
692
-	static function get_installed_langs($force_read=false)
692
+	static function get_installed_langs($force_read = false)
693 693
 	{
694 694
 		return self::get_available_langs($force_read);
695 695
 	}
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 		{
707 707
 			return self::$langs[$lang];
708 708
 		}
709
-		return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn();
709
+		return self::$db->select(self::LANGUAGES_TABLE, 'lang_name', array('lang_id' => $lang), __LINE__, __FILE__)->fetchColumn();
710 710
 	}
711 711
 
712 712
 	/**
@@ -715,20 +715,20 @@  discard block
 block discarded – undo
715 715
 	 * @param boolean $force_read =false
716 716
 	 * @return array with lang_id => lang_name pairs
717 717
 	 */
718
-	static function list_langs($force_read=false)
718
+	static function list_langs($force_read = false)
719 719
 	{
720 720
 		if (!$force_read)
721 721
 		{
722
-			return egw_cache::getInstance(__CLASS__,'list_langs',array(__CLASS__,'list_langs'),array(true));
722
+			return egw_cache::getInstance(__CLASS__, 'list_langs', array(__CLASS__, 'list_langs'), array(true));
723 723
 		}
724
-		$languages = self::get_installed_langs();	// available languages
725
-		$availible = "('".implode("','",array_keys($languages))."')";
724
+		$languages = self::get_installed_langs(); // available languages
725
+		$availible = "('".implode("','", array_keys($languages))."')";
726 726
 
727 727
 		// this shows first the installed, then the available and then the rest
728
-		foreach(self::$db->select(self::LANGUAGES_TABLE,array(
729
-			'lang_id','lang_name',
728
+		foreach (self::$db->select(self::LANGUAGES_TABLE, array(
729
+			'lang_id', 'lang_name',
730 730
 			"CASE WHEN lang_id IN $availible THEN 1 ELSE 0 END AS availible",
731
-		),"lang_id NOT IN ('".implode("','",array_keys($languages))."')",__LINE__,__FILE__,false,' ORDER BY availible DESC,lang_name') as $row)
731
+		), "lang_id NOT IN ('".implode("','", array_keys($languages))."')", __LINE__, __FILE__, false, ' ORDER BY availible DESC,lang_name') as $row)
732 732
 		{
733 733
 			$languages[$row['lang_id']] = $row['lang_name'];
734 734
 		}
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 	 * @param string $lang language code
743 743
 	 * @return the full path of the filename for the requested app and language
744 744
 	 */
745
-	static function get_lang_file($app,$lang)
745
+	static function get_lang_file($app, $lang)
746 746
 	{
747 747
 		if ($app == 'common') $app = 'phpgwapi';
748 748
 		return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION;
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 	 */
756 756
 	static function get_installed_charsets()
757 757
 	{
758
-		static $charsets=null;
758
+		static $charsets = null;
759 759
 
760 760
 		if (!isset($charsets))
761 761
 		{
@@ -785,13 +785,13 @@  discard block
 block discarded – undo
785 785
 		static $extra = array(
786 786
 			'&szlig;' => 'ss',
787 787
 		);
788
-		$entities = htmlentities($_str,ENT_QUOTES,self::charset());
788
+		$entities = htmlentities($_str, ENT_QUOTES, self::charset());
789 789
 
790
-		$estr = str_replace(array_keys($extra),array_values($extra), $entities);
791
-		$ustr = preg_replace('/&([aAuUoO])uml;/','\\1e', $estr);	// replace german umlauts with the letter plus one 'e'
792
-		$astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/','\\1', $ustr);	// remove all types of accents
790
+		$estr = str_replace(array_keys($extra), array_values($extra), $entities);
791
+		$ustr = preg_replace('/&([aAuUoO])uml;/', '\\1e', $estr); // replace german umlauts with the letter plus one 'e'
792
+		$astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/', '\\1', $ustr); // remove all types of accents
793 793
 
794
-		return preg_replace('/&([a-zA-Z]+|#[0-9]+|);/','', $astr);	// remove all other entities
794
+		return preg_replace('/&([a-zA-Z]+|#[0-9]+|);/', '', $astr); // remove all other entities
795 795
 	}
796 796
 
797 797
 	/**
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
 	 * @param boolean $check_to_from =true internal to bypass all charset replacements
804 804
 	 * @return string/array converted string(s) from $data
805 805
 	 */
806
-	static function convert($data,$from=False,$to=False,$check_to_from=true)
806
+	static function convert($data, $from = False, $to = False, $check_to_from = true)
807 807
 	{
808 808
 		if ($check_to_from)
809 809
 		{
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
 			if (!$from)
815 815
 			{
816 816
 				$from = self::$mbstring ? strtolower(mb_detect_encoding($data)) : 'iso-8859-1';
817
-				if($from == 'ascii')
817
+				if ($from == 'ascii')
818 818
 				{
819 819
 					$from = 'iso-8859-1';
820 820
 				}
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 				 php does not seem to support gb2312
825 825
 				 but seems to be able to decode it as EUC-CN
826 826
 			*/
827
-			switch($from)
827
+			switch ($from)
828 828
 			{
829 829
 				case 'ks_c_5601-1987':
830 830
 					$from = 'CP949';
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
 		}
871 871
 		if (is_array($data))
872 872
 		{
873
-			foreach($data as $key => $str)
873
+			foreach ($data as $key => $str)
874 874
 			{
875
-				$ret[$key] = self::convert($str,$from,$to,false);	// false = bypass the above checks, as they are already done
875
+				$ret[$key] = self::convert($str, $from, $to, false); // false = bypass the above checks, as they are already done
876 876
 			}
877 877
 			return $ret;
878 878
 		}
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 		{
885 885
 			return utf8_decode($data);
886 886
 		}
887
-		if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data,$to,$from)) != '')
887
+		if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data, $to, $from)) != '')
888 888
 		{
889 889
 			return $data;
890 890
 		}
@@ -912,12 +912,12 @@  discard block
 block discarded – undo
912 912
 			// in an email on the first Traditional/Japanese/Korean character,
913 913
 			// but in reality when people send mails in GB2312, UMA mostly use
914 914
 			// extended GB13000/GB18030 which allow T/Jap/Korean characters.
915
-			if($from == 'euc-cn')
915
+			if ($from == 'euc-cn')
916 916
 			{
917 917
 				$from = 'gb18030';
918 918
 			}
919 919
 
920
-			if (($convertedData = iconv($from,$to,$data)))
920
+			if (($convertedData = iconv($from, $to, $data)))
921 921
 			{
922 922
 				return $convertedData;
923 923
 			}
@@ -932,21 +932,21 @@  discard block
 block discarded – undo
932 932
 	 * @param string/boolean $from charset $data is in or False if it should be detected
933 933
 	 * @return string/array converted string(s) from $data
934 934
 	 */
935
-	static function convert_jsonsafe($data,$from=False)
935
+	static function convert_jsonsafe($data, $from = False)
936 936
 	{
937
-		if ($from===false) $from = self::detect_encoding($data);
938
-		$data = self::convert($data,strtolower($from));
937
+		if ($from === false) $from = self::detect_encoding($data);
938
+		$data = self::convert($data, strtolower($from));
939 939
 		// in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct
940 940
 		if (strtoupper(self::charset()) == 'UTF-8')
941 941
 		{
942 942
 			$test = @json_encode($data);
943 943
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($data).' Error:'.json_last_error().'<- data:#'.$test.'#');
944
-			if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
944
+			if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0)
945 945
 			{
946 946
 				// try to fix broken utf8
947
-				$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));
947
+				$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));
948 948
 				$test = @json_encode($x);
949
-				if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0)
949
+				if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0)
950 950
 				{
951 951
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
952 952
 					error_log(__METHOD__.__LINE__.' Charset Reported:'.$from.' Charset Detected:'.translation::detect_encoding($data));
@@ -969,36 +969,36 @@  discard block
 block discarded – undo
969 969
 	 * @param string $message_id
970 970
 	 * @param string $content translation or null to delete translation
971 971
 	 */
972
-	static function write($lang,$app,$message_id,$content)
972
+	static function write($lang, $app, $message_id, $content)
973 973
 	{
974 974
 		if ($content)
975 975
 		{
976
-			self::$db->insert(self::LANG_TABLE,array(
976
+			self::$db->insert(self::LANG_TABLE, array(
977 977
 				'content' => $content,
978
-			),array(
978
+			), array(
979 979
 				'lang' => $lang,
980 980
 				'app_name' => $app,
981 981
 				'message_id' => $message_id,
982
-			),__LINE__,__FILE__);
982
+			), __LINE__, __FILE__);
983 983
 		}
984 984
 		else
985 985
 		{
986
-			self::$db->delete(self::LANG_TABLE,array(
986
+			self::$db->delete(self::LANG_TABLE, array(
987 987
 				'lang' => $lang,
988 988
 				'app_name' => $app,
989 989
 				'message_id' => $message_id,
990
-			),__LINE__,__FILE__);
990
+			), __LINE__, __FILE__);
991 991
 		}
992 992
 		// invalidate the cache
993
-		if(!in_array($app,self::$instance_specific_translations))
993
+		if (!in_array($app, self::$instance_specific_translations))
994 994
 		{
995
-			egw_cache::unsetCache(egw_cache::TREE,__CLASS__,$app.':'.$lang);
995
+			egw_cache::unsetCache(egw_cache::TREE, __CLASS__, $app.':'.$lang);
996 996
 		}
997 997
 		else
998 998
 		{
999
-			foreach(array_keys((array)self::get_installed_langs()) as $key)
999
+			foreach (array_keys((array)self::get_installed_langs()) as $key)
1000 1000
 			{
1001
-				egw_cache::unsetCache(egw_cache::INSTANCE,__CLASS__,$app.':'.$key);
1001
+				egw_cache::unsetCache(egw_cache::INSTANCE, __CLASS__, $app.':'.$key);
1002 1002
 			}
1003 1003
 		}
1004 1004
  	}
@@ -1011,13 +1011,13 @@  discard block
 block discarded – undo
1011 1011
 	 * @param string $message_id
1012 1012
 	 * @return string/boolean content or false if not found
1013 1013
 	 */
1014
-	static function read($lang,$app_name,$message_id)
1014
+	static function read($lang, $app_name, $message_id)
1015 1015
 	{
1016
-		return self::$db->select(self::LANG_TABLE,'content',array(
1016
+		return self::$db->select(self::LANG_TABLE, 'content', array(
1017 1017
 			'lang' => $lang,
1018 1018
 			'app_name' => $app_name,
1019 1019
 			'message_id' => $message_id,
1020
-		),__LINE__,__FILE__)->fetchColumn();
1020
+		), __LINE__, __FILE__)->fetchColumn();
1021 1021
 	}
1022 1022
 
1023 1023
 	/**
@@ -1028,23 +1028,23 @@  discard block
 block discarded – undo
1028 1028
 	 * @param string $lang ='' default check all langs
1029 1029
 	 * @return string
1030 1030
 	 */
1031
-	static function get_message_id($translation,$app=null,$lang=null)
1031
+	static function get_message_id($translation, $app = null, $lang = null)
1032 1032
 	{
1033 1033
 		$where = array('content '.self::$db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation));
1034 1034
 		if ($app) $where['app_name'] = $app;
1035 1035
 		if ($lang) $where['lang'] = $lang;
1036 1036
 
1037
-		$id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn();
1037
+		$id = self::$db->select(self::LANG_TABLE, 'message_id', $where, __LINE__, __FILE__)->fetchColumn();
1038 1038
 
1039 1039
 		// Check cache, since most things aren't in the DB anymore
1040
-		if(!$id)
1040
+		if (!$id)
1041 1041
 		{
1042
-			$lang_arr = self::$lang_arr;	// PHP 5.3 does NOT allow to use class scope / self in closure
1042
+			$lang_arr = self::$lang_arr; // PHP 5.3 does NOT allow to use class scope / self in closure
1043 1043
 			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation, $lang_arr) {
1044
-				return stripos($lang_arr[$haystack],$translation) !== false;
1044
+				return stripos($lang_arr[$haystack], $translation) !== false;
1045 1045
 			});
1046 1046
 			$id = array_shift($ids);
1047
-			if(!$id && ($lang && $lang !== 'en' || self::$userlang != 'en'))
1047
+			if (!$id && ($lang && $lang !== 'en' || self::$userlang != 'en'))
1048 1048
 			{
1049 1049
 				// Try english
1050 1050
 				if (in_array($app, self::$instance_specific_translations))
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
 				if ($instance_level) $lang_arr = egw_cache::getInstance(__CLASS__, $instance_level);
1062 1062
 				$lang_arr = $lang_arr[$app.':en'];
1063 1063
 				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) {
1064
-					return stripos($lang_arr[$haystack],$translation) !== false;
1064
+					return stripos($lang_arr[$haystack], $translation) !== false;
1065 1065
 				});
1066 1066
 				$id = array_shift($ids);
1067 1067
 			}
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 	 * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available
1079 1079
 	 * @return string - encoding
1080 1080
 	 */
1081
-	static function detect_encoding($string, $verify=null)
1081
+	static function detect_encoding($string, $verify = null)
1082 1082
 	{
1083 1083
 		if (function_exists('iconv'))
1084 1084
 		{
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
 		}
1102 1102
 		if ($verify && (!isset($detected) || $detected === 'ascii'))
1103 1103
 		{
1104
-			return $verify;	// ascii matches all charsets
1104
+			return $verify; // ascii matches all charsets
1105 1105
 		}
1106 1106
 		return isset($detected) ? $detected : 'iso-8859-1'; // we choose to return iso-8859-1 as default
1107 1107
 	}
@@ -1113,10 +1113,10 @@  discard block
 block discarded – undo
1113 1113
 	 * @param string $displayCharset the charset parameter specifies the character set to represent the result by (if iconv_mime_decode is to be used)
1114 1114
 	 * @return string
1115 1115
 	 */
1116
-	static function decodeMailHeader($_string, $displayCharset='utf-8')
1116
+	static function decodeMailHeader($_string, $displayCharset = 'utf-8')
1117 1117
 	{
1118 1118
 		//error_log(__FILE__.','.__METHOD__.':'."called with $_string and CHARSET $displayCharset");
1119
-		if(function_exists(imap_mime_header_decode))
1119
+		if (function_exists(imap_mime_header_decode))
1120 1120
 		{
1121 1121
 			// some characterreplacements, as they fail to translate
1122 1122
 			$sar = array(
@@ -1138,23 +1138,23 @@  discard block
 block discarded – undo
1138 1138
 
1139 1139
 			$string = preg_replace('/\?=\s+=\?/', '?= =?', $_string);
1140 1140
 
1141
-			$elements=imap_mime_header_decode($string);
1141
+			$elements = imap_mime_header_decode($string);
1142 1142
 
1143 1143
 			$convertAtEnd = false;
1144
-			foreach((array)$elements as $element)
1144
+			foreach ((array)$elements as $element)
1145 1145
 			{
1146 1146
 				if ($element->charset == 'default') $element->charset = self::detect_encoding($element->text);
1147 1147
 				if ($element->charset != 'x-unknown')
1148 1148
 				{
1149
-					if( strtoupper($element->charset) != 'UTF-8') $element->text = preg_replace($sar,$rar,$element->text);
1149
+					if (strtoupper($element->charset) != 'UTF-8') $element->text = preg_replace($sar, $rar, $element->text);
1150 1150
 					// check if there is a possible nested encoding; make sure that the inputstring and the decoded result are different to avoid loops
1151
-					$openTags = substr_count($element->text,'?=');
1152
-					if(preg_match('/\?=.+=\?/', $element->text) && $openTags>0 && $openTags==substr_count($element->text,'=?') && $element->text != $_string)
1151
+					$openTags = substr_count($element->text, '?=');
1152
+					if (preg_match('/\?=.+=\?/', $element->text) && $openTags > 0 && $openTags == substr_count($element->text, '=?') && $element->text != $_string)
1153 1153
 					{
1154 1154
 						$element->text = self::decodeMailHeader($element->text, $element->charset);
1155 1155
 						$element->charset = $displayCharset;
1156 1156
 					}
1157
-					$newString .= self::convert($element->text,$element->charset);
1157
+					$newString .= self::convert($element->text, $element->charset);
1158 1158
 				}
1159 1159
 				else
1160 1160
 				{
@@ -1162,34 +1162,34 @@  discard block
 block discarded – undo
1162 1162
 					$convertAtEnd = true;
1163 1163
 				}
1164 1164
 			}
1165
-			if ($convertAtEnd) $newString = self::decodeMailHeader($newString,$displayCharset);
1166
-			return preg_replace('/([\000-\012\015\016\020-\037\075])/','',$newString);
1165
+			if ($convertAtEnd) $newString = self::decodeMailHeader($newString, $displayCharset);
1166
+			return preg_replace('/([\000-\012\015\016\020-\037\075])/', '', $newString);
1167 1167
 		}
1168
-		elseif(function_exists(mb_decode_mimeheader))
1168
+		elseif (function_exists(mb_decode_mimeheader))
1169 1169
 		{
1170 1170
 			$matches = null;
1171
-			if(preg_match_all('/=\?.*\?Q\?.*\?=/iU', $string=$_string, $matches))
1171
+			if (preg_match_all('/=\?.*\?Q\?.*\?=/iU', $string = $_string, $matches))
1172 1172
 			{
1173
-				foreach($matches[0] as $match)
1173
+				foreach ($matches[0] as $match)
1174 1174
 				{
1175 1175
 					$fixedMatch = str_replace('_', ' ', $match);
1176 1176
 					$string = str_replace($match, $fixedMatch, $string);
1177 1177
 				}
1178
-				$string = str_replace('=?ISO8859-','=?ISO-8859-',
1179
-					str_replace('=?windows-1258','=?ISO-8859-1',$string));
1178
+				$string = str_replace('=?ISO8859-', '=?ISO-8859-',
1179
+					str_replace('=?windows-1258', '=?ISO-8859-1', $string));
1180 1180
 			}
1181 1181
 			$string = mb_decode_mimeheader($string);
1182
-			return preg_replace('/([\000-\012\015\016\020-\037\075])/','',$string);
1182
+			return preg_replace('/([\000-\012\015\016\020-\037\075])/', '', $string);
1183 1183
 		}
1184
-		elseif(function_exists(iconv_mime_decode))
1184
+		elseif (function_exists(iconv_mime_decode))
1185 1185
 		{
1186 1186
 			// continue decoding also if an error occurs
1187 1187
 			$string = @iconv_mime_decode($_string, 2, $displayCharset);
1188
-			return preg_replace('/([\000-\012\015\016\020-\037\075])/','',$string);
1188
+			return preg_replace('/([\000-\012\015\016\020-\037\075])/', '', $string);
1189 1189
 		}
1190 1190
 
1191 1191
 		// no decoding function available
1192
-		return preg_replace('/([\000-\012\015\016\020-\037\075])/','',$_string);
1192
+		return preg_replace('/([\000-\012\015\016\020-\037\075])/', '', $_string);
1193 1193
 	}
1194 1194
 
1195 1195
 	/**
@@ -1202,15 +1202,15 @@  discard block
 block discarded – undo
1202 1202
 	{
1203 1203
 		//error_log($text);
1204 1204
 		//replace CRLF with something other to be preserved via preg_replace as CRLF seems to vanish
1205
-		$text = str_replace("\r\n",'<#cr-lf#>',$text);
1205
+		$text = str_replace("\r\n", '<#cr-lf#>', $text);
1206 1206
 		// replace emailaddresses eclosed in <> (eg.: <[email protected]>) with the emailaddress only (e.g: [email protected])
1207
-		$text = preg_replace("/(<|&lt;a href=\")*(mailto:([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","$2 ", $text);
1207
+		$text = preg_replace("/(<|&lt;a href=\")*(mailto:([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "$2 ", $text);
1208 1208
 		//$text = preg_replace_callback("/(<|&lt;a href=\")*(mailto:([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i",'self::transform_mailto2text',$text);
1209 1209
 		//$text = preg_replace('~<a[^>]+href=\"(mailto:)+([^"]+)\"[^>]*>~si','$2 ',$text);
1210
-		$text = preg_replace_callback('~<a[^>]+href=\"(mailto:)+([^"]+)\"[^>]*>([ @\w\.,-.,_.,0-9.]+)<\/a>~si','self::transform_mailto2text',$text);
1211
-		$text = preg_replace("/(([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))( |\s)*(<\/a>)*( |\s)*(>|&gt;)*/i","$1 ", $text);
1212
-		$text = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","$2 ", $text);
1213
-		$text = str_replace('<#cr-lf#>',"\r\n",$text);
1210
+		$text = preg_replace_callback('~<a[^>]+href=\"(mailto:)+([^"]+)\"[^>]*>([ @\w\.,-.,_.,0-9.]+)<\/a>~si', 'self::transform_mailto2text', $text);
1211
+		$text = preg_replace("/(([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))( |\s)*(<\/a>)*( |\s)*(>|&gt;)*/i", "$1 ", $text);
1212
+		$text = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "$2 ", $text);
1213
+		$text = str_replace('<#cr-lf#>', "\r\n", $text);
1214 1214
 		return 1;
1215 1215
 	}
1216 1216
 
@@ -1224,11 +1224,11 @@  discard block
 block discarded – undo
1224 1224
 	 *				or if you want the string to be matched as is
1225 1225
 	 * @return void the modified text is passed via reference
1226 1226
 	 */
1227
-	static function replaceTagsCompletley(&$_body,$tag,$endtag='',$addbracesforendtag=true)
1227
+	static function replaceTagsCompletley(&$_body, $tag, $endtag = '', $addbracesforendtag = true)
1228 1228
 	{
1229 1229
 		if ($tag) $tag = strtolower($tag);
1230 1230
 		$singleton = false;
1231
-		if ($endtag=='/>') $singleton =true;
1231
+		if ($endtag == '/>') $singleton = true;
1232 1232
 		if ($endtag == '' || empty($endtag) || !isset($endtag))
1233 1233
 		{
1234 1234
 			$endtag = $tag;
@@ -1241,31 +1241,31 @@  discard block
 block discarded – undo
1241 1241
 			if ($singleton)
1242 1242
 			{
1243 1243
 				//$_body = preg_replace('~<'.$tag.'[^>].*? '.$endtag.'~simU','',$_body);
1244
-				$_body = preg_replace('~<?'.$tag.'[^>].* '.$endtag.'~simU','',$_body); // we are in Ungreedy mode, so we expect * to be ungreedy without specifying ?
1244
+				$_body = preg_replace('~<?'.$tag.'[^>].* '.$endtag.'~simU', '', $_body); // we are in Ungreedy mode, so we expect * to be ungreedy without specifying ?
1245 1245
 			}
1246 1246
 			else
1247 1247
 			{
1248
-				$found=null;
1249
-				if ($addbracesforendtag === true )
1248
+				$found = null;
1249
+				if ($addbracesforendtag === true)
1250 1250
 				{
1251
-					if (stripos($_body,'<'.$tag)!==false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)</'.$endtag.'>#isU', $_body, $found);
1252
-					if ($ct>0)
1251
+					if (stripos($_body, '<'.$tag) !== false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)</'.$endtag.'>#isU', $_body, $found);
1252
+					if ($ct > 0)
1253 1253
 					{
1254 1254
 						//error_log(__METHOD__.__LINE__.array2string($found[0]));
1255 1255
 						// only replace what we have found
1256
-						$_body = str_ireplace($found[0],'',$_body);
1256
+						$_body = str_ireplace($found[0], '', $_body);
1257 1257
 					}
1258 1258
 					// remove left over tags, unfinished ones, and so on
1259
-					$_body = preg_replace('~<'.$tag.'[^>]*?>~si','',$_body);
1259
+					$_body = preg_replace('~<'.$tag.'[^>]*?>~si', '', $_body);
1260 1260
 				}
1261
-				if ($addbracesforendtag === false )
1261
+				if ($addbracesforendtag === false)
1262 1262
 				{
1263
-					if (stripos($_body,'<'.$tag)!==false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)'.$endtag.'#isU', $_body, $found);
1264
-					if ($ct>0)
1263
+					if (stripos($_body, '<'.$tag) !== false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)'.$endtag.'#isU', $_body, $found);
1264
+					if ($ct > 0)
1265 1265
 					{
1266 1266
 						//error_log(__METHOD__.__LINE__.array2string($found[0]));
1267 1267
 						// only replace what we have found
1268
-						$_body = str_ireplace($found[0],'',$_body);
1268
+						$_body = str_ireplace($found[0], '', $_body);
1269 1269
 					}
1270 1270
 /*
1271 1271
 					$_body = preg_replace('~<'.$tag.'[^>]*?>(.*?)'.$endtag.'~simU','',$_body);
@@ -1283,9 +1283,9 @@  discard block
 block discarded – undo
1283 1283
 		// this is the actual url
1284 1284
 		$matches[2] = trim(strip_tags($matches[2]));
1285 1285
 		$matches[3] = trim(strip_tags($matches[3]));
1286
-		$matches[2] = str_replace(array('%40','%20'),array('@',' '),$matches[2]);
1287
-		$matches[3] = str_replace(array('%40','%20'),array('@',' '),$matches[3]);
1288
-		return $matches[1].$matches[2].($matches[2]==$matches[3]?' ':' -> '.$matches[3].' ');
1286
+		$matches[2] = str_replace(array('%40', '%20'), array('@', ' '), $matches[2]);
1287
+		$matches[3] = str_replace(array('%40', '%20'), array('@', ' '), $matches[3]);
1288
+		return $matches[1].$matches[2].($matches[2] == $matches[3] ? ' ' : ' -> '.$matches[3].' ');
1289 1289
 	}
1290 1290
 
1291 1291
 	static function transform_url2text($matches)
@@ -1294,9 +1294,9 @@  discard block
 block discarded – undo
1294 1294
 		$linkTextislink = false;
1295 1295
 		// this is the actual url
1296 1296
 		$matches[2] = trim(strip_tags($matches[2]));
1297
-		if ($matches[2]==$matches[1]) $linkTextislink = true;
1298
-		$matches[1] = str_replace(' ','%20',$matches[1]);
1299
-		return ($linkTextislink?' ':'[ ').$matches[1].($linkTextislink?'':' -> '.$matches[2]).($linkTextislink?' ':' ]');
1297
+		if ($matches[2] == $matches[1]) $linkTextislink = true;
1298
+		$matches[1] = str_replace(' ', '%20', $matches[1]);
1299
+		return ($linkTextislink ? ' ' : '[ ').$matches[1].($linkTextislink ? '' : ' -> '.$matches[2]).($linkTextislink ? ' ' : ' ]');
1300 1300
 	}
1301 1301
 
1302 1302
 	/**
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 	 * @param bool $stripalltags : flag to indicate wether or not to strip $_html from all remaining tags
1308 1308
 	 * @return text $_html : the modified text.
1309 1309
 	 */
1310
-	static function convertHTMLToText($_html,$displayCharset=false,$stripcrl=false,$stripalltags=true)
1310
+	static function convertHTMLToText($_html, $displayCharset = false, $stripcrl = false, $stripalltags = true)
1311 1311
 	{
1312 1312
 		// assume input isHTML, but test the input anyway, because,
1313 1313
 		// if it is not, we may not want to strip whitespace
@@ -1323,27 +1323,27 @@  discard block
 block discarded – undo
1323 1323
 		#print "<pre>"; print htmlspecialchars($_html);
1324 1324
 		#print "</pre>";
1325 1325
 		#print "<hr>";
1326
-		if (stripos($_html,'style')!==false) self::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
1327
-		if (stripos($_html,'head')!==false) self::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
1328
-		if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) self::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
1329
-		if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) self::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
1330
-		$Rules = array ('@<script[^>]*?>.*?</script>@siU', // Strip out javascript
1331
-			'@&(quot|#34);@i',                // Replace HTML entities
1332
-			'@&(amp|#38);@i',                 //   Ampersand &
1333
-			'@&(lt|#60);@i',                  //   Less Than <
1334
-			'@&(gt|#62);@i',                  //   Greater Than >
1335
-			'@&(nbsp|#160);@i',               //   Non Breaking Space
1336
-			'@&(iexcl|#161);@i',              //   Inverted Exclamation point
1337
-			'@&(cent|#162);@i',               //   Cent
1338
-			'@&(pound|#163);@i',              //   Pound
1339
-			'@&(copy|#169);@i',               //   Copyright
1340
-			'@&(reg|#174);@i',                //   Registered
1341
-			'@&(trade|#8482);@i',             //   trade
1342
-			'@&#39;@i',                       //   singleQuote
1343
-			'@(\xc2\xa0)@',                   //   nbsp or tab (encoded windows-style)
1344
-			'@(\xe2\x80\x8b)@',               //   ZERO WIDTH SPACE
1326
+		if (stripos($_html, 'style') !== false) self::replaceTagsCompletley($_html, 'style'); // clean out empty or pagewide style definitions / left over tags
1327
+		if (stripos($_html, 'head') !== false) self::replaceTagsCompletley($_html, 'head'); // Strip out stuff in head
1328
+		if (stripos($_html, '![if') !== false && stripos($_html, '<![endif]>') !== false) self::replaceTagsCompletley($_html, '!\[if', '<!\[endif\]>', false); // Strip out stuff in ifs
1329
+		if (stripos($_html, '!--[if') !== false && stripos($_html, '<![endif]-->') !== false) self::replaceTagsCompletley($_html, '!--\[if', '<!\[endif\]-->', false); // Strip out stuff in ifs
1330
+		$Rules = array('@<script[^>]*?>.*?</script>@siU', // Strip out javascript
1331
+			'@&(quot|#34);@i', // Replace HTML entities
1332
+			'@&(amp|#38);@i', //   Ampersand &
1333
+			'@&(lt|#60);@i', //   Less Than <
1334
+			'@&(gt|#62);@i', //   Greater Than >
1335
+			'@&(nbsp|#160);@i', //   Non Breaking Space
1336
+			'@&(iexcl|#161);@i', //   Inverted Exclamation point
1337
+			'@&(cent|#162);@i', //   Cent
1338
+			'@&(pound|#163);@i', //   Pound
1339
+			'@&(copy|#169);@i', //   Copyright
1340
+			'@&(reg|#174);@i', //   Registered
1341
+			'@&(trade|#8482);@i', //   trade
1342
+			'@&#39;@i', //   singleQuote
1343
+			'@(\xc2\xa0)@', //   nbsp or tab (encoded windows-style)
1344
+			'@(\xe2\x80\x8b)@', //   ZERO WIDTH SPACE
1345 1345
 		);
1346
-		$Replace = array ('',
1346
+		$Replace = array('',
1347 1347
 			'"',
1348 1348
 			'#amper#sand#',
1349 1349
 			'<',
@@ -1352,9 +1352,9 @@  discard block
 block discarded – undo
1352 1352
 			chr(161),
1353 1353
 			chr(162),
1354 1354
 			chr(163),
1355
-			'(C)',//chr(169),// copyrighgt
1356
-			'(R)',//chr(174),// registered
1357
-			'(TM)',// trade
1355
+			'(C)', //chr(169),// copyrighgt
1356
+			'(R)', //chr(174),// registered
1357
+			'(TM)', // trade
1358 1358
 			"'",
1359 1359
 			' ',
1360 1360
 			'',
@@ -1362,27 +1362,27 @@  discard block
 block discarded – undo
1362 1362
 		$_html = preg_replace($Rules, $Replace, $_html);
1363 1363
 
1364 1364
 		//   removing carriage return linefeeds, preserve those enclosed in <pre> </pre> tags
1365
-		if ($stripcrl === true )
1365
+		if ($stripcrl === true)
1366 1366
 		{
1367
-			if (stripos($_html,'<pre ')!==false || stripos($_html,'<pre>')!==false)
1367
+			if (stripos($_html, '<pre ') !== false || stripos($_html, '<pre>') !== false)
1368 1368
 			{
1369 1369
 				$contentArr = html::splithtmlByPRE($_html);
1370 1370
 				foreach ($contentArr as $k =>&$elem)
1371 1371
 				{
1372
-					if (stripos($elem,'<pre ')===false && stripos($elem,'<pre>')===false)
1372
+					if (stripos($elem, '<pre ') === false && stripos($elem, '<pre>') === false)
1373 1373
 					{
1374 1374
 						//$elem = str_replace('@(\r\n)@i',' ',$elem);
1375
-						$elem = str_replace(array("\r\n","\n"),($isHTML?'':' '),$elem);
1375
+						$elem = str_replace(array("\r\n", "\n"), ($isHTML ? '' : ' '), $elem);
1376 1376
 					}
1377 1377
 				}
1378
-				$_html = implode('',$contentArr);
1378
+				$_html = implode('', $contentArr);
1379 1379
 			}
1380 1380
 			else
1381 1381
 			{
1382
-				$_html = str_replace(array("\r\n","\n"),($isHTML?'':' '),$_html);
1382
+				$_html = str_replace(array("\r\n", "\n"), ($isHTML ? '' : ' '), $_html);
1383 1383
 			}
1384 1384
 		}
1385
-		$tags = array (
1385
+		$tags = array(
1386 1386
 			0 => '~<h[123][^>]*>\r*\n*~si',
1387 1387
 			1 => '~<h[456][^>]*>\r*\n*~si',
1388 1388
 			2 => '~<table[^>]*>\r*\n*~si',
@@ -1403,7 +1403,7 @@  discard block
 block discarded – undo
1403 1403
 			17 => '/<([1234567890])/',
1404 1404
 			18 => '/>([1234567890])/',
1405 1405
 		);
1406
-		$Replace = array (
1406
+		$Replace = array(
1407 1407
 			0 => "\r\n",
1408 1408
 			1 => "\r\n",
1409 1409
 			2 => "\r\n",
@@ -1424,113 +1424,113 @@  discard block
 block discarded – undo
1424 1424
 			17 => '#lower#than#$1',
1425 1425
 			18 => '#greater#than#$1',
1426 1426
 		);
1427
-		$_html = preg_replace($tags,$Replace,$_html);
1427
+		$_html = preg_replace($tags, $Replace, $_html);
1428 1428
 		//error_log(__METHOD__.__LINE__.'#'.$_html);
1429
-		$_html = preg_replace('~</t(d|h)>\s*<t(d|h)[^>]*>~si',' - ',$_html);
1430
-		$_html = preg_replace('~<img[^>]+>~s','',$_html);
1429
+		$_html = preg_replace('~</t(d|h)>\s*<t(d|h)[^>]*>~si', ' - ', $_html);
1430
+		$_html = preg_replace('~<img[^>]+>~s', '', $_html);
1431 1431
 		// replace emailaddresses eclosed in <> (eg.: <[email protected]>) with the emailaddress only (e.g: [email protected])
1432 1432
 		self::replaceEmailAdresses($_html);
1433 1433
 		//convert hrefs to description -> URL
1434 1434
 		//$_html = preg_replace('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*)</a>~si','[$2 -> $1]',$_html);
1435
-		$_html = preg_replace_callback('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*?)</a>~si','self::transform_url2text',$_html);
1435
+		$_html = preg_replace_callback('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*?)</a>~si', 'self::transform_url2text', $_html);
1436 1436
 
1437 1437
 		// reducing double \r\n to single ones, dont mess with pre sections
1438 1438
 		if ($stripcrl === true && $isHTML)
1439 1439
 		{
1440
-			if (stripos($_html,'<pre ')!==false || stripos($_html,'<pre>')!==false)
1440
+			if (stripos($_html, '<pre ') !== false || stripos($_html, '<pre>') !== false)
1441 1441
 			{
1442 1442
 				$contentArr = html::splithtmlByPRE($_html);
1443 1443
 				foreach ($contentArr as $k =>&$elem)
1444 1444
 				{
1445
-					if (stripos($elem,'<pre ')===false && stripos($elem,'<pre>')===false)
1445
+					if (stripos($elem, '<pre ') === false && stripos($elem, '<pre>') === false)
1446 1446
 					{
1447 1447
 						//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
1448
-						if ( $stripalltags ) {
1449
-							$_html = preg_replace('~<[^>^@]+>~s','',$_html);
1448
+						if ($stripalltags) {
1449
+							$_html = preg_replace('~<[^>^@]+>~s', '', $_html);
1450 1450
 						}
1451 1451
 						// strip out whitespace inbetween CR/LF
1452 1452
 						$elem = preg_replace('~\r\n\s+\r\n~si', "\r\n\r\n", $elem);
1453 1453
 						// strip out / reduce exess CR/LF
1454
-						$elem = preg_replace('~\r\n{3,}~si',"\r\n\r\n",$elem);
1454
+						$elem = preg_replace('~\r\n{3,}~si', "\r\n\r\n", $elem);
1455 1455
 					}
1456 1456
 				}
1457
-				$_html = implode('',$contentArr);
1457
+				$_html = implode('', $contentArr);
1458 1458
 			}
1459 1459
 			else
1460 1460
 			{
1461 1461
 				//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
1462
-				if ( $stripalltags ) {
1463
-					$_html = preg_replace('~<[^>^@]+>~s','',$_html);
1462
+				if ($stripalltags) {
1463
+					$_html = preg_replace('~<[^>^@]+>~s', '', $_html);
1464 1464
 				}
1465 1465
 				// strip out whitespace inbetween CR/LF
1466 1466
 				$_html = preg_replace('~\r\n\s+\r\n~si', "\r\n\r\n", $_html);
1467 1467
 				// strip out / reduce exess CR/LF
1468
-				$_html = preg_replace('~(\r\n){3,}~si',"\r\n\r\n",$_html);
1468
+				$_html = preg_replace('~(\r\n){3,}~si', "\r\n\r\n", $_html);
1469 1469
 			}
1470 1470
 		}
1471 1471
 		//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
1472
-		if ( $stripalltags ) {
1473
-			$_html = preg_replace('~<[^>^@]+>~s','',$_html);
1472
+		if ($stripalltags) {
1473
+			$_html = preg_replace('~<[^>^@]+>~s', '', $_html);
1474 1474
 			//$_html = strip_tags($_html, '<a>');
1475 1475
 		}
1476 1476
 		// reducing spaces (not for input that was plain text from the beginning)
1477
-		if ($isHTML) $_html = preg_replace('~ +~s',' ',$_html);
1477
+		if ($isHTML) $_html = preg_replace('~ +~s', ' ', $_html);
1478 1478
 		// restoring ampersands
1479
-		$_html = str_replace('#amper#sand#','&',$_html);
1479
+		$_html = str_replace('#amper#sand#', '&', $_html);
1480 1480
 		// restoring lower|greater[or equal] than
1481
-		$_html = str_replace('#lowerorequal#than#','<=',$_html);
1482
-		$_html = str_replace('#greaterorequal#than#','>=',$_html);
1483
-		$_html = str_replace('#lower#than#','<',$_html);
1484
-		$_html = str_replace('#greater#than#','>',$_html);
1481
+		$_html = str_replace('#lowerorequal#than#', '<=', $_html);
1482
+		$_html = str_replace('#greaterorequal#than#', '>=', $_html);
1483
+		$_html = str_replace('#lower#than#', '<', $_html);
1484
+		$_html = str_replace('#greater#than#', '>', $_html);
1485 1485
 		//error_log(__METHOD__.__LINE__.' Charset:'.$displayCharset.' -> '.$_html);
1486 1486
 		$_html = html_entity_decode($_html, ENT_COMPAT, $displayCharset);
1487 1487
 		//error_log(__METHOD__.__LINE__.' Charset:'.$displayCharset.' After html_entity_decode: -> '.$_html);
1488 1488
 		//self::replaceEmailAdresses($_html);
1489 1489
 		$pos = strpos($_html, 'blockquote');
1490 1490
 		//error_log("convert HTML2Text: $_html");
1491
-		if($pos === false) {
1491
+		if ($pos === false) {
1492 1492
 			return $_html;
1493 1493
 		} else {
1494 1494
 			$indent = 0;
1495 1495
 			$indentString = '';
1496 1496
 
1497 1497
 			$quoteParts = preg_split('/#blockquote#type#cite#/', $_html, -1, PREG_SPLIT_OFFSET_CAPTURE);
1498
-			foreach($quoteParts as $quotePart) {
1499
-				if($quotePart[1] > 0) {
1498
+			foreach ($quoteParts as $quotePart) {
1499
+				if ($quotePart[1] > 0) {
1500 1500
 					$indent++;
1501 1501
 					$indentString .= '>';
1502 1502
 				}
1503 1503
 				$quoteParts2 = preg_split('/#blockquote#end#cite#/', $quotePart[0], -1, PREG_SPLIT_OFFSET_CAPTURE);
1504 1504
 
1505
-				foreach($quoteParts2 as $quotePart2) {
1506
-					if($quotePart2[1] > 0) {
1505
+				foreach ($quoteParts2 as $quotePart2) {
1506
+					if ($quotePart2[1] > 0) {
1507 1507
 						$indent--;
1508 1508
 						$indentString = substr($indentString, 0, $indent);
1509 1509
 					}
1510 1510
 
1511 1511
 					$quoteParts3 = explode("\r\n", $quotePart2[0]);
1512 1512
 
1513
-					foreach($quoteParts3 as $quotePart3) {
1513
+					foreach ($quoteParts3 as $quotePart3) {
1514 1514
 						//error_log(__METHOD__.__LINE__.'Line:'.$quotePart3);
1515
-						$allowedLength = 76-strlen("\r\n$indentString");
1515
+						$allowedLength = 76 - strlen("\r\n$indentString");
1516 1516
 						// only break lines, if not already indented
1517
-						if (substr($quotePart3,0,strlen($indentString)) != $indentString)
1517
+						if (substr($quotePart3, 0, strlen($indentString)) != $indentString)
1518 1518
 						{
1519 1519
 							if (strlen($quotePart3) > $allowedLength) {
1520
-								$s=explode(" ", $quotePart3);
1520
+								$s = explode(" ", $quotePart3);
1521 1521
 								$quotePart3 = "";
1522 1522
 								$linecnt = 0;
1523 1523
 								foreach ($s as $k=>$v) {
1524 1524
 									$cnt = strlen($v);
1525 1525
 									// only break long words within the wordboundaries,
1526 1526
 									// but it may destroy links, so we check for href and dont do it if we find it
1527
-									if($cnt > $allowedLength && stripos($v,'href=')===false) {
1527
+									if ($cnt > $allowedLength && stripos($v, 'href=') === false) {
1528 1528
 										//error_log(__METHOD__.__LINE__.'LongWordFound:'.$v);
1529
-										$v=wordwrap($v, $allowedLength, "\r\n$indentString", true);
1529
+										$v = wordwrap($v, $allowedLength, "\r\n$indentString", true);
1530 1530
 									}
1531 1531
 									// the rest should be broken at the start of the new word that exceeds the limit
1532
-									if ($linecnt+$cnt > $allowedLength) {
1533
-										$v="\r\n$indentString$v";
1532
+									if ($linecnt + $cnt > $allowedLength) {
1533
+										$v = "\r\n$indentString$v";
1534 1534
 										//error_log(__METHOD__.__LINE__.'breaking here:'.$v);
1535 1535
 										$linecnt = 0;
1536 1536
 									} else {
@@ -1541,11 +1541,11 @@  discard block
 block discarded – undo
1541 1541
 							}
1542 1542
 						}
1543 1543
 						//error_log(__METHOD__.__LINE__.'partString to return:'.$indentString . $quotePart3);
1544
-						$asciiTextBuff[] = $indentString . $quotePart3 ;
1544
+						$asciiTextBuff[] = $indentString.$quotePart3;
1545 1545
 					}
1546 1546
 				}
1547 1547
 			}
1548
-			return implode("\r\n",$asciiTextBuff);
1548
+			return implode("\r\n", $asciiTextBuff);
1549 1549
 		}
1550 1550
 	}
1551 1551
 }
Please login to merge, or discard this patch.
Braces   +222 added lines, -63 removed lines patch added patch discarded remove patch
@@ -124,17 +124,23 @@  discard block
 block discarded – undo
124 124
 			}
125 125
 			return $charsets[$lang];
126 126
 		}
127
-		if (self::$system_charset)	// do we have a system-charset ==> return it
127
+		if (self::$system_charset)
128
+		{
129
+			// do we have a system-charset ==> return it
128 130
 		{
129 131
 			$charset = self::$system_charset;
130 132
 		}
133
+		}
131 134
 		else
132 135
 		{
133 136
 			// if no translations are loaded (system-startup) use a default, else lang('charset')
134 137
 			$charset = !self::$lang_arr ? 'utf-8' : strtolower(self::translate('charset'));
135 138
 		}
136 139
 		// in case no charset is set, default to utf-8
137
-		if (empty($charset) || $charset == 'charset') $charset = 'utf-8';
140
+		if (empty($charset) || $charset == 'charset')
141
+		{
142
+			$charset = 'utf-8';
143
+		}
138 144
 
139 145
 		// we need to set our charset as mbstring.internal_encoding if mbstring.func_overlaod > 0
140 146
 		// else we get problems for a charset is different from the default utf-8
@@ -193,8 +199,14 @@  discard block
 block discarded – undo
193 199
 			}
194 200
 			$apps = array('common');
195 201
 			// for eTemplate apps, load etemplate before app itself (allowing app to overwrite etemplate translations)
196
-			if (class_exists('etemplate_new', false) || class_exists('etemplate', false)) $apps[] = 'etemplate';
197
-			if ($GLOBALS['egw_info']['flags']['currentapp']) $apps[] = $GLOBALS['egw_info']['flags']['currentapp'];
202
+			if (class_exists('etemplate_new', false) || class_exists('etemplate', false))
203
+			{
204
+				$apps[] = 'etemplate';
205
+			}
206
+			if ($GLOBALS['egw_info']['flags']['currentapp'])
207
+			{
208
+				$apps[] = $GLOBALS['egw_info']['flags']['currentapp'];
209
+			}
198 210
 			// load instance specific translations last, so they can overwrite everything
199 211
 			$apps[] = 'custom';
200 212
 			self::add_app($apps);
@@ -222,7 +234,10 @@  discard block
 block discarded – undo
222 234
 			self::init();
223 235
 		}
224 236
 		$ret = $key;				// save key if we dont find a translation
225
-		if ($not_found) $ret .= $not_found;
237
+		if ($not_found)
238
+		{
239
+			$ret .= $not_found;
240
+		}
226 241
 
227 242
 		if (isset(self::$lang_arr[$key]))
228 243
 		{
@@ -269,9 +284,15 @@  discard block
 block discarded – undo
269 284
 	{
270 285
 		//error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr));
271 286
 		//$start = microtime(true);
272
-		if (!$lang) $lang = self::$userlang;
287
+		if (!$lang)
288
+		{
289
+			$lang = self::$userlang;
290
+		}
273 291
 		$tree_level = $instance_level = array();
274
-		if (!is_array($apps)) $apps = (array)$apps;
292
+		if (!is_array($apps))
293
+		{
294
+			$apps = (array)$apps;
295
+		}
275 296
 		foreach($apps as $key => $app)
276 297
 		{
277 298
 			if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common')
@@ -291,8 +312,14 @@  discard block
 block discarded – undo
291 312
 			}
292 313
 		}
293 314
 		// load all translations from cache at once
294
-		if ($tree_level) $tree_level = egw_cache::getTree(__CLASS__, $tree_level);
295
-		if ($instance_level) $instance_level = egw_cache::getInstance(__CLASS__, $instance_level);
315
+		if ($tree_level)
316
+		{
317
+			$tree_level = egw_cache::getTree(__CLASS__, $tree_level);
318
+		}
319
+		if ($instance_level)
320
+		{
321
+			$instance_level = egw_cache::getInstance(__CLASS__, $instance_level);
322
+		}
296 323
 
297 324
 		// merging loaded translations together
298 325
 		$updated_load_via = false;
@@ -359,7 +386,10 @@  discard block
 block discarded – undo
359 386
 	static function &load_app($app,$lang)
360 387
 	{
361 388
 		//$start = microtime(true);
362
-		if (is_null(self::$db)) self::init(false);
389
+		if (is_null(self::$db))
390
+		{
391
+			self::init(false);
392
+		}
363 393
 		$loaded = array();
364 394
 		foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array(
365 395
 			'lang'		=> $lang,
@@ -465,7 +495,10 @@  discard block
 block discarded – undo
465 495
 				$cache['']['en'] = count($en_phrases);
466 496
 				foreach(array_keys(self::get_available_langs()) as $lang)
467 497
 				{
468
-					if ($lang == 'en') continue;
498
+					if ($lang == 'en')
499
+					{
500
+						continue;
501
+					}
469 502
 					$lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps'));
470 503
 					$valid_phrases = array_intersect($lang_phrases, $en_phrases);
471 504
 					$cache[''][$lang] = count($valid_phrases);
@@ -482,7 +515,10 @@  discard block
 block discarded – undo
482 515
 						continue;
483 516
 					}
484 517
 					$en_phrases = array_keys(self::load_app_files(null, 'en', $app));
485
-					if (count($en_phrases) <= 2) continue;
518
+					if (count($en_phrases) <= 2)
519
+					{
520
+						continue;
521
+					}
486 522
 					$cache['en'][$app] = count($en_phrases);
487 523
 					$lang_phrases = array_keys(self::load_app_files(null, $_lang, $app));
488 524
 					$valid_phrases = array_intersect($lang_phrases, $en_phrases);
@@ -514,7 +550,10 @@  discard block
 block discarded – undo
514 550
 			// check if cache is NOT invalided by checking if we have a modification time for concerned lang-file
515 551
 			$time = egw_cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang));
516 552
 			// if we dont have one, cache has been invalidated and we need to load translations
517
-			if (!isset($time)) self::add_app($_app, $_lang);
553
+			if (!isset($time))
554
+			{
555
+				self::add_app($_app, $_lang);
556
+			}
518 557
 
519 558
 			$etag = self::max_lang_time();
520 559
 		}
@@ -566,7 +605,11 @@  discard block
 block discarded – undo
566 605
 		$loaded = array();
567 606
 		foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir)
568 607
 		{
569
-			if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root
608
+			if ($load_app == 'all-apps' && $app_dir=='..')
609
+			{
610
+				continue;
611
+			}
612
+			// do not try to break out of egw server root
570 613
 			if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) ||
571 614
 				!@file_exists($file=self::get_lang_file($app_dir, $lang)) ||
572 615
 				!($f = fopen($file, 'r')))
@@ -585,9 +628,15 @@  discard block
 block discarded – undo
585 628
 			{
586 629
 				$line = explode("\t", trim($read));
587 630
 				++$line_nr;
588
-				if (count($line) != 4) continue;
631
+				if (count($line) != 4)
632
+				{
633
+					continue;
634
+				}
589 635
 				list($l_id,$l_app,$l_lang,$l_translation) = $line;
590
-				if ($l_lang != $lang) continue;
636
+				if ($l_lang != $lang)
637
+				{
638
+					continue;
639
+				}
591 640
 				if (!isset($just_app_file) && $l_app != $app)
592 641
 				{
593 642
 					// check if $l_app contained in file in $app_dir is mentioned in $load_via
@@ -601,8 +650,14 @@  discard block
 block discarded – undo
601 650
 						}
602 651
 						// if not update load_via accordingly and store it as config
603 652
 						//error_log(__METHOD__."() load_via does not contain $l_app => $app_dir");
604
-						if (!isset(self::$load_via[$l_app])) self::$load_via[$l_app] = array($l_app);
605
-						if (!is_array(self::$load_via[$l_app])) self::$load_via[$l_app] = array(self::$load_via[$l_app]);
653
+						if (!isset(self::$load_via[$l_app]))
654
+						{
655
+							self::$load_via[$l_app] = array($l_app);
656
+						}
657
+						if (!is_array(self::$load_via[$l_app]))
658
+						{
659
+							self::$load_via[$l_app] = array(self::$load_via[$l_app]);
660
+						}
606 661
 						self::$load_via[$l_app][] = $app_dir;
607 662
 						$updated_load_via = true;
608 663
 					}
@@ -669,7 +724,10 @@  discard block
 block discarded – undo
669 724
 
670 725
 			if ($translate)
671 726
 			{
672
-				if (is_null(self::$db)) self::init(false);
727
+				if (is_null(self::$db))
728
+				{
729
+					self::init(false);
730
+				}
673 731
 
674 732
 				foreach(self::$langs as $lang => $name)
675 733
 				{
@@ -702,10 +760,13 @@  discard block
 block discarded – undo
702 760
 	 */
703 761
 	static function lang2language($lang)
704 762
 	{
705
-		if (isset(self::$langs[$lang]))	// no need to query the DB
763
+		if (isset(self::$langs[$lang]))
764
+		{
765
+			// no need to query the DB
706 766
 		{
707 767
 			return self::$langs[$lang];
708 768
 		}
769
+		}
709 770
 		return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn();
710 771
 	}
711 772
 
@@ -744,7 +805,10 @@  discard block
 block discarded – undo
744 805
 	 */
745 806
 	static function get_lang_file($app,$lang)
746 807
 	{
747
-		if ($app == 'common') $app = 'phpgwapi';
808
+		if ($app == 'common')
809
+		{
810
+			$app = 'phpgwapi';
811
+		}
748 812
 		return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION;
749 813
 	}
750 814
 
@@ -807,9 +871,15 @@  discard block
 block discarded – undo
807 871
 	{
808 872
 		if ($check_to_from)
809 873
 		{
810
-			if ($from) $from = strtolower($from);
874
+			if ($from)
875
+			{
876
+				$from = strtolower($from);
877
+			}
811 878
 
812
-			if ($to) $to = strtolower($to);
879
+			if ($to)
880
+			{
881
+				$to = strtolower($to);
882
+			}
813 883
 
814 884
 			if (!$from)
815 885
 			{
@@ -934,7 +1004,10 @@  discard block
 block discarded – undo
934 1004
 	 */
935 1005
 	static function convert_jsonsafe($data,$from=False)
936 1006
 	{
937
-		if ($from===false) $from = self::detect_encoding($data);
1007
+		if ($from===false)
1008
+		{
1009
+			$from = self::detect_encoding($data);
1010
+		}
938 1011
 		$data = self::convert($data,strtolower($from));
939 1012
 		// in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct
940 1013
 		if (strtoupper(self::charset()) == 'UTF-8')
@@ -1031,8 +1104,14 @@  discard block
 block discarded – undo
1031 1104
 	static function get_message_id($translation,$app=null,$lang=null)
1032 1105
 	{
1033 1106
 		$where = array('content '.self::$db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation));
1034
-		if ($app) $where['app_name'] = $app;
1035
-		if ($lang) $where['lang'] = $lang;
1107
+		if ($app)
1108
+		{
1109
+			$where['app_name'] = $app;
1110
+		}
1111
+		if ($lang)
1112
+		{
1113
+			$where['lang'] = $lang;
1114
+		}
1036 1115
 
1037 1116
 		$id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn();
1038 1117
 
@@ -1040,7 +1119,8 @@  discard block
 block discarded – undo
1040 1119
 		if(!$id)
1041 1120
 		{
1042 1121
 			$lang_arr = self::$lang_arr;	// PHP 5.3 does NOT allow to use class scope / self in closure
1043
-			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation, $lang_arr) {
1122
+			$ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation, $lang_arr)
1123
+			{
1044 1124
 				return stripos($lang_arr[$haystack],$translation) !== false;
1045 1125
 			});
1046 1126
 			$id = array_shift($ids);
@@ -1057,10 +1137,17 @@  discard block
 block discarded – undo
1057 1137
 				}
1058 1138
 
1059 1139
 				// load all translations from cache at once
1060
-				if ($tree_level) $lang_arr = egw_cache::getTree(__CLASS__, $tree_level);
1061
-				if ($instance_level) $lang_arr = egw_cache::getInstance(__CLASS__, $instance_level);
1140
+				if ($tree_level)
1141
+				{
1142
+					$lang_arr = egw_cache::getTree(__CLASS__, $tree_level);
1143
+				}
1144
+				if ($instance_level)
1145
+				{
1146
+					$lang_arr = egw_cache::getInstance(__CLASS__, $instance_level);
1147
+				}
1062 1148
 				$lang_arr = $lang_arr[$app.':en'];
1063
-				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) {
1149
+				$ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr)
1150
+				{
1064 1151
 					return stripos($lang_arr[$haystack],$translation) !== false;
1065 1152
 				});
1066 1153
 				$id = array_shift($ids);
@@ -1084,7 +1171,10 @@  discard block
 block discarded – undo
1084 1171
 		{
1085 1172
 			$list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended
1086 1173
 
1087
-			if ($verify) array_unshift($list, $verify);
1174
+			if ($verify)
1175
+			{
1176
+				array_unshift($list, $verify);
1177
+			}
1088 1178
 
1089 1179
 			foreach ($list as $item)
1090 1180
 			{
@@ -1143,10 +1233,16 @@  discard block
 block discarded – undo
1143 1233
 			$convertAtEnd = false;
1144 1234
 			foreach((array)$elements as $element)
1145 1235
 			{
1146
-				if ($element->charset == 'default') $element->charset = self::detect_encoding($element->text);
1236
+				if ($element->charset == 'default')
1237
+				{
1238
+					$element->charset = self::detect_encoding($element->text);
1239
+				}
1147 1240
 				if ($element->charset != 'x-unknown')
1148 1241
 				{
1149
-					if( strtoupper($element->charset) != 'UTF-8') $element->text = preg_replace($sar,$rar,$element->text);
1242
+					if( strtoupper($element->charset) != 'UTF-8')
1243
+					{
1244
+						$element->text = preg_replace($sar,$rar,$element->text);
1245
+					}
1150 1246
 					// check if there is a possible nested encoding; make sure that the inputstring and the decoded result are different to avoid loops
1151 1247
 					$openTags = substr_count($element->text,'?=');
1152 1248
 					if(preg_match('/\?=.+=\?/', $element->text) && $openTags>0 && $openTags==substr_count($element->text,'=?') && $element->text != $_string)
@@ -1162,7 +1258,10 @@  discard block
 block discarded – undo
1162 1258
 					$convertAtEnd = true;
1163 1259
 				}
1164 1260
 			}
1165
-			if ($convertAtEnd) $newString = self::decodeMailHeader($newString,$displayCharset);
1261
+			if ($convertAtEnd)
1262
+			{
1263
+				$newString = self::decodeMailHeader($newString,$displayCharset);
1264
+			}
1166 1265
 			return preg_replace('/([\000-\012\015\016\020-\037\075])/','',$newString);
1167 1266
 		}
1168 1267
 		elseif(function_exists(mb_decode_mimeheader))
@@ -1226,18 +1325,27 @@  discard block
 block discarded – undo
1226 1325
 	 */
1227 1326
 	static function replaceTagsCompletley(&$_body,$tag,$endtag='',$addbracesforendtag=true)
1228 1327
 	{
1229
-		if ($tag) $tag = strtolower($tag);
1328
+		if ($tag)
1329
+		{
1330
+			$tag = strtolower($tag);
1331
+		}
1230 1332
 		$singleton = false;
1231
-		if ($endtag=='/>') $singleton =true;
1333
+		if ($endtag=='/>')
1334
+		{
1335
+			$singleton =true;
1336
+		}
1232 1337
 		if ($endtag == '' || empty($endtag) || !isset($endtag))
1233 1338
 		{
1234 1339
 			$endtag = $tag;
1235
-		} else {
1340
+		}
1341
+		else
1342
+		{
1236 1343
 			$endtag = strtolower($endtag);
1237 1344
 			//error_log(__METHOD__.' Using EndTag:'.$endtag);
1238 1345
 		}
1239 1346
 		// strip tags out of the message completely with their content
1240
-		if ($_body) {
1347
+		if ($_body)
1348
+		{
1241 1349
 			if ($singleton)
1242 1350
 			{
1243 1351
 				//$_body = preg_replace('~<'.$tag.'[^>].*? '.$endtag.'~simU','',$_body);
@@ -1248,7 +1356,10 @@  discard block
 block discarded – undo
1248 1356
 				$found=null;
1249 1357
 				if ($addbracesforendtag === true )
1250 1358
 				{
1251
-					if (stripos($_body,'<'.$tag)!==false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)</'.$endtag.'>#isU', $_body, $found);
1359
+					if (stripos($_body,'<'.$tag)!==false)
1360
+					{
1361
+						$ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)</'.$endtag.'>#isU', $_body, $found);
1362
+					}
1252 1363
 					if ($ct>0)
1253 1364
 					{
1254 1365
 						//error_log(__METHOD__.__LINE__.array2string($found[0]));
@@ -1260,7 +1371,10 @@  discard block
 block discarded – undo
1260 1371
 				}
1261 1372
 				if ($addbracesforendtag === false )
1262 1373
 				{
1263
-					if (stripos($_body,'<'.$tag)!==false)  $ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)'.$endtag.'#isU', $_body, $found);
1374
+					if (stripos($_body,'<'.$tag)!==false)
1375
+					{
1376
+						$ct = preg_match_all('#<'.$tag.'(?:\s.*)?>(.+)'.$endtag.'#isU', $_body, $found);
1377
+					}
1264 1378
 					if ($ct>0)
1265 1379
 					{
1266 1380
 						//error_log(__METHOD__.__LINE__.array2string($found[0]));
@@ -1294,7 +1408,10 @@  discard block
 block discarded – undo
1294 1408
 		$linkTextislink = false;
1295 1409
 		// this is the actual url
1296 1410
 		$matches[2] = trim(strip_tags($matches[2]));
1297
-		if ($matches[2]==$matches[1]) $linkTextislink = true;
1411
+		if ($matches[2]==$matches[1])
1412
+		{
1413
+			$linkTextislink = true;
1414
+		}
1298 1415
 		$matches[1] = str_replace(' ','%20',$matches[1]);
1299 1416
 		return ($linkTextislink?' ':'[ ').$matches[1].($linkTextislink?'':' -> '.$matches[2]).($linkTextislink?' ':' ]');
1300 1417
 	}
@@ -1317,16 +1434,35 @@  discard block
 block discarded – undo
1317 1434
 			$isHTML = false;
1318 1435
 			// return $_html; // maybe we should not proceed at all
1319 1436
 		}
1320
-		if ($displayCharset === false) $displayCharset = self::$system_charset;
1437
+		if ($displayCharset === false)
1438
+		{
1439
+			$displayCharset = self::$system_charset;
1440
+		}
1321 1441
 		//error_log(__METHOD__.$_html);
1322 1442
 		#print '<hr>';
1323 1443
 		#print "<pre>"; print htmlspecialchars($_html);
1324 1444
 		#print "</pre>";
1325 1445
 		#print "<hr>";
1326
-		if (stripos($_html,'style')!==false) self::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
1327
-		if (stripos($_html,'head')!==false) self::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
1328
-		if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) self::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
1329
-		if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) self::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
1446
+		if (stripos($_html,'style')!==false)
1447
+		{
1448
+			self::replaceTagsCompletley($_html,'style');
1449
+		}
1450
+		// clean out empty or pagewide style definitions / left over tags
1451
+		if (stripos($_html,'head')!==false)
1452
+		{
1453
+			self::replaceTagsCompletley($_html,'head');
1454
+		}
1455
+		// Strip out stuff in head
1456
+		if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false)
1457
+		{
1458
+			self::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false);
1459
+		}
1460
+		// Strip out stuff in ifs
1461
+		if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false)
1462
+		{
1463
+			self::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false);
1464
+		}
1465
+		// Strip out stuff in ifs
1330 1466
 		$Rules = array ('@<script[^>]*?>.*?</script>@siU', // Strip out javascript
1331 1467
 			'@&(quot|#34);@i',                // Replace HTML entities
1332 1468
 			'@&(amp|#38);@i',                 //   Ampersand &
@@ -1445,7 +1581,8 @@  discard block
 block discarded – undo
1445 1581
 					if (stripos($elem,'<pre ')===false && stripos($elem,'<pre>')===false)
1446 1582
 					{
1447 1583
 						//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
1448
-						if ( $stripalltags ) {
1584
+						if ( $stripalltags )
1585
+						{
1449 1586
 							$_html = preg_replace('~<[^>^@]+>~s','',$_html);
1450 1587
 						}
1451 1588
 						// strip out whitespace inbetween CR/LF
@@ -1459,7 +1596,8 @@  discard block
 block discarded – undo
1459 1596
 			else
1460 1597
 			{
1461 1598
 				//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
1462
-				if ( $stripalltags ) {
1599
+				if ( $stripalltags )
1600
+				{
1463 1601
 					$_html = preg_replace('~<[^>^@]+>~s','',$_html);
1464 1602
 				}
1465 1603
 				// strip out whitespace inbetween CR/LF
@@ -1469,12 +1607,16 @@  discard block
 block discarded – undo
1469 1607
 			}
1470 1608
 		}
1471 1609
 		//this is supposed to strip out all remaining stuff in tags, this is sometimes taking out whole sections off content
1472
-		if ( $stripalltags ) {
1610
+		if ( $stripalltags )
1611
+		{
1473 1612
 			$_html = preg_replace('~<[^>^@]+>~s','',$_html);
1474 1613
 			//$_html = strip_tags($_html, '<a>');
1475 1614
 		}
1476 1615
 		// reducing spaces (not for input that was plain text from the beginning)
1477
-		if ($isHTML) $_html = preg_replace('~ +~s',' ',$_html);
1616
+		if ($isHTML)
1617
+		{
1618
+			$_html = preg_replace('~ +~s',' ',$_html);
1619
+		}
1478 1620
 		// restoring ampersands
1479 1621
 		$_html = str_replace('#amper#sand#','&',$_html);
1480 1622
 		// restoring lower|greater[or equal] than
@@ -1488,55 +1630,72 @@  discard block
 block discarded – undo
1488 1630
 		//self::replaceEmailAdresses($_html);
1489 1631
 		$pos = strpos($_html, 'blockquote');
1490 1632
 		//error_log("convert HTML2Text: $_html");
1491
-		if($pos === false) {
1633
+		if($pos === false)
1634
+		{
1492 1635
 			return $_html;
1493
-		} else {
1636
+		}
1637
+		else
1638
+		{
1494 1639
 			$indent = 0;
1495 1640
 			$indentString = '';
1496 1641
 
1497 1642
 			$quoteParts = preg_split('/#blockquote#type#cite#/', $_html, -1, PREG_SPLIT_OFFSET_CAPTURE);
1498
-			foreach($quoteParts as $quotePart) {
1499
-				if($quotePart[1] > 0) {
1643
+			foreach($quoteParts as $quotePart)
1644
+			{
1645
+				if($quotePart[1] > 0)
1646
+				{
1500 1647
 					$indent++;
1501 1648
 					$indentString .= '>';
1502 1649
 				}
1503 1650
 				$quoteParts2 = preg_split('/#blockquote#end#cite#/', $quotePart[0], -1, PREG_SPLIT_OFFSET_CAPTURE);
1504 1651
 
1505
-				foreach($quoteParts2 as $quotePart2) {
1506
-					if($quotePart2[1] > 0) {
1652
+				foreach($quoteParts2 as $quotePart2)
1653
+				{
1654
+					if($quotePart2[1] > 0)
1655
+					{
1507 1656
 						$indent--;
1508 1657
 						$indentString = substr($indentString, 0, $indent);
1509 1658
 					}
1510 1659
 
1511 1660
 					$quoteParts3 = explode("\r\n", $quotePart2[0]);
1512 1661
 
1513
-					foreach($quoteParts3 as $quotePart3) {
1662
+					foreach($quoteParts3 as $quotePart3)
1663
+					{
1514 1664
 						//error_log(__METHOD__.__LINE__.'Line:'.$quotePart3);
1515 1665
 						$allowedLength = 76-strlen("\r\n$indentString");
1516 1666
 						// only break lines, if not already indented
1517 1667
 						if (substr($quotePart3,0,strlen($indentString)) != $indentString)
1518 1668
 						{
1519
-							if (strlen($quotePart3) > $allowedLength) {
1669
+							if (strlen($quotePart3) > $allowedLength)
1670
+							{
1520 1671
 								$s=explode(" ", $quotePart3);
1521 1672
 								$quotePart3 = "";
1522 1673
 								$linecnt = 0;
1523
-								foreach ($s as $k=>$v) {
1674
+								foreach ($s as $k=>$v)
1675
+								{
1524 1676
 									$cnt = strlen($v);
1525 1677
 									// only break long words within the wordboundaries,
1526 1678
 									// but it may destroy links, so we check for href and dont do it if we find it
1527
-									if($cnt > $allowedLength && stripos($v,'href=')===false) {
1679
+									if($cnt > $allowedLength && stripos($v,'href=')===false)
1680
+									{
1528 1681
 										//error_log(__METHOD__.__LINE__.'LongWordFound:'.$v);
1529 1682
 										$v=wordwrap($v, $allowedLength, "\r\n$indentString", true);
1530 1683
 									}
1531 1684
 									// the rest should be broken at the start of the new word that exceeds the limit
1532
-									if ($linecnt+$cnt > $allowedLength) {
1685
+									if ($linecnt+$cnt > $allowedLength)
1686
+									{
1533 1687
 										$v="\r\n$indentString$v";
1534 1688
 										//error_log(__METHOD__.__LINE__.'breaking here:'.$v);
1535 1689
 										$linecnt = 0;
1536
-									} else {
1690
+									}
1691
+									else
1692
+									{
1537 1693
 										$linecnt += $cnt;
1538 1694
 									}
1539
-									if (strlen($v))  $quotePart3 .= (strlen($quotePart3) ? " " : "").$v;
1695
+									if (strlen($v))
1696
+									{
1697
+										$quotePart3 .= (strlen($quotePart3) ? " " : "").$v;
1698
+									}
1540 1699
 								}
1541 1700
 							}
1542 1701
 						}
Please login to merge, or discard this patch.
phpgwapi/inc/class.uiaccountsel.inc.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@
 block discarded – undo
80 80
 	 *  Or a string which gets added as first Option with value='', eg. lang('all'), can also be specified in the array with key ''
81 81
 	 * @param boolean $nohtml if true, returns an array with the key 'selected' as the selected participants,
82 82
 	 *  and with the key 'participants' as the participants data as would fit in a select.
83
-	 * @param callback $label_callback=null callback to fetch a label for non-accounts
83
+	 * @param callback $label_callback callback to fetch a label for non-accounts
84 84
 	 * @return string/array string with html for !$nohtml, array('selected' => $selected,'participants' => $select)
85 85
 	 */
86 86
 	function selection($name,$element_id,$selected,$use='accounts',$lines=0,$not=False,$options='',$onchange='',$select=False,$nohtml=false,$label_callback=null)
Please login to merge, or discard this patch.
Spacing   +135 added lines, -137 removed lines patch added patch discarded remove patch
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 	 * @param callback $label_callback=null callback to fetch a label for non-accounts
84 84
 	 * @return string/array string with html for !$nohtml, array('selected' => $selected,'participants' => $select)
85 85
 	 */
86
-	function selection($name,$element_id,$selected,$use='accounts',$lines=0,$not=False,$options='',$onchange='',$select=False,$nohtml=false,$label_callback=null)
86
+	function selection($name, $element_id, $selected, $use = 'accounts', $lines = 0, $not = False, $options = '', $onchange = '', $select = False, $nohtml = false, $label_callback = null)
87 87
 	{
88 88
 		//error_log(__METHOD__."('$name',".array2string($selected).",'$use',rows=$lines,$not,'$options','$onchange',".array2string($select).",$nohtml,$label_callback) account_selection=$this->account_selection");
89
-		$multi_size=4;
89
+		$multi_size = 4;
90 90
 		if ($lines < 0)
91 91
 		{
92 92
 			$multi_size = abs($lines);
@@ -98,20 +98,20 @@  discard block
 block discarded – undo
98 98
 
99 99
 		if ($this->account_selection == 'none')	// dont show user-selection at all!
100 100
 		{
101
-			return html::input_hidden($name,$selected);
101
+			return html::input_hidden($name, $selected);
102 102
 		}
103 103
 		if (!is_array($selected))
104 104
 		{
105
-			$selected = $selected ? explode(',',$selected) : array();
105
+			$selected = $selected ? explode(',', $selected) : array();
106 106
 		}
107 107
 		$account_sel = $this->account_selection;
108 108
 		$app = False;
109
-		switch($use)
109
+		switch ($use)
110 110
 		{
111 111
 			default:
112
-				if (substr($use,-1) == '+')
112
+				if (substr($use, -1) == '+')
113 113
 				{
114
-					$app = substr($use,0,-1);
114
+					$app = substr($use, 0, -1);
115 115
 					$use = 'both';
116 116
 				}
117 117
 				else
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 
132 132
 			case 'owngroups':
133 133
 				$only_groups = true;
134
-				$account_sel = 'selectbox';	// groups always use only the selectbox
134
+				$account_sel = 'selectbox'; // groups always use only the selectbox
135 135
 				break;
136 136
 		}
137 137
 		$extra_label = is_string($select) && !empty($select) ? $select : False;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 			$extra_label = $select[''];
141 141
 			unset($select['']);
142 142
 		}
143
-		switch($account_sel)
143
+		switch ($account_sel)
144 144
 		{
145 145
 			case 'popup':
146 146
 				$select = $selected;
@@ -154,23 +154,23 @@  discard block
 block discarded – undo
154 154
 				}
155 155
 				else
156 156
 				{
157
-					$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
157
+					$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true);
158 158
 				}
159 159
 				$select = count($selected) && !isset($selected[0]) ? array_keys($selected) : $selected;
160
-				foreach($memberships as $gid)
160
+				foreach ($memberships as $gid)
161 161
 				{
162
-					foreach((array)$this->accounts->members($gid,true) as $member)
162
+					foreach ((array)$this->accounts->members($gid, true) as $member)
163 163
 					{
164
-						if (!in_array($member,$select) && $this->accounts->is_active($member)) $select[] = $member;
164
+						if (!in_array($member, $select) && $this->accounts->is_active($member)) $select[] = $member;
165 165
 					}
166 166
 				}
167 167
 				if ($use == 'both')	// show all memberships
168 168
 				{
169 169
 					if ($account_sel == 'primary_group')
170 170
 					{
171
-						$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
171
+						$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true);
172 172
 					}
173
-					$select = array_merge($select,$memberships);
173
+					$select = array_merge($select, $memberships);
174 174
 				}
175 175
 				break;
176 176
 
@@ -181,14 +181,14 @@  discard block
 block discarded – undo
181 181
 					$select = $GLOBALS['egw']->accounts->search(array(
182 182
 						'type' => $use,
183 183
 						'app' => $app,
184
-						'active' => true,	// return only active accounts
184
+						'active' => true, // return only active accounts
185 185
 					));
186 186
 					//error_log(__METHOD__."() account_selection='$this->account_selection', accounts->search(array('type'=>'$use', 'app' => '$app')) returns ".array2string($select));
187 187
 				}
188 188
 				// make sure everything in $selected is also in $select, as in the other account-selection methods
189
-				if ($selected && ($missing = array_diff_key($selected,$select)))
189
+				if ($selected && ($missing = array_diff_key($selected, $select)))
190 190
 				{
191
-					foreach($missing as $k => $v)	// merge missing (cant use array_merge, because of nummeric keys!)
191
+					foreach ($missing as $k => $v)	// merge missing (cant use array_merge, because of nummeric keys!)
192 192
 					{
193 193
 						$select[$k] = $v;
194 194
 					}
@@ -196,29 +196,28 @@  discard block
 block discarded – undo
196 196
 				break;
197 197
 		}
198 198
 		$already_selected = $users = $groups = array();
199
-		$use_keys = count($select) && !isset($select[0]);	// id's are the keys
200
-		foreach($select as $key => $val)
199
+		$use_keys = count($select) && !isset($select[0]); // id's are the keys
200
+		foreach ($select as $key => $val)
201 201
 		{
202 202
 			$id = $use_keys ? $key : (is_array($val) ? $val['account_id'] : $val);
203 203
 
204
-			if ($not && ($id == $not || is_array($not) && in_array($id,$not)))
204
+			if ($not && ($id == $not || is_array($not) && in_array($id, $not)))
205 205
 			{
206
-				continue;	// dont display that one
206
+				continue; // dont display that one
207 207
 			}
208 208
 			$label = common::grab_owner_name($id);
209 209
 			if ($label[0] === '#' && $label_callback)
210 210
 			{
211 211
 				if (!($label = call_user_func($label_callback, $id))) continue;
212 212
 			}
213
-			if (in_array($id,$selected))	// show already selected accounts first
213
+			if (in_array($id, $selected))	// show already selected accounts first
214 214
 			{
215 215
 				$already_selected[$id] = $label;
216 216
 			}
217 217
 			elseif ($this->accounts->get_type($id) == 'u')
218 218
 			{
219
-				$users[$id] = !is_array($val) ? $label :
220
-					common::display_fullname(
221
-						$val['account_lid'],$val['account_firstname'],$val['account_lastname'],$id);
219
+				$users[$id] = !is_array($val) ? $label : common::display_fullname(
220
+						$val['account_lid'], $val['account_firstname'], $val['account_lastname'], $id);
222 221
 			}
223 222
 			else
224 223
 			{
@@ -226,12 +225,12 @@  discard block
 block discarded – undo
226 225
 			}
227 226
 		}
228 227
 		// sort users and groups alphabeticaly and put the groups behind the users
229
-		uasort($users,strcasecmp);
230
-		uasort($groups,strcasecmp);
228
+		uasort($users, strcasecmp);
229
+		uasort($groups, strcasecmp);
231 230
 		$select = $already_selected + $users + $groups;
232 231
 		if (count($selected) && !isset($selected[0]))	// id's are the keys
233 232
 		{
234
-			foreach($selected as $id => $val)
233
+			foreach ($selected as $id => $val)
235 234
 			{
236 235
 				if (is_string($val) && isset($users[$id]))	// add string to option-label
237 236
 				{
@@ -241,13 +240,13 @@  discard block
 block discarded – undo
241 240
 			$selected = array_keys($selected);
242 241
 		}
243 242
 		// add necessary popup trigers
244
-		$link = egw::link('/index.php',array(
243
+		$link = egw::link('/index.php', array(
245 244
 			'menuaction' => 'phpgwapi.uiaccountsel.popup',
246 245
 			'app' => $app,
247 246
 			'use' => $use,
248 247
 			'element_id'  => $element_id,
249
-			'multiple' => $lines,	// single selection (multiple=0), closes after the first selection
250
-		),false);
248
+			'multiple' => $lines, // single selection (multiple=0), closes after the first selection
249
+		), false);
251 250
 		$app = $GLOBALS['egw_info']['flags']['currentapp'];
252 251
 		if (!$only_groups && ($lines <= 1 && $this->account_selection == 'popup' || !$lines && $this->account_selection == 'primary_group'))
253 252
 		{
@@ -256,14 +255,14 @@  discard block
 block discarded – undo
256 255
 				$select['popup'] = lang('Search').' ...';
257 256
 			}
258 257
 		}
259
-		if ($onchange) $options .= ' onchange="'.$onchange.'"';	// no working under CSP without 'unsafe-inline'
258
+		if ($onchange) $options .= ' onchange="'.$onchange.'"'; // no working under CSP without 'unsafe-inline'
260 259
 
261 260
 		if ($extra_label)
262 261
 		{
263 262
 			//in php5 this put's the extra-label at the end: $select = array($extra_label) + $select;
264 263
 			$select2 = array('' => $extra_label);
265 264
 			$select2 += $select;
266
-			$select =& $select2; unset($select2);
265
+			$select = & $select2; unset($select2);
267 266
 		}
268 267
 		//error_log(__METHOD__."(..., use='$use', ...) account_selection='$this->account_selection', select=".array2string($select));
269 268
 
@@ -275,20 +274,20 @@  discard block
 block discarded – undo
275 274
 			);
276 275
 		}
277 276
 		//echo "<p>html::select('$name',".print_r($selected,True).",".print_r($select,True).",True,'$options')</p>\n";
278
-		$html = html::select($name,$selected,$select,True,$options.' id="'.$element_id.
279
-			'" data-popup-link="'.htmlspecialchars($link).'"',$lines > 1 ? $lines : 0,false);
277
+		$html = html::select($name, $selected, $select, True, $options.' id="'.$element_id.
278
+			'" data-popup-link="'.htmlspecialchars($link).'"', $lines > 1 ? $lines : 0, false);
280 279
 
281 280
 		if (!$only_groups && ($lines > 0 && $this->account_selection == 'popup' || $lines > 1 && $this->account_selection == 'primary_group'))
282 281
 		{
283
-			$html .= html::submit_button('search','Search accounts',$js,false,
282
+			$html .= html::submit_button('search', 'Search accounts', $js, false,
284 283
 				' title="'.html::htmlspecialchars(lang('Search accounts')).
285
-				'" class="uiaccountselection_trigger" id="'.$element_id.'_popup"','search','phpgwapi','button');
284
+				'" class="uiaccountselection_trigger" id="'.$element_id.'_popup"', 'search', 'phpgwapi', 'button');
286 285
 		}
287 286
 		elseif (!$only_groups && ($lines == 1 || $lines > 0 && $this->account_selection == 'primary_group'))
288 287
 		{
289
-			$html .= html::submit_button('search','Select multiple accounts','',false,
288
+			$html .= html::submit_button('search', 'Select multiple accounts', '', false,
290 289
 				' title="'.html::htmlspecialchars(lang('Select multiple accounts')).
291
-				'" class="uiaccountselection_trigger" id="'.$element_id.'_multiple"','users','phpgwapi','button');
290
+				'" class="uiaccountselection_trigger" id="'.$element_id.'_multiple"', 'users', 'phpgwapi', 'button');
292 291
 		}
293 292
 		return $html;
294 293
 	}
@@ -298,20 +297,20 @@  discard block
 block discarded – undo
298 297
 		// switch CSP to script-src 'unsafe-inline', until code get fixed here to work without
299 298
 		egw_framework::csp_script_src_attrs('unsafe-inline');
300 299
 
301
-		global $query;	// nextmatch requires that !!!
300
+		global $query; // nextmatch requires that !!!
302 301
 
303
-		$app = get_var('app',array('POST','GET'));
304
-		$use = get_var('use',array('POST','GET'));
305
-		$group_id = get_var('group_id',array('POST','GET'), $GLOBALS['egw_info']['user']['account_primary_group']);
306
-		$element_id = get_var('element_id',array('POST','GET'));
307
-		$multiple = get_var('multiple',array('POST','GET'));
302
+		$app = get_var('app', array('POST', 'GET'));
303
+		$use = get_var('use', array('POST', 'GET'));
304
+		$group_id = get_var('group_id', array('POST', 'GET'), $GLOBALS['egw_info']['user']['account_primary_group']);
305
+		$element_id = get_var('element_id', array('POST', 'GET'));
306
+		$multiple = get_var('multiple', array('POST', 'GET'));
308 307
 
309
-		$query = get_var('query',array('POST','GET'));
310
-		$query_type = get_var('query_type',array('POST','GET'));
308
+		$query = get_var('query', array('POST', 'GET'));
309
+		$query_type = get_var('query_type', array('POST', 'GET'));
311 310
 
312
-		$start = (int) get_var('start',array('POST'),0);
313
-		$order = get_var('order',array('POST','GET'),'account_lid');
314
-		$sort = get_var('sort',array('POST','GET'),'ASC');
311
+		$start = (int)get_var('start', array('POST'), 0);
312
+		$order = get_var('order', array('POST', 'GET'), 'account_lid');
313
+		$sort = get_var('sort', array('POST', 'GET'), 'ASC');
315 314
 
316 315
 		//echo "<p>uiaccountsel::popup(): app='$app', use='$use', multiple='$multiple', group_id='$group_id', element_id='$element_id', start='$start', order='$order', sort='$sort'</p>\n";
317 316
 
@@ -320,47 +319,47 @@  discard block
 block discarded – undo
320 319
 		$GLOBALS['egw']->template->set_root(common::get_tpl_dir('phpgwapi'));
321 320
 
322 321
 		$GLOBALS['egw']->template->set_file(array('accounts_list_t' => 'uiaccountsel.tpl'));
323
-		$GLOBALS['egw']->template->set_block('accounts_list_t','letter_search','letter_search_cells');
324
-		$GLOBALS['egw']->template->set_block('accounts_list_t','group_cal','cal');
325
-		$GLOBALS['egw']->template->set_block('accounts_list_t','group_selectAll','selectAllGroups');
326
-		$GLOBALS['egw']->template->set_block('accounts_list_t','groups_multiple','multipleGroups');
327
-		$GLOBALS['egw']->template->set_block('accounts_list_t','group_other','other');
328
-		$GLOBALS['egw']->template->set_block('accounts_list_t','group_all','all');
329
-
330
-		$GLOBALS['egw']->template->set_block('accounts_list_t','bla_intro','ibla');
331
-		$GLOBALS['egw']->template->set_block('accounts_list_t','other_intro','iother');
332
-		$GLOBALS['egw']->template->set_block('accounts_list_t','all_intro','iall');
333
-
334
-		$GLOBALS['egw']->template->set_block('accounts_list_t','accounts_selectAll','selectAllAccounts');
335
-		$GLOBALS['egw']->template->set_block('accounts_list_t','accounts_multiple','multipleAccounts');
336
-		$GLOBALS['egw']->template->set_block('accounts_list_t','accounts_list','list');
337
-
338
-		$GLOBALS['egw']->template->set_var('font',$GLOBALS['egw_info']['theme']['font']);
339
-		$GLOBALS['egw']->template->set_var('lang_search',lang('search'));
340
-		$GLOBALS['egw']->template->set_var('lang_groups',lang('user groups'));
341
-		$GLOBALS['egw']->template->set_var('lang_accounts',lang('user accounts'));
342
-		$GLOBALS['egw']->template->set_var('lang_all',lang('all'));
343
-
344
-		$GLOBALS['egw']->template->set_var('img',common::image('phpgwapi','select'));
345
-		$GLOBALS['egw']->template->set_var('lang_select_user',lang('Select user'));
346
-		$GLOBALS['egw']->template->set_var('lang_select_group',lang('Select group'));
322
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'letter_search', 'letter_search_cells');
323
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'group_cal', 'cal');
324
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'group_selectAll', 'selectAllGroups');
325
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'groups_multiple', 'multipleGroups');
326
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'group_other', 'other');
327
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'group_all', 'all');
328
+
329
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'bla_intro', 'ibla');
330
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'other_intro', 'iother');
331
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'all_intro', 'iall');
332
+
333
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'accounts_selectAll', 'selectAllAccounts');
334
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'accounts_multiple', 'multipleAccounts');
335
+		$GLOBALS['egw']->template->set_block('accounts_list_t', 'accounts_list', 'list');
336
+
337
+		$GLOBALS['egw']->template->set_var('font', $GLOBALS['egw_info']['theme']['font']);
338
+		$GLOBALS['egw']->template->set_var('lang_search', lang('search'));
339
+		$GLOBALS['egw']->template->set_var('lang_groups', lang('user groups'));
340
+		$GLOBALS['egw']->template->set_var('lang_accounts', lang('user accounts'));
341
+		$GLOBALS['egw']->template->set_var('lang_all', lang('all'));
342
+
343
+		$GLOBALS['egw']->template->set_var('img', common::image('phpgwapi', 'select'));
344
+		$GLOBALS['egw']->template->set_var('lang_select_user', lang('Select user'));
345
+		$GLOBALS['egw']->template->set_var('lang_select_group', lang('Select group'));
347 346
 
348 347
 		if ($app)	// split the groups in the ones with run-rights and without
349 348
 		{
350 349
 			if ($use == 'both')		// groups with run-rights too, eg. calendar
351 350
 			{
352
-				$GLOBALS['egw']->template->fp('ibla','bla_intro',True);
351
+				$GLOBALS['egw']->template->fp('ibla', 'bla_intro', True);
353 352
 			}
354 353
 			else
355 354
 			{
356
-				$GLOBALS['egw']->template->fp('iother','other_intro',True);
355
+				$GLOBALS['egw']->template->fp('iother', 'other_intro', True);
357 356
 			}
358
-			$GLOBALS['egw']->template->fp('iall','all_intro',True);
357
+			$GLOBALS['egw']->template->fp('iall', 'all_intro', True);
359 358
 		}
360 359
 		else	// use all groups and account, eg. admin
361 360
 		{
362
-			$GLOBALS['egw']->template->set_var('lang_perm',lang('group name'));
363
-			$GLOBALS['egw']->template->fp('iother','other_intro',True);
361
+			$GLOBALS['egw']->template->set_var('lang_perm', lang('group name'));
362
+			$GLOBALS['egw']->template->fp('iother', 'other_intro', True);
364 363
 		}
365 364
 
366 365
 		if ($multiple >= 1)
@@ -370,11 +369,10 @@  discard block
 block discarded – undo
370 369
 		$GLOBALS['egw_info']['flags']['app_header'] = lang('search or select accounts');
371 370
 		common::egw_header();
372 371
 
373
-		$GLOBALS['egw']->template->set_var('lang_perm',lang('Groups with permission for %1',lang($app)));
374
-		$GLOBALS['egw']->template->set_var('lang_nonperm',lang('Groups without permission for %1',lang($app)));
372
+		$GLOBALS['egw']->template->set_var('lang_perm', lang('Groups with permission for %1', lang($app)));
373
+		$GLOBALS['egw']->template->set_var('lang_nonperm', lang('Groups without permission for %1', lang($app)));
375 374
 
376
-		$link_data = array
377
-		(
375
+		$link_data = array(
378 376
 			'menuaction' => 'phpgwapi.uiaccountsel.popup',
379 377
 			'app'        => $app,
380 378
 			'use'        => $use,
@@ -386,27 +384,27 @@  discard block
 block discarded – undo
386 384
 		);
387 385
 
388 386
 // -------------- list header variable template-declaration ------------------------
389
-		$GLOBALS['egw']->template->set_var('sort_lid',$nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('LoginID'),$link_data));
390
-		$GLOBALS['egw']->template->set_var('sort_firstname',$nextmatchs->show_sort_order($sort,'account_firstname',$order,'/index.php',lang('Firstname'),$link_data));
391
-		$GLOBALS['egw']->template->set_var('sort_lastname',$nextmatchs->show_sort_order($sort,'account_lastname',$order,'/index.php',lang('Lastname'),$link_data));
387
+		$GLOBALS['egw']->template->set_var('sort_lid', $nextmatchs->show_sort_order($sort, 'account_lid', $order, '/index.php', lang('LoginID'), $link_data));
388
+		$GLOBALS['egw']->template->set_var('sort_firstname', $nextmatchs->show_sort_order($sort, 'account_firstname', $order, '/index.php', lang('Firstname'), $link_data));
389
+		$GLOBALS['egw']->template->set_var('sort_lastname', $nextmatchs->show_sort_order($sort, 'account_lastname', $order, '/index.php', lang('Lastname'), $link_data));
392 390
 
393 391
 // ------------------------- end header declaration --------------------------------
394 392
 
395 393
 		$link_data['sort'] = $sort;
396 394
 		$link_data['order'] = $order;
397 395
 
398
-		$GLOBALS['egw']->template->set_var('lang_list_members',lang('List members'));
399
-		$GLOBALS['egw']->template->set_var('lang_firstname',lang('firstname'));
400
-		$GLOBALS['egw']->template->set_var('lang_lastname',lang('lastname'));
396
+		$GLOBALS['egw']->template->set_var('lang_list_members', lang('List members'));
397
+		$GLOBALS['egw']->template->set_var('lang_firstname', lang('firstname'));
398
+		$GLOBALS['egw']->template->set_var('lang_lastname', lang('lastname'));
401 399
 
402 400
 		if ($multiple)
403 401
 		{
404
-			$GLOBALS['egw']->template->fp('multipleGroups','groups_multiple',True);
402
+			$GLOBALS['egw']->template->fp('multipleGroups', 'groups_multiple', True);
405 403
 		}
406 404
 
407 405
 		if ($app)
408 406
 		{
409
-			$app_groups = $this->accounts->split_accounts($app,'groups');
407
+			$app_groups = $this->accounts->split_accounts($app, 'groups');
410 408
 		}
411 409
 		$all_groups = $this->accounts->search(array(
412 410
 			'type'  => 'groups',
@@ -414,44 +412,44 @@  discard block
 block discarded – undo
414 412
 			'sort'  => 'ASC',
415 413
 		));
416 414
 		$tr_color_app_groups = $tr_color_all_groups = 'row_off';
417
-		foreach($all_groups as $group)
415
+		foreach ($all_groups as $group)
418 416
 		{
419 417
 			$link_data['group_id'] = $group['account_id'];
420 418
 
421
-			$GLOBALS['egw']->template->set_var('onclick',"ownAddOption('$element_id','".
422
-				addslashes(common::grab_owner_name($group['account_id']))."','$group[account_id]',".(int)($multiple==1).")".
419
+			$GLOBALS['egw']->template->set_var('onclick', "ownAddOption('$element_id','".
420
+				addslashes(common::grab_owner_name($group['account_id']))."','$group[account_id]',".(int)($multiple == 1).")".
423 421
 				(!$multiple ? '; window.close()' : ''));
424 422
 
425
-			if (!$app || in_array($group['account_id'],$app_groups))
423
+			if (!$app || in_array($group['account_id'], $app_groups))
426 424
 			{
427
-				$GLOBALS['egw']->template->set_var('tr_color',$tr_color_app_groups=$nextmatchs->alternate_row_color($tr_color_app_groups,True));
428
-				$GLOBALS['egw']->template->set_var('link_user_group',egw::link('/index.php',$link_data));
425
+				$GLOBALS['egw']->template->set_var('tr_color', $tr_color_app_groups = $nextmatchs->alternate_row_color($tr_color_app_groups, True));
426
+				$GLOBALS['egw']->template->set_var('link_user_group', egw::link('/index.php', $link_data));
429 427
 				$GLOBALS['egw']->template->set_var('name_user_group', ($group['account_id'] == $group_id ? '<b>' : '').
430 428
 					common::grab_owner_name($group['account_id']).($group['account_id'] == $group_id ? '</b>' : ''));
431 429
 
432
-				if($use == 'both')	// allow selection of groups
430
+				if ($use == 'both')	// allow selection of groups
433 431
 				{
434
-					$GLOBALS['egw']->template->fp('cal','group_cal',True);
435
-					$GLOBALS['egw']->template->set_var('js_addAllGroups',"ownAddOption('$element_id','".
436
-						addslashes(common::grab_owner_name($group['account_id']))."','$group[account_id]',".(int)($multiple==1).")".
432
+					$GLOBALS['egw']->template->fp('cal', 'group_cal', True);
433
+					$GLOBALS['egw']->template->set_var('js_addAllGroups', "ownAddOption('$element_id','".
434
+						addslashes(common::grab_owner_name($group['account_id']))."','$group[account_id]',".(int)($multiple == 1).")".
437 435
 						(!$multiple ? '; window.close();' : ';'));
438
-					$GLOBALS['egw']->template->fp('selectAllGroups','group_selectAll',True);
436
+					$GLOBALS['egw']->template->fp('selectAllGroups', 'group_selectAll', True);
439 437
 				}
440 438
 				else
441 439
 				{
442
-					$GLOBALS['egw']->template->fp('other','group_other',True);
440
+					$GLOBALS['egw']->template->fp('other', 'group_other', True);
443 441
 				}
444 442
 			}
445 443
 			else
446 444
 			{
447
-				$GLOBALS['egw']->template->set_var('tr_color',$tr_color_all_groups=$nextmatchs->alternate_row_color($tr_color_all_groups,True));
448
-				$GLOBALS['egw']->template->set_var('link_all_group',egw::link('/index.php',$link_data));
449
-				$GLOBALS['egw']->template->set_var('name_all_group',common::grab_owner_name($group['account_id']));
450
-				$GLOBALS['egw']->template->set_var('accountid',$group['account_id']);
451
-				$GLOBALS['egw']->template->fp('all','group_all',True);
445
+				$GLOBALS['egw']->template->set_var('tr_color', $tr_color_all_groups = $nextmatchs->alternate_row_color($tr_color_all_groups, True));
446
+				$GLOBALS['egw']->template->set_var('link_all_group', egw::link('/index.php', $link_data));
447
+				$GLOBALS['egw']->template->set_var('name_all_group', common::grab_owner_name($group['account_id']));
448
+				$GLOBALS['egw']->template->set_var('accountid', $group['account_id']);
449
+				$GLOBALS['egw']->template->fp('all', 'group_all', True);
452 450
 			}
453 451
 		}
454
-		$link_data['group_id'] = $group_id;		// reset it
452
+		$link_data['group_id'] = $group_id; // reset it
455 453
 
456 454
 // --------------------------------- nextmatch ---------------------------
457 455
 		$users = $this->accounts->search(array(
@@ -465,30 +463,30 @@  discard block
 block discarded – undo
465 463
 		));
466 464
 
467 465
 		$GLOBALS['egw']->template->set_var(array(
468
-			'left'  => $nextmatchs->left('/index.php',$start,$this->accounts->total,$link_data+array('query'=>$query)),
469
-			'right' => $nextmatchs->right('/index.php',$start,$this->accounts->total,$link_data+array('query'=>$query)),
466
+			'left'  => $nextmatchs->left('/index.php', $start, $this->accounts->total, $link_data + array('query'=>$query)),
467
+			'right' => $nextmatchs->right('/index.php', $start, $this->accounts->total, $link_data + array('query'=>$query)),
470 468
 			'lang_showing' => ($group_id ? common::grab_owner_name($group_id).': ' : '').
471
-				($query ? lang("Search %1 '%2'",lang($this->accounts->query_types[$query_type]),$query).': ' : '')
472
-				.$nextmatchs->show_hits($this->accounts->total,$start),
469
+				($query ? lang("Search %1 '%2'", lang($this->accounts->query_types[$query_type]), $query).': ' : '')
470
+				.$nextmatchs->show_hits($this->accounts->total, $start),
473 471
 		));
474 472
 
475 473
 // -------------------------- end nextmatch ------------------------------------
476 474
 
477
-		$GLOBALS['egw']->template->set_var('search_action',egw::link('/index.php',$link_data));
475
+		$GLOBALS['egw']->template->set_var('search_action', egw::link('/index.php', $link_data));
478 476
 		$GLOBALS['egw']->template->set_var('prev_query', $query);
479
-		$GLOBALS['egw']->template->set_var('search_list',$nextmatchs->search(array('query' => $query, 'search_obj' => 1)));
477
+		$GLOBALS['egw']->template->set_var('search_list', $nextmatchs->search(array('query' => $query, 'search_obj' => 1)));
480 478
 		$GLOBALS['egw']->template->set_var('lang_firstname', lang("firstname"));
481 479
 		$GLOBALS['egw']->template->set_var('lang_lastname', lang("lastname"));
482 480
 
483 481
 		if ($multiple)
484 482
 		{
485
-			$GLOBALS['egw']->template->fp('multipleAccounts','accounts_multiple',True);
483
+			$GLOBALS['egw']->template->fp('multipleAccounts', 'accounts_multiple', True);
486 484
 		}
487 485
 
488 486
 		$tr_color = 'row_off';
489
-		foreach($users as $user)
487
+		foreach ($users as $user)
490 488
 		{
491
-			$GLOBALS['egw']->template->set_var('tr_color',$tr_color=$nextmatchs->alternate_row_color($tr_color,True));
489
+			$GLOBALS['egw']->template->set_var('tr_color', $tr_color = $nextmatchs->alternate_row_color($tr_color, True));
492 490
 
493 491
 // ---------------- template declaration for list records --------------------------
494 492
 
@@ -497,40 +495,40 @@  discard block
 block discarded – undo
497 495
 				'firstname'	=> $user['account_firstname'] ? $user['account_firstname'] : '&nbsp;',
498 496
 				'lastname'	=> $user['account_lastname'] ? $user['account_lastname'] : '&nbsp;',
499 497
 				'onclick'	=> "ownAddOption('$element_id','".
500
-					addslashes(common::grab_owner_name($user['account_id']))."','$user[account_id]',".(int)($multiple==1).")".
498
+					addslashes(common::grab_owner_name($user['account_id']))."','$user[account_id]',".(int)($multiple == 1).")".
501 499
 					(!$multiple ? '; window.close()' : ''),
502 500
 			));
503
-			$GLOBALS['egw']->template->fp('list','accounts_list',True);
504
-			$GLOBALS['egw']->template->set_var('js_addAllAccounts',"ownAddOption('$element_id','".
505
-					addslashes(common::grab_owner_name($user['account_id']))."','$user[account_id]',".(int)($multiple==1).")".
501
+			$GLOBALS['egw']->template->fp('list', 'accounts_list', True);
502
+			$GLOBALS['egw']->template->set_var('js_addAllAccounts', "ownAddOption('$element_id','".
503
+					addslashes(common::grab_owner_name($user['account_id']))."','$user[account_id]',".(int)($multiple == 1).")".
506 504
 					(!$multiple ? '; window.close()' : ';'));
507
-			$GLOBALS['egw']->template->fp('selectAllAccounts','accounts_selectAll',True);
505
+			$GLOBALS['egw']->template->fp('selectAllAccounts', 'accounts_selectAll', True);
508 506
 		}
509 507
 
510
-		$GLOBALS['egw']->template->set_var('accountsel_icon',html::image('phpgwapi','users-big'));
511
-		$GLOBALS['egw']->template->set_var('query_type',is_array($this->accounts->query_types) ? html::select('query_type',$query_type,$this->accounts->query_types) : '');
508
+		$GLOBALS['egw']->template->set_var('accountsel_icon', html::image('phpgwapi', 'users-big'));
509
+		$GLOBALS['egw']->template->set_var('query_type', is_array($this->accounts->query_types) ? html::select('query_type', $query_type, $this->accounts->query_types) : '');
512 510
 
513 511
 		$link_data['query_type'] = 'start';
514 512
 		$letters = lang('alphabet');
515
-		$letters = explode(',',substr($letters,-1) != '*' ? $letters : 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z');
516
-		foreach($letters as $letter)
513
+		$letters = explode(',', substr($letters, -1) != '*' ? $letters : 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z');
514
+		foreach ($letters as $letter)
517 515
 		{
518 516
 			$link_data['query'] = $letter;
519 517
 			$GLOBALS['egw']->template->set_var(array(
520 518
 				'letter' => $letter,
521
-				'link'   => egw::link('/index.php',$link_data),
519
+				'link'   => egw::link('/index.php', $link_data),
522 520
 				'class'  => $query == $letter && $query_type == 'start' ? 'letter_box_active' : 'letter_box',
523 521
 			));
524
-			$GLOBALS['egw']->template->fp('letter_search_cells','letter_search',True);
522
+			$GLOBALS['egw']->template->fp('letter_search_cells', 'letter_search', True);
525 523
 		}
526 524
 		unset($link_data['query']);
527 525
 		unset($link_data['query_type']);
528 526
 		$GLOBALS['egw']->template->set_var(array(
529 527
 			'letter' => lang('all'),
530
-			'link'   => egw::link('/index.php',$link_data),
531
-			'class'  => $query_type != 'start' || !in_array($query,$letters) ? 'letter_box_active' : 'letter_box',
528
+			'link'   => egw::link('/index.php', $link_data),
529
+			'class'  => $query_type != 'start' || !in_array($query, $letters) ? 'letter_box_active' : 'letter_box',
532 530
 		));
533
-		$GLOBALS['egw']->template->fp('letter_search_cells','letter_search',True);
531
+		$GLOBALS['egw']->template->fp('letter_search_cells', 'letter_search', True);
534 532
 
535 533
 		$GLOBALS['egw']->template->set_var(array(
536 534
 			'lang_selection' => lang('selection'),
@@ -551,12 +549,12 @@  discard block
 block discarded – undo
551 549
 		if ($multiple)
552 550
 		{
553 551
 			$GLOBALS['egw']->template->set_var(array(
554
-				'selection' => html::select('selected',False,array(),True,' id="uiaccountsel_popup_selection" style="width: 100%;"',13),
555
-				'remove' => html::submit_button('remove','remove',
556
-					"removeSelectedOptions('$element_id'); return false;",True,' title="'.lang('Remove selected accounts').'"','delete'),
552
+				'selection' => html::select('selected', False, array(), True, ' id="uiaccountsel_popup_selection" style="width: 100%;"', 13),
553
+				'remove' => html::submit_button('remove', 'remove',
554
+					"removeSelectedOptions('$element_id'); return false;", True, ' title="'.lang('Remove selected accounts').'"', 'delete'),
557 555
 			));
558 556
 		}
559
-		$GLOBALS['egw']->template->pfp('out','accounts_list_t',True);
557
+		$GLOBALS['egw']->template->pfp('out', 'accounts_list_t', True);
560 558
 
561 559
 		common::egw_footer();
562 560
 	}
Please login to merge, or discard this patch.
Braces   +49 added lines, -12 removed lines patch added patch discarded remove patch
@@ -93,13 +93,19 @@  discard block
 block discarded – undo
93 93
 			$lines = 1;
94 94
 		}
95 95
 		// add "uiaccountselection" and account_selection-type class, to be able to style and select it with jQuery
96
-		if (strpos($options, 'class="') === false) $options .= ' class=""';
96
+		if (strpos($options, 'class="') === false)
97
+		{
98
+			$options .= ' class=""';
99
+		}
97 100
 		$options = str_replace('class="', 'class="uiaccountselection '.$this->account_selection.' ', $options);
98 101
 
99
-		if ($this->account_selection == 'none')	// dont show user-selection at all!
102
+		if ($this->account_selection == 'none')
103
+		{
104
+			// dont show user-selection at all!
100 105
 		{
101 106
 			return html::input_hidden($name,$selected);
102 107
 		}
108
+		}
103 109
 		if (!is_array($selected))
104 110
 		{
105 111
 			$selected = $selected ? explode(',',$selected) : array();
@@ -126,7 +132,10 @@  discard block
 block discarded – undo
126 132
 				break;
127 133
 
128 134
 			case 'groups':
129
-				if ($this->account_selection == 'groupmembers') $use = 'owngroups';
135
+				if ($this->account_selection == 'groupmembers')
136
+				{
137
+					$use = 'owngroups';
138
+				}
130 139
 				// fall-through
131 140
 
132 141
 			case 'owngroups':
@@ -161,14 +170,20 @@  discard block
 block discarded – undo
161 170
 				{
162 171
 					foreach((array)$this->accounts->members($gid,true) as $member)
163 172
 					{
164
-						if (!in_array($member,$select) && $this->accounts->is_active($member)) $select[] = $member;
173
+						if (!in_array($member,$select) && $this->accounts->is_active($member))
174
+						{
175
+							$select[] = $member;
176
+						}
165 177
 					}
166 178
 				}
167
-				if ($use == 'both')	// show all memberships
179
+				if ($use == 'both')
180
+				{
181
+					// show all memberships
168 182
 				{
169 183
 					if ($account_sel == 'primary_group')
170 184
 					{
171 185
 						$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
186
+				}
172 187
 					}
173 188
 					$select = array_merge($select,$memberships);
174 189
 				}
@@ -188,10 +203,13 @@  discard block
 block discarded – undo
188 203
 				// make sure everything in $selected is also in $select, as in the other account-selection methods
189 204
 				if ($selected && ($missing = array_diff_key($selected,$select)))
190 205
 				{
191
-					foreach($missing as $k => $v)	// merge missing (cant use array_merge, because of nummeric keys!)
206
+					foreach($missing as $k => $v)
207
+					{
208
+						// merge missing (cant use array_merge, because of nummeric keys!)
192 209
 					{
193 210
 						$select[$k] = $v;
194 211
 					}
212
+					}
195 213
 				}
196 214
 				break;
197 215
 		}
@@ -208,12 +226,18 @@  discard block
 block discarded – undo
208 226
 			$label = common::grab_owner_name($id);
209 227
 			if ($label[0] === '#' && $label_callback)
210 228
 			{
211
-				if (!($label = call_user_func($label_callback, $id))) continue;
229
+				if (!($label = call_user_func($label_callback, $id)))
230
+				{
231
+					continue;
232
+				}
212 233
 			}
213
-			if (in_array($id,$selected))	// show already selected accounts first
234
+			if (in_array($id,$selected))
235
+			{
236
+				// show already selected accounts first
214 237
 			{
215 238
 				$already_selected[$id] = $label;
216 239
 			}
240
+			}
217 241
 			elseif ($this->accounts->get_type($id) == 'u')
218 242
 			{
219 243
 				$users[$id] = !is_array($val) ? $label :
@@ -229,13 +253,16 @@  discard block
 block discarded – undo
229 253
 		uasort($users,strcasecmp);
230 254
 		uasort($groups,strcasecmp);
231 255
 		$select = $already_selected + $users + $groups;
232
-		if (count($selected) && !isset($selected[0]))	// id's are the keys
256
+		if (count($selected) && !isset($selected[0]))
257
+		{
258
+			// id's are the keys
233 259
 		{
234 260
 			foreach($selected as $id => $val)
235 261
 			{
236 262
 				if (is_string($val) && isset($users[$id]))	// add string to option-label
237 263
 				{
238 264
 					$users[$id] .= " ($val)";
265
+		}
239 266
 				}
240 267
 			}
241 268
 			$selected = array_keys($selected);
@@ -256,7 +283,11 @@  discard block
 block discarded – undo
256 283
 				$select['popup'] = lang('Search').' ...';
257 284
 			}
258 285
 		}
259
-		if ($onchange) $options .= ' onchange="'.$onchange.'"';	// no working under CSP without 'unsafe-inline'
286
+		if ($onchange)
287
+		{
288
+			$options .= ' onchange="'.$onchange.'"';
289
+		}
290
+		// no working under CSP without 'unsafe-inline'
260 291
 
261 292
 		if ($extra_label)
262 293
 		{
@@ -345,11 +376,14 @@  discard block
 block discarded – undo
345 376
 		$GLOBALS['egw']->template->set_var('lang_select_user',lang('Select user'));
346 377
 		$GLOBALS['egw']->template->set_var('lang_select_group',lang('Select group'));
347 378
 
348
-		if ($app)	// split the groups in the ones with run-rights and without
379
+		if ($app)
380
+		{
381
+			// split the groups in the ones with run-rights and without
349 382
 		{
350 383
 			if ($use == 'both')		// groups with run-rights too, eg. calendar
351 384
 			{
352 385
 				$GLOBALS['egw']->template->fp('ibla','bla_intro',True);
386
+		}
353 387
 			}
354 388
 			else
355 389
 			{
@@ -429,9 +463,12 @@  discard block
 block discarded – undo
429 463
 				$GLOBALS['egw']->template->set_var('name_user_group', ($group['account_id'] == $group_id ? '<b>' : '').
430 464
 					common::grab_owner_name($group['account_id']).($group['account_id'] == $group_id ? '</b>' : ''));
431 465
 
432
-				if($use == 'both')	// allow selection of groups
466
+				if($use == 'both')
467
+				{
468
+					// allow selection of groups
433 469
 				{
434 470
 					$GLOBALS['egw']->template->fp('cal','group_cal',True);
471
+				}
435 472
 					$GLOBALS['egw']->template->set_var('js_addAllGroups',"ownAddOption('$element_id','".
436 473
 						addslashes(common::grab_owner_name($group['account_id']))."','$group[account_id]',".(int)($multiple==1).")".
437 474
 						(!$multiple ? '; window.close();' : ';'));
Please login to merge, or discard this patch.