Completed
Push — 16.1 ( 2b6741...abc73d )
by Nathan
50:22 queued 36:36
created
api/src/Db/Backup.php 4 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 	 * Restore data from a (compressed) csv file
497 497
 	 *
498 498
 	 * @param resource $f file opened with fopen for reading
499
-	 * @param int|string $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert
499
+	 * @param integer $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert
500 500
 	 * @returns int number of rows read from csv file
501 501
 	 */
502 502
 	function db_restore($f, $insert_n_rows=10)
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
 	/**
1045 1045
 	 * Backup all schemas in the form of a setup/tables_current.inc.php file
1046 1046
 	 *
1047
-	 * @param resource|boolean $f
1047
+	 * @param resource $f
1048 1048
 	 */
1049 1049
 	function schema_backup($f=False)
1050 1050
 	{
@@ -1089,6 +1089,7 @@  discard block
 block discarded – undo
1089 1089
 	 * Dump an array as php source
1090 1090
 	 *
1091 1091
 	 * copied from etemplate/inc/class.db_tools.inc.php
1092
+	 * @param integer $depth
1092 1093
 	 */
1093 1094
 	private static function write_array($arr,$depth,$parent='')
1094 1095
 	{
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 		$zip = NULL;
382 382
 		$_f = NULL;
383 383
 		if($type == 'zip')
384
-	    {
384
+		{
385 385
 			// has already been verified to be available in fopen_backup
386 386
 			$zip = new ZipArchive;
387 387
 			if(($zip->open($filename)) !== TRUE)
@@ -719,9 +719,9 @@  discard block
 block discarded – undo
719 719
 		while($file = $list[0])
720 720
 		{
721 721
 			if(is_dir($file) && $file != '.' && $file != '..')
722
-			    self::remove_dir_content($dir.'/'.$file);
722
+				self::remove_dir_content($dir.'/'.$file);
723 723
 			if(is_file($file) && $file != '.' && $file != '..')
724
-			    unlink($dir.'/'.$file);
724
+				unlink($dir.'/'.$file);
725 725
 			array_shift($list);
726 726
 		}
727 727
 		//rmdir($dir);  // dont remove own dir
@@ -967,8 +967,8 @@  discard block
 block discarded – undo
967 967
 				echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>';
968 968
 			}
969 969
 
970
-		    fclose($f);
971
-		    if (file_exists($name)) unlink($name);
970
+			fclose($f);
971
+			if (file_exists($name)) unlink($name);
972 972
 			return TRUE;
973 973
 		}
974 974
 		// save files ....
Please login to merge, or discard this patch.
Braces   +123 added lines, -34 removed lines patch added patch discarded remove patch
@@ -102,25 +102,34 @@  discard block
 block discarded – undo
102 102
 		{
103 103
 			$GLOBALS['egw_setup']->loaddb();	// we run inside setup, but db object is not loaded
104 104
 		}
105
-		if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc))	// schema_proc already instanciated, use it
105
+		if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc))
106
+		{
107
+			// schema_proc already instanciated, use it
106 108
 		{
107 109
 			$this->schema_proc = $GLOBALS['egw_setup']->oProc;
108 110
 		}
111
+		}
109 112
 		else
110 113
 		{
111 114
 			$this->schema_proc = new Api\Db\Schema();
112 115
 		}
113 116
 
114 117
 		$this->db = $this->schema_proc->m_odb;
115
-		if (!$this->db->Link_ID) $this->db->connect();
118
+		if (!$this->db->Link_ID)
119
+		{
120
+			$this->db->connect();
121
+		}
116 122
 		$this->adodb = $this->db->Link_ID;
117
-		if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']))		// called from setup
123
+		if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']))
124
+		{
125
+			// called from setup
118 126
 		{
119 127
 			if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table)))
120 128
 			{
121 129
 				if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__)->fetchColumn()))
122 130
 				{
123 131
 					error_log(__METHOD__."->"."No files Directory set/found");
132
+		}
124 133
 				}
125 134
 				if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__)->fetchColumn()))
126 135
 				{
@@ -134,7 +143,10 @@  discard block
 block discarded – undo
134 143
 				// backup files too
135 144
 				$this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'",__LINE__,__FILE__)->fetchColumn();
136 145
 			}
137
-			if (!$this->charset) $this->charset = 'utf-8';
146
+			if (!$this->charset)
147
+			{
148
+				$this->charset = 'utf-8';
149
+			}
138 150
 		}
139 151
 		else	// called from eGW
140 152
 		{
@@ -231,8 +243,7 @@  discard block
 block discarded – undo
231 243
 		if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) &&
232 244
 	 		!($f = fopen("compress.zlib://$name.gz",$mode)) &&
233 245
  		 	!($f = fopen($name,$mode))
234
-		)
235
-		{
246
+		) {
236 247
 			//echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>';	// !
237 248
 			$lang_mode = $reading ? lang("reading") : lang("writing");
238 249
 			return lang("Cant open '%1' for %2", $name, $lang_mode)."<br>";
@@ -268,16 +279,22 @@  discard block
 block discarded – undo
268 279
 				$files[filectime($this->backup_dir.'/'.$file)] = $file;
269 280
 			}
270 281
 		}
271
-		if ($handle) closedir($handle);
282
+		if ($handle)
283
+		{
284
+			closedir($handle);
285
+		}
272 286
 
273 287
 		/* Sort the files by ctime. */
274 288
 		krsort($files);
275 289
 		$count = 0;
276 290
 		foreach($files as $file)
277 291
 		{
278
-			if ($count >= $this->backup_mincount)//
292
+			if ($count >= $this->backup_mincount)
293
+			{
294
+				//
279 295
 			{
280 296
 				$ret = unlink($this->backup_dir.'/'.$file);
297
+			}
281 298
 				if (($ret) && (is_array($files_return)))
282 299
 				{
283 300
 					array_push($files_return, $file);
@@ -341,7 +358,11 @@  discard block
 block discarded – undo
341 358
 		@set_time_limit(0);
342 359
 		ini_set('auto_detect_line_endings',true);
343 360
 
344
-		if (true) $convert_to_system_charset = true;	// enforce now utf-8 as system charset restores of old backups
361
+		if (true)
362
+		{
363
+			$convert_to_system_charset = true;
364
+		}
365
+		// enforce now utf-8 as system charset restores of old backups
345 366
 
346 367
 		if ($protect_system_config)
347 368
 		{
@@ -393,7 +414,7 @@  discard block
 block discarded – undo
393 414
 		$zip = NULL;
394 415
 		$_f = NULL;
395 416
 		if($type == 'zip')
396
-	    {
417
+		{
397 418
 			// has already been verified to be available in fopen_backup
398 419
 			$zip = new ZipArchive;
399 420
 			if(($zip->open($filename)) !== TRUE)
@@ -412,7 +433,9 @@  discard block
 block discarded – undo
412 433
 		}
413 434
 		$this->db_restore($f, $insert_n_rows);
414 435
 
415
-		if ($convert_to_system_charset)	// store the changed charset
436
+		if ($convert_to_system_charset)
437
+		{
438
+			// store the changed charset
416 439
 		{
417 440
 			$this->db->insert(Api\Config::TABLE, array(
418 441
 				'config_value' => $this->schema_proc->system_charset,
@@ -421,6 +444,7 @@  discard block
 block discarded – undo
421 444
 				'config_name' => 'system_charset',
422 445
 			),__LINE__,__FILE__);
423 446
 		}
447
+		}
424 448
 		// restore protected system config
425 449
 		if ($protect_system_config)
426 450
 		{
@@ -510,7 +534,10 @@  discard block
 block discarded – undo
510 534
 		{
511 535
 			$line = trim(fgets($f)); ++$n;
512 536
 
513
-			if (empty($line)) continue;
537
+			if (empty($line))
538
+			{
539
+				continue;
540
+			}
514 541
 
515 542
 			if (substr($line,0,9) == 'version: ')
516 543
 			{
@@ -563,30 +590,45 @@  discard block
 block discarded – undo
563 590
 			}
564 591
 			if (substr($line,0,7) == 'table: ')
565 592
 			{
566
-				if ($rows)	// flush pending rows of last table
593
+				if ($rows)
594
+				{
595
+					// flush pending rows of last table
567 596
 				{
568 597
 					$this->insert_multiple($table, $rows, $this->schemas[$table]);
569 598
 				}
599
+				}
570 600
 				$rows = array();
571 601
 				$table = substr($line,7);
572
-				if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table);
602
+				if (!isset($this->schemas[$table]))
603
+				{
604
+					$this->schemas[$table] = $this->db->get_table_definitions(true, $table);
605
+				}
573 606
 				$auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null;
574 607
 
575 608
 				$cols = self::csv_split($line=fgets($f)); ++$n;
576 609
 				$blobs = array();
577 610
 				foreach($this->schemas[$table]['fd'] as $col => $data)
578 611
 				{
579
-					if ($data['type'] == 'blob') $blobs[] = $col;
612
+					if ($data['type'] == 'blob')
613
+					{
614
+						$blobs[] = $col;
615
+					}
580 616
 				}
581 617
 				// check if we have an old PostgreSQL backup useing 't'/'f' for bool values
582 618
 				// --> convert them to MySQL and our new PostgreSQL format of 1/0
583 619
 				$bools = array();
584 620
 				foreach($this->schemas[$table]['fd'] as $col => $def)
585 621
 				{
586
-					if ($def['type'] === 'bool') $bools[] = $col;
622
+					if ($def['type'] === 'bool')
623
+					{
624
+						$bools[] = $col;
625
+					}
587 626
 				}
588 627
 
589
-				if (feof($f)) break;
628
+				if (feof($f))
629
+				{
630
+					break;
631
+				}
590 632
 				continue;
591 633
 			}
592 634
 			if ($convert_to_system_charset && !$this->db->capabilities['client_encoding'])
@@ -599,9 +641,12 @@  discard block
 block discarded – undo
599 641
 					}
600 642
 				}
601 643
 			}
602
-			if ($table)	// do we already reached the data part
644
+			if ($table)
645
+			{
646
+				// do we already reached the data part
603 647
 			{
604 648
 				$import = true;
649
+			}
605 650
 				$data = self::csv_split($line, $cols, $blobs, $bools);
606 651
 
607 652
 				if ($table == 'egw_async' && in_array('##last-check-run##',$data))
@@ -637,7 +682,10 @@  discard block
 block discarded – undo
637 682
 						{
638 683
 							$where = array($insert_n_rows => $data[$insert_n_rows]);
639 684
 							unset($data[$insert_n_rows]);
640
-							if ($auto_id) unset($data[$auto_id]);
685
+							if ($auto_id)
686
+							{
687
+								unset($data[$auto_id]);
688
+							}
641 689
 							$this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]);
642 690
 						}
643 691
 						else
@@ -658,10 +706,13 @@  discard block
 block discarded – undo
658 706
 				}
659 707
 			}
660 708
 		}
661
-		if ($rows)	// flush pending rows
709
+		if ($rows)
710
+		{
711
+			// flush pending rows
662 712
 		{
663 713
 			$this->insert_multiple($table, $rows, $this->schemas[$table]);
664 714
 		}
715
+		}
665 716
 		// updated the sequences, if the DB uses them
666 717
 		foreach($this->schemas as $table => $schema)
667 718
 		{
@@ -719,9 +770,13 @@  discard block
 block discarded – undo
719 770
 		while($file = $list[0])
720 771
 		{
721 772
 			if(is_dir($file) && $file != '.' && $file != '..')
722
-			    self::remove_dir_content($dir.'/'.$file);
773
+			{
774
+						    self::remove_dir_content($dir.'/'.$file);
775
+			}
723 776
 			if(is_file($file) && $file != '.' && $file != '..')
724
-			    unlink($dir.'/'.$file);
777
+			{
778
+						    unlink($dir.'/'.$file);
779
+			}
725 780
 			array_shift($list);
726 781
 		}
727 782
 		//rmdir($dir);  // dont remove own dir
@@ -747,7 +802,9 @@  discard block
 block discarded – undo
747 802
 	 */
748 803
 	public static function csv_split($line, $keys=null, $blobs=array(), $bools=array())
749 804
 	{
750
-		if (function_exists('str_getcsv'))	// php5.3+
805
+		if (function_exists('str_getcsv'))
806
+		{
807
+			// php5.3+
751 808
 		{
752 809
 			// we need to take care of literal "NULL" values, replacing them we a special token as str_getcsv removes enclosures around strings
753 810
 			// str_getcsv uses '""' for '"' instead of '\\"' and does not unescape '\\n', '\\r' or '\\\\' (two backslashes)
@@ -757,6 +814,7 @@  discard block
 block discarded – undo
757 814
 				'\\"'    => '""',
758 815
 				'\\n'    => "\n",
759 816
 				'\\r'    => "\r")), ',', '"', '\0');
817
+		}
760 818
 			// replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash
761 819
 			foreach($fields as &$field)
762 820
 			{
@@ -773,9 +831,12 @@  discard block
 block discarded – undo
773 831
 						break;
774 832
 				}
775 833
 			}
776
-			if ($keys)	// if string keys are to be used --> combine keys and values
834
+			if ($keys)
835
+			{
836
+				// if string keys are to be used --> combine keys and values
777 837
 			{
778 838
 				$fields = array_combine($keys, $fields);
839
+			}
779 840
 				// base64-decode blob columns, if they are base64 encoded
780 841
 				foreach($blobs as $key)
781 842
 				{
@@ -924,7 +985,11 @@  discard block
 block discarded – undo
924 985
 
925 986
 		foreach($this->schemas as $table => $schema)
926 987
 		{
927
-			if (in_array($table,$this->exclude_tables)) continue;	// dont backup
988
+			if (in_array($table,$this->exclude_tables))
989
+			{
990
+				continue;
991
+			}
992
+			// dont backup
928 993
 
929 994
 			// do we have a primary key?
930 995
 			// --> use it to order and limit rows, to kope with rows being added during backup
@@ -950,8 +1015,14 @@  discard block
 block discarded – undo
950 1015
 					empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC',
951 1016
 					false, self::ROW_CHUNK) as $row)
952 1017
 				{
953
-					if (!empty($pk)) $max = $row[$pk];
954
-					if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
1018
+					if (!empty($pk))
1019
+					{
1020
+						$max = $row[$pk];
1021
+					}
1022
+					if ($total === 0)
1023
+					{
1024
+						fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
1025
+					}
955 1026
 
956 1027
 					array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']);
957 1028
 					fwrite($f,implode(',',$row)."\n");
@@ -961,21 +1032,30 @@  discard block
 block discarded – undo
961 1032
 			}
962 1033
 			while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
963 1034
 
964
-			if (!$pk) $this->db->rollback_lock($table);
1035
+			if (!$pk)
1036
+			{
1037
+				$this->db->rollback_lock($table);
1038
+			}
965 1039
 		}
966 1040
 
967 1041
 		// let apps know that backup is finished
968 1042
 		Api\Hooks::process('backup_finished', array(), true);
969 1043
 
970
-		if(!$zippresent)  // save without files
1044
+		if(!$zippresent)
1045
+		{
1046
+			// save without files
971 1047
 		{
972 1048
 			if ($this->backup_files)
973 1049
 			{
974 1050
 				echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>';
1051
+		}
975 1052
 			}
976 1053
 
977 1054
 		    fclose($f);
978
-		    if (file_exists($name)) unlink($name);
1055
+		    if (file_exists($name))
1056
+		    {
1057
+		    	unlink($name);
1058
+		    }
979 1059
 			return TRUE;
980 1060
 		}
981 1061
 		// save files ....
@@ -987,9 +1067,12 @@  discard block
 block discarded – undo
987 1067
 			//echo substr($file,strlen($dir)+1).'<br>';
988 1068
 			//echo $file.'<br>';
989 1069
 			$zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file);
