Completed
Push — master ( 9d054b...106a1b )
by Klaus
23:45 queued 04:19
created
api/src/Db.php 5 patches
Doc Comments   +4 added lines, -12 removed lines patch added patch discarded remove patch
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 	 * require_once(EGW_INCLUDE_ROOT.'/api/src/Db.php');
372 372
 	 * EGroupware\Api\Db::$health_check = array('EGroupware\Api\Db', 'galera_cluster_health');
373 373
 	 *
374
-	 * @param Api\Db $db already connected Api\Db instance to check
374
+	 * @param Db $db already connected Api\Db instance to check
375 375
 	 * @throws Db\Exception\Connection if node should NOT be used
376 376
 	 */
377 377
 	static function galera_cluster_health(Db $db)
@@ -1077,7 +1077,6 @@  discard block
 block discarded – undo
1077 1077
 	 *
1078 1078
 	 * Example: $db->concat($db->quote('Hallo '),'username') would return
1079 1079
 	 *	for mysql "concat('Hallo ',username)" or "'Hallo ' || username" for postgres
1080
-	 * @param string $str1 already quoted stringliteral or column-name, variable number of arguments
1081 1080
 	 * @return string to be used in a query
1082 1081
 	 */
1083 1082
 	function concat(/*$str1, ...*/)
@@ -1097,7 +1096,7 @@  discard block
 block discarded – undo
1097 1096
 	 * @param string $expr column-name or expression optional prefixed with "DISTINCT"
1098 1097
 	 * @param string $order_by ='' optional order
1099 1098
 	 * @param string $separator =',' optional separator, default is comma
1100
-	 * @return string|boolean false if not supported by dbms
1099
+	 * @return false|string false if not supported by dbms
1101 1100
 	 */
1102 1101
 	function group_concat($expr, $order_by='', $separator=',')
1103 1102
 	{
@@ -1430,7 +1429,7 @@  discard block
 block discarded – undo
1430 1429
 	*	array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!)
1431 1430
 	* @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False
1432 1431
 	*	or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned
1433
-	* @param array|boolean $only if set to an array only colums which are set (as data !!!) are written
1432
+	* @param boolean $only if set to an array only colums which are set (as data !!!) are written
1434 1433
 	*	typicaly used to form a WHERE-clause from the primary keys.
1435 1434
 	*	If set to True, only columns from the colum_definitons are written.
1436 1435
 	* @param array|boolean $column_definitions this can be set to the column-definitions-array
@@ -1910,13 +1909,6 @@  discard block
 block discarded – undo
1910 1909
 	 * gives "(name='test\'ed' AND lang='en') OR 'owner' IN (0,4,5,6,10)" if name,lang are strings and owner is an integer
1911 1910
 	 *
1912 1911
 	 * @param string|array $table_def table-name or definition array
1913
-	 * @param mixed $args variable number of arguments of the following types:
1914
-	 *	string: get's as is into the result
1915
-	 *	array:	column-name / value pairs: the value gets quoted according to the type of the column and prefixed
1916
-	 *		with column-name=, multiple pairs are AND'ed together, see db::column_data_implode
1917
-	 *	bool: If False or is_null($arg): the next 2 (!) arguments gets ignored
1918
-	 *
1919
-	 * Please note: As the function has a variable number of arguments, you CAN NOT add further parameters !!!
1920 1912
 	 *
1921 1913
 	 * @return string the expression generated from the arguments
1922 1914
 	 */
@@ -2054,7 +2046,7 @@  discard block
 block discarded – undo
2054 2046
 	 * Strip eg. a prefix from the keys of an array
2055 2047
 	 *
2056 2048
 	 * @param array $arr
2057
-	 * @param string|array $strip
2049
+	 * @param string $strip
2058 2050
 	 * @return array
2059 2051
 	 */
2060 2052
 	static function strip_array_keys($arr,$strip)
Please login to merge, or discard this patch.
Indentation   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -67,43 +67,43 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	const FETCH_BOTH = ADODB_FETCH_BOTH;
69 69
 	/**
70
-	* @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types
71
-	*/
70
+	 * @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types
71
+	 */
72 72
 	var $Type     = '';
73 73
 
74 74
 	/**
75
-	* @var string $type database type as defined in the header.inc.php, eg. mysqlt
76
-	*/
75
+	 * @var string $type database type as defined in the header.inc.php, eg. mysqlt
76
+	 */
77 77
 	var $setupType     = '';
78 78
 
79 79
 	/**
80
-	* @var string $Host database host to connect to
81
-	*/
80
+	 * @var string $Host database host to connect to
81
+	 */
82 82
 	var $Host     = '';
83 83
 
84 84
 	/**
85
-	* @var string $Port port number of database to connect to
86
-	*/
85
+	 * @var string $Port port number of database to connect to
86
+	 */
87 87
 	var $Port     = '';
88 88
 
89 89
 	/**
90
-	* @var string $Database name of database to use
91
-	*/
90
+	 * @var string $Database name of database to use
91
+	 */
92 92
 	var $Database = '';
93 93
 
94 94
 	/**
95
-	* @var string $User name of database user
96
-	*/
95
+	 * @var string $User name of database user
96
+	 */
97 97
 	var $User     = '';
98 98
 
99 99
 	/**
100
-	* @var string $Password password for database user
101
-	*/
100
+	 * @var string $Password password for database user
101
+	 */
102 102
 	var $Password = '';
103 103
 
104 104
 	/**
105
-	* @var int $Debug enable debuging - 0 no, 1 yes
106
-	*/
105
+	 * @var int $Debug enable debuging - 0 no, 1 yes
106
+	 */
107 107
 	var $Debug         = 0;
108 108
 
109 109
 	/**
@@ -114,23 +114,23 @@  discard block
 block discarded – undo
114 114
 	var $log_updates = false;
115 115
 
116 116
 	/**
117
-	* @var array $Record current record
118
-	*/
117
+	 * @var array $Record current record
118
+	 */
119 119
 	var $Record   = array();
120 120
 
121 121
 	/**
122
-	* @var int row number for current record
123
-	*/
122
+	 * @var int row number for current record
123
+	 */
124 124
 	var $Row;
125 125
 
126 126
 	/**
127
-	* @var int $Errno internal rdms error number for last error
128
-	*/
127
+	 * @var int $Errno internal rdms error number for last error
128
+	 */
129 129
 	var $Errno    = 0;
130 130
 
131 131
 	/**
132
-	* @var string descriptive text from last error
133
-	*/
132
+	 * @var string descriptive text from last error
133
+	 */
134 134
 	var $Error    = '';
135 135
 
136 136
 	/**
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	}
271 271
 
272 272
 	/**
273
-	* @param string $query query to be executed (optional)
274
-	*/
273
+	 * @param string $query query to be executed (optional)
274
+	 */
275 275
 
276 276
 	function db($query = '')
277 277
 	{
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 	}
280 280
 
281 281
 	/**
282
-	* @return int current connection id
283
-	*/
282
+	 * @return int current connection id
283
+	 */
284 284
 	function link_id()
285 285
 	{
286 286
 		return $this->Link_ID;
@@ -652,8 +652,8 @@  discard block
 block discarded – undo
652 652
 	}
653 653
 
654 654
 	/**
655
-	* Close a connection to a database
656
-	*/
655
+	 * Close a connection to a database
656
+	 */
657 657
 	function disconnect()
658 658
 	{
659 659
 		if (!$this->privat_Link_ID)
@@ -667,11 +667,11 @@  discard block
 block discarded – undo
667 667
 	}
668 668
 
669 669
 	/**
670
-	* Convert a unix timestamp to a rdms specific timestamp
671
-	*
672
-	* @param int unix timestamp
673
-	* @return string rdms specific timestamp
674
-	*/
670
+	 * Convert a unix timestamp to a rdms specific timestamp
671
+	 *
672
+	 * @param int unix timestamp
673
+	 * @return string rdms specific timestamp
674
+	 */
675 675
 	function to_timestamp($epoch)
676 676
 	{
677 677
 		if (!$this->Link_ID && !$this->connect())
@@ -683,11 +683,11 @@  discard block
 block discarded – undo
683 683
 	}
684 684
 
685 685
 	/**
686
-	* Convert a rdms specific timestamp to a unix timestamp
687
-	*
688
-	* @param string rdms specific timestamp
689
-	* @return int unix timestamp
690
-	*/
686
+	 * Convert a rdms specific timestamp to a unix timestamp
687
+	 *
688
+	 * @param string rdms specific timestamp
689
+	 * @return int unix timestamp
690
+	 */
691 691
 	function from_timestamp($timestamp)
692 692
 	{
693 693
 		if (!$this->Link_ID && !$this->connect())
@@ -709,19 +709,19 @@  discard block
 block discarded – undo
709 709
 	}
710 710
 
711 711
 	/**
712
-	* Execute a query
713
-	*
714
-	* @param string $Query_String the query to be executed
715
-	* @param int $line the line method was called from - use __LINE__
716
-	* @param string $file the file method was called from - use __FILE__
717
-	* @param int $offset row to start from, default 0
718
-	* @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']
719
-	* @param array|boolean $inputarr array for binding variables to parameters or false (default)
720
-	* @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM
721
-	* @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!)
722
-	* @return ADORecordSet or false, if the query fails
723
-	* @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code
724
-	*/
712
+	 * Execute a query
713
+	 *
714
+	 * @param string $Query_String the query to be executed
715
+	 * @param int $line the line method was called from - use __LINE__
716
+	 * @param string $file the file method was called from - use __FILE__
717
+	 * @param int $offset row to start from, default 0
718
+	 * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']
719
+	 * @param array|boolean $inputarr array for binding variables to parameters or false (default)
720
+	 * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM
721
+	 * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!)
722
+	 * @return ADORecordSet or false, if the query fails
723
+	 * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code
724
+	 */
725 725
 	function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true)
726 726
 	{
727 727
 		unset($line, $file);	// not used anymore
@@ -786,26 +786,26 @@  discard block
 block discarded – undo
786 786
 	}
787 787
 
788 788
 	/**
789
-	* Execute a query with limited result set
790
-	*
791
-	* @param string $Query_String the query to be executed
792
-	* @param int $offset row to start from, default 0
793
-	* @param int $line the line method was called from - use __LINE__
794
-	* @param string $file the file method was called from - use __FILE__
795
-	* @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']
796
-	* @param array|boolean $inputarr array for binding variables to parameters or false (default)
797
-	* @return ADORecordSet or false, if the query fails
798
-	*/
789
+	 * Execute a query with limited result set
790
+	 *
791
+	 * @param string $Query_String the query to be executed
792
+	 * @param int $offset row to start from, default 0
793
+	 * @param int $line the line method was called from - use __LINE__
794
+	 * @param string $file the file method was called from - use __FILE__
795
+	 * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']
796
+	 * @param array|boolean $inputarr array for binding variables to parameters or false (default)
797
+	 * @return ADORecordSet or false, if the query fails
798
+	 */
799 799
 	function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false)
800 800
 	{
801 801
 		return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr);
802 802
 	}
803 803
 
804 804
 	/**
805
-	* Begin Transaction
806
-	*
807
-	* @return int/boolean current transaction-id, of false if no connection
808
-	*/
805
+	 * Begin Transaction
806
+	 *
807
+	 * @return int/boolean current transaction-id, of false if no connection
808
+	 */
809 809
 	function transaction_begin()
810 810
 	{
811 811
 		if (!$this->Link_ID && !$this->connect())
@@ -817,10 +817,10 @@  discard block
 block discarded – undo
817 817
 	}
818 818
 
819 819
 	/**
820
-	* Complete the transaction
821
-	*
822
-	* @return bool True if sucessful, False if fails
823
-	*/
820
+	 * Complete the transaction
821
+	 *
822
+	 * @return bool True if sucessful, False if fails
823
+	 */
824 824
 	function transaction_commit()
825 825
 	{
826 826
 		if (!$this->Link_ID && !$this->connect())
@@ -832,10 +832,10 @@  discard block
 block discarded – undo
832 832
 	}
833 833
 
834 834
 	/**
835
-	* Rollback the current transaction
836
-	*
837
-	* @return bool True if sucessful, False if fails
838
-	*/
835
+	 * Rollback the current transaction
836
+	 *
837
+	 * @return bool True if sucessful, False if fails
838
+	 */
839 839
 	function transaction_abort()
840 840
 	{
841 841
 		if (!$this->Link_ID && !$this->connect())
@@ -847,12 +847,12 @@  discard block
 block discarded – undo
847 847
 	}
848 848
 
849 849
 	/**
850
-	* Find the primary key of the last insertion on the current db connection
851
-	*
852
-	* @param string $table name of table the insert was performed on
853
-	* @param string $field the autoincrement primary key of the table
854
-	* @return int the id, -1 if fails
855
-	*/
850
+	 * Find the primary key of the last insertion on the current db connection
851
+	 *
852
+	 * @param string $table name of table the insert was performed on
853
+	 * @param string $field the autoincrement primary key of the table
854
+	 * @return int the id, -1 if fails
855
+	 */
856 856
 	function get_last_insert_id($table, $field)
857 857
 	{
858 858
 		if (!$this->Link_ID && !$this->connect())
@@ -875,10 +875,10 @@  discard block
 block discarded – undo
875 875
 	}
876 876
 
877 877
 	/**
878
-	* Get the number of rows affected by last update or delete
879
-	*
880
-	* @return int number of rows
881
-	*/
878
+	 * Get the number of rows affected by last update or delete
879
+	 *
880
+	 * @return int number of rows
881
+	 */
882 882
 	function affected_rows()
883 883
 	{
884 884
 		if ($this->log_updates) return 0;
@@ -891,14 +891,14 @@  discard block
 block discarded – undo
891 891
 	}
892 892
 
893 893
 	/**
894
-	* Get description of a table
895
-	*
896
-	* Beside the column-name all other data depends on the db-type !!!
897
-	*
898
-	* @param string $table name of table to describe
899
-	* @param bool $full optional, default False summary information, True full information
900
-	* @return array table meta data
901
-	*/
894
+	 * Get description of a table
895
+	 *
896
+	 * Beside the column-name all other data depends on the db-type !!!
897
+	 *
898
+	 * @param string $table name of table to describe
899
+	 * @param bool $full optional, default False summary information, True full information
900
+	 * @return array table meta data
901
+	 */
902 902
 	function metadata($table='',$full=false)
903 903
 	{
904 904
 		if (!$this->Link_ID && !$this->connect())
@@ -980,10 +980,10 @@  discard block
 block discarded – undo
980 980
 	}
981 981
 
982 982
 	/**
983
-	* Return a list of indexes in current database
984
-	*
985
-	* @return array list of indexes
986
-	*/
983
+	 * Return a list of indexes in current database
984
+	 *
985
+	 * @return array list of indexes
986
+	 */
987 987
 	function index_names()
988 988
 	{
989 989
 		$indices = array();
@@ -1004,10 +1004,10 @@  discard block
 block discarded – undo
1004 1004
 	}
1005 1005
 
1006 1006
 	/**
1007
-	* Returns an array containing column names that are the primary keys of $tablename.
1008
-	*
1009
-	* @return array of columns
1010
-	*/
1007
+	 * Returns an array containing column names that are the primary keys of $tablename.
1008
+	 *
1009
+	 * @return array of columns
1010
+	 */
1011 1011
 	function pkey_columns($tablename)
1012 1012
 	{
1013 1013
 		if (!$this->Link_ID && !$this->connect())
@@ -1018,13 +1018,13 @@  discard block
 block discarded – undo
1018 1018
 	}
1019 1019
 
1020 1020
 	/**
1021
-	* Create a new database
1022
-	*
1023
-	* @param string $adminname name of database administrator user (optional)
1024
-	* @param string $adminpasswd password for the database administrator user (optional)
1025
-	* @param string $charset default charset for the database
1026
-	* @param string $grant_host ='localhost' host/ip of the webserver
1027
-	*/
1021
+	 * Create a new database
1022
+	 *
1023
+	 * @param string $adminname name of database administrator user (optional)
1024
+	 * @param string $adminpasswd password for the database administrator user (optional)
1025
+	 * @param string $charset default charset for the database
1026
+	 * @param string $grant_host ='localhost' host/ip of the webserver
1027
+	 */
1028 1028
 	function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost')
1029 1029
 	{
1030 1030
 		$currentUser = $this->User;
@@ -1280,12 +1280,12 @@  discard block
 block discarded – undo
1280 1280
 	}
1281 1281
 
1282 1282
 	/**
1283
-	* Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements
1284
-	*
1285
-	* This is mostly copy & paste from adodb's datadict class
1286
-	* @param string $_name
1287
-	* @return string quoted string
1288
-	*/
1283
+	 * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements
1284
+	 *
1285
+	 * This is mostly copy & paste from adodb's datadict class
1286
+	 * @param string $_name
1287
+	 * @return string quoted string
1288
+	 */
1289 1289
 	function name_quote($_name = NULL)
1290 1290
 	{
1291 1291
 		if (!is_string($_name))
@@ -1324,19 +1324,19 @@  discard block
 block discarded – undo
1324 1324
 	}
1325 1325
 
1326 1326
 	/**
1327
-	* Escape values before sending them to the database - prevents SQL injection and SQL errors ;-)
1328
-	*
1329
-	* Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'".
1330
-	* Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0
1331
-	* Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'"
1332
-	*
1333
-	* @param mixed $value the value to be escaped
1334
-	* @param string|boolean $type =false string the type of the db-column, default False === varchar
1335
-	* @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL
1336
-	* @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres)
1337
-	* @param string $glue =',' used to glue array values together for the string type
1338
-	* @return string escaped sting
1339
-	*/
1327
+	 * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-)
1328
+	 *
1329
+	 * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'".
1330
+	 * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0
1331
+	 * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'"
1332
+	 *
1333
+	 * @param mixed $value the value to be escaped
1334
+	 * @param string|boolean $type =false string the type of the db-column, default False === varchar
1335
+	 * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL
1336
+	 * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres)
1337
+	 * @param string $glue =',' used to glue array values together for the string type
1338
+	 * @return string escaped sting
1339
+	 */
1340 1340
 	function quote($value,$type=False,$not_null=true,$length=null,$glue=',')
1341 1341
 	{
1342 1342
 		if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n";
@@ -1417,27 +1417,27 @@  discard block
 block discarded – undo
1417 1417
 	}
1418 1418
 
1419 1419
 	/**
1420
-	* Implodes an array of column-value pairs for the use in sql-querys.
1421
-	* All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-).
1422
-	*
1423
-	* @author RalfBecker<at>outdoor-training.de
1424
-	*
1425
-	* @param string $glue in most cases this will be either ',' or ' AND ', depending you your query
1426
-	* @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted
1427
-	*	according to the type of the column, and the whole array with be formatted like (val1,val2,...)
1428
-	*	If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists.
1429
-	*	If the key is numerical (no key given in the array-definition) the value is used as is, eg.
1430
-	*	array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!)
1431
-	* @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False
1432
-	*	or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned
1433
-	* @param array|boolean $only if set to an array only colums which are set (as data !!!) are written
1434
-	*	typicaly used to form a WHERE-clause from the primary keys.
1435
-	*	If set to True, only columns from the colum_definitons are written.
1436
-	* @param array|boolean $column_definitions this can be set to the column-definitions-array
1437
-	*	of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file).
1438
-	*	If its set, the column-type-data determinates if (int) or addslashes is used.
1439
-	* @return string SQL
1440
-	*/
1420
+	 * Implodes an array of column-value pairs for the use in sql-querys.
1421
+	 * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-).
1422
+	 *
1423
+	 * @author RalfBecker<at>outdoor-training.de
1424
+	 *
1425
+	 * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query
1426
+	 * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted
1427
+	 *	according to the type of the column, and the whole array with be formatted like (val1,val2,...)
1428
+	 *	If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists.
1429
+	 *	If the key is numerical (no key given in the array-definition) the value is used as is, eg.
1430
+	 *	array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!)
1431
+	 * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False
1432
+	 *	or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned
1433
+	 * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written
1434
+	 *	typicaly used to form a WHERE-clause from the primary keys.
1435
+	 *	If set to True, only columns from the colum_definitons are written.
1436
+	 * @param array|boolean $column_definitions this can be set to the column-definitions-array
1437
+	 *	of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file).
1438
+	 *	If its set, the column-type-data determinates if (int) or addslashes is used.
1439
+	 * @return string SQL
1440
+	 */
1441 1441
 	function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False)
1442 1442
 	{
1443 1443
 		if (!is_array($array))	// this allows to give an SQL-string for delete or update
@@ -1523,14 +1523,14 @@  discard block
 block discarded – undo
1523 1523
 	}
1524 1524
 
1525 1525
 	/**
1526
-	* Sets the default column-definitions for use with column_data_implode()
1527
-	*
1528
-	* @author RalfBecker<at>outdoor-training.de
1529
-	*
1530
-	* @param array|boolean $column_definitions this can be set to the column-definitions-array
1531
-	*	of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file).
1532
-	*	If its set, the column-type-data determinates if (int) or addslashes is used.
1533
-	*/
1526
+	 * Sets the default column-definitions for use with column_data_implode()
1527
+	 *
1528
+	 * @author RalfBecker<at>outdoor-training.de
1529
+	 *
1530
+	 * @param array|boolean $column_definitions this can be set to the column-definitions-array
1531
+	 *	of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file).
1532
+	 *	If its set, the column-type-data determinates if (int) or addslashes is used.
1533
+	 */
1534 1534
 	function set_column_definitions($column_definitions=False)
1535 1535
 	{
1536 1536
 		$this->column_definitions=$column_definitions;
@@ -1570,17 +1570,17 @@  discard block
 block discarded – undo
1570 1570
 	}
1571 1571
 
1572 1572
 	/**
1573
-	* reads the table-definitions from the app's setup/tables_current.inc.php file
1574
-	*
1575
-	* The already read table-definitions are shared between all db-instances via a static var.
1576
-	*
1577
-	* @author RalfBecker<at>outdoor-training.de
1578
-	*
1579
-	* @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app,
1580
-	*	true to search the already loaded table-definitions for $table and then search all existing apps for it
1581
-	* @param bool|string $table if set return only defintions of that table, else return all defintions
1582
-	* @return mixed array with table-defintions or False if file not found
1583
-	*/
1573
+	 * reads the table-definitions from the app's setup/tables_current.inc.php file
1574
+	 *
1575
+	 * The already read table-definitions are shared between all db-instances via a static var.
1576
+	 *
1577
+	 * @author RalfBecker<at>outdoor-training.de
1578
+	 *
1579
+	 * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app,
1580
+	 *	true to search the already loaded table-definitions for $table and then search all existing apps for it
1581
+	 * @param bool|string $table if set return only defintions of that table, else return all defintions
1582
+	 * @return mixed array with table-defintions or False if file not found
1583
+	 */
1584 1584
 	function get_table_definitions($app=False,$table=False)
1585 1585
 	{
1586 1586
 		// ease the transition to api
@@ -1676,21 +1676,21 @@  discard block
 block discarded – undo
1676 1676
 	}
1677 1677
 
1678 1678
 	/**
1679
-	* Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type
1680
-	*
1681
-	* @author RalfBecker<at>outdoor-training.de
1682
-	*
1683
-	* @param string $table name of the table
1684
-	* @param array $data with column-name / value pairs
1685
-	* @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
1686
-	*	if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence)
1687
-	* @param int $line line-number to pass to query
1688
-	* @param string $file file-name to pass to query
1689
-	* @param string|boolean $app string with name of app or False to use the current-app
1690
-	* @param bool $use_prepared_statement use a prepared statement
1691
-	* @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1692
-	* @return ADORecordSet or false, if the query fails
1693
-	*/
1679
+	 * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type
1680
+	 *
1681
+	 * @author RalfBecker<at>outdoor-training.de
1682
+	 *
1683
+	 * @param string $table name of the table
1684
+	 * @param array $data with column-name / value pairs
1685
+	 * @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
1686
+	 *	if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence)
1687
+	 * @param int $line line-number to pass to query
1688
+	 * @param string $file file-name to pass to query
1689
+	 * @param string|boolean $app string with name of app or False to use the current-app
1690
+	 * @param bool $use_prepared_statement use a prepared statement
1691
+	 * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1692
+	 * @return ADORecordSet or false, if the query fails
1693
+	 */
1694 1694
 	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False)
1695 1695
 	{
1696 1696
 		if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n";
@@ -1786,20 +1786,20 @@  discard block
 block discarded – undo
1786 1786
 	}
1787 1787
 
1788 1788
 	/**
1789
-	* Updates the data of one or more rows in a table, all data is quoted according to it's type
1790
-	*
1791
-	* @author RalfBecker<at>outdoor-training.de
1792
-	*
1793
-	* @param string $table name of the table
1794
-	* @param array $data with column-name / value pairs
1795
-	* @param array $where column-name / values pairs and'ed together for the where clause
1796
-	* @param int $line line-number to pass to query
1797
-	* @param string $file file-name to pass to query
1798
-	* @param string|boolean $app string with name of app or False to use the current-app
1799
-	* @param bool $use_prepared_statement use a prepared statement
1800
-	* @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1801
-	* @return ADORecordSet or false, if the query fails
1802
-	*/
1789
+	 * Updates the data of one or more rows in a table, all data is quoted according to it's type
1790
+	 *
1791
+	 * @author RalfBecker<at>outdoor-training.de
1792
+	 *
1793
+	 * @param string $table name of the table
1794
+	 * @param array $data with column-name / value pairs
1795
+	 * @param array $where column-name / values pairs and'ed together for the where clause
1796
+	 * @param int $line line-number to pass to query
1797
+	 * @param string $file file-name to pass to query
1798
+	 * @param string|boolean $app string with name of app or False to use the current-app
1799
+	 * @param bool $use_prepared_statement use a prepared statement
1800
+	 * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1801
+	 * @return ADORecordSet or false, if the query fails
1802
+	 */
1803 1803
 	function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False)
1804 1804
 	{
1805 1805
 		if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n";
@@ -1876,18 +1876,18 @@  discard block
 block discarded – undo
1876 1876
 	}
1877 1877
 
1878 1878
 	/**
1879
-	* Deletes one or more rows in table, all data is quoted according to it's type
1880
-	*
1881
-	* @author RalfBecker<at>outdoor-training.de
1882
-	*
1883
-	* @param string $table name of the table
1884
-	* @param array $where column-name / values pairs and'ed together for the where clause
1885
-	* @param int $line line-number to pass to query
1886
-	* @param string $file file-name to pass to query
1887
-	* @param string|boolean $app string with name of app or False to use the current-app
1888
-	* @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1889
-	* @return ADORecordSet or false, if the query fails
1890
-	*/
1879
+	 * Deletes one or more rows in table, all data is quoted according to it's type
1880
+	 *
1881
+	 * @author RalfBecker<at>outdoor-training.de
1882
+	 *
1883
+	 * @param string $table name of the table
1884
+	 * @param array $where column-name / values pairs and'ed together for the where clause
1885
+	 * @param int $line line-number to pass to query
1886
+	 * @param string $file file-name to pass to query
1887
+	 * @param string|boolean $app string with name of app or False to use the current-app
1888
+	 * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1889
+	 * @return ADORecordSet or false, if the query fails
1890
+	 */
1891 1891
 	function delete($table,$where,$line,$file,$app=False,$table_def=False)
1892 1892
 	{
1893 1893
 		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
@@ -1953,25 +1953,25 @@  discard block
 block discarded – undo
1953 1953
 	}
1954 1954
 
1955 1955
 	/**
1956
-	* Selects one or more rows in table depending on where, all data is quoted according to it's type
1957
-	*
1958
-	* @author RalfBecker<at>outdoor-training.de
1959
-	*
1960
-	* @param string $table name of the table
1961
-	* @param array|string $cols string or array of column-names / select-expressions
1962
-	* @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause
1963
-	* @param int $line line-number to pass to query
1964
-	* @param string $file file-name to pass to query
1965
-	* @param int|bool $offset offset for a limited query or False (default)
1966
-	* @param string $append string to append to the end of the query, eg. ORDER BY ...
1967
-	* @param string|boolean $app string with name of app or False to use the current-app
1968
-	* @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs
1969
-	* @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
1970
-	*	"LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join!
1971
-	* @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1972
-	* @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM
1973
-	* @return ADORecordSet or false, if the query fails
1974
-	*/
1956
+	 * Selects one or more rows in table depending on where, all data is quoted according to it's type
1957
+	 *
1958
+	 * @author RalfBecker<at>outdoor-training.de
1959
+	 *
1960
+	 * @param string $table name of the table
1961
+	 * @param array|string $cols string or array of column-names / select-expressions
1962
+	 * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause
1963
+	 * @param int $line line-number to pass to query
1964
+	 * @param string $file file-name to pass to query
1965
+	 * @param int|bool $offset offset for a limited query or False (default)
1966
+	 * @param string $append string to append to the end of the query, eg. ORDER BY ...
1967
+	 * @param string|boolean $app string with name of app or False to use the current-app
1968
+	 * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs
1969
+	 * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
1970
+	 *	"LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join!
1971
+	 * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1972
+	 * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM
1973
+	 * @return ADORecordSet or false, if the query fails
1974
+	 */
1975 1975
 	function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC)
1976 1976
 	{
1977 1977
 		if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n";
@@ -2006,20 +2006,20 @@  discard block
 block discarded – undo
2006 2006
 	}
2007 2007
 
2008 2008
 	/**
2009
-	* Does a union over multiple selects
2010
-	*
2011
-	* @author RalfBecker<at>outdoor-training.de
2012
-	*
2013
-	* @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def
2014
-	*	For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional
2015
-	* @param int $line line-number to pass to query
2016
-	* @param string $file file-name to pass to query
2017
-	* @param string $order_by ORDER BY statement for the union
2018
-	* @param int|bool $offset offset for a limited query or False (default)
2019
-	* @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs
2020
-	* @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM
2021
-	* @return ADORecordSet or false, if the query fails
2022
-	*/
2009
+	 * Does a union over multiple selects
2010
+	 *
2011
+	 * @author RalfBecker<at>outdoor-training.de
2012
+	 *
2013
+	 * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def
2014
+	 *	For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional
2015
+	 * @param int $line line-number to pass to query
2016
+	 * @param string $file file-name to pass to query
2017
+	 * @param string $order_by ORDER BY statement for the union
2018
+	 * @param int|bool $offset offset for a limited query or False (default)
2019
+	 * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs
2020
+	 * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM
2021
+	 * @return ADORecordSet or false, if the query fails
2022
+	 */
2023 2023
 	function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC)
2024 2024
 	{
2025 2025
 		if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n";
Please login to merge, or discard this patch.
Braces   +244 added lines, -61 removed lines patch added patch discarded remove patch
@@ -383,7 +383,10 @@  discard block
 block discarded – undo
383 383
 			if ($state['wsrep_local_state_comment'] == 'Synced' ||
384 384
 				// if we have only 2 nodes (2. one starting), we can only use the donor
385 385
 				$state['wsrep_local_state_comment'] == 'Donor/Desynced' &&
386
-					$state['wsrep_cluster_size'] == 2) return;
386
+					$state['wsrep_cluster_size'] == 2)
387
+			{
388
+				return;
389
+			}
387 390
 
388 391
 			throw new Db\Exception\Connection('Node is NOT Synced! '.array2string($state));
389 392
 		}
@@ -402,7 +405,10 @@  discard block
 block discarded – undo
402 405
 		$hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host);
403 406
 		$num_hosts = count($hosts);
404 407
 		$n =& Cache::getSession(__CLASS__, $this->Host);
405
-		if (!isset($n)) $n = 0;
408
+		if (!isset($n))
409
+		{
410
+			$n = 0;
411
+		}
406 412
 
407 413
 		if ($next && ++$n >= $num_hosts+2)
408 414
 		{
@@ -432,7 +438,10 @@  discard block
 block discarded – undo
432 438
 			foreach(array('Database','User','Password','Port','Type') as $name)
433 439
 			{
434 440
 				$$name = $this->$name;
435
-				if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1));
441
+				if (${$name}[0] == '@' && $name != 'Password')
442
+				{
443
+					$$name = getenv(substr($$name, 1));
444
+				}
436 445
 			}
437 446
 			$this->setupType = $php_extension = $Type;
438 447
 
@@ -451,7 +460,10 @@  discard block
 block discarded – undo
451 460
 					$Type = 'mssql';
452 461
 					// fall through
453 462
 				case 'mssql':
454
-					if ($Port) $Host .= ','.$Port;
463
+					if ($Port)
464
+					{
465
+						$Host .= ','.$Port;
466
+					}
455 467
 					break;
456 468
 
457 469
 				case 'odbc_oracle':
@@ -486,7 +498,10 @@  discard block
 block discarded – undo
486 498
 					$this->Type = 'mysql';		// need to be "mysql", so apps can check just for "mysql"!
487 499
 					// fall through
488 500
 				default:
489
-					if ($Port) $Host .= ':'.$Port;
501
+					if ($Port)
502
+					{
503
+						$Host .= ':'.$Port;
504
+					}
490 505
 					break;
491 506
 			}
492 507
 			if (!isset($GLOBALS['egw']->ADOdb) ||	// we have no connection so far
@@ -501,10 +516,13 @@  discard block
 block discarded – undo
501 516
 				{
502 517
 					throw new Db\Exception\Connection("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!");
503 518
 				}
504
-				if (!isset($GLOBALS['egw']->ADOdb))	// use the global object to store the connection
519
+				if (!isset($GLOBALS['egw']->ADOdb))
520
+				{
521
+					// use the global object to store the connection
505 522
 				{
506 523
 					$this->Link_ID =& $GLOBALS['egw']->ADOdb;
507 524
 				}
525
+				}
508 526
 				else
509 527
 				{
510 528
 					$this->privat_Link_ID = True;	// remember that we use a privat Link_ID for disconnect
@@ -600,7 +618,11 @@  discard block
 block discarded – undo
600 618
 	 */
601 619
 	function __sleep()
602 620
 	{
603
-		if (!empty($this->setupType)) $this->Type = $this->setupType;	// restore Type eg. to mysqli
621
+		if (!empty($this->setupType))
622
+		{
623
+			$this->Type = $this->setupType;
624
+		}
625
+		// restore Type eg. to mysqli
604 626
 
605 627
 		$vars = get_object_vars($this);
606 628
 		unset($vars['Link_ID']);
@@ -663,7 +685,10 @@  discard block
 block discarded – undo
663 685
 		unset($this->Link_ID);
664 686
 		$this->Link_ID = 0;
665 687
 
666
-		if (!empty($this->setupType)) $this->Type = $this->setupType;
688
+		if (!empty($this->setupType))
689
+		{
690
+			$this->Type = $this->setupType;
691
+		}
667 692
 	}
668 693
 
669 694
 	/**
@@ -772,16 +797,22 @@  discard block
 block discarded – undo
772 797
 		}
773 798
 		if (!$rs)
774 799
 		{
775
-			if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006)	// Server has gone away
800
+			if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006)
801
+			{
802
+				// Server has gone away
776 803
 			{
777 804
 				$this->disconnect();
805
+			}
778 806
 				return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false);
779 807
 			}
780 808
 			throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String).
781 809
 				"\n$this->Error ($this->Errno)".
782 810
 				($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno);
783 811
 		}
784
-		elseif(empty($rs->sql)) $rs->sql = $Query_String;
812
+		elseif(empty($rs->sql))
813
+		{
814
+			$rs->sql = $Query_String;
815
+		}
785 816
 		return $rs;
786 817
 	}
787 818
 
@@ -865,9 +896,12 @@  discard block
 block discarded – undo
865 896
 		}
866 897
 		$id = $this->Link_ID->PO_Insert_ID($table,$field);	// simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible
867 898
 
868
-		if ($id === False)	// function not supported
899
+		if ($id === False)
900
+		{
901
+			// function not supported
869 902
 		{
870 903
 			echo "<p>db::get_last_insert_id(table='$table',field='$field') not yet implemented for db-type '$this->Type' OR no insert operation before</p>\n";
904
+		}
871 905
 			echo '<p>'.function_backtrace()."</p>\n";
872 906
 			return -1;
873 907
 		}
@@ -881,7 +915,10 @@  discard block
 block discarded – undo
881 915
 	*/
882 916
 	function affected_rows()
883 917
 	{
884
-		if ($this->log_updates) return 0;
918
+		if ($this->log_updates)
919
+		{
920
+			return 0;
921
+		}
885 922
 
886 923
 		if (!$this->Link_ID && !$this->connect())
887 924
 		{
@@ -915,9 +952,18 @@  discard block
 block discarded – undo
915 952
 		{
916 953
 			// for backwards compatibilty (depreciated)
917 954
 			$flags = null;
918
-			if($column->auto_increment) $flags .= "auto_increment ";
919
-			if($column->primary_key) $flags .= "primary_key ";
920
-			if($column->binary) $flags .= "binary ";
955
+			if($column->auto_increment)
956
+			{
957
+				$flags .= "auto_increment ";
958
+			}
959
+			if($column->primary_key)
960
+			{
961
+				$flags .= "primary_key ";
962
+			}
963
+			if($column->binary)
964
+			{
965
+				$flags .= "binary ";
966
+			}
921 967
 
922 968
 			$metadata[$i] = array(
923 969
 				'table' => $table,
@@ -954,7 +1000,10 @@  discard block
 block discarded – undo
954 1000
 	 */
955 1001
 	function table_names($just_name=false)
956 1002
 	{
957
-		if (!$this->Link_ID) $this->connect();
1003
+		if (!$this->Link_ID)
1004
+		{
1005
+			$this->connect();
1006
+		}
958 1007
 		if (!$this->Link_ID)
959 1008
 		{
960 1009
 			return False;
@@ -1105,8 +1154,14 @@  discard block
 block discarded – undo
1105 1154
 		{
1106 1155
 			case 'mysql':
1107 1156
 				$sql = 'GROUP_CONCAT('.$expr;
1108
-				if ($order_by) $sql .= ' ORDER BY '.$order_by;
1109
-				if ($separator != ',') $sql .= ' SEPARATOR '.$this->quote($separator);
1157
+				if ($order_by)
1158
+				{
1159
+					$sql .= ' ORDER BY '.$order_by;
1160
+				}
1161
+				if ($separator != ',')
1162
+				{
1163
+					$sql .= ' SEPARATOR '.$this->quote($separator);
1164
+				}
1110 1165
 				$sql .= ')';
1111 1166
 				break;
1112 1167
 
@@ -1116,7 +1171,10 @@  discard block
 block discarded – undo
1116 1171
 					return false;
1117 1172
 				}
1118 1173
 				$sql = 'ARRAY_TO_STRING(ARRAY_AGG('.$expr;
1119
-				if ($order_by) $sql .= ' ORDER BY '.$order_by;
1174
+				if ($order_by)
1175
+				{
1176
+					$sql .= ' ORDER BY '.$order_by;
1177
+				}
1120 1178
 				$sql .= '), '.$this->quote($separator).')';
1121 1179
 				break;
1122 1180
 
@@ -1339,12 +1397,18 @@  discard block
 block discarded – undo
1339 1397
 	*/
1340 1398
 	function quote($value,$type=False,$not_null=true,$length=null,$glue=',')
1341 1399
 	{
1342
-		if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n";
1400
+		if ($this->Debug)
1401
+		{
1402
+			echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n";
1403
+		}
1343 1404
 
1344
-		if (!$not_null && is_null($value))	// writing unset php-variables and those set to NULL now as SQL NULL
1405
+		if (!$not_null && is_null($value))
1406
+		{
1407
+			// writing unset php-variables and those set to NULL now as SQL NULL
1345 1408
 		{
1346 1409
 			return 'NULL';
1347 1410
 		}
1411
+		}
1348 1412
 		switch($type)
1349 1413
 		{
1350 1414
 			case 'int':
@@ -1359,10 +1423,13 @@  discard block
 block discarded – undo
1359 1423
 				// There for we have to keep it as float by using round instead the int cast.
1360 1424
 				return is_float($value) ? round($value) : (int) $value;
1361 1425
 			case 'bool':
1362
-				if ($this->Type == 'mysql')		// maybe it's not longer necessary with mysql5
1426
+				if ($this->Type == 'mysql')
1427
+				{
1428
+					// maybe it's not longer necessary with mysql5
1363 1429
 				{
1364 1430
 					return $value ? 1 : 0;
1365 1431
 				}
1432
+				}
1366 1433
 				return $value ? 'true' : 'false';
1367 1434
 			case 'float':
1368 1435
 			case 'decimal':
@@ -1410,7 +1477,10 @@  discard block
 block discarded – undo
1410 1477
 		}
1411 1478
 		// casting boolean explicitly to string, as ADODB_postgres64::qstr() has an unwanted special handling
1412 1479
 		// for boolean types, causing it to return "true" or "false" and not a quoted string like "'1'"!
1413
-		if (is_bool($value)) $value = (string)$value;
1480
+		if (is_bool($value))
1481
+		{
1482
+			$value = (string)$value;
1483
+		}
1414 1484
 
1415 1485
 		// need to cast to string, as ADOdb 5.20 would return NULL instead of '' for NULL, causing us to write that into NOT NULL columns
1416 1486
 		return $this->Link_ID->qstr((string)$value);
@@ -1440,15 +1510,21 @@  discard block
 block discarded – undo
1440 1510
 	*/
1441 1511
 	function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False)
1442 1512
 	{
1443
-		if (!is_array($array))	// this allows to give an SQL-string for delete or update
1513
+		if (!is_array($array))
1514
+		{
1515
+			// this allows to give an SQL-string for delete or update
1444 1516
 		{
1445 1517
 			return $array;
1446 1518
 		}
1519
+		}
1447 1520
 		if (!$column_definitions)
1448 1521
 		{
1449 1522
 			$column_definitions = $this->column_definitions;
1450 1523
 		}
1451
-		if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n";
1524
+		if ($this->Debug)
1525
+		{
1526
+			echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n";
1527
+		}
1452 1528
 
1453 1529
 		// do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres)
1454 1530
 		$truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR];
@@ -1465,7 +1541,10 @@  discard block
 block discarded – undo
1465 1541
 				// fix "table.column" expressions, to not trigger exception, if column alone would work
1466 1542
 				if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key]))
1467 1543
 				{
1468
-					if (strpos($key, '.') !== false) list(, $col) = explode('.', $key);
1544
+					if (strpos($key, '.') !== false)
1545
+					{
1546
+						list(, $col) = explode('.', $key);
1547
+					}
1469 1548
 					if (!isset($column_definitions[$col]))
1470 1549
 					{
1471 1550
 						throw new Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>");
@@ -1505,7 +1584,11 @@  discard block
 block discarded – undo
1505 1584
 				}
1506 1585
 				elseif (is_int($key) && $use_key===True)
1507 1586
 				{
1508
-					if (empty($data)) continue;	// would give SQL error
1587
+					if (empty($data))
1588
+					{
1589
+						continue;
1590
+					}
1591
+					// would give SQL error
1509 1592
 					$values[] = $data;
1510 1593
 				}
1511 1594
 				elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data))
@@ -1559,7 +1642,10 @@  discard block
 block discarded – undo
1559 1642
 	function set_app($app)
1560 1643
 	{
1561 1644
 		// ease the transition to api
1562
-		if ($app == 'phpgwapi') $app = 'api';
1645
+		if ($app == 'phpgwapi')
1646
+		{
1647
+			$app = 'api';
1648
+		}
1563 1649
 
1564 1650
 		if ($this === $GLOBALS['egw']->db && $app != self::API_APPNAME)
1565 1651
 		{
@@ -1584,7 +1670,10 @@  discard block
 block discarded – undo
1584 1670
 	function get_table_definitions($app=False,$table=False)
1585 1671
 	{
1586 1672
 		// ease the transition to api
1587
-		if ($app === 'phpgwapi') $app = 'api';
1673
+		if ($app === 'phpgwapi')
1674
+		{
1675
+			$app = 'api';
1676
+		}
1588 1677
 
1589 1678
 		static $all_app_data = array();
1590 1679
 		if ($app === true && $table)
@@ -1642,10 +1731,16 @@  discard block
 block discarded – undo
1642 1731
 		}
1643 1732
 		if ($table && (!$app_data || !isset($app_data[$table])))
1644 1733
 		{
1645
-			if ($this->Debug) echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n";
1734
+			if ($this->Debug)
1735
+			{
1736
+				echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n";
1737
+			}
1646 1738
 			return False;
1647 1739
 		}
1648
-		if ($this->Debug) echo "<p>get_table_definitions($app,$table) succeeded</p>\n";
1740
+		if ($this->Debug)
1741
+		{
1742
+			echo "<p>get_table_definitions($app,$table) succeeded</p>\n";
1743
+		}
1649 1744
 		return $table ? $app_data[$table] : $app_data;
1650 1745
 	}
1651 1746
 
@@ -1670,7 +1765,10 @@  discard block
 block discarded – undo
1670 1765
 			$table_def = $db->get_table_definitions($app,$table);
1671 1766
 			$cached_columns = is_array($table_def) ? $table_def['fd'] : false;
1672 1767
 		}
1673
-		if ($cached_columns === false) return null;
1768
+		if ($cached_columns === false)
1769
+		{
1770
+			return null;
1771
+		}
1674 1772
 
1675 1773
 		return is_null($attribute) ? $cached_columns[$column] : $cached_columns[$column][$attribute];
1676 1774
 	}
@@ -1693,9 +1791,15 @@  discard block
 block discarded – undo
1693 1791
 	*/
1694 1792
 	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False)
1695 1793
 	{
1696
-		if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n";
1794
+		if ($this->Debug)
1795
+		{
1796
+			echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n";
1797
+		}
1697 1798
 
1698
-		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
1799
+		if (!$table_def)
1800
+		{
1801
+			$table_def = $this->get_table_definitions($app,$table);
1802
+		}
1699 1803
 
1700 1804
 		$sql_append = '';
1701 1805
 		$cmd = 'INSERT';
@@ -1737,9 +1841,12 @@  discard block
 block discarded – undo
1737 1841
 			$table = self::$tablealiases[$table];
1738 1842
 		}
1739 1843
 		$inputarr = false;
1740
-		if (isset($data[0]) && is_array($data[0]))	// multiple data rows
1844
+		if (isset($data[0]) && is_array($data[0]))
1845
+		{
1846
+			// multiple data rows
1741 1847
 		{
1742 1848
 			if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!');
1849
+		}
1743 1850
 
1744 1851
 			$sql = "$cmd INTO $table ";
1745 1852
 			foreach($data as $k => $d)
@@ -1755,15 +1862,22 @@  discard block
 block discarded – undo
1755 1862
 			}
1756 1863
 			$sql .= $sql_append;
1757 1864
 		}
1758
-		elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray)	// eg. MaxDB
1865
+		elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray)
1759 1866
 		{
1760
-			$this->Link_ID->Param(false);	// reset param-counter
1867
+			// eg. MaxDB
1868
+		{
1869
+			$this->Link_ID->Param(false);
1870
+		}
1871
+		// reset param-counter
1761 1872
 			$cols = array_keys($data);
1762 1873
 			foreach($cols as $k => $col)
1763 1874
 			{
1764
-				if (!isset($table_def['fd'][$col]))	// ignore columns not in this table
1875
+				if (!isset($table_def['fd'][$col]))
1876
+				{
1877
+					// ignore columns not in this table
1765 1878
 				{
1766 1879
 					unset($cols[$k]);
1880
+				}
1767 1881
 					continue;
1768 1882
 				}
1769 1883
 				$params[] = $this->Link_ID->Param($col);
@@ -1781,7 +1895,10 @@  discard block
 block discarded – undo
1781 1895
 		{
1782 1896
 			$sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append;
1783 1897
 		}
1784
-		if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n";
1898
+		if ($this->Debug)
1899
+		{
1900
+			echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n";
1901
+		}
1785 1902
 		return $this->query($sql,$line,$file,0,-1,$inputarr);
1786 1903
 	}
1787 1904
 
@@ -1802,8 +1919,14 @@  discard block
 block discarded – undo
1802 1919
 	*/
1803 1920
 	function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False)
1804 1921
 	{
1805
-		if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n";
1806
-		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
1922
+		if ($this->Debug)
1923
+		{
1924
+			echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n";
1925
+		}
1926
+		if (!$table_def)
1927
+		{
1928
+			$table_def = $this->get_table_definitions($app,$table);
1929
+		}
1807 1930
 
1808 1931
 		$blobs2update = array();
1809 1932
 		// SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update
@@ -1812,7 +1935,10 @@  discard block
 block discarded – undo
1812 1935
 		{
1813 1936
 			case 'sapdb':
1814 1937
 			case 'maxdb':
1815
-				if ($use_prepared_statement) break;
1938
+				if ($use_prepared_statement)
1939
+				{
1940
+					break;
1941
+				}
1816 1942
 				// check if data contains any LONG columns
1817 1943
 				foreach($data as $col => $val)
1818 1944
 				{
@@ -1837,12 +1963,20 @@  discard block
 block discarded – undo
1837 1963
 		if (count($data))
1838 1964
 		{
1839 1965
 			$inputarr = false;
1840
-			if ($use_prepared_statement && $this->Link_ID->_bindInputArray)	// eg. MaxDB
1966
+			if ($use_prepared_statement && $this->Link_ID->_bindInputArray)
1967
+			{
1968
+				// eg. MaxDB
1841 1969
 			{
1842
-				$this->Link_ID->Param(false);	// reset param-counter
1970
+				$this->Link_ID->Param(false);
1971
+			}
1972
+			// reset param-counter
1843 1973
 				foreach($data as $col => $val)
1844 1974
 				{
1845
-					if (!isset($table_def['fd'][$col])) continue;	// ignore columns not in this table
1975
+					if (!isset($table_def['fd'][$col]))
1976
+					{
1977
+						continue;
1978
+					}
1979
+					// ignore columns not in this table
1846 1980
 					$params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col);
1847 1981
 				}
1848 1982
 				$sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str;
@@ -1860,7 +1994,10 @@  discard block
 block discarded – undo
1860 1994
 					$this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str;
1861 1995
 			}
1862 1996
 			$ret = $this->query($sql,$line,$file,0,-1,$inputarr);
1863
-			if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n";
1997
+			if ($this->Debug)
1998
+			{
1999
+				echo "<p>db::query('$sql',$line,$file)</p>\n";
2000
+			}
1864 2001
 		}
1865 2002
 		// if we have any blobs to update, we do so now
1866 2003
 		if (($ret || !count($data)) && count($blobs2update))
@@ -1868,8 +2005,14 @@  discard block
 block discarded – undo
1868 2005
 			foreach($blobs2update as $col => $val)
1869 2006
 			{
1870 2007
 				$ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB');
1871
-				if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n";
1872
-				if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file);
2008
+				if ($this->Debug)
2009
+				{
2010
+					echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n";
2011
+				}
2012
+				if (!$ret)
2013
+				{
2014
+					throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file);
2015
+				}
1873 2016
 			}
1874 2017
 		}
1875 2018
 		return $ret;
@@ -1890,7 +2033,10 @@  discard block
 block discarded – undo
1890 2033
 	*/
1891 2034
 	function delete($table,$where,$line,$file,$app=False,$table_def=False)