990
-			if(($count++) == 100) { // the file descriptor limit
1070
+			if(($count++) == 100)
1071
+			{
1072
+// the file descriptor limit
991 1073
 				$zip->close();
992
-				if(($zip = new ZipArchive())) {
1074
+				if(($zip = new ZipArchive()))
1075
+				{
993 1076
 					$zip->open($filename);
994 1077
 					$count =0;
995 1078
 				}
@@ -1014,15 +1097,21 @@  discard block
 block discarded – undo
1014 1097
 	{
1015 1098
 		//chdir($f);
1016 1099
 		//echo "Processing $f <br>";
1017
-		if ($path_name =='') $path_name = $f;
1100
+		if ($path_name =='')
1101
+		{
1102
+			$path_name = $f;
1103
+		}
1018 1104
 		$tlist = scandir($f);
1019 1105
 		$list = array();
1020 1106
 		$i = $cnt;
1021
-		while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1107
+		while($file = $tlist[0])
1108
+		{
1109
+			// remove all '.' and '..' and transfer to $list
1022 1110
 		{
1023 1111
 			if($file == '.' || $file == '..')
1024 1112
 			{
1025 1113
 				array_shift($tlist);
1114
+		}
1026 1115
 			}
1027 1116
 			elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false)
1028 1117
 			{
Please login to merge, or discard this patch.
Spacing   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 	 * @var array
52 52
 	 */
53 53
 	var $exclude_tables = array(
54
-		'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions',	// eGW's session-tables
55
-		'phpgw_anglemail',	// email's cache
56
-		'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus',	// felamimail's cache
54
+		'egw_sessions', 'egw_app_sessions', 'phpgw_sessions', 'phpgw_app_sessions', // eGW's session-tables
55
+		'phpgw_anglemail', // email's cache
56
+		'egw_felamimail_cache', 'egw_felamimail_folderstatus', 'phpgw_felamimail_cache', 'phpgw_felamimail_folderstatus', // felamimail's cache
57 57
 		'egw_phpfreechat', // as of the fieldnames of the table a restore would fail within egroupware, and chatcontent is of no particular intrest
58 58
 	);
59 59
 	/**
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @var boolean
87 87
 	 */
88
-	var $backup_files = false ;
88
+	var $backup_files = false;
89 89
 	/**
90 90
 	 * Reference to schema_proc's Api\Db object
91 91
 	 *
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	{
101 101
 		if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']) && !isset($GLOBALS['egw_setup']->db))
102 102
 		{
103
-			$GLOBALS['egw_setup']->loaddb();	// we run inside setup, but db object is not loaded
103
+			$GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded
104 104
 		}
105 105
 		if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc))	// schema_proc already instanciated, use it
106 106
 		{
@@ -118,21 +118,21 @@  discard block
 block discarded – undo
118 118
 		{
119 119
 			if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table)))
120 120
 			{
121
-				if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'",__LINE__,__FILE__)->fetchColumn()))
121
+				if (!($this->files_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='files_dir'", __LINE__, __FILE__)->fetchColumn()))
122 122
 				{
123 123
 					error_log(__METHOD__."->"."No files Directory set/found");
124 124
 				}
125
-				if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'",__LINE__,__FILE__)->fetchColumn()))
125
+				if (!($this->backup_dir = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_dir'", __LINE__, __FILE__)->fetchColumn()))
126 126
 				{
127 127
 					$this->backup_dir = $this->files_dir.'/db_backup';
128 128
 				}
129
-				$this->charset = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'",__LINE__,__FILE__)->fetchColumn();
130
-				$this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table,'app_version',array('app_name'=>array('api','phpgwapi')),
131
-					__LINE__,__FILE__,0,'ORDER BY app_name ASC')->fetchColumn();
129
+				$this->charset = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='system_charset'", __LINE__, __FILE__)->fetchColumn();
130
+				$this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table, 'app_version', array('app_name'=>array('api', 'phpgwapi')),
131
+					__LINE__, __FILE__, 0, 'ORDER BY app_name ASC')->fetchColumn();
132 132
 				// Backup settings
133
-				$this->backup_mincount = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'",__LINE__,__FILE__)->fetchColumn();
133
+				$this->backup_mincount = $this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_mincount'", __LINE__, __FILE__)->fetchColumn();
134 134
 				// backup files too
135
-				$this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'",__LINE__,__FILE__)->fetchColumn();
135
+				$this->backup_files = (bool)$this->db->query("SELECT config_value FROM {$GLOBALS['egw_setup']->config_table} WHERE config_app='phpgwapi' AND config_name='backup_files'", __LINE__, __FILE__)->fetchColumn();
136 136
 			}
137 137
 			if (!$this->charset) $this->charset = 'utf-8';
138 138
 		}
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 			$this->backup_files = $GLOBALS['egw_info']['server']['backup_files'];
148 148
 			$this->charset = Api\Translation::charset();
149 149
 
150
-			$this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api'])?'api':'phpgwapi']['version'];
150
+			$this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api']) ? 'api' : 'phpgwapi']['version'];
151 151
 		}
152 152
 		// Set a default value if not set.
153 153
 		if (!isset($this->backup_mincount))
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 		{
164 164
 			mkdir($this->backup_dir);
165 165
 		}
166
-		switch($this->db->Type)
166
+		switch ($this->db->Type)
167 167
 		{
168 168
 			case 'sapdb':
169 169
 			case 'maxdb':
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * @param $reading =false opening for reading ('rb') or writing ('wb')
181 181
 	 * @return string/resource/zip error-msg of file-handle
182 182
 	 */
183
-	function fopen_backup($name=false,$reading=false)
183
+	function fopen_backup($name = false, $reading = false)
184 184
 	{
185 185
 		//echo "function fopen_backup($name,$reading)<br>";	// !
186 186
 		if (!$name)
@@ -189,27 +189,27 @@  discard block
 block discarded – undo
189 189
 			if (!$this->backup_dir || !is_writable($this->backup_dir))
190 190
 			{
191 191
 				//echo '   -> !$this->backup_dir || !is_writable($this->backup_dir)<br>';	// !
192
-				return lang("backupdir '%1' is not writeable by the webserver",$this->backup_dir);
192
+				return lang("backupdir '%1' is not writeable by the webserver", $this->backup_dir);
193 193
 			}
194 194
 			$name = $this->backup_dir.'/db_backup-'.date('YmdHi');
195 195
 		}
196 196
 		else	// remove the extension, to use the correct wrapper based on the extension
197 197
 		{
198 198
 			//echo '-> else<br>';	// !
199
-			$name = preg_replace('/\.(bz2|gz)$/i','',$name);
199
+			$name = preg_replace('/\.(bz2|gz)$/i', '', $name);
200 200
 		}
201 201
 		$mode = $reading ? 'rb' : 'wb';
202
-		list( , $type) = explode('.', basename($name));
203
-		if($type == 'zip' && $reading && $this->backup_files)
202
+		list(, $type) = explode('.', basename($name));
203
+		if ($type == 'zip' && $reading && $this->backup_files)
204 204
 		{
205 205
 			//echo '-> $type == "zip" && $reading<br>';	// !
206
-			if(!class_exists('ZipArchive', false))
206
+			if (!class_exists('ZipArchive', false))
207 207
 			{
208 208
 				$this->backup_files = false;
209 209
 				//echo '   -> (new ZipArchive) == NULL<br>';	// !
210 210
 				return lang("Cant open %1, needs ZipArchive", $name)."<br>\n";
211 211
 			}
212
-			if(!($f = fopen($name, $mode)))
212
+			if (!($f = fopen($name, $mode)))
213 213
 			{
214 214
 				//echo '   -> !($f = fopen($name, $mode))<br>';	// !
215 215
 				$lang_mode = $reading ? lang("reading") : lang("writing");
@@ -217,10 +217,10 @@  discard block
 block discarded – undo
217 217
 			}
218 218
 			return $f;
219 219
 		}
220
-		if(class_exists('ZipArchive', false) && !$reading && $this->backup_files)
220
+		if (class_exists('ZipArchive', false) && !$reading && $this->backup_files)
221 221
 		{
222 222
 			//echo '-> (new ZipArchive) != NULL && !$reading; '.$name.'<br>';	// !
223
-			if(!($f = fopen($name, $mode)))
223
+			if (!($f = fopen($name, $mode)))
224 224
 			{
225 225
 				//echo '   -> !($f = fopen($name, $mode))<br>';	// !
226 226
 				$lang_mode = $reading ? lang("reading") : lang("writing");
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
 			}
229 229
 			return $f;
230 230
 		}
231
-		if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) &&
232
-	 		!($f = fopen("compress.zlib://$name.gz",$mode)) &&
233
- 		 	!($f = fopen($name,$mode))
231
+		if (!($f = fopen("compress.bzip2://$name.bz2", $mode)) &&
232
+	 		!($f = fopen("compress.zlib://$name.gz", $mode)) &&
233
+ 		 	!($f = fopen($name, $mode))
234 234
 		)
235 235
 		{
236 236
 			//echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>';	// !
@@ -257,13 +257,13 @@  discard block
 block discarded – undo
257 257
 		/* Search the backup directory for matching files. */
258 258
 		$handle = @opendir($this->backup_dir);
259 259
 		$files = array();
260
-		while($handle && ($file = readdir($handle)))
260
+		while ($handle && ($file = readdir($handle)))
261 261
 		{
262 262
 			/* Filter for only the files with the regular name (un-renamed).
263 263
 			 * Leave special backup files (renamed) in place.
264 264
 			 * Note that this also excludes "." and "..".
265 265
 			 */
266
-			if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/",$file))
266
+			if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/", $file))
267 267
 			{
268 268
 				$files[filectime($this->backup_dir.'/'.$file)] = $file;
269 269
 			}
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 		/* Sort the files by ctime. */
274 274
 		krsort($files);
275 275
 		$count = 0;
276
-		foreach($files as $file)
276
+		foreach ($files as $file)
277 277
 		{
278 278
 			if ($count >= $this->backup_mincount)//
279 279
 			{
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 					array_push($files_return, $file);
284 284
 				}
285 285
 			}
286
-			$count ++;
286
+			$count++;
287 287
 		}
288 288
 	}
289 289
 
@@ -293,13 +293,13 @@  discard block
 block discarded – undo
293 293
 	 * @param int $minCount Minimum number of backups to keep.
294 294
 	 * @param boolean $backupFiles include files in backup or not, default dont change!
295 295
 	 */
296
-	function saveConfig($minCount,$backupFiles=null)
296
+	function saveConfig($minCount, $backupFiles = null)
297 297
 	{
298
-		Api\Config::save_value('backup_mincount',$this->backup_mincount=(int)$minCount,'phpgwapi');
298
+		Api\Config::save_value('backup_mincount', $this->backup_mincount = (int)$minCount, 'phpgwapi');
299 299
 
300 300
 		if (!is_null($backupFiles))
301 301
 		{
302
-			Api\Config::save_value('backup_files',$this->backup_files=(boolean)$backupFiles,'phpgwapi');
302
+			Api\Config::save_value('backup_files', $this->backup_files = (boolean)$backupFiles, 'phpgwapi');
303 303
 		}
304 304
 	}
305 305
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 		'httpproxy_server_password',
323 323
 		'system_charset',
324 324
 		'usecookies',
325
-		'install_id',	// do not restore install_id, as that would give two systems with identical install_id
325
+		'install_id', // do not restore install_id, as that would give two systems with identical install_id
326 326
 	);
327 327
 
328 328
 	/**
@@ -336,20 +336,20 @@  discard block
 block discarded – undo
336 336
 	 *
337 337
 	 * @returns An empty string or an error message in case of failure.
338 338
 	 */
339
-	function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=10)
339
+	function restore($f, $convert_to_system_charset = true, $filename = '', $protect_system_config = true, $insert_n_rows = 10)
340 340
 	{
341 341
 		@set_time_limit(0);
342
-		ini_set('auto_detect_line_endings',true);
342
+		ini_set('auto_detect_line_endings', true);
343 343
 
344
-		if (true) $convert_to_system_charset = true;	// enforce now utf-8 as system charset restores of old backups
344
+		if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups
345 345
 
346 346
 		if ($protect_system_config)
347 347
 		{
348 348
 			$system_config = array();
349
-			foreach($this->db->select(self::TABLE,'*',array(
349
+			foreach ($this->db->select(self::TABLE, '*', array(
350 350
 				'config_app' => 'phpgwapi',
351 351
 				'config_name' => self::$system_config,
352
-			),__LINE__,__FILE__) as $row)
352
+			), __LINE__, __FILE__) as $row)
353 353
 			{
354 354
 				$system_config[] = $row;
355 355
 			}
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 		// as MySQL 5.7+ has sql_mode STRICT_(ALL|TRANS)_TABLES enabled by default,
359 359
 		// it will no longer restore '0000-00-00 00:00:00' in timestamps it created before,
360 360
 		// so switching strict-mode off temporary for the restore (we dont create these!)
361
-		if (substr($this->db->Type,0,5) == 'mysql')
361
+		if (substr($this->db->Type, 0, 5) == 'mysql')
362 362
 		{
363 363
 			$this->db->query("SET SESSION sql_mode=(SELECT REPLACE(REPLACE(@@sql_mode,'STRICT_ALL_TABLES',''),'STRICT_TRANS_TABLES',''))", __LINE__, __FILE__);
364 364
 		}
@@ -369,17 +369,17 @@  discard block
 block discarded – undo
369 369
 
370 370
 
371 371
 		// drop all existing tables
372
-		foreach($this->adodb->MetaTables('TABLES') as $table)
372
+		foreach ($this->adodb->MetaTables('TABLES') as $table)
373 373
 		{
374
-			if ($this->system_tables && preg_match($this->system_tables,$table) ||
375
-				$this->egw_tables && !preg_match($this->egw_tables,$table))
374
+			if ($this->system_tables && preg_match($this->system_tables, $table) ||
375
+				$this->egw_tables && !preg_match($this->egw_tables, $table))
376 376
 			{
377 377
 				 continue;
378 378
 			}
379 379
 			$this->schema_proc->DropTable($table);
380 380
 		}
381 381
 		// it could be an old backup
382
-		list( , $type) = explode('.', basename($filename));
382
+		list(, $type) = explode('.', basename($filename));
383 383
 		$dir = $this->files_dir; // $GLOBALS['egw_info']['server']['files_dir'];
384 384
 		// we may have to clean up old backup - left overs
385 385
 		if (is_dir($dir.'/database_backup'))
@@ -392,20 +392,20 @@  discard block
 block discarded – undo
392 392
 		$name = "";
393 393
 		$zip = NULL;
394 394
 		$_f = NULL;
395
-		if($type == 'zip')
395
+		if ($type == 'zip')
396 396
 	    {
397 397
 			// has already been verified to be available in fopen_backup
398 398
 			$zip = new ZipArchive;
399
-			if(($zip->open($filename)) !== TRUE)
399
+			if (($zip->open($filename)) !== TRUE)
400 400
 			{
401 401
 				return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n";
402 402
 			}
403
-			self::remove_dir_content($dir);  // removes the files-dir
403
+			self::remove_dir_content($dir); // removes the files-dir
404 404
 			$zip->extractTo($dir);
405 405
 			$_f = $f;
406 406
 			$list = $this->get_file_list($dir.'/database_backup/');
407 407
 			$name = $dir.'/database_backup/'.basename($list[0]);
408
-			if(!($f = fopen($name, 'rb')))
408
+			if (!($f = fopen($name, 'rb')))
409 409
 			{
410 410
 				return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n";
411 411
 			}
@@ -422,46 +422,46 @@  discard block
 block discarded – undo
422 422
 		{
423 423
 			$this->db->insert(Api\Config::TABLE, array(
424 424
 				'config_value' => $this->schema_proc->system_charset,
425
-			),array(
425
+			), array(
426 426
 				'config_app' => 'phpgwapi',
427 427
 				'config_name' => 'system_charset',
428
-			),__LINE__,__FILE__);
428
+			), __LINE__, __FILE__);
429 429
 		}
430 430
 		// restore protected system config
431 431
 		if ($protect_system_config)
432 432
 		{
433
-			foreach($system_config as $row)
433
+			foreach ($system_config as $row)
434 434
 			{
435
-				$this->db->insert(self::TABLE,array('config_value'=>$row['config_value']),array(
435
+				$this->db->insert(self::TABLE, array('config_value'=>$row['config_value']), array(
436 436
 					'config_name' => $row['config_name'],
437 437
 					'config_app'  => $row['config_app'],
438
-				),__LINE__,__FILE__);
438
+				), __LINE__, __FILE__);
439 439
 			}
440 440
 			// check and reset cookie configuration, if it does not match current enviroment
441 441
 			// if $_SERVER[HTTP_HOST] does not end with cookiedomain --> delete cookiedomain
442
-			if (($cookiedomain = $this->db->select(self::TABLE,'config_value',array(
442
+			if (($cookiedomain = $this->db->select(self::TABLE, 'config_value', array(
443 443
 					'config_app' => 'phpgwapi',
444 444
 					'config_name' => 'cookiedomain',
445
-				),__LINE__,__FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) &&
446
-				(list($hostname) = explode(':',$_SERVER['HTTP_HOST'])) &&
447
-				substr($hostname,-strlen($cookiedomain) !== $cookiedomain))
445
+				), __LINE__, __FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) &&
446
+				(list($hostname) = explode(':', $_SERVER['HTTP_HOST'])) &&
447
+				substr($hostname, -strlen($cookiedomain) !== $cookiedomain))
448 448
 			{
449
-				$this->db->delete(self::TABLE,array(
449
+				$this->db->delete(self::TABLE, array(
450 450
 					'config_app' => 'phpgwapi',
451 451
 					'config_name' => 'cookiedomain',
452
-				),__LINE__,__FILE__);
452
+				), __LINE__, __FILE__);
453 453
 			}
454 454
 			// if configured webserver_url does NOT start with cookiepath --> delete cookiepath
455
-			if (($cookiepath = $this->db->select(self::TABLE,'config_value',array(
455
+			if (($cookiepath = $this->db->select(self::TABLE, 'config_value', array(
456 456
 					'config_app' => 'phpgwapi',
457 457
 					'config_name' => 'cookiepath',
458
-				),__LINE__,__FILE__)->fetchColumn()) &&
459
-				substr(parse_url($system_config['webserver_url'], PHP_URL_PATH),0,strlen($cookiepath) !== $cookiepath))
458
+				), __LINE__, __FILE__)->fetchColumn()) &&
459
+				substr(parse_url($system_config['webserver_url'], PHP_URL_PATH), 0, strlen($cookiepath) !== $cookiepath))
460 460
 			{
461
-				$this->db->delete(self::TABLE,array(
461
+				$this->db->delete(self::TABLE, array(
462 462
 					'config_app' => 'phpgwapi',
463 463
 					'config_name' => 'cookiepath',
464
-				),__LINE__,__FILE__);
464
+				), __LINE__, __FILE__);
465 465
 			}
466 466
 		}
467 467
 		// restore original Halt_On_Error state (if changed)
@@ -470,13 +470,13 @@  discard block
 block discarded – undo
470 470
 			$this->db->Halt_On_Error = $backup_db_halt_on_error;
471 471
 		}
472 472
 		// zip?
473
-		if($type == 'zip')
473
+		if ($type == 'zip')
474 474
 		{
475 475
 			fclose($f);
476 476
 			unlink($name);
477 477
 			rmdir($dir.'/database_backup');
478 478
 		}
479
-		if (substr($this->db->Type,0,5) != 'mysql')
479
+		if (substr($this->db->Type, 0, 5) != 'mysql')
480 480
 		{
481 481
 			if (!$this->db->transaction_commit())
482 482
 			{
@@ -511,26 +511,26 @@  discard block
 block discarded – undo
511 511
 	 * @param int|string $insert_n_rows =10 how many rows to insert in one sql statement, or string with column-name used as unique key for insert
512 512
 	 * @returns int number of rows read from csv file
513 513
 	 */
514
-	function db_restore($f, $insert_n_rows=10)
514
+	function db_restore($f, $insert_n_rows = 10)
515 515
 	{
516 516
 		$convert_to_system_charset = true;
517 517
 		$table = null;
518 518
 		$n = 0;
519 519
 		$rows = array();
520
-		while(!feof($f))
520
+		while (!feof($f))
521 521
 		{
522 522
 			$line = trim(fgets($f)); ++$n;
523 523
 
524 524
 			if (empty($line)) continue;
525 525
 
526
-			if (substr($line,0,9) == 'version: ')
526
+			if (substr($line, 0, 9) == 'version: ')
527 527
 			{
528
-				$api_version = trim(substr($line,9));
528
+				$api_version = trim(substr($line, 9));
529 529
 				continue;
530 530
 			}
531
-			if (substr($line,0,9) == 'charset: ')
531
+			if (substr($line, 0, 9) == 'charset: ')
532 532
 			{
533
-				$charset = trim(substr($line,9));
533
+				$charset = trim(substr($line, 9));
534 534
 				// needed if mbstring.func_overload > 0, else eg. substr does not work with non ascii chars
535 535
 				$ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset';
536 536
 				@ini_set($ini_default_charset, $charset);
@@ -538,29 +538,29 @@  discard block
 block discarded – undo
538 538
 				// check if we really need to convert the charset, as it's not perfect and can do some damage
539 539
 				if ($convert_to_system_charset && !strcasecmp($this->schema_proc->system_charset, $charset))
540 540
 				{
541
-					$convert_to_system_charset = false;	// no conversation necessary
541
+					$convert_to_system_charset = false; // no conversation necessary
542 542
 				}
543 543
 				// set the DB's client encoding (for mysql only if api_version >= 1.0.1.019)
544 544
 				if ((!$convert_to_system_charset || $this->db->capabilities['client_encoding']) &&
545
-					(substr($this->db->Type,0,5) != 'mysql' || !is_object($GLOBALS['egw_setup']) ||
546
-					$api_version && !$GLOBALS['egw_setup']->alessthanb($api_version,'1.0.1.019')))
545
+					(substr($this->db->Type, 0, 5) != 'mysql' || !is_object($GLOBALS['egw_setup']) ||
546
+					$api_version && !$GLOBALS['egw_setup']->alessthanb($api_version, '1.0.1.019')))
547 547
 				{
548 548
 					$this->db->Link_ID->SetCharSet($charset);
549 549
 					if (!$convert_to_system_charset)
550 550
 					{
551
-						$this->schema_proc->system_charset = $charset;	// so schema_proc uses it for the creation of the tables
551
+						$this->schema_proc->system_charset = $charset; // so schema_proc uses it for the creation of the tables
552 552
 					}
553 553
 				}
554 554
 				continue;
555 555
 			}
556
-			if (substr($line,0,8) == 'schema: ')
556
+			if (substr($line, 0, 8) == 'schema: ')
557 557
 			{
558 558
 				// create the tables in the backup set
559
-				$this->schemas = json_php_unserialize(trim(substr($line,8)));
560
-				foreach($this->schemas as $table_name => $schema)
559
+				$this->schemas = json_php_unserialize(trim(substr($line, 8)));
560
+				foreach ($this->schemas as $table_name => $schema)
561 561
 				{
562 562
 					// if column is longtext in current schema, convert text to longtext, in case user already updated column
563
-					foreach($schema['fd'] as $col => &$def)
563
+					foreach ($schema['fd'] as $col => &$def)
564 564
 					{
565 565
 						if ($def['type'] == 'text' && $this->db->get_column_attribute($col, $table_name, true, 'type') == 'longtext')
566 566
 						{
@@ -572,27 +572,27 @@  discard block
 block discarded – undo
572 572
 				}
573 573
 				continue;
574 574
 			}
575
-			if (substr($line,0,7) == 'table: ')
575
+			if (substr($line, 0, 7) == 'table: ')
576 576
 			{
577 577
 				if ($rows)	// flush pending rows of last table
578 578
 				{
579 579
 					$this->insert_multiple($table, $rows, $this->schemas[$table]);
580 580
 				}
581 581
 				$rows = array();
582
-				$table = substr($line,7);
582
+				$table = substr($line, 7);
583 583
 				if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table);
584 584
 				$auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null;
585 585
 
586
-				$cols = self::csv_split($line=fgets($f)); ++$n;
586
+				$cols = self::csv_split($line = fgets($f)); ++$n;
587 587
 				$blobs = array();
588
-				foreach($this->schemas[$table]['fd'] as $col => $data)
588
+				foreach ($this->schemas[$table]['fd'] as $col => $data)
589 589
 				{
590 590
 					if ($data['type'] == 'blob') $blobs[] = $col;
591 591
 				}
592 592
 				// check if we have an old PostgreSQL backup useing 't'/'f' for bool values
593 593
 				// --> convert them to MySQL and our new PostgreSQL format of 1/0
594 594
 				$bools = array();
595
-				foreach($this->schemas[$table]['fd'] as $col => $def)
595
+				foreach ($this->schemas[$table]['fd'] as $col => $def)
596 596
 				{
597 597
 					if ($def['type'] === 'bool') $bools[] = $col;
598 598
 				}
@@ -615,15 +615,15 @@  discard block
 block discarded – undo
615 615
 				$import = true;
616 616
 				$data = self::csv_split($line, $cols, $blobs, $bools);
617 617
 
618
-				if ($table == 'egw_async' && in_array('##last-check-run##',$data))
618
+				if ($table == 'egw_async' && in_array('##last-check-run##', $data))
619 619
 				{
620 620
 					//echo '<p>'.lang("Line %1: '%2'<br><b>csv data does contain ##last-check-run## of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n";
621 621
 					//echo 'data=<pre>'.print_r($data,true)."</pre>\n";
622 622
 					$import = false;
623 623
 				}
624
-				if (in_array($table,$this->exclude_tables))
624
+				if (in_array($table, $this->exclude_tables))
625 625
 				{
626
-					echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n";
626
+					echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.", $table)."</b></p>\n";
627 627
 					$import = false; // dont restore data of excluded tables
628 628
 				}
629 629
 				if ($import)
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 					{
633 633
 						if ($convert_to_system_charset && !$this->db->capabilities['client_encoding'])
634 634
 						{
635
-							$data = Api\Translation::convert($data,$charset);
635
+							$data = Api\Translation::convert($data, $charset);
636 636
 						}
637 637
 						if ($insert_n_rows > 1)
638 638
 						{
@@ -644,27 +644,27 @@  discard block
 block discarded – undo
644 644
 							}
645 645
 						}
646 646
 						// update existing table using given unique key in $insert_n_rows (also removing auto-id/sequence)
647
-						elseif(!is_numeric($insert_n_rows))
647
+						elseif (!is_numeric($insert_n_rows))
648 648
 						{
649 649
 							$where = array($insert_n_rows => $data[$insert_n_rows]);
650 650
 							unset($data[$insert_n_rows]);
651 651
 							if ($auto_id) unset($data[$auto_id]);
652
-							$this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]);
652
+							$this->db->insert($table, $data, $where, __LINE__, __FILE__, false, false, $this->schemas[$table]);
653 653
 						}
654 654
 						else
655 655
 						{
656 656
 							try {
657
-								$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
657
+								$this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $this->schemas[$table]);
658 658
 							}
659
-							catch(Exception\InvalidSql $e) {
659
+							catch (Exception\InvalidSql $e) {
660 660
 								echo "<p>".$e->getMessage()."</p>\n";
661 661
 							}
662 662
 						}
663 663
 					}
664 664
 					else
665 665
 					{
666
-						echo '<p>'.lang("Line %1: '%2'<br><b>csv data does not match column-count of table %3 ==> ignored</b>",$n,$line,$table)."</p>\n";
667
-						echo 'data=<pre>'.print_r($data,true)."</pre>\n";
666
+						echo '<p>'.lang("Line %1: '%2'<br><b>csv data does not match column-count of table %3 ==> ignored</b>", $n, $line, $table)."</p>\n";
667
+						echo 'data=<pre>'.print_r($data, true)."</pre>\n";
668 668
 					}
669 669
 				}
670 670
 			}
@@ -674,14 +674,14 @@  discard block
 block discarded – undo
674 674
 			$this->insert_multiple($table, $rows, $this->schemas[$table]);
675 675
 		}
676 676
 		// updated the sequences, if the DB uses them
677
-		foreach($this->schemas as $table => $schema)
677
+		foreach ($this->schemas as $table => $schema)
678 678
 		{
679
-			foreach($schema['fd'] as $column => $definition)
679
+			foreach ($schema['fd'] as $column => $definition)
680 680
 			{
681 681
 				if ($definition['type'] == 'auto')
682 682
 				{
683
-					$this->schema_proc->UpdateSequence($table,$column);
684
-					break;	// max. one per table
683
+					$this->schema_proc->UpdateSequence($table, $column);
684
+					break; // max. one per table
685 685
 				}
686 686
 			}
687 687
 		}
@@ -704,15 +704,15 @@  discard block
 block discarded – undo
704 704
 		try {
705 705
 			$this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema);
706 706
 		}
707
-		catch(Exception\InvalidSql $e)
707
+		catch (Exception\InvalidSql $e)
708 708
 		{
709 709
 			// try inserting them one by one, ignoring doublicates
710
-			foreach($rows as $data)
710
+			foreach ($rows as $data)
711 711
 			{
712 712
 				try {
713 713
 					$this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema);
714 714
 				}
715
-				catch(Exception\InvalidSql $e) {
715
+				catch (Exception\InvalidSql $e) {
716 716
 					echo "<p>".$e->getMessage()."</p>\n";
717 717
 				}
718 718
 			}
@@ -727,11 +727,11 @@  discard block
 block discarded – undo
727 727
 	private static function remove_dir_content($dir)
728 728
 	{
729 729
 		$list = scandir($dir);
730
-		while($file = $list[0])
730
+		while ($file = $list[0])
731 731
 		{
732
-			if(is_dir($file) && $file != '.' && $file != '..')
732
+			if (is_dir($file) && $file != '.' && $file != '..')
733 733
 			    self::remove_dir_content($dir.'/'.$file);
734
-			if(is_file($file) && $file != '.' && $file != '..')
734
+			if (is_file($file) && $file != '.' && $file != '..')
735 735
 			    unlink($dir.'/'.$file);
736 736
 			array_shift($list);
737 737
 		}
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 	 * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups
757 757
 	 * @return array
758 758
 	 */
759
-	public static function csv_split($line, $keys=null, $blobs=array(), $bools=array())
759
+	public static function csv_split($line, $keys = null, $blobs = array(), $bools = array())
760 760
 	{
761 761
 		if (function_exists('str_getcsv'))	// php5.3+
762 762
 		{
@@ -769,9 +769,9 @@  discard block
 block discarded – undo
769 769
 				'\\n'    => "\n",
770 770
 				'\\r'    => "\r")), ',', '"', '\0');
771 771
 			// replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash
772
-			foreach($fields as &$field)
772
+			foreach ($fields as &$field)
773 773
 			{
774
-				switch($field)
774
+				switch ($field)
775 775
 				{
776 776
 					case self::NULL_TOKEN:
777 777
 						$field = 'NULL';
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 			{
789 789
 				$fields = array_combine($keys, $fields);
790 790
 				// base64-decode blob columns, if they are base64 encoded
791
-				foreach($blobs as $key)
791
+				foreach ($blobs as $key)
792 792
 				{
793 793
 					if (!is_null($fields[$key]) && ($tmp = base64_decode($fields[$key], true)) !== false)
794 794
 					{
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 					}
797 797
 				}
798 798
 				// decode bool columns, they might be 't'/'f' for old PostgreSQL backups
799
-				foreach($bools as $key)
799
+				foreach ($bools as $key)
800 800
 				{
801 801
 					$fields[$key] = Api\Db::from_bool($fields[$key]);
802 802
 				}
@@ -804,11 +804,11 @@  discard block
 block discarded – undo
804 804
 			return $fields;
805 805
 		}
806 806
 		// pre 5.3 implementation
807
-		$fields = explode(',',trim($line));
807
+		$fields = explode(',', trim($line));
808 808
 
809 809
 		$str_pending = False;
810 810
 		$n = 0;
811
-		foreach($fields as $field)
811
+		foreach ($fields as $field)
812 812
 		{
813 813
 			if ($str_pending !== False)
814 814
 			{
@@ -819,12 +819,12 @@  discard block
 block discarded – undo
819 819
 
820 820
 			if ($field[0] == '"')
821 821
 			{
822
-				if (substr($field,-1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/',$field))
822
+				if (substr($field, -1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/', $field))
823 823
 				{
824 824
 					$str_pending = $field;
825 825
 					continue;
826 826
 				}
827
-				$arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1)));
827
+				$arr[$key] = str_replace(self::BACKSLASH_TOKEN, '\\', str_replace(array('\\\\', '\\n', '\\r', '\\"'), array(self::BACKSLASH_TOKEN, "\n", "\r", '"'), substr($field, 1, -1)));
828 828
 			}
829 829
 			elseif ($keys && strlen($field) > 26)
830 830
 			{
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 	/**
847 847
 	 * escape data for csv
848 848
 	 */
849
-	public static function escape_data(&$data,$col,$defs)
849
+	public static function escape_data(&$data, $col, $defs)
850 850
 	{
851 851
 		if (is_null($data))
852 852
 		{
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
 		}
855 855
 		else
856 856
 		{
857
-			switch($defs[$col]['type'])
857
+			switch ($defs[$col]['type'])
858 858
 			{
859 859
 				case 'int':
860 860
 				case 'auto':
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 					$data = (int)Api\Db::from_bool($data);
870 870
 					break;
871 871
 				default:
872
-					$data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"';
872
+					$data = '"'.str_replace(array('\\', "\n", "\r", '"'), array('\\\\', '\\n', '\\r', '\\"'), $data).'"';
873 873
 					break;
874 874
 			}
875 875
 		}
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 	 *	default of null limits memory usage if there is no primary key, by locking table and use ROW_CHUCK
889 889
 	 * @todo use https://github.com/maennchen/ZipStream-PHP to not assemble all files in memmory
890 890
 	 */
891
-	function backup($f, $lock_table=null)
891
+	function backup($f, $lock_table = null)
892 892
 	{
893 893
 		//echo "function backup($f)<br>";	// !
894 894
 		@set_time_limit(0);
@@ -904,15 +904,15 @@  discard block
 block discarded – undo
904 904
 		$name = $this->backup_dir.'/db_backup-'.date('YmdHi');
905 905
 		$filename = $name.'.zip';
906 906
 		$zippresent = false;
907
-		if(class_exists('ZipArchive') && $this->backup_files)
907
+		if (class_exists('ZipArchive') && $this->backup_files)
908 908
 		{
909 909
 			$zip = new ZipArchive;
910
-			if(is_object($zip))
910
+			if (is_object($zip))
911 911
 			{
912 912
 				$zippresent = true;
913 913
 				//echo '-> is_object($zip); '.$filename.'<br>';	// !
914 914
 				$res = $zip->open($filename, ZipArchive::CREATE);
915
-				if($res !== TRUE)
915
+				if ($res !== TRUE)
916 916
 				{
917 917
 					//echo '   -> !$res<br>';	// !
918 918
 					return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n";
@@ -920,22 +920,22 @@  discard block
 block discarded – undo
920 920
 				$file_list = $this->get_file_list($dir);
921 921
 			}
922 922
 		}
923
-		fwrite($f,"EGroupware backup from ".date('Y-m-d H:i:s')."\n\n");
923
+		fwrite($f, "EGroupware backup from ".date('Y-m-d H:i:s')."\n\n");
924 924
 
925
-		fwrite($f,"version: $this->api_version\n\n");
925
+		fwrite($f, "version: $this->api_version\n\n");
926 926
 
927
-		fwrite($f,"charset: $this->charset\n\n");
927
+		fwrite($f, "charset: $this->charset\n\n");
928 928
 
929
-		$this->schema_backup($f);	// add the schema in a human readable form too
929
+		$this->schema_backup($f); // add the schema in a human readable form too
930 930
 
931
-		fwrite($f,"\nschema: ".json_encode($this->schemas)."\n");
931
+		fwrite($f, "\nschema: ".json_encode($this->schemas)."\n");
932 932
 
933 933
 		// let apps know that backup is about to start
934 934
 		Api\Hooks::process('backup_starts', array(), true);
935 935
 
936
-		foreach($this->schemas as $table => $schema)
936
+		foreach ($this->schemas as $table => $schema)
937 937
 		{
938
-			if (in_array($table,$this->exclude_tables)) continue;	// dont backup
938
+			if (in_array($table, $this->exclude_tables)) continue; // dont backup
939 939
 
940 940
 			// do we have a primary key?
941 941
 			// --> use it to order and limit rows, to kope with rows being added during backup
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
 			do {
952 952
 				$num_rows = 0;
953 953
 				// querying only chunks for 10000 rows, to not run into memory limit on huge tables
954
-				foreach($this->db->select($table, '*',
954
+				foreach ($this->db->select($table, '*',
955 955
 					// limit by maximum primary key already received
956 956
 					empty($pk) || !$max ? false : $pk.' > '.$this->db->quote($max, $schema['fd'][$pk]['type']),
957 957
 					__LINE__, __FILE__,
@@ -962,15 +962,15 @@  discard block
 block discarded – undo
962 962
 					false, self::ROW_CHUNK) as $row)
963 963
 				{
964 964
 					if (!empty($pk)) $max = $row[$pk];
965
-					if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
965
+					if ($total === 0) fwrite($f, "\ntable: $table\n".implode(',', array_keys($row))."\n");
966 966
 
967 967
 					array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']);
968
-					fwrite($f,implode(',',$row)."\n");
968
+					fwrite($f, implode(',', $row)."\n");
969 969
 					++$total;
970 970
 					++$num_rows;
971 971
 				}
972 972
 			}
973
-			while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
973
+			while ((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
974 974
 
975 975
 			if (!$pk) $this->db->rollback_lock($table);
976 976
 		}
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
 		// let apps know that backup is finished
979 979
 		Api\Hooks::process('backup_finished', array(), true);
980 980
 
981
-		if(!$zippresent)  // save without files
981
+		if (!$zippresent)  // save without files
982 982
 		{
983 983
 			if ($this->backup_files)
984 984
 			{
@@ -993,16 +993,16 @@  discard block
 block discarded – undo
993 993
 		//echo $name.'<br>';
994 994
 		$zip->addFile($name, 'database_backup/'.basename($name));
995 995
 		$count = 1;
996
-		foreach($file_list as $file)
996
+		foreach ($file_list as $file)
997 997
 		{
998 998
 			//echo substr($file,strlen($dir)+1).'<br>';
999 999
 			//echo $file.'<br>';
1000
-			$zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file);
1001
-			if(($count++) == 100) { // the file descriptor limit
1000
+			$zip->addFile($file, substr($file, strlen($dir) + 1)); //,substr($file);
1001
+			if (($count++) == 100) { // the file descriptor limit
1002 1002
 				$zip->close();
1003
-				if(($zip = new ZipArchive())) {
1003
+				if (($zip = new ZipArchive())) {
1004 1004
 					$zip->open($filename);
1005
-					$count =0;
1005
+					$count = 0;
1006 1006
 				}
1007 1007
 			}
1008 1008
 		}
@@ -1025,17 +1025,17 @@  discard block
 block discarded – undo
1025 1025
 	{
1026 1026
 		//chdir($f);
1027 1027
 		//echo "Processing $f <br>";
1028
-		if ($path_name =='') $path_name = $f;
1028
+		if ($path_name == '') $path_name = $f;
1029 1029
 		$tlist = scandir($f);
1030 1030
 		$list = array();
1031 1031
 		$i = $cnt;
1032
-		while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1032
+		while ($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1033 1033
 		{
1034
-			if($file == '.' || $file == '..')
1034
+			if ($file == '.' || $file == '..')
1035 1035
 			{
1036 1036
 				array_shift($tlist);
1037 1037
 			}
1038
-			elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false)
1038
+			elseif ($file == 'debug.txt' && stripos($f, 'activesync') !== false)
1039 1039
 			{
1040 1040
 				// skip activesync debug.txt on backupFiles
1041 1041
 				//error_log(__METHOD__.__LINE__.'->'.$f.'/'.$file);
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
 			}
1044 1044
 			else
1045 1045
 			{
1046
-				if(is_dir($f.'/'.$file))
1046
+				if (is_dir($f.'/'.$file))
1047 1047
 				{
1048 1048
 					$nlist = $this->get_file_list($f.'/'.$file, $i);
1049 1049
 					$list += $nlist;
@@ -1064,12 +1064,12 @@  discard block
 block discarded – undo
1064 1064
 	 *
1065 1065
 	 * @param resource|boolean $f
1066 1066
 	 */
1067
-	function schema_backup($f=False)
1067
+	function schema_backup($f = False)
1068 1068
 	{
1069
-		foreach($this->adodb->MetaTables('TABLES') as $table)
1069
+		foreach ($this->adodb->MetaTables('TABLES') as $table)
1070 1070
 		{
1071
-			if ($this->system_tables && preg_match($this->system_tables,$table) ||
1072
-				$this->egw_tables && !preg_match($this->egw_tables,$table))
1071
+			if ($this->system_tables && preg_match($this->system_tables, $table) ||
1072
+				$this->egw_tables && !preg_match($this->egw_tables, $table))
1073 1073
 			{
1074 1074
 				continue;
1075 1075
 			}
@@ -1088,17 +1088,17 @@  discard block
 block discarded – undo
1088 1088
 			}
1089 1089
 		}
1090 1090
 		$def = "\t\$phpgw_baseline = ";
1091
-		$def .= self::write_array($this->schemas,1);
1091
+		$def .= self::write_array($this->schemas, 1);
1092 1092
 		$def .= ";\n";
1093 1093
 
1094 1094
 		if ($f)
1095 1095
 		{
1096
-			fwrite($f,$def);
1096
+			fwrite($f, $def);
1097 1097
 		}
1098 1098
 		else
1099 1099
 		{
1100 1100
 			$def = "<?php\n\t/* EGroupware schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def;
1101
-			Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def));
1101
+			Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php', 'text/plain', bytes($def));
1102 1102
 			echo $def;
1103 1103
 		}
1104 1104
 	}
@@ -1108,9 +1108,9 @@  discard block
 block discarded – undo
1108 1108
 	 *
1109 1109
 	 * copied from etemplate/inc/class.db_tools.inc.php
1110 1110
 	 */
1111
-	private static function write_array($arr,$depth,$parent='')
1111
+	private static function write_array($arr, $depth, $parent = '')
1112 1112
 	{
1113
-		if (in_array($parent,array('pk','fk','ix','uc')))
1113
+		if (in_array($parent, array('pk', 'fk', 'ix', 'uc')))
1114 1114
 		{
1115 1115
 			$depth = 0;
1116 1116
 		}
@@ -1126,7 +1126,7 @@  discard block
 block discarded – undo
1126 1126
 		$def = "array($tabs".($tabs ? "\t" : '');
1127 1127
 
1128 1128
 		$n = 0;
1129
-		foreach($arr as $key => $val)
1129
+		foreach ($arr as $key => $val)
1130 1130
 		{
1131 1131
 			if (!is_int($key))
1132 1132
 			{
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
 			}
1135 1135
 			if (is_array($val))
1136 1136
 			{
1137
-				$def .= self::write_array($val,$parent == 'fd' ? 0 : $depth,$key);
1137
+				$def .= self::write_array($val, $parent == 'fd' ? 0 : $depth, $key);
1138 1138
 			}
1139 1139
 			else
1140 1140
 			{
@@ -1147,7 +1147,7 @@  discard block
 block discarded – undo
1147 1147
 					$def .= "'$val'";
1148 1148
 				}
1149 1149
 			}
1150
-			if ($n < count($arr)-1)
1150
+			if ($n < count($arr) - 1)
1151 1151
 			{
1152 1152
 				$def .= ",$tabs".($tabs ? "\t" : '');
1153 1153
 			}
Please login to merge, or discard this patch.
api/src/Db/CallbackIterator.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -94,10 +94,10 @@
 block discarded – undo
94 94
 	/**
95 95
 	 * Constructor
96 96
 	 *
97
-	 * @param Traversable $rs
97
+	 * @param \Traversable $rs
98 98
 	 * @param callback $callback
99 99
 	 * @param array $params =array() additional parameters, row is always first parameter
100
-	 * @param $key_callback =null optional callback, if you want different keys
100
+	 * @param \Closure $key_callback =null optional callback, if you want different keys
101 101
 	 */
102 102
 	public function __construct(\Traversable $rs, $callback, $params=array(), $key_callback=null)
103 103
 	{
Please login to merge, or discard this patch.
Spacing   +9 added lines, -10 removed lines patch added patch discarded remove patch
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 	 * @param array $params =array() additional parameters, row is always first parameter
100 100
 	 * @param $key_callback =null optional callback, if you want different keys
101 101
 	 */
102
-	public function __construct(\Traversable $rs, $callback, $params=array(), $key_callback=null)
102
+	public function __construct(\Traversable $rs, $callback, $params = array(), $key_callback = null)
103 103
 	{
104 104
 		$this->callback = $callback;
105 105
 		$this->params = $params;
106 106
 		$this->key_callback = $key_callback;
107 107
 
108
-		if (is_a($rs,'IteratorAggregate'))
108
+		if (is_a($rs, 'IteratorAggregate'))
109 109
 		{
110 110
 			$this->rs = $rs->getIterator();
111 111
 		}
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function current()
124 124
 	{
125
-		if (is_a($this->rs,'iterator'))
125
+		if (is_a($this->rs, 'iterator'))
126 126
 		{
127 127
 			$params = $this->params;
128 128
 			array_unshift($params, $this->rs->current());
@@ -138,11 +138,10 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function key()
140 140
 	{
141
-		if (is_a($this->rs,'iterator'))
141
+		if (is_a($this->rs, 'iterator'))
142 142
 		{
143 143
 			return $this->key_callback ?
144
-				call_user_func($this->key_callback, $this->rs->current()) :
145
-				$this->rs->key();
144
+				call_user_func($this->key_callback, $this->rs->current()) : $this->rs->key();
146 145
 		}
147 146
 		return 0;
148 147
 	}
@@ -152,7 +151,7 @@  discard block
 block discarded – undo
152 151
 	 */
153 152
 	public function next()
154 153
 	{
155
-		if (is_a($this->rs,'iterator'))
154
+		if (is_a($this->rs, 'iterator'))
156 155
 		{
157 156
 			return $this->rs->next();
158 157
 		}
@@ -163,7 +162,7 @@  discard block
 block discarded – undo
163 162
 	 */
164 163
 	public function rewind()
165 164
 	{
166
-		if (is_a($this->rs,'iterator'))
165
+		if (is_a($this->rs, 'iterator'))
167 166
 		{
168 167
 			return $this->rs->rewind();
169 168
 		}
@@ -174,9 +173,9 @@  discard block
 block discarded – undo
174 173
 	 *
175 174
 	 * @return boolean
176 175
 	 */
177
-	public function valid ()
176
+	public function valid()
178 177
 	{
179
-		if (is_a($this->rs,'iterator'))
178
+		if (is_a($this->rs, 'iterator'))
180 179
 		{
181 180
 			return $this->rs->valid();
182 181
 		}
Please login to merge, or discard this patch.
api/src/Db/Deprecated.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	* @deprecated not used anymore as it costs to much performance, use transactions if needed
186 186
 	* @param string $table name of table to lock
187 187
 	* @param string $mode type of lock required (optional), default write
188
-	* @return bool True if sucessful, False if fails
188
+	* @return boolean|null True if sucessful, False if fails
189 189
 	*/
190 190
 	function lock($table, $mode='write')
191 191
 	{
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	* Unlock a table
197 197
 	*
198 198
 	* @deprecated not used anymore as it costs to much performance, use transactions if needed
199
-	* @return bool True if sucessful, False if fails
199
+	* @return boolean|null True if sucessful, False if fails
200 200
 	*/
201 201
 	function unlock()
202 202
 	{}
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -41,19 +41,19 @@  discard block
 block discarded – undo
41 41
 	var $Query_ID = 0;
42 42
 
43 43
 	/**
44
-	* Execute a query
45
-	*
46
-	* @param string $Query_String the query to be executed
47
-	* @param int $line the line method was called from - use __LINE__
48
-	* @param string $file the file method was called from - use __FILE__
49
-	* @param int $offset row to start from, default 0
50
-	* @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']
51
-	* @param array|boolean $inputarr array for binding variables to parameters or false (default)
52
-	* @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM
53
-	* @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!)
54
-	* @return ADORecordSet or false, if the query fails
55
-	* @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code
56
-	*/
44
+	 * Execute a query
45
+	 *
46
+	 * @param string $Query_String the query to be executed
47
+	 * @param int $line the line method was called from - use __LINE__
48
+	 * @param string $file the file method was called from - use __FILE__
49
+	 * @param int $offset row to start from, default 0
50
+	 * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']
51
+	 * @param array|boolean $inputarr array for binding variables to parameters or false (default)
52
+	 * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM
53
+	 * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!)
54
+	 * @return ADORecordSet or false, if the query fails
55
+	 * @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code
56
+	 */
57 57
 	function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true)
58 58
 	{
59 59
 		// New query, discard previous result.
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 	}
77 77
 
78 78
 	/**
79
-	* Escape strings before sending them to the database
80
-	*
81
-	* @deprecated use quote($value,$type='') instead
82
-	* @param string $str the string to be escaped
83
-	* @return string escaped sting
84
-	*/
79
+	 * Escape strings before sending them to the database
80
+	 *
81
+	 * @deprecated use quote($value,$type='') instead
82
+	 * @param string $str the string to be escaped
83
+	 * @return string escaped sting
84
+	 */
85 85
 	function db_addslashes($str)
86 86
 	{
87 87
 		if (!isset($str) || $str == '')
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 	}
108 108
 
109 109
 	/**
110
-	* Move to the next row in the results set
111
-	*
112
-	* Specifying a fetch_mode only works for newly fetched rows, the first row always gets fetched by query!!!
113
-	*
114
-	* @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object
115
-	* @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM
116
-	* @return bool was another row found?
117
-	*/
110
+	 * Move to the next row in the results set
111
+	 *
112
+	 * Specifying a fetch_mode only works for newly fetched rows, the first row always gets fetched by query!!!
113
+	 *
114
+	 * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object
115
+	 * @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM
116
+	 * @return bool was another row found?
117
+	 */
118 118
 	function next_record($fetch_mode=self::FETCH_BOTH)
119 119
 	{
120 120
 		if (!$this->Query_ID)
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
 	}
165 165
 
166 166
 	/**
167
-	* Move to position in result set
168
-	*
169
-	* @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone
170
-	* @param int $pos required row (optional), default first row
171
-	* @return boolean true if sucessful or false if not found
172
-	*/
167
+	 * Move to position in result set
168
+	 *
169
+	 * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone
170
+	 * @param int $pos required row (optional), default first row
171
+	 * @return boolean true if sucessful or false if not found
172
+	 */
173 173
 	function seek($pos = 0)
174 174
 	{
175 175
 		if (!$this->Query_ID  || !$this->Query_ID->Move($this->Row = $pos))
@@ -180,74 +180,74 @@  discard block
 block discarded – undo
180 180
 	}
181 181
 
182 182
 	/**
183
-	* Lock a table
184
-	*
185
-	* @deprecated not used anymore as it costs to much performance, use transactions if needed
186
-	* @param string $table name of table to lock
187
-	* @param string $mode type of lock required (optional), default write
188
-	* @return bool True if sucessful, False if fails
189
-	*/
183
+	 * Lock a table
184
+	 *
185
+	 * @deprecated not used anymore as it costs to much performance, use transactions if needed
186
+	 * @param string $table name of table to lock
187
+	 * @param string $mode type of lock required (optional), default write
188
+	 * @return bool True if sucessful, False if fails
189
+	 */
190 190
 	function lock($table, $mode='write')
191 191
 	{
192 192
 		unset($table, $mode);	// not used anymore
193 193
 	}
194 194
 
195 195
 	/**
196
-	* Unlock a table
197
-	*
198
-	* @deprecated not used anymore as it costs to much performance, use transactions if needed
199
-	* @return bool True if sucessful, False if fails
200
-	*/
196
+	 * Unlock a table
197
+	 *
198
+	 * @deprecated not used anymore as it costs to much performance, use transactions if needed
199
+	 * @return bool True if sucessful, False if fails
200
+	 */
201 201
 	function unlock()
202 202
 	{}
203 203
 
204 204
 	/**
205
-	* Number of rows in current result set
206
-	*
207
-	* @deprecated use the result-object returned by query/select()->NumRows(), so you can use the global db-object and not a clone
208
-	* @return int number of rows
209
-	*/
205
+	 * Number of rows in current result set
206
+	 *
207
+	 * @deprecated use the result-object returned by query/select()->NumRows(), so you can use the global db-object and not a clone
208
+	 * @return int number of rows
209
+	 */
210 210
 	function num_rows()
211 211
 	{
212 212
 		return $this->Query_ID ? $this->Query_ID->RecordCount() : False;
213 213
 	}
214 214
 
215 215
 	/**
216
-	* Number of fields in current row
217
-	*
218
-	* @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone
219
-	* @return int number of fields
220
-	*/
216
+	 * Number of fields in current row
217
+	 *
218
+	 * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone
219
+	 * @return int number of fields
220
+	 */
221 221
 	function num_fields()
222 222
 	{
223 223
 		return $this->Query_ID ? $this->Query_ID->FieldCount() : False;
224 224
 	}
225 225
 
226 226
 	/**
227
-	* @deprecated use num_rows()
228
-	*/
227
+	 * @deprecated use num_rows()
228
+	 */
229 229
 	function nf()
230 230
 	{
231 231
 		return $this->num_rows();
232 232
 	}
233 233
 
234 234
 	/**
235
-	* @deprecated use print num_rows()
236
-	*/
235
+	 * @deprecated use print num_rows()
236
+	 */
237 237
 	function np()
238 238
 	{
239 239
 		print $this->num_rows();
240 240
 	}
241 241
 
242 242
 	/**
243
-	* Return the value of a column
244
-	*
245
-	* @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone
246
-	* @param string|integer $Name name of field or positional index starting from 0
247
-	* @param bool $strip_slashes string escape chars from field(optional), default false
248
-	*	depricated param, as correctly quoted values dont need any stripslashes!
249
-	* @return string the field value
250
-	*/
243
+	 * Return the value of a column
244
+	 *
245
+	 * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone
246
+	 * @param string|integer $Name name of field or positional index starting from 0
247
+	 * @param bool $strip_slashes string escape chars from field(optional), default false
248
+	 *	depricated param, as correctly quoted values dont need any stripslashes!
249
+	 * @return string the field value
250
+	 */
251 251
 	function f($Name, $strip_slashes = False)
252 252
 	{
253 253
 		if ($strip_slashes)
@@ -258,26 +258,26 @@  discard block
 block discarded – undo
258 258
 	}
259 259
 
260 260
 	/**
261
-	* Print the value of a field
262
-	*
263
-	* @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone
264
-	* @param string $Name name of field to print
265
-	* @param bool $strip_slashes string escape chars from field(optional), default false
266
-	*	depricated param, as correctly quoted values dont need any stripslashes!
267
-	*/
261
+	 * Print the value of a field
262
+	 *
263
+	 * @deprecated use the result-object returned by query() or select() direct, so you can use the global db-object and not a clone
264
+	 * @param string $Name name of field to print
265
+	 * @param bool $strip_slashes string escape chars from field(optional), default false
266
+	 *	depricated param, as correctly quoted values dont need any stripslashes!
267
+	 */
268 268
 	function p($Name, $strip_slashes = True)
269 269
 	{
270 270
 		print $this->f($Name, $strip_slashes);
271 271
 	}
272 272
 
273 273
 	/**
274
-	* Returns a query-result-row as an associative array (no numerical keys !!!)
275
-	*
276
-	* @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object
277
-	* @param bool $do_next_record should next_record() be called or not (default not)
278
-	* @param string $strip ='' string to strip of the column-name, default ''
279
-	* @return array/bool the associative array or False if no (more) result-row is availible
280
-	*/
274
+	 * Returns a query-result-row as an associative array (no numerical keys !!!)
275
+	 *
276
+	 * @deprecated use foreach(query() or foreach(select() to loop over the query using the global db object
277
+	 * @param bool $do_next_record should next_record() be called or not (default not)
278
+	 * @param string $strip ='' string to strip of the column-name, default ''
279
+	 * @return array/bool the associative array or False if no (more) result-row is availible
280
+	 */
281 281
 	function row($do_next_record=False,$strip='')
282 282
 	{
283 283
 		if ($do_next_record && !$this->next_record(self::FETCH_ASSOC) || !is_array($this->Record))
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	* @return ADORecordSet or false, if the query fails
55 55
 	* @throws EGroupware\Api\Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code
56 56
 	*/
57
-	function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true)
57
+	function query($Query_String, $line = '', $file = '', $offset = 0, $num_rows = -1, $inputarr = false, $fetchmode = self::FETCH_BOTH, $reconnect = true)
58 58
 	{
59 59
 		// New query, discard previous result.
60 60
 		if ($this->Query_ID)
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	function free()
104 104
 	{
105
-		unset($this->Query_ID);	// else copying of the db-object does not work
105
+		unset($this->Query_ID); // else copying of the db-object does not work
106 106
 		$this->Query_ID = 0;
107 107
 	}
108 108
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	* @param int $fetch_mode self::FETCH_BOTH = numerical+assoc keys (eGW default), self::FETCH_ASSOC or self::FETCH_NUM
116 116
 	* @return bool was another row found?
117 117
 	*/
118
-	function next_record($fetch_mode=self::FETCH_BOTH)
118
+	function next_record($fetch_mode = self::FETCH_BOTH)
119 119
 	{
120 120
 		if (!$this->Query_ID)
121 121
 		{
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		}
136 136
 		if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper')	// maxdb, oracle, ...
137 137
 		{
138
-			switch($fetch_mode)
138
+			switch ($fetch_mode)
139 139
 			{
140 140
 				case self::FETCH_ASSOC:
141 141
 					$this->Record = array_change_key_case($this->Record);
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
 	*/
173 173
 	function seek($pos = 0)
174 174
 	{
175
-		if (!$this->Query_ID  || !$this->Query_ID->Move($this->Row = $pos))
175
+		if (!$this->Query_ID || !$this->Query_ID->Move($this->Row = $pos))
176 176
 		{
177
-			throw new Exception("seek($pos) failed: resultset has " . $this->num_rows() . " rows");
177
+			throw new Exception("seek($pos) failed: resultset has ".$this->num_rows()." rows");
178 178
 		}
179 179
 		return True;
180 180
 	}
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
 	* @param string $mode type of lock required (optional), default write
188 188
 	* @return bool True if sucessful, False if fails
189 189
 	*/
190
-	function lock($table, $mode='write')
190
+	function lock($table, $mode = 'write')
191 191
 	{
192
-		unset($table, $mode);	// not used anymore
192
+		unset($table, $mode); // not used anymore
193 193
 	}
194 194
 
195 195
 	/**
@@ -278,18 +278,18 @@  discard block
 block discarded – undo
278 278
 	* @param string $strip ='' string to strip of the column-name, default ''
279 279
 	* @return array/bool the associative array or False if no (more) result-row is availible
280 280
 	*/
281
-	function row($do_next_record=False,$strip='')
281
+	function row($do_next_record = False, $strip = '')
282 282
 	{
283 283
 		if ($do_next_record && !$this->next_record(self::FETCH_ASSOC) || !is_array($this->Record))
284 284
 		{
285 285
 			return False;
286 286
 		}
287 287
 		$result = array();
288
-		foreach($this->Record as $column => $value)
288
+		foreach ($this->Record as $column => $value)
289 289
 		{
290 290
 			if (!is_numeric($column))
291 291
 			{
292
-				if ($strip) $column = str_replace($strip,'',$column);
292
+				if ($strip) $column = str_replace($strip, '', $column);
293 293
 
294 294
 				$result[$column] = $value;
295 295
 			}
Please login to merge, or discard this patch.
Braces   +17 added lines, -5 removed lines patch added patch discarded remove patch
@@ -121,10 +121,13 @@  discard block
 block discarded – undo
121 121
 		{
122 122
 			throw new Exception('next_record called with no query pending.');
123 123
 		}
124
-		if ($this->Row)	// first row is already fetched
124
+		if ($this->Row)
125
+		{
126
+			// first row is already fetched
125 127
 		{
126 128
 			$this->Query_ID->MoveNext();
127 129
 		}
130
+		}
128 131
 		++$this->Row;
129 132
 
130 133
 		$this->Record = $this->Query_ID->fields;
@@ -133,12 +136,15 @@  discard block
 block discarded – undo
133 136
 		{
134 137
 			return False;
135 138
 		}
136
-		if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper')	// maxdb, oracle, ...
139
+		if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper')
140
+		{
141
+			// maxdb, oracle, ...
137 142
 		{
138 143
 			switch($fetch_mode)
139 144
 			{
140 145
 				case self::FETCH_ASSOC:
141 146
 					$this->Record = array_change_key_case($this->Record);
147
+		}
142 148
 					break;
143 149
 				case self::FETCH_NUM:
144 150
 					$this->Record = array_values($this->Record);
@@ -199,7 +205,8 @@  discard block
 block discarded – undo
199 205
 	* @return bool True if sucessful, False if fails
200 206
 	*/
201 207
 	function unlock()
202
-	{}
208
+	{
209
+}
203 210
 
204 211
 	/**
205 212
 	* Number of rows in current result set
@@ -289,7 +296,10 @@  discard block
 block discarded – undo
289 296
 		{
290 297
 			if (!is_numeric($column))
291 298
 			{
292
-				if ($strip) $column = str_replace($strip,'',$column);
299
+				if ($strip)
300
+				{
301
+					$column = str_replace($strip,'',$column);
302
+				}
293 303
 
294 304
 				$result[$column] = $value;
295 305
 			}
@@ -301,4 +311,6 @@  discard block
 block discarded – undo
301 311
 /**
302 312
  * @deprecated use EGroupware\Api\Db\CallbackIterator
303 313
  */
304
-class egw_db_callback_iterator extends Api\Db\CallbackIterator {}
314
+class egw_db_callback_iterator extends Api\Db\CallbackIterator
315
+{
316
+}
Please login to merge, or discard this patch.
api/src/Db/Schema.php 5 patches
Doc Comments   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * Constructor of schema-processor
97 97
 	 *
98 98
 	 * @param string $dbms type of the database: 'mysql','pgsql','mssql','maxdb'
99
-	 * @param Db $db =null database class, if null we use $GLOBALS['egw']->db
99
+	 * @param  $db =null database class, if null we use $GLOBALS['egw']->db
100 100
 	 * @return schema_proc
101 101
 	 */
102 102
 	function __construct($dbms=False, Api\Db $db=null)
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 	 *
397 397
 	 * @param string $sTableName
398 398
 	 * @param bool $preserveValue
399
-	 * @return boolean|string sequence-name or false
399
+	 * @return false|string sequence-name or false
400 400
 	 */
401 401
 	function _PostgresHasOldSequence($sTableName,$preserveValue=False)
402 402
 	{
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 	/**
423 423
 	 * Check if we have an old, not automaticaly droped sequence and drop it
424 424
 	 *
425
-	 * @param $sTableName
425
+	 * @param string $sTableName
426 426
 	 */
427 427
 	function _PostgresTestDropOldSequence($sTableName)
428 428
 	{
@@ -877,12 +877,7 @@  discard block
 block discarded – undo
877 877
 	/**
878 878
 	* Execute a query
879 879
 	*
880
-	* @param string $Query_String the query to be executed
881
-	* @param mixed $line the line method was called from - use __LINE__
882
-	* @param string $file the file method was called from - use __FILE__
883
-	* @param int $offset row to start from
884
-	* @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
885
-	* @return ADORecordSet or false, if the query fails
880
+	* @param integer $line
886 881
 	*/
887 882
 	function query($sQuery, $line='', $file='')
888 883
 	{
@@ -898,8 +893,6 @@  discard block
 block discarded – undo
898 893
 	*	if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence)
899 894
 	* @param int $line line-number to pass to query
900 895
 	* @param string $file file-name to pass to query
901
-	* @param string $app=false string with name of app, this need to be set in setup anyway!!!
902
-	* @return ADORecordSet or false, if the query fails
903 896
 	*/
904 897
 	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false)
905 898
 	{
@@ -910,7 +903,6 @@  discard block
 block discarded – undo
910 903
 	 * Execute the Sql statements in an array and give diagnostics, if any error occures
911 904
 	 *
912 905
 	 * @param array $aSql array of SQL strings to execute
913
-	 * @param int $debug_level for which debug_level (and higher) should the diagnostics always been printed
914 906
 	 * @param string $debug variable number of arguments for the debug_message functions in case of an error
915 907
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
916 908
 	 */
@@ -953,7 +945,7 @@  discard block
 block discarded – undo
953 945
 	 * b) we use the table-names plus all column-names and remove dublicate parts
954 946
 	 *
955 947
 	 * @internal
956
-	 * @param $sTableName string name of the table
948
+	 * @param string $sTableName string name of the table
957 949
 	 * @param $aColumnNames array of column-names or string with a single column-name
958 950
 	 * @return string the index-name
959 951
 	 */
@@ -1010,6 +1002,7 @@  discard block
 block discarded – undo
1010 1002
 
1011 1003
 	/**
1012 1004
 	 * Giving a non-fatal error-message
1005
+	 * @param string $str
1013 1006
 	 */
1014 1007
 	function error($str)
1015 1008
 	{
@@ -1038,7 +1031,7 @@  discard block
 block discarded – undo
1038 1031
 	 *
1039 1032
 	 * The parameters get formated depending on their type.
1040 1033
 	 *
1041
-	 * @param $msg string message with parameters/variables like lang(), eg. '%1'
1034
+	 * @param string $msg string message with parameters/variables like lang(), eg. '%1'
1042 1035
 	 * @param $backtrace include a function-backtrace, default True=On
1043 1036
 	 *	should only be set to False=Off, if your code ensures a call with backtrace=On was made before !!!
1044 1037
 	 * @param $param mixed a variable number of parameters, to be inserted in $msg
Please login to merge, or discard this patch.
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -101,19 +101,19 @@  discard block
 block discarded – undo
101 101
 	 */
102 102
 	function __construct($dbms=False, Api\Db $db=null)
103 103
 	{
104
-	    if(is_object($db))
104
+		if(is_object($db))
105 105
 		{
106 106
 			$this->m_odb = $db;
107
-	    }
108
-	    else
109
-	    {
107
+		}
108
+		else
109
+		{
110 110
 			$this->m_odb = isset($GLOBALS['egw']->db) && is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db;
111
-	    }
112
-	    if (!($this->m_odb instanceof Api\Db))
113
-	    {
114
-	    	throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!');
115
-	    }
116
-	    $this->m_odb->connect();
111
+		}
112
+		if (!($this->m_odb instanceof Api\Db))
113
+		{
114
+			throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!');
115
+		}
116
+		$this->m_odb->connect();
117 117
 		$this->capabilities =& $this->m_odb->capabilities;
118 118
 
119 119
 		$this->sType = $dbms ? $dbms : $this->m_odb->Type;
@@ -828,79 +828,79 @@  discard block
 block discarded – undo
828 828
 	}
829 829
 
830 830
 	/**
831
-	* Return the value of a column
832
-	*
833
-	* @param string|integer $value name of field or positional index starting from 0
834
-	* @param bool $strip_slashes string escape chars from field(optional), default false
835
-	* @deprecated use result-set returned by query/select
836
-	* @return string the field value
837
-	*/
831
+	 * Return the value of a column
832
+	 *
833
+	 * @param string|integer $value name of field or positional index starting from 0
834
+	 * @param bool $strip_slashes string escape chars from field(optional), default false
835
+	 * @deprecated use result-set returned by query/select
836
+	 * @return string the field value
837
+	 */
838 838
 	function f($value,$strip_slashes=False)
839 839
 	{
840 840
 		if (!($this->m_odb instanceof Deprecated))
841 841
 		{
842
-	    	throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!');
842
+			throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!');
843 843
 		}
844 844
 		return $this->m_odb->f($value,$strip_slashes);
845 845
 	}
846 846
 
847 847
 	/**
848
-	* Number of rows in current result set
849
-	*
850
-	* @deprecated use result-set returned by query/select
851
-	* @return int number of rows
852
-	*/
848
+	 * Number of rows in current result set
849
+	 *
850
+	 * @deprecated use result-set returned by query/select
851
+	 * @return int number of rows
852
+	 */
853 853
 	function num_rows()
854 854
 	{
855 855
 		if (!($this->m_odb instanceof Deprecated))
856 856
 		{
857
-	    	throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!');
857
+			throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!');
858 858
 		}
859 859
 		return $this->m_odb->num_rows();
860 860
 	}
861 861
 
862 862
 	/**
863
-	* Move to the next row in the results set
864
-	*
865
-	* @deprecated use result-set returned by query/select
866
-	* @return bool was another row found?
867
-	*/
863
+	 * Move to the next row in the results set
864
+	 *
865
+	 * @deprecated use result-set returned by query/select
866
+	 * @return bool was another row found?
867
+	 */
868 868
 	function next_record()
869 869
 	{
870 870
 		if (!($this->m_odb instanceof Deprecated))
871 871
 		{
872
-	    	throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!');
872
+			throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!');
873 873
 		}
874 874
 		return $this->m_odb->next_record();
875 875
 	}
876 876
 
877 877
 	/**
878
-	* Execute a query
879
-	*
880
-	* @param string $Query_String the query to be executed
881
-	* @param mixed $line the line method was called from - use __LINE__
882
-	* @param string $file the file method was called from - use __FILE__
883
-	* @param int $offset row to start from
884
-	* @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
885
-	* @return ADORecordSet or false, if the query fails
886
-	*/
878
+	 * Execute a query
879
+	 *
880
+	 * @param string $Query_String the query to be executed
881
+	 * @param mixed $line the line method was called from - use __LINE__
882
+	 * @param string $file the file method was called from - use __FILE__
883
+	 * @param int $offset row to start from
884
+	 * @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
885
+	 * @return ADORecordSet or false, if the query fails
886
+	 */
887 887
 	function query($sQuery, $line='', $file='')
888 888
 	{
889 889
 		return $this->m_odb->query($sQuery, $line, $file);
890 890
 	}
891 891
 
892 892
 	/**
893
-	* Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type
894
-	*
895
-	* @param string $table name of the table
896
-	* @param array $data with column-name / value pairs
897
-	* @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
898
-	*	if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence)
899
-	* @param int $line line-number to pass to query
900
-	* @param string $file file-name to pass to query
901
-	* @param string $app=false string with name of app, this need to be set in setup anyway!!!
902
-	* @return ADORecordSet or false, if the query fails
903
-	*/
893
+	 * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type
894
+	 *
895
+	 * @param string $table name of the table
896
+	 * @param array $data with column-name / value pairs
897
+	 * @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
898
+	 *	if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence)
899
+	 * @param int $line line-number to pass to query
900
+	 * @param string $file file-name to pass to query
901
+	 * @param string $app=false string with name of app, this need to be set in setup anyway!!!
902
+	 * @return ADORecordSet or false, if the query fails
903
+	 */
904 904
 	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false)
905 905
 	{
906 906
 		return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement);
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.
Spacing   +181 added lines, -182 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 *
58 58
 	 * @var array
59 59
 	 */
60
-	var $max_index_length=array(
60
+	var $max_index_length = array(
61 61
 		'maxdb'  => 32,
62 62
 		'oracle' => 30,
63 63
 	);
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 	 * @param Db $db =null database class, if null we use $GLOBALS['egw']->db
100 100
 	 * @return schema_proc
101 101
 	 */
102
-	function __construct($dbms=False, Api\Db $db=null)
102
+	function __construct($dbms = False, Api\Db $db = null)
103 103
 	{
104
-	    if(is_object($db))
104
+	    if (is_object($db))
105 105
 		{
106 106
 			$this->m_odb = $db;
107 107
 	    }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	    	throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!');
115 115
 	    }
116 116
 	    $this->m_odb->connect();
117
-		$this->capabilities =& $this->m_odb->capabilities;
117
+		$this->capabilities = & $this->m_odb->capabilities;
118 118
 
119 119
 		$this->sType = $dbms ? $dbms : $this->m_odb->Type;
120 120
 		$this->adodb = &$this->m_odb->Link_ID;
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		// to allow some of the former translator-functions to be called, we assign ourself as the translator
127 127
 		$this->m_oTranslator = &$this;
128 128
 
129
-		switch($this->sType)
129
+		switch ($this->sType)
130 130
 		{
131 131
 			case 'maxdb':
132 132
 				$this->max_varchar_length = 8000;
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		}
143 143
 		if (is_object($GLOBALS['egw_setup']))
144 144
 		{
145
-			$this->system_charset =& $GLOBALS['egw_setup']->system_charset;
145
+			$this->system_charset = & $GLOBALS['egw_setup']->system_charset;
146 146
 		}
147 147
 		elseif (isset($GLOBALS['egw_info']['server']['system_charset']))
148 148
 		{
@@ -158,20 +158,20 @@  discard block
 block discarded – undo
158 158
 	 * @param boolean $ignore_length_limit =false should we take lenght-limits of indexes into account or not
159 159
 	 * @return boolean true if index over $columns exist in the $indexes array
160 160
 	 */
161
-	function _in_index($columns, $indexs, $ignore_length_limit=false)
161
+	function _in_index($columns, $indexs, $ignore_length_limit = false)
162 162
 	{
163 163
 		if (is_array($columns))
164 164
 		{
165 165
 			unset($columns['options']);
166
-			$columns = implode('-',$columns);
166
+			$columns = implode('-', $columns);
167 167
 			if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns);
168 168
 		}
169
-		foreach($indexs as $index)
169
+		foreach ($indexs as $index)
170 170
 		{
171 171
 			if (is_array($index))
172 172
 			{
173 173
 				unset($index['options']);
174
-				$index = implode('-',$index);
174
+				$index = implode('-', $index);
175 175
 			}
176 176
 			if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index);
177 177
 			if ($columns == $index) return true;
@@ -187,21 +187,21 @@  discard block
 block discarded – undo
187 187
 	 * @param bool $preserveSequence
188 188
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
189 189
 	 */
190
-	function CreateTable($sTableName, $aTableDef, $preserveSequence=False)
190
+	function CreateTable($sTableName, $aTableDef, $preserveSequence = False)
191 191
 	{
192 192
 		if ($this->debug)
193 193
 		{
194
-			$this->debug_message('schema_proc::CreateTable(%1,%2)',False,$sTableName, $aTableDef);
194
+			$this->debug_message('schema_proc::CreateTable(%1,%2)', False, $sTableName, $aTableDef);
195 195
 		}
196 196
 		// for mysql 4.0+ we set the charset for the table
197
-		if ($this->system_charset && substr($this->sType,0,5) == 'mysql' &&
198
-			(float) $this->m_odb->ServerInfo['version'] >= 4.0)
197
+		if ($this->system_charset && substr($this->sType, 0, 5) == 'mysql' &&
198
+			(float)$this->m_odb->ServerInfo['version'] >= 4.0)
199 199
 		{
200 200
 			$set_table_charset = array($this->sType => 'CHARACTER SET utf8');
201 201
 		}
202 202
 		// creating the table
203
-		$aSql = $this->dict->CreateTableSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef($aTableDef),$set_table_charset);
204
-		if (!($retVal = $this->ExecuteSQLArray($aSql,2,'CreateTableSQL(%1,%2) sql=%3',False,$sTableName,$ado_cols,$aSql)))
203
+		$aSql = $this->dict->CreateTableSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef($aTableDef), $set_table_charset);
204
+		if (!($retVal = $this->ExecuteSQLArray($aSql, 2, 'CreateTableSQL(%1,%2) sql=%3', False, $sTableName, $ado_cols, $aSql)))
205 205
 		{
206 206
 			return $retVal;
207 207
 		}
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
 		{
211 211
 			if (empty($mFields))
212 212
 			{
213
-				continue;	// cant create an index without fields (was observed in broken backups)
213
+				continue; // cant create an index without fields (was observed in broken backups)
214 214
 			}
215
-			if ($this->_in_index($mFields,array($aTableDef['pk'])))
215
+			if ($this->_in_index($mFields, array($aTableDef['pk'])))
216 216
 			{
217
-				continue;	// is already created as primary key
217
+				continue; // is already created as primary key
218 218
 			}
219
-			if (!($retVal = $this->CreateIndex($sTableName,$mFields,true,'',$name)))
219
+			if (!($retVal = $this->CreateIndex($sTableName, $mFields, true, '', $name)))
220 220
 			{
221 221
 				return $retVal;
222 222
 			}
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
 		{
227 227
 			if (empty($mFields))
228 228
 			{
229
-				continue;	// cant create an index without fields (was observed in broken backups)
229
+				continue; // cant create an index without fields (was observed in broken backups)
230 230
 			}
231
-			if ($this->_in_index($mFields,array($aTableDef['pk'])) ||
232
-				$this->_in_index($mFields,$aTableDef['uc']))
231
+			if ($this->_in_index($mFields, array($aTableDef['pk'])) ||
232
+				$this->_in_index($mFields, $aTableDef['uc']))
233 233
 			{
234
-				continue;	// is already created as primary key or unique index
234
+				continue; // is already created as primary key or unique index
235 235
 			}
236 236
 			$options = False;
237 237
 			if (is_array($mFields))
@@ -240,21 +240,21 @@  discard block
 block discarded – undo
240 240
 				{
241 241
 					if (isset($mFields['options'][$this->sType]))
242 242
 					{
243
-						$options = $mFields['options'][$this->sType];	// db-specific options, eg. index-type
244
-						if (!$options) continue;	// no index for our db-type
243
+						$options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type
244
+						if (!$options) continue; // no index for our db-type
245 245
 					}
246 246
 					unset($mFields['options']);
247 247
 				}
248 248
 			}
249
-			foreach((array)$mFields as $k => $col)
249
+			foreach ((array)$mFields as $k => $col)
250 250
 			{
251 251
 				// only create indexes on text-columns, if (db-)specifiy options are given or FULLTEXT for mysql
252 252
 				// most DB's cant do them and give errors
253
-				if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext')))
253
+				if (in_array($aTableDef['fd'][$col]['type'], array('text', 'longtext')))
254 254
 				{
255 255
 					if (is_array($mFields))	// index over multiple columns including a text column
256 256
 					{
257
-						$mFields[$k] .= '(32)';	// 32=limit of egw_addressbook_extra.extra_value to fix old backups
257
+						$mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups
258 258
 					}
259 259
 					elseif (!$options)	// index over a single text column and no options given
260 260
 					{
@@ -264,12 +264,12 @@  discard block
 block discarded – undo
264 264
 						}
265 265
 						else
266 266
 						{
267
-							continue 2;	// ignore that index, 2=not just column but whole index!
267
+							continue 2; // ignore that index, 2=not just column but whole index!
268 268
 						}
269 269
 					}
270 270
 				}
271 271
 			}
272
-			if (!($retVal = $this->CreateIndex($sTableName,$mFields,false,$options,$name)))
272
+			if (!($retVal = $this->CreateIndex($sTableName, $mFields, false, $options, $name)))
273 273
 			{
274 274
 				return $retVal;
275 275
 			}
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 			if (($seq = $this->_PostgresHasOldSequence($sTableName)))
281 281
 			{
282 282
 				$this->pgsql_old_seq = $this->pgsql_old_seq + 1;
283
-				$this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH " . $this->pgsql_old_seq,__LINE__,__FILE__);
283
+				$this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH ".$this->pgsql_old_seq, __LINE__, __FILE__);
284 284
 			}
285 285
 			$this->pgsql_old_seq = 0;
286 286
 		}
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 	 * @param boolean $bOutputHTML should we give diagnostics, default False
295 295
 	 * @return boolean True if no error, else False
296 296
 	 */
297
-	function DropAllTables($aTables, $bOutputHTML=False)
297
+	function DropAllTables($aTables, $bOutputHTML = False)
298 298
 	{
299
-		if(!is_array($aTables) || !isset($this->m_odb))
299
+		if (!is_array($aTables) || !isset($this->m_odb))
300 300
 		{
301 301
 			return False;
302 302
 		}
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
 		if ($this->debug) $bOutputHTML = True;
305 305
 		if ($bOutputHTML && !$this->debug) $this->debug = 2;
306 306
 
307
-		foreach(array_keys($aTables) as $sTableName)
307
+		foreach (array_keys($aTables) as $sTableName)
308 308
 		{
309
-			if($this->DropTable($sTableName))
309
+			if ($this->DropTable($sTableName))
310 310
 			{
311
-				if($bOutputHTML)
311
+				if ($bOutputHTML)
312 312
 				{
313
-					echo '<br>Drop Table <b>' . $sTableName . '</b>';
313
+					echo '<br>Drop Table <b>'.$sTableName.'</b>';
314 314
 				}
315 315
 			}
316 316
 			else
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 
334 334
 		$aSql = $this->dict->DropTableSql($sTableName);
335 335
 
336
-		return $this->ExecuteSQLArray($aSql,2,'DropTable(%1) sql=%2',False,$sTableName,$aSql);
336
+		return $this->ExecuteSQLArray($aSql, 2, 'DropTable(%1) sql=%2', False, $sTableName, $aSql);
337 337
 	}
338 338
 
339 339
 	/**
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
 	 */
347 347
 	function DropColumn($sTableName, $aTableDef, $sColumnName)
348 348
 	{
349
-		unset($aTableDef);	// not used, but required by function signature
349
+		unset($aTableDef); // not used, but required by function signature
350 350
 
351 351
 		if (!($table_def = $this->GetTableDefinition($sTableName))) return 0;
352 352
 		unset($table_def['fd'][$sColumnName]);
353 353
 
354
-		$aSql = $this->dict->DropColumnSql($sTableName,$sColumnName,$ado_table=$this->_egw2adodb_columndef($table_def));
354
+		$aSql = $this->dict->DropColumnSql($sTableName, $sColumnName, $ado_table = $this->_egw2adodb_columndef($table_def));
355 355
 
356
-		return $this->ExecuteSQLArray($aSql,2,'DropColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName,$ado_table,$aSql);
356
+		return $this->ExecuteSQLArray($aSql, 2, 'DropColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $ado_table, $aSql);
357 357
 	}
358 358
 
359 359
 	/**
@@ -372,12 +372,12 @@  discard block
 block discarded – undo
372 372
 			if (!($table_def = $this->GetTableDefinition($sOldTableName))) return 0;
373 373
 
374 374
 			// only use old PostgreSQL stuff, if we have an old sequence, otherwise rely on it being new enough
375
-			if ($this->_PostgresHasOldSequence($sOldTableName,True) &&
375
+			if ($this->_PostgresHasOldSequence($sOldTableName, True) &&
376 376
 				(count($table_def['pk']) || count($table_def['ix']) || count($table_def['uc'])))
377 377
 			{
378 378
 				if ($this->adodb->BeginTrans() &&
379
-					$this->CreateTable($sNewTableName,$table_def,True) &&
380
-					$this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName",__LINE__,__FILE__) &&
379
+					$this->CreateTable($sNewTableName, $table_def, True) &&
380
+					$this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName", __LINE__, __FILE__) &&
381 381
 					// sequence must be updated, after inserts containing pkey, otherwise new inserst will fail!
382 382
 					(count($table_def['pk']) !== 1 || $this->UpdateSequence($sNewTableName, $table_def['pk'][0])) &&
383 383
 					$this->DropTable($sOldTableName))
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 		}
392 392
 		$aSql = $this->dict->RenameTableSQL($sOldTableName, $sNewTableName);
393 393
 
394
-		return $this->ExecuteSQLArray($aSql,2,'RenameTableSQL(%1,%2) sql=%3',False,$sOldTableName,$sNewTableName,$aSql);
394
+		return $this->ExecuteSQLArray($aSql, 2, 'RenameTableSQL(%1,%2) sql=%3', False, $sOldTableName, $sNewTableName, $aSql);
395 395
 	}
396 396
 
397 397
 	/**
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 	 * @param bool $preserveValue
402 402
 	 * @return boolean|string sequence-name or false
403 403
 	 */
404
-	function _PostgresHasOldSequence($sTableName,$preserveValue=False)
404
+	function _PostgresHasOldSequence($sTableName, $preserveValue = False)
405 405
 	{
406 406
 		if ($this->sType != 'pgsql') return false;
407 407
 
@@ -409,14 +409,14 @@  discard block
 block discarded – undo
409 409
 		$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");
410 410
 
411 411
 		$matches = null;
412
-		if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches))
412
+		if ($seq && preg_match('/^nextval\(\'(.*)\'/', $seq, $matches))
413 413
 		{
414
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
414
+			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]);
415 415
 			return $matches[1];
416 416
 		}
417
-		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches))
417
+		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/', $seq2, $matches))
418 418
 		{
419
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
419
+			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]);
420 420
 			return $matches[1];
421 421
 		}
422 422
 		return false;
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 			// only drop sequence, if there is no dependency on it
436 436
 			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'"))
437 437
 			{
438
-				$this->query('DROP SEQUENCE '.$seq,__LINE__,__FILE__);
438
+				$this->query('DROP SEQUENCE '.$seq, __LINE__, __FILE__);
439 439
 			}
440 440
 		}
441 441
 	}
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		if (!($table_def = $this->GetTableDefinition($sTableName))) return 0;
454 454
 
455 455
 		// PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long
456
-		if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
456
+		if ($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
457 457
 			in_array($aColumnDef['type'], array('varchar', 'ascii')) &&
458 458
 			$table_def['fd'][$sColumnName]['precision'] > $aColumnDef['precision'])
459 459
 		{
@@ -468,12 +468,12 @@  discard block
 block discarded – undo
468 468
 		}
469 469
 		$table_def['fd'][$sColumnName] = $aColumnDef;
470 470
 
471
-		$aSql = $this->dict->AlterColumnSQL($sTableName,$ado_col = $this->_egw2adodb_columndef(array(
471
+		$aSql = $this->dict->AlterColumnSQL($sTableName, $ado_col = $this->_egw2adodb_columndef(array(
472 472
 				'fd' => array($sColumnName => $aColumnDef),
473 473
 				'pk' => array(),
474
-			)),$ado_table=$this->_egw2adodb_columndef($table_def));
474
+			)), $ado_table = $this->_egw2adodb_columndef($table_def));
475 475
 
476
-		return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$ado_col,$ado_table,$aSql);
476
+		return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $ado_col, $ado_table, $aSql);
477 477
 	}
478 478
 
479 479
 	/**
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 		}
496 496
 		else
497 497
 		{
498
-			foreach($table_def['fd'] as $col => $def)
498
+			foreach ($table_def['fd'] as $col => $def)
499 499
 			{
500 500
 				if (strtolower($col) == strtolower($sOldColumnName))
501 501
 				{
@@ -509,9 +509,9 @@  discard block
 block discarded – undo
509 509
 				'pk' => array(),
510 510
 			));
511 511
 
512
-		$aSql = $this->dict->RenameColumnSQL($sTableName,$sOldColumnName,$sNewColumnName,$col_def);
512
+		$aSql = $this->dict->RenameColumnSQL($sTableName, $sOldColumnName, $sNewColumnName, $col_def);
513 513
 
514
-		return $this->ExecuteSQLArray($aSql,2,'RenameColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sOldColumnName, $sNewColumnName,$aSql);
514
+		return $this->ExecuteSQLArray($aSql, 2, 'RenameColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sOldColumnName, $sNewColumnName, $aSql);
515 515
 	}
516 516
 
517 517
 	/**
@@ -524,12 +524,12 @@  discard block
 block discarded – undo
524 524
 	 */
525 525
 	function AddColumn($sTableName, $sColumnName, $aColumnDef)
526 526
 	{
527
-		$aSql = $this->dict->AddColumnSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef(array(
527
+		$aSql = $this->dict->AddColumnSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef(array(
528 528
 				'fd' => array($sColumnName => $aColumnDef),
529 529
 				'pk' => array(),
530 530
 			)));
531 531
 
532
-		return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName, $aColumnDef,$aSql);
532
+		return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $aColumnDef, $aSql);
533 533
 	}
534 534
 
535 535
 	/**
@@ -542,23 +542,23 @@  discard block
 block discarded – undo
542 542
 	 * @param string $sIdxName ='' name of the index, if not given (default) its created automaticaly
543 543
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
544 544
 	 */
545
-	function CreateIndex($sTableName,$aColumnNames,$bUnique=false,$options='',$sIdxName='')
545
+	function CreateIndex($sTableName, $aColumnNames, $bUnique = false, $options = '', $sIdxName = '')
546 546
 	{
547 547
 		// remove length limits from column names, if DB type is NOT MySQL
548 548
 		if ($this->sType != 'mysql')
549 549
 		{
550
-			$aColumnNames = preg_replace('/ *\(\d+\)$/','',$aColumnNames);
550
+			$aColumnNames = preg_replace('/ *\(\d+\)$/', '', $aColumnNames);
551 551
 		}
552 552
 		if (!$sIdxName || is_numeric($sIdxName))
553 553
 		{
554
-			$sIdxName = $this->_index_name($sTableName,$aColumnNames);
554
+			$sIdxName = $this->_index_name($sTableName, $aColumnNames);
555 555
 		}
556 556
 		if (!is_array($options)) $options = $options ? array($options) : array();
557 557
 		if ($bUnique) $options[] = 'UNIQUE';
558 558
 
559
-		$aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options);
559
+		$aSql = $this->dict->CreateIndexSQL($sIdxName, $sTableName, $aColumnNames, $options);
560 560
 
561
-		return $this->ExecuteSQLArray($aSql,2,'CreateIndexSQL(%1,%2,%3,%4) sql=%5',False,$sTableName,$aColumnNames,$options,$sIdxName,$aSql);
561
+		return $this->ExecuteSQLArray($aSql, 2, 'CreateIndexSQL(%1,%2,%3,%4) sql=%5', False, $sTableName, $aColumnNames, $options, $sIdxName, $aSql);
562 562
 	}
563 563
 
564 564
 	/**
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 	 * @param array|string $aColumnNames columns of the index or the name of the index
569 569
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
570 570
 	 */
571
-	function DropIndex($sTableName,$aColumnNames)
571
+	function DropIndex($sTableName, $aColumnNames)
572 572
 	{
573 573
 		if (is_array($aColumnNames))
574 574
 		{
@@ -578,13 +578,13 @@  discard block
 block discarded – undo
578 578
 			{
579 579
 				// if MetaIndexes is not availible for the DB, we try the name the index was created with
580 580
 				// this fails if one of the columns have been renamed
581
-				$sIdxName = $this->_index_name($sTableName,$aColumnNames);
581
+				$sIdxName = $this->_index_name($sTableName, $aColumnNames);
582 582
 			}
583 583
 			else
584 584
 			{
585
-				foreach($indexes as $idx => $idx_data)
585
+				foreach ($indexes as $idx => $idx_data)
586 586
 				{
587
-					if (strtolower(implode(':',$idx_data['columns'])) == implode(':',$aColumnNames))
587
+					if (strtolower(implode(':', $idx_data['columns'])) == implode(':', $aColumnNames))
588 588
 					{
589 589
 						$sIdxName = $idx;
590 590
 						break;
@@ -596,13 +596,13 @@  discard block
 block discarded – undo
596 596
 		{
597 597
 			$sIdxName = $aColumnNames;
598 598
 		}
599
-		if(!$sIdxName)
599
+		if (!$sIdxName)
600 600
 		{
601 601
 			return True;
602 602
 		}
603
-		$aSql = $this->dict->DropIndexSQL($sIdxName,$sTableName);
603
+		$aSql = $this->dict->DropIndexSQL($sIdxName, $sTableName);
604 604
 
605
-		return $this->ExecuteSQLArray($aSql,2,'DropIndexSQL(%1(%2),%3) sql=%4',False,$sIdxName,$aColumnNames,$sTableName,$aSql);
605
+		return $this->ExecuteSQLArray($aSql, 2, 'DropIndexSQL(%1(%2),%3) sql=%4', False, $sIdxName, $aColumnNames, $sTableName, $aSql);
606 606
 	}
607 607
 
608 608
 	/**
@@ -610,22 +610,22 @@  discard block
 block discarded – undo
610 610
 	 * @param string $sTableName table-name
611 611
 	 * @param string $sColumnName column-name, which default is set to nextval()
612 612
 	 */
613
-	function UpdateSequence($sTableName,$sColumnName)
613
+	function UpdateSequence($sTableName, $sColumnName)
614 614
 	{
615
-		switch($this->sType)
615
+		switch ($this->sType)
616 616
 		{
617 617
 			case 'pgsql':
618 618
 				// identify the sequence name, ADOdb uses a different name or it might be renamed
619 619
 				$columns = $this->dict->MetaColumns($sTableName);
620 620
 				$seq_name = 'seq_'.$sTableName;
621 621
 				$matches = null;
622
-				if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$columns[strtoupper($sColumnName)]->default_value,$matches))
622
+				if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $columns[strtoupper($sColumnName)]->default_value, $matches))
623 623
 				{
624 624
 					$seq_name = $matches[1];
625 625
 				}
626 626
 				$sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName";
627
-				if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
628
-				return $this->query($sql,__LINE__,__FILE__);
627
+				if ($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
628
+				return $this->query($sql, __LINE__, __FILE__);
629 629
 		}
630 630
 		return True;
631 631
 	}
@@ -642,9 +642,9 @@  discard block
 block discarded – undo
642 642
 	 * @param array $aTableDef eGW table-defintion
643 643
 	 * @param array|boolean $aDefaults array with default for the colums during copying, values are either (old) column-names or quoted string-literals
644 644
 	 */
645
-	function RefreshTable($sTableName, $aTableDef, $aDefaults=False)
645
+	function RefreshTable($sTableName, $aTableDef, $aDefaults = False)
646 646
 	{
647
-		if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; }
647
+		if ($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef, False).")\n"; }
648 648
 
649 649
 		$old_table_def = $this->GetTableDefinition($sTableName);
650 650
 
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 
654 654
 		$select = array();
655 655
 		$blob_column_included = $auto_column_included = False;
656
-		foreach($aTableDef['fd'] as $name => $data)
656
+		foreach ($aTableDef['fd'] as $name => $data)
657 657
 		{
658 658
 			// new auto column with no default or explicit NULL as default (can be an existing column too!)
659 659
 			if ($data['type'] == 'auto' &&
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 				$aDefaults && strtoupper($aDefaults[$name]) == 'NULL'))
662 662
 			{
663 663
 				$sequence_name = $sTableName.'_'.$name.'_seq';
664
-				switch($GLOBALS['egw_setup']->db->Type)
664
+				switch ($GLOBALS['egw_setup']->db->Type)
665 665
 				{
666 666
 					case 'mysql':
667 667
 						$value = 'NULL'; break;
@@ -682,25 +682,25 @@  discard block
 block discarded – undo
682 682
 				if ($this->sType == 'pgsql')			// some postgres specific code
683 683
 				{
684 684
 					// this is eg. necessary to change a varchar into an int column under postgres
685
-					if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) &&
686
-						in_array($data['type'],array('int','decimal')))
685
+					if (in_array($old_table_def['fd'][$name]['type'], array('char', 'varchar', 'text', 'blob')) &&
686
+						in_array($data['type'], array('int', 'decimal')))
687 687
 					{
688 688
 						$value = "to_number($name,'S9999999999999D99')";
689 689
 					}
690 690
 					// blobs cant be casted to text
691
-					elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
691
+					elseif ($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
692 692
 					{
693 693
 						$value = "ENCODE($value,'escape')";
694 694
 					}
695 695
 					// varchar or ascii column shortened, use substring to avoid error if current content is to long
696
-					elseif(in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) &&
696
+					elseif (in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) &&
697 697
 						in_array($data['type'], array('varchar', 'ascii')) &&
698 698
 						$old_table_def['fd'][$name]['precision'] > $data['precision'])
699 699
 					{
700 700
 						$value = "SUBSTRING($value FROM 1 FOR ".(int)$data['precision'].')';
701 701
 					}
702 702
 					// cast everything which is a different type
703
-					elseif($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type'])))
703
+					elseif ($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type'])))
704 704
 					{
705 705
 						$value = "CAST($value AS $type_translated)";
706 706
 					}
@@ -713,42 +713,42 @@  discard block
 block discarded – undo
713 713
 					$value = 'NULL';
714 714
 				}
715 715
 				// some stuff is NOT to be quoted
716
-				elseif (in_array(strtoupper($data['default']),array('CURRENT_TIMESTAMP','CURRENT_DATE','NULL','NOW()')))
716
+				elseif (in_array(strtoupper($data['default']), array('CURRENT_TIMESTAMP', 'CURRENT_DATE', 'NULL', 'NOW()')))
717 717
 				{
718 718
 					$value = $data['default'];
719 719
 				}
720 720
 				else
721 721
 				{
722
-					$value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '',$data['type']);
722
+					$value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '', $data['type']);
723 723
 				}
724 724
 				if ($this->sType == 'pgsql')
725 725
 				{
726 726
 					// fix for postgres error "no '<' operator for type 'unknown'"
727
-					if(($type_translated = $this->TranslateType($data['type'])))
727
+					if (($type_translated = $this->TranslateType($data['type'])))
728 728
 					{
729 729
 						$value = "CAST($value AS $type_translated)";
730 730
 					}
731 731
 				}
732 732
 			}
733
-			$blob_column_included = $blob_column_included || in_array($data['type'],array('blob','text','longtext'));
733
+			$blob_column_included = $blob_column_included || in_array($data['type'], array('blob', 'text', 'longtext'));
734 734
 			$auto_column_included = $auto_column_included || $data['type'] == 'auto';
735 735
 			$select[] = $value;
736 736
 		}
737 737
 
738 738
 		$extra = '';
739 739
 		$distinct = 'DISTINCT';
740
-		switch($this->sType)
740
+		switch ($this->sType)
741 741
 		{
742 742
 			case 'mssql':
743 743
 				if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n";
744
-				if ($blob_column_included) $distinct = '';	// no distinct on blob-columns
744
+				if ($blob_column_included) $distinct = ''; // no distinct on blob-columns
745 745
 				break;
746 746
 		}
747 747
 		// because of all the trouble with sequences and indexes in the global namespace,
748 748
 		// we use an additional temp. table for postgres and not rename the existing one, but drop it.
749 749
 		if ($this->sType == 'pgsql')
750 750
 		{
751
-			$Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName",__LINE__,__FILE__) &&
751
+			$Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName", __LINE__, __FILE__) &&
752 752
 				$this->DropTable($sTableName);
753 753
 		}
754 754
 		else
@@ -758,12 +758,12 @@  discard block
 block discarded – undo
758 758
 			{
759 759
 				$this->DropTable($tmp_name);
760 760
 			}
761
-			$Ok = $this->RenameTable($sTableName,$tmp_name);
761
+			$Ok = $this->RenameTable($sTableName, $tmp_name);
762 762
 		}
763
-		$Ok = $Ok && $this->CreateTable($sTableName,$aTableDef) &&
764
-			$this->m_odb->query($sql_copy_data="$extra INSERT INTO $sTableName (".
765
-				implode(',',array_keys($aTableDef['fd'])).
766
-				") SELEcT $distinct ".implode(',',$select)." FROM $tmp_name",__LINE__,__FILE__) &&
763
+		$Ok = $Ok && $this->CreateTable($sTableName, $aTableDef) &&
764
+			$this->m_odb->query($sql_copy_data = "$extra INSERT INTO $sTableName (".
765
+				implode(',', array_keys($aTableDef['fd'])).
766
+				") SELEcT $distinct ".implode(',', $select)." FROM $tmp_name", __LINE__, __FILE__) &&
767 767
 			$this->DropTable($tmp_name);
768 768
 		//error_log($sql_copy_data);
769 769
 
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 		// do we need to update the new sequences value ?
776 776
 		if (count($aTableDef['pk']) == 1 && $aTableDef['fd'][$aTableDef['pk'][0]]['type'] == 'auto')
777 777
 		{
778
-			$this->UpdateSequence($sTableName,$aTableDef['pk'][0]);
778
+			$this->UpdateSequence($sTableName, $aTableDef['pk'][0]);
779 779
 		}
780 780
 		$this->m_odb->transaction_commit();
781 781
 
@@ -798,9 +798,9 @@  discard block
 block discarded – undo
798 798
 	 * @param boolean $bOutputHTML =false should we give diagnostics, default False
799 799
 	 * @return boolean True on success, False if an (fatal) error occured
800 800
 	 */
801
-	function ExecuteScripts($aTables, $bOutputHTML=False)
801
+	function ExecuteScripts($aTables, $bOutputHTML = False)
802 802
 	{
803
-		if(!is_array($aTables) || !IsSet($this->m_odb))
803
+		if (!is_array($aTables) || !IsSet($this->m_odb))
804 804
 		{
805 805
 			return False;
806 806
 		}
@@ -808,20 +808,20 @@  discard block
 block discarded – undo
808 808
 		if ($this->debug) $bOutputHTML = True;
809 809
 		if ($bOutputHTML && !$this->debug) $this->debug = 2;
810 810
 
811
-		foreach($aTables as $sTableName => $aTableDef)
811
+		foreach ($aTables as $sTableName => $aTableDef)
812 812
 		{
813
-			if($this->CreateTable($sTableName, $aTableDef))
813
+			if ($this->CreateTable($sTableName, $aTableDef))
814 814
 			{
815
-				if($bOutputHTML)
815
+				if ($bOutputHTML)
816 816
 				{
817
-					echo '<br>Create Table <b>' . $sTableName . '</b>';
817
+					echo '<br>Create Table <b>'.$sTableName.'</b>';
818 818
 				}
819 819
 			}
820 820
 			else
821 821
 			{
822
-				if($bOutputHTML)
822
+				if ($bOutputHTML)
823 823
 				{
824
-					echo '<br>Create Table Failed For <b>' . $sTableName . '</b>';
824
+					echo '<br>Create Table Failed For <b>'.$sTableName.'</b>';
825 825
 				}
826 826
 
827 827
 				return False;
@@ -838,13 +838,13 @@  discard block
 block discarded – undo
838 838
 	* @deprecated use result-set returned by query/select
839 839
 	* @return string the field value
840 840
 	*/
841
-	function f($value,$strip_slashes=False)
841
+	function f($value, $strip_slashes = False)
842 842
 	{
843 843
 		if (!($this->m_odb instanceof Deprecated))
844 844
 		{
845 845
 	    	throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!');
846 846
 		}
847
-		return $this->m_odb->f($value,$strip_slashes);
847
+		return $this->m_odb->f($value, $strip_slashes);
848 848
 	}
849 849
 
850 850
 	/**
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 	* @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
888 888
 	* @return ADORecordSet or false, if the query fails
889 889
 	*/
890
-	function query($sQuery, $line='', $file='')
890
+	function query($sQuery, $line = '', $file = '')
891 891
 	{
892 892
 		return $this->m_odb->query($sQuery, $line, $file);
893 893
 	}
@@ -904,9 +904,9 @@  discard block
 block discarded – undo
904 904
 	* @param string $app=false string with name of app, this need to be set in setup anyway!!!
905 905
 	* @return ADORecordSet or false, if the query fails
906 906
 	*/
907
-	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false)
907
+	function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false)
908 908
 	{
909
-		return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement);
909
+		return $this->m_odb->insert($table, $data, $where, $line, $file, $app, $use_prepared_statement);
910 910
 	}
911 911
 
912 912
 	/**
@@ -917,14 +917,14 @@  discard block
 block discarded – undo
917 917
 	 * @param string $debug variable number of arguments for the debug_message functions in case of an error
918 918
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
919 919
 	 */
920
-	function ExecuteSqlArray($aSql,$debug_level)
920
+	function ExecuteSqlArray($aSql, $debug_level)
921 921
 	{
922 922
 		if ($this->m_odb->query_log)	// we use Db::query to log the queries
923 923
 		{
924 924
 			$retval = 2;
925
-			foreach($aSql as $sql)
925
+			foreach ($aSql as $sql)
926 926
 			{
927
-				if (!$this->m_odb->query($sql,__LINE__,__FILE__))
927
+				if (!$this->m_odb->query($sql, __LINE__, __FILE__))
928 928
 				{
929 929
 					$retval = 1;
930 930
 				}
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 			$debug_params = func_get_args();
940 940
 			array_shift($debug_params);
941 941
 			array_shift($debug_params);
942
-			call_user_func_array(array($this,'debug_message'),$debug_params);
942
+			call_user_func_array(array($this, 'debug_message'), $debug_params);
943 943
 			if ($retval < 2 && !$this->dict->debug)
944 944
 			{
945 945
 				echo '<p><b>'.$this->adodb->ErrorMsg()."</b></p>\n";
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
 	 * @param $aColumnNames array of column-names or string with a single column-name
961 961
 	 * @return string the index-name
962 962
 	 */
963
-	function _index_name($sTableName,$aColumnNames)
963
+	function _index_name($sTableName, $aColumnNames)
964 964
 	{
965 965
 		// this code creates extrem short index-names, eg. for MaxDB
966 966
 //			if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32)
@@ -985,28 +985,28 @@  discard block
 block discarded – undo
985 985
 //				return $name;
986 986
 //			}
987 987
 		// This code creates longer index-names incl. the table-names and the used columns
988
-		$table = str_replace(array('phpgw_','egw_'),'',$sTableName);
988
+		$table = str_replace(array('phpgw_', 'egw_'), '', $sTableName);
989 989
 		// if the table-name or a part of it is repeated in the column-name, remove it there
990 990
 		$remove[] = $table.'_';
991 991
 		// also remove 3 or 4 letter shortcuts of the table- or app-name
992
-		$remove[] = substr($table,0,3).'_';
993
-		$remove[] = substr($table,0,4).'_';
992
+		$remove[] = substr($table, 0, 3).'_';
993
+		$remove[] = substr($table, 0, 4).'_';
994 994
 		// if the table-name consists of '_' limtied parts, remove occurences of these parts too
995
-		foreach (explode('_',$table) as $part)
995
+		foreach (explode('_', $table) as $part)
996 996
 		{
997 997
 			$remove[] = $part.'_';
998 998
 		}
999
-		$cols = str_replace($remove,'',$aColumnNames);
999
+		$cols = str_replace($remove, '', $aColumnNames);
1000 1000
 
1001
-		$name = $sTableName.'_'.(is_array($cols) ? implode('_',$cols) : $cols);
1001
+		$name = $sTableName.'_'.(is_array($cols) ? implode('_', $cols) : $cols);
1002 1002
 		// remove length limits from column names
1003
-		$name = preg_replace('/ *\(\d+\)/','',$name);
1003
+		$name = preg_replace('/ *\(\d+\)/', '', $name);
1004 1004
 
1005 1005
 		// this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle
1006 1006
 		if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 ||
1007 1007
 			strlen($name) >= 64)	// even mysql has a limit here ;-)
1008 1008
 		{
1009
-			$name = "i".substr(md5($name),0,29);
1009
+			$name = "i".substr(md5($name), 0, 29);
1010 1010
 		}
1011 1011
 		return $name;
1012 1012
 	}
@@ -1047,19 +1047,19 @@  discard block
 block discarded – undo
1047 1047
 	 * @param $param mixed a variable number of parameters, to be inserted in $msg
1048 1048
 	 *	arrays get serialized with print_r() !
1049 1049
 	 */
1050
-	function debug_message($msg,$backtrace=True)
1050
+	function debug_message($msg, $backtrace = True)
1051 1051
 	{
1052
-		for($i = 2; $i < func_num_args(); ++$i)
1052
+		for ($i = 2; $i < func_num_args(); ++$i)
1053 1053
 		{
1054 1054
 			$param = func_get_arg($i);
1055 1055
 
1056 1056
 			if (is_null($param))
1057 1057
 			{
1058
-				$param='NULL';
1058
+				$param = 'NULL';
1059 1059
 			}
1060 1060
 			else
1061 1061
 			{
1062
-				switch(gettype($param))
1062
+				switch (gettype($param))
1063 1063
 				{
1064 1064
 					case 'string':
1065 1065
 						$param = "'$param'";
@@ -1067,15 +1067,15 @@  discard block
 block discarded – undo
1067 1067
 					case 'array':
1068 1068
 					case 'object':
1069 1069
 						list(,$content) = @each($param);
1070
-						$do_pre = is_array($param) ? count($param) > 6 || is_array($content)&&count($content) : True;
1071
-						$param = ($do_pre ? '<pre>' : '').print_r($param,True).($do_pre ? '</pre>' : '');
1070
+						$do_pre = is_array($param) ? count($param) > 6 || is_array($content) && count($content) : True;
1071
+						$param = ($do_pre ? '<pre>' : '').print_r($param, True).($do_pre ? '</pre>' : '');
1072 1072
 						break;
1073 1073
 					case 'boolean':
1074 1074
 						$param = $param ? 'True' : 'False';
1075 1075
 						break;
1076 1076
 				}
1077 1077
 			}
1078
-			$msg = str_replace('%'.($i-1),$param,$msg);
1078
+			$msg = str_replace('%'.($i - 1), $param, $msg);
1079 1079
 		}
1080 1080
 		echo '<p>'.$msg."<br>\n".($backtrace ? 'Backtrace: '.function_backtrace(1)."</p>\n" : '');
1081 1081
 	}
@@ -1090,15 +1090,15 @@  discard block
 block discarded – undo
1090 1090
 	function _egw2adodb_columndef($aTableDef)
1091 1091
 	{
1092 1092
 		$ado_defs = array();
1093
-		foreach($aTableDef['fd'] as $col => $col_data)
1093
+		foreach ($aTableDef['fd'] as $col => $col_data)
1094 1094
 		{
1095 1095
 			$ado_col = False;
1096 1096
 
1097
-			switch($col_data['type'])
1097
+			switch ($col_data['type'])
1098 1098
 			{
1099 1099
 				case 'auto':
1100 1100
 					$ado_col = 'I AUTOINCREMENT NOTNULL';
1101
-					unset($col_data['nullable']);	// else we set it twice
1101
+					unset($col_data['nullable']); // else we set it twice
1102 1102
 					break;
1103 1103
 				case 'blob':
1104 1104
 					$ado_col = 'B';
@@ -1111,11 +1111,11 @@  discard block
 block discarded – undo
1111 1111
 				case 'ascii':
1112 1112
 				case 'varchar':
1113 1113
 					$ado_col = "C";
1114
-					if(0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length)
1114
+					if (0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length)
1115 1115
 					{
1116 1116
 						$ado_col .= "($col_data[precision])";
1117 1117
 					}
1118
-					if($col_data['precision'] > $this->max_varchar_length)
1118
+					if ($col_data['precision'] > $this->max_varchar_length)
1119 1119
 					{
1120 1120
 						$ado_col = 'X';
1121 1121
 					}
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
 				case 'date':
1128 1128
 					$ado_col = 'D';
1129 1129
 					// allow to use now() beside current_date, as Postgres backups contain it and it's easier to remember anyway
1130
-					if (in_array($col_data['default'],array('current_date','now()')))
1130
+					if (in_array($col_data['default'], array('current_date', 'now()')))
1131 1131
 					{
1132 1132
 						$ado_col .= ' DEFDATE';
1133 1133
 						unset($col_data['default']);
@@ -1143,7 +1143,7 @@  discard block
 block discarded – undo
1143 1143
 					break;
1144 1144
 				case 'int':
1145 1145
 					$ado_col = 'I';
1146
-					switch($col_data['precision'])
1146
+					switch ($col_data['precision'])
1147 1147
 					{
1148 1148
 						case 1:
1149 1149
 						case 2:
@@ -1162,7 +1162,7 @@  discard block
 block discarded – undo
1162 1162
 				case 'timestamp':
1163 1163
 					$ado_col = 'T';
1164 1164
 					// allow to use now() beside current_timestamp, as Postgres backups contain it and it's easier to remember anyway
1165
-					if (in_array($col_data['default'],array('current_timestamp','now()')))
1165
+					if (in_array($col_data['default'], array('current_timestamp', 'now()')))
1166 1166
 					{
1167 1167
 						$ado_col .= ' DEFTIMESTAMP';
1168 1168
 						unset($col_data['default']);
@@ -1180,17 +1180,17 @@  discard block
 block discarded – undo
1180 1180
 			}
1181 1181
 			if (isset($col_data['default']))
1182 1182
 			{
1183
-				$ado_col .= (in_array($col_data['type'],array('bool','int','decimal','float','double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : '').
1184
-					' DEFAULT '.$this->m_odb->quote($col_data['default'],$col_data['type']);
1183
+				$ado_col .= (in_array($col_data['type'], array('bool', 'int', 'decimal', 'float', 'double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : '').
1184
+					' DEFAULT '.$this->m_odb->quote($col_data['default'], $col_data['type']);
1185 1185
 			}
1186
-			if (in_array($col,$aTableDef['pk']))
1186
+			if (in_array($col, $aTableDef['pk']))
1187 1187
 			{
1188 1188
 				$ado_col .= ' PRIMARY';
1189 1189
 			}
1190
-			$ado_defs[] = $col . ' ' . $ado_col;
1190
+			$ado_defs[] = $col.' '.$ado_col;
1191 1191
 		}
1192 1192
 		//print_r($aTableDef); echo implode(",\n",$ado_defs)."\n";
1193
-		return implode(",\n",$ado_defs);
1193
+		return implode(",\n", $ado_defs);
1194 1194
 	}
1195 1195
 
1196 1196
 	/**
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
 			'pk' => array(),
1207 1207
 		));
1208 1208
 		$matches = null;
1209
-		return preg_match('/test ([A-Z0-9]+)/i',$ado_col,$matches) ? $this->dict->ActualType($matches[1]) : false;
1209
+		return preg_match('/test ([A-Z0-9]+)/i', $ado_col, $matches) ? $this->dict->ActualType($matches[1]) : false;
1210 1210
 	}
1211 1211
 
1212 1212
 	/**
@@ -1222,7 +1222,7 @@  discard block
 block discarded – undo
1222 1222
 		// MetaType returns all varchar >= blobSize as blob, it's by default 100, which is wrong
1223 1223
 		$this->dict->blobSize = $this->max_varchar_length;
1224 1224
 
1225
-		if (!method_exists($this->dict,'MetaColumns') ||
1225
+		if (!method_exists($this->dict, 'MetaColumns') ||
1226 1226
 			!($columns = $this->dict->MetaColumns($sTableName)))
1227 1227
 		{
1228 1228
 			return False;
@@ -1235,11 +1235,11 @@  discard block
 block discarded – undo
1235 1235
 			'uc' => array(),
1236 1236
 		);
1237 1237
 		//echo "$sTableName: <pre>".print_r($columns,true)."</pre>";
1238
-		foreach($columns as $column)
1238
+		foreach ($columns as $column)
1239 1239
 		{
1240 1240
 			$name = $this->capabilities['name_case'] == 'upper' ? strtolower($column->name) : $column->name;
1241 1241
 
1242
-			$type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1242
+			$type = method_exists($this->dict, 'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1243 1243
 
1244 1244
 			// fix longtext not correctly handled by ADOdb
1245 1245
 			if ($type == 'X' && $column->type == 'longtext') $type = 'XL';
@@ -1261,11 +1261,11 @@  discard block
 block discarded – undo
1261 1261
 			);
1262 1262
 			$definition['fd'][$name]['type'] = $ado_type2egw[$type];
1263 1263
 
1264
-			switch($type)
1264
+			switch ($type)
1265 1265
 			{
1266 1266
 				case 'D': case 'T':
1267 1267
 					// detecting the automatic timestamps again
1268
-					if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i',$column->default_value))
1268
+					if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i', $column->default_value))
1269 1269
 					{
1270 1270
 						$column->default_value = $type == 'D' ? 'current_date' : 'current_timestamp';
1271 1271
 					}
@@ -1292,10 +1292,10 @@  discard block
 block discarded – undo
1292 1292
 					$column->auto_increment = true;
1293 1293
 					// fall-through
1294 1294
 				case 'I': case 'I1': case 'I2': case 'I4': case 'I8':
1295
-					switch($type)
1295
+					switch ($type)
1296 1296
 					{
1297 1297
 						case 'I1': case 'I2': case 'I4': case 'I8':
1298
-							$definition['fd'][$name]['precision'] = (int) $type[1];
1298
+							$definition['fd'][$name]['precision'] = (int)$type[1];
1299 1299
 							break;
1300 1300
 						default:
1301 1301
 							if ($column->max_length > 11)
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
 						$definition['fd'][$name]['type'] = 'int';
1332 1332
 						// detect postgres type-spec and remove it
1333 1333
 						$matches = null;
1334
-						if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/',$column->default_value,$matches))
1334
+						if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/', $column->default_value, $matches))
1335 1335
 						{
1336 1336
 							$definition['fd'][$name]['default'] = $matches[1];
1337 1337
 							$column->has_default = False;
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 			}
1350 1350
 			if ($column->has_default)
1351 1351
 			{
1352
-				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))	// postgres
1352
+				if (preg_match("/^'(.*)'::.*$/", $column->default_value, $matches))	// postgres
1353 1353
 				{
1354 1354
 					$column->default_value = $matches[1];
1355 1355
 				}
@@ -1359,18 +1359,18 @@  discard block
 block discarded – undo
1359 1359
 			{
1360 1360
 				$definition['fd'][$name]['nullable'] = False;
1361 1361
 			}
1362
-			if ($column->primary_key && !in_array($name,$definition['pk']))
1362
+			if ($column->primary_key && !in_array($name, $definition['pk']))
1363 1363
 			{
1364 1364
 				$definition['pk'][] = $name;
1365 1365
 			}
1366 1366
 		}
1367
-		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1367
+		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2", False, $sTableName, $columns);
1368 1368
 
1369 1369
 		// not all DB's (odbc) return the primary keys via MetaColumns
1370
-		if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') &&
1370
+		if (!count($definition['pk']) && method_exists($this->dict, 'MetaPrimaryKeys') &&
1371 1371
 			is_array($primary = $this->dict->MetaPrimaryKeys($sTableName)) && count($primary))
1372 1372
 		{
1373
-			if($this->capabilities['name_case'] == 'upper')
1373
+			if ($this->capabilities['name_case'] == 'upper')
1374 1374
 			{
1375 1375
 				array_walk($primary, function(&$s)
1376 1376
 				{
@@ -1379,10 +1379,10 @@  discard block
 block discarded – undo
1379 1379
 			}
1380 1380
 			$definition['pk'] = $primary;
1381 1381
 		}
1382
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1382
+		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2", False, $sTableName, $primary);
1383 1383
 
1384 1384
 		$this->GetIndexes($sTableName, $definition);
1385
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1385
+		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2", False, $sTableName, $definition);
1386 1386
 
1387 1387
 		return $definition;
1388 1388
 	}
@@ -1394,35 +1394,35 @@  discard block
 block discarded – undo
1394 1394
 	 * @param array& $definition=array()
1395 1395
 	 * @return array of arrays with keys 'ix' and 'uc'
1396 1396
 	 */
1397
-	public function GetIndexes($sTableName, array &$definition=array())
1397
+	public function GetIndexes($sTableName, array &$definition = array())
1398 1398
 	{
1399
-		if (method_exists($this->dict,'MetaIndexes') &&
1399
+		if (method_exists($this->dict, 'MetaIndexes') &&
1400 1400
 			is_array($indexes = $this->dict->MetaIndexes($sTableName)) && count($indexes))
1401 1401
 		{
1402
-			foreach($indexes as $index)
1402
+			foreach ($indexes as $index)
1403 1403
 			{
1404 1404
 				// append (optional) length of index in brackets to column
1405
-				foreach((array)$index['length'] as $col => $length)
1405
+				foreach ((array)$index['length'] as $col => $length)
1406 1406
 				{
1407 1407
 					if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')';
1408 1408
 				}
1409
-				if($this->capabilities['name_case'] == 'upper')
1409
+				if ($this->capabilities['name_case'] == 'upper')
1410 1410
 				{
1411 1411
 					array_walk($index['columns'], function(&$s)
1412 1412
 					{
1413 1413
 						$s = strtolower($s);
1414 1414
 					});
1415 1415
 				}
1416
-				if (count($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) ||
1417
-					$index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk'])))
1416
+				if (count($definition['pk']) && (implode(':', $definition['pk']) == implode(':', $index['columns']) ||
1417
+					$index['unique'] && count(array_intersect($definition['pk'], $index['columns'])) == count($definition['pk'])))
1418 1418
 				{
1419
-					continue;	// is already the primary key => ignore it
1419
+					continue; // is already the primary key => ignore it
1420 1420
 				}
1421 1421
 				$kind = $index['unique'] ? 'uc' : 'ix';
1422 1422
 
1423 1423
 				$definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0];
1424 1424
 			}
1425
-			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1425
+			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2", False, $sTableName, $indexes);
1426 1426
 		}
1427 1427
 		return $definition;
1428 1428
 	}
@@ -1434,7 +1434,7 @@  discard block
 block discarded – undo
1434 1434
 	 */
1435 1435
 	function CheckCreateIndexes()
1436 1436
 	{
1437
-		foreach($this->adodb->MetaTables('TABLES') as $table)
1437
+		foreach ($this->adodb->MetaTables('TABLES') as $table)
1438 1438
 		{
1439 1439
 			if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue;
1440 1440
 
@@ -1442,9 +1442,9 @@  discard block
 block discarded – undo
1442 1442
 			$this->GetIndexes($table, $definition);
1443 1443
 
1444 1444
 			// iterate though indexes we should have according to tables_current
1445
-			foreach(array('uc', 'ix') as $type)
1445
+			foreach (array('uc', 'ix') as $type)
1446 1446
 			{
1447
-				foreach($table_def[$type] as $columns)
1447
+				foreach ($table_def[$type] as $columns)
1448 1448
 				{
1449 1449
 					// sometimes primary key is listed as (unique) index too --> ignore it
1450 1450
 					if ($this->_in_index($columns, array($table_def['pk']), true)) continue;
@@ -1475,27 +1475,26 @@  discard block
 block discarded – undo
1475 1475
 	 * old translator function, use GetTableDefition() instead
1476 1476
 	 * @depricated
1477 1477
 	 */
1478
-	function _GetColumns($oProc,$sTableName,&$sColumns)
1478
+	function _GetColumns($oProc, $sTableName, &$sColumns)
1479 1479
 	{
1480
-		unset($oProc);	// unused, but required by function signature
1480
+		unset($oProc); // unused, but required by function signature
1481 1481
 		$this->sCol = $this->pk = $this->fk = $this->ix = $this->uc = array();
1482 1482
 
1483 1483
 		$tabledef = $this->GetTableDefinition($sTableName);
1484 1484
 
1485
-		$sColumns = implode(',',array_keys($tabledef['fd']));
1485
+		$sColumns = implode(',', array_keys($tabledef['fd']));
1486 1486
 
1487
-		foreach($tabledef['fd'] as $column => $data)
1487
+		foreach ($tabledef['fd'] as $column => $data)
1488 1488
 		{
1489 1489
 			$col_def = "'type' => '$data[type]'";
1490 1490
 			unset($data['type']);
1491
-			foreach($data as $key => $val)
1491
+			foreach ($data as $key => $val)
1492 1492
 			{
1493
-				$col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') :
1494
-					(is_int($val) ? $val : "'$val'"));
1493
+				$col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : (is_int($val) ? $val : "'$val'"));
1495 1494
 			}
1496 1495
 			$this->sCol[] = "\t\t\t\t'$column' => array($col_def),\n";
1497 1496
 		}
1498
-		foreach(array('pk','fk','ix','uc') as $kind)
1497
+		foreach (array('pk', 'fk', 'ix', 'uc') as $kind)
1499 1498
 		{
1500 1499
 			$this->$kind = $tabledef[$kind];
1501 1500
 		}
Please login to merge, or discard this patch.
Braces   +165 added lines, -43 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	function __construct($dbms=False, Api\Db $db=null)
103 103
 	{
104 104
 	    if(is_object($db))
105
-		{
105
+	    {
106 106
 			$this->m_odb = $db;
107 107
 	    }
108 108
 	    else
@@ -121,7 +121,10 @@  discard block
 block discarded – undo
121 121
 		$this->dict = NewDataDictionary($this->adodb);
122 122
 
123 123
 		// enable the debuging in ADOdb's datadictionary if the debug-level is greater then 1
124
-		if ($this->debug > 1) $this->dict->debug = True;
124
+		if ($this->debug > 1)
125
+		{
126
+			$this->dict->debug = True;
127
+		}
125 128
 
126 129
 		// to allow some of the former translator-functions to be called, we assign ourself as the translator
127 130
 		$this->m_oTranslator = &$this;
@@ -164,7 +167,10 @@  discard block
 block discarded – undo
164 167
 		{
165 168
 			unset($columns['options']);
166 169
 			$columns = implode('-',$columns);
167
-			if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns);
170
+			if ($ignore_length_limit)
171
+			{
172
+				$columns = preg_replace('/\(\d+\)/', '', $columns);
173
+			}
168 174
 		}
169 175
 		foreach($indexs as $index)
170 176
 		{
@@ -173,8 +179,14 @@  discard block
 block discarded – undo
173 179
 				unset($index['options']);
174 180
 				$index = implode('-',$index);
175 181
 			}
176
-			if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index);
177
-			if ($columns == $index) return true;
182
+			if ($ignore_length_limit)
183
+			{
184
+				$index = preg_replace('/\(\d+\)/', '', $index);
185
+			}
186
+			if ($columns == $index)
187
+			{
188
+				return true;
189
+			}
178 190
 		}
179 191
 		return false;
180 192
 	}
@@ -236,12 +248,20 @@  discard block
 block discarded – undo
236 248
 			$options = False;
237 249
 			if (is_array($mFields))
238 250
 			{
239
-				if (isset($mFields['options']))		// array sets additional options
251
+				if (isset($mFields['options']))
252
+				{
253
+					// array sets additional options
240 254
 				{
241 255
 					if (isset($mFields['options'][$this->sType]))
242 256
 					{
243
-						$options = $mFields['options'][$this->sType];	// db-specific options, eg. index-type
244
-						if (!$options) continue;	// no index for our db-type
257
+						$options = $mFields['options'][$this->sType];
258
+				}
259
+				// db-specific options, eg. index-type
260
+						if (!$options)
261
+						{
262
+							continue;
263
+						}
264
+						// no index for our db-type
245 265
 					}
246 266
 					unset($mFields['options']);
247 267
 				}
@@ -252,15 +272,22 @@  discard block
 block discarded – undo
252 272
 				// most DB's cant do them and give errors
253 273
 				if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext')))
254 274
 				{
255
-					if (is_array($mFields))	// index over multiple columns including a text column
275
+					if (is_array($mFields))
256 276
 					{
257
-						$mFields[$k] .= '(32)';	// 32=limit of egw_addressbook_extra.extra_value to fix old backups
277
+						// index over multiple columns including a text column
278
+					{
279
+						$mFields[$k] .= '(32)';
280
+					}
281
+					// 32=limit of egw_addressbook_extra.extra_value to fix old backups
258 282
 					}
259
-					elseif (!$options)	// index over a single text column and no options given
283
+					elseif (!$options)
284
+					{
285
+						// index over a single text column and no options given
260 286
 					{
261 287
 						if ($this->sType == 'mysql')
262 288
 						{
263 289
 							$options = 'FULLTEXT';
290
+					}
264 291
 						}
265 292
 						else
266 293
 						{
@@ -301,8 +328,14 @@  discard block
 block discarded – undo
301 328
 			return False;
302 329
 		}
303 330
 		// set our debug-mode or $bOutputHTML is the other one is set
304
-		if ($this->debug) $bOutputHTML = True;
305
-		if ($bOutputHTML && !$this->debug) $this->debug = 2;
331
+		if ($this->debug)
332
+		{
333
+			$bOutputHTML = True;
334
+		}
335
+		if ($bOutputHTML && !$this->debug)
336
+		{
337
+			$this->debug = 2;
338
+		}
306 339
 
307 340
 		foreach(array_keys($aTables) as $sTableName)
308 341
 		{
@@ -329,7 +362,10 @@  discard block
 block discarded – undo
329 362
 	 */
330 363
 	function DropTable($sTableName)
331 364
 	{
332
-		if ($this->sType == 'pgsql') $this->_PostgresTestDropOldSequence($sTableName);
365
+		if ($this->sType == 'pgsql')
366
+		{
367
+			$this->_PostgresTestDropOldSequence($sTableName);
368
+		}
333 369
 
334 370
 		$aSql = $this->dict->DropTableSql($sTableName);
335 371
 
@@ -348,7 +384,10 @@  discard block
 block discarded – undo
348 384
 	{
349 385
 		unset($aTableDef);	// not used, but required by function signature
350 386
 
351
-		if (!($table_def = $this->GetTableDefinition($sTableName))) return 0;
387
+		if (!($table_def = $this->GetTableDefinition($sTableName)))
388
+		{
389
+			return 0;
390
+		}
352 391
 		unset($table_def['fd'][$sColumnName]);
353 392
 
354 393
 		$aSql = $this->dict->DropColumnSql($sTableName,$sColumnName,$ado_table=$this->_egw2adodb_columndef($table_def));
@@ -369,7 +408,10 @@  discard block
 block discarded – undo
369 408
 		// we create a new table, copy the content and drop the old one
370 409
 		if ($this->sType == 'pgsql')
371 410
 		{
372
-			if (!($table_def = $this->GetTableDefinition($sOldTableName))) return 0;
411
+			if (!($table_def = $this->GetTableDefinition($sOldTableName)))
412
+			{
413
+				return 0;
414
+			}
373 415
 
374 416
 			// only use old PostgreSQL stuff, if we have an old sequence, otherwise rely on it being new enough
375 417
 			if ($this->_PostgresHasOldSequence($sOldTableName,True) &&
@@ -403,7 +445,10 @@  discard block
 block discarded – undo
403 445
 	 */
404 446
 	function _PostgresHasOldSequence($sTableName,$preserveValue=False)
405 447
 	{
406
-		if ($this->sType != 'pgsql') return false;
448
+		if ($this->sType != 'pgsql')
449
+		{
450
+			return false;
451
+		}
407 452
 
408 453
 		$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");
409 454
 		$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");
@@ -411,12 +456,18 @@  discard block
 block discarded – undo
411 456
 		$matches = null;
412 457
 		if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches))
413 458
 		{
414
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
459
+			if ($preserveValue)
460
+			{
461
+				$this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
462
+			}
415 463
 			return $matches[1];
416 464
 		}
417 465
 		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches))
418 466
 		{
419
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
467
+			if ($preserveValue)
468
+			{
469
+				$this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
470
+			}
420 471
 			return $matches[1];
421 472
 		}
422 473
 		return false;
@@ -450,7 +501,10 @@  discard block
 block discarded – undo
450 501
 	 */
451 502
 	function AlterColumn($sTableName, $sColumnName, $aColumnDef)
452 503
 	{
453
-		if (!($table_def = $this->GetTableDefinition($sTableName))) return 0;
504
+		if (!($table_def = $this->GetTableDefinition($sTableName)))
505
+		{
506
+			return 0;
507
+		}
454 508
 
455 509
 		// PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long
456 510
 		if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
@@ -553,8 +607,14 @@  discard block
 block discarded – undo
553 607
 		{
554 608
 			$sIdxName = $this->_index_name($sTableName,$aColumnNames);
555 609
 		}
556
-		if (!is_array($options)) $options = $options ? array($options) : array();
557
-		if ($bUnique) $options[] = 'UNIQUE';
610
+		if (!is_array($options))
611
+		{
612
+			$options = $options ? array($options) : array();
613
+		}
614
+		if ($bUnique)
615
+		{
616
+			$options[] = 'UNIQUE';
617
+		}
558 618
 
559 619
 		$aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options);
560 620
 
@@ -624,7 +684,9 @@  discard block
 block discarded – undo
624 684
 					$seq_name = $matches[1];
625 685
 				}
626 686
 				$sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName";
627
-				if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
687
+				if($this->debug)
688
+				{
689
+echo "<br>Updating sequence '$seq_name using: $sql"; }
628 690
 				return $this->query($sql,__LINE__,__FILE__);
629 691
 		}
630 692
 		return True;
@@ -644,7 +706,9 @@  discard block
 block discarded – undo
644 706
 	 */
645 707
 	function RefreshTable($sTableName, $aTableDef, $aDefaults=False)
646 708
 	{
647
-		if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; }
709
+		if($this->debug)
710
+		{
711
+echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; }
648 712
 
649 713
 		$old_table_def = $this->GetTableDefinition($sTableName);
650 714
 
@@ -671,21 +735,30 @@  discard block
 block discarded – undo
671 735
 						$value = "nextval('$sequence_name')"; break;
672 736
 				}
673 737
 			}
674
-			elseif ($aDefaults && isset($aDefaults[$name]))	// use given default
738
+			elseif ($aDefaults && isset($aDefaults[$name]))
739
+			{
740
+				// use given default
675 741
 			{
676 742
 				$value = $aDefaults[$name];
677 743
 			}
678
-			elseif (isset($old_table_def['fd'][$name]))	// existing column, use its value => column-name in query
744
+			}
745
+			elseif (isset($old_table_def['fd'][$name]))
746
+			{
747
+				// existing column, use its value => column-name in query
679 748
 			{
680 749
 				$value = $name;
750
+			}
681 751
 
682
-				if ($this->sType == 'pgsql')			// some postgres specific code
752
+				if ($this->sType == 'pgsql')
753
+				{
754
+					// some postgres specific code
683 755
 				{
684 756
 					// this is eg. necessary to change a varchar into an int column under postgres
685 757
 					if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) &&
686 758
 						in_array($data['type'],array('int','decimal')))
687 759
 					{
688 760
 						$value = "to_number($name,'S9999999999999D99')";
761
+				}
689 762
 					}
690 763
 					// blobs cant be casted to text
691 764
 					elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
@@ -740,8 +813,15 @@  discard block
 block discarded – undo
740 813
 		switch($this->sType)
741 814
 		{
742 815
 			case 'mssql':
743
-				if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n";
744
-				if ($blob_column_included) $distinct = '';	// no distinct on blob-columns
816
+				if ($auto_column_included)
817
+				{
818
+					$extra = "SET IDENTITY_INSERT $sTableName ON\n";
819
+				}
820
+				if ($blob_column_included)
821
+				{
822
+					$distinct = '';
823
+				}
824
+				// no distinct on blob-columns
745 825
 				break;
746 826
 		}
747 827
 		// because of all the trouble with sequences and indexes in the global namespace,
@@ -805,8 +885,14 @@  discard block
 block discarded – undo
805 885
 			return False;
806 886
 		}
807 887
 		// set our debug-mode or $bOutputHTML is the other one is set
808
-		if ($this->debug) $bOutputHTML = True;
809
-		if ($bOutputHTML && !$this->debug) $this->debug = 2;
888
+		if ($this->debug)
889
+		{
890
+			$bOutputHTML = True;
891
+		}
892
+		if ($bOutputHTML && !$this->debug)
893
+		{
894
+			$this->debug = 2;
895
+		}
810 896
 
811 897
 		foreach($aTables as $sTableName => $aTableDef)
812 898
 		{
@@ -919,9 +1005,12 @@  discard block
 block discarded – undo
919 1005
 	 */
920 1006
 	function ExecuteSqlArray($aSql,$debug_level)
921 1007
 	{
922
-		if ($this->m_odb->query_log)	// we use Db::query to log the queries
1008
+		if ($this->m_odb->query_log)
1009
+		{
1010
+			// we use Db::query to log the queries
923 1011
 		{
924 1012
 			$retval = 2;
1013
+		}
925 1014
 			foreach($aSql as $sql)
926 1015
 			{
927 1016
 				if (!$this->m_odb->query($sql,__LINE__,__FILE__))
@@ -1004,10 +1093,13 @@  discard block
 block discarded – undo
1004 1093
 
1005 1094
 		// this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle
1006 1095
 		if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 ||
1007
-			strlen($name) >= 64)	// even mysql has a limit here ;-)
1096
+			strlen($name) >= 64)
1097
+		{
1098
+			// even mysql has a limit here ;-)
1008 1099
 		{
1009 1100
 			$name = "i".substr(md5($name),0,29);
1010 1101
 		}
1102
+		}
1011 1103
 		return $name;
1012 1104
 	}
1013 1105
 
@@ -1242,7 +1334,10 @@  discard block
 block discarded – undo
1242 1334
 			$type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1243 1335
 
1244 1336
 			// fix longtext not correctly handled by ADOdb
1245
-			if ($type == 'X' && $column->type == 'longtext') $type = 'XL';
1337
+			if ($type == 'X' && $column->type == 'longtext')
1338
+			{
1339
+				$type = 'XL';
1340
+			}
1246 1341
 
1247 1342
 			static $ado_type2egw = array(
1248 1343
 				'C'		=> 'varchar',
@@ -1349,10 +1444,13 @@  discard block
 block discarded – undo
1349 1444
 			}
1350 1445
 			if ($column->has_default)
1351 1446
 			{
1352
-				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))	// postgres
1447
+				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))
1448
+				{
1449
+					// postgres
1353 1450
 				{
1354 1451
 					$column->default_value = $matches[1];
1355 1452
 				}
1453
+				}
1356 1454
 				$definition['fd'][$name]['default'] = $column->default_value;
1357 1455
 			}
1358 1456
 			if ($column->not_null)
@@ -1364,7 +1462,10 @@  discard block
 block discarded – undo
1364 1462
 				$definition['pk'][] = $name;
1365 1463
 			}
1366 1464
 		}
1367
-		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1465
+		if ($this->debug > 2)
1466
+		{
1467
+			$this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1468
+		}
1368 1469
 
1369 1470
 		// not all DB's (odbc) return the primary keys via MetaColumns
1370 1471
 		if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') &&
@@ -1379,10 +1480,16 @@  discard block
 block discarded – undo
1379 1480
 			}
1380 1481
 			$definition['pk'] = $primary;
1381 1482
 		}
1382
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1483
+		if ($this->debug > 1)
1484
+		{
1485
+			$this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1486
+		}
1383 1487
 
1384 1488
 		$this->GetIndexes($sTableName, $definition);
1385
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1489
+		if ($this->debug > 1)
1490
+		{
1491
+			$this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1492
+		}
1386 1493
 
1387 1494
 		return $definition;
1388 1495
 	}
@@ -1404,7 +1511,10 @@  discard block
 block discarded – undo
1404 1511
 				// append (optional) length of index in brackets to column
1405 1512
 				foreach((array)$index['length'] as $col => $length)
1406 1513
 				{
1407
-					if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')';
1514
+					if (($key = array_search($col, $index['columns'])))
1515
+					{
1516
+						$index['columns'][$key] .= '('.$length.')';
1517
+					}
1408 1518
 				}
1409 1519
 				if($this->capabilities['name_case'] == 'upper')
1410 1520
 				{
@@ -1422,7 +1532,10 @@  discard block
 block discarded – undo
1422 1532
 
1423 1533
 				$definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0];
1424 1534
 			}
1425
-			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1535
+			if ($this->debug > 2)
1536
+			{
1537
+				$this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1538
+			}
1426 1539
 		}
1427 1540
 		return $definition;
1428 1541
 	}
@@ -1436,7 +1549,10 @@  discard block
 block discarded – undo
1436 1549
 	{
1437 1550
 		foreach($this->adodb->MetaTables('TABLES') as $table)
1438 1551
 		{
1439
-			if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue;
1552
+			if (!($table_def = $this->m_odb->get_table_definitions(true, $table)))
1553
+			{
1554
+				continue;
1555
+			}
1440 1556
 
1441 1557
 			$definition = array();
1442 1558
 			$this->GetIndexes($table, $definition);
@@ -1447,7 +1563,10 @@  discard block
 block discarded – undo
1447 1563
 				foreach($table_def[$type] as $columns)
1448 1564
 				{
1449 1565
 					// sometimes primary key is listed as (unique) index too --> ignore it
1450
-					if ($this->_in_index($columns, array($table_def['pk']), true)) continue;
1566
+					if ($this->_in_index($columns, array($table_def['pk']), true))
1567
+					{
1568
+						continue;
1569
+					}
1451 1570
 
1452 1571
 					// check if they exist in real table and create them if not
1453 1572
 					if (!$this->_in_index($columns, $definition[$type]) &&
@@ -1458,7 +1577,10 @@  discard block
 block discarded – undo
1458 1577
 						if ($this->_in_index($columns, $definition[$type], true))
1459 1578
 						{
1460 1579
 							// for PostgreSQL we dont use length-limited indexes --> nothing to do
1461
-							if ($this->m_odb->Type == 'pgsql') continue;
1580
+							if ($this->m_odb->Type == 'pgsql')
1581
+							{
1582
+								continue;
1583
+							}
1462 1584
 							// for MySQL we drop current index and create it with correct length
1463 1585
 							$this->DropIndex($table, $columns);
1464 1586
 						}
Please login to merge, or discard this patch.
api/src/Etemplate.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -543,7 +543,7 @@
 block discarded – undo
543 543
 	 *
544 544
 	 * @param string $name cell-name
545 545
 	 * @param string $attr attribute-name
546
-	 * @param mixed $val if not NULL sets attribute else returns it
546
+	 * @param boolean|string $val if not NULL sets attribute else returns it
547 547
 	 * @return reference to attribute
548 548
 	 * @deprecated use setElementAttribute($name, $attr, $val)
549 549
 	 */
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -158,7 +158,7 @@
 block discarded – undo
158 158
 		// instanciate template to fill self::$request->sel_options for select-* widgets
159 159
 		// not sure if we want to handle it this way, thought otherwise we will have a few ajax request for each dialog fetching predefined selectboxes
160 160
 		$template = self::instance($this->name, $this->template_set, $this->version, $this->laod_via);
161
-		if (!$template) throw new Exception\AssertionFailed("Template $this->name not instanciable! Maybe you forgot to rename template id.");
161
+		if (!$template) throw new Exception\AssertionFailed("template $this->name not instanciable! Maybe you forgot to rename template id.");
162 162
 		$template->run('beforeSendToClient', array('', array('cont'=>$content)));
163 163
 
164 164
 		// some apps (eg. InfoLog) set app_header only in get_rows depending on filter settings
Please login to merge, or discard this patch.
Spacing   +58 added lines, -59 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @public boolean
31 31
 	 */
32
-	public $sitemgr=false;
32
+	public $sitemgr = false;
33 33
 
34 34
 	/**
35 35
 	 * Tell egw framework it's ok to call this
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
 	 * @param string $name of etemplate or array with name and other keys
45 45
 	 * @param string|array $load_via with keys of other etemplate to load in order to get $name
46 46
 	 */
47
-	function __construct($name='',$load_via='')
47
+	function __construct($name = '', $load_via = '')
48 48
 	{
49 49
 		// we do NOT call parent consturctor, as we only want to enherit it's (static) methods
50
-		if (false) parent::__construct ($name);	// satisfy IDE, as we dont call parent constructor
50
+		if (false) parent::__construct($name); // satisfy IDE, as we dont call parent constructor
51 51
 
52 52
 		$this->sitemgr = isset($GLOBALS['Common_BO']) && is_object($GLOBALS['Common_BO']);
53 53
 
54
-		if ($name) $this->read($name,$template='default','default',0,'',$load_via);
54
+		if ($name) $this->read($name, $template = 'default', 'default', 0, '', $load_via);
55 55
 
56 56
 		// generate new etemplate request object, if not already existing
57
-		if(!isset(self::$request)) self::$request = Etemplate\Request::read();
57
+		if (!isset(self::$request)) self::$request = Etemplate\Request::read();
58 58
 	}
59 59
 
60 60
 	/**
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @param string|array $params url or array with get-params incl. menuaction
67 67
 	 */
68
-	static function location($params='')
68
+	static function location($params = '')
69 69
 	{
70 70
 		Framework::redirect_link(is_array($params) ? '/index.php' : $params,
71 71
 			is_array($params) ? $params : '');
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * @param array $changes change made in the last call if looping, only used internaly by process_exec
101 101
 	 * @return string html for $output_mode == 1, else nothing
102 102
 	 */
103
-	function exec($method,array $content,array $sel_options=null,array $readonlys=null,array $preserv=null,$output_mode=0,$ignore_validation='',array $changes=null)
103
+	function exec($method, array $content, array $sel_options = null, array $readonlys = null, array $preserv = null, $output_mode = 0, $ignore_validation = '', array $changes = null)
104 104
 	{
105 105
 		$hook_data = Hooks::process(
106 106
 			array('hook_location'   => 'etemplate2_before_exec') +
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 			$content
110 110
 		);
111 111
 
112
-		foreach($hook_data as $extras)
112
+		foreach ($hook_data as $extras)
113 113
 		{
114 114
 			if (!$extras) continue;
115 115
 
116
-			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
116
+			foreach (isset($extras[0]) ? $extras : array($extras) as $extra)
117 117
 			{
118 118
 				if ($extra['data'] && is_array($extra['data']))
119 119
 				{
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 			$output_mode = 0;
144 144
 			self::$response = Json\Response::get();
145 145
 		}
146
-		self::$request->output_mode = $output_mode;	// let extensions "know" they are run eg. in a popup
146
+		self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup
147 147
 		self::$request->content = self::$cont = $content;
148 148
 		self::$request->changes = $changes;
149 149
 		self::$request->sel_options = is_array($sel_options) ? self::fix_sel_options($sel_options) : array();
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
 
167 167
 		// compile required translations translations
168 168
 		$currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
169
-		$langRequire = array('common' => array(), 'etemplate' => array());	// keep that order
170
-		foreach(Translation::$loaded_apps as $l_app => $lang)
169
+		$langRequire = array('common' => array(), 'etemplate' => array()); // keep that order
170
+		foreach (Translation::$loaded_apps as $l_app => $lang)
171 171
 		{
172 172
 			if (!in_array($l_app, array($currentapp, 'custom')))
173 173
 			{
174 174
 				$langRequire[$l_app] = array('app' => $l_app, 'lang' => $lang, 'etag' => Translation::etag($l_app, $lang));
175 175
 			}
176 176
 		}
177
-		foreach(array($currentapp, 'custom') as $l_app)
177
+		foreach (array($currentapp, 'custom') as $l_app)
178 178
 		{
179 179
 			if (isset(Translation::$loaded_apps[$l_app]))
180 180
 			{
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 		);
196 196
 
197 197
 		// Info required to load the etemplate client-side
198
-		$dom_id = str_replace('.','-',$this->dom_id);
198
+		$dom_id = str_replace('.', '-', $this->dom_id);
199 199
 		$load_array = array(
200 200
 			'name' => $this->name,
201 201
 			'url' => self::rel2url($this->rel_path),
@@ -205,16 +205,16 @@  discard block
 block discarded – undo
205 205
 		if (self::$response)	// call is within an ajax event / form submit
206 206
 		{
207 207
 			//error_log("Ajax " . __LINE__);
208
-			self::$response->generic('et2_load', $load_array+Framework::get_extra());
209
-			Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
208
+			self::$response->generic('et2_load', $load_array + Framework::get_extra());
209
+			Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)
210 210
 		}
211 211
 		else	// first call
212 212
 		{
213 213
 			// check if application of template has a app.js file --> load it
214
-			list($app) = explode('.',$this->name);
214
+			list($app) = explode('.', $this->name);
215 215
 			if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/js/app.js'))
216 216
 			{
217
-				Framework::includeJS('.','app',$app,false);
217
+				Framework::includeJS('.', 'app', $app, false);
218 218
 			}
219 219
 			// Category styles
220 220
 			Categories::css($app);
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
 				$content = '<form target="egw_iframe_autocomplete_helper" action="'.$form_action.'" id="'.$dom_id.'" class="et2_container"></form>'."\n".
233 233
 					'<iframe name="egw_iframe_autocomplete_helper" style="width:0;height:0;position: absolute;visibility:hidden;"></iframe>';
234 234
 				$GLOBALS['egw']->framework->response->generic("data", array($content));
235
-				$GLOBALS['egw']->framework->response->generic('et2_load',$load_array+Framework::get_extra());
236
-				Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
235
+				$GLOBALS['egw']->framework->response->generic('et2_load', $load_array + Framework::get_extra());
236
+				Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)
237 237
 				self::$request = null;
238 238
 				return;
239 239
 			}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 				echo '<div id="popupMainDiv" class="popupMainDiv">'."\n";
253 253
 			}
254 254
 			// Send any accumulated json responses - after flush to avoid sending the buffer as a response
255
-			if(Json\Response::isJSONResponse())
255
+			if (Json\Response::isJSONResponse())
256 256
 			{
257 257
 				$load_array['response'] = Json\Response::get()->returnResult();
258 258
 			}
@@ -279,10 +279,10 @@  discard block
 block discarded – undo
279 279
 	 */
280 280
 	static protected function fix_sel_options(array $sel_options)
281 281
 	{
282
-		foreach($sel_options as &$options)
282
+		foreach ($sel_options as &$options)
283 283
 		{
284
-			if (!is_array($options)||empty($options)) continue;
285
-			foreach($options as $key => $value)
284
+			if (!is_array($options) || empty($options)) continue;
285
+			foreach ($options as $key => $value)
286 286
 			{
287 287
 				if (is_numeric($key) && (!is_array($value) || !isset($value['value'])))
288 288
 				{
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
 		$GLOBALS['egw']->session->set_action('Etemplate: '.self::$request->method);
322 322
 
323 323
 		// Set current app for validation
324
-		list($app) = explode('.',self::$request->method);
325
-		if(!$app) list($app) = explode('::',self::$request->method);
326
-		if($app)
324
+		list($app) = explode('.', self::$request->method);
325
+		if (!$app) list($app) = explode('::', self::$request->method);
326
+		if ($app)
327 327
 		{
328 328
 			Translation::add_app($app);
329 329
 			$GLOBALS['egw_info']['flags']['currentapp'] = $app;
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		$expand = array(
333 333
 			'cont' => &self::$request->content,
334 334
 		);
335
-		$template->run('validate', array('', $expand, $_content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
335
+		$template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
336 336
 
337 337
 		if ($no_validation)
338 338
 		{
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
 		// tell request call to remove request, if it is not modified eg. by call to exec in callback
349 349
 		self::$request->remove_if_not_modified();
350 350
 
351
-		foreach(Hooks::process(array(
351
+		foreach (Hooks::process(array(
352 352
 			'hook_location'   => 'etemplate2_before_process',
353 353
 			'location_name'   => $template->id,
354 354
 		) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras)
355 355
 		{
356 356
 			if (!$extras) continue;
357 357
 
358
-			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
358
+			foreach (isset($extras[0]) ? $extras : array($extras) as $extra)
359 359
 			{
360 360
 				if ($extra['data'] && is_array($extra['data']))
361 361
 				{
@@ -368,8 +368,7 @@  discard block
 block discarded – undo
368 368
 		//error_log(' validated='.array2string($validated));
369 369
 		$content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated));
370 370
 
371
-		$tcontent = is_array($content) ? $content :
372
-			self::complete_array_merge(self::$request->preserv, $validated);
371
+		$tcontent = is_array($content) ? $content : self::complete_array_merge(self::$request->preserv, $validated);
373 372
 
374 373
 		$hook_data = Hooks::process(
375 374
 			array(
@@ -381,11 +380,11 @@  discard block
 block discarded – undo
381 380
 
382 381
 		if (is_array($content))
383 382
 		{
384
-			foreach($hook_data as $extras)
383
+			foreach ($hook_data as $extras)
385 384
 			{
386 385
 				if (!$extras) continue;
387 386
 
388
-				foreach(isset($extras[0]) ? $extras : array($extras) as $extra) {
387
+				foreach (isset($extras[0]) ? $extras : array($extras) as $extra) {
389 388
 					if ($extra['data'] && is_array($extra['data'])) {
390 389
 						$content = array_merge($content, $extra['data']);
391 390
 					}
@@ -397,7 +396,7 @@  discard block
 block discarded – undo
397 396
 		if (isset($GLOBALS['egw_info']['flags']['java_script']))
398 397
 		{
399 398
 			// Strip out any script tags
400
-			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']);
399
+			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']);
401 400
 			self::$response->script($GLOBALS['egw_info']['flags']['java_script']);
402 401
 			//error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use Json\Response->script() instead.');
403 402
 		}
@@ -426,7 +425,7 @@  discard block
 block discarded – undo
426 425
 	static public function process_exec()
427 426
 	{
428 427
 		if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']);
429
-		$content = json_decode($_POST['value'],true);
428
+		$content = json_decode($_POST['value'], true);
430 429
 		//error_log(__METHOD__."(".array2string($content).")");
431 430
 
432 431
 		self::$request = Etemplate\Request::read($_POST['etemplate_exec_id']);
@@ -440,7 +439,7 @@  discard block
 block discarded – undo
440 439
 		$expand = array(
441 440
 			'cont' => &self::$request->content,
442 441
 		);
443
-		$template->run('validate', array('', $expand, $content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
442
+		$template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
444 443
 		if (self::validation_errors(self::$request->ignore_validation))
445 444
 		{
446 445
 			error_log(__METHOD__."(,".array2string($content).') validation_errors='.array2string(self::$validation_errors));
@@ -476,7 +475,7 @@  discard block
 block discarded – undo
476 475
 	 *
477 476
 	 * @ToDo supported customized templates stored in DB
478 477
 	 */
479
-	public function read($name,$template_set=null,$lang='default',$group=0,$version='',$load_via='')
478
+	public function read($name, $template_set = null, $lang = 'default', $group = 0, $version = '', $load_via = '')
480 479
 	{
481 480
 
482 481
 		// For mobile experience try to load custom mobile templates
@@ -485,9 +484,9 @@  discard block
 block discarded – undo
485 484
 			$template_set = "mobile";
486 485
 		}
487 486
 
488
-		unset($lang); unset($group);	// not used, but in old signature
489
-		$this->rel_path = self::relPath($this->name=$name, $this->template_set=$template_set,
490
-			$this->version=$version, $this->laod_via = $load_via);
487
+		unset($lang); unset($group); // not used, but in old signature
488
+		$this->rel_path = self::relPath($this->name = $name, $this->template_set = $template_set,
489
+			$this->version = $version, $this->laod_via = $load_via);
491 490
 		//error_log(__METHOD__."('$name', '$template_set', '$lang', $group, '$version', '$load_via') rel_path=".array2string($this->rel_path));
492 491
 
493 492
 		$this->dom_id = $name;
@@ -530,7 +529,7 @@  discard block
 block discarded – undo
530 529
 	 * @return mixed reference to attribute, usually NULL
531 530
 	 * @deprecated use getElementAttribute($name, $attr)
532 531
 	 */
533
-	public function &get_cell_attribute($name,$attr)
532
+	public function &get_cell_attribute($name, $attr)
534 533
 	{
535 534
 		return self::getElementAttribute($name, $attr);
536 535
 	}
@@ -544,7 +543,7 @@  discard block
 block discarded – undo
544 543
 	 * @return reference to attribute
545 544
 	 * @deprecated use setElementAttribute($name, $attr, $val)
546 545
 	 */
547
-	public function &set_cell_attribute($name,$attr,$val)
546
+	public function &set_cell_attribute($name, $attr, $val)
548 547
 	{
549 548
 		return self::setElementAttribute($name, $attr, $val);
550 549
 	}
@@ -557,7 +556,7 @@  discard block
 block discarded – undo
557 556
 	 * @return reference to attribute
558 557
 	 * @deprecated use disableElement($name, $disabled=true)
559 558
 	 */
560
-	public function disable_cells($name,$disabled=True)
559
+	public function disable_cells($name, $disabled = True)
561 560
 	{
562 561
 		return self::disableElement($name, $disabled);
563 562
 	}
@@ -573,23 +572,23 @@  discard block
 block discarded – undo
573 572
 	 * @param array $new
574 573
 	 * @return array the merged array
575 574
 	 */
576
-	public static function complete_array_merge($old,$new)
575
+	public static function complete_array_merge($old, $new)
577 576
 	{
578 577
 		if (is_array($new))
579 578
 		{
580
-			if (!is_array($old)) $old = (array) $old;
579
+			if (!is_array($old)) $old = (array)$old;
581 580
 
582
-			foreach($new as $k => $v)
581
+			foreach ($new as $k => $v)
583 582
 			{
584
-				if (!is_array($v) || !isset($old[$k]) || 	// no array or a new array
585
-					isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1])	|| // or no associative array, eg. selecting multiple accounts
583
+				if (!is_array($v) || !isset($old[$k]) || // no array or a new array
584
+					isset($v[0]) && !is_array($v[0]) && isset($v[count($v) - 1]) || // or no associative array, eg. selecting multiple accounts
586 585
 					is_array($v) && count($v) == 0)			// Empty array replacing non-empty
587 586
 				{
588 587
 					$old[$k] = $v;
589 588
 				}
590 589
 				else
591 590
 				{
592
-					$old[$k] = self::complete_array_merge($old[$k],$v);
591
+					$old[$k] = self::complete_array_merge($old[$k], $v);
593 592
 				}
594 593
 			}
595 594
 		}
@@ -601,7 +600,7 @@  discard block
 block discarded – undo
601 600
 	 *
602 601
 	 * @param array $content =null
603 602
 	 */
604
-	public function debug(array $content=null)
603
+	public function debug(array $content = null)
605 604
 	{
606 605
 		$GLOBALS['egw']->framework->render(print_r($content, true));
607 606
 	}
@@ -615,11 +614,11 @@  discard block
 block discarded – undo
615 614
 	 * @param int &$max_upload=null on return max. upload size in byte
616 615
 	 * @return string
617 616
 	 */
618
-	static function max_upload_size_message(&$max_upload=null)
617
+	static function max_upload_size_message(&$max_upload = null)
619 618
 	{
620 619
 		$upload_max_filesize = ini_get('upload_max_filesize');
621 620
 		$post_max_size = ini_get('post_max_size');
622
-		$max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800);
621
+		$max_upload = min(self::km2int($upload_max_filesize), self::km2int($post_max_size) - 2800);
623 622
 
624 623
 		return lang('Maximum size for uploads').': '.Vfs::hsize($max_upload).
625 624
 			" (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)";
@@ -633,9 +632,9 @@  discard block
 block discarded – undo
633 632
 	 * @param boolean $readonly =true
634 633
 	 * @return string
635 634
 	 */
636
-	static public function number_format($number,$num_decimal_places=2,$readonly=true)
635
+	static public function number_format($number, $num_decimal_places = 2, $readonly = true)
637 636
 	{
638
-		static $dec_separator=null,$thousands_separator=null;
637
+		static $dec_separator = null, $thousands_separator = null;
639 638
 		if (is_null($dec_separator))
640 639
 		{
641 640
 			$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
@@ -644,7 +643,7 @@  discard block
 block discarded – undo
644 643
 		}
645 644
 		if ((string)$number === '') return '';
646 645
 
647
-		return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : '');
646
+		return number_format(str_replace(' ', '', $number), $num_decimal_places, $dec_separator, $readonly ? $thousands_separator : '');
648 647
 	}
649 648
 
650 649
 	/**
@@ -657,13 +656,13 @@  discard block
 block discarded – undo
657 656
 	{
658 657
 		if (!is_numeric($size))
659 658
 		{
660
-			switch(strtolower(substr($size,-1)))
659
+			switch (strtolower(substr($size, -1)))
661 660
 			{
662 661
 				case 'm':
663
-					$size = 1024*1024*(int)$size;
662
+					$size = 1024 * 1024 * (int)$size;
664 663
 					break;
665 664
 				case 'k':
666
-					$size = 1024*(int)$size;
665
+					$size = 1024 * (int)$size;
667 666
 					break;
668 667
 			}
669 668
 		}
Please login to merge, or discard this patch.
Braces   +81 added lines, -21 removed lines patch added patch discarded remove patch
@@ -47,14 +47,24 @@  discard block
 block discarded – undo
47 47
 	function __construct($name='',$load_via='')
48 48
 	{
49 49
 		// we do NOT call parent consturctor, as we only want to enherit it's (static) methods
50
-		if (false) parent::__construct ($name);	// satisfy IDE, as we dont call parent constructor
50
+		if (false)
51
+		{
52
+			parent::__construct ($name);
53
+		}
54
+		// satisfy IDE, as we dont call parent constructor
51 55
 
52 56
 		$this->sitemgr = isset($GLOBALS['Common_BO']) && is_object($GLOBALS['Common_BO']);
53 57
 
54
-		if ($name) $this->read($name,$template='default','default',0,'',$load_via);
58
+		if ($name)
59
+		{
60
+			$this->read($name,$template='default','default',0,'',$load_via);
61
+		}
55 62
 
56 63
 		// generate new etemplate request object, if not already existing
57
-		if(!isset(self::$request)) self::$request = Etemplate\Request::read();
64
+		if(!isset(self::$request))
65
+		{
66
+			self::$request = Etemplate\Request::read();
67
+		}
58 68
 	}
59 69
 
60 70
 	/**
@@ -111,7 +121,10 @@  discard block
 block discarded – undo
111 121
 
112 122
 		foreach($hook_data as $extras)
113 123
 		{
114
-			if (!$extras) continue;
124
+			if (!$extras)
125
+			{
126
+				continue;
127
+			}
115 128
 
116 129
 			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
117 130
 			{
@@ -136,7 +149,10 @@  discard block
 block discarded – undo
136 149
 		// Include the etemplate2 javascript code
137 150
 		Framework::includeJS('etemplate', 'etemplate2', 'api');
138 151
 
139
-		if (!$this->rel_path) throw new Exception\AssertionFailed("No (valid) template '$this->name' found!");
152
+		if (!$this->rel_path)
153
+		{
154
+			throw new Exception\AssertionFailed("No (valid) template '$this->name' found!");
155
+		}
140 156
 
141 157
 		if ($output_mode == 4)
142 158
 		{
@@ -151,14 +167,23 @@  discard block
 block discarded – undo
151 167
 		self::$request->preserv = $preserv ? $preserv : array();
152 168
 		self::$request->method = $method;
153 169
 		self::$request->ignore_validation = $ignore_validation;
154
-		if (self::$request->output_mode == -1) self::$request->output_mode = 0;
170
+		if (self::$request->output_mode == -1)
171
+		{
172
+			self::$request->output_mode = 0;
173
+		}
155 174
 		self::$request->template = $this->as_array();
156 175
 
157
-		if (empty($this->name)) throw new Exception\AssertionFailed("Template  name is not set '$this->name' !");
176
+		if (empty($this->name))
177
+		{
178
+			throw new Exception\AssertionFailed("Template  name is not set '$this->name' !");
179
+		}
158 180
 		// instanciate template to fill self::$request->sel_options for select-* widgets
159 181
 		// not sure if we want to handle it this way, thought otherwise we will have a few ajax request for each dialog fetching predefined selectboxes
160 182
 		$template = self::instance($this->name, $this->template_set, $this->version, $this->laod_via);
161
-		if (!$template) throw new Exception\AssertionFailed("Template $this->name not instanciable! Maybe you forgot to rename template id.");
183
+		if (!$template)
184
+		{
185
+			throw new Exception\AssertionFailed("Template $this->name not instanciable! Maybe you forgot to rename template id.");
186
+		}
162 187
 		$template->run('beforeSendToClient', array('', array('cont'=>$content)));
163 188
 
164 189
 		// some apps (eg. InfoLog) set app_header only in get_rows depending on filter settings
@@ -202,10 +227,13 @@  discard block
 block discarded – undo
202 227
 			'data' => $data,
203 228
 			'DOMNodeID' => $dom_id,
204 229
 		);
205
-		if (self::$response)	// call is within an ajax event / form submit
230
+		if (self::$response)
231
+		{
232
+			// call is within an ajax event / form submit
206 233
 		{
207 234
 			//error_log("Ajax " . __LINE__);
208 235
 			self::$response->generic('et2_load', $load_array+Framework::get_extra());
236
+		}
209 237
 			Framework::clear_extra();	// to not send/set it twice for multiple etemplates (eg. CRM view)
210 238
 		}
211 239
 		else	// first call
@@ -268,7 +296,10 @@  discard block
 block discarded – undo
268 296
 				echo $GLOBALS['egw']->framework->footer();
269 297
 			}
270 298
 			ob_flush();
271
-			if ($output_mode == 1)	return $form;
299
+			if ($output_mode == 1)
300
+			{
301
+				return $form;
302
+			}
272 303
 		}
273 304
 		self::$request = null;
274 305
 	}
@@ -283,7 +314,10 @@  discard block
 block discarded – undo
283 314
 	{
284 315
 		foreach($sel_options as &$options)
285 316
 		{
286
-			if (!is_array($options)||empty($options)) continue;
317
+			if (!is_array($options)||empty($options))
318
+			{
319
+				continue;
320
+			}
287 321
 			foreach($options as $key => $value)
288 322
 			{
289 323
 				if (is_numeric($key) && (!is_array($value) || !isset($value['value'])))
@@ -324,7 +358,10 @@  discard block
 block discarded – undo
324 358
 
325 359
 		// Set current app for validation
326 360
 		list($app) = explode('.',self::$request->method);
327
-		if(!$app) list($app) = explode('::',self::$request->method);
361
+		if(!$app)
362
+		{
363
+			list($app) = explode('::',self::$request->method);
364
+		}
328 365
 		if($app)
329 366
 		{
330 367
 			Translation::add_app($app);
@@ -355,7 +392,10 @@  discard block
 block discarded – undo
355 392
 			'location_name'   => $template->id,
356 393
 		) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras)
357 394
 		{
358
-			if (!$extras) continue;
395
+			if (!$extras)
396
+			{
397
+				continue;
398
+			}
359 399
 
360 400
 			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
361 401
 			{
@@ -385,10 +425,15 @@  discard block
 block discarded – undo
385 425
 		{
386 426
 			foreach($hook_data as $extras)
387 427
 			{
388
-				if (!$extras) continue;
428
+				if (!$extras)
429
+				{
430
+					continue;
431
+				}
389 432
 
390
-				foreach(isset($extras[0]) ? $extras : array($extras) as $extra) {
391
-					if ($extra['data'] && is_array($extra['data'])) {
433
+				foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
434
+				{
435
+					if ($extra['data'] && is_array($extra['data']))
436
+					{
392 437
 						$content = array_merge($content, $extra['data']);
393 438
 					}
394 439
 				}
@@ -427,7 +472,10 @@  discard block
 block discarded – undo
427 472
 	 */
428 473
 	static public function process_exec()
429 474
 	{
430
-		if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']);
475
+		if (get_magic_quotes_gpc())
476
+		{
477
+			$_POST['value'] = stripslashes($_POST['value']);
478
+		}
431 479
 		$content = json_decode($_POST['value'],true);
432 480
 		//error_log(__METHOD__."(".array2string($content).")");
433 481
 
@@ -579,16 +627,22 @@  discard block
 block discarded – undo
579 627
 	{
580 628
 		if (is_array($new))
581 629
 		{
582
-			if (!is_array($old)) $old = (array) $old;
630
+			if (!is_array($old))
631
+			{
632
+				$old = (array) $old;
633
+			}
583 634
 
584 635
 			foreach($new as $k => $v)
585 636
 			{
586 637
 				if (!is_array($v) || !isset($old[$k]) || 	// no array or a new array
587 638
 					isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1])	|| // or no associative array, eg. selecting multiple accounts
588
-					is_array($v) && count($v) == 0)			// Empty array replacing non-empty
639
+					is_array($v) && count($v) == 0)
640
+				{
641
+					// Empty array replacing non-empty
589 642
 				{
590 643
 					$old[$k] = $v;
591 644
 				}
645
+				}
592 646
 				else
593 647
 				{
594 648
 					$old[$k] = self::complete_array_merge($old[$k],$v);
@@ -641,10 +695,16 @@  discard block
 block discarded – undo
641 695
 		if (is_null($dec_separator))
642 696
 		{
643 697
 			$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
644
-			if (empty($dec_separator)) $dec_separator = '.';
698
+			if (empty($dec_separator))
699
+			{
700
+				$dec_separator = '.';
701
+			}
645 702
 			$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
646 703
 		}
647
-		if ((string)$number === '') return '';
704
+		if ((string)$number === '')
705
+		{
706
+			return '';
707
+		}
648 708
 
649 709
 		return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : '');
650 710
 	}
Please login to merge, or discard this patch.
api/src/Etemplate/Widget.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@
 block discarded – undo
155 155
 	 *
156 156
 	 * @param string|XMLReader $xml
157 157
 	 * @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object
158
-	 * @return Template current object or clone, if any attribute was set
158
+	 * @return Widget current object or clone, if any attribute was set
159 159
 	 */
160 160
 	public function set_attrs($xml, $cloned=true)
161 161
 	{
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -903,12 +903,12 @@
 block discarded – undo
903 903
 	}
904 904
 
905 905
 	/**
906
-	* Check if we have not ignored validation errors
907
-	*
908
-	* @param string $ignore_validation ='' if not empty regular expression for validation-errors to ignore
909
-	* @param string $cname =null name-prefix, which need to be ignored, default self::$name_vars
910
-	* @return boolean true if there are not ignored validation errors, false otherwise
911
-	*/
906
+	 * Check if we have not ignored validation errors
907
+	 *
908
+	 * @param string $ignore_validation ='' if not empty regular expression for validation-errors to ignore
909
+	 * @param string $cname =null name-prefix, which need to be ignored, default self::$name_vars
910
+	 * @return boolean true if there are not ignored validation errors, false otherwise
911
+	 */
912 912
 	public static function validation_errors($ignore_validation='',$cname='')
913 913
 	{
914 914
 		// not yet used: if (is_null($cname)) $cname = self::$name_vars;
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 		$this->id = $reader->getAttribute('id');
100 100
 
101 101
 		// Update content?
102
-		if(self::$cont == null)
102
+		if (self::$cont == null)
103 103
 			self::$cont = is_array(self::$request->content) ? self::$request->content : array();
104
-		if($this->id && is_array(self::$cont[$this->id]))
104
+		if ($this->id && is_array(self::$cont[$this->id]))
105 105
 		{
106 106
 			$old_cont = self::$cont;
107 107
 			self::$cont = self::$cont[$this->id];
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		// read all attributes
111 111
 		$this->set_attrs($reader);
112 112
 
113
-		while($reader->read() && $reader->depth > $depth)
113
+		while ($reader->read() && $reader->depth > $depth)
114 114
 		{
115 115
 			if ($reader->nodeType == XMLReader::ELEMENT && $reader->depth > $depth)
116 116
 			{
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 		}
120 120
 
121 121
 		// Reset content as we leave
122
-		if($old_cont) {
122
+		if ($old_cont) {
123 123
 			self::$cont = $old_cont;
124 124
 		}
125 125
 	}
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object
158 158
 	 * @return Template current object or clone, if any attribute was set
159 159
 	 */
160
-	public function set_attrs($xml, $cloned=true)
160
+	public function set_attrs($xml, $cloned = true)
161 161
 	{
162 162
 		$reader = self::get_reader($xml);
163 163
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 
175 175
 		// read and set all attributes
176 176
 		$template = $this;
177
-		while($reader->moveToNextAttribute())
177
+		while ($reader->moveToNextAttribute())
178 178
 		{
179 179
 			if ($reader->name != 'id' && $template->attr[$reader->name] != $reader->value)
180 180
 			{
181 181
 				if (!$cloned)
182 182
 				{
183 183
 					$template = clone($this);
184
-					$cloned = true;	// only clone it once, otherwise we loose attributes!
184
+					$cloned = true; // only clone it once, otherwise we loose attributes!
185 185
 				}
186 186
 				// $reader->value is an object and therefore assigned by reference
187 187
 				// this is important to not loose content when validating dynamic generated tabs as in settings!
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 				if ($legacy_options && $reader->name == 'options')
199 199
 				{
200 200
 					$legacy_options = explode(',', $legacy_options);
201
-					foreach(self::csv_split($value, count($legacy_options)) as $n => $val)
201
+					foreach (self::csv_split($value, count($legacy_options)) as $n => $val)
202 202
 					{
203 203
 						if ($legacy_options[$n] && (string)$val !== '') $template->attrs[$legacy_options[$n]] = $val;
204 204
 					}
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
 		}
208 208
 
209 209
 		// Add in anything in the modification array
210
-		if(is_array(self::$request->modifications[$this->id]))
210
+		if (is_array(self::$request->modifications[$this->id]))
211 211
 		{
212
-			$this->attrs = array_merge($this->attrs,self::$request->modifications[$this->id]);
212
+			$this->attrs = array_merge($this->attrs, self::$request->modifications[$this->id]);
213 213
 		}
214 214
 
215 215
 		return $template;
@@ -230,32 +230,32 @@  discard block
 block discarded – undo
230 230
 	 * @param string $enclosure ='"'
231 231
 	 * @return array
232 232
 	 */
233
-	public static function csv_split($str,$num=null,$delimiter=',',$enclosure='"')
233
+	public static function csv_split($str, $num = null, $delimiter = ',', $enclosure = '"')
234 234
 	{
235
-		if (strpos($str,$enclosure) === false)
235
+		if (strpos($str, $enclosure) === false)
236 236
 		{
237
-			return is_null($num) ? explode($delimiter,$str) : explode($delimiter,$str,$num);	// no need to run this more expensive code
237
+			return is_null($num) ? explode($delimiter, $str) : explode($delimiter, $str, $num); // no need to run this more expensive code
238 238
 		}
239
-		$parts = explode($delimiter,$str);
240
-		for($n = 0; isset($parts[$n]); ++$n)
239
+		$parts = explode($delimiter, $str);
240
+		for ($n = 0; isset($parts[$n]); ++$n)
241 241
 		{
242
-			$part =& $parts[$n];
242
+			$part = & $parts[$n];
243 243
 			if ($part[0] === $enclosure)
244 244
 			{
245
-				while (isset($parts[$n+1]) && substr($part,-1) !== $enclosure)
245
+				while (isset($parts[$n + 1]) && substr($part, -1) !== $enclosure)
246 246
 				{
247 247
 					$part .= $delimiter.$parts[++$n];
248 248
 					unset($parts[$n]);
249 249
 				}
250
-				$part = substr(str_replace($enclosure.$enclosure,$enclosure,$part),1,-1);
250
+				$part = substr(str_replace($enclosure.$enclosure, $enclosure, $part), 1, -1);
251 251
 			}
252 252
 		}
253
-		$parts_renum = array_values($parts);	// renumber the parts (in case we had to concat them)
253
+		$parts_renum = array_values($parts); // renumber the parts (in case we had to concat them)
254 254
 
255 255
 		if ($num > 0 && count($parts_renum) > $num)
256 256
 		{
257
-			$parts_renum[$num-1] = implode($delimiter,array_slice($parts_renum,$num-1,count($parts_renum)-$num+1));
258
-			$parts_renum = array_slice($parts_renum,0,$num);
257
+			$parts_renum[$num - 1] = implode($delimiter, array_slice($parts_renum, $num - 1, count($parts_renum) - $num + 1));
258
+			$parts_renum = array_slice($parts_renum, 0, $num);
259 259
 		}
260 260
 		return $parts_renum;
261 261
 	}
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 		{
283 283
 			throw new Api\Exception\WrongParameter(__METHOD__."('$class', ".array2string($widgets).") $class is no subclass of ".__CLASS__.'!');
284 284
 		}
285
-		foreach((array)$widgets as $widget)
285
+		foreach ((array)$widgets as $widget)
286 286
 		{
287 287
 			self::$widget_registry[$widget] = $class;
288 288
 		}
@@ -307,15 +307,15 @@  discard block
 block discarded – undo
307 307
 
308 308
 		if (!$widget_registry)	// not in instance cache --> rescan from filesystem
309 309
 		{
310
-			foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path)
310
+			foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path)
311 311
 			{
312
-				if(substr($path, -4) == '.php')
312
+				if (substr($path, -4) == '.php')
313 313
 				{
314 314
 					try
315 315
 					{
316 316
 						include_once($path);
317 317
 					}
318
-					catch(Exception $e)
318
+					catch (Exception $e)
319 319
 					{
320 320
 						error_log($e->getMessage());
321 321
 					}
@@ -323,18 +323,18 @@  discard block
 block discarded – undo
323 323
 			}
324 324
 
325 325
 			// Use hook to load custom widgets from other apps
326
-			$widgets = Api\Hooks::process('etemplate2_register_widgets',array(),true);
327
-			foreach($widgets as $list)
326
+			$widgets = Api\Hooks::process('etemplate2_register_widgets', array(), true);
327
+			foreach ($widgets as $list)
328 328
 			{
329 329
 				if (is_array($list))
330 330
 				{
331
-					foreach($list as $class)
331
+					foreach ($list as $class)
332 332
 					{
333 333
 						try
334 334
 						{
335
-							class_exists($class);	// trigger autoloader
335
+							class_exists($class); // trigger autoloader
336 336
 						}
337
-						catch(Exception $e)
337
+						catch (Exception $e)
338 338
 						{
339 339
 							error_log($e->getMessage());
340 340
 						}
@@ -357,22 +357,22 @@  discard block
 block discarded – undo
357 357
 	 * @param string|XMLReader $xml
358 358
 	 * @param string $id =null
359 359
 	 */
360
-	public static function factory($type, $xml, $id=null)
360
+	public static function factory($type, $xml, $id = null)
361 361
 	{
362
-		$class_name =& self::$widget_registry[$type];
362
+		$class_name = & self::$widget_registry[$type];
363 363
 
364 364
 		if (!isset($class_name))
365 365
 		{
366
-			list($basetype) = explode('-',$type);
366
+			list($basetype) = explode('-', $type);
367 367
 			if (//dont think this is used: !class_exists($class_name = 'etemplate_widget_'.str_replace('-','_',$type)) &&
368 368
 				!class_exists($class_name = __CLASS__.'\\'.ucfirst($basetype)) &&
369 369
 				// widgets supplied by application in class ${app}_widget_etemplate or ${app}_${subtype}_widget_etemplate
370 370
 				!(isset($GLOBALS['egw_info']['apps'][$basetype]) &&
371
-					(class_exists($class_name = str_replace('-','_',$type).'_etemplate_widget') ||
371
+					(class_exists($class_name = str_replace('-', '_', $type).'_etemplate_widget') ||
372 372
 					 class_exists($class_name = $basetype.'_etemplate_widget'))))
373 373
 			{
374 374
 				// Try for base type, it's probably better than the root
375
-				if(self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name)
375
+				if (self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name)
376 376
 				{
377 377
 					$class_name = self::$widget_registry[$basetype];
378 378
 				}
@@ -393,22 +393,22 @@  discard block
 block discarded – undo
393 393
 		{
394 394
 			// Class in widget registry, but not loaded
395 395
 			// Try for a base class
396
-			$subtypes = explode('-',$type);
396
+			$subtypes = explode('-', $type);
397 397
 			$basetype = $subtypes[0];
398
-			$class_name = __CLASS__.'\\'.implode('\\',array_map('ucfirst',$subtypes));
399
-			if(!class_exists($class_name) && self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name)
398
+			$class_name = __CLASS__.'\\'.implode('\\', array_map('ucfirst', $subtypes));
399
+			if (!class_exists($class_name) && self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name)
400 400
 			{
401 401
 				// Try for base type, it's probably better than the root
402 402
 				$class_name = self::$widget_registry[$basetype];
403 403
 			}
404
-			if(!class_exists($class_name))
404
+			if (!class_exists($class_name))
405 405
 			{
406 406
 				// Fall back to widget class, we can not ignore it, as the widget may contain other widgets
407 407
 				$class_name = __CLASS__;
408 408
 			}
409 409
 		}
410 410
 
411
-		if(!$xml)
411
+		if (!$xml)
412 412
 		{
413 413
 			if (empty($type)) $type = 'widget';
414 414
 			$xml = "<$type id='$id'/>";
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 		if ($type == 'template' && $id && ($template = Widget\Template::instance($id)))
420 420
 		{
421 421
 			// references can set different attributes like: class, span, content (namespace)
422
-			return $template->set_attrs($xml, false);	// false = need to clone template, if attributs are set!
422
+			return $template->set_attrs($xml, false); // false = need to clone template, if attributs are set!
423 423
 		}
424 424
 		return new $class_name($xml);
425 425
 	}
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
 	 * @param string $type =null
432 432
 	 * @return Widget|NULL
433 433
 	 */
434
-	public function getElementById($id, $type=null)
434
+	public function getElementById($id, $type = null)
435 435
 	{
436
-		foreach($this->children as $child)
436
+		foreach ($this->children as $child)
437 437
 		{
438 438
 			if ($child->id === $id && (is_null($type) || $child->type === $type))
439 439
 			{
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 	public function getElementsByType($type)
457 457
 	{
458 458
 		$elements = array();
459
-		foreach($this->children as $child)
459
+		foreach ($this->children as $child)
460 460
 		{
461 461
 			if ($child->type === $type)
462 462
 			{
@@ -476,14 +476,14 @@  discard block
 block discarded – undo
476 476
 	 * @param array $params =array('') parameter(s) first parameter has to be the cname, second $expand!
477 477
 	 * @param boolean $respect_disabled =false false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children
478 478
 	 */
479
-	public function run($method_name, $params=array(''), $respect_disabled=false)
479
+	public function run($method_name, $params = array(''), $respect_disabled = false)
480 480
 	{
481 481
 		// maintain $expand array name-expansion
482 482
 		$cname = $params[0];
483
-		$expand =& $params[1];
483
+		$expand = & $params[1];
484 484
 		if ($expand['cname'] && $expand['cname'] !== $cname)
485 485
 		{
486
-			$expand['cont'] =& self::get_array(self::$request->content, $cname);
486
+			$expand['cont'] = & self::get_array(self::$request->content, $cname);
487 487
 			$expand['cname'] = $cname;
488 488
 		}
489 489
 		if ($respect_disabled && ($disabled = $this->attrs['disabled'] && self::check_disabled($this->attrs['disabled'], $expand)))
@@ -496,22 +496,22 @@  discard block
 block discarded – undo
496 496
 			// Some parameter checking to avoid fatal errors
497 497
 			$call = true;
498 498
 			$method = new ReflectionMethod($this, $method_name);
499
-			foreach($method->getParameters() as $index => $param)
499
+			foreach ($method->getParameters() as $index => $param)
500 500
 			{
501
-				if(!$param->isOptional() && !array_key_exists($index,$params))
501
+				if (!$param->isOptional() && !array_key_exists($index, $params))
502 502
 				{
503 503
 					error_log("Missing required parameter {$param->getPosition()}: {$param->getName()}");
504 504
 					$call = false;
505 505
 				}
506
-				if($param->isArray() && !is_array($params[$index]))
506
+				if ($param->isArray() && !is_array($params[$index]))
507 507
 				{
508 508
 					error_log("$method_name expects an array for {$param->getPosition()}: {$param->getName()}");
509 509
 					$params[$index] = (array)$params[$index];
510 510
 				}
511 511
 			}
512
-			if($call) call_user_func_array(array($this, $method_name), $params);
512
+			if ($call) call_user_func_array(array($this, $method_name), $params);
513 513
 		}
514
-		foreach($this->children as $child)
514
+		foreach ($this->children as $child)
515 515
 		{
516 516
 			// If type has something that can be expanded, we need to expand it so the correct method is run
517 517
 			$this->expand_widget($child, $expand);
@@ -526,15 +526,15 @@  discard block
 block discarded – undo
526 526
 	 * @param Widget& $child Widget to check & expand if needed
527 527
 	 * @param array& $expand Expansion array
528 528
 	 */
529
-	protected function expand_widget(Widget &$child, array &$expand)
529
+	protected function expand_widget(Widget&$child, array &$expand)
530 530
 	{
531
-		if(strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false)
531
+		if (strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false)
532 532
 		{
533
-			$type = self::expand_name($child->attrs['type'],$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
534
-			$id = self::expand_name($child->id,$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
533
+			$type = self::expand_name($child->attrs['type'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
534
+			$id = self::expand_name($child->id, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
535 535
 			$attrs = $child->attrs;
536 536
 			unset($attrs['type']);
537
-			$expanded_child = self::factory($type, false,$id);
537
+			$expanded_child = self::factory($type, false, $id);
538 538
 			$expanded_child->id = $id;
539 539
 			$expanded_child->type = $type;
540 540
 			$expanded_child->attrs = $attrs + array('type' => $type);
@@ -557,14 +557,14 @@  discard block
 block discarded – undo
557 557
 	{
558 558
 		if (($not = $disabled[0] == '!'))
559 559
 		{
560
-			$disabled = substr($disabled,1);
560
+			$disabled = substr($disabled, 1);
561 561
 		}
562
-		list($value,$check) = $vals = explode('=',$disabled);
562
+		list($value, $check) = $vals = explode('=', $disabled);
563 563
 
564 564
 		// use expand_name to be able to use @ or $
565 565
 		$val = self::expand_name($value, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
566 566
 		$check_val = self::expand_name($check, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
567
-		$result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val,$val) : $val == $check_val);
567
+		$result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val, $val) : $val == $check_val);
568 568
 		if ($not) $result = !$result;
569 569
 
570 570
 		//error_log(__METHOD__."('".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False'));
@@ -606,33 +606,33 @@  discard block
 block discarded – undo
606 606
 	 * 	"del[$cont[id]]" expands to "del[123]" if $cont = array('id' => 123)
607 607
 	 * @return string the expanded name
608 608
 	 */
609
-	protected static function expand_name($name,$c,$row,$c_='',$row_='',$cont='')
609
+	protected static function expand_name($name, $c, $row, $c_ = '', $row_ = '', $cont = '')
610 610
 	{
611 611
 		$is_index_in_content = $name[0] == '@';
612
-		if (($pos_var=strpos($name,'$')) !== false)
612
+		if (($pos_var = strpos($name, '$')) !== false)
613 613
 		{
614 614
 			if (!$cont)
615 615
 			{
616 616
 				$cont = array();
617 617
 			}
618 618
 			if (!is_numeric($c)) $c = self::chrs2num($c);
619
-			$col = self::num2chrs($c-1);	// $c-1 to get: 0:'@', 1:'A', ...
620
-			$col_ = self::num2chrs($c_-1);
619
+			$col = self::num2chrs($c - 1); // $c-1 to get: 0:'@', 1:'A', ...
620
+			$col_ = self::num2chrs($c_ - 1);
621 621
 			$row_cont = $cont[$row];
622 622
 			$col_row_cont = $cont[$col.$row];
623 623
 
624
-			eval('$name = "'.str_replace('"','\\"',$name).'";');
625
-			unset($col_, $row_, $row_cont, $col_row_cont);	// quiten IDE warning about used vars, they might be used in above eval!
624
+			eval('$name = "'.str_replace('"', '\\"', $name).'";');
625
+			unset($col_, $row_, $row_cont, $col_row_cont); // quiten IDE warning about used vars, they might be used in above eval!
626 626
 		}
627 627
 		if ($is_index_in_content)
628 628
 		{
629 629
 			if ($name[1] == '@' && is_array(self::$request->content))
630 630
 			{
631
-				$name = self::get_array(self::$request->content,substr($name,2));
631
+				$name = self::get_array(self::$request->content, substr($name, 2));
632 632
 			}
633
-			elseif(is_array($cont))
633
+			elseif (is_array($cont))
634 634
 			{
635
-				$name = self::get_array($cont,substr($name,1));
635
+				$name = self::get_array($cont, substr($name, 1));
636 636
 			}
637 637
 			else
638 638
 			{
@@ -654,11 +654,11 @@  discard block
 block discarded – undo
654 654
 		$min = ord('A');
655 655
 		$max = ord('Z') - $min + 1;
656 656
 
657
-		$num = 1+ord($chrs{0})-$min;
657
+		$num = 1 + ord($chrs{0}) - $min;
658 658
 		if (strlen($chrs) > 1)
659 659
 		{
660 660
 			$num *= 1 + $max - $min;
661
-			$num += 1+ord($chrs{1})-$min;
661
+			$num += 1 + ord($chrs{1}) - $min;
662 662
 		}
663 663
 		return $num;
664 664
 	}
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 	 */
690 690
 	public function __toString()
691 691
 	{
692
-		return '['.get_class($this).'] ' .
692
+		return '['.get_class($this).'] '.
693 693
 			$this->type.($this->attrs['type'] && $this->attrs['type'] != $this->type ? '('.$this->attrs['type'].')' : '').'#'.$this->id;
694 694
 	}
695 695
 
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 	 */
699 699
 	public function __clone()
700 700
 	{
701
-		foreach($this->children as $child_num => $child) {
701
+		foreach ($this->children as $child_num => $child) {
702 702
 			$this->children[$child_num] = clone $child;
703 703
 		}
704 704
 	}
@@ -709,16 +709,16 @@  discard block
 block discarded – undo
709 709
 	 * @param string $indent =''
710 710
 	 * @return string
711 711
 	 */
712
-	public function toXml($indent='')
712
+	public function toXml($indent = '')
713 713
 	{
714 714
 		echo "$indent<$this->type";
715 715
 		if ($this->id) echo ' id="'.htmlspecialchars($this->id).'"';
716
-		foreach($this->attrs as $name => $value)
716
+		foreach ($this->attrs as $name => $value)
717 717
 		{
718 718
 			if ($name == 'options' && $this->legacy_options && (!is_array($this->legacy_options) ||
719 719
 				isset($this->legacy_options[$this->attrs['type'] ? $this->attrs['type'] : $this->type])))
720 720
 			{
721
-				continue;	// do NOT output already converted legacy options
721
+				continue; // do NOT output already converted legacy options
722 722
 			}
723 723
 			echo ' '.$name.'="'.htmlspecialchars($value).'"';
724 724
 		}
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 		if ($this->children)
728 728
 		{
729 729
 			echo ">\n";
730
-			foreach($this->children as $child)
730
+			foreach ($this->children as $child)
731 731
 			{
732 732
 				$child->toXml($indent."\t");
733 733
 			}
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 	 * @param array $expand =null values for keys 'c', 'row', 'c_', 'row_', 'cont'
751 751
 	 * @return string complete form-name
752 752
 	 */
753
-	static function form_name($cname,$name,array $expand=null)
753
+	static function form_name($cname, $name, array $expand = null)
754 754
 	{
755 755
 		if ($expand && !empty($name))
756 756
 		{
@@ -758,18 +758,18 @@  discard block
 block discarded – undo
758 758
 		}
759 759
 		if (count($name_parts = explode('[', $name, 2)) > 1)
760 760
 		{
761
-			$name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1],0,-1)));
761
+			$name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1], 0, -1)));
762 762
 		}
763 763
 		if (!empty($cname))
764 764
 		{
765
-			array_unshift($name_parts,$cname);
765
+			array_unshift($name_parts, $cname);
766 766
 		}
767 767
 		$form_name = array_shift($name_parts);
768 768
 		if (count($name_parts))
769 769
 		{
770 770
 			// RB: not sure why this business with entity encoding for square brakets, it messes up validation
771 771
 			//$form_name .= '&#x5B;'.implode('&#x5D;&#x5B;',$name_parts).'&#x5D;';
772
-			$form_name .= '['.implode('][',$name_parts).']';
772
+			$form_name .= '['.implode('][', $name_parts).']';
773 773
 		}
774 774
 		return $form_name;
775 775
 	}
@@ -786,36 +786,36 @@  discard block
 block discarded – undo
786 786
 	 * @param bool $skip_empty returns false if $idx is not present in $arr
787 787
 	 * @return mixed reference to $arr[$idx] or null if $idx is not set and not $reference_into
788 788
 	 */
789
-	static function &get_array(&$arr,$_idx,$reference_into=False,$skip_empty=False)
789
+	static function &get_array(&$arr, $_idx, $reference_into = False, $skip_empty = False)
790 790
 	{
791 791
 		if (!is_array($arr))
792 792
 		{
793 793
 			throw new Api\Exception\AssertionFailed(__METHOD__."(\$arr,'$_idx',$reference_into,$skip_empty) \$arr is no array!");
794 794
 		}
795
-		if (is_object($_idx)) return false;	// given an error in php5.2
795
+		if (is_object($_idx)) return false; // given an error in php5.2
796 796
 
797 797
 		// Make sure none of these are left
798
-		$idx = str_replace(array('&#x5B;','&#x5D;'), array('[',']'), $_idx);
798
+		$idx = str_replace(array('&#x5B;', '&#x5D;'), array('[', ']'), $_idx);
799 799
 
800 800
 		// Handle things expecting arrays - ends in []
801
-		if(substr($idx,-2) == "[]")
801
+		if (substr($idx, -2) == "[]")
802 802
 		{
803
-			$idx = substr($idx,0,-2);
803
+			$idx = substr($idx, 0, -2);
804 804
 		}
805 805
 
806 806
 		if (count($idxs = explode('[', $idx, 2)) > 1)
807 807
 		{
808
-			$idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1],0,-1)));
808
+			$idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1], 0, -1)));
809 809
 		}
810 810
 		$pos = &$arr;
811
-		foreach($idxs as $idx)
811
+		foreach ($idxs as $idx)
812 812
 		{
813 813
 			if (!is_array($pos) && (!$reference_into || $reference_into && isset($pos)))
814 814
 			{
815 815
 				//if ($reference_into) error_log(__METHOD__."(".(strlen($s=array2string($arr))>512?substr($s,0,512).'...':$s).", '$idx', ".array2string($reference_into).", ".array2string($skip_empty).") ".function_backtrace());
816 816
 				return null;
817 817
 			}
818
-			if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null;
818
+			if ($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null;
819 819
 			$pos = &$pos[$idx];
820 820
 		}
821 821
 		return $pos;
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 	 */
834 834
 	static function set_array(&$_arr, $_idx, $_value)
835 835
 	{
836
-		$ref =& self::get_array($_arr, $_idx, true);
836
+		$ref = & self::get_array($_arr, $_idx, true);
837 837
 		if (true) $ref = $_value;
838 838
 	}
839 839
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 	 * @param string $form_name =null form_name, to not calculate him again
848 848
 	 * @return boolean
849 849
 	 */
850
-	public function is_readonly($cname='', $form_name=null)
850
+	public function is_readonly($cname = '', $form_name = null)
851 851
 	{
852 852
 		if (!isset($form_name))
853 853
 		{
@@ -857,11 +857,11 @@  discard block
 block discarded – undo
857 857
 			$form_name = self::form_name($cname, $this->id, $expand);
858 858
 		}
859 859
 		$readonly = $this->attrs['readonly'] || self::$request->readonlys[$form_name] ||
860
-			self::get_array(self::$request->readonlys,$form_name) === true ||
860
+			self::get_array(self::$request->readonlys, $form_name) === true ||
861 861
 			isset(self::$request->readonlys['__ALL__']) && (
862 862
 				// Exceptions to all
863 863
 				self::$request->readonlys[$form_name] !== false &&
864
-				self::get_array(self::$request->readonlys,$form_name) !== false
864
+				self::get_array(self::$request->readonlys, $form_name) !== false
865 865
 			);
866 866
 
867 867
 		//error_log(__METHOD__."('$cname') this->id='$this->id' --> form_name='$form_name': attrs[readonly]=".array2string($this->attrs['readonly']).", readonlys['$form_name']=".array2string(self::$request->readonlys[$form_name]).", readonlys[$form_name]=".array2string(self::get_array(self::$request->readonlys,$form_name)).", readonlys['__ALL__']=".array2string(self::$request->readonlys['__ALL__'])." returning ".array2string($readonly));
@@ -881,12 +881,12 @@  discard block
 block discarded – undo
881 881
 	 * @param string|boolean $error error-message already translated or false to reset all existing error for given name
882 882
 	 * @param string $cname =null set it to '', if the name is already a form-name, defaults to self::$name_vars
883 883
 	 */
884
-	public static function set_validation_error($name,$error,$cname=null)
884
+	public static function set_validation_error($name, $error, $cname = null)
885 885
 	{
886 886
 		// not yet used: if (is_null($cname)) $cname = self::$name_vars;
887 887
 		error_log(__METHOD__."('$name','$error','$cname') ".function_backtrace());
888 888
 
889
-		if ($cname) $name = self::form_name($cname,$name);
889
+		if ($cname) $name = self::form_name($cname, $name);
890 890
 
891 891
 		if ($error === false)
892 892
 		{
@@ -909,18 +909,18 @@  discard block
 block discarded – undo
909 909
 	* @param string $cname =null name-prefix, which need to be ignored, default self::$name_vars
910 910
 	* @return boolean true if there are not ignored validation errors, false otherwise
911 911
 	*/
912
-	public static function validation_errors($ignore_validation='',$cname='')
912
+	public static function validation_errors($ignore_validation = '', $cname = '')
913 913
 	{
914 914
 		// not yet used: if (is_null($cname)) $cname = self::$name_vars;
915 915
 		//echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors);
916 916
 		if (!$ignore_validation) return count(self::$validation_errors) > 0;
917 917
 
918
-		foreach(array_values(self::$validation_errors) as $name)
918
+		foreach (array_values(self::$validation_errors) as $name)
919 919
 		{
920
-			if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name);
920
+			if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/', '\\1\\2', $name);
921 921
 
922 922
 			// treat $ignoare_validation only as regular expression, if it starts with a slash
923
-			if ($ignore_validation[0] == '/' && !preg_match($ignore_validation,$name) ||
923
+			if ($ignore_validation[0] == '/' && !preg_match($ignore_validation, $name) ||
924 924
 				$ignore_validation[0] != '/' && $ignore_validation != $name)
925 925
 			{
926 926
 				//echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') name='$name' ($error) not ignored!!!</p>\n";
@@ -957,14 +957,14 @@  discard block
 block discarded – undo
957 957
 	 * @param mixed $val if not NULL sets attribute else returns it
958 958
 	 * @return reference to attribute
959 959
 	 */
960
-	public static function &setElementAttribute($name,$attr,$val)
960
+	public static function &setElementAttribute($name, $attr, $val)
961 961
 	{
962 962
 		//error_log(__METHOD__."('$name', '$attr', ...) request=".get_class(self::$request).", response=".get_class(self::$response).function_backtrace());
963
-		$ref =& self::$request->modifications[$name][$attr];
964
-		if(self::$request && self::$response && (!isset($this) || $val != $this->attrs[$attr]))
963
+		$ref = & self::$request->modifications[$name][$attr];
964
+		if (self::$request && self::$response && (!isset($this) || $val != $this->attrs[$attr]))
965 965
 		{
966 966
 			// In an AJAX response - automatically add
967
-			self::$response->generic('assign',array(
967
+			self::$response->generic('assign', array(
968 968
 				'etemplate_exec_id' => self::$request->id(),
969 969
 				'id' => $name,
970 970
 				'key' => $attr,
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
 	 * @param boolean $disabled =true disable or enable a cell, default true=disable
989 989
 	 * @return reference to attribute
990 990
 	 */
991
-	public function disableElement($name,$disabled=True)
991
+	public function disableElement($name, $disabled = True)
992 992
 	{
993 993
 		return self::setElementAttribute($name, 'disabled', $disabled);
994 994
 	}
Please login to merge, or discard this patch.
Braces   +68 added lines, -18 removed lines patch added patch discarded remove patch
@@ -100,7 +100,9 @@  discard block
 block discarded – undo
100 100
 
101 101
 		// Update content?
102 102
 		if(self::$cont == null)
103
-			self::$cont = is_array(self::$request->content) ? self::$request->content : array();
103
+		{
104
+					self::$cont = is_array(self::$request->content) ? self::$request->content : array();
105
+		}
104 106
 		if($this->id && is_array(self::$cont[$this->id]))
105 107
 		{
106 108
 			$old_cont = self::$cont;
@@ -119,7 +121,8 @@  discard block
 block discarded – undo
119 121
 		}
120 122
 
121 123
 		// Reset content as we leave
122
-		if($old_cont) {
124
+		if($old_cont)
125
+		{
123 126
 			self::$cont = $old_cont;
124 127
 		}
125 128
 	}
@@ -200,7 +203,10 @@  discard block
 block discarded – undo
200 203
 					$legacy_options = explode(',', $legacy_options);
201 204
 					foreach(self::csv_split($value, count($legacy_options)) as $n => $val)
202 205
 					{
203
-						if ($legacy_options[$n] && (string)$val !== '') $template->attrs[$legacy_options[$n]] = $val;
206
+						if ($legacy_options[$n] && (string)$val !== '')
207
+						{
208
+							$template->attrs[$legacy_options[$n]] = $val;
209
+						}
204 210
 					}
205 211
 				}
206 212
 			}
@@ -305,7 +311,9 @@  discard block
 block discarded – undo
305 311
 
306 312
 		$widget_registry = Api\Cache::getInstance('etemplate', 'widget_registry');
307 313
 
308
-		if (!$widget_registry)	// not in instance cache --> rescan from filesystem
314
+		if (!$widget_registry)
315
+		{
316
+			// not in instance cache --> rescan from filesystem
309 317
 		{
310 318
 			foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path)
311 319
 			{
@@ -314,6 +322,7 @@  discard block
 block discarded – undo
314 322
 					try
315 323
 					{
316 324
 						include_once($path);
325
+		}
317 326
 					}
318 327
 					catch(Exception $e)
319 328
 					{
@@ -410,7 +419,10 @@  discard block
 block discarded – undo
410 419
 
411 420
 		if(!$xml)
412 421
 		{
413
-			if (empty($type)) $type = 'widget';
422
+			if (empty($type))
423
+			{
424
+				$type = 'widget';
425
+			}
414 426
 			$xml = "<$type id='$id'/>";
415 427
 		}
416 428
 		//error_log(__METHOD__."('$type', ..., '$id') using $class_name");
@@ -509,7 +521,10 @@  discard block
 block discarded – undo
509 521
 					$params[$index] = (array)$params[$index];
510 522
 				}
511 523
 			}
512
-			if($call) call_user_func_array(array($this, $method_name), $params);
524
+			if($call)
525
+			{
526
+				call_user_func_array(array($this, $method_name), $params);
527
+			}
513 528
 		}
514 529
 		foreach($this->children as $child)
515 530
 		{
@@ -565,7 +580,10 @@  discard block
 block discarded – undo
565 580
 		$val = self::expand_name($value, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
566 581
 		$check_val = self::expand_name($check, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
567 582
 		$result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val,$val) : $val == $check_val);
568
-		if ($not) $result = !$result;
583
+		if ($not)
584
+		{
585
+			$result = !$result;
586
+		}
569 587
 
570 588
 		//error_log(__METHOD__."('".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False'));
571 589
 		return $result;
@@ -615,7 +633,10 @@  discard block
 block discarded – undo
615 633
 			{
616 634
 				$cont = array();
617 635
 			}
618
-			if (!is_numeric($c)) $c = self::chrs2num($c);
636
+			if (!is_numeric($c))
637
+			{
638
+				$c = self::chrs2num($c);
639
+			}
619 640
 			$col = self::num2chrs($c-1);	// $c-1 to get: 0:'@', 1:'A', ...
620 641
 			$col_ = self::num2chrs($c_-1);
621 642
 			$row_cont = $cont[$row];
@@ -698,7 +719,8 @@  discard block
 block discarded – undo
698 719
 	 */
699 720
 	public function __clone()
700 721
 	{
701
-		foreach($this->children as $child_num => $child) {
722
+		foreach($this->children as $child_num => $child)
723
+		{
702 724
 			$this->children[$child_num] = clone $child;
703 725
 		}
704 726
 	}
@@ -712,7 +734,10 @@  discard block
 block discarded – undo
712 734
 	public function toXml($indent='')
713 735
 	{
714 736
 		echo "$indent<$this->type";
715
-		if ($this->id) echo ' id="'.htmlspecialchars($this->id).'"';
737
+		if ($this->id)
738
+		{
739
+			echo ' id="'.htmlspecialchars($this->id).'"';
740
+		}
716 741
 		foreach($this->attrs as $name => $value)
717 742
 		{
718 743
 			if ($name == 'options' && $this->legacy_options && (!is_array($this->legacy_options) ||
@@ -792,7 +817,11 @@  discard block
 block discarded – undo
792 817
 		{
793 818
 			throw new Api\Exception\AssertionFailed(__METHOD__."(\$arr,'$_idx',$reference_into,$skip_empty) \$arr is no array!");
794 819
 		}
795
-		if (is_object($_idx)) return false;	// given an error in php5.2
820
+		if (is_object($_idx))
821
+		{
822
+			return false;
823
+		}
824
+		// given an error in php5.2
796 825
 
797 826
 		// Make sure none of these are left
798 827
 		$idx = str_replace(array('&#x5B;','&#x5D;'), array('[',']'), $_idx);
@@ -815,7 +844,10 @@  discard block
 block discarded – undo
815 844
 				//if ($reference_into) error_log(__METHOD__."(".(strlen($s=array2string($arr))>512?substr($s,0,512).'...':$s).", '$idx', ".array2string($reference_into).", ".array2string($skip_empty).") ".function_backtrace());
816 845
 				return null;
817 846
 			}
818
-			if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null;
847
+			if($skip_empty && (!is_array($pos) || !isset($pos[$idx])))
848
+			{
849
+				return null;
850
+			}
819 851
 			$pos = &$pos[$idx];
820 852
 		}
821 853
 		return $pos;
@@ -834,7 +866,10 @@  discard block
 block discarded – undo
834 866
 	static function set_array(&$_arr, $_idx, $_value)
835 867
 	{
836 868
 		$ref =& self::get_array($_arr, $_idx, true);
837
-		if (true) $ref = $_value;
869
+		if (true)
870
+		{
871
+			$ref = $_value;
872
+		}
838 873
 	}
839 874
 
840 875
 	/**
@@ -886,7 +921,10 @@  discard block
 block discarded – undo
886 921
 		// not yet used: if (is_null($cname)) $cname = self::$name_vars;
887 922
 		error_log(__METHOD__."('$name','$error','$cname') ".function_backtrace());
888 923
 
889
-		if ($cname) $name = self::form_name($cname,$name);
924
+		if ($cname)
925
+		{
926
+			$name = self::form_name($cname,$name);
927
+		}
890 928
 
891 929
 		if ($error === false)
892 930
 		{
@@ -913,11 +951,17 @@  discard block
 block discarded – undo
913 951
 	{
914 952
 		// not yet used: if (is_null($cname)) $cname = self::$name_vars;
915 953
 		//echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors);
916
-		if (!$ignore_validation) return count(self::$validation_errors) > 0;
954
+		if (!$ignore_validation)
955
+		{
956
+			return count(self::$validation_errors) > 0;
957
+		}
917 958
 
918 959
 		foreach(array_values(self::$validation_errors) as $name)
919 960
 		{
920
-			if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name);
961
+			if ($cname)
962
+			{
963
+				$name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name);
964
+			}
921 965
 
922 966
 			// treat $ignoare_validation only as regular expression, if it starts with a slash
923 967
 			if ($ignore_validation[0] == '/' && !preg_match($ignore_validation,$name) ||
@@ -974,8 +1018,14 @@  discard block
 block discarded – undo
974 1018
 			self::$request->unset_to_process('');
975 1019
 			//error_log(__METHOD__."('$name', '$attr', ...) ".function_backtrace());
976 1020
 		}
977
-		if (isset($this)) $this->attrs[$attr] = $val;
978
-		if (!is_null($val)) $ref = $val;
1021
+		if (isset($this))
1022
+		{
1023
+			$this->attrs[$attr] = $val;
1024
+		}
1025
+		if (!is_null($val))
1026
+		{
1027
+			$ref = $val;
1028
+		}
979 1029
 
980 1030
 		//error_log(__METHOD__."('$name', '$attr', ".array2string($val).')');
981 1031
 		return $ref;
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/Checkbox.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
43 43
 	 * @param array $content
44 44
 	 * @param array &$validated=array() validated content
45
-	 * @return boolean true if no validation error, false otherwise
45
+	 * @return boolean|null true if no validation error, false otherwise
46 46
 	 */
47 47
 	public function validate($cname, array $expand, array $content, &$validated=array())
48 48
 	{
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * @param array &$validated=array() validated content
45 45
 	 * @return boolean true if no validation error, false otherwise
46 46
 	 */
47
-	public function validate($cname, array $expand, array $content, &$validated=array())
47
+	public function validate($cname, array $expand, array $content, &$validated = array())
48 48
 	{
49 49
 		$form_name = self::form_name($cname, $this->id, $expand);
50 50
 
@@ -56,28 +56,28 @@  discard block
 block discarded – undo
56 56
 		if (!$this->is_readonly($cname, $form_name))
57 57
 		{
58 58
 			$value = self::get_array($content, $form_name);
59
-			if (!isset($value))	return;	// value not transmitted --> nothing to validate
60
-			$valid =& self::get_array($validated, $form_name, true);
59
+			if (!isset($value))	return; // value not transmitted --> nothing to validate
60
+			$valid = & self::get_array($validated, $form_name, true);
61 61
 
62 62
 			if (!$value && $this->attrs['needed'])
63 63
 			{
64
-				self::set_validation_error($form_name,lang('Field must not be empty !!!'),'');
64
+				self::set_validation_error($form_name, lang('Field must not be empty !!!'), '');
65 65
 			}
66 66
 			$type = $this->type ? $this->type : $this->attrs['type'];
67 67
 			$value_attr = $type == 'radio' ? 'set_value' : 'selected_value';
68 68
 			// defaults for set and unset values
69 69
 			$selected_value = true;
70 70
 			$unselected_value = false;
71
-			if (array_key_exists($value_attr, $this->attrs) || array_key_exists('unselected_value',$this->attrs))
71
+			if (array_key_exists($value_attr, $this->attrs) || array_key_exists('unselected_value', $this->attrs))
72 72
 			{
73
-				if(array_key_exists($value_attr, $this->attrs))
73
+				if (array_key_exists($value_attr, $this->attrs))
74 74
 				{
75 75
 					// Expand any content stuff
76
-					$selected_value = self::expand_name($this->attrs[$value_attr], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'],$expand['cont']);
76
+					$selected_value = self::expand_name($this->attrs[$value_attr], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
77 77
 				}
78
-				if(array_key_exists('unselected_value',$this->attrs))
78
+				if (array_key_exists('unselected_value', $this->attrs))
79 79
 				{
80
-					$unselected_value = self::expand_name($this->attrs['unselected_value'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'],$expand['cont']);
80
+					$unselected_value = self::expand_name($this->attrs['unselected_value'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
81 81
 				}
82 82
 			}
83 83
 			if ($type == 'radio')
@@ -87,14 +87,14 @@  discard block
 block discarded – undo
87 87
 				{
88 88
 					$valid = $value;
89 89
 				}
90
-				elseif ( !$options && $selected_value && $value == $selected_value)
90
+				elseif (!$options && $selected_value && $value == $selected_value)
91 91
 				{
92 92
 					// Options set in template, not in sel_options
93 93
 					$valid = $selected_value;
94 94
 				}
95 95
 				elseif (!isset($valid))
96 96
 				{
97
-					$valid = '';	// do not overwrite value of an other radio-button of the same group (identical name)!
97
+					$valid = ''; // do not overwrite value of an other radio-button of the same group (identical name)!
98 98
 				}
99 99
 			}
100 100
 			elseif (in_array((string)$selected_value, (array)$value))
Please login to merge, or discard this patch.
Braces   +13 added lines, -3 removed lines patch added patch discarded remove patch
@@ -56,7 +56,11 @@  discard block
 block discarded – undo
56 56
 		if (!$this->is_readonly($cname, $form_name))
57 57
 		{
58 58
 			$value = self::get_array($content, $form_name);
59
-			if (!isset($value))	return;	// value not transmitted --> nothing to validate
59
+			if (!isset($value))
60
+			{
61
+				return;
62
+			}
63
+			// value not transmitted --> nothing to validate
60 64
 			$valid =& self::get_array($validated, $form_name, true);
61 65
 
62 66
 			if (!$value && $this->attrs['needed'])
@@ -101,7 +105,10 @@  discard block
 block discarded – undo
101 105
 			{
102 106
 				if ($multiple)
103 107
 				{
104
-					if (!isset($valid)) $valid = array();
108
+					if (!isset($valid))
109
+					{
110
+						$valid = array();
111
+					}
105 112
 					$valid[] = $selected_value;
106 113
 				}
107 114
 				else
@@ -113,7 +120,10 @@  discard block
 block discarded – undo
113 120
 			{
114 121
 				if ($multiple)
115 122
 				{
116
-					if (!isset($valid)) $valid = array();
123
+					if (!isset($valid))
124
+					{
125
+						$valid = array();
126
+					}
117 127
 				}
118 128
 				elseif ($value === 'true')
119 129
 				{
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/Date.php 4 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -101,7 +101,6 @@  discard block
 block discarded – undo
101 101
 	/**
102 102
 	 * Put date in the proper format for sending to client
103 103
 	 * @param string|int $value
104
-	 * @param string $format
105 104
 	 */
106 105
 	public function format_date($value)
107 106
 	{
@@ -139,7 +138,7 @@  discard block
 block discarded – undo
139 138
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
140 139
 	 * @param array $content
141 140
 	 * @param array &$validated=array() validated content
142
-	 * @return boolean true if no validation error, false otherwise
141
+	 * @return boolean|null true if no validation error, false otherwise
143 142
 	 */
144 143
 	public function validate($cname, array $expand, array $content, &$validated=array())
145 144
 	{
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
 	 * @param string $cname
61 61
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
62 62
 	 */
63
-	public function beforeSendToClient($cname, array $expand=null)
63
+	public function beforeSendToClient($cname, array $expand = null)
64 64
 	{
65
-		if($this->type == 'date-houronly')
65
+		if ($this->type == 'date-houronly')
66 66
 		{
67 67
 			return parent::beforeSendToClient($cname, $expand);
68 68
 		}
69 69
 
70 70
 		$form_name = self::form_name($cname, $this->id, $expand);
71
-		$value =& self::get_array(self::$request->content, $form_name, false, true);
71
+		$value = & self::get_array(self::$request->content, $form_name, false, true);
72 72
 
73
-		if($this->type != 'date-duration' && $value)
73
+		if ($this->type != 'date-duration' && $value)
74 74
 		{
75 75
 			$value = $this->format_date($value);
76 76
 		}
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function set_row_value($cname, Array $expand, Array &$data)
92 92
 	{
93
-		if($this->type == 'date-duration') return;
93
+		if ($this->type == 'date-duration') return;
94 94
 
95 95
 		$form_name = self::form_name($cname, $this->id, $expand);
96
-		$value =& $this->get_array($data, $form_name, true);
96
+		$value = & $this->get_array($data, $form_name, true);
97 97
 
98 98
 		if (true) $value = $this->format_date($value);
99 99
 	}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	public function format_date($value)
107 107
 	{
108
-		if (!$value) return $value;	// otherwise we will get current date or 1970-01-01 instead of an empty value
108
+		if (!$value) return $value; // otherwise we will get current date or 1970-01-01 instead of an empty value
109 109
 
110 110
 		if ($this->attrs['dataformat'] && !is_numeric($value))
111 111
 		{
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 		{
116 116
 			$date = new Api\DateTime($value);
117 117
 		}
118
-		if($this->type == 'date-timeonly')
118
+		if ($this->type == 'date-timeonly')
119 119
 		{
120 120
 			$date->setDate(1970, 1, 1);
121 121
 		}
122
-		if($date)
122
+		if ($date)
123 123
 		{
124 124
 			// postfix date-string with "Z" so javascript doesn't add/subtract anything
125 125
 			$value = $date->format('Y-m-d\TH:i:s\Z');
@@ -141,18 +141,18 @@  discard block
 block discarded – undo
141 141
 	 * @param array &$validated=array() validated content
142 142
 	 * @return boolean true if no validation error, false otherwise
143 143
 	 */
144
-	public function validate($cname, array $expand, array $content, &$validated=array())
144
+	public function validate($cname, array $expand, array $content, &$validated = array())
145 145
 	{
146 146
 		$form_name = self::form_name($cname, $this->id, $expand);
147 147
 
148 148
 		if (!$this->is_readonly($cname, $form_name) && $this->type != 'date-since')	// date-since is always readonly
149 149
 		{
150 150
 			$value = self::get_array($content, $form_name);
151
-			$valid =& self::get_array($validated, $form_name, true);
151
+			$valid = & self::get_array($validated, $form_name, true);
152 152
 
153 153
 			if ((string)$value === '' && $this->attrs['needed'])
154 154
 			{
155
-				self::set_validation_error($form_name,lang('Field must not be empty !!!'));
155
+				self::set_validation_error($form_name, lang('Field must not be empty !!!'));
156 156
 			}
157 157
 			elseif (is_null($value))
158 158
 			{
@@ -162,49 +162,49 @@  discard block
 block discarded – undo
162 162
 			{
163 163
 				$valid = (string)$value === '' ? '' : (int)$value;
164 164
 			}
165
-			if($value)
165
+			if ($value)
166 166
 			{
167 167
 				$date = new Api\DateTime($value);
168 168
 			}
169 169
 			if (!empty($this->attrs['min']))
170 170
 			{
171
-				if(is_numeric($this->attrs['min']))
171
+				if (is_numeric($this->attrs['min']))
172 172
 				{
173
-					$min = new Api\DateTime(strtotime( $this->attrs['min'] . 'days'));
173
+					$min = new Api\DateTime(strtotime($this->attrs['min'].'days'));
174 174
 				}
175 175
 				else
176 176
 				{
177 177
 					$min = new Api\DateTime(strtotime($this->attrs['min']));
178 178
 				}
179
-				if($value < $min)
179
+				if ($value < $min)
180 180
 				{
181
-					self::set_validation_error($form_name,lang(
181
+					self::set_validation_error($form_name, lang(
182 182
 						"Value has to be at least '%1' !!!",
183 183
 						$min->format($this->type != 'date')
184
-					),'');
184
+					), '');
185 185
 					$value = $min;
186 186
 				}
187 187
 			}
188 188
 			if (!empty($this->attrs['max']))
189 189
 			{
190
-				if(is_numeric($this->attrs['max']))
190
+				if (is_numeric($this->attrs['max']))
191 191
 				{
192
-					$max = new Api\DateTime(strtotime( $this->attrs['max'] . 'days'));
192
+					$max = new Api\DateTime(strtotime($this->attrs['max'].'days'));
193 193
 				}
194 194
 				else
195 195
 				{
196 196
 					$max = new Api\DateTime(strtotime($this->attrs['max']));
197 197
 				}
198
-				if($value < $max)
198
+				if ($value < $max)
199 199
 				{
200
-					self::set_validation_error($form_name,lang(
200
+					self::set_validation_error($form_name, lang(
201 201
 						"Value has to be at maximum '%1' !!!",
202 202
 						$max->format($this->type != 'date')
203
-					),'');
203
+					), '');
204 204
 					$value = $max;
205 205
 				}
206 206
 			}
207
-			if(!$value)
207
+			if (!$value)
208 208
 			{
209 209
 				// Not null, blank
210 210
 				$value = '';
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 			else
222 222
 			{
223 223
 				// this is not really a user error, but one of the clientside engine
224
-				self::set_validation_error($form_name,lang("'%1' is not a valid date !!!", $value).' '.$this->dataformat);
224
+				self::set_validation_error($form_name, lang("'%1' is not a valid date !!!", $value).' '.$this->dataformat);
225 225
 			}
226 226
 			//error_log("$this : ($valid)" . Api\DateTime::to($valid));
227 227
 		}
Please login to merge, or discard this patch.
Braces   +21 added lines, -5 removed lines patch added patch discarded remove patch
@@ -90,12 +90,18 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function set_row_value($cname, Array $expand, Array &$data)
92 92
 	{
93
-		if($this->type == 'date-duration') return;
93
+		if($this->type == 'date-duration')
94
+		{
95
+			return;
96
+		}
94 97
 
95 98
 		$form_name = self::form_name($cname, $this->id, $expand);
96 99
 		$value =& $this->get_array($data, $form_name, true);
97 100
 
98
-		if (true) $value = $this->format_date($value);
101
+		if (true)
102
+		{
103
+			$value = $this->format_date($value);
104
+		}
99 105
 	}
100 106
 
101 107
 	/**
@@ -105,7 +111,11 @@  discard block
 block discarded – undo
105 111
 	 */
106 112
 	public function format_date($value)
107 113
 	{
108
-		if (!$value) return $value;	// otherwise we will get current date or 1970-01-01 instead of an empty value
114
+		if (!$value)
115
+		{
116
+			return $value;
117
+		}
118
+		// otherwise we will get current date or 1970-01-01 instead of an empty value
109 119
 
110 120
 		if ($this->attrs['dataformat'] && !is_numeric($value))
111 121
 		{
@@ -145,9 +155,12 @@  discard block
 block discarded – undo
145 155
 	{
146 156
 		$form_name = self::form_name($cname, $this->id, $expand);
147 157
 
148
-		if (!$this->is_readonly($cname, $form_name) && $this->type != 'date-since')	// date-since is always readonly
158
+		if (!$this->is_readonly($cname, $form_name) && $this->type != 'date-since')
159
+		{
160
+			// date-since is always readonly
149 161
 		{
150 162
 			$value = self::get_array($content, $form_name);
163
+		}
151 164
 			$valid =& self::get_array($validated, $form_name, true);
152 165
 
153 166
 			if ((string)$value === '' && $this->attrs['needed'])
@@ -209,10 +222,13 @@  discard block
 block discarded – undo
209 222
 				// Not null, blank
210 223
 				$value = '';
211 224
 			}
212
-			elseif (empty($this->attrs['dataformat']))	// integer timestamp
225
+			elseif (empty($this->attrs['dataformat']))
226
+			{
227
+				// integer timestamp
213 228
 			{
214 229
 				$valid = $date->format('ts');
215 230
 			}
231
+			}
216 232
 			// string with formatting letters like for php's date() method
217 233
 			elseif ($date && ($valid = $date->format($this->attrs['dataformat'])))
218 234
 			{
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
 	 * @param array $data Row data
89 89
 	 * @return type
90 90
 	 */
91
-	public function set_row_value($cname, Array $expand, Array &$data)
91
+	public function set_row_value($cname, array $expand, array &$data)
92 92
 	{
93 93
 		if($this->type == 'date-duration') return;
94 94
 
Please login to merge, or discard this patch.
api/src/Etemplate/Widget/Tabbox.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,6 @@
 block discarded – undo
102 102
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
103 103
 	 * @param array $content
104 104
 	 * @param array &$validated=array() validated content
105
-	 * @param array $expand=array values for keys 'c', 'row', 'c_', 'row_', 'cont'
106 105
 	 */
107 106
 	public function validate($cname, array $expand, array $content, &$validated=array())
108 107
 	{
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,7 +65,10 @@  discard block
 block discarded – undo
65 65
 			foreach($tabs as &$tab)
66 66
 			{
67 67
 				$template= clone Template::instance($tab['template']);
68
-				if($tab['id']) $template->attrs['content'] = $tab['id'];
68
+				if($tab['id'])
69
+				{
70
+					$template->attrs['content'] = $tab['id'];
71
+				}
69 72
 				$this->children[1]->children[] = $template;
70 73
 				$tab['url'] = Template::rel2url($template->rel_path);
71 74
 				//$this->tabs[] = $tab;
@@ -112,7 +115,10 @@  discard block
 block discarded – undo
112 115
 		{
113 116
 			$value = self::get_array($content, $form_name);
114 117
 			$valid =& self::get_array($validated, $form_name, true);
115
-			if (true) $valid = $value;
118
+			if (true)
119
+			{
120
+				$valid = $value;
121
+			}
116 122
 		}
117 123
 	}
118 124
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -42,30 +42,30 @@  discard block
 block discarded – undo
42 42
 	 * @param array $params =array('') parameter(s) first parameter has to be the cname, second $expand!
43 43
 	 * @param boolean $respect_disabled =false false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children
44 44
 	 */
45
-	public function run($method_name, $params=array(''), $respect_disabled=false)
45
+	public function run($method_name, $params = array(''), $respect_disabled = false)
46 46
 	{
47 47
 		$form_name = self::form_name($params[0], $this->id, $params[1]);
48 48
 
49 49
 		// Make sure additional tabs are processed for any method
50
-		if (!($tabs =& self::getElementAttribute($form_name, 'tabs')))
50
+		if (!($tabs = & self::getElementAttribute($form_name, 'tabs')))
51 51
 		{
52 52
 			$tabs = $this->attrs['tabs'];
53 53
 		}
54
-		if($tabs && !$this->tabs_attr_evaluated)
54
+		if ($tabs && !$this->tabs_attr_evaluated)
55 55
 		{
56
-			$this->tabs_attr_evaluated = true;	// we must not evaluate tabs attribte more then once!
56
+			$this->tabs_attr_evaluated = true; // we must not evaluate tabs attribte more then once!
57 57
 
58 58
 			// add_tabs toggles replacing or adding to existing tabs
59
-			if(!$this->attrs['add_tabs'])
59
+			if (!$this->attrs['add_tabs'])
60 60
 			{
61 61
 				$this->children[1]->children = array();
62 62
 			}
63 63
 
64 64
 			//$this->tabs = array();
65
-			foreach($tabs as &$tab)
65
+			foreach ($tabs as &$tab)
66 66
 			{
67
-				$template= clone Template::instance($tab['template']);
68
-				if($tab['id']) $template->attrs['content'] = $tab['id'];
67
+				$template = clone Template::instance($tab['template']);
68
+				if ($tab['id']) $template->attrs['content'] = $tab['id'];
69 69
 				$this->children[1]->children[] = $template;
70 70
 				$tab['url'] = Template::rel2url($template->rel_path);
71 71
 				//$this->tabs[] = $tab;
@@ -83,22 +83,22 @@  discard block
 block discarded – undo
83 83
 		// to avoid checking for server side validation
84 84
 		if ($form_name == 'tabs' && is_array($readonlys))
85 85
 		{
86
-			foreach($this->children[1]->children as $tab)
86
+			foreach ($this->children[1]->children as $tab)
87 87
 			{
88
-				if($readonlys[$tab->id])
88
+				if ($readonlys[$tab->id])
89 89
 				{
90 90
 					$tab->attrs['disabled'] = $readonlys[$tab->id];
91 91
 				}
92 92
 			}
93 93
 		}
94 94
 		
95
-		if($respect_disabled && $readonlys)
95
+		if ($respect_disabled && $readonlys)
96 96
 		{
97
-			foreach($this->children[1]->children as $tab)
97
+			foreach ($this->children[1]->children as $tab)
98 98
 			{
99
-				$parts = explode('.',$tab->template ? $tab->template : $tab->id);
99
+				$parts = explode('.', $tab->template ? $tab->template : $tab->id);
100 100
 				$ro_id = array_pop($parts);
101
-				if($readonlys[$ro_id])
101
+				if ($readonlys[$ro_id])
102 102
 				{
103 103
 					$tab->attrs['disabled'] = $readonlys[$ro_id];
104 104
 				}
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 	 * @param array &$validated=array() validated content
119 119
 	 * @param array $expand=array values for keys 'c', 'row', 'c_', 'row_', 'cont'
120 120
 	 */
121
-	public function validate($cname, array $expand, array $content, &$validated=array())
121
+	public function validate($cname, array $expand, array $content, &$validated = array())
122 122
 	{
123 123
 		$form_name = self::form_name($cname, $this->id, $expand);
124 124
 
125 125
 		if (!empty($form_name))
126 126
 		{
127 127
 			$value = self::get_array($content, $form_name);
128
-			$valid =& self::get_array($validated, $form_name, true);
128
+			$valid = & self::get_array($validated, $form_name, true);
129 129
 			if (true) $valid = $value;
130 130
 		}
131 131
 	}
Please login to merge, or discard this patch.