1892 2035
 	{
1893
-		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
2036
+		if (!$table_def)
2037
+		{
2038
+			$table_def = $this->get_table_definitions($app,$table);
2039
+		}
1894 2040
 
1895 2041
 		if (self::$tablealiases && isset(self::$tablealiases[$table]))
1896 2042
 		{
@@ -1922,19 +2068,29 @@  discard block
 block discarded – undo
1922 2068
 	 */
1923 2069
 	function expression($table_def/*,$args, ...*/)
1924 2070
 	{
1925
-		if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def);
2071
+		if (!is_array($table_def))
2072
+		{
2073
+			$table_def = $this->get_table_definitions(true,$table_def);
2074
+		}
1926 2075
 		$sql = '';
1927 2076
 		$ignore_next = 0;
1928 2077
 		foreach(func_get_args() as $n => $arg)
1929 2078
 		{
1930
-			if ($n < 1) continue;	// table-name
2079
+			if ($n < 1)
2080
+			{
2081
+				continue;
2082
+			}
2083
+			// table-name
1931 2084
 
1932 2085
 			if ($ignore_next)
1933 2086
 			{
1934 2087
 				--$ignore_next;
1935 2088
 				continue;
1936 2089
 			}
1937
-			if (is_null($arg)) $arg = False;
2090
+			if (is_null($arg))
2091
+			{
2092
+				$arg = False;
2093
+			}
1938 2094
 
1939 2095
 			switch(gettype($arg))
1940 2096
 			{
@@ -1974,9 +2130,15 @@  discard block
 block discarded – undo
1974 2130
 	*/
1975 2131
 	function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC)
1976 2132
 	{
1977
-		if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n";
2133
+		if ($this->Debug)
2134
+		{
2135
+			echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n";
2136
+		}
1978 2137
 
1979
-		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
2138
+		if (!$table_def)
2139
+		{
2140
+			$table_def = $this->get_table_definitions($app,$table);
2141
+		}
1980 2142
 		if (is_array($cols))
1981 2143
 		{
1982 2144
 			$cols = implode(',',$cols);
@@ -1992,16 +2154,28 @@  discard block
 block discarded – undo
1992 2154
 		$sql = "SELECT $cols FROM $table $join";
1993 2155
 
1994 2156
 		// if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join
1995
-		if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where;
2157
+		if ($where)
2158
+		{
2159
+			$sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where;
2160
+		}
1996 2161
 
1997
-		if ($append) $sql .= ' '.$append;
2162
+		if ($append)
2163
+		{
2164
+			$sql .= ' '.$append;
2165
+		}
1998 2166
 
1999
-		if ($this->Debug) echo "<p>sql='$sql'</p>";
2167
+		if ($this->Debug)
2168
+		{
2169
+			echo "<p>sql='$sql'</p>";
2170
+		}
2000 2171
 
2001
-		if ($line === false && $file === false)	// call by union, to return the sql rather then run the query
2172
+		if ($line === false && $file === false)
2173
+		{
2174
+			// call by union, to return the sql rather then run the query
2002 2175
 		{
2003 2176
 			return $sql;
2004 2177
 		}
2178
+		}
2005 2179
 		return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode);
2006 2180
 	}
2007 2181
 
@@ -2022,7 +2196,10 @@  discard block
 block discarded – undo
2022 2196
 	*/
2023 2197
 	function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC)
2024 2198
 	{
2025
-		if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n";
2199
+		if ($this->Debug)
2200
+		{
2201
+			echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n";
2202
+		}
2026 2203
 
2027 2204
 		$union = array();
2028 2205
 		foreach($selects as $select)
@@ -2043,9 +2220,15 @@  discard block
 block discarded – undo
2043 2220
 		}
2044 2221
 		$sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6);
2045 2222
 
2046
-		if ($order_by) $sql .=  (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by;
2223
+		if ($order_by)
2224
+		{
2225
+			$sql .=  (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by;
2226
+		}
2047 2227
 
2048
-		if ($this->Debug) echo "<p>sql='$sql'</p>";
2228
+		if ($this->Debug)
2229
+		{
2230
+			echo "<p>sql='$sql'</p>";
2231
+		}
2049 2232
 
2050 2233
 		return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode);
2051 2234
 	}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1845,7 +1845,7 @@  discard block
 block discarded – undo
1845 1845
 					if (!isset($table_def['fd'][$col])) continue;	// ignore columns not in this table
1846 1846
 					$params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col);
1847 1847
 				}
1848
-				$sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str;
1848
+				$sql = "update $table SET ".implode(',',$params).' WHERE '.$where_str;
1849 1849
 				// check if we already prepared that statement
1850 1850
 				if (!isset($this->prepared_sql[$sql]))
1851 1851
 				{
@@ -1856,7 +1856,7 @@  discard block
 block discarded – undo
1856 1856
 			}
1857 1857
 			else
1858 1858
 			{
1859
-				$sql = "UPDATE $table SET ".
1859
+				$sql = "update $table SET ".
1860 1860
 					$this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str;
1861 1861
 			}
1862 1862
 			$ret = $this->query($sql,$line,$file,0,-1,$inputarr);
@@ -1989,7 +1989,7 @@  discard block
 block discarded – undo
1989 1989
 		{
1990 1990
 			$table = self::$tablealiases[$table];
1991 1991
 		}
1992
-		$sql = "SELECT $cols FROM $table $join";
1992
+		$sql = "select $cols FROM $table $join";
1993 1993
 
1994 1994
 		// if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join
1995 1995
 		if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where;
Please login to merge, or discard this patch.
Spacing   +201 added lines, -202 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 namespace EGroupware\Api;
15 15
 
16
-if(empty($GLOBALS['egw_info']['server']['db_type']))
16
+if (empty($GLOBALS['egw_info']['server']['db_type']))
17 17
 {
18 18
 	$GLOBALS['egw_info']['server']['db_type'] = 'mysql';
19 19
 }
@@ -69,22 +69,22 @@  discard block
 block discarded – undo
69 69
 	/**
70 70
 	* @var string $type translated database type: mysqlt+mysqli ==> mysql, same for odbc-types
71 71
 	*/
72
-	var $Type     = '';
72
+	var $Type = '';
73 73
 
74 74
 	/**
75 75
 	* @var string $type database type as defined in the header.inc.php, eg. mysqlt
76 76
 	*/
77
-	var $setupType     = '';
77
+	var $setupType = '';
78 78
 
79 79
 	/**
80 80
 	* @var string $Host database host to connect to
81 81
 	*/
82
-	var $Host     = '';
82
+	var $Host = '';
83 83
 
84 84
 	/**
85 85
 	* @var string $Port port number of database to connect to
86 86
 	*/
87
-	var $Port     = '';
87
+	var $Port = '';
88 88
 
89 89
 	/**
90 90
 	* @var string $Database name of database to use
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	/**
95 95
 	* @var string $User name of database user
96 96
 	*/
97
-	var $User     = '';
97
+	var $User = '';
98 98
 
99 99
 	/**
100 100
 	* @var string $Password password for database user
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	/**
105 105
 	* @var int $Debug enable debuging - 0 no, 1 yes
106 106
 	*/
107
-	var $Debug         = 0;
107
+	var $Debug = 0;
108 108
 
109 109
 	/**
110 110
 	 * Log update querys to error_log, do not run them
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	/**
117 117
 	* @var array $Record current record
118 118
 	*/
119
-	var $Record   = array();
119
+	var $Record = array();
120 120
 
121 121
 	/**
122 122
 	* @var int row number for current record
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 	/**
127 127
 	* @var int $Errno internal rdms error number for last error
128 128
 	*/
129
-	var $Errno    = 0;
129
+	var $Errno = 0;
130 130
 
131 131
 	/**
132 132
 	* @var string descriptive text from last error
133 133
 	*/
134
-	var $Error    = '';
134
+	var $Error = '';
135 135
 
136 136
 	/**
137 137
 	 * eGW's own query log, independent of the db-type, eg. /tmp/query.log
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 *
152 152
 	 * @var ADOConnection
153 153
 	 */
154
-	var $privat_Link_ID = False;	// do we use a privat Link_ID or a reference to the global ADOdb object
154
+	var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object
155 155
 
156 156
 	/**
157 157
 	 * Can be used to transparently convert tablenames, eg. 'mytable' => 'otherdb.othertable'
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
 	/**
188 188
 	 * db is able to use DISTINCT on text or blob columns
189 189
 	 */
190
-	const CAPABILITY_DISTINCT_ON_TEXT =	'distinct_on_text';
190
+	const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text';
191 191
 	/**
192 192
 	 * DB is able to use LIKE on text columns
193 193
 	 */
194
-	const CAPABILITY_LIKE_ON_TEXT =	'like_on_text';
194
+	const CAPABILITY_LIKE_ON_TEXT = 'like_on_text';
195 195
 	/**
196 196
 	 * DB allows ORDER on text columns
197 197
 	 *
@@ -243,18 +243,18 @@  discard block
 block discarded – undo
243 243
 		self::CAPABILITY_CAST_AS_VARCHAR   => 'CAST(%s AS varchar)',
244 244
 	);
245 245
 
246
-	var $prepared_sql = array();	// sql is the index
246
+	var $prepared_sql = array(); // sql is the index
247 247
 
248 248
 	/**
249 249
 	 * Constructor
250 250
 	 *
251 251
 	 * @param array $db_data =null values for keys 'db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_type'
252 252
 	 */
253
-	function __construct(array $db_data=null)
253
+	function __construct(array $db_data = null)
254 254
 	{
255 255
 		if (!is_null($db_data))
256 256
 		{
257
-			foreach(array(
257
+			foreach (array(
258 258
 				'Database' => 'db_name',
259 259
 				'Host'     => 'db_host',
260 260
 				'Port'     => 'db_port',
@@ -307,15 +307,15 @@  discard block
 block discarded – undo
307 307
 		}
308 308
 		if (!is_null($Host) && $Host)
309 309
 		{
310
-			$this->Host     = $Host;
310
+			$this->Host = $Host;
311 311
 		}
312 312
 		if (!is_null($Port) && $Port)
313 313
 		{
314
-			$this->Port     = $Port;
314
+			$this->Port = $Port;
315 315
 		}
316 316
 		if (!is_null($User) && $User)
317 317
 		{
318
-			$this->User     = $User;
318
+			$this->User = $User;
319 319
 		}
320 320
 		if (!is_null($Password) && $Password)
321 321
 		{
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		// on connection failure re-try with an other host
333 333
 		// remembering in session which host we used last time
334 334
 		$use_host_from_session = true;
335
-		while(($host = $this->get_host(!$use_host_from_session)))
335
+		while (($host = $this->get_host(!$use_host_from_session)))
336 336
 		{
337 337
 			try {
338 338
 				//error_log(__METHOD__."() this->Host(s)=$this->Host, n=$n --> host=$host");
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
 				//error_log(__METHOD__."() host=$host, new_connection=$new_connection, this->Type=$this->Type, this->Host=$this->Host, wsrep_local_state=".array2string($state));
347 347
 				return $this->Link_ID;
348 348
 			}
349
-			catch(Db\Exception\Connection $e) {
349
+			catch (Db\Exception\Connection $e) {
350 350
 				//_egw_log_exception($e);
351
-				$this->disconnect();	// force a new connect
352
-				$this->Type = $this->setupType;	// get set to "mysql" for "mysqli"
353
-				$use_host_from_session = false;	// re-try with next host from list
351
+				$this->disconnect(); // force a new connect
352
+				$this->Type = $this->setupType; // get set to "mysql" for "mysqli"
353
+				$use_host_from_session = false; // re-try with next host from list
354 354
 			}
355 355
 		}
356 356
 		if (!isset($e))
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
 	{
402 402
 		$hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host);
403 403
 		$num_hosts = count($hosts);
404
-		$n =& Cache::getSession(__CLASS__, $this->Host);
404
+		$n = & Cache::getSession(__CLASS__, $this->Host);
405 405
 		if (!isset($n)) $n = 0;
406 406
 
407
-		if ($next && ++$n >= $num_hosts+2)
407
+		if ($next && ++$n >= $num_hosts + 2)
408 408
 		{
409
-			$n = 0;	// start search again with default on next request
409
+			$n = 0; // start search again with default on next request
410 410
 			$ret = false;
411 411
 		}
412 412
 		else
@@ -429,21 +429,21 @@  discard block
 block discarded – undo
429 429
 		if (!$this->Link_ID)
430 430
 		{
431 431
 			$Database = $User = $Password = $Port = $Type = '';
432
-			foreach(array('Database','User','Password','Port','Type') as $name)
432
+			foreach (array('Database', 'User', 'Password', 'Port', 'Type') as $name)
433 433
 			{
434 434
 				$$name = $this->$name;
435 435
 				if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1));
436 436
 			}
437 437
 			$this->setupType = $php_extension = $Type;
438 438
 
439
-			switch($Type)	// convert to ADO db-type-names
439
+			switch ($Type)	// convert to ADO db-type-names
440 440
 			{
441 441
 				case 'pgsql':
442 442
 					$Type = 'postgres'; // name in ADOdb
443 443
 					// create our own pgsql connection-string, to allow unix domain soccets if !$Host
444 444
 					$Host = "dbname=$Database".($Host ? " host=$Host".($Port ? " port=$Port" : '') : '').
445 445
 						" user=$User".($Password ? " password='".addslashes($Password)."'" : '');
446
-					$User = $Password = $Database = '';	// to indicate $Host is a connection-string
446
+					$User = $Password = $Database = ''; // to indicate $Host is a connection-string
447 447
 					break;
448 448
 
449 449
 				case 'odbc_mssql':
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 					$Type = 'maxdb';
467 467
 					// fall through
468 468
 				case 'maxdb':
469
-					$Type ='sapdb';	// name in ADOdb
469
+					$Type = 'sapdb'; // name in ADOdb
470 470
 					$php_extension = 'odbc';
471 471
 					break;
472 472
 
@@ -479,18 +479,18 @@  discard block
 block discarded – undo
479 479
 					}
480 480
 					else
481 481
 					{
482
-						$php_extension = 'mysql';	// you can use $this->setupType to determine if it's mysqlt or mysql
482
+						$php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql
483 483
 					}
484 484
 					// fall through
485 485
 				case 'mysqli':
486
-					$this->Type = 'mysql';		// need to be "mysql", so apps can check just for "mysql"!
486
+					$this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"!
487 487
 					// fall through
488 488
 				default:
489 489
 					if ($Port) $Host .= ':'.$Port;
490 490
 					break;
491 491
 			}
492
-			if (!isset($GLOBALS['egw']->ADOdb) ||	// we have no connection so far
493
-				(is_object($GLOBALS['egw']->db) &&	// we connect to a different db, then the global one
492
+			if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far
493
+				(is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one
494 494
 					($this->Type != $GLOBALS['egw']->db->Type ||
495 495
 					$this->Database != $GLOBALS['egw']->db->Database ||
496 496
 					$this->User != $GLOBALS['egw']->db->User ||
@@ -503,11 +503,11 @@  discard block
 block discarded – undo
503 503
 				}
504 504
 				if (!isset($GLOBALS['egw']->ADOdb))	// use the global object to store the connection
505 505
 				{
506
-					$this->Link_ID =& $GLOBALS['egw']->ADOdb;
506
+					$this->Link_ID = & $GLOBALS['egw']->ADOdb;
507 507
 				}
508 508
 				else
509 509
 				{
510
-					$this->privat_Link_ID = True;	// remember that we use a privat Link_ID for disconnect
510
+					$this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect
511 511
 				}
512 512
 				$this->Link_ID = ADONewConnection($Type);
513 513
 				if (!$this->Link_ID)
@@ -523,11 +523,11 @@  discard block
 block discarded – undo
523 523
 				if (($Ok = $this->Link_ID->$connect($Host, $User, $Password, $Database)))
524 524
 				{
525 525
 					$this->ServerInfo = $this->Link_ID->ServerInfo();
526
-					$this->set_capabilities($Type,$this->ServerInfo['version']);
526
+					$this->set_capabilities($Type, $this->ServerInfo['version']);
527 527
 				}
528 528
 				if (!$Ok)
529 529
 				{
530
-					$Host = preg_replace('/password=[^ ]+/','password=$Password',$Host);	// eg. postgres dsn contains password
530
+					$Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password
531 531
 					throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed.");
532 532
 				}
533 533
 				if ($this->Debug)
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
 					// this is the format ADOdb expects
544 544
 					$this->Link_ID->Execute('SET DATEFORMAT ymd');
545 545
 					// sets the limit to the maximum
546
-					ini_set('mssql.textlimit',2147483647);
547
-					ini_set('mssql.sizelimit',2147483647);
546
+					ini_set('mssql.textlimit', 2147483647);
547
+					ini_set('mssql.sizelimit', 2147483647);
548 548
 				}
549 549
 				// set our default charset
550 550
 				$this->Link_ID->SetCharSet($this->Type == 'mysql' ? 'utf8' : 'utf-8');
@@ -553,12 +553,12 @@  discard block
 block discarded – undo
553 553
 			}
554 554
 			else
555 555
 			{
556
-				$this->Link_ID =& $GLOBALS['egw']->ADOdb;
556
+				$this->Link_ID = & $GLOBALS['egw']->ADOdb;
557 557
 			}
558 558
 		}
559 559
 		if (!$this->Link_ID->isConnected() && !$this->Link_ID->Connect())
560 560
 		{
561
-			$Host = preg_replace('/password=[^ ]+/','password=$Password',$Host);	// eg. postgres dsn contains password
561
+			$Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password
562 562
 			throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) reconnect failed.");
563 563
 		}
564 564
 		// fix due to caching and reusing of connection not correctly set $this->Type == 'mysql'
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 		}
570 570
 		if ($new_connection)
571 571
 		{
572
-			foreach(get_included_files() as $file)
572
+			foreach (get_included_files() as $file)
573 573
 			{
574
-				if (strpos($file,'adodb') !== false && !in_array($file,(array)$_SESSION['egw_required_files']))
574
+				if (strpos($file, 'adodb') !== false && !in_array($file, (array)$_SESSION['egw_required_files']))
575 575
 				{
576 576
 					$_SESSION['egw_required_files'][] = $file;
577 577
 					//error_log(__METHOD__."() egw_required_files[] = $file");
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
 	 */
588 588
 	function __wakeup()
589 589
 	{
590
-		$this->connect();	// we need to re-connect
590
+		$this->connect(); // we need to re-connect
591 591
 	}
592 592
 
593 593
 	/**
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
 	 */
601 601
 	function __sleep()
602 602
 	{
603
-		if (!empty($this->setupType)) $this->Type = $this->setupType;	// restore Type eg. to mysqli
603
+		if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli
604 604
 
605 605
 		$vars = get_object_vars($this);
606 606
 		unset($vars['Link_ID']);
@@ -614,23 +614,23 @@  discard block
 block discarded – undo
614 614
 	 * @param string $adodb_driver mysql, postgres, mssql, sapdb, oci8
615 615
 	 * @param string $db_version version-number of connected db-server, as reported by ServerInfo
616 616
 	 */
617
-	function set_capabilities($adodb_driver,$db_version)
617
+	function set_capabilities($adodb_driver, $db_version)
618 618
 	{
619
-		switch($adodb_driver)
619
+		switch ($adodb_driver)
620 620
 		{
621 621
 			case 'mysql':
622 622
 			case 'mysqlt':
623 623
 			case 'mysqli':
624
-				$this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float) $db_version >= 4.1;
625
-				$this->capabilities[self::CAPABILITY_UNION] = (float) $db_version >= 4.0;
624
+				$this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float)$db_version >= 4.1;
625
+				$this->capabilities[self::CAPABILITY_UNION] = (float)$db_version >= 4.0;
626 626
 				$this->capabilities[self::CAPABILITY_NAME_CASE] = 'preserv';
627
-				$this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 4.1;
627
+				$this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 4.1;
628 628
 				$this->capabilities[self::CAPABILITY_CAST_AS_VARCHAR] = 'CAST(%s AS char)';
629 629
 				break;
630 630
 
631 631
 			case 'postgres':
632 632
 				$this->capabilities[self::CAPABILITY_NAME_CASE] = 'lower';
633
-				$this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 7.4;
633
+				$this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 7.4;
634 634
 				$this->capabilities[self::CAPABILITY_OUTER_JOIN] = true;
635 635
 				$this->capabilities[self::CAPABILITY_CASE_INSENSITIV_LIKE] = '::text ILIKE';
636 636
 				$this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR] = true;
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
 			return False;
680 680
 		}
681 681
 		// the substring is needed as the string is already in quotes
682
-		return substr($this->Link_ID->DBTimeStamp($epoch),1,-1);
682
+		return substr($this->Link_ID->DBTimeStamp($epoch), 1, -1);
683 683
 	}
684 684
 
685 685
 	/**
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 	 */
706 706
 	public static function from_bool($val)
707 707
 	{
708
-		return $val && $val[0] !== 'f';	// everthing other then 0 or f[alse] is returned as true
708
+		return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true
709 709
 	}
710 710
 
711 711
 	/**
@@ -722,9 +722,9 @@  discard block
 block discarded – undo
722 722
 	* @return ADORecordSet or false, if the query fails
723 723
 	* @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code
724 724
 	*/
725
-	function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true)
725
+	function query($Query_String, $line = '', $file = '', $offset = 0, $num_rows = -1, $inputarr = false, $fetchmode = self::FETCH_BOTH, $reconnect = true)
726 726
 	{
727
-		unset($line, $file);	// not used anymore
727
+		unset($line, $file); // not used anymore
728 728
 
729 729
 		if ($Query_String == '')
730 730
 		{
@@ -750,23 +750,23 @@  discard block
 block discarded – undo
750 750
 		}
751 751
 		if ($num_rows > 0)
752 752
 		{
753
-			$rs = $this->Link_ID->SelectLimit($Query_String,$num_rows,(int)$offset,$inputarr);
753
+			$rs = $this->Link_ID->SelectLimit($Query_String, $num_rows, (int)$offset, $inputarr);
754 754
 		}
755 755
 		else
756 756
 		{
757
-			$rs = $this->Link_ID->Execute($Query_String,$inputarr);
757
+			$rs = $this->Link_ID->Execute($Query_String, $inputarr);
758 758
 		}
759 759
 		$this->Row = 0;
760 760
 		$this->Errno  = $this->Link_ID->ErrorNo();
761 761
 		$this->Error  = $this->Link_ID->ErrorMsg();
762 762
 
763
-		if ($this->query_log && ($f = @fopen($this->query_log,'a+')))
763
+		if ($this->query_log && ($f = @fopen($this->query_log, 'a+')))
764 764
 		{
765
-			fwrite($f,'['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] ');
766
-			fwrite($f,date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr,true) : '')."\n");
765
+			fwrite($f, '['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] ');
766
+			fwrite($f, date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr, true) : '')."\n");
767 767
 			if (!$rs)
768 768
 			{
769
-				fwrite($f,"*** Error $this->Errno: $this->Error\n".function_backtrace()."\n");
769
+				fwrite($f, "*** Error $this->Errno: $this->Error\n".function_backtrace()."\n");
770 770
 			}
771 771
 			fclose($f);
772 772
 		}
@@ -777,11 +777,11 @@  discard block
 block discarded – undo
777 777
 				$this->disconnect();
778 778
 				return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false);
779 779
 			}
780
-			throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String).
780
+			throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String) ? $Query_String[0] : $Query_String).
781 781
 				"\n$this->Error ($this->Errno)".
782
-				($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno);
782
+				($inputarr ? "\nParameters: '".implode("','", $inputarr)."'" : ''), $this->Errno);
783 783
 		}
784
-		elseif(empty($rs->sql)) $rs->sql = $Query_String;
784
+		elseif (empty($rs->sql)) $rs->sql = $Query_String;
785 785
 		return $rs;
786 786
 	}
787 787
 
@@ -796,9 +796,9 @@  discard block
 block discarded – undo
796 796
 	* @param array|boolean $inputarr array for binding variables to parameters or false (default)
797 797
 	* @return ADORecordSet or false, if the query fails
798 798
 	*/
799
-	function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false)
799
+	function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '', $inputarr = false)
800 800
 	{
801
-		return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr);
801
+		return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr);
802 802
 	}
803 803
 
804 804
 	/**
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
 		{
864 864
 			$table = self::$tablealiases[$table];
865 865
 		}
866
-		$id = $this->Link_ID->PO_Insert_ID($table,$field);	// simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible
866
+		$id = $this->Link_ID->PO_Insert_ID($table, $field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible
867 867
 
868 868
 		if ($id === False)	// function not supported
869 869
 		{
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 	* @param bool $full optional, default False summary information, True full information
900 900
 	* @return array table meta data
901 901
 	*/
902
-	function metadata($table='',$full=false)
902
+	function metadata($table = '', $full = false)
903 903
 	{
904 904
 		if (!$this->Link_ID && !$this->connect())
905 905
 		{
@@ -911,13 +911,13 @@  discard block
 block discarded – undo
911 911
 
912 912
 		$metadata = array();
913 913
 		$i = 0;
914
-		foreach($columns as $column)
914
+		foreach ($columns as $column)
915 915
 		{
916 916
 			// for backwards compatibilty (depreciated)
917 917
 			$flags = null;
918
-			if($column->auto_increment) $flags .= "auto_increment ";
919
-			if($column->primary_key) $flags .= "primary_key ";
920
-			if($column->binary) $flags .= "binary ";
918
+			if ($column->auto_increment) $flags .= "auto_increment ";
919
+			if ($column->primary_key) $flags .= "primary_key ";
920
+			if ($column->binary) $flags .= "binary ";
921 921
 
922 922
 			$metadata[$i] = array(
923 923
 				'table' => $table,
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
 	 * @param boolean $just_name =false true return array of table-names, false return old format
953 953
 	 * @return array list of the tables
954 954
 	 */
955
-	function table_names($just_name=false)
955
+	function table_names($just_name = false)
956 956
 	{
957 957
 		if (!$this->Link_ID) $this->connect();
958 958
 		if (!$this->Link_ID)
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 		$tables = $this->Link_ID->MetaTables('TABLES');
964 964
 		if (is_array($tables))
965 965
 		{
966
-			foreach($tables as $table)
966
+			foreach ($tables as $table)
967 967
 			{
968 968
 				if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper')
969 969
 				{
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 			echo "<p>db::index_names() not yet implemented for db-type '$this->Type'</p>\n";
993 993
 			return $indices;
994 994
 		}
995
-		foreach($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row)
995
+		foreach ($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row)
996 996
 		{
997 997
 			$indices[] = array(
998 998
 				'index_name'      => $row[0],
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 	* @param string $charset default charset for the database
1026 1026
 	* @param string $grant_host ='localhost' host/ip of the webserver
1027 1027
 	*/
1028
-	function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost')
1028
+	function create_database($adminname = '', $adminpasswd = '', $charset = '', $grant_host = 'localhost')
1029 1029
 	{
1030 1030
 		$currentUser = $this->User;
1031 1031
 		$currentPassword = $this->Password;
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 			case 'mysqli':
1050 1050
 			case 'mysqlt':
1051 1051
 				$create = "CREATE DATABASE `$currentDatabase`";
1052
-				if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float) $this->ServerInfo['version'] >= 4.1)
1052
+				if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float)$this->ServerInfo['version'] >= 4.1)
1053 1053
 				{
1054 1054
 					$create .= ' DEFAULT CHARACTER SET '.$this->Link_ID->charset2mysql[$charset].';';
1055 1055
 				}
@@ -1060,9 +1060,9 @@  discard block
 block discarded – undo
1060 1060
 				echo "<p>db::create_database(user='$adminname',\$pw) not yet implemented for DB-type '$this->Type'</p>\n";
1061 1061
 				break;
1062 1062
 		}
1063
-		foreach($sqls as $sql)
1063
+		foreach ($sqls as $sql)
1064 1064
 		{
1065
-			$this->query($sql,__LINE__,__FILE__);
1065
+			$this->query($sql, __LINE__, __FILE__);
1066 1066
 		}
1067 1067
 		$this->disconnect();
1068 1068
 
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
 		{
1089 1089
 			return False;
1090 1090
 		}
1091
-		return call_user_func_array(array(&$this->Link_ID,'concat'),$args);
1091
+		return call_user_func_array(array(&$this->Link_ID, 'concat'), $args);
1092 1092
 	}
1093 1093
 
1094 1094
 	/**
@@ -1099,9 +1099,9 @@  discard block
 block discarded – undo
1099 1099
 	 * @param string $separator =',' optional separator, default is comma
1100 1100
 	 * @return string|boolean false if not supported by dbms
1101 1101
 	 */
1102
-	function group_concat($expr, $order_by='', $separator=',')
1102
+	function group_concat($expr, $order_by = '', $separator = ',')
1103 1103
 	{
1104
-		switch($this->Type)
1104
+		switch ($this->Type)
1105 1105
 		{
1106 1106
 			case 'mysql':
1107 1107
 				$sql = 'GROUP_CONCAT('.$expr;
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 	 */
1136 1136
 	function strpos($str, $substr)
1137 1137
 	{
1138
-		switch($this->Type)
1138
+		switch ($this->Type)
1139 1139
 		{
1140 1140
 			case 'mysql':
1141 1141
 				return "LOCATE($substr,$str)";
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 	 */
1156 1156
 	function unix_timestamp($expr)
1157 1157
 	{
1158
-		switch($this->Type)
1158
+		switch ($this->Type)
1159 1159
 		{
1160 1160
 			case 'mysql':
1161 1161
 				return "UNIX_TIMESTAMP($expr)";
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
 	 */
1177 1177
 	function from_unixtime($expr)
1178 1178
 	{
1179
-		switch($this->Type)
1179
+		switch ($this->Type)
1180 1180
 		{
1181 1181
 			case 'mysql':
1182 1182
 				return "FROM_UNIXTIME($expr)";
@@ -1185,7 +1185,7 @@  discard block
 block discarded – undo
1185 1185
 				return "(TIMESTAMP WITH TIME ZONE 'epoch' + ($expr) * INTERVAL '1 sec')";
1186 1186
 
1187 1187
 			case 'mssql':	// we use date(,0) as we store server-time
1188
-				return "DATEADD(second,($expr),'".date('Y-m-d H:i:s',0)."')";
1188
+				return "DATEADD(second,($expr),'".date('Y-m-d H:i:s', 0)."')";
1189 1189
 		}
1190 1190
 		return false;
1191 1191
 	}
@@ -1199,30 +1199,30 @@  discard block
 block discarded – undo
1199 1199
 	 * @param string $format format specifier like '%Y-%m-%d %H:%i:%s' or '%V%X' ('%v%x') weeknumber & year with Sunday (Monday) as first day
1200 1200
 	 * @return string SQL expression of type timestamp
1201 1201
 	 */
1202
-	function date_format($expr,$format)
1202
+	function date_format($expr, $format)
1203 1203
 	{
1204
-		switch($this->Type)
1204
+		switch ($this->Type)
1205 1205
 		{
1206 1206
 			case 'mysql':
1207 1207
 				return "DATE_FORMAT($expr,'$format')";
1208 1208
 
1209 1209
 			case 'pgsql':
1210 1210
 				$format = str_replace(
1211
-					array('%Y',  '%y','%m','%d','%H',  '%h','%i','%s','%V','%v','%X',  '%x'),
1212
-					array('YYYY','YY','MM','DD','HH24','HH','MI','SS','IW','IW','YYYY','YYYY'),
1211
+					array('%Y', '%y', '%m', '%d', '%H', '%h', '%i', '%s', '%V', '%v', '%X', '%x'),
1212
+					array('YYYY', 'YY', 'MM', 'DD', 'HH24', 'HH', 'MI', 'SS', 'IW', 'IW', 'YYYY', 'YYYY'),
1213 1213
 					$format);
1214 1214
 				return "TO_CHAR($expr,'$format')";
1215 1215
 
1216 1216
 			case 'mssql':
1217 1217
 				$from = $to = array();
1218
-				foreach(array('%Y'=>'yyyy','%y'=>'yy','%m'=>'mm','%d'=>'dd','%H'=>'hh','%i'=>'mi','%s'=>'ss','%V'=>'wk','%v'=>'wk','%X'=>'yyyy','%x'=>'yyyy') as $f => $t)
1218
+				foreach (array('%Y'=>'yyyy', '%y'=>'yy', '%m'=>'mm', '%d'=>'dd', '%H'=>'hh', '%i'=>'mi', '%s'=>'ss', '%V'=>'wk', '%v'=>'wk', '%X'=>'yyyy', '%x'=>'yyyy') as $f => $t)
1219 1219
 				{
1220 1220
 					$from[] = $f;
1221 1221
 					$to[] = "'+DATEPART($t,($expr))+'";
1222 1222
 				}
1223 1223
 				$from[] = "''+"; $to[] = '';
1224 1224
 				$from[] = "+''"; $to[] = '';
1225
-				return str_replace($from,$to,$format);
1225
+				return str_replace($from, $to, $format);
1226 1226
 		}
1227 1227
 		return false;
1228 1228
 	}
@@ -1235,7 +1235,7 @@  discard block
 block discarded – undo
1235 1235
 	 */
1236 1236
 	function to_double($expr)
1237 1237
 	{
1238
-		switch($this->Type)
1238
+		switch ($this->Type)
1239 1239
 		{
1240 1240
 			case 'pgsql':
1241 1241
 				return $expr.'::double';
@@ -1253,7 +1253,7 @@  discard block
 block discarded – undo
1253 1253
 	 */
1254 1254
 	function to_int($expr)
1255 1255
 	{
1256
-		switch($this->Type)
1256
+		switch ($this->Type)
1257 1257
 		{
1258 1258
 			case 'pgsql':
1259 1259
 				return $expr.'::integer';
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
 	 */
1272 1272
 	function to_varchar($expr)
1273 1273
 	{
1274
-		switch($this->Type)
1274
+		switch ($this->Type)
1275 1275
 		{
1276 1276
 			case 'pgsql':
1277 1277
 				return 'CAST('.$expr.' AS varchar)';
@@ -1315,7 +1315,7 @@  discard block
 block discarded – undo
1315 1315
 			// always quote for postgreSQL, as this is the only way to support mixed case names
1316 1316
 			if (preg_match('/\W/', $name) || $type == 'pgsql' && preg_match('/[A-Z]+/', $name) || $name == 'index')
1317 1317
 			{
1318
-				return $quote . $name . $quote;
1318
+				return $quote.$name.$quote;
1319 1319
 			}
1320 1320
 			return $name;
1321 1321
 		}, explode('.', $name));
@@ -1337,27 +1337,27 @@  discard block
 block discarded – undo
1337 1337
 	* @param string $glue =',' used to glue array values together for the string type
1338 1338
 	* @return string escaped sting
1339 1339
 	*/
1340
-	function quote($value,$type=False,$not_null=true,$length=null,$glue=',')
1340
+	function quote($value, $type = False, $not_null = true, $length = null, $glue = ',')
1341 1341
 	{
1342
-		if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n";
1342
+		if ($this->Debug) echo "<p>db::quote(".(is_null($value) ? 'NULL' : "'$value'").",'$type','$not_null')</p>\n";
1343 1343
 
1344 1344
 		if (!$not_null && is_null($value))	// writing unset php-variables and those set to NULL now as SQL NULL
1345 1345
 		{
1346 1346
 			return 'NULL';
1347 1347
 		}
1348
-		switch($type)
1348
+		switch ($type)
1349 1349
 		{
1350 1350
 			case 'int':
1351 1351
 				// if DateTime object given, convert it to a unix timestamp (NOT converting the timezone!)
1352 1352
 				if (is_object($value) && ($value instanceof \DateTime))
1353 1353
 				{
1354
-					return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value,'ts');
1354
+					return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value, 'ts');
1355 1355
 				}
1356 1356
 			case 'auto':
1357 1357
 				// atm. (php5.2) php has only 32bit integers, it converts everything else to float.
1358 1358
 				// Casting it to int gives a negative number instead of the big 64bit integer!
1359 1359
 				// There for we have to keep it as float by using round instead the int cast.
1360
-				return is_float($value) ? round($value) : (int) $value;
1360
+				return is_float($value) ? round($value) : (int)$value;
1361 1361
 			case 'bool':
1362 1362
 				if ($this->Type == 'mysql')		// maybe it's not longer necessary with mysql5
1363 1363
 				{
@@ -1366,23 +1366,23 @@  discard block
 block discarded – undo
1366 1366
 				return $value ? 'true' : 'false';
1367 1367
 			case 'float':
1368 1368
 			case 'decimal':
1369
-				return (double) $value;
1369
+				return (double)$value;
1370 1370
 		}
1371 1371
 		if (!$this->Link_ID && !$this->connect())
1372 1372
 		{
1373 1373
 			return False;
1374 1374
 		}
1375
-		switch($type)
1375
+		switch ($type)
1376 1376
 		{
1377 1377
 			case 'blob':
1378 1378
 				switch ($this->Link_ID->blobEncodeType)
1379 1379
 				{
1380 1380
 					case 'C':	// eg. postgres
1381
-						return "'" . $this->Link_ID->BlobEncode($value) . "'";
1381
+						return "'".$this->Link_ID->BlobEncode($value)."'";
1382 1382
 					case 'I':
1383 1383
 						return $this->Link_ID->BlobEncode($value);
1384 1384
 				}
1385
-				break;	// handled like strings
1385
+				break; // handled like strings
1386 1386
 			case 'date':
1387 1387
 				// if DateTime object given, convert it (NOT converting the timezone!)
1388 1388
 				if (is_object($value) && ($value instanceof \DateTime))
@@ -1400,7 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 		}
1401 1401
 		if (is_array($value))
1402 1402
 		{
1403
-			$value = implode($glue,$value);
1403
+			$value = implode($glue, $value);
1404 1404
 		}
1405 1405
 		// only truncate string if length given and <= 255
1406 1406
 		// to not unnecessary truncate varchar(>255) as PostgreSQL uses text anyway and MySQL truncates itself silently (unless strict mode!)
@@ -1438,7 +1438,7 @@  discard block
 block discarded – undo
1438 1438
 	*	If its set, the column-type-data determinates if (int) or addslashes is used.
1439 1439
 	* @return string SQL
1440 1440
 	*/
1441
-	function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False)
1441
+	function column_data_implode($glue, $array, $use_key = True, $only = False, $column_definitions = False)
1442 1442
 	{
1443 1443
 		if (!is_array($array))	// this allows to give an SQL-string for delete or update
1444 1444
 		{
@@ -1448,16 +1448,16 @@  discard block
 block discarded – undo
1448 1448
 		{
1449 1449
 			$column_definitions = $this->column_definitions;
1450 1450
 		}
1451
-		if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n";
1451
+		if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array, True).",'$use_key',".print_r($only, True).",<pre>".print_r($column_definitions, True)."</pre>\n";
1452 1452
 
1453 1453
 		// do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres)
1454 1454
 		$truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR];
1455 1455
 
1456 1456
 		$keys = $values = array();
1457
-		foreach($array as $key => $data)
1457
+		foreach ($array as $key => $data)
1458 1458
 		{
1459 1459
 			if (is_int($key) && $use_key !== 'VALUES' || !$only || $only === True && isset($column_definitions[$key]) ||
1460
-				is_array($only) && in_array($key,$only))
1460
+				is_array($only) && in_array($key, $only))
1461 1461
 			{
1462 1462
 				$keys[] = $this->name_quote($key);
1463 1463
 
@@ -1468,7 +1468,7 @@  discard block
 block discarded – undo
1468 1468
 					if (strpos($key, '.') !== false) list(, $col) = explode('.', $key);
1469 1469
 					if (!isset($column_definitions[$col]))
1470 1470
 					{
1471
-						throw new Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>");
1471
+						throw new Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array, True).",'$use_key',".print_r($only, True).",<pre>".print_r($column_definitions, True)."</pre><b>nothing known about column '$key'!</b>");
1472 1472
 					}
1473 1473
 				}
1474 1474
 				$column_type = is_array($column_definitions) ? @$column_definitions[$col]['type'] : False;
@@ -1477,7 +1477,7 @@  discard block
 block discarded – undo
1477 1477
 				$maxlength = null;
1478 1478
 				if ($truncate_varchar)
1479 1479
 				{
1480
-					$maxlength = in_array($column_definitions[$col]['type'], array('varchar','ascii')) ? $column_definitions[$col]['precision'] : null;
1480
+					$maxlength = in_array($column_definitions[$col]['type'], array('varchar', 'ascii')) ? $column_definitions[$col]['precision'] : null;
1481 1481
 				}
1482 1482
 				// dont use IN ( ), if there's only one value, it's slower for MySQL
1483 1483
 				if (is_array($data) && count($data) == 1)
@@ -1487,39 +1487,38 @@  discard block
 block discarded – undo
1487 1487
 				if (is_array($data))
1488 1488
 				{
1489 1489
 					$or_null = '';
1490
-					foreach($data as $k => $v)
1490
+					foreach ($data as $k => $v)
1491 1491
 					{
1492
-						if (!$not_null && $use_key===True && is_null($v))
1492
+						if (!$not_null && $use_key === True && is_null($v))
1493 1493
 						{
1494 1494
 							$or_null = $this->name_quote($key).' IS NULL)';
1495 1495
 							unset($data[$k]);
1496 1496
 							continue;
1497 1497
 						}
1498
-						$data[$k] = $this->quote($v,$column_type,$not_null,$maxlength);
1498
+						$data[$k] = $this->quote($v, $column_type, $not_null, $maxlength);
1499 1499
 					}
1500
-					$values[] = ($or_null?'(':'').(!count($data) ?
1500
+					$values[] = ($or_null ? '(' : '').(!count($data) ?
1501 1501
 						// empty array on insert/update, store as NULL, or if not allowed whatever value NULL is casted to
1502
-						$this->quote(null, $column_type, $not_null) :
1503
-						($use_key===True ? $this->name_quote($key).' IN ' : '') .
1504
-						'('.implode(',',$data).')'.($or_null ? ' OR ' : '')).$or_null;
1502
+						$this->quote(null, $column_type, $not_null) : ($use_key === True ? $this->name_quote($key).' IN ' : '').
1503
+						'('.implode(',', $data).')'.($or_null ? ' OR ' : '')).$or_null;
1505 1504
 				}
1506
-				elseif (is_int($key) && $use_key===True)
1505
+				elseif (is_int($key) && $use_key === True)
1507 1506
 				{
1508
-					if (empty($data)) continue;	// would give SQL error
1507
+					if (empty($data)) continue; // would give SQL error
1509 1508
 					$values[] = $data;
1510 1509
 				}
1511 1510
 				elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data))
1512 1511
 				{
1513
-					$values[] = $this->name_quote($key) .' IS NULL';
1512
+					$values[] = $this->name_quote($key).' IS NULL';
1514 1513
 				}
1515 1514
 				else
1516 1515
 				{
1517
-					$values[] = ($use_key===True ? $this->name_quote($key) . '=' : '') . $this->quote($data,$column_type,$not_null,$maxlength);
1516
+					$values[] = ($use_key === True ? $this->name_quote($key).'=' : '').$this->quote($data, $column_type, $not_null, $maxlength);
1518 1517
 				}
1519 1518
 			}
1520 1519
 		}
1521
-		return ($use_key==='VALUES' ? '('.implode(',',$keys).') VALUES (' : '').
1522
-			implode($glue,$values) . ($use_key==='VALUES' ? ')' : '');
1520
+		return ($use_key === 'VALUES' ? '('.implode(',', $keys).') VALUES (' : '').
1521
+			implode($glue, $values).($use_key === 'VALUES' ? ')' : '');
1523 1522
 	}
1524 1523
 
1525 1524
 	/**
@@ -1531,9 +1530,9 @@  discard block
 block discarded – undo
1531 1530
 	*	of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file).
1532 1531
 	*	If its set, the column-type-data determinates if (int) or addslashes is used.
1533 1532
 	*/
1534
-	function set_column_definitions($column_definitions=False)
1533
+	function set_column_definitions($column_definitions = False)
1535 1534
 	{
1536
-		$this->column_definitions=$column_definitions;
1535
+		$this->column_definitions = $column_definitions;
1537 1536
 	}
1538 1537
 
1539 1538
 	/**
@@ -1546,7 +1545,7 @@  discard block
 block discarded – undo
1546 1545
 	 *
1547 1546
 	 * @var string
1548 1547
 	 */
1549
-	private $app=self::API_APPNAME;
1548
+	private $app = self::API_APPNAME;
1550 1549
 
1551 1550
 	/**
1552 1551
 	 * Sets the application in which the db-class looks for table-defintions
@@ -1581,7 +1580,7 @@  discard block
 block discarded – undo
1581 1580
 	* @param bool|string $table if set return only defintions of that table, else return all defintions
1582 1581
 	* @return mixed array with table-defintions or False if file not found
1583 1582
 	*/
1584
-	function get_table_definitions($app=False,$table=False)
1583
+	function get_table_definitions($app = False, $table = False)
1585 1584
 	{
1586 1585
 		// ease the transition to api
1587 1586
 		if ($app === 'phpgwapi') $app = 'api';
@@ -1589,7 +1588,7 @@  discard block
 block discarded – undo
1589 1588
 		static $all_app_data = array();
1590 1589
 		if ($app === true && $table)
1591 1590
 		{
1592
-			foreach($all_app_data as $app => &$app_data)
1591
+			foreach ($all_app_data as $app => &$app_data)
1593 1592
 			{
1594 1593
 				if (isset($app_data[$table]))
1595 1594
 				{
@@ -1597,13 +1596,13 @@  discard block
 block discarded – undo
1597 1596
 				}
1598 1597
 			}
1599 1598
 			// $table not found in loaded apps, check not yet loaded ones
1600
-			foreach(scandir(EGW_INCLUDE_ROOT) as $app)
1599
+			foreach (scandir(EGW_INCLUDE_ROOT) as $app)
1601 1600
 			{
1602 1601
 				if ($app[0] == '.' || !is_dir(EGW_INCLUDE_ROOT.'/'.$app) || isset($all_app_data[$app]))
1603 1602
 				{
1604 1603
 					continue;
1605 1604
 				}
1606
-				$tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php";
1605
+				$tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php";
1607 1606
 				if (!@file_exists($tables_current))
1608 1607
 				{
1609 1608
 					$all_app_data[$app] = False;
@@ -1612,7 +1611,7 @@  discard block
 block discarded – undo
1612 1611
 				{
1613 1612
 					$phpgw_baseline = null;
1614 1613
 					include($tables_current);
1615
-					$all_app_data[$app] =& $phpgw_baseline;
1614
+					$all_app_data[$app] = & $phpgw_baseline;
1616 1615
 					unset($phpgw_baseline);
1617 1616
 
1618 1617
 					if (isset($all_app_data[$app][$table]))
@@ -1627,17 +1626,17 @@  discard block
 block discarded – undo
1627 1626
 		{
1628 1627
 			$app = $this->app ? $this->app : $GLOBALS['egw_info']['flags']['currentapp'];
1629 1628
 		}
1630
-		$app_data =& $all_app_data[$app];
1629
+		$app_data = & $all_app_data[$app];
1631 1630
 
1632 1631
 		if (!isset($app_data))
1633 1632
 		{
1634
-			$tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php";
1633
+			$tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php";
1635 1634
 			if (!@file_exists($tables_current))
1636 1635
 			{
1637 1636
 				return $app_data = False;
1638 1637
 			}
1639 1638
 			include($tables_current);
1640
-			$app_data =& $phpgw_baseline;
1639
+			$app_data = & $phpgw_baseline;
1641 1640
 			unset($phpgw_baseline);
1642 1641
 		}
1643 1642
 		if ($table && (!$app_data || !isset($app_data[$table])))
@@ -1660,14 +1659,14 @@  discard block
 block discarded – undo
1660 1659
 	 * @param string $attribute='comment' what field to return, NULL for array with all fields, default 'comment' to return the comment
1661 1660
 	 * @return string|array NULL if table or column or attribute not found
1662 1661
 	 */
1663
-	/* static */ function get_column_attribute($column,$table,$app=null,$attribute='comment')
1662
+	/* static */ function get_column_attribute($column, $table, $app = null, $attribute = 'comment')
1664 1663
 	{
1665
-		static $cached_columns=null,$cached_table=null;	// some caching
1664
+		static $cached_columns = null, $cached_table = null; // some caching
1666 1665
 
1667 1666
 		if ($cached_table !== $table || is_null($cached_columns))
1668 1667
 		{
1669 1668
 			$db = isset($this) ? $this : $GLOBALS['egw']->db;
1670
-			$table_def = $db->get_table_definitions($app,$table);
1669
+			$table_def = $db->get_table_definitions($app, $table);
1671 1670
 			$cached_columns = is_array($table_def) ? $table_def['fd'] : false;
1672 1671
 		}
1673 1672
 		if ($cached_columns === false) return null;
@@ -1691,38 +1690,38 @@  discard block
 block discarded – undo
1691 1690
 	* @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1692 1691
 	* @return ADORecordSet or false, if the query fails
1693 1692
 	*/
1694
-	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False)
1693
+	function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False)
1695 1694
 	{
1696
-		if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n";
1695
+		if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app')</p>\n";
1697 1696
 
1698
-		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
1697
+		if (!$table_def) $table_def = $this->get_table_definitions($app, $table);
1699 1698
 
1700 1699
 		$sql_append = '';
1701 1700
 		$cmd = 'INSERT';
1702 1701
 		if (is_array($where) && count($where))
1703 1702
 		{
1704
-			switch($this->Type)
1703
+			switch ($this->Type)
1705 1704
 			{
1706 1705
 				case 'sapdb': case 'maxdb':
1707 1706
 					$sql_append = ' UPDATE DUPLICATES';
1708 1707
 					break;
1709 1708
 				case 'mysql':
1710 1709
 					// use replace if primary keys are included
1711
-					if (count(array_intersect(array_keys($where),(array)$table_def['pk'])) == count($table_def['pk']))
1710
+					if (count(array_intersect(array_keys($where), (array)$table_def['pk'])) == count($table_def['pk']))
1712 1711
 					{
1713 1712
 						$cmd = 'REPLACE';
1714 1713
 						break;
1715 1714
 					}
1716 1715
 					// fall through !!!
1717 1716
 				default:
1718
-					if ($this->select($table,'count(*)',$where,$line,$file)->fetchColumn())
1717
+					if ($this->select($table, 'count(*)', $where, $line, $file)->fetchColumn())
1719 1718
 					{
1720
-						return !!$this->update($table,$data,$where,$line,$file,$app,$use_prepared_statement,$table_def);
1719
+						return !!$this->update($table, $data, $where, $line, $file, $app, $use_prepared_statement, $table_def);
1721 1720
 					}
1722 1721
 					break;
1723 1722
 			}
1724 1723
 			// the checked values need to be inserted too, value in data has precedence, also cant insert sql strings (numerical id)
1725
-			foreach($where as $column => $value)
1724
+			foreach ($where as $column => $value)
1726 1725
 			{
1727 1726
 				if (!is_numeric($column) && !isset($data[$column]) &&
1728 1727
 					// skip auto-id of 0 or NULL, as PostgreSQL does NOT create an auto-id, if they are given
@@ -1742,24 +1741,24 @@  discard block
 block discarded – undo
1742 1741
 			if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!');
1743 1742
 
1744 1743
 			$sql = "$cmd INTO $table ";
1745
-			foreach($data as $k => $d)
1744
+			foreach ($data as $k => $d)
1746 1745
 			{
1747 1746
 				if (!$k)
1748 1747
 				{
1749
-					$sql .= $this->column_data_implode(',',$d,'VALUES',true,$table_def['fd']);
1748
+					$sql .= $this->column_data_implode(',', $d, 'VALUES', true, $table_def['fd']);
1750 1749
 				}
1751 1750
 				else
1752 1751
 				{
1753
-					$sql .= ",\n(".$this->column_data_implode(',',$d,false,true,$table_def['fd']).')';
1752
+					$sql .= ",\n(".$this->column_data_implode(',', $d, false, true, $table_def['fd']).')';
1754 1753
 				}
1755 1754
 			}
1756 1755
 			$sql .= $sql_append;
1757 1756
 		}
1758 1757
 		elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray)	// eg. MaxDB
1759 1758
 		{
1760
-			$this->Link_ID->Param(false);	// reset param-counter
1759
+			$this->Link_ID->Param(false); // reset param-counter
1761 1760
 			$cols = array_keys($data);
1762
-			foreach($cols as $k => $col)
1761
+			foreach ($cols as $k => $col)
1763 1762
 			{
1764 1763
 				if (!isset($table_def['fd'][$col]))	// ignore columns not in this table
1765 1764
 				{
@@ -1768,7 +1767,7 @@  discard block
 block discarded – undo
1768 1767
 				}
1769 1768
 				$params[] = $this->Link_ID->Param($col);
1770 1769
 			}
1771
-			$sql = "$cmd INTO $table (".implode(',',$cols).') VALUES ('.implode(',',$params).')'.$sql_append;
1770
+			$sql = "$cmd INTO $table (".implode(',', $cols).') VALUES ('.implode(',', $params).')'.$sql_append;
1772 1771
 			// check if we already prepared that statement
1773 1772
 			if (!isset($this->prepared_sql[$sql]))
1774 1773
 			{
@@ -1779,10 +1778,10 @@  discard block
 block discarded – undo
1779 1778
 		}
1780 1779
 		else
1781 1780
 		{
1782
-			$sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append;
1781
+			$sql = "$cmd INTO $table ".$this->column_data_implode(',', $data, 'VALUES', true, $table_def['fd']).$sql_append;
1783 1782
 		}
1784
-		if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n";
1785
-		return $this->query($sql,$line,$file,0,-1,$inputarr);
1783
+		if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app') sql='$sql'</p>\n";
1784
+		return $this->query($sql, $line, $file, 0, -1, $inputarr);
1786 1785
 	}
1787 1786
 
1788 1787
 	/**
@@ -1800,10 +1799,10 @@  discard block
 block discarded – undo
1800 1799
 	* @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1801 1800
 	* @return ADORecordSet or false, if the query fails
1802 1801
 	*/
1803
-	function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False)
1802
+	function update($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False)
1804 1803
 	{
1805
-		if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n";
1806
-		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
1804
+		if ($this->Debug) echo "<p>db::update('$table',".print_r($data, true).','.print_r($where, true).",$line,$file,'$app')</p>\n";
1805
+		if (!$table_def) $table_def = $this->get_table_definitions($app, $table);
1807 1806
 
1808 1807
 		$blobs2update = array();
1809 1808
 		// SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update
@@ -1814,7 +1813,7 @@  discard block
 block discarded – undo
1814 1813
 			case 'maxdb':
1815 1814
 				if ($use_prepared_statement) break;
1816 1815
 				// check if data contains any LONG columns
1817
-				foreach($data as $col => $val)
1816
+				foreach ($data as $col => $val)
1818 1817
 				{
1819 1818
 					switch ($table_def['fd'][$col]['type'])
1820 1819
 					{
@@ -1828,7 +1827,7 @@  discard block
 block discarded – undo
1828 1827
 				}
1829 1828
 				break;
1830 1829
 		}
1831
-		$where_str = $this->column_data_implode(' AND ',$where,True,true,$table_def['fd']);
1830
+		$where_str = $this->column_data_implode(' AND ', $where, True, true, $table_def['fd']);
1832 1831
 
1833 1832
 		if (self::$tablealiases && isset(self::$tablealiases[$table]))
1834 1833
 		{
@@ -1839,13 +1838,13 @@  discard block
 block discarded – undo
1839 1838
 			$inputarr = false;
1840 1839
 			if ($use_prepared_statement && $this->Link_ID->_bindInputArray)	// eg. MaxDB
1841 1840
 			{
1842
-				$this->Link_ID->Param(false);	// reset param-counter
1843
-				foreach($data as $col => $val)
1841
+				$this->Link_ID->Param(false); // reset param-counter
1842
+				foreach ($data as $col => $val)
1844 1843
 				{
1845
-					if (!isset($table_def['fd'][$col])) continue;	// ignore columns not in this table
1844
+					if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table
1846 1845
 					$params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col);
1847 1846
 				}
1848
-				$sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str;
1847
+				$sql = "UPDATE $table SET ".implode(',', $params).' WHERE '.$where_str;
1849 1848
 				// check if we already prepared that statement
1850 1849
 				if (!isset($this->prepared_sql[$sql]))
1851 1850
 				{
@@ -1857,19 +1856,19 @@  discard block
 block discarded – undo
1857 1856
 			else
1858 1857
 			{
1859 1858
 				$sql = "UPDATE $table SET ".
1860
-					$this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str;
1859
+					$this->column_data_implode(',', $data, True, true, $table_def['fd']).' WHERE '.$where_str;
1861 1860
 			}
1862
-			$ret = $this->query($sql,$line,$file,0,-1,$inputarr);
1861
+			$ret = $this->query($sql, $line, $file, 0, -1, $inputarr);
1863 1862
 			if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n";
1864 1863
 		}
1865 1864
 		// if we have any blobs to update, we do so now
1866 1865
 		if (($ret || !count($data)) && count($blobs2update))
1867 1866
 		{
1868
-			foreach($blobs2update as $col => $val)
1867
+			foreach ($blobs2update as $col => $val)
1869 1868
 			{
1870
-				$ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB');
1869
+				$ret = $this->Link_ID->UpdateBlob($table, $col, $val, $where_str, $table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB');
1871 1870
 				if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n";
1872
-				if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file);
1871
+				if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)", $line, $file);
1873 1872
 			}
1874 1873
 		}
1875 1874
 		return $ret;
@@ -1888,18 +1887,18 @@  discard block
 block discarded – undo
1888 1887
 	* @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline
1889 1888
 	* @return ADORecordSet or false, if the query fails
1890 1889
 	*/
1891
-	function delete($table,$where,$line,$file,$app=False,$table_def=False)
1890
+	function delete($table, $where, $line, $file, $app = False, $table_def = False)
1892 1891
 	{
1893
-		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
1892
+		if (!$table_def) $table_def = $this->get_table_definitions($app, $table);
1894 1893
 
1895 1894
 		if (self::$tablealiases && isset(self::$tablealiases[$table]))
1896 1895
 		{
1897 1896
 			$table = self::$tablealiases[$table];
1898 1897
 		}
1899 1898
 		$sql = "DELETE FROM $table WHERE ".
1900
-			$this->column_data_implode(' AND ',$where,True,False,$table_def['fd']);
1899
+			$this->column_data_implode(' AND ', $where, True, False, $table_def['fd']);
1901 1900
 
1902
-		return $this->query($sql,$line,$file);
1901
+		return $this->query($sql, $line, $file);
1903 1902
 	}
1904 1903
 
1905 1904
 	/**
@@ -1922,12 +1921,12 @@  discard block
 block discarded – undo
1922 1921
 	 */
1923 1922
 	function expression($table_def/*,$args, ...*/)
1924 1923
 	{
1925
-		if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def);
1924
+		if (!is_array($table_def)) $table_def = $this->get_table_definitions(true, $table_def);
1926 1925
 		$sql = '';
1927 1926
 		$ignore_next = 0;
1928
-		foreach(func_get_args() as $n => $arg)
1927
+		foreach (func_get_args() as $n => $arg)
1929 1928
 		{
1930
-			if ($n < 1) continue;	// table-name
1929
+			if ($n < 1) continue; // table-name
1931 1930
 
1932 1931
 			if ($ignore_next)
1933 1932
 			{
@@ -1936,7 +1935,7 @@  discard block
 block discarded – undo
1936 1935
 			}
1937 1936
 			if (is_null($arg)) $arg = False;
1938 1937
 
1939
-			switch(gettype($arg))
1938
+			switch (gettype($arg))
1940 1939
 			{
1941 1940
 				case 'string':
1942 1941
 					$sql .= $arg;
@@ -1945,7 +1944,7 @@  discard block
 block discarded – undo
1945 1944
 					$ignore_next += !$arg ? 2 : 0;
1946 1945
 					break;
1947 1946
 				case 'array':
1948
-					$sql .= $this->column_data_implode(' AND ',$arg,True,False,$table_def['fd']);
1947
+					$sql .= $this->column_data_implode(' AND ', $arg, True, False, $table_def['fd']);
1949 1948
 					break;
1950 1949
 			}
1951 1950
 		}
@@ -1972,18 +1971,18 @@  discard block
 block discarded – undo
1972 1971
 	* @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM
1973 1972
 	* @return ADORecordSet or false, if the query fails
1974 1973
 	*/
1975
-	function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC)
1974
+	function select($table, $cols, $where, $line, $file, $offset = False, $append = '', $app = False, $num_rows = 0, $join = '', $table_def = False, $fetchmode = self::FETCH_ASSOC)
1976 1975
 	{
1977
-		if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n";
1976
+		if ($this->Debug) echo "<p>db::select('$table',".print_r($cols, True).",".print_r($where, True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n";
1978 1977
 
1979
-		if (!$table_def) $table_def = $this->get_table_definitions($app,$table);
1978
+		if (!$table_def) $table_def = $this->get_table_definitions($app, $table);
1980 1979
 		if (is_array($cols))
1981 1980
 		{
1982
-			$cols = implode(',',$cols);
1981
+			$cols = implode(',', $cols);
1983 1982
 		}
1984 1983
 		if (is_array($where))
1985 1984
 		{
1986
-			$where = $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']);
1985
+			$where = $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']);
1987 1986
 		}
1988 1987
 		if (self::$tablealiases && isset(self::$tablealiases[$table]))
1989 1988
 		{
@@ -1992,7 +1991,7 @@  discard block
 block discarded – undo
1992 1991
 		$sql = "SELECT $cols FROM $table $join";
1993 1992
 
1994 1993
 		// if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join
1995
-		if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where;
1994
+		if ($where) $sql .= (strpos($join, "WHERE") !== false) ? ' AND ('.$where.')' : ' WHERE '.$where;
1996 1995
 
1997 1996
 		if ($append) $sql .= ' '.$append;
1998 1997
 
@@ -2002,7 +2001,7 @@  discard block
 block discarded – undo
2002 2001
 		{
2003 2002
 			return $sql;
2004 2003
 		}
2005
-		return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode);
2004
+		return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode);
2006 2005
 	}
2007 2006
 
2008 2007
 	/**
@@ -2020,34 +2019,34 @@  discard block
 block discarded – undo
2020 2019
 	* @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM
2021 2020
 	* @return ADORecordSet or false, if the query fails
2022 2021
 	*/
2023
-	function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC)
2022
+	function union($selects, $line, $file, $order_by = '', $offset = false, $num_rows = 0, $fetchmode = self::FETCH_ASSOC)
2024 2023
 	{
2025
-		if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n";
2024
+		if ($this->Debug) echo "<p>db::union(".print_r($selects, True).",$line,$file,$order_by,$offset,$num_rows)</p>\n";
2026 2025
 
2027 2026
 		$union = array();
2028
-		foreach($selects as $select)
2027
+		foreach ($selects as $select)
2029 2028
 		{
2030
-			$union[] = call_user_func_array(array($this,'select'),array(
2029
+			$union[] = call_user_func_array(array($this, 'select'), array(
2031 2030
 				$select['table'],
2032 2031
 				$select['cols'],
2033 2032
 				$select['where'],
2034
-				false,	// line
2035
-				false,	// file
2036
-				false,	// offset
2033
+				false, // line
2034
+				false, // file
2035
+				false, // offset
2037 2036
 				$select['append'],
2038 2037
 				$select['app'],
2039
-				0,		// num_rows,
2038
+				0, // num_rows,
2040 2039
 				$select['join'],
2041 2040
 				$select['table_def'],
2042 2041
 			));
2043 2042
 		}
2044
-		$sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6);
2043
+		$sql = count($union) > 1 ? '('.implode(")\nUNION\n(", $union).')' : 'SELECT DISTINCT'.substr($union[0], 6);
2045 2044
 
2046
-		if ($order_by) $sql .=  (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by;
2045
+		if ($order_by) $sql .= (!stristr($order_by, 'ORDER BY') ? "\nORDER BY " : '').$order_by;
2047 2046
 
2048 2047
 		if ($this->Debug) echo "<p>sql='$sql'</p>";
2049 2048
 
2050
-		return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode);
2049
+		return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode);
2051 2050
 	}
2052 2051
 
2053 2052
 	/**
@@ -2057,15 +2056,15 @@  discard block
 block discarded – undo
2057 2056
 	 * @param string|array $strip
2058 2057
 	 * @return array
2059 2058
 	 */
2060
-	static function strip_array_keys($arr,$strip)
2059
+	static function strip_array_keys($arr, $strip)
2061 2060
 	{
2062 2061
 		$keys = array_keys($arr);
2063 2062
 
2064 2063
 		return array_walk($keys, function(&$v, $k, $strip)
2065 2064
 		{
2066
-			unset($k);	// not used, but required by function signature
2065
+			unset($k); // not used, but required by function signature
2067 2066
 			$v = str_replace($strip, '', $v);
2068 2067
 		}, $strip) ?
2069
-			array_combine($keys,$arr) : $arr;
2068
+			array_combine($keys, $arr) : $arr;
2070 2069
 	}
2071 2070
 }
Please login to merge, or discard this patch.
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.
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->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
 				}
@@ -616,15 +616,15 @@  discard block
 block discarded – undo
616 616
 				$import = true;
617 617
 				$data = self::csv_split($line, $cols, $blobs, $bools);
618 618
 
619
-				if ($table == 'egw_async' && in_array('##last-check-run##',$data))
619
+				if ($table == 'egw_async' && in_array('##last-check-run##', $data))
620 620
 				{
621 621
 					//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";
622 622
 					//echo 'data=<pre>'.print_r($data,true)."</pre>\n";
623 623
 					$import = false;
624 624
 				}
625
-				if (in_array($table,$this->exclude_tables))
625
+				if (in_array($table, $this->exclude_tables))
626 626
 				{
627
-					echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n";
627
+					echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.", $table)."</b></p>\n";
628 628
 					$import = false; // dont restore data of excluded tables
629 629
 				}
630 630
 				if ($import)
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 					{
634 634
 						if ($convert_to_system_charset && !$this->db->capabilities['client_encoding'])
635 635
 						{
636
-							$data = Api\Translation::convert($data,$charset);
636
+							$data = Api\Translation::convert($data, $charset);
637 637
 						}
638 638
 						if ($insert_n_rows > 1)
639 639
 						{
@@ -645,27 +645,27 @@  discard block
 block discarded – undo
645 645
 							}
646 646
 						}
647 647
 						// update existing table using given unique key in $insert_n_rows (also removing auto-id/sequence)
648
-						elseif(!is_numeric($insert_n_rows))
648
+						elseif (!is_numeric($insert_n_rows))
649 649
 						{
650 650
 							$where = array($insert_n_rows => $data[$insert_n_rows]);
651 651
 							unset($data[$insert_n_rows]);
652 652
 							if ($auto_id) unset($data[$auto_id]);
653
-							$this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]);
653
+							$this->db->insert($table, $data, $where, __LINE__, __FILE__, false, false, $this->schemas[$table]);
654 654
 						}
655 655
 						else
656 656
 						{
657 657
 							try {
658
-								$this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]);
658
+								$this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $this->schemas[$table]);
659 659
 							}
660
-							catch(Exception\InvalidSql $e) {
660
+							catch (Exception\InvalidSql $e) {
661 661
 								echo "<p>".$e->getMessage()."</p>\n";
662 662
 							}
663 663
 						}
664 664
 					}
665 665
 					else
666 666
 					{
667
-						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";
668
-						echo 'data=<pre>'.print_r($data,true)."</pre>\n";
667
+						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";
668
+						echo 'data=<pre>'.print_r($data, true)."</pre>\n";
669 669
 					}
670 670
 				}
671 671
 			}
@@ -675,14 +675,14 @@  discard block
 block discarded – undo
675 675
 			$this->insert_multiple($table, $rows, $this->schemas[$table]);
676 676
 		}
677 677
 		// updated the sequences, if the DB uses them
678
-		foreach($this->schemas as $table => $schema)
678
+		foreach ($this->schemas as $table => $schema)
679 679
 		{
680
-			foreach($schema['fd'] as $column => $definition)
680
+			foreach ($schema['fd'] as $column => $definition)
681 681
 			{
682 682
 				if ($definition['type'] == 'auto')
683 683
 				{
684
-					$this->schema_proc->UpdateSequence($table,$column);
685
-					break;	// max. one per table
684
+					$this->schema_proc->UpdateSequence($table, $column);
685
+					break; // max. one per table
686 686
 				}
687 687
 			}
688 688
 		}
@@ -705,15 +705,15 @@  discard block
 block discarded – undo
705 705
 		try {
706 706
 			$this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema);
707 707
 		}
708
-		catch(Exception\InvalidSql $e)
708
+		catch (Exception\InvalidSql $e)
709 709
 		{
710 710
 			// try inserting them one by one, ignoring doublicates
711
-			foreach($rows as $data)
711
+			foreach ($rows as $data)
712 712
 			{
713 713
 				try {
714 714
 					$this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema);
715 715
 				}
716
-				catch(Exception\InvalidSql $e) {
716
+				catch (Exception\InvalidSql $e) {
717 717
 					echo "<p>".$e->getMessage()."</p>\n";
718 718
 				}
719 719
 			}
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
 	private static function remove_dir_content($dir)
729 729
 	{
730 730
 		$list = scandir($dir);
731
-		while($file = $list[0])
731
+		while ($file = $list[0])
732 732
 		{
733
-			if(is_dir($file) && $file != '.' && $file != '..')
733
+			if (is_dir($file) && $file != '.' && $file != '..')
734 734
 			    self::remove_dir_content($dir.'/'.$file);
735
-			if(is_file($file) && $file != '.' && $file != '..')
735
+			if (is_file($file) && $file != '.' && $file != '..')
736 736
 			    unlink($dir.'/'.$file);
737 737
 			array_shift($list);
738 738
 		}
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 	 * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups
758 758
 	 * @return array
759 759
 	 */
760
-	public static function csv_split($line, $keys=null, $blobs=array(), $bools=array())
760
+	public static function csv_split($line, $keys = null, $blobs = array(), $bools = array())
761 761
 	{
762 762
 		if (function_exists('str_getcsv'))	// php5.3+
763 763
 		{
@@ -770,9 +770,9 @@  discard block
 block discarded – undo
770 770
 				'\\n'    => "\n",
771 771
 				'\\r'    => "\r")), ',', '"', '\0');
772 772
 			// replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash
773
-			foreach($fields as &$field)
773
+			foreach ($fields as &$field)
774 774
 			{
775
-				switch($field)
775
+				switch ($field)
776 776
 				{
777 777
 					case self::NULL_TOKEN:
778 778
 						$field = 'NULL';
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
 			{
790 790
 				$fields = array_combine($keys, $fields);
791 791
 				// base64-decode blob columns, if they are base64 encoded
792
-				foreach($blobs as $key)
792
+				foreach ($blobs as $key)
793 793
 				{
794 794
 					if (!is_null($fields[$key]) && ($tmp = base64_decode($fields[$key], true)) !== false)
795 795
 					{
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 					}
798 798
 				}
799 799
 				// decode bool columns, they might be 't'/'f' for old PostgreSQL backups
800
-				foreach($bools as $key)
800
+				foreach ($bools as $key)
801 801
 				{
802 802
 					$fields[$key] = Api\Db::from_bool($fields[$key]);
803 803
 				}
@@ -805,11 +805,11 @@  discard block
 block discarded – undo
805 805
 			return $fields;
806 806
 		}
807 807
 		// pre 5.3 implementation
808
-		$fields = explode(',',trim($line));
808
+		$fields = explode(',', trim($line));
809 809
 
810 810
 		$str_pending = False;
811 811
 		$n = 0;
812
-		foreach($fields as $field)
812
+		foreach ($fields as $field)
813 813
 		{
814 814
 			if ($str_pending !== False)
815 815
 			{
@@ -820,12 +820,12 @@  discard block
 block discarded – undo
820 820
 
821 821
 			if ($field[0] == '"')
822 822
 			{
823
-				if (substr($field,-1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/',$field))
823
+				if (substr($field, -1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/', $field))
824 824
 				{
825 825
 					$str_pending = $field;
826 826
 					continue;
827 827
 				}
828
-				$arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1)));
828
+				$arr[$key] = str_replace(self::BACKSLASH_TOKEN, '\\', str_replace(array('\\\\', '\\n', '\\r', '\\"'), array(self::BACKSLASH_TOKEN, "\n", "\r", '"'), substr($field, 1, -1)));
829 829
 			}
830 830
 			elseif ($keys && strlen($field) > 26)
831 831
 			{
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 	/**
848 848
 	 * escape data for csv
849 849
 	 */
850
-	public static function escape_data(&$data,$col,$defs)
850
+	public static function escape_data(&$data, $col, $defs)
851 851
 	{
852 852
 		if (is_null($data))
853 853
 		{
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
 		}
856 856
 		else
857 857
 		{
858
-			switch($defs[$col]['type'])
858
+			switch ($defs[$col]['type'])
859 859
 			{
860 860
 				case 'int':
861 861
 				case 'auto':
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 					$data = (int)Api\Db::from_bool($data);
871 871
 					break;
872 872
 				default:
873
-					$data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"';
873
+					$data = '"'.str_replace(array('\\', "\n", "\r", '"'), array('\\\\', '\\n', '\\r', '\\"'), $data).'"';
874 874
 					break;
875 875
 			}
876 876
 		}
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 	 *	default of null limits memory usage if there is no primary key, by locking table and use ROW_CHUCK
890 890
 	 * @todo use https://github.com/maennchen/ZipStream-PHP to not assemble all files in memmory
891 891
 	 */
892
-	function backup($f, $lock_table=null)
892
+	function backup($f, $lock_table = null)
893 893
 	{
894 894
 		//echo "function backup($f)<br>";	// !
895 895
 		@set_time_limit(0);
@@ -905,15 +905,15 @@  discard block
 block discarded – undo
905 905
 		$name = $this->backup_dir.'/db_backup-'.date('YmdHi');
906 906
 		$filename = $name.'.zip';
907 907
 		$zippresent = false;
908
-		if(class_exists('ZipArchive') && $this->backup_files)
908
+		if (class_exists('ZipArchive') && $this->backup_files)
909 909
 		{
910 910
 			$zip = new ZipArchive;
911
-			if(is_object($zip))
911
+			if (is_object($zip))
912 912
 			{
913 913
 				$zippresent = true;
914 914
 				//echo '-> is_object($zip); '.$filename.'<br>';	// !
915 915
 				$res = $zip->open($filename, ZipArchive::CREATE);
916
-				if($res !== TRUE)
916
+				if ($res !== TRUE)
917 917
 				{
918 918
 					//echo '   -> !$res<br>';	// !
919 919
 					return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n";
@@ -921,19 +921,19 @@  discard block
 block discarded – undo
921 921
 				$file_list = $this->get_file_list($dir);
922 922
 			}
923 923
 		}
924
-		fwrite($f,"EGroupware backup from ".date('Y-m-d H:i:s')."\n\n");
924
+		fwrite($f, "EGroupware backup from ".date('Y-m-d H:i:s')."\n\n");
925 925
 
926
-		fwrite($f,"version: $this->api_version\n\n");
926
+		fwrite($f, "version: $this->api_version\n\n");
927 927
 
928
-		fwrite($f,"charset: $this->charset\n\n");
928
+		fwrite($f, "charset: $this->charset\n\n");
929 929
 
930
-		$this->schema_backup($f);	// add the schema in a human readable form too
930
+		$this->schema_backup($f); // add the schema in a human readable form too
931 931
 
932
-		fwrite($f,"\nschema: ".json_encode($this->schemas)."\n");
932
+		fwrite($f, "\nschema: ".json_encode($this->schemas)."\n");
933 933
 
934
-		foreach($this->schemas as $table => $schema)
934
+		foreach ($this->schemas as $table => $schema)
935 935
 		{
936
-			if (in_array($table,$this->exclude_tables)) continue;	// dont backup
936
+			if (in_array($table, $this->exclude_tables)) continue; // dont backup
937 937
 
938 938
 			// do we have a primary key?
939 939
 			// --> use it to order and limit rows, to kope with rows being added during backup
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
 			do {
950 950
 				$num_rows = 0;
951 951
 				// querying only chunks for 10000 rows, to not run into memory limit on huge tables
952
-				foreach($this->db->select($table, '*',
952
+				foreach ($this->db->select($table, '*',
953 953
 					// limit by maximum primary key already received
954 954
 					empty($pk) || !$max ? false : $pk.' > '.$this->db->quote($max, $schema['fd'][$pk]['type']),
955 955
 					__LINE__, __FILE__,
@@ -960,19 +960,19 @@  discard block
 block discarded – undo
960 960
 					false, self::ROW_CHUNK) as $row)
961 961
 				{
962 962
 					if (!empty($pk)) $max = $row[$pk];
963
-					if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
963
+					if ($total === 0) fwrite($f, "\ntable: $table\n".implode(',', array_keys($row))."\n");
964 964
 
965 965
 					array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']);
966
-					fwrite($f,implode(',',$row)."\n");
966
+					fwrite($f, implode(',', $row)."\n");
967 967
 					++$total;
968 968
 					++$num_rows;
969 969
 				}
970 970
 			}
971
-			while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
971
+			while ((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
972 972
 
973 973
 			if (!$pk) $this->db->Link_ID->RollbackLock($table);
974 974
 		}
975
-		if(!$zippresent)  // save without files
975
+		if (!$zippresent)  // save without files
976 976
 		{
977 977
 			if ($this->backup_files)
978 978
 			{
@@ -987,16 +987,16 @@  discard block
 block discarded – undo
987 987
 		//echo $name.'<br>';
988 988
 		$zip->addFile($name, 'database_backup/'.basename($name));
989 989
 		$count = 1;
990
-		foreach($file_list as $file)
990
+		foreach ($file_list as $file)
991 991
 		{
992 992
 			//echo substr($file,strlen($dir)+1).'<br>';
993 993
 			//echo $file.'<br>';
994
-			$zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file);
995
-			if(($count++) == 100) { // the file descriptor limit
994
+			$zip->addFile($file, substr($file, strlen($dir) + 1)); //,substr($file);
995
+			if (($count++) == 100) { // the file descriptor limit
996 996
 				$zip->close();
997
-				if(($zip = new ZipArchive())) {
997
+				if (($zip = new ZipArchive())) {
998 998
 					$zip->open($filename);
999
-					$count =0;
999
+					$count = 0;
1000 1000
 				}
1001 1001
 			}
1002 1002
 		}
@@ -1019,17 +1019,17 @@  discard block
 block discarded – undo
1019 1019
 	{
1020 1020
 		//chdir($f);
1021 1021
 		//echo "Processing $f <br>";
1022
-		if ($path_name =='') $path_name = $f;
1022
+		if ($path_name == '') $path_name = $f;
1023 1023
 		$tlist = scandir($f);
1024 1024
 		$list = array();
1025 1025
 		$i = $cnt;
1026
-		while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1026
+		while ($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1027 1027
 		{
1028
-			if($file == '.' || $file == '..')
1028
+			if ($file == '.' || $file == '..')
1029 1029
 			{
1030 1030
 				array_shift($tlist);
1031 1031
 			}
1032
-			elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false)
1032
+			elseif ($file == 'debug.txt' && stripos($f, 'activesync') !== false)
1033 1033
 			{
1034 1034
 				// skip activesync debug.txt on backupFiles
1035 1035
 				//error_log(__METHOD__.__LINE__.'->'.$f.'/'.$file);
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
 			}
1038 1038
 			else
1039 1039
 			{
1040
-				if(is_dir($f.'/'.$file))
1040
+				if (is_dir($f.'/'.$file))
1041 1041
 				{
1042 1042
 					$nlist = $this->get_file_list($f.'/'.$file, $i);
1043 1043
 					$list += $nlist;
@@ -1058,12 +1058,12 @@  discard block
 block discarded – undo
1058 1058
 	 *
1059 1059
 	 * @param resource|boolean $f
1060 1060
 	 */
1061
-	function schema_backup($f=False)
1061
+	function schema_backup($f = False)
1062 1062
 	{
1063
-		foreach($this->adodb->MetaTables('TABLES') as $table)
1063
+		foreach ($this->adodb->MetaTables('TABLES') as $table)
1064 1064
 		{
1065
-			if ($this->system_tables && preg_match($this->system_tables,$table) ||
1066
-				$this->egw_tables && !preg_match($this->egw_tables,$table))
1065
+			if ($this->system_tables && preg_match($this->system_tables, $table) ||
1066
+				$this->egw_tables && !preg_match($this->egw_tables, $table))
1067 1067
 			{
1068 1068
 				continue;
1069 1069
 			}
@@ -1082,17 +1082,17 @@  discard block
 block discarded – undo
1082 1082
 			}
1083 1083
 		}
1084 1084
 		$def = "\t\$phpgw_baseline = ";
1085
-		$def .= self::write_array($this->schemas,1);
1085
+		$def .= self::write_array($this->schemas, 1);
1086 1086
 		$def .= ";\n";
1087 1087
 
1088 1088
 		if ($f)
1089 1089
 		{
1090
-			fwrite($f,$def);
1090
+			fwrite($f, $def);
1091 1091
 		}
1092 1092
 		else
1093 1093
 		{
1094 1094
 			$def = "<?php\n\t/* EGroupware schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def;
1095
-			Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def));
1095
+			Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php', 'text/plain', bytes($def));
1096 1096
 			echo $def;
1097 1097
 		}
1098 1098
 	}
@@ -1102,9 +1102,9 @@  discard block
 block discarded – undo
1102 1102
 	 *
1103 1103
 	 * copied from etemplate/inc/class.db_tools.inc.php
1104 1104
 	 */
1105
-	private static function write_array($arr,$depth,$parent='')
1105
+	private static function write_array($arr, $depth, $parent = '')
1106 1106
 	{
1107
-		if (in_array($parent,array('pk','fk','ix','uc')))
1107
+		if (in_array($parent, array('pk', 'fk', 'ix', 'uc')))
1108 1108
 		{
1109 1109
 			$depth = 0;
1110 1110
 		}
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 		$def = "array($tabs".($tabs ? "\t" : '');
1121 1121
 
1122 1122
 		$n = 0;
1123
-		foreach($arr as $key => $val)
1123
+		foreach ($arr as $key => $val)
1124 1124
 		{
1125 1125
 			if (!is_int($key))
1126 1126
 			{
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
 			}
1129 1129
 			if (is_array($val))
1130 1130
 			{
1131
-				$def .= self::write_array($val,$parent == 'fd' ? 0 : $depth,$key);
1131
+				$def .= self::write_array($val, $parent == 'fd' ? 0 : $depth, $key);
1132 1132
 			}
1133 1133
 			else
1134 1134
 			{
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
 					$def .= "'$val'";
1142 1142
 				}
1143 1143
 			}
1144
-			if ($n < count($arr)-1)
1144
+			if ($n < count($arr) - 1)
1145 1145
 			{
1146 1146
 				$def .= ",$tabs".($tabs ? "\t" : '');
1147 1147
 			}
Please login to merge, or discard this patch.
Braces   +127 added lines, -35 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)
@@ -418,7 +439,9 @@  discard block
 block discarded – undo
418 439
 		}
419 440
 		$this->db_restore($f, $insert_n_rows);
420 441
 
421
-		if ($convert_to_system_charset)	// store the changed charset
442
+		if ($convert_to_system_charset)
443
+		{
444
+			// store the changed charset
422 445
 		{
423 446
 			$this->db->insert(Api\Config::TABLE, array(
424 447
 				'config_value' => $this->schema_proc->system_charset,
@@ -427,6 +450,7 @@  discard block
 block discarded – undo
427 450
 				'config_name' => 'system_charset',
428 451
 			),__LINE__,__FILE__);
429 452
 		}
453
+		}
430 454
 		// restore protected system config
431 455
 		if ($protect_system_config)
432 456
 		{
@@ -521,7 +545,10 @@  discard block
 block discarded – undo
521 545
 		{
522 546
 			$line = trim(fgets($f)); ++$n;
523 547
 
524
-			if (empty($line)) continue;
548
+			if (empty($line))
549
+			{
550
+				continue;
551
+			}
525 552
 
526 553
 			if (substr($line,0,9) == 'version: ')
527 554
 			{
@@ -574,31 +601,49 @@  discard block
 block discarded – undo
574 601
 			}
575 602
 			if (substr($line,0,7) == 'table: ')
576 603
 			{
577
-				if ($rows)	// flush pending rows of last table
604
+				if ($rows)
605
+				{
606
+					// flush pending rows of last table
578 607
 				{
579 608
 					$this->insert_multiple($table, $rows, $this->schemas[$table]);
580 609
 				}
610
+				}
581 611
 				$rows = array();
582 612
 				$table = substr($line,7);
583
-				if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table);
613
+				if (!isset($this->schemas[$table]))
614
+				{
615
+					$this->schemas[$table] = $this->db->get_table_definitions(true, $table);
616
+				}
584 617
 				$auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null;
585 618
 
586 619
 				$cols = self::csv_split($line=fgets($f)); ++$n;
587 620
 				$blobs = array();
588 621
 				foreach($this->schemas[$table]['fd'] as $col => $data)
589 622
 				{
590
-					if ($data['type'] == 'blob') $blobs[] = $col;
623
+					if ($data['type'] == 'blob')
624
+					{
625
+						$blobs[] = $col;
626
+					}
591 627
 				}
592 628
 				// check if we have an old PostgreSQL backup useing 't'/'f' for bool values
593 629
 				// --> convert them to MySQL and our new PostgreSQL format of 1/0
594 630
 				$bools = array();
595 631
 				foreach($this->schemas[$table]['fd'] as $col => $def)
596 632
 				{
597
-					if ($def['type'] === 'bool') $bools[] = $col;
633
+					if ($def['type'] === 'bool')
634
+					{
635
+						$bools[] = $col;
636
+					}
637
+				}
638
+				if ($table == 'egw_cal_dates')
639
+				{
640
+					error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd']));
598 641
 				}
599
-				if ($table == 'egw_cal_dates') error_log(__METHOD__."() $table: bools=".array2string($bools).", schema[fd]=".array2string($this->schemas[$table]['fd']));
600 642
 
601
-				if (feof($f)) break;
643
+				if (feof($f))
644
+				{
645
+					break;
646
+				}
602 647
 				continue;
603 648
 			}
604 649
 			if ($convert_to_system_charset && !$this->db->capabilities['client_encoding'])
@@ -611,9 +656,12 @@  discard block
 block discarded – undo
611 656
 					}
612 657
 				}
613 658
 			}
614
-			if ($table)	// do we already reached the data part
659
+			if ($table)
660
+			{
661
+				// do we already reached the data part
615 662
 			{
616 663
 				$import = true;
664
+			}
617 665
 				$data = self::csv_split($line, $cols, $blobs, $bools);
618 666
 
619 667
 				if ($table == 'egw_async' && in_array('##last-check-run##',$data))
@@ -649,7 +697,10 @@  discard block
 block discarded – undo
649 697
 						{
650 698
 							$where = array($insert_n_rows => $data[$insert_n_rows]);
651 699
 							unset($data[$insert_n_rows]);
652
-							if ($auto_id) unset($data[$auto_id]);
700
+							if ($auto_id)
701
+							{
702
+								unset($data[$auto_id]);
703
+							}
653 704
 							$this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]);
654 705
 						}
655 706
 						else
@@ -670,10 +721,13 @@  discard block
 block discarded – undo
670 721
 				}
671 722
 			}
672 723
 		}
673
-		if ($rows)	// flush pending rows
724
+		if ($rows)
725
+		{
726
+			// flush pending rows
674 727
 		{
675 728
 			$this->insert_multiple($table, $rows, $this->schemas[$table]);
676 729
 		}
730
+		}
677 731
 		// updated the sequences, if the DB uses them
678 732
 		foreach($this->schemas as $table => $schema)
679 733
 		{
@@ -731,9 +785,13 @@  discard block
 block discarded – undo
731 785
 		while($file = $list[0])
732 786
 		{
733 787
 			if(is_dir($file) && $file != '.' && $file != '..')
734
-			    self::remove_dir_content($dir.'/'.$file);
788
+			{
789
+						    self::remove_dir_content($dir.'/'.$file);
790
+			}
735 791
 			if(is_file($file) && $file != '.' && $file != '..')
736
-			    unlink($dir.'/'.$file);
792
+			{
793
+						    unlink($dir.'/'.$file);
794
+			}
737 795
 			array_shift($list);
738 796
 		}
739 797
 		//rmdir($dir);  // dont remove own dir
@@ -759,7 +817,9 @@  discard block
 block discarded – undo
759 817
 	 */
760 818
 	public static function csv_split($line, $keys=null, $blobs=array(), $bools=array())
761 819
 	{
762
-		if (function_exists('str_getcsv'))	// php5.3+
820
+		if (function_exists('str_getcsv'))
821
+		{
822
+			// php5.3+
763 823
 		{
764 824
 			// we need to take care of literal "NULL" values, replacing them we a special token as str_getcsv removes enclosures around strings
765 825
 			// str_getcsv uses '""' for '"' instead of '\\"' and does not unescape '\\n', '\\r' or '\\\\' (two backslashes)
@@ -769,6 +829,7 @@  discard block
 block discarded – undo
769 829
 				'\\"'    => '""',
770 830
 				'\\n'    => "\n",
771 831
 				'\\r'    => "\r")), ',', '"', '\0');
832
+		}
772 833
 			// replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash
773 834
 			foreach($fields as &$field)
774 835
 			{
@@ -785,9 +846,12 @@  discard block
 block discarded – undo
785 846
 						break;
786 847
 				}
787 848
 			}
788
-			if ($keys)	// if string keys are to be used --> combine keys and values
849
+			if ($keys)
850
+			{
851
+				// if string keys are to be used --> combine keys and values
789 852
 			{
790 853
 				$fields = array_combine($keys, $fields);
854
+			}
791 855
 				// base64-decode blob columns, if they are base64 encoded
792 856
 				foreach($blobs as $key)
793 857
 				{
@@ -933,7 +997,11 @@  discard block
 block discarded – undo
933 997
 
934 998
 		foreach($this->schemas as $table => $schema)
935 999
 		{
936
-			if (in_array($table,$this->exclude_tables)) continue;	// dont backup
1000
+			if (in_array($table,$this->exclude_tables))
1001
+			{
1002
+				continue;
1003
+			}
1004
+			// dont backup
937 1005
 
938 1006
 			// do we have a primary key?
939 1007
 			// --> use it to order and limit rows, to kope with rows being added during backup
@@ -959,8 +1027,14 @@  discard block
 block discarded – undo
959 1027
 					empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC',
960 1028
 					false, self::ROW_CHUNK) as $row)
961 1029
 				{
962
-					if (!empty($pk)) $max = $row[$pk];
963
-					if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
1030
+					if (!empty($pk))
1031
+					{
1032
+						$max = $row[$pk];
1033
+					}
1034
+					if ($total === 0)
1035
+					{
1036
+						fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n");
1037
+					}
964 1038
 
965 1039
 					array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']);
966 1040
 					fwrite($f,implode(',',$row)."\n");
@@ -970,17 +1044,26 @@  discard block
 block discarded – undo
970 1044
 			}
971 1045
 			while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
972 1046
 
973
-			if (!$pk) $this->db->Link_ID->RollbackLock($table);
1047
+			if (!$pk)
1048
+			{
1049
+				$this->db->Link_ID->RollbackLock($table);
1050
+			}
974 1051
 		}
975
-		if(!$zippresent)  // save without files
1052
+		if(!$zippresent)
1053
+		{
1054
+			// save without files
976 1055
 		{
977 1056
 			if ($this->backup_files)
978 1057
 			{
979 1058
 				echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>';
1059
+		}
980 1060
 			}
981 1061
 
982 1062
 		    fclose($f);
983
-		    if (file_exists($name)) unlink($name);
1063
+		    if (file_exists($name))
1064
+		    {
1065
+		    	unlink($name);
1066
+		    }
984 1067
 			return TRUE;
985 1068
 		}
986 1069
 		// save files ....
@@ -992,9 +1075,12 @@  discard block
 block discarded – undo
992 1075
 			//echo substr($file,strlen($dir)+1).'<br>';
993 1076
 			//echo $file.'<br>';
994 1077
 			$zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file);
995
-			if(($count++) == 100) { // the file descriptor limit
1078
+			if(($count++) == 100)
1079
+			{
1080
+// the file descriptor limit
996 1081
 				$zip->close();
997
-				if(($zip = new ZipArchive())) {
1082
+				if(($zip = new ZipArchive()))
1083
+				{
998 1084
 					$zip->open($filename);
999 1085
 					$count =0;
1000 1086
 				}
@@ -1019,15 +1105,21 @@  discard block
 block discarded – undo
1019 1105
 	{
1020 1106
 		//chdir($f);
1021 1107
 		//echo "Processing $f <br>";
1022
-		if ($path_name =='') $path_name = $f;
1108
+		if ($path_name =='')
1109
+		{
1110
+			$path_name = $f;
1111
+		}
1023 1112
 		$tlist = scandir($f);
1024 1113
 		$list = array();
1025 1114
 		$i = $cnt;
1026
-		while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list
1115
+		while($file = $tlist[0])
1116
+		{
1117
+			// remove all '.' and '..' and transfer to $list
1027 1118
 		{
1028 1119
 			if($file == '.' || $file == '..')
1029 1120
 			{
1030 1121
 				array_shift($tlist);
1122
+		}
1031 1123
 			}
1032 1124
 			elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false)
1033 1125
 			{
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.
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
 		$table_def = $this->GetTableDefinition($sTableName);
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
 	/**
@@ -371,12 +371,12 @@  discard block
 block discarded – undo
371 371
 		{
372 372
 			$table_def = $this->GetTableDefinition($sOldTableName);
373 373
 
374
-			if ($this->_PostgresHasOldSequence($sOldTableName,True) || count($table_def['pk']) ||
374
+			if ($this->_PostgresHasOldSequence($sOldTableName, True) || count($table_def['pk']) ||
375 375
 				count($table_def['ix']) || count($table_def['uc']))
376 376
 			{
377 377
 				if ($this->adodb->BeginTrans() &&
378
-					$this->CreateTable($sNewTableName,$table_def,True) &&
379
-					$this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName",__LINE__,__FILE__) &&
378
+					$this->CreateTable($sNewTableName, $table_def, True) &&
379
+					$this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName", __LINE__, __FILE__) &&
380 380
 					$this->DropTable($sOldTableName))
381 381
 				{
382 382
 					$this->adodb->CommitTrans();
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 		}
389 389
 		$aSql = $this->dict->RenameTableSQL($sOldTableName, $sNewTableName);
390 390
 
391
-		return $this->ExecuteSQLArray($aSql,2,'RenameTableSQL(%1,%2) sql=%3',False,$sOldTableName,$sNewTableName,$aSql);
391
+		return $this->ExecuteSQLArray($aSql, 2, 'RenameTableSQL(%1,%2) sql=%3', False, $sOldTableName, $sNewTableName, $aSql);
392 392
 	}
393 393
 
394 394
 	/**
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	 * @param bool $preserveValue
399 399
 	 * @return boolean|string sequence-name or false
400 400
 	 */
401
-	function _PostgresHasOldSequence($sTableName,$preserveValue=False)
401
+	function _PostgresHasOldSequence($sTableName, $preserveValue = False)
402 402
 	{
403 403
 		if ($this->sType != 'pgsql') return false;
404 404
 
@@ -406,14 +406,14 @@  discard block
 block discarded – undo
406 406
 		$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");
407 407
 
408 408
 		$matches = null;
409
-		if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches))
409
+		if ($seq && preg_match('/^nextval\(\'(.*)\'/', $seq, $matches))
410 410
 		{
411
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
411
+			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]);
412 412
 			return $matches[1];
413 413
 		}
414
-		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches))
414
+		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/', $seq2, $matches))
415 415
 		{
416
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
416
+			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]);
417 417
 			return $matches[1];
418 418
 		}
419 419
 		return false;
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 			// only drop sequence, if there is no dependency on it
433 433
 			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'"))
434 434
 			{
435
-				$this->query('DROP SEQUENCE '.$seq,__LINE__,__FILE__);
435
+				$this->query('DROP SEQUENCE '.$seq, __LINE__, __FILE__);
436 436
 			}
437 437
 		}
438 438
 	}
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 		$table_def = $this->GetTableDefinition($sTableName);
451 451
 
452 452
 		// PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long
453
-		if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
453
+		if ($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
454 454
 			in_array($aColumnDef['type'], array('varchar', 'ascii')) &&
455 455
 			$table_def['fd'][$sColumnName]['precision'] > $aColumnDef['precision'])
456 456
 		{
@@ -465,12 +465,12 @@  discard block
 block discarded – undo
465 465
 		}
466 466
 		$table_def['fd'][$sColumnName] = $aColumnDef;
467 467
 
468
-		$aSql = $this->dict->AlterColumnSQL($sTableName,$ado_col = $this->_egw2adodb_columndef(array(
468
+		$aSql = $this->dict->AlterColumnSQL($sTableName, $ado_col = $this->_egw2adodb_columndef(array(
469 469
 				'fd' => array($sColumnName => $aColumnDef),
470 470
 				'pk' => array(),
471
-			)),$ado_table=$this->_egw2adodb_columndef($table_def));
471
+			)), $ado_table = $this->_egw2adodb_columndef($table_def));
472 472
 
473
-		return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$ado_col,$ado_table,$aSql);
473
+		return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $ado_col, $ado_table, $aSql);
474 474
 	}
475 475
 
476 476
 	/**
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 		}
493 493
 		else
494 494
 		{
495
-			foreach($table_def['fd'] as $col => $def)
495
+			foreach ($table_def['fd'] as $col => $def)
496 496
 			{
497 497
 				if (strtolower($col) == strtolower($sOldColumnName))
498 498
 				{
@@ -506,9 +506,9 @@  discard block
 block discarded – undo
506 506
 				'pk' => array(),
507 507
 			));
508 508
 
509
-		$aSql = $this->dict->RenameColumnSQL($sTableName,$sOldColumnName,$sNewColumnName,$col_def);
509
+		$aSql = $this->dict->RenameColumnSQL($sTableName, $sOldColumnName, $sNewColumnName, $col_def);
510 510
 
511
-		return $this->ExecuteSQLArray($aSql,2,'RenameColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sOldColumnName, $sNewColumnName,$aSql);
511
+		return $this->ExecuteSQLArray($aSql, 2, 'RenameColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sOldColumnName, $sNewColumnName, $aSql);
512 512
 	}
513 513
 
514 514
 	/**
@@ -521,12 +521,12 @@  discard block
 block discarded – undo
521 521
 	 */
522 522
 	function AddColumn($sTableName, $sColumnName, $aColumnDef)
523 523
 	{
524
-		$aSql = $this->dict->AddColumnSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef(array(
524
+		$aSql = $this->dict->AddColumnSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef(array(
525 525
 				'fd' => array($sColumnName => $aColumnDef),
526 526
 				'pk' => array(),
527 527
 			)));
528 528
 
529
-		return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName, $aColumnDef,$aSql);
529
+		return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $aColumnDef, $aSql);
530 530
 	}
531 531
 
532 532
 	/**
@@ -539,23 +539,23 @@  discard block
 block discarded – undo
539 539
 	 * @param string $sIdxName ='' name of the index, if not given (default) its created automaticaly
540 540
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
541 541
 	 */
542
-	function CreateIndex($sTableName,$aColumnNames,$bUnique=false,$options='',$sIdxName='')
542
+	function CreateIndex($sTableName, $aColumnNames, $bUnique = false, $options = '', $sIdxName = '')
543 543
 	{
544 544
 		// remove length limits from column names, if DB type is NOT MySQL
545 545
 		if ($this->sType != 'mysql')
546 546
 		{
547
-			$aColumnNames = preg_replace('/ *\(\d+\)$/','',$aColumnNames);
547
+			$aColumnNames = preg_replace('/ *\(\d+\)$/', '', $aColumnNames);
548 548
 		}
549 549
 		if (!$sIdxName || is_numeric($sIdxName))
550 550
 		{
551
-			$sIdxName = $this->_index_name($sTableName,$aColumnNames);
551
+			$sIdxName = $this->_index_name($sTableName, $aColumnNames);
552 552
 		}
553 553
 		if (!is_array($options)) $options = $options ? array($options) : array();
554 554
 		if ($bUnique) $options[] = 'UNIQUE';
555 555
 
556
-		$aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options);
556
+		$aSql = $this->dict->CreateIndexSQL($sIdxName, $sTableName, $aColumnNames, $options);
557 557
 
558
-		return $this->ExecuteSQLArray($aSql,2,'CreateIndexSQL(%1,%2,%3,%4) sql=%5',False,$sTableName,$aColumnNames,$options,$sIdxName,$aSql);
558
+		return $this->ExecuteSQLArray($aSql, 2, 'CreateIndexSQL(%1,%2,%3,%4) sql=%5', False, $sTableName, $aColumnNames, $options, $sIdxName, $aSql);
559 559
 	}
560 560
 
561 561
 	/**
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 	 * @param array|string $aColumnNames columns of the index or the name of the index
566 566
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
567 567
 	 */
568
-	function DropIndex($sTableName,$aColumnNames)
568
+	function DropIndex($sTableName, $aColumnNames)
569 569
 	{
570 570
 		if (is_array($aColumnNames))
571 571
 		{
@@ -575,13 +575,13 @@  discard block
 block discarded – undo
575 575
 			{
576 576
 				// if MetaIndexes is not availible for the DB, we try the name the index was created with
577 577
 				// this fails if one of the columns have been renamed
578
-				$sIdxName = $this->_index_name($sTableName,$aColumnNames);
578
+				$sIdxName = $this->_index_name($sTableName, $aColumnNames);
579 579
 			}
580 580
 			else
581 581
 			{
582
-				foreach($indexes as $idx => $idx_data)
582
+				foreach ($indexes as $idx => $idx_data)
583 583
 				{
584
-					if (strtolower(implode(':',$idx_data['columns'])) == implode(':',$aColumnNames))
584
+					if (strtolower(implode(':', $idx_data['columns'])) == implode(':', $aColumnNames))
585 585
 					{
586 586
 						$sIdxName = $idx;
587 587
 						break;
@@ -593,13 +593,13 @@  discard block
 block discarded – undo
593 593
 		{
594 594
 			$sIdxName = $aColumnNames;
595 595
 		}
596
-		if(!$sIdxName)
596
+		if (!$sIdxName)
597 597
 		{
598 598
 			return True;
599 599
 		}
600
-		$aSql = $this->dict->DropIndexSQL($sIdxName,$sTableName);
600
+		$aSql = $this->dict->DropIndexSQL($sIdxName, $sTableName);
601 601
 
602
-		return $this->ExecuteSQLArray($aSql,2,'DropIndexSQL(%1(%2),%3) sql=%4',False,$sIdxName,$aColumnNames,$sTableName,$aSql);
602
+		return $this->ExecuteSQLArray($aSql, 2, 'DropIndexSQL(%1(%2),%3) sql=%4', False, $sIdxName, $aColumnNames, $sTableName, $aSql);
603 603
 	}
604 604
 
605 605
 	/**
@@ -607,22 +607,22 @@  discard block
 block discarded – undo
607 607
 	 * @param string $sTableName table-name
608 608
 	 * @param string $sColumnName column-name, which default is set to nextval()
609 609
 	 */
610
-	function UpdateSequence($sTableName,$sColumnName)
610
+	function UpdateSequence($sTableName, $sColumnName)
611 611
 	{
612
-		switch($this->sType)
612
+		switch ($this->sType)
613 613
 		{
614 614
 			case 'pgsql':
615 615
 				// identify the sequence name, ADOdb uses a different name or it might be renamed
616 616
 				$columns = $this->dict->MetaColumns($sTableName);
617 617
 				$seq_name = 'seq_'.$sTableName;
618 618
 				$matches = null;
619
-				if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$columns[strtoupper($sColumnName)]->default_value,$matches))
619
+				if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $columns[strtoupper($sColumnName)]->default_value, $matches))
620 620
 				{
621 621
 					$seq_name = $matches[1];
622 622
 				}
623 623
 				$sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName";
624
-				if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
625
-				return $this->query($sql,__LINE__,__FILE__);
624
+				if ($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
625
+				return $this->query($sql, __LINE__, __FILE__);
626 626
 		}
627 627
 		return True;
628 628
 	}
@@ -639,9 +639,9 @@  discard block
 block discarded – undo
639 639
 	 * @param array $aTableDef eGW table-defintion
640 640
 	 * @param array|boolean $aDefaults array with default for the colums during copying, values are either (old) column-names or quoted string-literals
641 641
 	 */
642
-	function RefreshTable($sTableName, $aTableDef, $aDefaults=False)
642
+	function RefreshTable($sTableName, $aTableDef, $aDefaults = False)
643 643
 	{
644
-		if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; }
644
+		if ($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef, False).")\n"; }
645 645
 
646 646
 		$old_table_def = $this->GetTableDefinition($sTableName);
647 647
 
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 
651 651
 		$select = array();
652 652
 		$blob_column_included = $auto_column_included = False;
653
-		foreach($aTableDef['fd'] as $name => $data)
653
+		foreach ($aTableDef['fd'] as $name => $data)
654 654
 		{
655 655
 			// new auto column with no default or explicit NULL as default (can be an existing column too!)
656 656
 			if ($data['type'] == 'auto' &&
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 				$aDefaults && strtoupper($aDefaults[$name]) == 'NULL'))
659 659
 			{
660 660
 				$sequence_name = $sTableName.'_'.$name.'_seq';
661
-				switch($GLOBALS['egw_setup']->db->Type)
661
+				switch ($GLOBALS['egw_setup']->db->Type)
662 662
 				{
663 663
 					case 'mysql':
664 664
 						$value = 'NULL'; break;
@@ -679,25 +679,25 @@  discard block
 block discarded – undo
679 679
 				if ($this->sType == 'pgsql')			// some postgres specific code
680 680
 				{
681 681
 					// this is eg. necessary to change a varchar into an int column under postgres
682
-					if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) &&
683
-						in_array($data['type'],array('int','decimal')))
682
+					if (in_array($old_table_def['fd'][$name]['type'], array('char', 'varchar', 'text', 'blob')) &&
683
+						in_array($data['type'], array('int', 'decimal')))
684 684
 					{
685 685
 						$value = "to_number($name,'S9999999999999D99')";
686 686
 					}
687 687
 					// blobs cant be casted to text
688
-					elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
688
+					elseif ($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
689 689
 					{
690 690
 						$value = "ENCODE($value,'escape')";
691 691
 					}
692 692
 					// varchar or ascii column shortened, use substring to avoid error if current content is to long
693
-					elseif(in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) &&
693
+					elseif (in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) &&
694 694
 						in_array($data['type'], array('varchar', 'ascii')) &&
695 695
 						$old_table_def['fd'][$name]['precision'] > $data['precision'])
696 696
 					{
697 697
 						$value = "SUBSTRING($value FROM 1 FOR ".(int)$data['precision'].')';
698 698
 					}
699 699
 					// cast everything which is a different type
700
-					elseif($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type'])))
700
+					elseif ($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type'])))
701 701
 					{
702 702
 						$value = "CAST($value AS $type_translated)";
703 703
 					}
@@ -710,42 +710,42 @@  discard block
 block discarded – undo
710 710
 					$value = 'NULL';
711 711
 				}
712 712
 				// some stuff is NOT to be quoted
713
-				elseif (in_array(strtoupper($data['default']),array('CURRENT_TIMESTAMP','CURRENT_DATE','NULL','NOW()')))
713
+				elseif (in_array(strtoupper($data['default']), array('CURRENT_TIMESTAMP', 'CURRENT_DATE', 'NULL', 'NOW()')))
714 714
 				{
715 715
 					$value = $data['default'];
716 716
 				}
717 717
 				else
718 718
 				{
719
-					$value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '',$data['type']);
719
+					$value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '', $data['type']);
720 720
 				}
721 721
 				if ($this->sType == 'pgsql')
722 722
 				{
723 723
 					// fix for postgres error "no '<' operator for type 'unknown'"
724
-					if(($type_translated = $this->TranslateType($data['type'])))
724
+					if (($type_translated = $this->TranslateType($data['type'])))
725 725
 					{
726 726
 						$value = "CAST($value AS $type_translated)";
727 727
 					}
728 728
 				}
729 729
 			}
730
-			$blob_column_included = $blob_column_included || in_array($data['type'],array('blob','text','longtext'));
730
+			$blob_column_included = $blob_column_included || in_array($data['type'], array('blob', 'text', 'longtext'));
731 731
 			$auto_column_included = $auto_column_included || $data['type'] == 'auto';
732 732
 			$select[] = $value;
733 733
 		}
734 734
 
735 735
 		$extra = '';
736 736
 		$distinct = 'DISTINCT';
737
-		switch($this->sType)
737
+		switch ($this->sType)
738 738
 		{
739 739
 			case 'mssql':
740 740
 				if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n";
741
-				if ($blob_column_included) $distinct = '';	// no distinct on blob-columns
741
+				if ($blob_column_included) $distinct = ''; // no distinct on blob-columns
742 742
 				break;
743 743
 		}
744 744
 		// because of all the trouble with sequences and indexes in the global namespace,
745 745
 		// we use an additional temp. table for postgres and not rename the existing one, but drop it.
746 746
 		if ($this->sType == 'pgsql')
747 747
 		{
748
-			$Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName",__LINE__,__FILE__) &&
748
+			$Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName", __LINE__, __FILE__) &&
749 749
 				$this->DropTable($sTableName);
750 750
 		}
751 751
 		else
@@ -755,12 +755,12 @@  discard block
 block discarded – undo
755 755
 			{
756 756
 				$this->DropTable($tmp_name);
757 757
 			}
758
-			$Ok = $this->RenameTable($sTableName,$tmp_name);
758
+			$Ok = $this->RenameTable($sTableName, $tmp_name);
759 759
 		}
760
-		$Ok = $Ok && $this->CreateTable($sTableName,$aTableDef) &&
761
-			$this->m_odb->query($sql_copy_data="$extra INSERT INTO $sTableName (".
762
-				implode(',',array_keys($aTableDef['fd'])).
763
-				") SELEcT $distinct ".implode(',',$select)." FROM $tmp_name",__LINE__,__FILE__) &&
760
+		$Ok = $Ok && $this->CreateTable($sTableName, $aTableDef) &&
761
+			$this->m_odb->query($sql_copy_data = "$extra INSERT INTO $sTableName (".
762
+				implode(',', array_keys($aTableDef['fd'])).
763
+				") SELEcT $distinct ".implode(',', $select)." FROM $tmp_name", __LINE__, __FILE__) &&
764 764
 			$this->DropTable($tmp_name);
765 765
 		//error_log($sql_copy_data);
766 766
 
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 		// do we need to update the new sequences value ?
773 773
 		if (count($aTableDef['pk']) == 1 && $aTableDef['fd'][$aTableDef['pk'][0]]['type'] == 'auto')
774 774
 		{
775
-			$this->UpdateSequence($sTableName,$aTableDef['pk'][0]);
775
+			$this->UpdateSequence($sTableName, $aTableDef['pk'][0]);
776 776
 		}
777 777
 		$this->m_odb->transaction_commit();
778 778
 
@@ -795,9 +795,9 @@  discard block
 block discarded – undo
795 795
 	 * @param boolean $bOutputHTML =false should we give diagnostics, default False
796 796
 	 * @return boolean True on success, False if an (fatal) error occured
797 797
 	 */
798
-	function ExecuteScripts($aTables, $bOutputHTML=False)
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
 		}
@@ -805,20 +805,20 @@  discard block
 block discarded – undo
805 805
 		if ($this->debug) $bOutputHTML = True;
806 806
 		if ($bOutputHTML && !$this->debug) $this->debug = 2;
807 807
 
808
-		foreach($aTables as $sTableName => $aTableDef)
808
+		foreach ($aTables as $sTableName => $aTableDef)
809 809
 		{
810
-			if($this->CreateTable($sTableName, $aTableDef))
810
+			if ($this->CreateTable($sTableName, $aTableDef))
811 811
 			{
812
-				if($bOutputHTML)
812
+				if ($bOutputHTML)
813 813
 				{
814
-					echo '<br>Create Table <b>' . $sTableName . '</b>';
814
+					echo '<br>Create Table <b>'.$sTableName.'</b>';
815 815
 				}
816 816
 			}
817 817
 			else
818 818
 			{
819
-				if($bOutputHTML)
819
+				if ($bOutputHTML)
820 820
 				{
821
-					echo '<br>Create Table Failed For <b>' . $sTableName . '</b>';
821
+					echo '<br>Create Table Failed For <b>'.$sTableName.'</b>';
822 822
 				}
823 823
 
824 824
 				return False;
@@ -835,13 +835,13 @@  discard block
 block discarded – undo
835 835
 	* @deprecated use result-set returned by query/select
836 836
 	* @return string the field value
837 837
 	*/
838
-	function f($value,$strip_slashes=False)
838
+	function f($value, $strip_slashes = False)
839 839
 	{
840 840
 		if (!($this->m_odb instanceof Deprecated))
841 841
 		{
842 842
 	    	throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!');
843 843
 		}
844
-		return $this->m_odb->f($value,$strip_slashes);
844
+		return $this->m_odb->f($value, $strip_slashes);
845 845
 	}
846 846
 
847 847
 	/**
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 	* @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']
885 885
 	* @return ADORecordSet or false, if the query fails
886 886
 	*/
887
-	function query($sQuery, $line='', $file='')
887
+	function query($sQuery, $line = '', $file = '')
888 888
 	{
889 889
 		return $this->m_odb->query($sQuery, $line, $file);
890 890
 	}
@@ -901,9 +901,9 @@  discard block
 block discarded – undo
901 901
 	* @param string $app=false string with name of app, this need to be set in setup anyway!!!
902 902
 	* @return ADORecordSet or false, if the query fails
903 903
 	*/
904
-	function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false)
904
+	function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false)
905 905
 	{
906
-		return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement);
906
+		return $this->m_odb->insert($table, $data, $where, $line, $file, $app, $use_prepared_statement);
907 907
 	}
908 908
 
909 909
 	/**
@@ -914,14 +914,14 @@  discard block
 block discarded – undo
914 914
 	 * @param string $debug variable number of arguments for the debug_message functions in case of an error
915 915
 	 * @return int 2: no error, 1: errors, but continued, 0: errors aborted
916 916
 	 */
917
-	function ExecuteSqlArray($aSql,$debug_level)
917
+	function ExecuteSqlArray($aSql, $debug_level)
918 918
 	{
919 919
 		if ($this->m_odb->query_log)	// we use Db::query to log the queries
920 920
 		{
921 921
 			$retval = 2;
922
-			foreach($aSql as $sql)
922
+			foreach ($aSql as $sql)
923 923
 			{
924
-				if (!$this->m_odb->query($sql,__LINE__,__FILE__))
924
+				if (!$this->m_odb->query($sql, __LINE__, __FILE__))
925 925
 				{
926 926
 					$retval = 1;
927 927
 				}
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
 			$debug_params = func_get_args();
937 937
 			array_shift($debug_params);
938 938
 			array_shift($debug_params);
939
-			call_user_func_array(array($this,'debug_message'),$debug_params);
939
+			call_user_func_array(array($this, 'debug_message'), $debug_params);
940 940
 			if ($retval < 2 && !$this->dict->debug)
941 941
 			{
942 942
 				echo '<p><b>'.$this->adodb->ErrorMsg()."</b></p>\n";
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
 	 * @param $aColumnNames array of column-names or string with a single column-name
958 958
 	 * @return string the index-name
959 959
 	 */
960
-	function _index_name($sTableName,$aColumnNames)
960
+	function _index_name($sTableName, $aColumnNames)
961 961
 	{
962 962
 		// this code creates extrem short index-names, eg. for MaxDB
963 963
 //			if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32)
@@ -982,28 +982,28 @@  discard block
 block discarded – undo
982 982
 //				return $name;
983 983
 //			}
984 984
 		// This code creates longer index-names incl. the table-names and the used columns
985
-		$table = str_replace(array('phpgw_','egw_'),'',$sTableName);
985
+		$table = str_replace(array('phpgw_', 'egw_'), '', $sTableName);
986 986
 		// if the table-name or a part of it is repeated in the column-name, remove it there
987 987
 		$remove[] = $table.'_';
988 988
 		// also remove 3 or 4 letter shortcuts of the table- or app-name
989
-		$remove[] = substr($table,0,3).'_';
990
-		$remove[] = substr($table,0,4).'_';
989
+		$remove[] = substr($table, 0, 3).'_';
990
+		$remove[] = substr($table, 0, 4).'_';
991 991
 		// if the table-name consists of '_' limtied parts, remove occurences of these parts too
992
-		foreach (explode('_',$table) as $part)
992
+		foreach (explode('_', $table) as $part)
993 993
 		{
994 994
 			$remove[] = $part.'_';
995 995
 		}
996
-		$cols = str_replace($remove,'',$aColumnNames);
996
+		$cols = str_replace($remove, '', $aColumnNames);
997 997
 
998
-		$name = $sTableName.'_'.(is_array($cols) ? implode('_',$cols) : $cols);
998
+		$name = $sTableName.'_'.(is_array($cols) ? implode('_', $cols) : $cols);
999 999
 		// remove length limits from column names
1000
-		$name = preg_replace('/ *\(\d+\)/','',$name);
1000
+		$name = preg_replace('/ *\(\d+\)/', '', $name);
1001 1001
 
1002 1002
 		// this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle
1003 1003
 		if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 ||
1004 1004
 			strlen($name) >= 64)	// even mysql has a limit here ;-)
1005 1005
 		{
1006
-			$name = "i".substr(md5($name),0,29);
1006
+			$name = "i".substr(md5($name), 0, 29);
1007 1007
 		}
1008 1008
 		return $name;
1009 1009
 	}
@@ -1044,19 +1044,19 @@  discard block
 block discarded – undo
1044 1044
 	 * @param $param mixed a variable number of parameters, to be inserted in $msg
1045 1045
 	 *	arrays get serialized with print_r() !
1046 1046
 	 */
1047
-	function debug_message($msg,$backtrace=True)
1047
+	function debug_message($msg, $backtrace = True)
1048 1048
 	{
1049
-		for($i = 2; $i < func_num_args(); ++$i)
1049
+		for ($i = 2; $i < func_num_args(); ++$i)
1050 1050
 		{
1051 1051
 			$param = func_get_arg($i);
1052 1052
 
1053 1053
 			if (is_null($param))
1054 1054
 			{
1055
-				$param='NULL';
1055
+				$param = 'NULL';
1056 1056
 			}
1057 1057
 			else
1058 1058
 			{
1059
-				switch(gettype($param))
1059
+				switch (gettype($param))
1060 1060
 				{
1061 1061
 					case 'string':
1062 1062
 						$param = "'$param'";
@@ -1064,15 +1064,15 @@  discard block
 block discarded – undo
1064 1064
 					case 'array':
1065 1065
 					case 'object':
1066 1066
 						list(,$content) = @each($param);
1067
-						$do_pre = is_array($param) ? count($param) > 6 || is_array($content)&&count($content) : True;
1068
-						$param = ($do_pre ? '<pre>' : '').print_r($param,True).($do_pre ? '</pre>' : '');
1067
+						$do_pre = is_array($param) ? count($param) > 6 || is_array($content) && count($content) : True;
1068
+						$param = ($do_pre ? '<pre>' : '').print_r($param, True).($do_pre ? '</pre>' : '');
1069 1069
 						break;
1070 1070
 					case 'boolean':
1071 1071
 						$param = $param ? 'True' : 'False';
1072 1072
 						break;
1073 1073
 				}
1074 1074
 			}
1075
-			$msg = str_replace('%'.($i-1),$param,$msg);
1075
+			$msg = str_replace('%'.($i - 1), $param, $msg);
1076 1076
 		}
1077 1077
 		echo '<p>'.$msg."<br>\n".($backtrace ? 'Backtrace: '.function_backtrace(1)."</p>\n" : '');
1078 1078
 	}
@@ -1087,15 +1087,15 @@  discard block
 block discarded – undo
1087 1087
 	function _egw2adodb_columndef($aTableDef)
1088 1088
 	{
1089 1089
 		$ado_defs = array();
1090
-		foreach($aTableDef['fd'] as $col => $col_data)
1090
+		foreach ($aTableDef['fd'] as $col => $col_data)
1091 1091
 		{
1092 1092
 			$ado_col = False;
1093 1093
 
1094
-			switch($col_data['type'])
1094
+			switch ($col_data['type'])
1095 1095
 			{
1096 1096
 				case 'auto':
1097 1097
 					$ado_col = 'I AUTOINCREMENT NOTNULL';
1098
-					unset($col_data['nullable']);	// else we set it twice
1098
+					unset($col_data['nullable']); // else we set it twice
1099 1099
 					break;
1100 1100
 				case 'blob':
1101 1101
 					$ado_col = 'B';
@@ -1108,11 +1108,11 @@  discard block
 block discarded – undo
1108 1108
 				case 'ascii':
1109 1109
 				case 'varchar':
1110 1110
 					$ado_col = "C";
1111
-					if(0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length)
1111
+					if (0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length)
1112 1112
 					{
1113 1113
 						$ado_col .= "($col_data[precision])";
1114 1114
 					}
1115
-					if($col_data['precision'] > $this->max_varchar_length)
1115
+					if ($col_data['precision'] > $this->max_varchar_length)
1116 1116
 					{
1117 1117
 						$ado_col = 'X';
1118 1118
 					}
@@ -1124,7 +1124,7 @@  discard block
 block discarded – undo
1124 1124
 				case 'date':
1125 1125
 					$ado_col = 'D';
1126 1126
 					// allow to use now() beside current_date, as Postgres backups contain it and it's easier to remember anyway
1127
-					if (in_array($col_data['default'],array('current_date','now()')))
1127
+					if (in_array($col_data['default'], array('current_date', 'now()')))
1128 1128
 					{
1129 1129
 						$ado_col .= ' DEFDATE';
1130 1130
 						unset($col_data['default']);
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
 					break;
1141 1141
 				case 'int':
1142 1142
 					$ado_col = 'I';
1143
-					switch($col_data['precision'])
1143
+					switch ($col_data['precision'])
1144 1144
 					{
1145 1145
 						case 1:
1146 1146
 						case 2:
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 				case 'timestamp':
1160 1160
 					$ado_col = 'T';
1161 1161
 					// allow to use now() beside current_timestamp, as Postgres backups contain it and it's easier to remember anyway
1162
-					if (in_array($col_data['default'],array('current_timestamp','now()')))
1162
+					if (in_array($col_data['default'], array('current_timestamp', 'now()')))
1163 1163
 					{
1164 1164
 						$ado_col .= ' DEFTIMESTAMP';
1165 1165
 						unset($col_data['default']);
@@ -1177,17 +1177,17 @@  discard block
 block discarded – undo
1177 1177
 			}
1178 1178
 			if (isset($col_data['default']))
1179 1179
 			{
1180
-				$ado_col .= (in_array($col_data['type'],array('bool','int','decimal','float','double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : '').
1181
-					' DEFAULT '.$this->m_odb->quote($col_data['default'],$col_data['type']);
1180
+				$ado_col .= (in_array($col_data['type'], array('bool', 'int', 'decimal', 'float', 'double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : '').
1181
+					' DEFAULT '.$this->m_odb->quote($col_data['default'], $col_data['type']);
1182 1182
 			}
1183
-			if (in_array($col,$aTableDef['pk']))
1183
+			if (in_array($col, $aTableDef['pk']))
1184 1184
 			{
1185 1185
 				$ado_col .= ' PRIMARY';
1186 1186
 			}
1187
-			$ado_defs[] = $col . ' ' . $ado_col;
1187
+			$ado_defs[] = $col.' '.$ado_col;
1188 1188
 		}
1189 1189
 		//print_r($aTableDef); echo implode(",\n",$ado_defs)."\n";
1190
-		return implode(",\n",$ado_defs);
1190
+		return implode(",\n", $ado_defs);
1191 1191
 	}
1192 1192
 
1193 1193
 	/**
@@ -1203,7 +1203,7 @@  discard block
 block discarded – undo
1203 1203
 			'pk' => array(),
1204 1204
 		));
1205 1205
 		$matches = null;
1206
-		return preg_match('/test ([A-Z0-9]+)/i',$ado_col,$matches) ? $this->dict->ActualType($matches[1]) : false;
1206
+		return preg_match('/test ([A-Z0-9]+)/i', $ado_col, $matches) ? $this->dict->ActualType($matches[1]) : false;
1207 1207
 	}
1208 1208
 
1209 1209
 	/**
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 		// MetaType returns all varchar >= blobSize as blob, it's by default 100, which is wrong
1220 1220
 		$this->dict->blobSize = $this->max_varchar_length;
1221 1221
 
1222
-		if (!method_exists($this->dict,'MetaColumns') ||
1222
+		if (!method_exists($this->dict, 'MetaColumns') ||
1223 1223
 			!($columns = $this->dict->MetaColumns($sTableName)))
1224 1224
 		{
1225 1225
 			return False;
@@ -1232,11 +1232,11 @@  discard block
 block discarded – undo
1232 1232
 			'uc' => array(),
1233 1233
 		);
1234 1234
 		//echo "$sTableName: <pre>".print_r($columns,true)."</pre>";
1235
-		foreach($columns as $column)
1235
+		foreach ($columns as $column)
1236 1236
 		{
1237 1237
 			$name = $this->capabilities['name_case'] == 'upper' ? strtolower($column->name) : $column->name;
1238 1238
 
1239
-			$type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1239
+			$type = method_exists($this->dict, 'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1240 1240
 
1241 1241
 			// fix longtext not correctly handled by ADOdb
1242 1242
 			if ($type == 'X' && $column->type == 'longtext') $type = 'XL';
@@ -1258,11 +1258,11 @@  discard block
 block discarded – undo
1258 1258
 			);
1259 1259
 			$definition['fd'][$name]['type'] = $ado_type2egw[$type];
1260 1260
 
1261
-			switch($type)
1261
+			switch ($type)
1262 1262
 			{
1263 1263
 				case 'D': case 'T':
1264 1264
 					// detecting the automatic timestamps again
1265
-					if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i',$column->default_value))
1265
+					if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i', $column->default_value))
1266 1266
 					{
1267 1267
 						$column->default_value = $type == 'D' ? 'current_date' : 'current_timestamp';
1268 1268
 					}
@@ -1289,10 +1289,10 @@  discard block
 block discarded – undo
1289 1289
 					$column->auto_increment = true;
1290 1290
 					// fall-through
1291 1291
 				case 'I': case 'I1': case 'I2': case 'I4': case 'I8':
1292
-					switch($type)
1292
+					switch ($type)
1293 1293
 					{
1294 1294
 						case 'I1': case 'I2': case 'I4': case 'I8':
1295
-							$definition['fd'][$name]['precision'] = (int) $type[1];
1295
+							$definition['fd'][$name]['precision'] = (int)$type[1];
1296 1296
 							break;
1297 1297
 						default:
1298 1298
 							if ($column->max_length > 11)
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
 						$definition['fd'][$name]['type'] = 'int';
1329 1329
 						// detect postgres type-spec and remove it
1330 1330
 						$matches = null;
1331
-						if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/',$column->default_value,$matches))
1331
+						if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/', $column->default_value, $matches))
1332 1332
 						{
1333 1333
 							$definition['fd'][$name]['default'] = $matches[1];
1334 1334
 							$column->has_default = False;
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
 			}
1347 1347
 			if ($column->has_default)
1348 1348
 			{
1349
-				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))	// postgres
1349
+				if (preg_match("/^'(.*)'::.*$/", $column->default_value, $matches))	// postgres
1350 1350
 				{
1351 1351
 					$column->default_value = $matches[1];
1352 1352
 				}
@@ -1356,18 +1356,18 @@  discard block
 block discarded – undo
1356 1356
 			{
1357 1357
 				$definition['fd'][$name]['nullable'] = False;
1358 1358
 			}
1359
-			if ($column->primary_key && !in_array($name,$definition['pk']))
1359
+			if ($column->primary_key && !in_array($name, $definition['pk']))
1360 1360
 			{
1361 1361
 				$definition['pk'][] = $name;
1362 1362
 			}
1363 1363
 		}
1364
-		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1364
+		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2", False, $sTableName, $columns);
1365 1365
 
1366 1366
 		// not all DB's (odbc) return the primary keys via MetaColumns
1367
-		if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') &&
1367
+		if (!count($definition['pk']) && method_exists($this->dict, 'MetaPrimaryKeys') &&
1368 1368
 			is_array($primary = $this->dict->MetaPrimaryKeys($sTableName)) && count($primary))
1369 1369
 		{
1370
-			if($this->capabilities['name_case'] == 'upper')
1370
+			if ($this->capabilities['name_case'] == 'upper')
1371 1371
 			{
1372 1372
 				array_walk($primary, function(&$s)
1373 1373
 				{
@@ -1376,10 +1376,10 @@  discard block
 block discarded – undo
1376 1376
 			}
1377 1377
 			$definition['pk'] = $primary;
1378 1378
 		}
1379
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1379
+		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2", False, $sTableName, $primary);
1380 1380
 
1381 1381
 		$this->GetIndexes($sTableName, $definition);
1382
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1382
+		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2", False, $sTableName, $definition);
1383 1383
 
1384 1384
 		return $definition;
1385 1385
 	}
@@ -1391,35 +1391,35 @@  discard block
 block discarded – undo
1391 1391
 	 * @param array& $definition=array()
1392 1392
 	 * @return array of arrays with keys 'ix' and 'uc'
1393 1393
 	 */
1394
-	public function GetIndexes($sTableName, array &$definition=array())
1394
+	public function GetIndexes($sTableName, array &$definition = array())
1395 1395
 	{
1396
-		if (method_exists($this->dict,'MetaIndexes') &&
1396
+		if (method_exists($this->dict, 'MetaIndexes') &&
1397 1397
 			is_array($indexes = $this->dict->MetaIndexes($sTableName)) && count($indexes))
1398 1398
 		{
1399
-			foreach($indexes as $index)
1399
+			foreach ($indexes as $index)
1400 1400
 			{
1401 1401
 				// append (optional) length of index in brackets to column
1402
-				foreach((array)$index['length'] as $col => $length)
1402
+				foreach ((array)$index['length'] as $col => $length)
1403 1403
 				{
1404 1404
 					if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')';
1405 1405
 				}
1406
-				if($this->capabilities['name_case'] == 'upper')
1406
+				if ($this->capabilities['name_case'] == 'upper')
1407 1407
 				{
1408 1408
 					array_walk($index['columns'], function(&$s)
1409 1409
 					{
1410 1410
 						$s = strtolower($s);
1411 1411
 					});
1412 1412
 				}
1413
-				if (count($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) ||
1414
-					$index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk'])))
1413
+				if (count($definition['pk']) && (implode(':', $definition['pk']) == implode(':', $index['columns']) ||
1414
+					$index['unique'] && count(array_intersect($definition['pk'], $index['columns'])) == count($definition['pk'])))
1415 1415
 				{
1416
-					continue;	// is already the primary key => ignore it
1416
+					continue; // is already the primary key => ignore it
1417 1417
 				}
1418 1418
 				$kind = $index['unique'] ? 'uc' : 'ix';
1419 1419
 
1420 1420
 				$definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0];
1421 1421
 			}
1422
-			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1422
+			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2", False, $sTableName, $indexes);
1423 1423
 		}
1424 1424
 		return $definition;
1425 1425
 	}
@@ -1431,7 +1431,7 @@  discard block
 block discarded – undo
1431 1431
 	 */
1432 1432
 	function CheckCreateIndexes()
1433 1433
 	{
1434
-		foreach($this->adodb->MetaTables('TABLES') as $table)
1434
+		foreach ($this->adodb->MetaTables('TABLES') as $table)
1435 1435
 		{
1436 1436
 			if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue;
1437 1437
 
@@ -1439,9 +1439,9 @@  discard block
 block discarded – undo
1439 1439
 			$this->GetIndexes($table, $definition);
1440 1440
 
1441 1441
 			// iterate though indexes we should have according to tables_current
1442
-			foreach(array('uc', 'ix') as $type)
1442
+			foreach (array('uc', 'ix') as $type)
1443 1443
 			{
1444
-				foreach($table_def[$type] as $columns)
1444
+				foreach ($table_def[$type] as $columns)
1445 1445
 				{
1446 1446
 					// sometimes primary key is listed as (unique) index too --> ignore it
1447 1447
 					if ($this->_in_index($columns, array($table_def['pk']), true)) continue;
@@ -1472,27 +1472,26 @@  discard block
 block discarded – undo
1472 1472
 	 * old translator function, use GetTableDefition() instead
1473 1473
 	 * @depricated
1474 1474
 	 */
1475
-	function _GetColumns($oProc,$sTableName,&$sColumns)
1475
+	function _GetColumns($oProc, $sTableName, &$sColumns)
1476 1476
 	{
1477
-		unset($oProc);	// unused, but required by function signature
1477
+		unset($oProc); // unused, but required by function signature
1478 1478
 		$this->sCol = $this->pk = $this->fk = $this->ix = $this->uc = array();
1479 1479
 
1480 1480
 		$tabledef = $this->GetTableDefinition($sTableName);
1481 1481
 
1482
-		$sColumns = implode(',',array_keys($tabledef['fd']));
1482
+		$sColumns = implode(',', array_keys($tabledef['fd']));
1483 1483
 
1484
-		foreach($tabledef['fd'] as $column => $data)
1484
+		foreach ($tabledef['fd'] as $column => $data)
1485 1485
 		{
1486 1486
 			$col_def = "'type' => '$data[type]'";
1487 1487
 			unset($data['type']);
1488
-			foreach($data as $key => $val)
1488
+			foreach ($data as $key => $val)
1489 1489
 			{
1490
-				$col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') :
1491
-					(is_int($val) ? $val : "'$val'"));
1490
+				$col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : (is_int($val) ? $val : "'$val'"));
1492 1491
 			}
1493 1492
 			$this->sCol[] = "\t\t\t\t'$column' => array($col_def),\n";
1494 1493
 		}
1495
-		foreach(array('pk','fk','ix','uc') as $kind)
1494
+		foreach (array('pk', 'fk', 'ix', 'uc') as $kind)
1496 1495
 		{
1497 1496
 			$this->$kind = $tabledef[$kind];
1498 1497
 		}
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.
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
 			if ($this->_PostgresHasOldSequence($sOldTableName,True) || count($table_def['pk']) ||
375 417
 				count($table_def['ix']) || count($table_def['uc']))
@@ -400,7 +442,10 @@  discard block
 block discarded – undo
400 442
 	 */
401 443
 	function _PostgresHasOldSequence($sTableName,$preserveValue=False)
402 444
 	{
403
-		if ($this->sType != 'pgsql') return false;
445
+		if ($this->sType != 'pgsql')
446
+		{
447
+			return false;
448
+		}
404 449
 
405 450
 		$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");
406 451
 		$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");
@@ -408,12 +453,18 @@  discard block
 block discarded – undo
408 453
 		$matches = null;
409 454
 		if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches))
410 455
 		{
411
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
456
+			if ($preserveValue)
457
+			{
458
+				$this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
459
+			}
412 460
 			return $matches[1];
413 461
 		}
414 462
 		if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches))
415 463
 		{
416
-			if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
464
+			if ($preserveValue)
465
+			{
466
+				$this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]);
467
+			}
417 468
 			return $matches[1];
418 469
 		}
419 470
 		return false;
@@ -447,7 +498,10 @@  discard block
 block discarded – undo
447 498
 	 */
448 499
 	function AlterColumn($sTableName, $sColumnName, $aColumnDef)
449 500
 	{
450
-		if (!($table_def = $this->GetTableDefinition($sTableName))) return 0;
501
+		if (!($table_def = $this->GetTableDefinition($sTableName)))
502
+		{
503
+			return 0;
504
+		}
451 505
 
452 506
 		// PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long
453 507
 		if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
@@ -550,8 +604,14 @@  discard block
 block discarded – undo
550 604
 		{
551 605
 			$sIdxName = $this->_index_name($sTableName,$aColumnNames);
552 606
 		}
553
-		if (!is_array($options)) $options = $options ? array($options) : array();
554
-		if ($bUnique) $options[] = 'UNIQUE';
607
+		if (!is_array($options))
608
+		{
609
+			$options = $options ? array($options) : array();
610
+		}
611
+		if ($bUnique)
612
+		{
613
+			$options[] = 'UNIQUE';
614
+		}
555 615
 
556 616
 		$aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options);
557 617
 
@@ -621,7 +681,9 @@  discard block
 block discarded – undo
621 681
 					$seq_name = $matches[1];
622 682
 				}
623 683
 				$sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName";
624
-				if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; }
684
+				if($this->debug)
685
+				{
686
+echo "<br>Updating sequence '$seq_name using: $sql"; }
625 687
 				return $this->query($sql,__LINE__,__FILE__);
626 688
 		}
627 689
 		return True;
@@ -641,7 +703,9 @@  discard block
 block discarded – undo
641 703
 	 */
642 704
 	function RefreshTable($sTableName, $aTableDef, $aDefaults=False)
643 705
 	{
644
-		if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; }
706
+		if($this->debug)
707
+		{
708
+echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; }
645 709
 
646 710
 		$old_table_def = $this->GetTableDefinition($sTableName);
647 711
 
@@ -668,21 +732,30 @@  discard block
 block discarded – undo
668 732
 						$value = "nextval('$sequence_name')"; break;
669 733
 				}
670 734
 			}
671
-			elseif ($aDefaults && isset($aDefaults[$name]))	// use given default
735
+			elseif ($aDefaults && isset($aDefaults[$name]))
736
+			{
737
+				// use given default
672 738
 			{
673 739
 				$value = $aDefaults[$name];
674 740
 			}
675
-			elseif (isset($old_table_def['fd'][$name]))	// existing column, use its value => column-name in query
741
+			}
742
+			elseif (isset($old_table_def['fd'][$name]))
743
+			{
744
+				// existing column, use its value => column-name in query
676 745
 			{
677 746
 				$value = $name;
747
+			}
678 748
 
679
-				if ($this->sType == 'pgsql')			// some postgres specific code
749
+				if ($this->sType == 'pgsql')
750
+				{
751
+					// some postgres specific code
680 752
 				{
681 753
 					// this is eg. necessary to change a varchar into an int column under postgres
682 754
 					if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) &&
683 755
 						in_array($data['type'],array('int','decimal')))
684 756
 					{
685 757
 						$value = "to_number($name,'S9999999999999D99')";
758
+				}
686 759
 					}
687 760
 					// blobs cant be casted to text
688 761
 					elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text')
@@ -737,8 +810,15 @@  discard block
 block discarded – undo
737 810
 		switch($this->sType)
738 811
 		{
739 812
 			case 'mssql':
740
-				if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n";
741
-				if ($blob_column_included) $distinct = '';	// no distinct on blob-columns
813
+				if ($auto_column_included)
814
+				{
815
+					$extra = "SET IDENTITY_INSERT $sTableName ON\n";
816
+				}
817
+				if ($blob_column_included)
818
+				{
819
+					$distinct = '';
820
+				}
821
+				// no distinct on blob-columns
742 822
 				break;
743 823
 		}
744 824
 		// because of all the trouble with sequences and indexes in the global namespace,
@@ -802,8 +882,14 @@  discard block
 block discarded – undo
802 882
 			return False;
803 883
 		}
804 884
 		// set our debug-mode or $bOutputHTML is the other one is set
805
-		if ($this->debug) $bOutputHTML = True;
806
-		if ($bOutputHTML && !$this->debug) $this->debug = 2;
885
+		if ($this->debug)
886
+		{
887
+			$bOutputHTML = True;
888
+		}
889
+		if ($bOutputHTML && !$this->debug)
890
+		{
891
+			$this->debug = 2;
892
+		}
807 893
 
808 894
 		foreach($aTables as $sTableName => $aTableDef)
809 895
 		{
@@ -916,9 +1002,12 @@  discard block
 block discarded – undo
916 1002
 	 */
917 1003
 	function ExecuteSqlArray($aSql,$debug_level)
918 1004
 	{
919
-		if ($this->m_odb->query_log)	// we use Db::query to log the queries
1005
+		if ($this->m_odb->query_log)
1006
+		{
1007
+			// we use Db::query to log the queries
920 1008
 		{
921 1009
 			$retval = 2;
1010
+		}
922 1011
 			foreach($aSql as $sql)
923 1012
 			{
924 1013
 				if (!$this->m_odb->query($sql,__LINE__,__FILE__))
@@ -1001,10 +1090,13 @@  discard block
 block discarded – undo
1001 1090
 
1002 1091
 		// this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle
1003 1092
 		if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 ||
1004
-			strlen($name) >= 64)	// even mysql has a limit here ;-)
1093
+			strlen($name) >= 64)
1094
+		{
1095
+			// even mysql has a limit here ;-)
1005 1096
 		{
1006 1097
 			$name = "i".substr(md5($name),0,29);
1007 1098
 		}
1099
+		}
1008 1100
 		return $name;
1009 1101
 	}
1010 1102
 
@@ -1239,7 +1331,10 @@  discard block
 block discarded – undo
1239 1331
 			$type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
1240 1332
 
1241 1333
 			// fix longtext not correctly handled by ADOdb
1242
-			if ($type == 'X' && $column->type == 'longtext') $type = 'XL';
1334
+			if ($type == 'X' && $column->type == 'longtext')
1335
+			{
1336
+				$type = 'XL';
1337
+			}
1243 1338
 
1244 1339
 			static $ado_type2egw = array(
1245 1340
 				'C'		=> 'varchar',
@@ -1346,10 +1441,13 @@  discard block
 block discarded – undo
1346 1441
 			}
1347 1442
 			if ($column->has_default)
1348 1443
 			{
1349
-				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))	// postgres
1444
+				if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches))
1445
+				{
1446
+					// postgres
1350 1447
 				{
1351 1448
 					$column->default_value = $matches[1];
1352 1449
 				}
1450
+				}
1353 1451
 				$definition['fd'][$name]['default'] = $column->default_value;
1354 1452
 			}
1355 1453
 			if ($column->not_null)
@@ -1361,7 +1459,10 @@  discard block
 block discarded – undo
1361 1459
 				$definition['pk'][] = $name;
1362 1460
 			}
1363 1461
 		}
1364
-		if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1462
+		if ($this->debug > 2)
1463
+		{
1464
+			$this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns);
1465
+		}
1365 1466
 
1366 1467
 		// not all DB's (odbc) return the primary keys via MetaColumns
1367 1468
 		if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') &&
@@ -1376,10 +1477,16 @@  discard block
 block discarded – undo
1376 1477
 			}
1377 1478
 			$definition['pk'] = $primary;
1378 1479
 		}
1379
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1480
+		if ($this->debug > 1)
1481
+		{
1482
+			$this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary);
1483
+		}
1380 1484
 
1381 1485
 		$this->GetIndexes($sTableName, $definition);
1382
-		if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1486
+		if ($this->debug > 1)
1487
+		{
1488
+			$this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition);
1489
+		}
1383 1490
 
1384 1491
 		return $definition;
1385 1492
 	}
@@ -1401,7 +1508,10 @@  discard block
 block discarded – undo
1401 1508
 				// append (optional) length of index in brackets to column
1402 1509
 				foreach((array)$index['length'] as $col => $length)
1403 1510
 				{
1404
-					if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')';
1511
+					if (($key = array_search($col, $index['columns'])))
1512
+					{
1513
+						$index['columns'][$key] .= '('.$length.')';
1514
+					}
1405 1515
 				}
1406 1516
 				if($this->capabilities['name_case'] == 'upper')
1407 1517
 				{
@@ -1419,7 +1529,10 @@  discard block
 block discarded – undo
1419 1529
 
1420 1530
 				$definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0];
1421 1531
 			}
1422
-			if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1532
+			if ($this->debug > 2)
1533
+			{
1534
+				$this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes);
1535
+			}
1423 1536
 		}
1424 1537
 		return $definition;
1425 1538
 	}
@@ -1433,7 +1546,10 @@  discard block
 block discarded – undo
1433 1546
 	{
1434 1547
 		foreach($this->adodb->MetaTables('TABLES') as $table)
1435 1548
 		{
1436
-			if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue;
1549
+			if (!($table_def = $this->m_odb->get_table_definitions(true, $table)))
1550
+			{
1551
+				continue;
1552
+			}
1437 1553
 
1438 1554
 			$definition = array();
1439 1555
 			$this->GetIndexes($table, $definition);
@@ -1444,7 +1560,10 @@  discard block
 block discarded – undo
1444 1560
 				foreach($table_def[$type] as $columns)
1445 1561
 				{
1446 1562
 					// sometimes primary key is listed as (unique) index too --> ignore it
1447
-					if ($this->_in_index($columns, array($table_def['pk']), true)) continue;
1563
+					if ($this->_in_index($columns, array($table_def['pk']), true))
1564
+					{
1565
+						continue;
1566
+					}
1448 1567
 
1449 1568
 					// check if they exist in real table and create them if not
1450 1569
 					if (!$this->_in_index($columns, $definition[$type]) &&
@@ -1455,7 +1574,10 @@  discard block
 block discarded – undo
1455 1574
 						if ($this->_in_index($columns, $definition[$type], true))
1456 1575
 						{
1457 1576
 							// for PostgreSQL we dont use length-limited indexes --> nothing to do
1458
-							if ($this->m_odb->Type == 'pgsql') continue;
1577
+							if ($this->m_odb->Type == 'pgsql')
1578
+							{
1579
+								continue;
1580
+							}
1459 1581
 							// for MySQL we drop current index and create it with correct length
1460 1582
 							$this->DropIndex($table, $columns);
1461 1583
 						}
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.
Braces   +77 added lines, -20 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
@@ -287,7 +315,10 @@  discard block
 block discarded – undo
287 315
 	{
288 316
 		foreach($sel_options as &$options)
289 317
 		{
290
-			if (!is_array($options)||empty($options)) continue;
318
+			if (!is_array($options)||empty($options))
319
+			{
320
+				continue;
321
+			}
291 322
 			foreach($options as $key => $value)
292 323
 			{
293 324
 				if (is_numeric($key) && (!is_array($value) || !isset($value['value'])))
@@ -325,7 +356,10 @@  discard block
 block discarded – undo
325 356
 
326 357
 		// Set current app for validation
327 358
 		list($app) = explode('.',self::$request->method);
328
-		if(!$app) list($app) = explode('::',self::$request->method);
359
+		if(!$app)
360
+		{
361
+			list($app) = explode('::',self::$request->method);
362
+		}
329 363
 		if($app)
330 364
 		{
331 365
 			Translation::add_app($app);
@@ -356,7 +390,10 @@  discard block
 block discarded – undo
356 390
 			'location_name'   => $template->id,
357 391
 		) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras)
358 392
 		{
359
-			if (!$extras) continue;
393
+			if (!$extras)
394
+			{
395
+				continue;
396
+			}
360 397
 
361 398
 			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
362 399
 			{
@@ -386,10 +423,15 @@  discard block
 block discarded – undo
386 423
 		{
387 424
 			foreach($hook_data as $extras)
388 425
 			{
389
-				if (!$extras) continue;
426
+				if (!$extras)
427
+				{
428
+					continue;
429
+				}
390 430
 
391
-				foreach(isset($extras[0]) ? $extras : array($extras) as $extra) {
392
-					if ($extra['data'] && is_array($extra['data'])) {
431
+				foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
432
+				{
433
+					if ($extra['data'] && is_array($extra['data']))
434
+					{
393 435
 						$content = array_merge($content, $extra['data']);
394 436
 					}
395 437
 				}
@@ -428,7 +470,10 @@  discard block
 block discarded – undo
428 470
 	 */
429 471
 	static public function process_exec()
430 472
 	{
431
-		if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']);
473
+		if (get_magic_quotes_gpc())
474
+		{
475
+			$_POST['value'] = stripslashes($_POST['value']);
476
+		}
432 477
 		$content = json_decode($_POST['value'],true);
433 478
 		//error_log(__METHOD__."(".array2string($content).")");
434 479
 
@@ -580,16 +625,22 @@  discard block
 block discarded – undo
580 625
 	{
581 626
 		if (is_array($new))
582 627
 		{
583
-			if (!is_array($old)) $old = (array) $old;
628
+			if (!is_array($old))
629
+			{
630
+				$old = (array) $old;
631
+			}
584 632
 
585 633
 			foreach($new as $k => $v)
586 634
 			{
587 635
 				if (!is_array($v) || !isset($old[$k]) || 	// no array or a new array
588 636
 					isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1])	|| // or no associative array, eg. selecting multiple accounts
589
-					is_array($v) && count($v) == 0)			// Empty array replacing non-empty
637
+					is_array($v) && count($v) == 0)
638
+				{
639
+					// Empty array replacing non-empty
590 640
 				{
591 641
 					$old[$k] = $v;
592 642
 				}
643
+				}
593 644
 				else
594 645
 				{
595 646
 					$old[$k] = self::complete_array_merge($old[$k],$v);
@@ -642,10 +693,16 @@  discard block
 block discarded – undo
642 693
 		if (is_null($dec_separator))
643 694
 		{
644 695
 			$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
645
-			if (empty($dec_separator)) $dec_separator = '.';
696
+			if (empty($dec_separator))
697
+			{
698
+				$dec_separator = '.';
699
+			}
646 700
 			$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
647 701
 		}
648
-		if ((string)$number === '') return '';
702
+		if ((string)$number === '')
703
+		{
704
+			return '';
705
+		}
649 706
 
650 707
 		return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : '');
651 708
 	}
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
 				{
@@ -318,9 +318,9 @@  discard block
 block discarded – undo
318 318
 		}
319 319
 
320 320
 		// Set current app for validation
321
-		list($app) = explode('.',self::$request->method);
322
-		if(!$app) list($app) = explode('::',self::$request->method);
323
-		if($app)
321
+		list($app) = explode('.', self::$request->method);
322
+		if (!$app) list($app) = explode('::', self::$request->method);
323
+		if ($app)
324 324
 		{
325 325
 			Translation::add_app($app);
326 326
 			$GLOBALS['egw_info']['flags']['currentapp'] = $app;
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 		$expand = array(
330 330
 			'cont' => &self::$request->content,
331 331
 		);
332
-		$template->run('validate', array('', $expand, $_content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
332
+		$template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
333 333
 
334 334
 		if ($no_validation)
335 335
 		{
@@ -345,14 +345,14 @@  discard block
 block discarded – undo
345 345
 		// tell request call to remove request, if it is not modified eg. by call to exec in callback
346 346
 		self::$request->remove_if_not_modified();
347 347
 
348
-		foreach(Hooks::process(array(
348
+		foreach (Hooks::process(array(
349 349
 			'hook_location'   => 'etemplate2_before_process',
350 350
 			'location_name'   => $template->id,
351 351
 		) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras)
352 352
 		{
353 353
 			if (!$extras) continue;
354 354
 
355
-			foreach(isset($extras[0]) ? $extras : array($extras) as $extra)
355
+			foreach (isset($extras[0]) ? $extras : array($extras) as $extra)
356 356
 			{
357 357
 				if ($extra['data'] && is_array($extra['data']))
358 358
 				{
@@ -365,8 +365,7 @@  discard block
 block discarded – undo
365 365
 		//error_log(' validated='.array2string($validated));
366 366
 		$content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated));
367 367
 
368
-		$tcontent = is_array($content) ? $content :
369
-			self::complete_array_merge(self::$request->preserv, $validated);
368
+		$tcontent = is_array($content) ? $content : self::complete_array_merge(self::$request->preserv, $validated);
370 369
 
371 370
 		$hook_data = Hooks::process(
372 371
 			array(
@@ -378,11 +377,11 @@  discard block
 block discarded – undo
378 377
 
379 378
 		if (is_array($content))
380 379
 		{
381
-			foreach($hook_data as $extras)
380
+			foreach ($hook_data as $extras)
382 381
 			{
383 382
 				if (!$extras) continue;
384 383
 
385
-				foreach(isset($extras[0]) ? $extras : array($extras) as $extra) {
384
+				foreach (isset($extras[0]) ? $extras : array($extras) as $extra) {
386 385
 					if ($extra['data'] && is_array($extra['data'])) {
387 386
 						$content = array_merge($content, $extra['data']);
388 387
 					}
@@ -394,7 +393,7 @@  discard block
 block discarded – undo
394 393
 		if (isset($GLOBALS['egw_info']['flags']['java_script']))
395 394
 		{
396 395
 			// Strip out any script tags
397
-			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']);
396
+			$GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']);
398 397
 			self::$response->script($GLOBALS['egw_info']['flags']['java_script']);
399 398
 			//error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use Json\Response->script() instead.');
400 399
 		}
@@ -423,7 +422,7 @@  discard block
 block discarded – undo
423 422
 	static public function process_exec()
424 423
 	{
425 424
 		if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']);
426
-		$content = json_decode($_POST['value'],true);
425
+		$content = json_decode($_POST['value'], true);
427 426
 		//error_log(__METHOD__."(".array2string($content).")");
428 427
 
429 428
 		self::$request = Etemplate\Request::read($_POST['etemplate_exec_id']);
@@ -437,7 +436,7 @@  discard block
 block discarded – undo
437 436
 		$expand = array(
438 437
 			'cont' => &self::$request->content,
439 438
 		);
440
-		$template->run('validate', array('', $expand, $content, &$validated), true);	// $respect_disabled=true: do NOT validate disabled widgets and children
439
+		$template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children
441 440
 		if (self::validation_errors(self::$request->ignore_validation))
442 441
 		{
443 442
 			error_log(__METHOD__."(,".array2string($content).') validation_errors='.array2string(self::$validation_errors));
@@ -473,7 +472,7 @@  discard block
 block discarded – undo
473 472
 	 *
474 473
 	 * @ToDo supported customized templates stored in DB
475 474
 	 */
476
-	public function read($name,$template_set=null,$lang='default',$group=0,$version='',$load_via='')
475
+	public function read($name, $template_set = null, $lang = 'default', $group = 0, $version = '', $load_via = '')
477 476
 	{
478 477
 
479 478
 		// For mobile experience try to load custom mobile templates
@@ -482,9 +481,9 @@  discard block
 block discarded – undo
482 481
 			$template_set = "mobile";
483 482
 		}
484 483
 
485
-		unset($lang); unset($group);	// not used, but in old signature
486
-		$this->rel_path = self::relPath($this->name=$name, $this->template_set=$template_set,
487
-			$this->version=$version, $this->laod_via = $load_via);
484
+		unset($lang); unset($group); // not used, but in old signature
485
+		$this->rel_path = self::relPath($this->name = $name, $this->template_set = $template_set,
486
+			$this->version = $version, $this->laod_via = $load_via);
488 487
 		//error_log(__METHOD__."('$name', '$template_set', '$lang', $group, '$version', '$load_via') rel_path=".array2string($this->rel_path));
489 488
 
490 489
 		$this->dom_id = $name;
@@ -527,7 +526,7 @@  discard block
 block discarded – undo
527 526
 	 * @return mixed reference to attribute, usually NULL
528 527
 	 * @deprecated use getElementAttribute($name, $attr)
529 528
 	 */
530
-	public function &get_cell_attribute($name,$attr)
529
+	public function &get_cell_attribute($name, $attr)
531 530
 	{
532 531
 		return self::getElementAttribute($name, $attr);
533 532
 	}
@@ -541,7 +540,7 @@  discard block
 block discarded – undo
541 540
 	 * @return reference to attribute
542 541
 	 * @deprecated use setElementAttribute($name, $attr, $val)
543 542
 	 */
544
-	public function &set_cell_attribute($name,$attr,$val)
543
+	public function &set_cell_attribute($name, $attr, $val)
545 544
 	{
546 545
 		return self::setElementAttribute($name, $attr, $val);
547 546
 	}
@@ -554,7 +553,7 @@  discard block
 block discarded – undo
554 553
 	 * @return reference to attribute
555 554
 	 * @deprecated use disableElement($name, $disabled=true)
556 555
 	 */
557
-	public function disable_cells($name,$disabled=True)
556
+	public function disable_cells($name, $disabled = True)
558 557
 	{
559 558
 		return self::disableElement($name, $disabled);
560 559
 	}
@@ -570,23 +569,23 @@  discard block
 block discarded – undo
570 569
 	 * @param array $new
571 570
 	 * @return array the merged array
572 571
 	 */
573
-	public static function complete_array_merge($old,$new)
572
+	public static function complete_array_merge($old, $new)
574 573
 	{
575 574
 		if (is_array($new))
576 575
 		{
577
-			if (!is_array($old)) $old = (array) $old;
576
+			if (!is_array($old)) $old = (array)$old;
578 577
 
579
-			foreach($new as $k => $v)
578
+			foreach ($new as $k => $v)
580 579
 			{
581
-				if (!is_array($v) || !isset($old[$k]) || 	// no array or a new array
582
-					isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1])	|| // or no associative array, eg. selecting multiple accounts
580
+				if (!is_array($v) || !isset($old[$k]) || // no array or a new array
581
+					isset($v[0]) && !is_array($v[0]) && isset($v[count($v) - 1]) || // or no associative array, eg. selecting multiple accounts
583 582
 					is_array($v) && count($v) == 0)			// Empty array replacing non-empty
584 583
 				{
585 584
 					$old[$k] = $v;
586 585
 				}
587 586
 				else
588 587
 				{
589
-					$old[$k] = self::complete_array_merge($old[$k],$v);
588
+					$old[$k] = self::complete_array_merge($old[$k], $v);
590 589
 				}
591 590
 			}
592 591
 		}
@@ -598,7 +597,7 @@  discard block
 block discarded – undo
598 597
 	 *
599 598
 	 * @param array $content =null
600 599
 	 */
601
-	public function debug(array $content=null)
600
+	public function debug(array $content = null)
602 601
 	{
603 602
 		$GLOBALS['egw']->framework->render(print_r($content, true));
604 603
 	}
@@ -612,11 +611,11 @@  discard block
 block discarded – undo
612 611
 	 * @param int &$max_upload=null on return max. upload size in byte
613 612
 	 * @return string
614 613
 	 */
615
-	static function max_upload_size_message(&$max_upload=null)
614
+	static function max_upload_size_message(&$max_upload = null)
616 615
 	{
617 616
 		$upload_max_filesize = ini_get('upload_max_filesize');
618 617
 		$post_max_size = ini_get('post_max_size');
619
-		$max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800);
618
+		$max_upload = min(self::km2int($upload_max_filesize), self::km2int($post_max_size) - 2800);
620 619
 
621 620
 		return lang('Maximum size for uploads').': '.Vfs::hsize($max_upload).
622 621
 			" (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)";
@@ -630,9 +629,9 @@  discard block
 block discarded – undo
630 629
 	 * @param boolean $readonly =true
631 630
 	 * @return string
632 631
 	 */
633
-	static public function number_format($number,$num_decimal_places=2,$readonly=true)
632
+	static public function number_format($number, $num_decimal_places = 2, $readonly = true)
634 633
 	{
635
-		static $dec_separator=null,$thousands_separator=null;
634
+		static $dec_separator = null, $thousands_separator = null;
636 635
 		if (is_null($dec_separator))
637 636
 		{
638 637
 			$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
@@ -641,7 +640,7 @@  discard block
 block discarded – undo
641 640
 		}
642 641
 		if ((string)$number === '') return '';
643 642
 
644
-		return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : '');
643
+		return number_format(str_replace(' ', '', $number), $num_decimal_places, $dec_separator, $readonly ? $thousands_separator : '');
645 644
 	}
646 645
 
647 646
 	/**
@@ -654,13 +653,13 @@  discard block
 block discarded – undo
654 653
 	{
655 654
 		if (!is_numeric($size))
656 655
 		{
657
-			switch(strtolower(substr($size,-1)))
656
+			switch (strtolower(substr($size, -1)))
658 657
 			{
659 658
 				case 'm':
660
-					$size = 1024*1024*(int)$size;
659
+					$size = 1024 * 1024 * (int)$size;
661 660
 					break;
662 661
 				case 'k':
663
-					$size = 1024*(int)$size;
662
+					$size = 1024 * (int)$size;
664 663
 					break;
665 664
 			}
666 665
 		}
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.