@@ -371,7 +371,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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) |
@@ -1845,7 +1845,7 @@ discard block |
||
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 |
||
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 |
||
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; |
@@ -67,38 +67,38 @@ discard block |
||
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 | /** |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | var $readonly = false; |
108 | 108 | |
109 | 109 | /** |
110 | - * @var int $Debug enable debuging - 0 no, 1 yes |
|
111 | - */ |
|
110 | + * @var int $Debug enable debuging - 0 no, 1 yes |
|
111 | + */ |
|
112 | 112 | var $Debug = 0; |
113 | 113 | |
114 | 114 | /** |
@@ -119,23 +119,23 @@ discard block |
||
119 | 119 | var $log_updates = false; |
120 | 120 | |
121 | 121 | /** |
122 | - * @var array $Record current record |
|
123 | - */ |
|
122 | + * @var array $Record current record |
|
123 | + */ |
|
124 | 124 | var $Record = array(); |
125 | 125 | |
126 | 126 | /** |
127 | - * @var int row number for current record |
|
128 | - */ |
|
127 | + * @var int row number for current record |
|
128 | + */ |
|
129 | 129 | var $Row; |
130 | 130 | |
131 | 131 | /** |
132 | - * @var int $Errno internal rdms error number for last error |
|
133 | - */ |
|
132 | + * @var int $Errno internal rdms error number for last error |
|
133 | + */ |
|
134 | 134 | var $Errno = 0; |
135 | 135 | |
136 | 136 | /** |
137 | - * @var string descriptive text from last error |
|
138 | - */ |
|
137 | + * @var string descriptive text from last error |
|
138 | + */ |
|
139 | 139 | var $Error = ''; |
140 | 140 | |
141 | 141 | /** |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
279 | - * @param string $query query to be executed (optional) |
|
280 | - */ |
|
279 | + * @param string $query query to be executed (optional) |
|
280 | + */ |
|
281 | 281 | |
282 | 282 | function db($query = '') |
283 | 283 | { |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | - * @return int current connection id |
|
289 | - */ |
|
288 | + * @return int current connection id |
|
289 | + */ |
|
290 | 290 | function link_id() |
291 | 291 | { |
292 | 292 | return $this->Link_ID; |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
666 | - * Close a connection to a database |
|
667 | - */ |
|
666 | + * Close a connection to a database |
|
667 | + */ |
|
668 | 668 | function disconnect() |
669 | 669 | { |
670 | 670 | if (!$this->privat_Link_ID) |
@@ -678,11 +678,11 @@ discard block |
||
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
681 | - * Convert a unix timestamp to a rdms specific timestamp |
|
682 | - * |
|
683 | - * @param int unix timestamp |
|
684 | - * @return string rdms specific timestamp |
|
685 | - */ |
|
681 | + * Convert a unix timestamp to a rdms specific timestamp |
|
682 | + * |
|
683 | + * @param int unix timestamp |
|
684 | + * @return string rdms specific timestamp |
|
685 | + */ |
|
686 | 686 | function to_timestamp($epoch) |
687 | 687 | { |
688 | 688 | if (!$this->Link_ID && !$this->connect()) |
@@ -694,11 +694,11 @@ discard block |
||
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
697 | - * Convert a rdms specific timestamp to a unix timestamp |
|
698 | - * |
|
699 | - * @param string rdms specific timestamp |
|
700 | - * @return int unix timestamp |
|
701 | - */ |
|
697 | + * Convert a rdms specific timestamp to a unix timestamp |
|
698 | + * |
|
699 | + * @param string rdms specific timestamp |
|
700 | + * @return int unix timestamp |
|
701 | + */ |
|
702 | 702 | function from_timestamp($timestamp) |
703 | 703 | { |
704 | 704 | if (!$this->Link_ID && !$this->connect()) |
@@ -720,19 +720,19 @@ discard block |
||
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
723 | - * Execute a query |
|
724 | - * |
|
725 | - * @param string $Query_String the query to be executed |
|
726 | - * @param int $line the line method was called from - use __LINE__ |
|
727 | - * @param string $file the file method was called from - use __FILE__ |
|
728 | - * @param int $offset row to start from, default 0 |
|
729 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
730 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
731 | - * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
732 | - * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
733 | - * @return ADORecordSet or false, if the query fails |
|
734 | - * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
735 | - */ |
|
723 | + * Execute a query |
|
724 | + * |
|
725 | + * @param string $Query_String the query to be executed |
|
726 | + * @param int $line the line method was called from - use __LINE__ |
|
727 | + * @param string $file the file method was called from - use __FILE__ |
|
728 | + * @param int $offset row to start from, default 0 |
|
729 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
730 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
731 | + * @param int $fetchmode =self::FETCH_BOTH self::FETCH_BOTH (default), self::FETCH_ASSOC or self::FETCH_NUM |
|
732 | + * @param boolean $reconnect =true true: try reconnecting if server closes connection, false: dont (mysql only!) |
|
733 | + * @return ADORecordSet or false, if the query fails |
|
734 | + * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
|
735 | + */ |
|
736 | 736 | function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
737 | 737 | { |
738 | 738 | unset($line, $file); // not used anymore |
@@ -797,26 +797,26 @@ discard block |
||
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
800 | - * Execute a query with limited result set |
|
801 | - * |
|
802 | - * @param string $Query_String the query to be executed |
|
803 | - * @param int $offset row to start from, default 0 |
|
804 | - * @param int $line the line method was called from - use __LINE__ |
|
805 | - * @param string $file the file method was called from - use __FILE__ |
|
806 | - * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
807 | - * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
808 | - * @return ADORecordSet or false, if the query fails |
|
809 | - */ |
|
800 | + * Execute a query with limited result set |
|
801 | + * |
|
802 | + * @param string $Query_String the query to be executed |
|
803 | + * @param int $offset row to start from, default 0 |
|
804 | + * @param int $line the line method was called from - use __LINE__ |
|
805 | + * @param string $file the file method was called from - use __FILE__ |
|
806 | + * @param int $num_rows number of rows to return (optional), default -1 = all, 0 will use $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'] |
|
807 | + * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
|
808 | + * @return ADORecordSet or false, if the query fails |
|
809 | + */ |
|
810 | 810 | function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false) |
811 | 811 | { |
812 | 812 | return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr); |
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
816 | - * Begin Transaction |
|
817 | - * |
|
818 | - * @return int/boolean current transaction-id, of false if no connection |
|
819 | - */ |
|
816 | + * Begin Transaction |
|
817 | + * |
|
818 | + * @return int/boolean current transaction-id, of false if no connection |
|
819 | + */ |
|
820 | 820 | function transaction_begin() |
821 | 821 | { |
822 | 822 | if (!$this->Link_ID && !$this->connect()) |
@@ -828,10 +828,10 @@ discard block |
||
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
831 | - * Complete the transaction |
|
832 | - * |
|
833 | - * @return bool True if sucessful, False if fails |
|
834 | - */ |
|
831 | + * Complete the transaction |
|
832 | + * |
|
833 | + * @return bool True if sucessful, False if fails |
|
834 | + */ |
|
835 | 835 | function transaction_commit() |
836 | 836 | { |
837 | 837 | if (!$this->Link_ID && !$this->connect()) |
@@ -843,10 +843,10 @@ discard block |
||
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | - * Rollback the current transaction |
|
847 | - * |
|
848 | - * @return bool True if sucessful, False if fails |
|
849 | - */ |
|
846 | + * Rollback the current transaction |
|
847 | + * |
|
848 | + * @return bool True if sucessful, False if fails |
|
849 | + */ |
|
850 | 850 | function transaction_abort() |
851 | 851 | { |
852 | 852 | if (!$this->Link_ID && !$this->connect()) |
@@ -922,12 +922,12 @@ discard block |
||
922 | 922 | } |
923 | 923 | |
924 | 924 | /** |
925 | - * Find the primary key of the last insertion on the current db connection |
|
926 | - * |
|
927 | - * @param string $table name of table the insert was performed on |
|
928 | - * @param string $field the autoincrement primary key of the table |
|
929 | - * @return int the id, -1 if fails |
|
930 | - */ |
|
925 | + * Find the primary key of the last insertion on the current db connection |
|
926 | + * |
|
927 | + * @param string $table name of table the insert was performed on |
|
928 | + * @param string $field the autoincrement primary key of the table |
|
929 | + * @return int the id, -1 if fails |
|
930 | + */ |
|
931 | 931 | function get_last_insert_id($table, $field) |
932 | 932 | { |
933 | 933 | if (!$this->Link_ID && !$this->connect()) |
@@ -950,10 +950,10 @@ discard block |
||
950 | 950 | } |
951 | 951 | |
952 | 952 | /** |
953 | - * Get the number of rows affected by last update or delete |
|
954 | - * |
|
955 | - * @return int number of rows |
|
956 | - */ |
|
953 | + * Get the number of rows affected by last update or delete |
|
954 | + * |
|
955 | + * @return int number of rows |
|
956 | + */ |
|
957 | 957 | function affected_rows() |
958 | 958 | { |
959 | 959 | if ($this->log_updates) return 0; |
@@ -966,14 +966,14 @@ discard block |
||
966 | 966 | } |
967 | 967 | |
968 | 968 | /** |
969 | - * Get description of a table |
|
970 | - * |
|
971 | - * Beside the column-name all other data depends on the db-type !!! |
|
972 | - * |
|
973 | - * @param string $table name of table to describe |
|
974 | - * @param bool $full optional, default False summary information, True full information |
|
975 | - * @return array table meta data |
|
976 | - */ |
|
969 | + * Get description of a table |
|
970 | + * |
|
971 | + * Beside the column-name all other data depends on the db-type !!! |
|
972 | + * |
|
973 | + * @param string $table name of table to describe |
|
974 | + * @param bool $full optional, default False summary information, True full information |
|
975 | + * @return array table meta data |
|
976 | + */ |
|
977 | 977 | function metadata($table='',$full=false) |
978 | 978 | { |
979 | 979 | if (!$this->Link_ID && !$this->connect()) |
@@ -1055,10 +1055,10 @@ discard block |
||
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | /** |
1058 | - * Return a list of indexes in current database |
|
1059 | - * |
|
1060 | - * @return array list of indexes |
|
1061 | - */ |
|
1058 | + * Return a list of indexes in current database |
|
1059 | + * |
|
1060 | + * @return array list of indexes |
|
1061 | + */ |
|
1062 | 1062 | function index_names() |
1063 | 1063 | { |
1064 | 1064 | $indices = array(); |
@@ -1079,10 +1079,10 @@ discard block |
||
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
1082 | - * Returns an array containing column names that are the primary keys of $tablename. |
|
1083 | - * |
|
1084 | - * @return array of columns |
|
1085 | - */ |
|
1082 | + * Returns an array containing column names that are the primary keys of $tablename. |
|
1083 | + * |
|
1084 | + * @return array of columns |
|
1085 | + */ |
|
1086 | 1086 | function pkey_columns($tablename) |
1087 | 1087 | { |
1088 | 1088 | if (!$this->Link_ID && !$this->connect()) |
@@ -1093,13 +1093,13 @@ discard block |
||
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | /** |
1096 | - * Create a new database |
|
1097 | - * |
|
1098 | - * @param string $adminname name of database administrator user (optional) |
|
1099 | - * @param string $adminpasswd password for the database administrator user (optional) |
|
1100 | - * @param string $charset default charset for the database |
|
1101 | - * @param string $grant_host ='localhost' host/ip of the webserver |
|
1102 | - */ |
|
1096 | + * Create a new database |
|
1097 | + * |
|
1098 | + * @param string $adminname name of database administrator user (optional) |
|
1099 | + * @param string $adminpasswd password for the database administrator user (optional) |
|
1100 | + * @param string $charset default charset for the database |
|
1101 | + * @param string $grant_host ='localhost' host/ip of the webserver |
|
1102 | + */ |
|
1103 | 1103 | function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost') |
1104 | 1104 | { |
1105 | 1105 | $currentUser = $this->User; |
@@ -1356,12 +1356,12 @@ discard block |
||
1356 | 1356 | } |
1357 | 1357 | |
1358 | 1358 | /** |
1359 | - * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements |
|
1360 | - * |
|
1361 | - * This is mostly copy & paste from adodb's datadict class |
|
1362 | - * @param string $_name |
|
1363 | - * @return string quoted string |
|
1364 | - */ |
|
1359 | + * Correctly Quote Identifiers like table- or colmnnames for use in SQL-statements |
|
1360 | + * |
|
1361 | + * This is mostly copy & paste from adodb's datadict class |
|
1362 | + * @param string $_name |
|
1363 | + * @return string quoted string |
|
1364 | + */ |
|
1365 | 1365 | function name_quote($_name = NULL) |
1366 | 1366 | { |
1367 | 1367 | if (!is_string($_name)) |
@@ -1400,19 +1400,19 @@ discard block |
||
1400 | 1400 | } |
1401 | 1401 | |
1402 | 1402 | /** |
1403 | - * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-) |
|
1404 | - * |
|
1405 | - * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'". |
|
1406 | - * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0 |
|
1407 | - * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'" |
|
1408 | - * |
|
1409 | - * @param mixed $value the value to be escaped |
|
1410 | - * @param string|boolean $type =false string the type of the db-column, default False === varchar |
|
1411 | - * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL |
|
1412 | - * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres) |
|
1413 | - * @param string $glue =',' used to glue array values together for the string type |
|
1414 | - * @return string escaped sting |
|
1415 | - */ |
|
1403 | + * Escape values before sending them to the database - prevents SQL injection and SQL errors ;-) |
|
1404 | + * |
|
1405 | + * Please note that the quote function already returns necessary quotes: quote('Hello') === "'Hello'". |
|
1406 | + * Int and Auto types are casted to int: quote('1','int') === 1, quote('','int') === 0, quote('Hello','int') === 0 |
|
1407 | + * Arrays of id's stored in strings: quote(array(1,2,3),'string') === "'1,2,3'" |
|
1408 | + * |
|
1409 | + * @param mixed $value the value to be escaped |
|
1410 | + * @param string|boolean $type =false string the type of the db-column, default False === varchar |
|
1411 | + * @param boolean $not_null =true is column NOT NULL, default true, else php null values are written as SQL NULL |
|
1412 | + * @param int $length =null length of the varchar column, to truncate it if the database requires it (eg. Postgres) |
|
1413 | + * @param string $glue =',' used to glue array values together for the string type |
|
1414 | + * @return string escaped sting |
|
1415 | + */ |
|
1416 | 1416 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
1417 | 1417 | { |
1418 | 1418 | if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
@@ -1493,27 +1493,27 @@ discard block |
||
1493 | 1493 | } |
1494 | 1494 | |
1495 | 1495 | /** |
1496 | - * Implodes an array of column-value pairs for the use in sql-querys. |
|
1497 | - * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-). |
|
1498 | - * |
|
1499 | - * @author RalfBecker<at>outdoor-training.de |
|
1500 | - * |
|
1501 | - * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query |
|
1502 | - * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted |
|
1503 | - * according to the type of the column, and the whole array with be formatted like (val1,val2,...) |
|
1504 | - * If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists. |
|
1505 | - * If the key is numerical (no key given in the array-definition) the value is used as is, eg. |
|
1506 | - * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
|
1507 | - * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
|
1508 | - * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
|
1509 | - * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
1510 | - * typicaly used to form a WHERE-clause from the primary keys. |
|
1511 | - * If set to True, only columns from the colum_definitons are written. |
|
1512 | - * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1513 | - * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1514 | - * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1515 | - * @return string SQL |
|
1516 | - */ |
|
1496 | + * Implodes an array of column-value pairs for the use in sql-querys. |
|
1497 | + * All data is run through quote (does either addslashes() or (int)) - prevents SQL injunction and SQL errors ;-). |
|
1498 | + * |
|
1499 | + * @author RalfBecker<at>outdoor-training.de |
|
1500 | + * |
|
1501 | + * @param string $glue in most cases this will be either ',' or ' AND ', depending you your query |
|
1502 | + * @param array $array column-name / value pairs, if the value is an array all its array-values will be quoted |
|
1503 | + * according to the type of the column, and the whole array with be formatted like (val1,val2,...) |
|
1504 | + * If $use_key == True, an ' IN ' instead a '=' is used. Good for category- or user-lists. |
|
1505 | + * If the key is numerical (no key given in the array-definition) the value is used as is, eg. |
|
1506 | + * array('visits=visits+1') gives just "visits=visits+1" (no quoting at all !!!) |
|
1507 | + * @param boolean|string $use_key If $use_key===True a "$key=" prefix each value (default), typically set to False |
|
1508 | + * or 'VALUES' for insert querys, on 'VALUES' "(key1,key2,...) VALUES (val1,val2,...)" is returned |
|
1509 | + * @param array|boolean $only if set to an array only colums which are set (as data !!!) are written |
|
1510 | + * typicaly used to form a WHERE-clause from the primary keys. |
|
1511 | + * If set to True, only columns from the colum_definitons are written. |
|
1512 | + * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1513 | + * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1514 | + * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1515 | + * @return string SQL |
|
1516 | + */ |
|
1517 | 1517 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
1518 | 1518 | { |
1519 | 1519 | if (!is_array($array)) // this allows to give an SQL-string for delete or update |
@@ -1599,14 +1599,14 @@ discard block |
||
1599 | 1599 | } |
1600 | 1600 | |
1601 | 1601 | /** |
1602 | - * Sets the default column-definitions for use with column_data_implode() |
|
1603 | - * |
|
1604 | - * @author RalfBecker<at>outdoor-training.de |
|
1605 | - * |
|
1606 | - * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1607 | - * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1608 | - * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1609 | - */ |
|
1602 | + * Sets the default column-definitions for use with column_data_implode() |
|
1603 | + * |
|
1604 | + * @author RalfBecker<at>outdoor-training.de |
|
1605 | + * |
|
1606 | + * @param array|boolean $column_definitions this can be set to the column-definitions-array |
|
1607 | + * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
|
1608 | + * If its set, the column-type-data determinates if (int) or addslashes is used. |
|
1609 | + */ |
|
1610 | 1610 | function set_column_definitions($column_definitions=False) |
1611 | 1611 | { |
1612 | 1612 | $this->column_definitions=$column_definitions; |
@@ -1668,17 +1668,17 @@ discard block |
||
1668 | 1668 | } |
1669 | 1669 | |
1670 | 1670 | /** |
1671 | - * reads the table-definitions from the app's setup/tables_current.inc.php file |
|
1672 | - * |
|
1673 | - * The already read table-definitions are shared between all db-instances via a static var. |
|
1674 | - * |
|
1675 | - * @author RalfBecker<at>outdoor-training.de |
|
1676 | - * |
|
1677 | - * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app, |
|
1678 | - * true to search the already loaded table-definitions for $table and then search all existing apps for it |
|
1679 | - * @param bool|string $table if set return only defintions of that table, else return all defintions |
|
1680 | - * @return mixed array with table-defintions or False if file not found |
|
1681 | - */ |
|
1671 | + * reads the table-definitions from the app's setup/tables_current.inc.php file |
|
1672 | + * |
|
1673 | + * The already read table-definitions are shared between all db-instances via a static var. |
|
1674 | + * |
|
1675 | + * @author RalfBecker<at>outdoor-training.de |
|
1676 | + * |
|
1677 | + * @param bool|string $app name of the app or default False to use the app set by db::set_app or the current app, |
|
1678 | + * true to search the already loaded table-definitions for $table and then search all existing apps for it |
|
1679 | + * @param bool|string $table if set return only defintions of that table, else return all defintions |
|
1680 | + * @return mixed array with table-defintions or False if file not found |
|
1681 | + */ |
|
1682 | 1682 | function get_table_definitions($app=False,$table=False) |
1683 | 1683 | { |
1684 | 1684 | // ease the transition to api |
@@ -1773,21 +1773,21 @@ discard block |
||
1773 | 1773 | } |
1774 | 1774 | |
1775 | 1775 | /** |
1776 | - * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
1777 | - * |
|
1778 | - * @author RalfBecker<at>outdoor-training.de |
|
1779 | - * |
|
1780 | - * @param string $table name of the table |
|
1781 | - * @param array $data with column-name / value pairs |
|
1782 | - * @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 |
|
1783 | - * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
1784 | - * @param int $line line-number to pass to query |
|
1785 | - * @param string $file file-name to pass to query |
|
1786 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1787 | - * @param bool $use_prepared_statement use a prepared statement |
|
1788 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1789 | - * @return ADORecordSet or false, if the query fails |
|
1790 | - */ |
|
1776 | + * Insert a row of data into a table or updates it if $where is given, all data is quoted according to it's type |
|
1777 | + * |
|
1778 | + * @author RalfBecker<at>outdoor-training.de |
|
1779 | + * |
|
1780 | + * @param string $table name of the table |
|
1781 | + * @param array $data with column-name / value pairs |
|
1782 | + * @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 |
|
1783 | + * if the row exists db::update is called else a new row with $date merged with $where gets inserted (data has precedence) |
|
1784 | + * @param int $line line-number to pass to query |
|
1785 | + * @param string $file file-name to pass to query |
|
1786 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1787 | + * @param bool $use_prepared_statement use a prepared statement |
|
1788 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1789 | + * @return ADORecordSet or false, if the query fails |
|
1790 | + */ |
|
1791 | 1791 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1792 | 1792 | { |
1793 | 1793 | if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
@@ -1883,20 +1883,20 @@ discard block |
||
1883 | 1883 | } |
1884 | 1884 | |
1885 | 1885 | /** |
1886 | - * Updates the data of one or more rows in a table, all data is quoted according to it's type |
|
1887 | - * |
|
1888 | - * @author RalfBecker<at>outdoor-training.de |
|
1889 | - * |
|
1890 | - * @param string $table name of the table |
|
1891 | - * @param array $data with column-name / value pairs |
|
1892 | - * @param array $where column-name / values pairs and'ed together for the where clause |
|
1893 | - * @param int $line line-number to pass to query |
|
1894 | - * @param string $file file-name to pass to query |
|
1895 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1896 | - * @param bool $use_prepared_statement use a prepared statement |
|
1897 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1898 | - * @return ADORecordSet or false, if the query fails |
|
1899 | - */ |
|
1886 | + * Updates the data of one or more rows in a table, all data is quoted according to it's type |
|
1887 | + * |
|
1888 | + * @author RalfBecker<at>outdoor-training.de |
|
1889 | + * |
|
1890 | + * @param string $table name of the table |
|
1891 | + * @param array $data with column-name / value pairs |
|
1892 | + * @param array $where column-name / values pairs and'ed together for the where clause |
|
1893 | + * @param int $line line-number to pass to query |
|
1894 | + * @param string $file file-name to pass to query |
|
1895 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1896 | + * @param bool $use_prepared_statement use a prepared statement |
|
1897 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1898 | + * @return ADORecordSet or false, if the query fails |
|
1899 | + */ |
|
1900 | 1900 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1901 | 1901 | { |
1902 | 1902 | if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
@@ -1973,18 +1973,18 @@ discard block |
||
1973 | 1973 | } |
1974 | 1974 | |
1975 | 1975 | /** |
1976 | - * Deletes one or more rows in table, all data is quoted according to it's type |
|
1977 | - * |
|
1978 | - * @author RalfBecker<at>outdoor-training.de |
|
1979 | - * |
|
1980 | - * @param string $table name of the table |
|
1981 | - * @param array $where column-name / values pairs and'ed together for the where clause |
|
1982 | - * @param int $line line-number to pass to query |
|
1983 | - * @param string $file file-name to pass to query |
|
1984 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
1985 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1986 | - * @return ADORecordSet or false, if the query fails |
|
1987 | - */ |
|
1976 | + * Deletes one or more rows in table, all data is quoted according to it's type |
|
1977 | + * |
|
1978 | + * @author RalfBecker<at>outdoor-training.de |
|
1979 | + * |
|
1980 | + * @param string $table name of the table |
|
1981 | + * @param array $where column-name / values pairs and'ed together for the where clause |
|
1982 | + * @param int $line line-number to pass to query |
|
1983 | + * @param string $file file-name to pass to query |
|
1984 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
1985 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
1986 | + * @return ADORecordSet or false, if the query fails |
|
1987 | + */ |
|
1988 | 1988 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
1989 | 1989 | { |
1990 | 1990 | if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
@@ -2050,25 +2050,25 @@ discard block |
||
2050 | 2050 | } |
2051 | 2051 | |
2052 | 2052 | /** |
2053 | - * Selects one or more rows in table depending on where, all data is quoted according to it's type |
|
2054 | - * |
|
2055 | - * @author RalfBecker<at>outdoor-training.de |
|
2056 | - * |
|
2057 | - * @param string $table name of the table |
|
2058 | - * @param array|string $cols string or array of column-names / select-expressions |
|
2059 | - * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause |
|
2060 | - * @param int $line line-number to pass to query |
|
2061 | - * @param string $file file-name to pass to query |
|
2062 | - * @param int|bool $offset offset for a limited query or False (default) |
|
2063 | - * @param string $append string to append to the end of the query, eg. ORDER BY ... |
|
2064 | - * @param string|boolean $app string with name of app or False to use the current-app |
|
2065 | - * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2066 | - * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
|
2067 | - * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
|
2068 | - * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
2069 | - * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2070 | - * @return ADORecordSet or false, if the query fails |
|
2071 | - */ |
|
2053 | + * Selects one or more rows in table depending on where, all data is quoted according to it's type |
|
2054 | + * |
|
2055 | + * @author RalfBecker<at>outdoor-training.de |
|
2056 | + * |
|
2057 | + * @param string $table name of the table |
|
2058 | + * @param array|string $cols string or array of column-names / select-expressions |
|
2059 | + * @param array|string $where string or array with column-name / values pairs AND'ed together for the where clause |
|
2060 | + * @param int $line line-number to pass to query |
|
2061 | + * @param string $file file-name to pass to query |
|
2062 | + * @param int|bool $offset offset for a limited query or False (default) |
|
2063 | + * @param string $append string to append to the end of the query, eg. ORDER BY ... |
|
2064 | + * @param string|boolean $app string with name of app or False to use the current-app |
|
2065 | + * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2066 | + * @param string $join =null sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
|
2067 | + * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
|
2068 | + * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
|
2069 | + * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2070 | + * @return ADORecordSet or false, if the query fails |
|
2071 | + */ |
|
2072 | 2072 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
2073 | 2073 | { |
2074 | 2074 | 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"; |
@@ -2103,20 +2103,20 @@ discard block |
||
2103 | 2103 | } |
2104 | 2104 | |
2105 | 2105 | /** |
2106 | - * Does a union over multiple selects |
|
2107 | - * |
|
2108 | - * @author RalfBecker<at>outdoor-training.de |
|
2109 | - * |
|
2110 | - * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def |
|
2111 | - * For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional |
|
2112 | - * @param int $line line-number to pass to query |
|
2113 | - * @param string $file file-name to pass to query |
|
2114 | - * @param string $order_by ORDER BY statement for the union |
|
2115 | - * @param int|bool $offset offset for a limited query or False (default) |
|
2116 | - * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2117 | - * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2118 | - * @return ADORecordSet or false, if the query fails |
|
2119 | - */ |
|
2106 | + * Does a union over multiple selects |
|
2107 | + * |
|
2108 | + * @author RalfBecker<at>outdoor-training.de |
|
2109 | + * |
|
2110 | + * @param array $selects array of selects, each select is an array with the possible keys/parameters: table, cols, where, append, app, join, table_def |
|
2111 | + * For further info about parameters see the definition of the select function, beside table, cols and where all other params are optional |
|
2112 | + * @param int $line line-number to pass to query |
|
2113 | + * @param string $file file-name to pass to query |
|
2114 | + * @param string $order_by ORDER BY statement for the union |
|
2115 | + * @param int|bool $offset offset for a limited query or False (default) |
|
2116 | + * @param int $num_rows number of rows to return if offset set, default 0 = use default in user prefs |
|
2117 | + * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
|
2118 | + * @return ADORecordSet or false, if the query fails |
|
2119 | + */ |
|
2120 | 2120 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
2121 | 2121 | { |
2122 | 2122 | if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
@@ -389,7 +389,10 @@ discard block |
||
389 | 389 | if ($state['wsrep_local_state_comment'] == 'Synced' || |
390 | 390 | // if we have only 2 nodes (2. one starting), we can only use the donor |
391 | 391 | $state['wsrep_local_state_comment'] == 'Donor/Desynced' && |
392 | - $state['wsrep_cluster_size'] == 2) return; |
|
392 | + $state['wsrep_cluster_size'] == 2) |
|
393 | + { |
|
394 | + return; |
|
395 | + } |
|
393 | 396 | |
394 | 397 | throw new Db\Exception\Connection('Node is NOT Synced! '.array2string($state)); |
395 | 398 | } |
@@ -408,7 +411,10 @@ discard block |
||
408 | 411 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
409 | 412 | $num_hosts = count($hosts); |
410 | 413 | $n =& Cache::getSession(__CLASS__, $this->Host); |
411 | - if (!isset($n)) $n = 0; |
|
414 | + if (!isset($n)) |
|
415 | + { |
|
416 | + $n = 0; |
|
417 | + } |
|
412 | 418 | |
413 | 419 | if ($next && ++$n >= $num_hosts+2) |
414 | 420 | { |
@@ -438,7 +444,10 @@ discard block |
||
438 | 444 | foreach(array('Database','User','Password','Port','Type') as $name) |
439 | 445 | { |
440 | 446 | $$name = $this->$name; |
441 | - if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
|
447 | + if (${$name}[0] == '@' && $name != 'Password') |
|
448 | + { |
|
449 | + $$name = getenv(substr($$name, 1)); |
|
450 | + } |
|
442 | 451 | } |
443 | 452 | $this->setupType = $php_extension = $Type; |
444 | 453 | |
@@ -457,7 +466,10 @@ discard block |
||
457 | 466 | $Type = 'mssql'; |
458 | 467 | // fall through |
459 | 468 | case 'mssql': |
460 | - if ($Port) $Host .= ','.$Port; |
|
469 | + if ($Port) |
|
470 | + { |
|
471 | + $Host .= ','.$Port; |
|
472 | + } |
|
461 | 473 | break; |
462 | 474 | |
463 | 475 | case 'odbc_oracle': |
@@ -492,7 +504,10 @@ discard block |
||
492 | 504 | $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
493 | 505 | // fall through |
494 | 506 | default: |
495 | - if ($Port) $Host .= ':'.$Port; |
|
507 | + if ($Port) |
|
508 | + { |
|
509 | + $Host .= ':'.$Port; |
|
510 | + } |
|
496 | 511 | break; |
497 | 512 | } |
498 | 513 | if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
@@ -507,10 +522,13 @@ discard block |
||
507 | 522 | { |
508 | 523 | 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 !!!"); |
509 | 524 | } |
510 | - if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
|
525 | + if (!isset($GLOBALS['egw']->ADOdb)) |
|
526 | + { |
|
527 | + // use the global object to store the connection |
|
511 | 528 | { |
512 | 529 | $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
513 | 530 | } |
531 | + } |
|
514 | 532 | else |
515 | 533 | { |
516 | 534 | $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
@@ -612,7 +630,11 @@ discard block |
||
612 | 630 | */ |
613 | 631 | function __sleep() |
614 | 632 | { |
615 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
633 | + if (!empty($this->setupType)) |
|
634 | + { |
|
635 | + $this->Type = $this->setupType; |
|
636 | + } |
|
637 | + // restore Type eg. to mysqli |
|
616 | 638 | |
617 | 639 | $vars = get_object_vars($this); |
618 | 640 | unset($vars['Link_ID'], $vars['Query_ID'], $vars['privat_Link_ID']); |
@@ -674,7 +696,10 @@ discard block |
||
674 | 696 | unset($this->Link_ID); |
675 | 697 | $this->Link_ID = 0; |
676 | 698 | |
677 | - if (!empty($this->setupType)) $this->Type = $this->setupType; |
|
699 | + if (!empty($this->setupType)) |
|
700 | + { |
|
701 | + $this->Type = $this->setupType; |
|
702 | + } |
|
678 | 703 | } |
679 | 704 | |
680 | 705 | /** |
@@ -756,7 +781,10 @@ discard block |
||
756 | 781 | } |
757 | 782 | if (($this->readonly || $this->log_updates) && !preg_match('/^\(?(SELECT|SET|SHOW)/i', $Query_String)) |
758 | 783 | { |
759 | - if ($this->log_updates) error_log($Query_String.': '.function_backtrace()); |
|
784 | + if ($this->log_updates) |
|
785 | + { |
|
786 | + error_log($Query_String.': '.function_backtrace()); |
|
787 | + } |
|
760 | 788 | if ($this->readonly) |
761 | 789 | { |
762 | 790 | $this->Error = 'Database is readonly'; |
@@ -788,16 +816,22 @@ discard block |
||
788 | 816 | } |
789 | 817 | if (!$rs) |
790 | 818 | { |
791 | - if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) // Server has gone away |
|
819 | + if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) |
|
820 | + { |
|
821 | + // Server has gone away |
|
792 | 822 | { |
793 | 823 | $this->disconnect(); |
824 | + } |
|
794 | 825 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
795 | 826 | } |
796 | 827 | throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
797 | 828 | "\n$this->Error ($this->Errno)". |
798 | 829 | ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
799 | 830 | } |
800 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
831 | + elseif(empty($rs->sql)) |
|
832 | + { |
|
833 | + $rs->sql = $Query_String; |
|
834 | + } |
|
801 | 835 | return $rs; |
802 | 836 | } |
803 | 837 | |
@@ -945,9 +979,12 @@ discard block |
||
945 | 979 | } |
946 | 980 | $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
947 | 981 | |
948 | - if ($id === False) // function not supported |
|
982 | + if ($id === False) |
|
983 | + { |
|
984 | + // function not supported |
|
949 | 985 | { |
950 | 986 | 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"; |
987 | + } |
|
951 | 988 | echo '<p>'.function_backtrace()."</p>\n"; |
952 | 989 | return -1; |
953 | 990 | } |
@@ -961,7 +998,10 @@ discard block |
||
961 | 998 | */ |
962 | 999 | function affected_rows() |
963 | 1000 | { |
964 | - if ($this->log_updates) return 0; |
|
1001 | + if ($this->log_updates) |
|
1002 | + { |
|
1003 | + return 0; |
|
1004 | + } |
|
965 | 1005 | |
966 | 1006 | if (!$this->Link_ID && !$this->connect()) |
967 | 1007 | { |
@@ -995,9 +1035,18 @@ discard block |
||
995 | 1035 | { |
996 | 1036 | // for backwards compatibilty (depreciated) |
997 | 1037 | $flags = null; |
998 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
999 | - if($column->primary_key) $flags .= "primary_key "; |
|
1000 | - if($column->binary) $flags .= "binary "; |
|
1038 | + if($column->auto_increment) |
|
1039 | + { |
|
1040 | + $flags .= "auto_increment "; |
|
1041 | + } |
|
1042 | + if($column->primary_key) |
|
1043 | + { |
|
1044 | + $flags .= "primary_key "; |
|
1045 | + } |
|
1046 | + if($column->binary) |
|
1047 | + { |
|
1048 | + $flags .= "binary "; |
|
1049 | + } |
|
1001 | 1050 | |
1002 | 1051 | $metadata[$i] = array( |
1003 | 1052 | 'table' => $table, |
@@ -1034,7 +1083,10 @@ discard block |
||
1034 | 1083 | */ |
1035 | 1084 | function table_names($just_name=false) |
1036 | 1085 | { |
1037 | - if (!$this->Link_ID) $this->connect(); |
|
1086 | + if (!$this->Link_ID) |
|
1087 | + { |
|
1088 | + $this->connect(); |
|
1089 | + } |
|
1038 | 1090 | if (!$this->Link_ID) |
1039 | 1091 | { |
1040 | 1092 | return False; |
@@ -1186,8 +1238,14 @@ discard block |
||
1186 | 1238 | case 'mysqli': |
1187 | 1239 | case 'mysql': |
1188 | 1240 | $sql = 'GROUP_CONCAT('.$expr; |
1189 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
1190 | - if ($separator != ',') $sql .= ' SEPARATOR '.$this->quote($separator); |
|
1241 | + if ($order_by) |
|
1242 | + { |
|
1243 | + $sql .= ' ORDER BY '.$order_by; |
|
1244 | + } |
|
1245 | + if ($separator != ',') |
|
1246 | + { |
|
1247 | + $sql .= ' SEPARATOR '.$this->quote($separator); |
|
1248 | + } |
|
1191 | 1249 | $sql .= ')'; |
1192 | 1250 | break; |
1193 | 1251 | |
@@ -1197,7 +1255,10 @@ discard block |
||
1197 | 1255 | return false; |
1198 | 1256 | } |
1199 | 1257 | $sql = 'ARRAY_TO_STRING(ARRAY_AGG('.$expr; |
1200 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
1258 | + if ($order_by) |
|
1259 | + { |
|
1260 | + $sql .= ' ORDER BY '.$order_by; |
|
1261 | + } |
|
1201 | 1262 | $sql .= '), '.$this->quote($separator).')'; |
1202 | 1263 | break; |
1203 | 1264 | |
@@ -1420,12 +1481,18 @@ discard block |
||
1420 | 1481 | */ |
1421 | 1482 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
1422 | 1483 | { |
1423 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1484 | + if ($this->Debug) |
|
1485 | + { |
|
1486 | + echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1487 | + } |
|
1424 | 1488 | |
1425 | - if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
|
1489 | + if (!$not_null && is_null($value)) |
|
1490 | + { |
|
1491 | + // writing unset php-variables and those set to NULL now as SQL NULL |
|
1426 | 1492 | { |
1427 | 1493 | return 'NULL'; |
1428 | 1494 | } |
1495 | + } |
|
1429 | 1496 | switch($type) |
1430 | 1497 | { |
1431 | 1498 | case 'int': |
@@ -1440,10 +1507,13 @@ discard block |
||
1440 | 1507 | // There for we have to keep it as float by using round instead the int cast. |
1441 | 1508 | return is_float($value) ? round($value) : (int) $value; |
1442 | 1509 | case 'bool': |
1443 | - if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
|
1510 | + if ($this->Type == 'mysql') |
|
1511 | + { |
|
1512 | + // maybe it's not longer necessary with mysql5 |
|
1444 | 1513 | { |
1445 | 1514 | return $value ? 1 : 0; |
1446 | 1515 | } |
1516 | + } |
|
1447 | 1517 | return $value ? 'true' : 'false'; |
1448 | 1518 | case 'float': |
1449 | 1519 | case 'decimal': |
@@ -1490,7 +1560,10 @@ discard block |
||
1490 | 1560 | } |
1491 | 1561 | // casting boolean explicitly to string, as ADODB_postgres64::qstr() has an unwanted special handling |
1492 | 1562 | // for boolean types, causing it to return "true" or "false" and not a quoted string like "'1'"! |
1493 | - if (is_bool($value)) $value = (string)$value; |
|
1563 | + if (is_bool($value)) |
|
1564 | + { |
|
1565 | + $value = (string)$value; |
|
1566 | + } |
|
1494 | 1567 | |
1495 | 1568 | // MySQL and MariaDB not 10.1 need 4-byte utf8 chars replaced with our default utf8 charset |
1496 | 1569 | // (MariaDB 10.1 does the replacement automatic, 10.0 cuts everything off behind and MySQL gives an error) |
@@ -1529,15 +1602,21 @@ discard block |
||
1529 | 1602 | */ |
1530 | 1603 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
1531 | 1604 | { |
1532 | - if (!is_array($array)) // this allows to give an SQL-string for delete or update |
|
1605 | + if (!is_array($array)) |
|
1606 | + { |
|
1607 | + // this allows to give an SQL-string for delete or update |
|
1533 | 1608 | { |
1534 | 1609 | return $array; |
1535 | 1610 | } |
1611 | + } |
|
1536 | 1612 | if (!$column_definitions) |
1537 | 1613 | { |
1538 | 1614 | $column_definitions = $this->column_definitions; |
1539 | 1615 | } |
1540 | - 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"; |
|
1616 | + if ($this->Debug) |
|
1617 | + { |
|
1618 | + 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"; |
|
1619 | + } |
|
1541 | 1620 | |
1542 | 1621 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
1543 | 1622 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
@@ -1554,7 +1633,10 @@ discard block |
||
1554 | 1633 | // fix "table.column" expressions, to not trigger exception, if column alone would work |
1555 | 1634 | if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key])) |
1556 | 1635 | { |
1557 | - if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
|
1636 | + if (strpos($key, '.') !== false) |
|
1637 | + { |
|
1638 | + list(, $col) = explode('.', $key); |
|
1639 | + } |
|
1558 | 1640 | if (!isset($column_definitions[$col])) |
1559 | 1641 | { |
1560 | 1642 | 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>"); |
@@ -1594,7 +1676,11 @@ discard block |
||
1594 | 1676 | } |
1595 | 1677 | elseif (is_int($key) && $use_key===True) |
1596 | 1678 | { |
1597 | - if (empty($data)) continue; // would give SQL error |
|
1679 | + if (empty($data)) |
|
1680 | + { |
|
1681 | + continue; |
|
1682 | + } |
|
1683 | + // would give SQL error |
|
1598 | 1684 | $values[] = $data; |
1599 | 1685 | } |
1600 | 1686 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
@@ -1648,7 +1734,10 @@ discard block |
||
1648 | 1734 | function set_app($app) |
1649 | 1735 | { |
1650 | 1736 | // ease the transition to api |
1651 | - if ($app == 'phpgwapi') $app = 'api'; |
|
1737 | + if ($app == 'phpgwapi') |
|
1738 | + { |
|
1739 | + $app = 'api'; |
|
1740 | + } |
|
1652 | 1741 | |
1653 | 1742 | if ($this === $GLOBALS['egw']->db && $app != self::API_APPNAME) |
1654 | 1743 | { |
@@ -1695,7 +1784,10 @@ discard block |
||
1695 | 1784 | function get_table_definitions($app=False,$table=False) |
1696 | 1785 | { |
1697 | 1786 | // ease the transition to api |
1698 | - if ($app === 'phpgwapi') $app = 'api'; |
|
1787 | + if ($app === 'phpgwapi') |
|
1788 | + { |
|
1789 | + $app = 'api'; |
|
1790 | + } |
|
1699 | 1791 | |
1700 | 1792 | if ($app === true && $table) |
1701 | 1793 | { |
@@ -1752,10 +1844,16 @@ discard block |
||
1752 | 1844 | } |
1753 | 1845 | if ($table && (!$app_data || !isset($app_data[$table]))) |
1754 | 1846 | { |
1755 | - if ($this->Debug) echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
1847 | + if ($this->Debug) |
|
1848 | + { |
|
1849 | + echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
1850 | + } |
|
1756 | 1851 | return False; |
1757 | 1852 | } |
1758 | - if ($this->Debug) echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
1853 | + if ($this->Debug) |
|
1854 | + { |
|
1855 | + echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
1856 | + } |
|
1759 | 1857 | return $table ? $app_data[$table] : $app_data; |
1760 | 1858 | } |
1761 | 1859 | |
@@ -1780,7 +1878,10 @@ discard block |
||
1780 | 1878 | $table_def = $db->get_table_definitions($app,$table); |
1781 | 1879 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
1782 | 1880 | } |
1783 | - if ($cached_columns === false) return null; |
|
1881 | + if ($cached_columns === false) |
|
1882 | + { |
|
1883 | + return null; |
|
1884 | + } |
|
1784 | 1885 | |
1785 | 1886 | return is_null($attribute) ? $cached_columns[$column] : $cached_columns[$column][$attribute]; |
1786 | 1887 | } |
@@ -1803,9 +1904,15 @@ discard block |
||
1803 | 1904 | */ |
1804 | 1905 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1805 | 1906 | { |
1806 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1907 | + if ($this->Debug) |
|
1908 | + { |
|
1909 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1910 | + } |
|
1807 | 1911 | |
1808 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1912 | + if (!$table_def) |
|
1913 | + { |
|
1914 | + $table_def = $this->get_table_definitions($app,$table); |
|
1915 | + } |
|
1809 | 1916 | |
1810 | 1917 | $sql_append = ''; |
1811 | 1918 | $cmd = 'INSERT'; |
@@ -1847,9 +1954,12 @@ discard block |
||
1847 | 1954 | $table = self::$tablealiases[$table]; |
1848 | 1955 | } |
1849 | 1956 | $inputarr = false; |
1850 | - if (isset($data[0]) && is_array($data[0])) // multiple data rows |
|
1957 | + if (isset($data[0]) && is_array($data[0])) |
|
1958 | + { |
|
1959 | + // multiple data rows |
|
1851 | 1960 | { |
1852 | 1961 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
1962 | + } |
|
1853 | 1963 | |
1854 | 1964 | $sql = "$cmd INTO $table "; |
1855 | 1965 | foreach($data as $k => $d) |
@@ -1865,15 +1975,22 @@ discard block |
||
1865 | 1975 | } |
1866 | 1976 | $sql .= $sql_append; |
1867 | 1977 | } |
1868 | - elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
1978 | + elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
1979 | + { |
|
1980 | + // eg. MaxDB |
|
1869 | 1981 | { |
1870 | - $this->Link_ID->Param(false); // reset param-counter |
|
1982 | + $this->Link_ID->Param(false); |
|
1983 | + } |
|
1984 | + // reset param-counter |
|
1871 | 1985 | $cols = array_keys($data); |
1872 | 1986 | foreach($cols as $k => $col) |
1873 | 1987 | { |
1874 | - if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
|
1988 | + if (!isset($table_def['fd'][$col])) |
|
1989 | + { |
|
1990 | + // ignore columns not in this table |
|
1875 | 1991 | { |
1876 | 1992 | unset($cols[$k]); |
1993 | + } |
|
1877 | 1994 | continue; |
1878 | 1995 | } |
1879 | 1996 | $params[] = $this->Link_ID->Param($col); |
@@ -1891,7 +2008,10 @@ discard block |
||
1891 | 2008 | { |
1892 | 2009 | $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
1893 | 2010 | } |
1894 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
2011 | + if ($this->Debug) |
|
2012 | + { |
|
2013 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
2014 | + } |
|
1895 | 2015 | return $this->query($sql,$line,$file,0,-1,$inputarr); |
1896 | 2016 | } |
1897 | 2017 | |
@@ -1912,8 +2032,14 @@ discard block |
||
1912 | 2032 | */ |
1913 | 2033 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
1914 | 2034 | { |
1915 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
1916 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2035 | + if ($this->Debug) |
|
2036 | + { |
|
2037 | + echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
2038 | + } |
|
2039 | + if (!$table_def) |
|
2040 | + { |
|
2041 | + $table_def = $this->get_table_definitions($app,$table); |
|
2042 | + } |
|
1917 | 2043 | |
1918 | 2044 | $blobs2update = array(); |
1919 | 2045 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1922,7 +2048,10 @@ discard block |
||
1922 | 2048 | { |
1923 | 2049 | case 'sapdb': |
1924 | 2050 | case 'maxdb': |
1925 | - if ($use_prepared_statement) break; |
|
2051 | + if ($use_prepared_statement) |
|
2052 | + { |
|
2053 | + break; |
|
2054 | + } |
|
1926 | 2055 | // check if data contains any LONG columns |
1927 | 2056 | foreach($data as $col => $val) |
1928 | 2057 | { |
@@ -1947,12 +2076,20 @@ discard block |
||
1947 | 2076 | if (!empty($data)) |
1948 | 2077 | { |
1949 | 2078 | $inputarr = false; |
1950 | - if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
2079 | + if ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
1951 | 2080 | { |
1952 | - $this->Link_ID->Param(false); // reset param-counter |
|
2081 | + // eg. MaxDB |
|
2082 | + { |
|
2083 | + $this->Link_ID->Param(false); |
|
2084 | + } |
|
2085 | + // reset param-counter |
|
1953 | 2086 | foreach($data as $col => $val) |
1954 | 2087 | { |
1955 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
2088 | + if (!isset($table_def['fd'][$col])) |
|
2089 | + { |
|
2090 | + continue; |
|
2091 | + } |
|
2092 | + // ignore columns not in this table |
|
1956 | 2093 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
1957 | 2094 | } |
1958 | 2095 | $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
@@ -1970,7 +2107,10 @@ discard block |
||
1970 | 2107 | $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
1971 | 2108 | } |
1972 | 2109 | $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
1973 | - if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
2110 | + if ($this->Debug) |
|
2111 | + { |
|
2112 | + echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
2113 | + } |
|
1974 | 2114 | } |
1975 | 2115 | // if we have any blobs to update, we do so now |
1976 | 2116 | if (($ret || !count($data)) && count($blobs2update)) |
@@ -1978,8 +2118,14 @@ discard block |
||
1978 | 2118 | foreach($blobs2update as $col => $val) |
1979 | 2119 | { |
1980 | 2120 | $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
1981 | - if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
1982 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
2121 | + if ($this->Debug) |
|
2122 | + { |
|
2123 | + echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
2124 | + } |
|
2125 | + if (!$ret) |
|
2126 | + { |
|
2127 | + throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
2128 | + } |
|
1983 | 2129 | } |
1984 | 2130 | } |
1985 | 2131 | return $ret; |
@@ -2000,7 +2146,10 @@ discard block |
||
2000 | 2146 | */ |
2001 | 2147 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
2002 | 2148 | { |
2003 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2149 | + if (!$table_def) |
|
2150 | + { |
|
2151 | + $table_def = $this->get_table_definitions($app,$table); |
|
2152 | + } |
|
2004 | 2153 | |
2005 | 2154 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
2006 | 2155 | { |
@@ -2032,19 +2181,29 @@ discard block |
||
2032 | 2181 | */ |
2033 | 2182 | function expression($table_def/*,$args, ...*/) |
2034 | 2183 | { |
2035 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
2184 | + if (!is_array($table_def)) |
|
2185 | + { |
|
2186 | + $table_def = $this->get_table_definitions(true,$table_def); |
|
2187 | + } |
|
2036 | 2188 | $sql = ''; |
2037 | 2189 | $ignore_next = 0; |
2038 | 2190 | foreach(func_get_args() as $n => $arg) |
2039 | 2191 | { |
2040 | - if ($n < 1) continue; // table-name |
|
2192 | + if ($n < 1) |
|
2193 | + { |
|
2194 | + continue; |
|
2195 | + } |
|
2196 | + // table-name |
|
2041 | 2197 | |
2042 | 2198 | if ($ignore_next) |
2043 | 2199 | { |
2044 | 2200 | --$ignore_next; |
2045 | 2201 | continue; |
2046 | 2202 | } |
2047 | - if (is_null($arg)) $arg = False; |
|
2203 | + if (is_null($arg)) |
|
2204 | + { |
|
2205 | + $arg = False; |
|
2206 | + } |
|
2048 | 2207 | |
2049 | 2208 | switch(gettype($arg)) |
2050 | 2209 | { |
@@ -2084,9 +2243,15 @@ discard block |
||
2084 | 2243 | */ |
2085 | 2244 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
2086 | 2245 | { |
2087 | - 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"; |
|
2246 | + if ($this->Debug) |
|
2247 | + { |
|
2248 | + echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
2249 | + } |
|
2088 | 2250 | |
2089 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2251 | + if (!$table_def) |
|
2252 | + { |
|
2253 | + $table_def = $this->get_table_definitions($app,$table); |
|
2254 | + } |
|
2090 | 2255 | if (is_array($cols)) |
2091 | 2256 | { |
2092 | 2257 | $cols = implode(',',$cols); |
@@ -2102,16 +2267,28 @@ discard block |
||
2102 | 2267 | $sql = "SELECT $cols FROM $table $join"; |
2103 | 2268 | |
2104 | 2269 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
2105 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2270 | + if ($where) |
|
2271 | + { |
|
2272 | + $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2273 | + } |
|
2106 | 2274 | |
2107 | - if ($append) $sql .= ' '.$append; |
|
2275 | + if ($append) |
|
2276 | + { |
|
2277 | + $sql .= ' '.$append; |
|
2278 | + } |
|
2108 | 2279 | |
2109 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
2280 | + if ($this->Debug) |
|
2281 | + { |
|
2282 | + echo "<p>sql='$sql'</p>"; |
|
2283 | + } |
|
2110 | 2284 | |
2111 | - if ($line === false && $file === false) // call by union, to return the sql rather then run the query |
|
2285 | + if ($line === false && $file === false) |
|
2286 | + { |
|
2287 | + // call by union, to return the sql rather then run the query |
|
2112 | 2288 | { |
2113 | 2289 | return $sql; |
2114 | 2290 | } |
2291 | + } |
|
2115 | 2292 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
2116 | 2293 | } |
2117 | 2294 | |
@@ -2132,7 +2309,10 @@ discard block |
||
2132 | 2309 | */ |
2133 | 2310 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
2134 | 2311 | { |
2135 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2312 | + if ($this->Debug) |
|
2313 | + { |
|
2314 | + echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2315 | + } |
|
2136 | 2316 | |
2137 | 2317 | $union = array(); |
2138 | 2318 | foreach($selects as $select) |
@@ -2153,9 +2333,15 @@ discard block |
||
2153 | 2333 | } |
2154 | 2334 | $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
2155 | 2335 | |
2156 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2336 | + if ($order_by) |
|
2337 | + { |
|
2338 | + $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2339 | + } |
|
2157 | 2340 | |
2158 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
2341 | + if ($this->Debug) |
|
2342 | + { |
|
2343 | + echo "<p>sql='$sql'</p>"; |
|
2344 | + } |
|
2159 | 2345 | |
2160 | 2346 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
2161 | 2347 | } |
@@ -13,7 +13,7 @@ discard block |
||
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 |
||
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 |
||
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 |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * @var int $Debug enable debuging - 0 no, 1 yes |
111 | 111 | */ |
112 | - var $Debug = 0; |
|
112 | + var $Debug = 0; |
|
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Log update querys to error_log |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | /** |
122 | 122 | * @var array $Record current record |
123 | 123 | */ |
124 | - var $Record = array(); |
|
124 | + var $Record = array(); |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * @var int row number for current record |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | /** |
132 | 132 | * @var int $Errno internal rdms error number for last error |
133 | 133 | */ |
134 | - var $Errno = 0; |
|
134 | + var $Errno = 0; |
|
135 | 135 | |
136 | 136 | /** |
137 | 137 | * @var string descriptive text from last error |
138 | 138 | */ |
139 | - var $Error = ''; |
|
139 | + var $Error = ''; |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * eGW's own query log, independent of the db-type, eg. /tmp/query.log |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @var ADOConnection |
158 | 158 | */ |
159 | - var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object |
|
159 | + var $privat_Link_ID = False; // do we use a privat Link_ID or a reference to the global ADOdb object |
|
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Can be used to transparently convert tablenames, eg. 'mytable' => 'otherdb.othertable' |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | /** |
193 | 193 | * db is able to use DISTINCT on text or blob columns |
194 | 194 | */ |
195 | - const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text'; |
|
195 | + const CAPABILITY_DISTINCT_ON_TEXT = 'distinct_on_text'; |
|
196 | 196 | /** |
197 | 197 | * DB is able to use LIKE on text columns |
198 | 198 | */ |
199 | - const CAPABILITY_LIKE_ON_TEXT = 'like_on_text'; |
|
199 | + const CAPABILITY_LIKE_ON_TEXT = 'like_on_text'; |
|
200 | 200 | /** |
201 | 201 | * DB allows ORDER on text columns |
202 | 202 | * |
@@ -248,18 +248,18 @@ discard block |
||
248 | 248 | self::CAPABILITY_CAST_AS_VARCHAR => 'CAST(%s AS varchar)', |
249 | 249 | ); |
250 | 250 | |
251 | - var $prepared_sql = array(); // sql is the index |
|
251 | + var $prepared_sql = array(); // sql is the index |
|
252 | 252 | |
253 | 253 | /** |
254 | 254 | * Constructor |
255 | 255 | * |
256 | 256 | * @param array $db_data =null values for keys 'db_name', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_type', 'db_readonly' |
257 | 257 | */ |
258 | - function __construct(array $db_data=null) |
|
258 | + function __construct(array $db_data = null) |
|
259 | 259 | { |
260 | 260 | if (!is_null($db_data)) |
261 | 261 | { |
262 | - foreach(array( |
|
262 | + foreach (array( |
|
263 | 263 | 'Database' => 'db_name', |
264 | 264 | 'Host' => 'db_host', |
265 | 265 | 'Port' => 'db_port', |
@@ -313,15 +313,15 @@ discard block |
||
313 | 313 | } |
314 | 314 | if (!is_null($Host) && $Host) |
315 | 315 | { |
316 | - $this->Host = $Host; |
|
316 | + $this->Host = $Host; |
|
317 | 317 | } |
318 | 318 | if (!is_null($Port) && $Port) |
319 | 319 | { |
320 | - $this->Port = $Port; |
|
320 | + $this->Port = $Port; |
|
321 | 321 | } |
322 | 322 | if (!is_null($User) && $User) |
323 | 323 | { |
324 | - $this->User = $User; |
|
324 | + $this->User = $User; |
|
325 | 325 | } |
326 | 326 | if (!is_null($Password) && $Password) |
327 | 327 | { |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | // on connection failure re-try with an other host |
339 | 339 | // remembering in session which host we used last time |
340 | 340 | $use_host_from_session = true; |
341 | - while(($host = $this->get_host(!$use_host_from_session))) |
|
341 | + while (($host = $this->get_host(!$use_host_from_session))) |
|
342 | 342 | { |
343 | 343 | try { |
344 | 344 | //error_log(__METHOD__."() this->Host(s)=$this->Host, n=$n --> host=$host"); |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | //error_log(__METHOD__."() host=$host, new_connection=$new_connection, this->Type=$this->Type, this->Host=$this->Host, wsrep_local_state=".array2string($state)); |
353 | 353 | return $this->Link_ID; |
354 | 354 | } |
355 | - catch(Db\Exception\Connection $e) { |
|
355 | + catch (Db\Exception\Connection $e) { |
|
356 | 356 | //_egw_log_exception($e); |
357 | - $this->disconnect(); // force a new connect |
|
358 | - $this->Type = $this->setupType; // get set to "mysql" for "mysqli" |
|
359 | - $use_host_from_session = false; // re-try with next host from list |
|
357 | + $this->disconnect(); // force a new connect |
|
358 | + $this->Type = $this->setupType; // get set to "mysql" for "mysqli" |
|
359 | + $use_host_from_session = false; // re-try with next host from list |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | if (!isset($e)) |
@@ -407,12 +407,12 @@ discard block |
||
407 | 407 | { |
408 | 408 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
409 | 409 | $num_hosts = count($hosts); |
410 | - $n =& Cache::getSession(__CLASS__, $this->Host); |
|
410 | + $n = & Cache::getSession(__CLASS__, $this->Host); |
|
411 | 411 | if (!isset($n)) $n = 0; |
412 | 412 | |
413 | - if ($next && ++$n >= $num_hosts+2) |
|
413 | + if ($next && ++$n >= $num_hosts + 2) |
|
414 | 414 | { |
415 | - $n = 0; // start search again with default on next request |
|
415 | + $n = 0; // start search again with default on next request |
|
416 | 416 | $ret = false; |
417 | 417 | } |
418 | 418 | else |
@@ -435,21 +435,21 @@ discard block |
||
435 | 435 | if (!$this->Link_ID || $Host != $this->Link_ID->host) |
436 | 436 | { |
437 | 437 | $Database = $User = $Password = $Port = $Type = ''; |
438 | - foreach(array('Database','User','Password','Port','Type') as $name) |
|
438 | + foreach (array('Database', 'User', 'Password', 'Port', 'Type') as $name) |
|
439 | 439 | { |
440 | 440 | $$name = $this->$name; |
441 | 441 | if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
442 | 442 | } |
443 | 443 | $this->setupType = $php_extension = $Type; |
444 | 444 | |
445 | - switch($Type) // convert to ADO db-type-names |
|
445 | + switch ($Type) // convert to ADO db-type-names |
|
446 | 446 | { |
447 | 447 | case 'pgsql': |
448 | 448 | $Type = 'postgres'; // name in ADOdb |
449 | 449 | // create our own pgsql connection-string, to allow unix domain soccets if !$Host |
450 | 450 | $Host = "dbname=$Database".($Host ? " host=$Host".($Port ? " port=$Port" : '') : ''). |
451 | 451 | " user=$User".($Password ? " password='".addslashes($Password)."'" : ''); |
452 | - $User = $Password = $Database = ''; // to indicate $Host is a connection-string |
|
452 | + $User = $Password = $Database = ''; // to indicate $Host is a connection-string |
|
453 | 453 | break; |
454 | 454 | |
455 | 455 | case 'odbc_mssql': |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | $Type = 'maxdb'; |
473 | 473 | // fall through |
474 | 474 | case 'maxdb': |
475 | - $Type ='sapdb'; // name in ADOdb |
|
475 | + $Type = 'sapdb'; // name in ADOdb |
|
476 | 476 | $php_extension = 'odbc'; |
477 | 477 | break; |
478 | 478 | |
@@ -485,18 +485,18 @@ discard block |
||
485 | 485 | } |
486 | 486 | else |
487 | 487 | { |
488 | - $php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql |
|
488 | + $php_extension = 'mysql'; // you can use $this->setupType to determine if it's mysqlt or mysql |
|
489 | 489 | } |
490 | 490 | // fall through |
491 | 491 | case 'mysqli': |
492 | - $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
|
492 | + $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
|
493 | 493 | // fall through |
494 | 494 | default: |
495 | 495 | if ($Port) $Host .= ':'.$Port; |
496 | 496 | break; |
497 | 497 | } |
498 | - if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
|
499 | - (is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one |
|
498 | + if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
|
499 | + (is_object($GLOBALS['egw']->db) && // we connect to a different db, then the global one |
|
500 | 500 | ($this->Type != $GLOBALS['egw']->db->Type || |
501 | 501 | $this->Database != $GLOBALS['egw']->db->Database || |
502 | 502 | $this->User != $GLOBALS['egw']->db->User || |
@@ -509,11 +509,11 @@ discard block |
||
509 | 509 | } |
510 | 510 | if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
511 | 511 | { |
512 | - $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
|
512 | + $this->Link_ID = & $GLOBALS['egw']->ADOdb; |
|
513 | 513 | } |
514 | 514 | else |
515 | 515 | { |
516 | - $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
|
516 | + $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
|
517 | 517 | } |
518 | 518 | $this->Link_ID = ADONewConnection($Type); |
519 | 519 | if (!$this->Link_ID) |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | if (($Ok = $this->Link_ID->$connect($Host, $User, $Password, $Database))) |
530 | 530 | { |
531 | 531 | $this->ServerInfo = $this->Link_ID->ServerInfo(); |
532 | - $this->set_capabilities($Type,$this->ServerInfo['version']); |
|
532 | + $this->set_capabilities($Type, $this->ServerInfo['version']); |
|
533 | 533 | |
534 | 534 | // switch off MySQL 5.7+ ONLY_FULL_GROUP_BY sql_mode |
535 | 535 | if (substr($this->Type, 0, 5) == 'mysql' && $this->ServerInfo['version'] >= 5.7 && $this->ServerInfo['version'] < 10.0) |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | } |
540 | 540 | if (!$Ok) |
541 | 541 | { |
542 | - $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password |
|
542 | + $Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password |
|
543 | 543 | throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) failed."); |
544 | 544 | } |
545 | 545 | if ($this->Debug) |
@@ -555,8 +555,8 @@ discard block |
||
555 | 555 | // this is the format ADOdb expects |
556 | 556 | $this->Link_ID->Execute('SET DATEFORMAT ymd'); |
557 | 557 | // sets the limit to the maximum |
558 | - ini_set('mssql.textlimit',2147483647); |
|
559 | - ini_set('mssql.sizelimit',2147483647); |
|
558 | + ini_set('mssql.textlimit', 2147483647); |
|
559 | + ini_set('mssql.sizelimit', 2147483647); |
|
560 | 560 | } |
561 | 561 | // set our default charset |
562 | 562 | $this->Link_ID->SetCharSet($this->Type == 'mysql' ? 'utf8' : 'utf-8'); |
@@ -565,12 +565,12 @@ discard block |
||
565 | 565 | } |
566 | 566 | else |
567 | 567 | { |
568 | - $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
|
568 | + $this->Link_ID = & $GLOBALS['egw']->ADOdb; |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | if (!$this->Link_ID->isConnected() && !$this->Link_ID->Connect()) |
572 | 572 | { |
573 | - $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password |
|
573 | + $Host = preg_replace('/password=[^ ]+/', 'password=$Password', $Host); // eg. postgres dsn contains password |
|
574 | 574 | throw new Db\Exception\Connection("ADOdb::$connect($Host, $User, \$Password, $Database) reconnect failed."); |
575 | 575 | } |
576 | 576 | // fix due to caching and reusing of connection not correctly set $this->Type == 'mysql' |
@@ -581,9 +581,9 @@ discard block |
||
581 | 581 | } |
582 | 582 | if ($new_connection) |
583 | 583 | { |
584 | - foreach(get_included_files() as $file) |
|
584 | + foreach (get_included_files() as $file) |
|
585 | 585 | { |
586 | - if (strpos($file,'adodb') !== false && !in_array($file,(array)$_SESSION['egw_required_files'])) |
|
586 | + if (strpos($file, 'adodb') !== false && !in_array($file, (array)$_SESSION['egw_required_files'])) |
|
587 | 587 | { |
588 | 588 | $_SESSION['egw_required_files'][] = $file; |
589 | 589 | //error_log(__METHOD__."() egw_required_files[] = $file"); |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | */ |
600 | 600 | function __wakeup() |
601 | 601 | { |
602 | - $this->connect(); // we need to re-connect |
|
602 | + $this->connect(); // we need to re-connect |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | */ |
613 | 613 | function __sleep() |
614 | 614 | { |
615 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
615 | + if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
616 | 616 | |
617 | 617 | $vars = get_object_vars($this); |
618 | 618 | unset($vars['Link_ID'], $vars['Query_ID'], $vars['privat_Link_ID']); |
@@ -625,23 +625,23 @@ discard block |
||
625 | 625 | * @param string $adodb_driver mysql, postgres, mssql, sapdb, oci8 |
626 | 626 | * @param string $db_version version-number of connected db-server, as reported by ServerInfo |
627 | 627 | */ |
628 | - function set_capabilities($adodb_driver,$db_version) |
|
628 | + function set_capabilities($adodb_driver, $db_version) |
|
629 | 629 | { |
630 | - switch($adodb_driver) |
|
630 | + switch ($adodb_driver) |
|
631 | 631 | { |
632 | 632 | case 'mysql': |
633 | 633 | case 'mysqlt': |
634 | 634 | case 'mysqli': |
635 | - $this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float) $db_version >= 4.1; |
|
636 | - $this->capabilities[self::CAPABILITY_UNION] = (float) $db_version >= 4.0; |
|
635 | + $this->capabilities[self::CAPABILITY_SUB_QUERIES] = (float)$db_version >= 4.1; |
|
636 | + $this->capabilities[self::CAPABILITY_UNION] = (float)$db_version >= 4.0; |
|
637 | 637 | $this->capabilities[self::CAPABILITY_NAME_CASE] = 'preserv'; |
638 | - $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 4.1; |
|
638 | + $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 4.1; |
|
639 | 639 | $this->capabilities[self::CAPABILITY_CAST_AS_VARCHAR] = 'CAST(%s AS char)'; |
640 | 640 | break; |
641 | 641 | |
642 | 642 | case 'postgres': |
643 | 643 | $this->capabilities[self::CAPABILITY_NAME_CASE] = 'lower'; |
644 | - $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 7.4; |
|
644 | + $this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float)$db_version >= 7.4; |
|
645 | 645 | $this->capabilities[self::CAPABILITY_OUTER_JOIN] = true; |
646 | 646 | $this->capabilities[self::CAPABILITY_CASE_INSENSITIV_LIKE] = '::text ILIKE'; |
647 | 647 | $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR] = true; |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | return False; |
691 | 691 | } |
692 | 692 | // the substring is needed as the string is already in quotes |
693 | - return substr($this->Link_ID->DBTimeStamp($epoch),1,-1); |
|
693 | + return substr($this->Link_ID->DBTimeStamp($epoch), 1, -1); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | */ |
717 | 717 | public static function from_bool($val) |
718 | 718 | { |
719 | - return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true |
|
719 | + return $val && $val[0] !== 'f'; // everthing other then 0 or f[alse] is returned as true |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -733,9 +733,9 @@ discard block |
||
733 | 733 | * @return ADORecordSet or false, if the query fails |
734 | 734 | * @throws Db\Exception\InvalidSql with $this->Link_ID->ErrorNo() as code |
735 | 735 | */ |
736 | - function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true) |
|
736 | + function query($Query_String, $line = '', $file = '', $offset = 0, $num_rows = -1, $inputarr = false, $fetchmode = self::FETCH_BOTH, $reconnect = true) |
|
737 | 737 | { |
738 | - unset($line, $file); // not used anymore |
|
738 | + unset($line, $file); // not used anymore |
|
739 | 739 | |
740 | 740 | if ($Query_String == '') |
741 | 741 | { |
@@ -766,23 +766,23 @@ discard block |
||
766 | 766 | } |
767 | 767 | if ($num_rows > 0) |
768 | 768 | { |
769 | - $rs = $this->Link_ID->SelectLimit($Query_String,$num_rows,(int)$offset,$inputarr); |
|
769 | + $rs = $this->Link_ID->SelectLimit($Query_String, $num_rows, (int)$offset, $inputarr); |
|
770 | 770 | } |
771 | 771 | else |
772 | 772 | { |
773 | - $rs = $this->Link_ID->Execute($Query_String,$inputarr); |
|
773 | + $rs = $this->Link_ID->Execute($Query_String, $inputarr); |
|
774 | 774 | } |
775 | 775 | $this->Row = 0; |
776 | 776 | $this->Errno = $this->Link_ID->ErrorNo(); |
777 | 777 | $this->Error = $this->Link_ID->ErrorMsg(); |
778 | 778 | |
779 | - if ($this->query_log && ($f = @fopen($this->query_log,'a+'))) |
|
779 | + if ($this->query_log && ($f = @fopen($this->query_log, 'a+'))) |
|
780 | 780 | { |
781 | - fwrite($f,'['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] '); |
|
782 | - fwrite($f,date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr,true) : '')."\n"); |
|
781 | + fwrite($f, '['.(isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->ConfigDomain : $GLOBALS['egw_info']['user']['domain']).'] '); |
|
782 | + fwrite($f, date('Y-m-d H:i:s ').$Query_String.($inputarr ? "\n".print_r($inputarr, true) : '')."\n"); |
|
783 | 783 | if (!$rs) |
784 | 784 | { |
785 | - fwrite($f,"*** Error $this->Errno: $this->Error\n".function_backtrace()."\n"); |
|
785 | + fwrite($f, "*** Error $this->Errno: $this->Error\n".function_backtrace()."\n"); |
|
786 | 786 | } |
787 | 787 | fclose($f); |
788 | 788 | } |
@@ -793,11 +793,11 @@ discard block |
||
793 | 793 | $this->disconnect(); |
794 | 794 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
795 | 795 | } |
796 | - throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
|
796 | + throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String) ? $Query_String[0] : $Query_String). |
|
797 | 797 | "\n$this->Error ($this->Errno)". |
798 | - ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
|
798 | + ($inputarr ? "\nParameters: '".implode("','", $inputarr)."'" : ''), $this->Errno); |
|
799 | 799 | } |
800 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
800 | + elseif (empty($rs->sql)) $rs->sql = $Query_String; |
|
801 | 801 | return $rs; |
802 | 802 | } |
803 | 803 | |
@@ -812,9 +812,9 @@ discard block |
||
812 | 812 | * @param array|boolean $inputarr array for binding variables to parameters or false (default) |
813 | 813 | * @return ADORecordSet or false, if the query fails |
814 | 814 | */ |
815 | - function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '',$inputarr=false) |
|
815 | + function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '', $inputarr = false) |
|
816 | 816 | { |
817 | - return $this->query($Query_String,$line,$file,$offset,$num_rows,$inputarr); |
|
817 | + return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | * @param string $where ='true' where clause to use, eg: "WHERE row=12". Defaults to lock whole table. |
873 | 873 | * @param string $col ='1 as adodbignore' |
874 | 874 | */ |
875 | - function row_lock($table, $where='true', $col='1 as adodbignore') |
|
875 | + function row_lock($table, $where = 'true', $col = '1 as adodbignore') |
|
876 | 876 | { |
877 | 877 | if (!$this->Link_ID && !$this->connect()) |
878 | 878 | { |
@@ -943,7 +943,7 @@ discard block |
||
943 | 943 | { |
944 | 944 | $table = self::$tablealiases[$table]; |
945 | 945 | } |
946 | - $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
|
946 | + $id = $this->Link_ID->PO_Insert_ID($table, $field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
|
947 | 947 | |
948 | 948 | if ($id === False) // function not supported |
949 | 949 | { |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | * @param bool $full optional, default False summary information, True full information |
980 | 980 | * @return array table meta data |
981 | 981 | */ |
982 | - function metadata($table='',$full=false) |
|
982 | + function metadata($table = '', $full = false) |
|
983 | 983 | { |
984 | 984 | if (!$this->Link_ID && !$this->connect()) |
985 | 985 | { |
@@ -991,13 +991,13 @@ discard block |
||
991 | 991 | |
992 | 992 | $metadata = array(); |
993 | 993 | $i = 0; |
994 | - foreach($columns as $column) |
|
994 | + foreach ($columns as $column) |
|
995 | 995 | { |
996 | 996 | // for backwards compatibilty (depreciated) |
997 | 997 | $flags = null; |
998 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
999 | - if($column->primary_key) $flags .= "primary_key "; |
|
1000 | - if($column->binary) $flags .= "binary "; |
|
998 | + if ($column->auto_increment) $flags .= "auto_increment "; |
|
999 | + if ($column->primary_key) $flags .= "primary_key "; |
|
1000 | + if ($column->binary) $flags .= "binary "; |
|
1001 | 1001 | |
1002 | 1002 | $metadata[$i] = array( |
1003 | 1003 | 'table' => $table, |
@@ -1032,7 +1032,7 @@ discard block |
||
1032 | 1032 | * @param boolean $just_name =false true return array of table-names, false return old format |
1033 | 1033 | * @return array list of the tables |
1034 | 1034 | */ |
1035 | - function table_names($just_name=false) |
|
1035 | + function table_names($just_name = false) |
|
1036 | 1036 | { |
1037 | 1037 | if (!$this->Link_ID) $this->connect(); |
1038 | 1038 | if (!$this->Link_ID) |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | $tables = $this->Link_ID->MetaTables('TABLES'); |
1044 | 1044 | if (is_array($tables)) |
1045 | 1045 | { |
1046 | - foreach($tables as $table) |
|
1046 | + foreach ($tables as $table) |
|
1047 | 1047 | { |
1048 | 1048 | if ($this->capabilities[self::CAPABILITY_NAME_CASE] == 'upper') |
1049 | 1049 | { |
@@ -1072,7 +1072,7 @@ discard block |
||
1072 | 1072 | echo "<p>db::index_names() not yet implemented for db-type '$this->Type'</p>\n"; |
1073 | 1073 | return $indices; |
1074 | 1074 | } |
1075 | - foreach($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row) |
|
1075 | + foreach ($this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname") as $row) |
|
1076 | 1076 | { |
1077 | 1077 | $indices[] = array( |
1078 | 1078 | 'index_name' => $row[0], |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | * @param string $charset default charset for the database |
1106 | 1106 | * @param string $grant_host ='localhost' host/ip of the webserver |
1107 | 1107 | */ |
1108 | - function create_database($adminname = '', $adminpasswd = '', $charset='', $grant_host='localhost') |
|
1108 | + function create_database($adminname = '', $adminpasswd = '', $charset = '', $grant_host = 'localhost') |
|
1109 | 1109 | { |
1110 | 1110 | $currentUser = $this->User; |
1111 | 1111 | $currentPassword = $this->Password; |
@@ -1129,7 +1129,7 @@ discard block |
||
1129 | 1129 | case 'mysqli': |
1130 | 1130 | case 'mysqlt': |
1131 | 1131 | $create = "CREATE DATABASE `$currentDatabase`"; |
1132 | - if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float) $this->ServerInfo['version'] >= 4.1) |
|
1132 | + if ($charset && isset($this->Link_ID->charset2mysql[$charset]) && (float)$this->ServerInfo['version'] >= 4.1) |
|
1133 | 1133 | { |
1134 | 1134 | $create .= ' DEFAULT CHARACTER SET '.$this->Link_ID->charset2mysql[$charset].';'; |
1135 | 1135 | } |
@@ -1140,9 +1140,9 @@ discard block |
||
1140 | 1140 | throw new Exception\WrongParameter(__METHOD__."(user=$adminname, \$pw) not yet implemented for DB-type '$this->Type'"); |
1141 | 1141 | } |
1142 | 1142 | //error_log(__METHOD__."() this->Type=$this->Type: sqls=".array2string($sqls)); |
1143 | - foreach($sqls as $sql) |
|
1143 | + foreach ($sqls as $sql) |
|
1144 | 1144 | { |
1145 | - $this->query($sql,__LINE__,__FILE__); |
|
1145 | + $this->query($sql, __LINE__, __FILE__); |
|
1146 | 1146 | } |
1147 | 1147 | $this->disconnect(); |
1148 | 1148 | |
@@ -1168,7 +1168,7 @@ discard block |
||
1168 | 1168 | { |
1169 | 1169 | return False; |
1170 | 1170 | } |
1171 | - return call_user_func_array(array(&$this->Link_ID,'concat'),$args); |
|
1171 | + return call_user_func_array(array(&$this->Link_ID, 'concat'), $args); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | /** |
@@ -1179,9 +1179,9 @@ discard block |
||
1179 | 1179 | * @param string $separator =',' optional separator, default is comma |
1180 | 1180 | * @return string|boolean false if not supported by dbms |
1181 | 1181 | */ |
1182 | - function group_concat($expr, $order_by='', $separator=',') |
|
1182 | + function group_concat($expr, $order_by = '', $separator = ',') |
|
1183 | 1183 | { |
1184 | - switch($this->Type) |
|
1184 | + switch ($this->Type) |
|
1185 | 1185 | { |
1186 | 1186 | case 'mysqli': |
1187 | 1187 | case 'mysql': |
@@ -1216,7 +1216,7 @@ discard block |
||
1216 | 1216 | */ |
1217 | 1217 | function strpos($str, $substr) |
1218 | 1218 | { |
1219 | - switch($this->Type) |
|
1219 | + switch ($this->Type) |
|
1220 | 1220 | { |
1221 | 1221 | case 'mysql': |
1222 | 1222 | return "LOCATE($substr,$str)"; |
@@ -1236,7 +1236,7 @@ discard block |
||
1236 | 1236 | */ |
1237 | 1237 | function unix_timestamp($expr) |
1238 | 1238 | { |
1239 | - switch($this->Type) |
|
1239 | + switch ($this->Type) |
|
1240 | 1240 | { |
1241 | 1241 | case 'mysql': |
1242 | 1242 | return "UNIX_TIMESTAMP($expr)"; |
@@ -1257,7 +1257,7 @@ discard block |
||
1257 | 1257 | */ |
1258 | 1258 | function from_unixtime($expr) |
1259 | 1259 | { |
1260 | - switch($this->Type) |
|
1260 | + switch ($this->Type) |
|
1261 | 1261 | { |
1262 | 1262 | case 'mysql': |
1263 | 1263 | return "FROM_UNIXTIME($expr)"; |
@@ -1266,7 +1266,7 @@ discard block |
||
1266 | 1266 | return "(TIMESTAMP WITH TIME ZONE 'epoch' + ($expr) * INTERVAL '1 sec')"; |
1267 | 1267 | |
1268 | 1268 | case 'mssql': // we use date(,0) as we store server-time |
1269 | - return "DATEADD(second,($expr),'".date('Y-m-d H:i:s',0)."')"; |
|
1269 | + return "DATEADD(second,($expr),'".date('Y-m-d H:i:s', 0)."')"; |
|
1270 | 1270 | } |
1271 | 1271 | return false; |
1272 | 1272 | } |
@@ -1280,30 +1280,30 @@ discard block |
||
1280 | 1280 | * @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 |
1281 | 1281 | * @return string SQL expression of type timestamp |
1282 | 1282 | */ |
1283 | - function date_format($expr,$format) |
|
1283 | + function date_format($expr, $format) |
|
1284 | 1284 | { |
1285 | - switch($this->Type) |
|
1285 | + switch ($this->Type) |
|
1286 | 1286 | { |
1287 | 1287 | case 'mysql': |
1288 | 1288 | return "DATE_FORMAT($expr,'$format')"; |
1289 | 1289 | |
1290 | 1290 | case 'pgsql': |
1291 | 1291 | $format = str_replace( |
1292 | - array('%Y', '%y','%m','%d','%H', '%h','%i','%s','%V','%v','%X', '%x'), |
|
1293 | - array('YYYY','YY','MM','DD','HH24','HH','MI','SS','IW','IW','YYYY','YYYY'), |
|
1292 | + array('%Y', '%y', '%m', '%d', '%H', '%h', '%i', '%s', '%V', '%v', '%X', '%x'), |
|
1293 | + array('YYYY', 'YY', 'MM', 'DD', 'HH24', 'HH', 'MI', 'SS', 'IW', 'IW', 'YYYY', 'YYYY'), |
|
1294 | 1294 | $format); |
1295 | 1295 | return "TO_CHAR($expr,'$format')"; |
1296 | 1296 | |
1297 | 1297 | case 'mssql': |
1298 | 1298 | $from = $to = array(); |
1299 | - 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) |
|
1299 | + 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) |
|
1300 | 1300 | { |
1301 | 1301 | $from[] = $f; |
1302 | 1302 | $to[] = "'+DATEPART($t,($expr))+'"; |
1303 | 1303 | } |
1304 | 1304 | $from[] = "''+"; $to[] = ''; |
1305 | 1305 | $from[] = "+''"; $to[] = ''; |
1306 | - return str_replace($from,$to,$format); |
|
1306 | + return str_replace($from, $to, $format); |
|
1307 | 1307 | } |
1308 | 1308 | return false; |
1309 | 1309 | } |
@@ -1316,7 +1316,7 @@ discard block |
||
1316 | 1316 | */ |
1317 | 1317 | function to_double($expr) |
1318 | 1318 | { |
1319 | - switch($this->Type) |
|
1319 | + switch ($this->Type) |
|
1320 | 1320 | { |
1321 | 1321 | case 'pgsql': |
1322 | 1322 | return $expr.'::double'; |
@@ -1334,7 +1334,7 @@ discard block |
||
1334 | 1334 | */ |
1335 | 1335 | function to_int($expr) |
1336 | 1336 | { |
1337 | - switch($this->Type) |
|
1337 | + switch ($this->Type) |
|
1338 | 1338 | { |
1339 | 1339 | case 'pgsql': |
1340 | 1340 | return $expr.'::integer'; |
@@ -1352,7 +1352,7 @@ discard block |
||
1352 | 1352 | */ |
1353 | 1353 | function to_varchar($expr) |
1354 | 1354 | { |
1355 | - switch($this->Type) |
|
1355 | + switch ($this->Type) |
|
1356 | 1356 | { |
1357 | 1357 | case 'pgsql': |
1358 | 1358 | return 'CAST('.$expr.' AS varchar)'; |
@@ -1396,7 +1396,7 @@ discard block |
||
1396 | 1396 | // always quote for postgreSQL, as this is the only way to support mixed case names |
1397 | 1397 | if (preg_match('/\W/', $name) || $type == 'pgsql' && preg_match('/[A-Z]+/', $name) || $name == 'index') |
1398 | 1398 | { |
1399 | - return $quote . $name . $quote; |
|
1399 | + return $quote.$name.$quote; |
|
1400 | 1400 | } |
1401 | 1401 | return $name; |
1402 | 1402 | }, explode('.', $name)); |
@@ -1418,27 +1418,27 @@ discard block |
||
1418 | 1418 | * @param string $glue =',' used to glue array values together for the string type |
1419 | 1419 | * @return string escaped sting |
1420 | 1420 | */ |
1421 | - function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
|
1421 | + function quote($value, $type = False, $not_null = true, $length = null, $glue = ',') |
|
1422 | 1422 | { |
1423 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
1423 | + if ($this->Debug) echo "<p>db::quote(".(is_null($value) ? 'NULL' : "'$value'").",'$type','$not_null')</p>\n"; |
|
1424 | 1424 | |
1425 | 1425 | if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
1426 | 1426 | { |
1427 | 1427 | return 'NULL'; |
1428 | 1428 | } |
1429 | - switch($type) |
|
1429 | + switch ($type) |
|
1430 | 1430 | { |
1431 | 1431 | case 'int': |
1432 | 1432 | // if DateTime object given, convert it to a unix timestamp (NOT converting the timezone!) |
1433 | 1433 | if (is_object($value) && ($value instanceof \DateTime)) |
1434 | 1434 | { |
1435 | - return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value,'ts'); |
|
1435 | + return ($value instanceof DateTime) ? $value->format('ts') : DateTime::to($value, 'ts'); |
|
1436 | 1436 | } |
1437 | 1437 | case 'auto': |
1438 | 1438 | // atm. (php5.2) php has only 32bit integers, it converts everything else to float. |
1439 | 1439 | // Casting it to int gives a negative number instead of the big 64bit integer! |
1440 | 1440 | // There for we have to keep it as float by using round instead the int cast. |
1441 | - return is_float($value) ? round($value) : (int) $value; |
|
1441 | + return is_float($value) ? round($value) : (int)$value; |
|
1442 | 1442 | case 'bool': |
1443 | 1443 | if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
1444 | 1444 | { |
@@ -1447,23 +1447,23 @@ discard block |
||
1447 | 1447 | return $value ? 'true' : 'false'; |
1448 | 1448 | case 'float': |
1449 | 1449 | case 'decimal': |
1450 | - return (double) $value; |
|
1450 | + return (double)$value; |
|
1451 | 1451 | } |
1452 | 1452 | if (!$this->Link_ID && !$this->connect()) |
1453 | 1453 | { |
1454 | 1454 | return False; |
1455 | 1455 | } |
1456 | - switch($type) |
|
1456 | + switch ($type) |
|
1457 | 1457 | { |
1458 | 1458 | case 'blob': |
1459 | 1459 | switch ($this->Link_ID->blobEncodeType) |
1460 | 1460 | { |
1461 | 1461 | case 'C': // eg. postgres |
1462 | - return "'" . $this->Link_ID->BlobEncode($value) . "'"; |
|
1462 | + return "'".$this->Link_ID->BlobEncode($value)."'"; |
|
1463 | 1463 | case 'I': |
1464 | 1464 | return $this->Link_ID->BlobEncode($value); |
1465 | 1465 | } |
1466 | - break; // handled like strings |
|
1466 | + break; // handled like strings |
|
1467 | 1467 | case 'date': |
1468 | 1468 | // if DateTime object given, convert it (NOT converting the timezone!) |
1469 | 1469 | if (is_object($value) && ($value instanceof \DateTime)) |
@@ -1481,7 +1481,7 @@ discard block |
||
1481 | 1481 | } |
1482 | 1482 | if (is_array($value)) |
1483 | 1483 | { |
1484 | - $value = implode($glue,$value); |
|
1484 | + $value = implode($glue, $value); |
|
1485 | 1485 | } |
1486 | 1486 | // truncate to long strings for varchar(X) columns as PostgreSQL and newer MySQL/MariaDB given an error otherwise |
1487 | 1487 | if (!is_null($length) && mb_strlen($value) > $length) |
@@ -1527,7 +1527,7 @@ discard block |
||
1527 | 1527 | * If its set, the column-type-data determinates if (int) or addslashes is used. |
1528 | 1528 | * @return string SQL |
1529 | 1529 | */ |
1530 | - function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
|
1530 | + function column_data_implode($glue, $array, $use_key = True, $only = False, $column_definitions = False) |
|
1531 | 1531 | { |
1532 | 1532 | if (!is_array($array)) // this allows to give an SQL-string for delete or update |
1533 | 1533 | { |
@@ -1537,16 +1537,16 @@ discard block |
||
1537 | 1537 | { |
1538 | 1538 | $column_definitions = $this->column_definitions; |
1539 | 1539 | } |
1540 | - 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"; |
|
1540 | + 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"; |
|
1541 | 1541 | |
1542 | 1542 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
1543 | 1543 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
1544 | 1544 | |
1545 | 1545 | $keys = $values = array(); |
1546 | - foreach($array as $key => $data) |
|
1546 | + foreach ($array as $key => $data) |
|
1547 | 1547 | { |
1548 | 1548 | if (is_int($key) && $use_key !== 'VALUES' || !$only || $only === True && isset($column_definitions[$key]) || |
1549 | - is_array($only) && in_array($key,$only)) |
|
1549 | + is_array($only) && in_array($key, $only)) |
|
1550 | 1550 | { |
1551 | 1551 | $keys[] = $this->name_quote($key); |
1552 | 1552 | |
@@ -1557,7 +1557,7 @@ discard block |
||
1557 | 1557 | if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
1558 | 1558 | if (!isset($column_definitions[$col])) |
1559 | 1559 | { |
1560 | - 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>"); |
|
1560 | + 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>"); |
|
1561 | 1561 | } |
1562 | 1562 | } |
1563 | 1563 | $column_type = is_array($column_definitions) ? @$column_definitions[$col]['type'] : False; |
@@ -1566,7 +1566,7 @@ discard block |
||
1566 | 1566 | $maxlength = null; |
1567 | 1567 | if ($truncate_varchar) |
1568 | 1568 | { |
1569 | - $maxlength = in_array($column_definitions[$col]['type'], array('varchar','ascii')) ? $column_definitions[$col]['precision'] : null; |
|
1569 | + $maxlength = in_array($column_definitions[$col]['type'], array('varchar', 'ascii')) ? $column_definitions[$col]['precision'] : null; |
|
1570 | 1570 | } |
1571 | 1571 | // dont use IN ( ), if there's only one value, it's slower for MySQL |
1572 | 1572 | if (is_array($data) && count($data) == 1) |
@@ -1576,39 +1576,38 @@ discard block |
||
1576 | 1576 | if (is_array($data)) |
1577 | 1577 | { |
1578 | 1578 | $or_null = ''; |
1579 | - foreach($data as $k => $v) |
|
1579 | + foreach ($data as $k => $v) |
|
1580 | 1580 | { |
1581 | - if (!$not_null && $use_key===True && is_null($v)) |
|
1581 | + if (!$not_null && $use_key === True && is_null($v)) |
|
1582 | 1582 | { |
1583 | 1583 | $or_null = $this->name_quote($key).' IS NULL)'; |
1584 | 1584 | unset($data[$k]); |
1585 | 1585 | continue; |
1586 | 1586 | } |
1587 | - $data[$k] = $this->quote($v,$column_type,$not_null,$maxlength); |
|
1587 | + $data[$k] = $this->quote($v, $column_type, $not_null, $maxlength); |
|
1588 | 1588 | } |
1589 | - $values[] = ($or_null?'(':'').(!count($data) ? |
|
1589 | + $values[] = ($or_null ? '(' : '').(!count($data) ? |
|
1590 | 1590 | // empty array on insert/update, store as NULL, or if not allowed whatever value NULL is casted to |
1591 | - $this->quote(null, $column_type, $not_null) : |
|
1592 | - ($use_key===True ? $this->name_quote($key).' IN ' : '') . |
|
1593 | - '('.implode(',',$data).')'.($or_null ? ' OR ' : '')).$or_null; |
|
1591 | + $this->quote(null, $column_type, $not_null) : ($use_key === True ? $this->name_quote($key).' IN ' : ''). |
|
1592 | + '('.implode(',', $data).')'.($or_null ? ' OR ' : '')).$or_null; |
|
1594 | 1593 | } |
1595 | - elseif (is_int($key) && $use_key===True) |
|
1594 | + elseif (is_int($key) && $use_key === True) |
|
1596 | 1595 | { |
1597 | - if (empty($data)) continue; // would give SQL error |
|
1596 | + if (empty($data)) continue; // would give SQL error |
|
1598 | 1597 | $values[] = $data; |
1599 | 1598 | } |
1600 | 1599 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
1601 | 1600 | { |
1602 | - $values[] = $this->name_quote($key) .' IS NULL'; |
|
1601 | + $values[] = $this->name_quote($key).' IS NULL'; |
|
1603 | 1602 | } |
1604 | 1603 | else |
1605 | 1604 | { |
1606 | - $values[] = ($use_key===True ? $this->name_quote($key) . '=' : '') . $this->quote($data,$column_type,$not_null,$maxlength); |
|
1605 | + $values[] = ($use_key === True ? $this->name_quote($key).'=' : '').$this->quote($data, $column_type, $not_null, $maxlength); |
|
1607 | 1606 | } |
1608 | 1607 | } |
1609 | 1608 | } |
1610 | - return ($use_key==='VALUES' ? '('.implode(',',$keys).') VALUES (' : ''). |
|
1611 | - implode($glue,$values) . ($use_key==='VALUES' ? ')' : ''); |
|
1609 | + return ($use_key === 'VALUES' ? '('.implode(',', $keys).') VALUES (' : ''). |
|
1610 | + implode($glue, $values).($use_key === 'VALUES' ? ')' : ''); |
|
1612 | 1611 | } |
1613 | 1612 | |
1614 | 1613 | /** |
@@ -1620,9 +1619,9 @@ discard block |
||
1620 | 1619 | * of your table ($tables_baseline[$table]['fd'] of the setup/tables_current.inc.php file). |
1621 | 1620 | * If its set, the column-type-data determinates if (int) or addslashes is used. |
1622 | 1621 | */ |
1623 | - function set_column_definitions($column_definitions=False) |
|
1622 | + function set_column_definitions($column_definitions = False) |
|
1624 | 1623 | { |
1625 | - $this->column_definitions=$column_definitions; |
|
1624 | + $this->column_definitions = $column_definitions; |
|
1626 | 1625 | } |
1627 | 1626 | |
1628 | 1627 | /** |
@@ -1635,7 +1634,7 @@ discard block |
||
1635 | 1634 | * |
1636 | 1635 | * @var string |
1637 | 1636 | */ |
1638 | - private $app=self::API_APPNAME; |
|
1637 | + private $app = self::API_APPNAME; |
|
1639 | 1638 | |
1640 | 1639 | /** |
1641 | 1640 | * Sets the application in which the db-class looks for table-defintions |
@@ -1692,14 +1691,14 @@ discard block |
||
1692 | 1691 | * @param bool|string $table if set return only defintions of that table, else return all defintions |
1693 | 1692 | * @return mixed array with table-defintions or False if file not found |
1694 | 1693 | */ |
1695 | - function get_table_definitions($app=False,$table=False) |
|
1694 | + function get_table_definitions($app = False, $table = False) |
|
1696 | 1695 | { |
1697 | 1696 | // ease the transition to api |
1698 | 1697 | if ($app === 'phpgwapi') $app = 'api'; |
1699 | 1698 | |
1700 | 1699 | if ($app === true && $table) |
1701 | 1700 | { |
1702 | - foreach(self::$all_app_data as $app => &$app_data) |
|
1701 | + foreach (self::$all_app_data as $app => &$app_data) |
|
1703 | 1702 | { |
1704 | 1703 | if (isset($app_data[$table])) |
1705 | 1704 | { |
@@ -1707,13 +1706,13 @@ discard block |
||
1707 | 1706 | } |
1708 | 1707 | } |
1709 | 1708 | // $table not found in loaded apps, check not yet loaded ones |
1710 | - foreach(scandir(EGW_INCLUDE_ROOT) as $app) |
|
1709 | + foreach (scandir(EGW_INCLUDE_ROOT) as $app) |
|
1711 | 1710 | { |
1712 | 1711 | if ($app[0] == '.' || !is_dir(EGW_INCLUDE_ROOT.'/'.$app) || isset(self::$all_app_data[$app])) |
1713 | 1712 | { |
1714 | 1713 | continue; |
1715 | 1714 | } |
1716 | - $tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php"; |
|
1715 | + $tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php"; |
|
1717 | 1716 | if (!@file_exists($tables_current)) |
1718 | 1717 | { |
1719 | 1718 | self::$all_app_data[$app] = False; |
@@ -1722,7 +1721,7 @@ discard block |
||
1722 | 1721 | { |
1723 | 1722 | $phpgw_baseline = null; |
1724 | 1723 | include($tables_current); |
1725 | - self::$all_app_data[$app] =& $phpgw_baseline; |
|
1724 | + self::$all_app_data[$app] = & $phpgw_baseline; |
|
1726 | 1725 | unset($phpgw_baseline); |
1727 | 1726 | |
1728 | 1727 | if (isset(self::$all_app_data[$app][$table])) |
@@ -1737,17 +1736,17 @@ discard block |
||
1737 | 1736 | { |
1738 | 1737 | $app = $this->app ? $this->app : $GLOBALS['egw_info']['flags']['currentapp']; |
1739 | 1738 | } |
1740 | - $app_data =& self::$all_app_data[$app]; |
|
1739 | + $app_data = & self::$all_app_data[$app]; |
|
1741 | 1740 | |
1742 | 1741 | if (!isset($app_data)) |
1743 | 1742 | { |
1744 | - $tables_current = EGW_INCLUDE_ROOT . "/$app/setup/tables_current.inc.php"; |
|
1743 | + $tables_current = EGW_INCLUDE_ROOT."/$app/setup/tables_current.inc.php"; |
|
1745 | 1744 | if (!@file_exists($tables_current)) |
1746 | 1745 | { |
1747 | 1746 | return $app_data = False; |
1748 | 1747 | } |
1749 | 1748 | include($tables_current); |
1750 | - $app_data =& $phpgw_baseline; |
|
1749 | + $app_data = & $phpgw_baseline; |
|
1751 | 1750 | unset($phpgw_baseline); |
1752 | 1751 | } |
1753 | 1752 | if ($table && (!$app_data || !isset($app_data[$table]))) |
@@ -1770,14 +1769,14 @@ discard block |
||
1770 | 1769 | * @param string $attribute='comment' what field to return, NULL for array with all fields, default 'comment' to return the comment |
1771 | 1770 | * @return string|array NULL if table or column or attribute not found |
1772 | 1771 | */ |
1773 | - /* static */ function get_column_attribute($column,$table,$app=null,$attribute='comment') |
|
1772 | + /* static */ function get_column_attribute($column, $table, $app = null, $attribute = 'comment') |
|
1774 | 1773 | { |
1775 | - static $cached_columns=null,$cached_table=null; // some caching |
|
1774 | + static $cached_columns = null, $cached_table = null; // some caching |
|
1776 | 1775 | |
1777 | 1776 | if ($cached_table !== $table || is_null($cached_columns)) |
1778 | 1777 | { |
1779 | 1778 | $db = isset($this) && is_a($this, __CLASS__) ? $this : $GLOBALS['egw']->db; |
1780 | - $table_def = $db->get_table_definitions($app,$table); |
|
1779 | + $table_def = $db->get_table_definitions($app, $table); |
|
1781 | 1780 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
1782 | 1781 | } |
1783 | 1782 | if ($cached_columns === false) return null; |
@@ -1801,38 +1800,38 @@ discard block |
||
1801 | 1800 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1802 | 1801 | * @return ADORecordSet or false, if the query fails |
1803 | 1802 | */ |
1804 | - function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
|
1803 | + function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False) |
|
1805 | 1804 | { |
1806 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
1805 | + if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app')</p>\n"; |
|
1807 | 1806 | |
1808 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1807 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
1809 | 1808 | |
1810 | 1809 | $sql_append = ''; |
1811 | 1810 | $cmd = 'INSERT'; |
1812 | 1811 | if (is_array($where) && count($where)) |
1813 | 1812 | { |
1814 | - switch($this->Type) |
|
1813 | + switch ($this->Type) |
|
1815 | 1814 | { |
1816 | 1815 | case 'sapdb': case 'maxdb': |
1817 | 1816 | $sql_append = ' UPDATE DUPLICATES'; |
1818 | 1817 | break; |
1819 | 1818 | case 'mysql': |
1820 | 1819 | // use replace if primary keys are included |
1821 | - if (count(array_intersect(array_keys($where),(array)$table_def['pk'])) == count($table_def['pk'])) |
|
1820 | + if (count(array_intersect(array_keys($where), (array)$table_def['pk'])) == count($table_def['pk'])) |
|
1822 | 1821 | { |
1823 | 1822 | $cmd = 'REPLACE'; |
1824 | 1823 | break; |
1825 | 1824 | } |
1826 | 1825 | // fall through !!! |
1827 | 1826 | default: |
1828 | - if ($this->select($table,'count(*)',$where,$line,$file)->fetchColumn()) |
|
1827 | + if ($this->select($table, 'count(*)', $where, $line, $file)->fetchColumn()) |
|
1829 | 1828 | { |
1830 | - return !!$this->update($table,$data,$where,$line,$file,$app,$use_prepared_statement,$table_def); |
|
1829 | + return !!$this->update($table, $data, $where, $line, $file, $app, $use_prepared_statement, $table_def); |
|
1831 | 1830 | } |
1832 | 1831 | break; |
1833 | 1832 | } |
1834 | 1833 | // the checked values need to be inserted too, value in data has precedence, also cant insert sql strings (numerical id) |
1835 | - foreach($where as $column => $value) |
|
1834 | + foreach ($where as $column => $value) |
|
1836 | 1835 | { |
1837 | 1836 | if (!is_numeric($column) && !isset($data[$column]) && |
1838 | 1837 | // skip auto-id of 0 or NULL, as PostgreSQL does NOT create an auto-id, if they are given |
@@ -1852,24 +1851,24 @@ discard block |
||
1852 | 1851 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
1853 | 1852 | |
1854 | 1853 | $sql = "$cmd INTO $table "; |
1855 | - foreach($data as $k => $d) |
|
1854 | + foreach ($data as $k => $d) |
|
1856 | 1855 | { |
1857 | 1856 | if (!$k) |
1858 | 1857 | { |
1859 | - $sql .= $this->column_data_implode(',',$d,'VALUES',true,$table_def['fd']); |
|
1858 | + $sql .= $this->column_data_implode(',', $d, 'VALUES', true, $table_def['fd']); |
|
1860 | 1859 | } |
1861 | 1860 | else |
1862 | 1861 | { |
1863 | - $sql .= ",\n(".$this->column_data_implode(',',$d,false,true,$table_def['fd']).')'; |
|
1862 | + $sql .= ",\n(".$this->column_data_implode(',', $d, false, true, $table_def['fd']).')'; |
|
1864 | 1863 | } |
1865 | 1864 | } |
1866 | 1865 | $sql .= $sql_append; |
1867 | 1866 | } |
1868 | 1867 | elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
1869 | 1868 | { |
1870 | - $this->Link_ID->Param(false); // reset param-counter |
|
1869 | + $this->Link_ID->Param(false); // reset param-counter |
|
1871 | 1870 | $cols = array_keys($data); |
1872 | - foreach($cols as $k => $col) |
|
1871 | + foreach ($cols as $k => $col) |
|
1873 | 1872 | { |
1874 | 1873 | if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
1875 | 1874 | { |
@@ -1878,7 +1877,7 @@ discard block |
||
1878 | 1877 | } |
1879 | 1878 | $params[] = $this->Link_ID->Param($col); |
1880 | 1879 | } |
1881 | - $sql = "$cmd INTO $table (".implode(',',$cols).') VALUES ('.implode(',',$params).')'.$sql_append; |
|
1880 | + $sql = "$cmd INTO $table (".implode(',', $cols).') VALUES ('.implode(',', $params).')'.$sql_append; |
|
1882 | 1881 | // check if we already prepared that statement |
1883 | 1882 | if (!isset($this->prepared_sql[$sql])) |
1884 | 1883 | { |
@@ -1889,10 +1888,10 @@ discard block |
||
1889 | 1888 | } |
1890 | 1889 | else |
1891 | 1890 | { |
1892 | - $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
|
1891 | + $sql = "$cmd INTO $table ".$this->column_data_implode(',', $data, 'VALUES', true, $table_def['fd']).$sql_append; |
|
1893 | 1892 | } |
1894 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
1895 | - return $this->query($sql,$line,$file,0,-1,$inputarr); |
|
1893 | + if ($this->Debug) echo "<p>db::insert('$table',".print_r($data, True).",".print_r($where, True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
1894 | + return $this->query($sql, $line, $file, 0, -1, $inputarr); |
|
1896 | 1895 | } |
1897 | 1896 | |
1898 | 1897 | /** |
@@ -1910,10 +1909,10 @@ discard block |
||
1910 | 1909 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1911 | 1910 | * @return ADORecordSet or false, if the query fails |
1912 | 1911 | */ |
1913 | - function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
|
1912 | + function update($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false, $table_def = False) |
|
1914 | 1913 | { |
1915 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
1916 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
1914 | + if ($this->Debug) echo "<p>db::update('$table',".print_r($data, true).','.print_r($where, true).",$line,$file,'$app')</p>\n"; |
|
1915 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
1917 | 1916 | |
1918 | 1917 | $blobs2update = array(); |
1919 | 1918 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1924,7 +1923,7 @@ discard block |
||
1924 | 1923 | case 'maxdb': |
1925 | 1924 | if ($use_prepared_statement) break; |
1926 | 1925 | // check if data contains any LONG columns |
1927 | - foreach($data as $col => $val) |
|
1926 | + foreach ($data as $col => $val) |
|
1928 | 1927 | { |
1929 | 1928 | switch ($table_def['fd'][$col]['type']) |
1930 | 1929 | { |
@@ -1938,7 +1937,7 @@ discard block |
||
1938 | 1937 | } |
1939 | 1938 | break; |
1940 | 1939 | } |
1941 | - $where_str = $this->column_data_implode(' AND ',$where,True,true,$table_def['fd']); |
|
1940 | + $where_str = $this->column_data_implode(' AND ', $where, True, true, $table_def['fd']); |
|
1942 | 1941 | |
1943 | 1942 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
1944 | 1943 | { |
@@ -1949,13 +1948,13 @@ discard block |
||
1949 | 1948 | $inputarr = false; |
1950 | 1949 | if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
1951 | 1950 | { |
1952 | - $this->Link_ID->Param(false); // reset param-counter |
|
1953 | - foreach($data as $col => $val) |
|
1951 | + $this->Link_ID->Param(false); // reset param-counter |
|
1952 | + foreach ($data as $col => $val) |
|
1954 | 1953 | { |
1955 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
1954 | + if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
1956 | 1955 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
1957 | 1956 | } |
1958 | - $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
|
1957 | + $sql = "UPDATE $table SET ".implode(',', $params).' WHERE '.$where_str; |
|
1959 | 1958 | // check if we already prepared that statement |
1960 | 1959 | if (!isset($this->prepared_sql[$sql])) |
1961 | 1960 | { |
@@ -1967,19 +1966,19 @@ discard block |
||
1967 | 1966 | else |
1968 | 1967 | { |
1969 | 1968 | $sql = "UPDATE $table SET ". |
1970 | - $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
|
1969 | + $this->column_data_implode(',', $data, True, true, $table_def['fd']).' WHERE '.$where_str; |
|
1971 | 1970 | } |
1972 | - $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
|
1971 | + $ret = $this->query($sql, $line, $file, 0, -1, $inputarr); |
|
1973 | 1972 | if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
1974 | 1973 | } |
1975 | 1974 | // if we have any blobs to update, we do so now |
1976 | 1975 | if (($ret || !count($data)) && count($blobs2update)) |
1977 | 1976 | { |
1978 | - foreach($blobs2update as $col => $val) |
|
1977 | + foreach ($blobs2update as $col => $val) |
|
1979 | 1978 | { |
1980 | - $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
|
1979 | + $ret = $this->Link_ID->UpdateBlob($table, $col, $val, $where_str, $table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
|
1981 | 1980 | if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
1982 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
1981 | + if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)", $line, $file); |
|
1983 | 1982 | } |
1984 | 1983 | } |
1985 | 1984 | return $ret; |
@@ -1998,18 +1997,18 @@ discard block |
||
1998 | 1997 | * @param array|bool $table_def use this table definition. If False, the table definition will be read from tables_baseline |
1999 | 1998 | * @return ADORecordSet or false, if the query fails |
2000 | 1999 | */ |
2001 | - function delete($table,$where,$line,$file,$app=False,$table_def=False) |
|
2000 | + function delete($table, $where, $line, $file, $app = False, $table_def = False) |
|
2002 | 2001 | { |
2003 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2002 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
2004 | 2003 | |
2005 | 2004 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
2006 | 2005 | { |
2007 | 2006 | $table = self::$tablealiases[$table]; |
2008 | 2007 | } |
2009 | 2008 | $sql = "DELETE FROM $table WHERE ". |
2010 | - $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']); |
|
2009 | + $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']); |
|
2011 | 2010 | |
2012 | - return $this->query($sql,$line,$file); |
|
2011 | + return $this->query($sql, $line, $file); |
|
2013 | 2012 | } |
2014 | 2013 | |
2015 | 2014 | /** |
@@ -2032,12 +2031,12 @@ discard block |
||
2032 | 2031 | */ |
2033 | 2032 | function expression($table_def/*,$args, ...*/) |
2034 | 2033 | { |
2035 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
2034 | + if (!is_array($table_def)) $table_def = $this->get_table_definitions(true, $table_def); |
|
2036 | 2035 | $sql = ''; |
2037 | 2036 | $ignore_next = 0; |
2038 | - foreach(func_get_args() as $n => $arg) |
|
2037 | + foreach (func_get_args() as $n => $arg) |
|
2039 | 2038 | { |
2040 | - if ($n < 1) continue; // table-name |
|
2039 | + if ($n < 1) continue; // table-name |
|
2041 | 2040 | |
2042 | 2041 | if ($ignore_next) |
2043 | 2042 | { |
@@ -2046,7 +2045,7 @@ discard block |
||
2046 | 2045 | } |
2047 | 2046 | if (is_null($arg)) $arg = False; |
2048 | 2047 | |
2049 | - switch(gettype($arg)) |
|
2048 | + switch (gettype($arg)) |
|
2050 | 2049 | { |
2051 | 2050 | case 'string': |
2052 | 2051 | $sql .= $arg; |
@@ -2055,7 +2054,7 @@ discard block |
||
2055 | 2054 | $ignore_next += !$arg ? 2 : 0; |
2056 | 2055 | break; |
2057 | 2056 | case 'array': |
2058 | - $sql .= $this->column_data_implode(' AND ',$arg,True,False,$table_def['fd']); |
|
2057 | + $sql .= $this->column_data_implode(' AND ', $arg, True, False, $table_def['fd']); |
|
2059 | 2058 | break; |
2060 | 2059 | } |
2061 | 2060 | } |
@@ -2082,18 +2081,18 @@ discard block |
||
2082 | 2081 | * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
2083 | 2082 | * @return ADORecordSet or false, if the query fails |
2084 | 2083 | */ |
2085 | - function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
|
2084 | + function select($table, $cols, $where, $line, $file, $offset = False, $append = '', $app = False, $num_rows = 0, $join = '', $table_def = False, $fetchmode = self::FETCH_ASSOC) |
|
2086 | 2085 | { |
2087 | - 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"; |
|
2086 | + 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"; |
|
2088 | 2087 | |
2089 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
2088 | + if (!$table_def) $table_def = $this->get_table_definitions($app, $table); |
|
2090 | 2089 | if (is_array($cols)) |
2091 | 2090 | { |
2092 | - $cols = implode(',',$cols); |
|
2091 | + $cols = implode(',', $cols); |
|
2093 | 2092 | } |
2094 | 2093 | if (is_array($where)) |
2095 | 2094 | { |
2096 | - $where = $this->column_data_implode(' AND ',$where,True,False,$table_def['fd']); |
|
2095 | + $where = $this->column_data_implode(' AND ', $where, True, False, $table_def['fd']); |
|
2097 | 2096 | } |
2098 | 2097 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
2099 | 2098 | { |
@@ -2102,7 +2101,7 @@ discard block |
||
2102 | 2101 | $sql = "SELECT $cols FROM $table $join"; |
2103 | 2102 | |
2104 | 2103 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
2105 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2104 | + if ($where) $sql .= (strpos($join, "WHERE") !== false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
2106 | 2105 | |
2107 | 2106 | if ($append) $sql .= ' '.$append; |
2108 | 2107 | |
@@ -2112,7 +2111,7 @@ discard block |
||
2112 | 2111 | { |
2113 | 2112 | return $sql; |
2114 | 2113 | } |
2115 | - return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
|
2114 | + return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode); |
|
2116 | 2115 | } |
2117 | 2116 | |
2118 | 2117 | /** |
@@ -2130,34 +2129,34 @@ discard block |
||
2130 | 2129 | * @param int $fetchmode =self::FETCH_ASSOC self::FETCH_ASSOC (default), self::FETCH_BOTH or self::FETCH_NUM |
2131 | 2130 | * @return ADORecordSet or false, if the query fails |
2132 | 2131 | */ |
2133 | - function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
|
2132 | + function union($selects, $line, $file, $order_by = '', $offset = false, $num_rows = 0, $fetchmode = self::FETCH_ASSOC) |
|
2134 | 2133 | { |
2135 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2134 | + if ($this->Debug) echo "<p>db::union(".print_r($selects, True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
2136 | 2135 | |
2137 | 2136 | $union = array(); |
2138 | - foreach($selects as $select) |
|
2137 | + foreach ($selects as $select) |
|
2139 | 2138 | { |
2140 | - $union[] = call_user_func_array(array($this,'select'),array( |
|
2139 | + $union[] = call_user_func_array(array($this, 'select'), array( |
|
2141 | 2140 | $select['table'], |
2142 | 2141 | $select['cols'], |
2143 | 2142 | $select['where'], |
2144 | - false, // line |
|
2145 | - false, // file |
|
2146 | - false, // offset |
|
2143 | + false, // line |
|
2144 | + false, // file |
|
2145 | + false, // offset |
|
2147 | 2146 | $select['append'], |
2148 | 2147 | $select['app'], |
2149 | - 0, // num_rows, |
|
2148 | + 0, // num_rows, |
|
2150 | 2149 | $select['join'], |
2151 | 2150 | $select['table_def'], |
2152 | 2151 | )); |
2153 | 2152 | } |
2154 | - $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
|
2153 | + $sql = count($union) > 1 ? '('.implode(")\nUNION\n(", $union).')' : 'SELECT DISTINCT'.substr($union[0], 6); |
|
2155 | 2154 | |
2156 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2155 | + if ($order_by) $sql .= (!stristr($order_by, 'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
2157 | 2156 | |
2158 | 2157 | if ($this->Debug) echo "<p>sql='$sql'</p>"; |
2159 | 2158 | |
2160 | - return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
|
2159 | + return $this->query($sql, $line, $file, $offset, $offset === False ? -1 : (int)$num_rows, false, $fetchmode); |
|
2161 | 2160 | } |
2162 | 2161 | |
2163 | 2162 | /** |
@@ -2167,15 +2166,15 @@ discard block |
||
2167 | 2166 | * @param string|array $strip |
2168 | 2167 | * @return array |
2169 | 2168 | */ |
2170 | - static function strip_array_keys($arr,$strip) |
|
2169 | + static function strip_array_keys($arr, $strip) |
|
2171 | 2170 | { |
2172 | 2171 | $keys = array_keys($arr); |
2173 | 2172 | |
2174 | 2173 | return array_walk($keys, function(&$v, $k, $strip) |
2175 | 2174 | { |
2176 | - unset($k); // not used, but required by function signature |
|
2175 | + unset($k); // not used, but required by function signature |
|
2177 | 2176 | $v = str_replace($strip, '', $v); |
2178 | 2177 | }, $strip) ? |
2179 | - array_combine($keys,$arr) : $arr; |
|
2178 | + array_combine($keys, $arr) : $arr; |
|
2180 | 2179 | } |
2181 | 2180 | } |
@@ -496,7 +496,7 @@ discard block |
||
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 |
||
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 |
||
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 | { |
@@ -381,7 +381,7 @@ discard block |
||
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 |
||
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 |
||
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 .... |
@@ -102,25 +102,34 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
393 | 414 | $zip = NULL; |
394 | 415 | $_f = NULL; |
395 | 416 | if($type == 'zip') |
396 | - { |
|
417 | + { |
|
397 | 418 | // has already been verified to be available in fopen_backup |
398 | 419 | $zip = new ZipArchive; |
399 | 420 | if(($zip->open($filename)) !== TRUE) |
@@ -412,7 +433,9 @@ discard block |
||
412 | 433 | } |
413 | 434 | $this->db_restore($f, $insert_n_rows); |
414 | 435 | |
415 | - if ($convert_to_system_charset) // store the changed charset |
|
436 | + if ($convert_to_system_charset) |
|
437 | + { |
|
438 | + // store the changed charset |
|
416 | 439 | { |
417 | 440 | $this->db->insert(Api\Config::TABLE, array( |
418 | 441 | 'config_value' => $this->schema_proc->system_charset, |
@@ -421,6 +444,7 @@ discard block |
||
421 | 444 | 'config_name' => 'system_charset', |
422 | 445 | ),__LINE__,__FILE__); |
423 | 446 | } |
447 | + } |
|
424 | 448 | // restore protected system config |
425 | 449 | if ($protect_system_config) |
426 | 450 | { |
@@ -510,7 +534,10 @@ discard block |
||
510 | 534 | { |
511 | 535 | $line = trim(fgets($f)); ++$n; |
512 | 536 | |
513 | - if (empty($line)) continue; |
|
537 | + if (empty($line)) |
|
538 | + { |
|
539 | + continue; |
|
540 | + } |
|
514 | 541 | |
515 | 542 | if (substr($line,0,9) == 'version: ') |
516 | 543 | { |
@@ -552,35 +579,53 @@ discard block |
||
552 | 579 | } |
553 | 580 | if (substr($line,0,7) == 'table: ') |
554 | 581 | { |
555 | - if ($rows) // flush pending rows of last table |
|
582 | + if ($rows) |
|
583 | + { |
|
584 | + // flush pending rows of last table |
|
556 | 585 | { |
557 | 586 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
558 | 587 | } |
588 | + } |
|
559 | 589 | $rows = array(); |
560 | 590 | $table = substr($line,7); |
561 | - if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
591 | + if (!isset($this->schemas[$table])) |
|
592 | + { |
|
593 | + $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
|
594 | + } |
|
562 | 595 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
563 | 596 | |
564 | 597 | $cols = self::csv_split($line=fgets($f)); ++$n; |
565 | 598 | $blobs = array(); |
566 | 599 | foreach($this->schemas[$table]['fd'] as $col => $data) |
567 | 600 | { |
568 | - if ($data['type'] == 'blob') $blobs[] = $col; |
|
601 | + if ($data['type'] == 'blob') |
|
602 | + { |
|
603 | + $blobs[] = $col; |
|
604 | + } |
|
569 | 605 | } |
570 | 606 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
571 | 607 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
572 | 608 | $bools = array(); |
573 | 609 | foreach($this->schemas[$table]['fd'] as $col => $def) |
574 | 610 | { |
575 | - if ($def['type'] === 'bool') $bools[] = $col; |
|
611 | + if ($def['type'] === 'bool') |
|
612 | + { |
|
613 | + $bools[] = $col; |
|
614 | + } |
|
576 | 615 | } |
577 | 616 | |
578 | - if (feof($f)) break; |
|
617 | + if (feof($f)) |
|
618 | + { |
|
619 | + break; |
|
620 | + } |
|
579 | 621 | continue; |
580 | 622 | } |
581 | - if ($table) // do we already reached the data part |
|
623 | + if ($table) |
|
624 | + { |
|
625 | + // do we already reached the data part |
|
582 | 626 | { |
583 | 627 | $import = true; |
628 | + } |
|
584 | 629 | $data = self::csv_split($line, $cols, $blobs, $bools); |
585 | 630 | |
586 | 631 | if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
@@ -616,7 +661,10 @@ discard block |
||
616 | 661 | { |
617 | 662 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
618 | 663 | unset($data[$insert_n_rows]); |
619 | - if ($auto_id) unset($data[$auto_id]); |
|
664 | + if ($auto_id) |
|
665 | + { |
|
666 | + unset($data[$auto_id]); |
|
667 | + } |
|
620 | 668 | $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
621 | 669 | } |
622 | 670 | else |
@@ -637,10 +685,13 @@ discard block |
||
637 | 685 | } |
638 | 686 | } |
639 | 687 | } |
640 | - if ($rows) // flush pending rows |
|
688 | + if ($rows) |
|
689 | + { |
|
690 | + // flush pending rows |
|
641 | 691 | { |
642 | 692 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
643 | 693 | } |
694 | + } |
|
644 | 695 | // updated the sequences, if the DB uses them |
645 | 696 | foreach($this->schemas as $table => $schema) |
646 | 697 | { |
@@ -698,9 +749,13 @@ discard block |
||
698 | 749 | while($file = $list[0]) |
699 | 750 | { |
700 | 751 | if(is_dir($file) && $file != '.' && $file != '..') |
701 | - self::remove_dir_content($dir.'/'.$file); |
|
752 | + { |
|
753 | + self::remove_dir_content($dir.'/'.$file); |
|
754 | + } |
|
702 | 755 | if(is_file($file) && $file != '.' && $file != '..') |
703 | - unlink($dir.'/'.$file); |
|
756 | + { |
|
757 | + unlink($dir.'/'.$file); |
|
758 | + } |
|
704 | 759 | array_shift($list); |
705 | 760 | } |
706 | 761 | //rmdir($dir); // dont remove own dir |
@@ -726,7 +781,9 @@ discard block |
||
726 | 781 | */ |
727 | 782 | public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
728 | 783 | { |
729 | - if (function_exists('str_getcsv')) // php5.3+ |
|
784 | + if (function_exists('str_getcsv')) |
|
785 | + { |
|
786 | + // php5.3+ |
|
730 | 787 | { |
731 | 788 | // we need to take care of literal "NULL" values, replacing them we a special token as str_getcsv removes enclosures around strings |
732 | 789 | // str_getcsv uses '""' for '"' instead of '\\"' and does not unescape '\\n', '\\r' or '\\\\' (two backslashes) |
@@ -736,6 +793,7 @@ discard block |
||
736 | 793 | '\\"' => '""', |
737 | 794 | '\\n' => "\n", |
738 | 795 | '\\r' => "\r")), ',', '"', '\0'); |
796 | + } |
|
739 | 797 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
740 | 798 | foreach($fields as &$field) |
741 | 799 | { |
@@ -752,9 +810,12 @@ discard block |
||
752 | 810 | break; |
753 | 811 | } |
754 | 812 | } |
755 | - if ($keys) // if string keys are to be used --> combine keys and values |
|
813 | + if ($keys) |
|
814 | + { |
|
815 | + // if string keys are to be used --> combine keys and values |
|
756 | 816 | { |
757 | 817 | $fields = array_combine($keys, $fields); |
818 | + } |
|
758 | 819 | // base64-decode blob columns, if they are base64 encoded |
759 | 820 | foreach($blobs as $key) |
760 | 821 | { |
@@ -903,7 +964,11 @@ discard block |
||
903 | 964 | |
904 | 965 | foreach($this->schemas as $table => $schema) |
905 | 966 | { |
906 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
967 | + if (in_array($table,$this->exclude_tables)) |
|
968 | + { |
|
969 | + continue; |
|
970 | + } |
|
971 | + // dont backup |
|
907 | 972 | |
908 | 973 | // do we have a primary key? |
909 | 974 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -929,8 +994,14 @@ discard block |
||
929 | 994 | empty($pk) ? '' : 'ORDER BY '.$this->db->name_quote($pk).' ASC', |
930 | 995 | false, self::ROW_CHUNK) as $row) |
931 | 996 | { |
932 | - if (!empty($pk)) $max = $row[$pk]; |
|
933 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
997 | + if (!empty($pk)) |
|
998 | + { |
|
999 | + $max = $row[$pk]; |
|
1000 | + } |
|
1001 | + if ($total === 0) |
|
1002 | + { |
|
1003 | + fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
1004 | + } |
|
934 | 1005 | |
935 | 1006 | array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']); |
936 | 1007 | fwrite($f,implode(',',$row)."\n"); |
@@ -940,21 +1011,30 @@ discard block |
||
940 | 1011 | } |
941 | 1012 | while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
942 | 1013 | |
943 | - if (!$pk) $this->db->rollback_lock($table); |
|
1014 | + if (!$pk) |
|
1015 | + { |
|
1016 | + $this->db->rollback_lock($table); |
|
1017 | + } |
|
944 | 1018 | } |
945 | 1019 | |
946 | 1020 | // let apps know that backup is finished |
947 | 1021 | Api\Hooks::process('backup_finished', array(), true); |
948 | 1022 | |
949 | - if(!$zippresent) // save without files |
|
1023 | + if(!$zippresent) |
|
1024 | + { |
|
1025 | + // save without files |
|
950 | 1026 | { |
951 | 1027 | if ($this->backup_files) |
952 | 1028 | { |
953 | 1029 | echo '<center>'.lang("Cant open %1, needs ZipArchive", $name)."<br>\n".'</center>'; |
1030 | + } |
|
954 | 1031 | } |
955 | 1032 | |
956 | 1033 | fclose($f); |
957 | - if (file_exists($name)) unlink($name); |
|
1034 | + if (file_exists($name)) |
|
1035 | + { |
|
1036 | + unlink($name); |
|
1037 | + } |
|
958 | 1038 | return TRUE; |
959 | 1039 | } |
960 | 1040 | // save files .... |
@@ -966,9 +1046,12 @@ discard block |
||
966 | 1046 | //echo substr($file,strlen($dir)+1).'<br>'; |
967 | 1047 | //echo $file.'<br>'; |
968 | 1048 | $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
969 | - if(($count++) == 100) { // the file descriptor limit |
|
1049 | + if(($count++) == 100) |
|
1050 | + { |
|
1051 | +// the file descriptor limit |
|
970 | 1052 | $zip->close(); |
971 | - if(($zip = new ZipArchive())) { |
|
1053 | + if(($zip = new ZipArchive())) |
|
1054 | + { |
|
972 | 1055 | $zip->open($filename); |
973 | 1056 | $count =0; |
974 | 1057 | } |
@@ -993,15 +1076,21 @@ discard block |
||
993 | 1076 | { |
994 | 1077 | //chdir($f); |
995 | 1078 | //echo "Processing $f <br>"; |
996 | - if ($path_name =='') $path_name = $f; |
|
1079 | + if ($path_name =='') |
|
1080 | + { |
|
1081 | + $path_name = $f; |
|
1082 | + } |
|
997 | 1083 | $tlist = scandir($f); |
998 | 1084 | $list = array(); |
999 | 1085 | $i = $cnt; |
1000 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1086 | + while($file = $tlist[0]) |
|
1087 | + { |
|
1088 | + // remove all '.' and '..' and transfer to $list |
|
1001 | 1089 | { |
1002 | 1090 | if($file == '.' || $file == '..') |
1003 | 1091 | { |
1004 | 1092 | array_shift($tlist); |
1093 | + } |
|
1005 | 1094 | } |
1006 | 1095 | elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
1007 | 1096 | { |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * @var array |
51 | 51 | */ |
52 | 52 | var $exclude_tables = array( |
53 | - 'egw_sessions','egw_app_sessions','phpgw_sessions','phpgw_app_sessions', // eGW's session-tables |
|
54 | - 'phpgw_anglemail', // email's cache |
|
55 | - 'egw_felamimail_cache','egw_felamimail_folderstatus','phpgw_felamimail_cache','phpgw_felamimail_folderstatus', // felamimail's cache |
|
53 | + 'egw_sessions', 'egw_app_sessions', 'phpgw_sessions', 'phpgw_app_sessions', // eGW's session-tables |
|
54 | + 'phpgw_anglemail', // email's cache |
|
55 | + 'egw_felamimail_cache', 'egw_felamimail_folderstatus', 'phpgw_felamimail_cache', 'phpgw_felamimail_folderstatus', // felamimail's cache |
|
56 | 56 | 'egw_phpfreechat', // as of the fieldnames of the table a restore would fail within egroupware, and chatcontent is of no particular intrest |
57 | 57 | ); |
58 | 58 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @var boolean |
86 | 86 | */ |
87 | - var $backup_files = false ; |
|
87 | + var $backup_files = false; |
|
88 | 88 | /** |
89 | 89 | * Reference to schema_proc's Api\Db object |
90 | 90 | * |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | if (isset($GLOBALS['egw_setup']) && is_object($GLOBALS['egw_setup']) && !isset($GLOBALS['egw_setup']->db)) |
101 | 101 | { |
102 | - $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
102 | + $GLOBALS['egw_setup']->loaddb(); // we run inside setup, but db object is not loaded |
|
103 | 103 | } |
104 | 104 | if (isset($GLOBALS['egw_setup']->oProc) && is_object($GLOBALS['egw_setup']->oProc)) // schema_proc already instanciated, use it |
105 | 105 | { |
@@ -117,21 +117,21 @@ discard block |
||
117 | 117 | { |
118 | 118 | if ($GLOBALS['egw_setup']->config_table && $GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->config_table))) |
119 | 119 | { |
120 | - 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())) |
|
120 | + 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 | 121 | { |
122 | 122 | error_log(__METHOD__."->"."No files Directory set/found"); |
123 | 123 | } |
124 | - 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())) |
|
124 | + 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 | 125 | { |
126 | 126 | $this->backup_dir = $this->files_dir.'/db_backup'; |
127 | 127 | } |
128 | - $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(); |
|
129 | - $this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table,'app_version',array('app_name'=>array('api','phpgwapi')), |
|
130 | - __LINE__,__FILE__,0,'ORDER BY app_name ASC')->fetchColumn(); |
|
128 | + $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(); |
|
129 | + $this->api_version = $this->db->select($GLOBALS['egw_setup']->applications_table, 'app_version', array('app_name'=>array('api', 'phpgwapi')), |
|
130 | + __LINE__, __FILE__, 0, 'ORDER BY app_name ASC')->fetchColumn(); |
|
131 | 131 | // Backup settings |
132 | - $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(); |
|
132 | + $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 | 133 | // backup files too |
134 | - $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(); |
|
134 | + $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 | 135 | } |
136 | 136 | if (!$this->charset) $this->charset = 'utf-8'; |
137 | 137 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $this->backup_files = $GLOBALS['egw_info']['server']['backup_files']; |
147 | 147 | $this->charset = Api\Translation::charset(); |
148 | 148 | |
149 | - $this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api'])?'api':'phpgwapi']['version']; |
|
149 | + $this->api_version = $GLOBALS['egw_info']['apps'][isset($GLOBALS['egw_info']['apps']['api']) ? 'api' : 'phpgwapi']['version']; |
|
150 | 150 | } |
151 | 151 | // Set a default value if not set. |
152 | 152 | if (!isset($this->backup_mincount)) |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | { |
163 | 163 | mkdir($this->backup_dir); |
164 | 164 | } |
165 | - switch($this->db->Type) |
|
165 | + switch ($this->db->Type) |
|
166 | 166 | { |
167 | 167 | case 'sapdb': |
168 | 168 | case 'maxdb': |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param $reading =false opening for reading ('rb') or writing ('wb') |
180 | 180 | * @return string/resource/zip error-msg of file-handle |
181 | 181 | */ |
182 | - function fopen_backup($name=false,$reading=false) |
|
182 | + function fopen_backup($name = false, $reading = false) |
|
183 | 183 | { |
184 | 184 | //echo "function fopen_backup($name,$reading)<br>"; // ! |
185 | 185 | if (!$name) |
@@ -188,27 +188,27 @@ discard block |
||
188 | 188 | if (!$this->backup_dir || !is_writable($this->backup_dir)) |
189 | 189 | { |
190 | 190 | //echo ' -> !$this->backup_dir || !is_writable($this->backup_dir)<br>'; // ! |
191 | - return lang("backupdir '%1' is not writeable by the webserver",$this->backup_dir); |
|
191 | + return lang("backupdir '%1' is not writeable by the webserver", $this->backup_dir); |
|
192 | 192 | } |
193 | 193 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
194 | 194 | } |
195 | 195 | else // remove the extension, to use the correct wrapper based on the extension |
196 | 196 | { |
197 | 197 | //echo '-> else<br>'; // ! |
198 | - $name = preg_replace('/\.(bz2|gz)$/i','',$name); |
|
198 | + $name = preg_replace('/\.(bz2|gz)$/i', '', $name); |
|
199 | 199 | } |
200 | 200 | $mode = $reading ? 'rb' : 'wb'; |
201 | - list( , $type) = explode('.', basename($name)); |
|
202 | - if($type == 'zip' && $reading && $this->backup_files) |
|
201 | + list(, $type) = explode('.', basename($name)); |
|
202 | + if ($type == 'zip' && $reading && $this->backup_files) |
|
203 | 203 | { |
204 | 204 | //echo '-> $type == "zip" && $reading<br>'; // ! |
205 | - if(!class_exists('ZipArchive', false)) |
|
205 | + if (!class_exists('ZipArchive', false)) |
|
206 | 206 | { |
207 | 207 | $this->backup_files = false; |
208 | 208 | //echo ' -> (new ZipArchive) == NULL<br>'; // ! |
209 | 209 | return lang("Cant open %1, needs ZipArchive", $name)."<br>\n"; |
210 | 210 | } |
211 | - if(!($f = fopen($name, $mode))) |
|
211 | + if (!($f = fopen($name, $mode))) |
|
212 | 212 | { |
213 | 213 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
214 | 214 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | } |
217 | 217 | return $f; |
218 | 218 | } |
219 | - if(class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
219 | + if (class_exists('ZipArchive', false) && !$reading && $this->backup_files) |
|
220 | 220 | { |
221 | 221 | //echo '-> (new ZipArchive) != NULL && !$reading; '.$name.'<br>'; // ! |
222 | - if(!($f = fopen($name, $mode))) |
|
222 | + if (!($f = fopen($name, $mode))) |
|
223 | 223 | { |
224 | 224 | //echo ' -> !($f = fopen($name, $mode))<br>'; // ! |
225 | 225 | $lang_mode = $reading ? lang("reading") : lang("writing"); |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | } |
228 | 228 | return $f; |
229 | 229 | } |
230 | - if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
231 | - !($f = fopen("compress.zlib://$name.gz",$mode)) && |
|
232 | - !($f = fopen($name,$mode)) |
|
230 | + if (!($f = fopen("compress.bzip2://$name.bz2", $mode)) && |
|
231 | + !($f = fopen("compress.zlib://$name.gz", $mode)) && |
|
232 | + !($f = fopen($name, $mode)) |
|
233 | 233 | ) |
234 | 234 | { |
235 | 235 | //echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))<br>'; // ! |
@@ -256,13 +256,13 @@ discard block |
||
256 | 256 | /* Search the backup directory for matching files. */ |
257 | 257 | $handle = @opendir($this->backup_dir); |
258 | 258 | $files = array(); |
259 | - while($handle && ($file = readdir($handle))) |
|
259 | + while ($handle && ($file = readdir($handle))) |
|
260 | 260 | { |
261 | 261 | /* Filter for only the files with the regular name (un-renamed). |
262 | 262 | * Leave special backup files (renamed) in place. |
263 | 263 | * Note that this also excludes "." and "..". |
264 | 264 | */ |
265 | - if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/",$file)) |
|
265 | + if (preg_match("/^db_backup-[0-9]{12}(\.bz2|\.gz|\.zip|)$/", $file)) |
|
266 | 266 | { |
267 | 267 | $files[filectime($this->backup_dir.'/'.$file)] = $file; |
268 | 268 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | /* Sort the files by ctime. */ |
273 | 273 | krsort($files); |
274 | 274 | $count = 0; |
275 | - foreach($files as $file) |
|
275 | + foreach ($files as $file) |
|
276 | 276 | { |
277 | 277 | if ($count >= $this->backup_mincount)// |
278 | 278 | { |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | array_push($files_return, $file); |
283 | 283 | } |
284 | 284 | } |
285 | - $count ++; |
|
285 | + $count++; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
@@ -292,13 +292,13 @@ discard block |
||
292 | 292 | * @param int $minCount Minimum number of backups to keep. |
293 | 293 | * @param boolean $backupFiles include files in backup or not, default dont change! |
294 | 294 | */ |
295 | - function saveConfig($minCount,$backupFiles=null) |
|
295 | + function saveConfig($minCount, $backupFiles = null) |
|
296 | 296 | { |
297 | - Api\Config::save_value('backup_mincount',$this->backup_mincount=(int)$minCount,'phpgwapi'); |
|
297 | + Api\Config::save_value('backup_mincount', $this->backup_mincount = (int)$minCount, 'phpgwapi'); |
|
298 | 298 | |
299 | 299 | if (!is_null($backupFiles)) |
300 | 300 | { |
301 | - Api\Config::save_value('backup_files',$this->backup_files=(boolean)$backupFiles,'phpgwapi'); |
|
301 | + Api\Config::save_value('backup_files', $this->backup_files = (boolean)$backupFiles, 'phpgwapi'); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | 'httpproxy_server_password', |
322 | 322 | 'system_charset', |
323 | 323 | 'usecookies', |
324 | - 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
324 | + 'install_id', // do not restore install_id, as that would give two systems with identical install_id |
|
325 | 325 | ); |
326 | 326 | |
327 | 327 | /** |
@@ -335,20 +335,20 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @returns An empty string or an error message in case of failure. |
337 | 337 | */ |
338 | - function restore($f,$convert_to_system_charset=true,$filename='',$protect_system_config=true, $insert_n_rows=10) |
|
338 | + function restore($f, $convert_to_system_charset = true, $filename = '', $protect_system_config = true, $insert_n_rows = 10) |
|
339 | 339 | { |
340 | 340 | @set_time_limit(0); |
341 | - ini_set('auto_detect_line_endings',true); |
|
341 | + ini_set('auto_detect_line_endings', true); |
|
342 | 342 | |
343 | - if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
343 | + if (true) $convert_to_system_charset = true; // enforce now utf-8 as system charset restores of old backups |
|
344 | 344 | |
345 | 345 | if ($protect_system_config) |
346 | 346 | { |
347 | 347 | $system_config = array(); |
348 | - foreach($this->db->select(self::TABLE,'*',array( |
|
348 | + foreach ($this->db->select(self::TABLE, '*', array( |
|
349 | 349 | 'config_app' => 'phpgwapi', |
350 | 350 | 'config_name' => self::$system_config, |
351 | - ),__LINE__,__FILE__) as $row) |
|
351 | + ), __LINE__, __FILE__) as $row) |
|
352 | 352 | { |
353 | 353 | $system_config[] = $row; |
354 | 354 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | // as MySQL 5.7+ has sql_mode STRICT_(ALL|TRANS)_TABLES enabled by default, |
358 | 358 | // it will no longer restore '0000-00-00 00:00:00' in timestamps it created before, |
359 | 359 | // so switching strict-mode off temporary for the restore (we dont create these!) |
360 | - if (substr($this->db->Type,0,5) == 'mysql') |
|
360 | + if (substr($this->db->Type, 0, 5) == 'mysql') |
|
361 | 361 | { |
362 | 362 | $this->db->query("SET SESSION sql_mode=(SELECT REPLACE(REPLACE(@@sql_mode,'STRICT_ALL_TABLES',''),'STRICT_TRANS_TABLES',''))", __LINE__, __FILE__); |
363 | 363 | } |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | |
369 | 369 | |
370 | 370 | // drop all existing tables |
371 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
371 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
372 | 372 | { |
373 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
374 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
373 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
374 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
375 | 375 | { |
376 | 376 | continue; |
377 | 377 | } |
378 | 378 | $this->schema_proc->DropTable($table); |
379 | 379 | } |
380 | 380 | // it could be an old backup |
381 | - list( , $type) = explode('.', basename($filename)); |
|
381 | + list(, $type) = explode('.', basename($filename)); |
|
382 | 382 | $dir = $this->files_dir; // $GLOBALS['egw_info']['server']['files_dir']; |
383 | 383 | // we may have to clean up old backup - left overs |
384 | 384 | if (is_dir($dir.'/database_backup')) |
@@ -391,20 +391,20 @@ discard block |
||
391 | 391 | $name = ""; |
392 | 392 | $zip = NULL; |
393 | 393 | $_f = NULL; |
394 | - if($type == 'zip') |
|
394 | + if ($type == 'zip') |
|
395 | 395 | { |
396 | 396 | // has already been verified to be available in fopen_backup |
397 | 397 | $zip = new ZipArchive; |
398 | - if(($zip->open($filename)) !== TRUE) |
|
398 | + if (($zip->open($filename)) !== TRUE) |
|
399 | 399 | { |
400 | 400 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
401 | 401 | } |
402 | - self::remove_dir_content($dir); // removes the files-dir |
|
402 | + self::remove_dir_content($dir); // removes the files-dir |
|
403 | 403 | $zip->extractTo($dir); |
404 | 404 | $_f = $f; |
405 | 405 | $list = $this->get_file_list($dir.'/database_backup/'); |
406 | 406 | $name = $dir.'/database_backup/'.basename($list[0]); |
407 | - if(!($f = fopen($name, 'rb'))) |
|
407 | + if (!($f = fopen($name, 'rb'))) |
|
408 | 408 | { |
409 | 409 | return lang("Cant open '%1' for %2", $filename, lang("reading"))."<br>\n"; |
410 | 410 | } |
@@ -415,56 +415,56 @@ discard block |
||
415 | 415 | { |
416 | 416 | $this->db->insert(Api\Config::TABLE, array( |
417 | 417 | 'config_value' => $this->schema_proc->system_charset, |
418 | - ),array( |
|
418 | + ), array( |
|
419 | 419 | 'config_app' => 'phpgwapi', |
420 | 420 | 'config_name' => 'system_charset', |
421 | - ),__LINE__,__FILE__); |
|
421 | + ), __LINE__, __FILE__); |
|
422 | 422 | } |
423 | 423 | // restore protected system config |
424 | 424 | if ($protect_system_config) |
425 | 425 | { |
426 | - foreach($system_config as $row) |
|
426 | + foreach ($system_config as $row) |
|
427 | 427 | { |
428 | - $this->db->insert(self::TABLE,array('config_value'=>$row['config_value']),array( |
|
428 | + $this->db->insert(self::TABLE, array('config_value'=>$row['config_value']), array( |
|
429 | 429 | 'config_name' => $row['config_name'], |
430 | 430 | 'config_app' => $row['config_app'], |
431 | - ),__LINE__,__FILE__); |
|
431 | + ), __LINE__, __FILE__); |
|
432 | 432 | } |
433 | 433 | // check and reset cookie configuration, if it does not match current enviroment |
434 | 434 | // if $_SERVER[HTTP_HOST] does not end with cookiedomain --> delete cookiedomain |
435 | - if (($cookiedomain = $this->db->select(self::TABLE,'config_value',array( |
|
435 | + if (($cookiedomain = $this->db->select(self::TABLE, 'config_value', array( |
|
436 | 436 | 'config_app' => 'phpgwapi', |
437 | 437 | 'config_name' => 'cookiedomain', |
438 | - ),__LINE__,__FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
439 | - (list($hostname) = explode(':',$_SERVER['HTTP_HOST'])) && |
|
440 | - substr($hostname,-strlen($cookiedomain) !== $cookiedomain)) |
|
438 | + ), __LINE__, __FILE__)->fetchColumn()) && isset($_SERVER['HTTP_HOST']) && |
|
439 | + (list($hostname) = explode(':', $_SERVER['HTTP_HOST'])) && |
|
440 | + substr($hostname, -strlen($cookiedomain) !== $cookiedomain)) |
|
441 | 441 | { |
442 | - $this->db->delete(self::TABLE,array( |
|
442 | + $this->db->delete(self::TABLE, array( |
|
443 | 443 | 'config_app' => 'phpgwapi', |
444 | 444 | 'config_name' => 'cookiedomain', |
445 | - ),__LINE__,__FILE__); |
|
445 | + ), __LINE__, __FILE__); |
|
446 | 446 | } |
447 | 447 | // if configured webserver_url does NOT start with cookiepath --> delete cookiepath |
448 | - if (($cookiepath = $this->db->select(self::TABLE,'config_value',array( |
|
448 | + if (($cookiepath = $this->db->select(self::TABLE, 'config_value', array( |
|
449 | 449 | 'config_app' => 'phpgwapi', |
450 | 450 | 'config_name' => 'cookiepath', |
451 | - ),__LINE__,__FILE__)->fetchColumn()) && |
|
452 | - substr(parse_url($system_config['webserver_url'], PHP_URL_PATH),0,strlen($cookiepath) !== $cookiepath)) |
|
451 | + ), __LINE__, __FILE__)->fetchColumn()) && |
|
452 | + substr(parse_url($system_config['webserver_url'], PHP_URL_PATH), 0, strlen($cookiepath) !== $cookiepath)) |
|
453 | 453 | { |
454 | - $this->db->delete(self::TABLE,array( |
|
454 | + $this->db->delete(self::TABLE, array( |
|
455 | 455 | 'config_app' => 'phpgwapi', |
456 | 456 | 'config_name' => 'cookiepath', |
457 | - ),__LINE__,__FILE__); |
|
457 | + ), __LINE__, __FILE__); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | // zip? |
461 | - if($type == 'zip') |
|
461 | + if ($type == 'zip') |
|
462 | 462 | { |
463 | 463 | fclose($f); |
464 | 464 | unlink($name); |
465 | 465 | rmdir($dir.'/database_backup'); |
466 | 466 | } |
467 | - if (substr($this->db->Type,0,5) != 'mysql') |
|
467 | + if (substr($this->db->Type, 0, 5) != 'mysql') |
|
468 | 468 | { |
469 | 469 | if (!$this->db->transaction_commit()) |
470 | 470 | { |
@@ -499,26 +499,26 @@ discard block |
||
499 | 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 |
500 | 500 | * @returns int number of rows read from csv file |
501 | 501 | */ |
502 | - function db_restore($f, $insert_n_rows=10) |
|
502 | + function db_restore($f, $insert_n_rows = 10) |
|
503 | 503 | { |
504 | 504 | $convert_to_system_charset = true; |
505 | 505 | $table = null; |
506 | 506 | $n = 0; |
507 | 507 | $rows = array(); |
508 | - while(!feof($f)) |
|
508 | + while (!feof($f)) |
|
509 | 509 | { |
510 | 510 | $line = trim(fgets($f)); ++$n; |
511 | 511 | |
512 | 512 | if (empty($line)) continue; |
513 | 513 | |
514 | - if (substr($line,0,9) == 'version: ') |
|
514 | + if (substr($line, 0, 9) == 'version: ') |
|
515 | 515 | { |
516 | 516 | // currenty not used: $api_version = trim(substr($line,9)); |
517 | 517 | continue; |
518 | 518 | } |
519 | - if (substr($line,0,9) == 'charset: ') |
|
519 | + if (substr($line, 0, 9) == 'charset: ') |
|
520 | 520 | { |
521 | - $charset = trim(substr($line,9)); |
|
521 | + $charset = trim(substr($line, 9)); |
|
522 | 522 | // needed if mbstring.func_overload > 0, else eg. substr does not work with non ascii chars |
523 | 523 | $ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset'; |
524 | 524 | @ini_set($ini_default_charset, $charset); |
@@ -526,18 +526,18 @@ discard block |
||
526 | 526 | // check if we really need to convert the charset, as it's not perfect and can do some damage |
527 | 527 | if ($convert_to_system_charset && !strcasecmp($this->schema_proc->system_charset, $charset)) |
528 | 528 | { |
529 | - $convert_to_system_charset = false; // no conversation necessary |
|
529 | + $convert_to_system_charset = false; // no conversation necessary |
|
530 | 530 | } |
531 | 531 | continue; |
532 | 532 | } |
533 | - if (substr($line,0,8) == 'schema: ') |
|
533 | + if (substr($line, 0, 8) == 'schema: ') |
|
534 | 534 | { |
535 | 535 | // create the tables in the backup set |
536 | - $this->schemas = json_php_unserialize(trim(substr($line,8))); |
|
537 | - foreach($this->schemas as $table_name => $schema) |
|
536 | + $this->schemas = json_php_unserialize(trim(substr($line, 8))); |
|
537 | + foreach ($this->schemas as $table_name => $schema) |
|
538 | 538 | { |
539 | 539 | // if column is longtext in current schema, convert text to longtext, in case user already updated column |
540 | - foreach($schema['fd'] as $col => &$def) |
|
540 | + foreach ($schema['fd'] as $col => &$def) |
|
541 | 541 | { |
542 | 542 | if ($def['type'] == 'text' && $this->db->get_column_attribute($col, $table_name, true, 'type') == 'longtext') |
543 | 543 | { |
@@ -549,27 +549,27 @@ discard block |
||
549 | 549 | } |
550 | 550 | continue; |
551 | 551 | } |
552 | - if (substr($line,0,7) == 'table: ') |
|
552 | + if (substr($line, 0, 7) == 'table: ') |
|
553 | 553 | { |
554 | 554 | if ($rows) // flush pending rows of last table |
555 | 555 | { |
556 | 556 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
557 | 557 | } |
558 | 558 | $rows = array(); |
559 | - $table = substr($line,7); |
|
559 | + $table = substr($line, 7); |
|
560 | 560 | if (!isset($this->schemas[$table])) $this->schemas[$table] = $this->db->get_table_definitions(true, $table); |
561 | 561 | $auto_id = count($this->schemas[$table]['pk']) == 1 ? $this->schemas[$table]['pk'][0] : null; |
562 | 562 | |
563 | - $cols = self::csv_split($line=fgets($f)); ++$n; |
|
563 | + $cols = self::csv_split($line = fgets($f)); ++$n; |
|
564 | 564 | $blobs = array(); |
565 | - foreach($this->schemas[$table]['fd'] as $col => $data) |
|
565 | + foreach ($this->schemas[$table]['fd'] as $col => $data) |
|
566 | 566 | { |
567 | 567 | if ($data['type'] == 'blob') $blobs[] = $col; |
568 | 568 | } |
569 | 569 | // check if we have an old PostgreSQL backup useing 't'/'f' for bool values |
570 | 570 | // --> convert them to MySQL and our new PostgreSQL format of 1/0 |
571 | 571 | $bools = array(); |
572 | - foreach($this->schemas[$table]['fd'] as $col => $def) |
|
572 | + foreach ($this->schemas[$table]['fd'] as $col => $def) |
|
573 | 573 | { |
574 | 574 | if ($def['type'] === 'bool') $bools[] = $col; |
575 | 575 | } |
@@ -582,15 +582,15 @@ discard block |
||
582 | 582 | $import = true; |
583 | 583 | $data = self::csv_split($line, $cols, $blobs, $bools); |
584 | 584 | |
585 | - if ($table == 'egw_async' && in_array('##last-check-run##',$data)) |
|
585 | + if ($table == 'egw_async' && in_array('##last-check-run##', $data)) |
|
586 | 586 | { |
587 | 587 | //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"; |
588 | 588 | //echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
589 | 589 | $import = false; |
590 | 590 | } |
591 | - if (in_array($table,$this->exclude_tables)) |
|
591 | + if (in_array($table, $this->exclude_tables)) |
|
592 | 592 | { |
593 | - echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.",$table)."</b></p>\n"; |
|
593 | + echo '<p><b>'.lang("Table %1 is excluded from backup and restore. Data will not be restored.", $table)."</b></p>\n"; |
|
594 | 594 | $import = false; // dont restore data of excluded tables |
595 | 595 | } |
596 | 596 | if ($import) |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | { |
600 | 600 | if ($convert_to_system_charset) |
601 | 601 | { |
602 | - $data = Api\Translation::convert($data,$charset); |
|
602 | + $data = Api\Translation::convert($data, $charset); |
|
603 | 603 | } |
604 | 604 | if ($insert_n_rows > 1) |
605 | 605 | { |
@@ -611,27 +611,27 @@ discard block |
||
611 | 611 | } |
612 | 612 | } |
613 | 613 | // update existing table using given unique key in $insert_n_rows (also removing auto-id/sequence) |
614 | - elseif(!is_numeric($insert_n_rows)) |
|
614 | + elseif (!is_numeric($insert_n_rows)) |
|
615 | 615 | { |
616 | 616 | $where = array($insert_n_rows => $data[$insert_n_rows]); |
617 | 617 | unset($data[$insert_n_rows]); |
618 | 618 | if ($auto_id) unset($data[$auto_id]); |
619 | - $this->db->insert($table,$data,$where,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
619 | + $this->db->insert($table, $data, $where, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
620 | 620 | } |
621 | 621 | else |
622 | 622 | { |
623 | 623 | try { |
624 | - $this->db->insert($table,$data,False,__LINE__,__FILE__,false,false,$this->schemas[$table]); |
|
624 | + $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $this->schemas[$table]); |
|
625 | 625 | } |
626 | - catch(Exception\InvalidSql $e) { |
|
626 | + catch (Exception\InvalidSql $e) { |
|
627 | 627 | echo "<p>".$e->getMessage()."</p>\n"; |
628 | 628 | } |
629 | 629 | } |
630 | 630 | } |
631 | 631 | else |
632 | 632 | { |
633 | - 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"; |
|
634 | - echo 'data=<pre>'.print_r($data,true)."</pre>\n"; |
|
633 | + 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"; |
|
634 | + echo 'data=<pre>'.print_r($data, true)."</pre>\n"; |
|
635 | 635 | } |
636 | 636 | } |
637 | 637 | } |
@@ -641,14 +641,14 @@ discard block |
||
641 | 641 | $this->insert_multiple($table, $rows, $this->schemas[$table]); |
642 | 642 | } |
643 | 643 | // updated the sequences, if the DB uses them |
644 | - foreach($this->schemas as $table => $schema) |
|
644 | + foreach ($this->schemas as $table => $schema) |
|
645 | 645 | { |
646 | - foreach($schema['fd'] as $column => $definition) |
|
646 | + foreach ($schema['fd'] as $column => $definition) |
|
647 | 647 | { |
648 | 648 | if ($definition['type'] == 'auto') |
649 | 649 | { |
650 | - $this->schema_proc->UpdateSequence($table,$column); |
|
651 | - break; // max. one per table |
|
650 | + $this->schema_proc->UpdateSequence($table, $column); |
|
651 | + break; // max. one per table |
|
652 | 652 | } |
653 | 653 | } |
654 | 654 | } |
@@ -671,15 +671,15 @@ discard block |
||
671 | 671 | try { |
672 | 672 | $this->db->insert($table, $rows, False, __LINE__, __FILE__, false, false, $schema); |
673 | 673 | } |
674 | - catch(Exception\InvalidSql $e) |
|
674 | + catch (Exception\InvalidSql $e) |
|
675 | 675 | { |
676 | 676 | // try inserting them one by one, ignoring doublicates |
677 | - foreach($rows as $data) |
|
677 | + foreach ($rows as $data) |
|
678 | 678 | { |
679 | 679 | try { |
680 | 680 | $this->db->insert($table, $data, False, __LINE__, __FILE__, false, false, $schema); |
681 | 681 | } |
682 | - catch(Exception\InvalidSql $e) { |
|
682 | + catch (Exception\InvalidSql $e) { |
|
683 | 683 | echo "<p>".$e->getMessage()."</p>\n"; |
684 | 684 | } |
685 | 685 | } |
@@ -694,11 +694,11 @@ discard block |
||
694 | 694 | private static function remove_dir_content($dir) |
695 | 695 | { |
696 | 696 | $list = scandir($dir); |
697 | - while($file = $list[0]) |
|
697 | + while ($file = $list[0]) |
|
698 | 698 | { |
699 | - if(is_dir($file) && $file != '.' && $file != '..') |
|
699 | + if (is_dir($file) && $file != '.' && $file != '..') |
|
700 | 700 | self::remove_dir_content($dir.'/'.$file); |
701 | - if(is_file($file) && $file != '.' && $file != '..') |
|
701 | + if (is_file($file) && $file != '.' && $file != '..') |
|
702 | 702 | unlink($dir.'/'.$file); |
703 | 703 | array_shift($list); |
704 | 704 | } |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | * @param array $bools =array() bool columns, values might be 't'/'f' for old PostgreSQL backups |
724 | 724 | * @return array |
725 | 725 | */ |
726 | - public static function csv_split($line, $keys=null, $blobs=array(), $bools=array()) |
|
726 | + public static function csv_split($line, $keys = null, $blobs = array(), $bools = array()) |
|
727 | 727 | { |
728 | 728 | if (function_exists('str_getcsv')) // php5.3+ |
729 | 729 | { |
@@ -736,9 +736,9 @@ discard block |
||
736 | 736 | '\\n' => "\n", |
737 | 737 | '\\r' => "\r")), ',', '"', '\0'); |
738 | 738 | // replace NULL-token again with 'NULL', 'NULL' with null and BACKSLASH-token with a backslash |
739 | - foreach($fields as &$field) |
|
739 | + foreach ($fields as &$field) |
|
740 | 740 | { |
741 | - switch($field) |
|
741 | + switch ($field) |
|
742 | 742 | { |
743 | 743 | case self::NULL_TOKEN: |
744 | 744 | $field = 'NULL'; |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | { |
756 | 756 | $fields = array_combine($keys, $fields); |
757 | 757 | // base64-decode blob columns, if they are base64 encoded |
758 | - foreach($blobs as $key) |
|
758 | + foreach ($blobs as $key) |
|
759 | 759 | { |
760 | 760 | if (!is_null($fields[$key]) && ($tmp = base64_decode($fields[$key], true)) !== false) |
761 | 761 | { |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | } |
764 | 764 | } |
765 | 765 | // decode bool columns, they might be 't'/'f' for old PostgreSQL backups |
766 | - foreach($bools as $key) |
|
766 | + foreach ($bools as $key) |
|
767 | 767 | { |
768 | 768 | $fields[$key] = Api\Db::from_bool($fields[$key]); |
769 | 769 | } |
@@ -771,11 +771,11 @@ discard block |
||
771 | 771 | return $fields; |
772 | 772 | } |
773 | 773 | // pre 5.3 implementation |
774 | - $fields = explode(',',trim($line)); |
|
774 | + $fields = explode(',', trim($line)); |
|
775 | 775 | |
776 | 776 | $str_pending = False; |
777 | 777 | $n = 0; |
778 | - foreach($fields as $field) |
|
778 | + foreach ($fields as $field) |
|
779 | 779 | { |
780 | 780 | if ($str_pending !== False) |
781 | 781 | { |
@@ -786,12 +786,12 @@ discard block |
||
786 | 786 | |
787 | 787 | if ($field[0] == '"') |
788 | 788 | { |
789 | - if (substr($field,-1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/',$field)) |
|
789 | + if (substr($field, -1) !== '"' || $field === '"' || !preg_match('/[^\\\\]+(\\\\\\\\)*"$/', $field)) |
|
790 | 790 | { |
791 | 791 | $str_pending = $field; |
792 | 792 | continue; |
793 | 793 | } |
794 | - $arr[$key] = str_replace(self::BACKSLASH_TOKEN,'\\',str_replace(array('\\\\','\\n','\\r','\\"'),array(self::BACKSLASH_TOKEN,"\n","\r",'"'),substr($field,1,-1))); |
|
794 | + $arr[$key] = str_replace(self::BACKSLASH_TOKEN, '\\', str_replace(array('\\\\', '\\n', '\\r', '\\"'), array(self::BACKSLASH_TOKEN, "\n", "\r", '"'), substr($field, 1, -1))); |
|
795 | 795 | } |
796 | 796 | elseif ($keys && strlen($field) > 26) |
797 | 797 | { |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | /** |
814 | 814 | * escape data for csv |
815 | 815 | */ |
816 | - public static function escape_data(&$data,$col,$defs) |
|
816 | + public static function escape_data(&$data, $col, $defs) |
|
817 | 817 | { |
818 | 818 | if (is_null($data)) |
819 | 819 | { |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | } |
822 | 822 | else |
823 | 823 | { |
824 | - switch($defs[$col]['type']) |
|
824 | + switch ($defs[$col]['type']) |
|
825 | 825 | { |
826 | 826 | case 'int': |
827 | 827 | case 'auto': |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | $data = (int)Api\Db::from_bool($data); |
837 | 837 | break; |
838 | 838 | default: |
839 | - $data = '"'.str_replace(array('\\',"\n","\r",'"'),array('\\\\','\\n','\\r','\\"'),$data).'"'; |
|
839 | + $data = '"'.str_replace(array('\\', "\n", "\r", '"'), array('\\\\', '\\n', '\\r', '\\"'), $data).'"'; |
|
840 | 840 | break; |
841 | 841 | } |
842 | 842 | } |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | * default of null limits memory usage if there is no primary key, by locking table and use ROW_CHUCK |
856 | 856 | * @todo use https://github.com/maennchen/ZipStream-PHP to not assemble all files in memmory |
857 | 857 | */ |
858 | - function backup($f, $lock_table=null) |
|
858 | + function backup($f, $lock_table = null) |
|
859 | 859 | { |
860 | 860 | //echo "function backup($f)<br>"; // ! |
861 | 861 | @set_time_limit(0); |
@@ -871,15 +871,15 @@ discard block |
||
871 | 871 | $name = $this->backup_dir.'/db_backup-'.date('YmdHi'); |
872 | 872 | $filename = $name.'.zip'; |
873 | 873 | $zippresent = false; |
874 | - if(class_exists('ZipArchive') && $this->backup_files) |
|
874 | + if (class_exists('ZipArchive') && $this->backup_files) |
|
875 | 875 | { |
876 | 876 | $zip = new ZipArchive; |
877 | - if(is_object($zip)) |
|
877 | + if (is_object($zip)) |
|
878 | 878 | { |
879 | 879 | $zippresent = true; |
880 | 880 | //echo '-> is_object($zip); '.$filename.'<br>'; // ! |
881 | 881 | $res = $zip->open($filename, ZipArchive::CREATE); |
882 | - if($res !== TRUE) |
|
882 | + if ($res !== TRUE) |
|
883 | 883 | { |
884 | 884 | //echo ' -> !$res<br>'; // ! |
885 | 885 | return lang("Cant open '%1' for %2", $filename, lang("writing"))."<br>\n"; |
@@ -887,22 +887,22 @@ discard block |
||
887 | 887 | $file_list = $this->get_file_list($dir); |
888 | 888 | } |
889 | 889 | } |
890 | - fwrite($f,"EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
890 | + fwrite($f, "EGroupware backup from ".date('Y-m-d H:i:s')."\n\n"); |
|
891 | 891 | |
892 | - fwrite($f,"version: $this->api_version\n\n"); |
|
892 | + fwrite($f, "version: $this->api_version\n\n"); |
|
893 | 893 | |
894 | - fwrite($f,"charset: $this->charset\n\n"); |
|
894 | + fwrite($f, "charset: $this->charset\n\n"); |
|
895 | 895 | |
896 | - $this->schema_backup($f); // add the schema in a human readable form too |
|
896 | + $this->schema_backup($f); // add the schema in a human readable form too |
|
897 | 897 | |
898 | - fwrite($f,"\nschema: ".json_encode($this->schemas)."\n"); |
|
898 | + fwrite($f, "\nschema: ".json_encode($this->schemas)."\n"); |
|
899 | 899 | |
900 | 900 | // let apps know that backup is about to start |
901 | 901 | Api\Hooks::process('backup_starts', array(), true); |
902 | 902 | |
903 | - foreach($this->schemas as $table => $schema) |
|
903 | + foreach ($this->schemas as $table => $schema) |
|
904 | 904 | { |
905 | - if (in_array($table,$this->exclude_tables)) continue; // dont backup |
|
905 | + if (in_array($table, $this->exclude_tables)) continue; // dont backup |
|
906 | 906 | |
907 | 907 | // do we have a primary key? |
908 | 908 | // --> use it to order and limit rows, to kope with rows being added during backup |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | do { |
919 | 919 | $num_rows = 0; |
920 | 920 | // querying only chunks for 10000 rows, to not run into memory limit on huge tables |
921 | - foreach($this->db->select($table, '*', |
|
921 | + foreach ($this->db->select($table, '*', |
|
922 | 922 | // limit by maximum primary key already received |
923 | 923 | empty($pk) || !$max ? false : $pk.' > '.$this->db->quote($max, $schema['fd'][$pk]['type']), |
924 | 924 | __LINE__, __FILE__, |
@@ -929,15 +929,15 @@ discard block |
||
929 | 929 | false, self::ROW_CHUNK) as $row) |
930 | 930 | { |
931 | 931 | if (!empty($pk)) $max = $row[$pk]; |
932 | - if ($total === 0) fwrite($f,"\ntable: $table\n".implode(',',array_keys($row))."\n"); |
|
932 | + if ($total === 0) fwrite($f, "\ntable: $table\n".implode(',', array_keys($row))."\n"); |
|
933 | 933 | |
934 | 934 | array_walk($row, array(__CLASS__, 'escape_data'), $schema['fd']); |
935 | - fwrite($f,implode(',',$row)."\n"); |
|
935 | + fwrite($f, implode(',', $row)."\n"); |
|
936 | 936 | ++$total; |
937 | 937 | ++$num_rows; |
938 | 938 | } |
939 | 939 | } |
940 | - while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
|
940 | + while ((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows); |
|
941 | 941 | |
942 | 942 | if (!$pk) $this->db->rollback_lock($table); |
943 | 943 | } |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | // let apps know that backup is finished |
946 | 946 | Api\Hooks::process('backup_finished', array(), true); |
947 | 947 | |
948 | - if(!$zippresent) // save without files |
|
948 | + if (!$zippresent) // save without files |
|
949 | 949 | { |
950 | 950 | if ($this->backup_files) |
951 | 951 | { |
@@ -960,16 +960,16 @@ discard block |
||
960 | 960 | //echo $name.'<br>'; |
961 | 961 | $zip->addFile($name, 'database_backup/'.basename($name)); |
962 | 962 | $count = 1; |
963 | - foreach($file_list as $file) |
|
963 | + foreach ($file_list as $file) |
|
964 | 964 | { |
965 | 965 | //echo substr($file,strlen($dir)+1).'<br>'; |
966 | 966 | //echo $file.'<br>'; |
967 | - $zip->addFile($file,substr($file,strlen($dir)+1));//,substr($file); |
|
968 | - if(($count++) == 100) { // the file descriptor limit |
|
967 | + $zip->addFile($file, substr($file, strlen($dir) + 1)); //,substr($file); |
|
968 | + if (($count++) == 100) { // the file descriptor limit |
|
969 | 969 | $zip->close(); |
970 | - if(($zip = new ZipArchive())) { |
|
970 | + if (($zip = new ZipArchive())) { |
|
971 | 971 | $zip->open($filename); |
972 | - $count =0; |
|
972 | + $count = 0; |
|
973 | 973 | } |
974 | 974 | } |
975 | 975 | } |
@@ -992,17 +992,17 @@ discard block |
||
992 | 992 | { |
993 | 993 | //chdir($f); |
994 | 994 | //echo "Processing $f <br>"; |
995 | - if ($path_name =='') $path_name = $f; |
|
995 | + if ($path_name == '') $path_name = $f; |
|
996 | 996 | $tlist = scandir($f); |
997 | 997 | $list = array(); |
998 | 998 | $i = $cnt; |
999 | - while($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
999 | + while ($file = $tlist[0]) // remove all '.' and '..' and transfer to $list |
|
1000 | 1000 | { |
1001 | - if($file == '.' || $file == '..') |
|
1001 | + if ($file == '.' || $file == '..') |
|
1002 | 1002 | { |
1003 | 1003 | array_shift($tlist); |
1004 | 1004 | } |
1005 | - elseif ($file == 'debug.txt' && stripos($f,'activesync')!==false) |
|
1005 | + elseif ($file == 'debug.txt' && stripos($f, 'activesync') !== false) |
|
1006 | 1006 | { |
1007 | 1007 | // skip activesync debug.txt on backupFiles |
1008 | 1008 | //error_log(__METHOD__.__LINE__.'->'.$f.'/'.$file); |
@@ -1010,7 +1010,7 @@ discard block |
||
1010 | 1010 | } |
1011 | 1011 | else |
1012 | 1012 | { |
1013 | - if(is_dir($f.'/'.$file)) |
|
1013 | + if (is_dir($f.'/'.$file)) |
|
1014 | 1014 | { |
1015 | 1015 | $nlist = $this->get_file_list($f.'/'.$file, $i); |
1016 | 1016 | $list += $nlist; |
@@ -1031,12 +1031,12 @@ discard block |
||
1031 | 1031 | * |
1032 | 1032 | * @param resource|boolean $f |
1033 | 1033 | */ |
1034 | - function schema_backup($f=False) |
|
1034 | + function schema_backup($f = False) |
|
1035 | 1035 | { |
1036 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
1036 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
1037 | 1037 | { |
1038 | - if ($this->system_tables && preg_match($this->system_tables,$table) || |
|
1039 | - $this->egw_tables && !preg_match($this->egw_tables,$table)) |
|
1038 | + if ($this->system_tables && preg_match($this->system_tables, $table) || |
|
1039 | + $this->egw_tables && !preg_match($this->egw_tables, $table)) |
|
1040 | 1040 | { |
1041 | 1041 | continue; |
1042 | 1042 | } |
@@ -1055,17 +1055,17 @@ discard block |
||
1055 | 1055 | } |
1056 | 1056 | } |
1057 | 1057 | $def = "\t\$phpgw_baseline = "; |
1058 | - $def .= self::write_array($this->schemas,1); |
|
1058 | + $def .= self::write_array($this->schemas, 1); |
|
1059 | 1059 | $def .= ";\n"; |
1060 | 1060 | |
1061 | 1061 | if ($f) |
1062 | 1062 | { |
1063 | - fwrite($f,$def); |
|
1063 | + fwrite($f, $def); |
|
1064 | 1064 | } |
1065 | 1065 | else |
1066 | 1066 | { |
1067 | 1067 | $def = "<?php\n\t/* EGroupware schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def; |
1068 | - Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def)); |
|
1068 | + Api\Header\Content::type('schema-backup-'.date('YmdHi').'.inc.php', 'text/plain', bytes($def)); |
|
1069 | 1069 | echo $def; |
1070 | 1070 | } |
1071 | 1071 | } |
@@ -1075,9 +1075,9 @@ discard block |
||
1075 | 1075 | * |
1076 | 1076 | * copied from etemplate/inc/class.db_tools.inc.php |
1077 | 1077 | */ |
1078 | - private static function write_array($arr,$depth,$parent='') |
|
1078 | + private static function write_array($arr, $depth, $parent = '') |
|
1079 | 1079 | { |
1080 | - if (in_array($parent,array('pk','fk','ix','uc'))) |
|
1080 | + if (in_array($parent, array('pk', 'fk', 'ix', 'uc'))) |
|
1081 | 1081 | { |
1082 | 1082 | $depth = 0; |
1083 | 1083 | } |
@@ -1093,7 +1093,7 @@ discard block |
||
1093 | 1093 | $def = "array($tabs".($tabs ? "\t" : ''); |
1094 | 1094 | |
1095 | 1095 | $n = 0; |
1096 | - foreach($arr as $key => $val) |
|
1096 | + foreach ($arr as $key => $val) |
|
1097 | 1097 | { |
1098 | 1098 | if (!is_int($key)) |
1099 | 1099 | { |
@@ -1101,7 +1101,7 @@ discard block |
||
1101 | 1101 | } |
1102 | 1102 | if (is_array($val)) |
1103 | 1103 | { |
1104 | - $def .= self::write_array($val,$parent == 'fd' ? 0 : $depth,$key); |
|
1104 | + $def .= self::write_array($val, $parent == 'fd' ? 0 : $depth, $key); |
|
1105 | 1105 | } |
1106 | 1106 | else |
1107 | 1107 | { |
@@ -1114,7 +1114,7 @@ discard block |
||
1114 | 1114 | $def .= "'$val'"; |
1115 | 1115 | } |
1116 | 1116 | } |
1117 | - if ($n < count($arr)-1) |
|
1117 | + if ($n < count($arr) - 1) |
|
1118 | 1118 | { |
1119 | 1119 | $def .= ",$tabs".($tabs ? "\t" : ''); |
1120 | 1120 | } |
@@ -94,10 +94,10 @@ |
||
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 | { |
@@ -99,13 +99,13 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -185,7 +185,7 @@ discard block |
||
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 |
||
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 | {} |
@@ -41,19 +41,19 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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)) |
@@ -54,7 +54,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -121,10 +121,13 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | +} |
@@ -96,7 +96,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -101,19 +101,19 @@ discard block |
||
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 |
||
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); |
@@ -797,7 +797,7 @@ |
||
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 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @var array |
58 | 58 | */ |
59 | - var $max_index_length=array( |
|
59 | + var $max_index_length = array( |
|
60 | 60 | 'maxdb' => 32, |
61 | 61 | 'oracle' => 30, |
62 | 62 | ); |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @param Db $db =null database class, if null we use $GLOBALS['egw']->db |
99 | 99 | * @return schema_proc |
100 | 100 | */ |
101 | - function __construct($dbms=False, Api\Db $db=null) |
|
101 | + function __construct($dbms = False, Api\Db $db = null) |
|
102 | 102 | { |
103 | - if(is_object($db)) |
|
103 | + if (is_object($db)) |
|
104 | 104 | { |
105 | 105 | $this->m_odb = $db; |
106 | 106 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | throw new Api\Exception\AssertionFailed('no EGroupware\Api\Db object!'); |
114 | 114 | } |
115 | 115 | $this->m_odb->connect(); |
116 | - $this->capabilities =& $this->m_odb->capabilities; |
|
116 | + $this->capabilities = & $this->m_odb->capabilities; |
|
117 | 117 | |
118 | 118 | $this->sType = $dbms ? $dbms : $this->m_odb->Type; |
119 | 119 | $this->adodb = &$this->m_odb->Link_ID; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | // to allow some of the former translator-functions to be called, we assign ourself as the translator |
126 | 126 | $this->m_oTranslator = &$this; |
127 | 127 | |
128 | - switch($this->sType) |
|
128 | + switch ($this->sType) |
|
129 | 129 | { |
130 | 130 | case 'maxdb': |
131 | 131 | $this->max_varchar_length = 8000; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | if (is_object($GLOBALS['egw_setup'])) |
143 | 143 | { |
144 | - $this->system_charset =& $GLOBALS['egw_setup']->system_charset; |
|
144 | + $this->system_charset = & $GLOBALS['egw_setup']->system_charset; |
|
145 | 145 | } |
146 | 146 | elseif (isset($GLOBALS['egw_info']['server']['system_charset'])) |
147 | 147 | { |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | * @param boolean $ignore_length_limit =false should we take lenght-limits of indexes into account or not |
158 | 158 | * @return boolean true if index over $columns exist in the $indexes array |
159 | 159 | */ |
160 | - function _in_index($columns, $indexs, $ignore_length_limit=false) |
|
160 | + function _in_index($columns, $indexs, $ignore_length_limit = false) |
|
161 | 161 | { |
162 | 162 | if (is_array($columns)) |
163 | 163 | { |
164 | 164 | unset($columns['options']); |
165 | - $columns = implode('-',$columns); |
|
165 | + $columns = implode('-', $columns); |
|
166 | 166 | if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns); |
167 | 167 | } |
168 | - foreach($indexs as $index) |
|
168 | + foreach ($indexs as $index) |
|
169 | 169 | { |
170 | 170 | if (is_array($index)) |
171 | 171 | { |
172 | 172 | unset($index['options']); |
173 | - $index = implode('-',$index); |
|
173 | + $index = implode('-', $index); |
|
174 | 174 | } |
175 | 175 | if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index); |
176 | 176 | if ($columns == $index) return true; |
@@ -186,21 +186,21 @@ discard block |
||
186 | 186 | * @param bool $preserveSequence |
187 | 187 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
188 | 188 | */ |
189 | - function CreateTable($sTableName, $aTableDef, $preserveSequence=False) |
|
189 | + function CreateTable($sTableName, $aTableDef, $preserveSequence = False) |
|
190 | 190 | { |
191 | 191 | if ($this->debug) |
192 | 192 | { |
193 | - $this->debug_message('schema_proc::CreateTable(%1,%2)',False,$sTableName, $aTableDef); |
|
193 | + $this->debug_message('schema_proc::CreateTable(%1,%2)', False, $sTableName, $aTableDef); |
|
194 | 194 | } |
195 | 195 | // for mysql 4.0+ we set the charset for the table |
196 | - if ($this->system_charset && substr($this->sType,0,5) == 'mysql' && |
|
197 | - (float) $this->m_odb->ServerInfo['version'] >= 4.0) |
|
196 | + if ($this->system_charset && substr($this->sType, 0, 5) == 'mysql' && |
|
197 | + (float)$this->m_odb->ServerInfo['version'] >= 4.0) |
|
198 | 198 | { |
199 | 199 | $set_table_charset = array($this->sType => 'CHARACTER SET utf8'); |
200 | 200 | } |
201 | 201 | // creating the table |
202 | - $aSql = $this->dict->CreateTableSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef($aTableDef),$set_table_charset); |
|
203 | - if (!($retVal = $this->ExecuteSQLArray($aSql,2,'CreateTableSQL(%1,%2) sql=%3',False,$sTableName,$ado_cols,$aSql))) |
|
202 | + $aSql = $this->dict->CreateTableSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef($aTableDef), $set_table_charset); |
|
203 | + if (!($retVal = $this->ExecuteSQLArray($aSql, 2, 'CreateTableSQL(%1,%2) sql=%3', False, $sTableName, $ado_cols, $aSql))) |
|
204 | 204 | { |
205 | 205 | return $retVal; |
206 | 206 | } |
@@ -209,13 +209,13 @@ discard block |
||
209 | 209 | { |
210 | 210 | if (empty($mFields)) |
211 | 211 | { |
212 | - continue; // cant create an index without fields (was observed in broken backups) |
|
212 | + continue; // cant create an index without fields (was observed in broken backups) |
|
213 | 213 | } |
214 | - if ($this->_in_index($mFields,array($aTableDef['pk']))) |
|
214 | + if ($this->_in_index($mFields, array($aTableDef['pk']))) |
|
215 | 215 | { |
216 | - continue; // is already created as primary key |
|
216 | + continue; // is already created as primary key |
|
217 | 217 | } |
218 | - if (!($retVal = $this->CreateIndex($sTableName,$mFields,true,'',$name))) |
|
218 | + if (!($retVal = $this->CreateIndex($sTableName, $mFields, true, '', $name))) |
|
219 | 219 | { |
220 | 220 | return $retVal; |
221 | 221 | } |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | { |
226 | 226 | if (empty($mFields)) |
227 | 227 | { |
228 | - continue; // cant create an index without fields (was observed in broken backups) |
|
228 | + continue; // cant create an index without fields (was observed in broken backups) |
|
229 | 229 | } |
230 | - if ($this->_in_index($mFields,array($aTableDef['pk'])) || |
|
231 | - $this->_in_index($mFields,$aTableDef['uc'])) |
|
230 | + if ($this->_in_index($mFields, array($aTableDef['pk'])) || |
|
231 | + $this->_in_index($mFields, $aTableDef['uc'])) |
|
232 | 232 | { |
233 | - continue; // is already created as primary key or unique index |
|
233 | + continue; // is already created as primary key or unique index |
|
234 | 234 | } |
235 | 235 | $options = False; |
236 | 236 | if (is_array($mFields)) |
@@ -239,21 +239,21 @@ discard block |
||
239 | 239 | { |
240 | 240 | if (isset($mFields['options'][$this->sType])) |
241 | 241 | { |
242 | - $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
243 | - if (!$options) continue; // no index for our db-type |
|
242 | + $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
243 | + if (!$options) continue; // no index for our db-type |
|
244 | 244 | } |
245 | 245 | unset($mFields['options']); |
246 | 246 | } |
247 | 247 | } |
248 | - foreach((array)$mFields as $k => $col) |
|
248 | + foreach ((array)$mFields as $k => $col) |
|
249 | 249 | { |
250 | 250 | // only create indexes on text-columns, if (db-)specifiy options are given or FULLTEXT for mysql |
251 | 251 | // most DB's cant do them and give errors |
252 | - if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext'))) |
|
252 | + if (in_array($aTableDef['fd'][$col]['type'], array('text', 'longtext'))) |
|
253 | 253 | { |
254 | 254 | if (is_array($mFields)) // index over multiple columns including a text column |
255 | 255 | { |
256 | - $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
256 | + $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
257 | 257 | } |
258 | 258 | elseif (!$options) // index over a single text column and no options given |
259 | 259 | { |
@@ -263,12 +263,12 @@ discard block |
||
263 | 263 | } |
264 | 264 | else |
265 | 265 | { |
266 | - continue 2; // ignore that index, 2=not just column but whole index! |
|
266 | + continue 2; // ignore that index, 2=not just column but whole index! |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | } |
270 | 270 | } |
271 | - if (!($retVal = $this->CreateIndex($sTableName,$mFields,false,$options,$name))) |
|
271 | + if (!($retVal = $this->CreateIndex($sTableName, $mFields, false, $options, $name))) |
|
272 | 272 | { |
273 | 273 | return $retVal; |
274 | 274 | } |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | if (($seq = $this->_PostgresHasOldSequence($sTableName))) |
280 | 280 | { |
281 | 281 | $this->pgsql_old_seq = $this->pgsql_old_seq + 1; |
282 | - $this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH " . $this->pgsql_old_seq,__LINE__,__FILE__); |
|
282 | + $this->m_odb->query("ALTER SEQUENCE $seq RESTART WITH ".$this->pgsql_old_seq, __LINE__, __FILE__); |
|
283 | 283 | } |
284 | 284 | $this->pgsql_old_seq = 0; |
285 | 285 | } |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | * @param boolean $bOutputHTML should we give diagnostics, default False |
294 | 294 | * @return boolean True if no error, else False |
295 | 295 | */ |
296 | - function DropAllTables($aTables, $bOutputHTML=False) |
|
296 | + function DropAllTables($aTables, $bOutputHTML = False) |
|
297 | 297 | { |
298 | - if(!is_array($aTables) || !isset($this->m_odb)) |
|
298 | + if (!is_array($aTables) || !isset($this->m_odb)) |
|
299 | 299 | { |
300 | 300 | return False; |
301 | 301 | } |
@@ -303,13 +303,13 @@ discard block |
||
303 | 303 | if ($this->debug) $bOutputHTML = True; |
304 | 304 | if ($bOutputHTML && !$this->debug) $this->debug = 2; |
305 | 305 | |
306 | - foreach(array_keys($aTables) as $sTableName) |
|
306 | + foreach (array_keys($aTables) as $sTableName) |
|
307 | 307 | { |
308 | - if($this->DropTable($sTableName)) |
|
308 | + if ($this->DropTable($sTableName)) |
|
309 | 309 | { |
310 | - if($bOutputHTML) |
|
310 | + if ($bOutputHTML) |
|
311 | 311 | { |
312 | - echo '<br>Drop Table <b>' . $sTableName . '</b>'; |
|
312 | + echo '<br>Drop Table <b>'.$sTableName.'</b>'; |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | else |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | |
333 | 333 | $aSql = $this->dict->DropTableSql($sTableName); |
334 | 334 | |
335 | - return $this->ExecuteSQLArray($aSql,2,'DropTable(%1) sql=%2',False,$sTableName,$aSql); |
|
335 | + return $this->ExecuteSQLArray($aSql, 2, 'DropTable(%1) sql=%2', False, $sTableName, $aSql); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -345,14 +345,14 @@ discard block |
||
345 | 345 | */ |
346 | 346 | function DropColumn($sTableName, $aTableDef, $sColumnName) |
347 | 347 | { |
348 | - unset($aTableDef); // not used, but required by function signature |
|
348 | + unset($aTableDef); // not used, but required by function signature |
|
349 | 349 | |
350 | 350 | if (!($table_def = $this->GetTableDefinition($sTableName))) return 0; |
351 | 351 | unset($table_def['fd'][$sColumnName]); |
352 | 352 | |
353 | - $aSql = $this->dict->DropColumnSql($sTableName,$sColumnName,$ado_table=$this->_egw2adodb_columndef($table_def)); |
|
353 | + $aSql = $this->dict->DropColumnSql($sTableName, $sColumnName, $ado_table = $this->_egw2adodb_columndef($table_def)); |
|
354 | 354 | |
355 | - return $this->ExecuteSQLArray($aSql,2,'DropColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName,$ado_table,$aSql); |
|
355 | + return $this->ExecuteSQLArray($aSql, 2, 'DropColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $ado_table, $aSql); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -371,12 +371,12 @@ discard block |
||
371 | 371 | if (!($table_def = $this->GetTableDefinition($sOldTableName))) return 0; |
372 | 372 | |
373 | 373 | // only use old PostgreSQL stuff, if we have an old sequence, otherwise rely on it being new enough |
374 | - if ($this->_PostgresHasOldSequence($sOldTableName,True) && |
|
374 | + if ($this->_PostgresHasOldSequence($sOldTableName, True) && |
|
375 | 375 | (count($table_def['pk']) || 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 | // sequence must be updated, after inserts containing pkey, otherwise new inserst will fail! |
381 | 381 | (count($table_def['pk']) !== 1 || $this->UpdateSequence($sNewTableName, $table_def['pk'][0])) && |
382 | 382 | $this->DropTable($sOldTableName)) |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | } |
391 | 391 | $aSql = $this->dict->RenameTableSQL($sOldTableName, $sNewTableName); |
392 | 392 | |
393 | - return $this->ExecuteSQLArray($aSql,2,'RenameTableSQL(%1,%2) sql=%3',False,$sOldTableName,$sNewTableName,$aSql); |
|
393 | + return $this->ExecuteSQLArray($aSql, 2, 'RenameTableSQL(%1,%2) sql=%3', False, $sOldTableName, $sNewTableName, $aSql); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @param bool $preserveValue |
401 | 401 | * @return boolean|string sequence-name or false |
402 | 402 | */ |
403 | - function _PostgresHasOldSequence($sTableName,$preserveValue=False) |
|
403 | + function _PostgresHasOldSequence($sTableName, $preserveValue = False) |
|
404 | 404 | { |
405 | 405 | if ($this->sType != 'pgsql') return false; |
406 | 406 | |
@@ -408,14 +408,14 @@ discard block |
||
408 | 408 | $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"); |
409 | 409 | |
410 | 410 | $matches = null; |
411 | - if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches)) |
|
411 | + if ($seq && preg_match('/^nextval\(\'(.*)\'/', $seq, $matches)) |
|
412 | 412 | { |
413 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
413 | + if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]); |
|
414 | 414 | return $matches[1]; |
415 | 415 | } |
416 | - if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches)) |
|
416 | + if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/', $seq2, $matches)) |
|
417 | 417 | { |
418 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
418 | + if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM ".$matches[1]); |
|
419 | 419 | return $matches[1]; |
420 | 420 | } |
421 | 421 | return false; |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | // only drop sequence, if there is no dependency on it |
435 | 435 | 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'")) |
436 | 436 | { |
437 | - $this->query('DROP SEQUENCE '.$seq,__LINE__,__FILE__); |
|
437 | + $this->query('DROP SEQUENCE '.$seq, __LINE__, __FILE__); |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | } |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | if (!($table_def = $this->GetTableDefinition($sTableName))) return 0; |
453 | 453 | |
454 | 454 | // PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long |
455 | - if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) && |
|
455 | + if ($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) && |
|
456 | 456 | in_array($aColumnDef['type'], array('varchar', 'ascii')) && |
457 | 457 | $table_def['fd'][$sColumnName]['precision'] > $aColumnDef['precision']) |
458 | 458 | { |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | } |
468 | 468 | $table_def['fd'][$sColumnName] = $aColumnDef; |
469 | 469 | |
470 | - $aSql = $this->dict->AlterColumnSQL($sTableName,$ado_col = $this->_egw2adodb_columndef(array( |
|
470 | + $aSql = $this->dict->AlterColumnSQL($sTableName, $ado_col = $this->_egw2adodb_columndef(array( |
|
471 | 471 | 'fd' => array($sColumnName => $aColumnDef), |
472 | 472 | 'pk' => array(), |
473 | - )),$ado_table=$this->_egw2adodb_columndef($table_def)); |
|
473 | + )), $ado_table = $this->_egw2adodb_columndef($table_def)); |
|
474 | 474 | |
475 | - return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$ado_col,$ado_table,$aSql); |
|
475 | + return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $ado_col, $ado_table, $aSql); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | } |
495 | 495 | else |
496 | 496 | { |
497 | - foreach($table_def['fd'] as $col => $def) |
|
497 | + foreach ($table_def['fd'] as $col => $def) |
|
498 | 498 | { |
499 | 499 | if (strtolower($col) == strtolower($sOldColumnName)) |
500 | 500 | { |
@@ -508,9 +508,9 @@ discard block |
||
508 | 508 | 'pk' => array(), |
509 | 509 | )); |
510 | 510 | |
511 | - $aSql = $this->dict->RenameColumnSQL($sTableName,$sOldColumnName,$sNewColumnName,$col_def); |
|
511 | + $aSql = $this->dict->RenameColumnSQL($sTableName, $sOldColumnName, $sNewColumnName, $col_def); |
|
512 | 512 | |
513 | - return $this->ExecuteSQLArray($aSql,2,'RenameColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sOldColumnName, $sNewColumnName,$aSql); |
|
513 | + return $this->ExecuteSQLArray($aSql, 2, 'RenameColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sOldColumnName, $sNewColumnName, $aSql); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -523,12 +523,12 @@ discard block |
||
523 | 523 | */ |
524 | 524 | function AddColumn($sTableName, $sColumnName, $aColumnDef) |
525 | 525 | { |
526 | - $aSql = $this->dict->AddColumnSQL($sTableName,$ado_cols = $this->_egw2adodb_columndef(array( |
|
526 | + $aSql = $this->dict->AddColumnSQL($sTableName, $ado_cols = $this->_egw2adodb_columndef(array( |
|
527 | 527 | 'fd' => array($sColumnName => $aColumnDef), |
528 | 528 | 'pk' => array(), |
529 | 529 | ))); |
530 | 530 | |
531 | - return $this->ExecuteSQLArray($aSql,2,'AlterColumnSQL(%1,%2,%3) sql=%4',False,$sTableName,$sColumnName, $aColumnDef,$aSql); |
|
531 | + return $this->ExecuteSQLArray($aSql, 2, 'AlterColumnSQL(%1,%2,%3) sql=%4', False, $sTableName, $sColumnName, $aColumnDef, $aSql); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
@@ -541,16 +541,16 @@ discard block |
||
541 | 541 | * @param string $sIdxName ='' name of the index, if not given (default) its created automaticaly |
542 | 542 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
543 | 543 | */ |
544 | - function CreateIndex($sTableName,$aColumnNames,$bUnique=false,$options='',$sIdxName='') |
|
544 | + function CreateIndex($sTableName, $aColumnNames, $bUnique = false, $options = '', $sIdxName = '') |
|
545 | 545 | { |
546 | 546 | // remove length limits from column names, if DB type is NOT MySQL |
547 | 547 | if ($this->sType != 'mysql') |
548 | 548 | { |
549 | - $aColumnNames = preg_replace('/ *\(\d+\)$/','',$aColumnNames); |
|
549 | + $aColumnNames = preg_replace('/ *\(\d+\)$/', '', $aColumnNames); |
|
550 | 550 | } |
551 | 551 | if (!$sIdxName || is_numeric($sIdxName)) |
552 | 552 | { |
553 | - $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
|
553 | + $sIdxName = $this->_index_name($sTableName, $aColumnNames); |
|
554 | 554 | } |
555 | 555 | if (!is_array($options)) $options = $options ? array($options) : array(); |
556 | 556 | if ($bUnique) $options[] = 'UNIQUE'; |
@@ -567,9 +567,9 @@ discard block |
||
567 | 567 | $this->DropIndex($sTableName, (array)$aColumnNames); |
568 | 568 | } |
569 | 569 | |
570 | - $aSql = $this->dict->CreateIndexSQL($sIdxName,$sTableName,$aColumnNames,$options); |
|
570 | + $aSql = $this->dict->CreateIndexSQL($sIdxName, $sTableName, $aColumnNames, $options); |
|
571 | 571 | |
572 | - return $this->ExecuteSQLArray($aSql,2,'CreateIndexSQL(%1,%2,%3,%4) sql=%5',False,$sTableName,$aColumnNames,$options,$sIdxName,$aSql); |
|
572 | + return $this->ExecuteSQLArray($aSql, 2, 'CreateIndexSQL(%1,%2,%3,%4) sql=%5', False, $sTableName, $aColumnNames, $options, $sIdxName, $aSql); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * @param array|string $aColumnNames columns of the index or the name of the index |
580 | 580 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
581 | 581 | */ |
582 | - function DropIndex($sTableName,$aColumnNames) |
|
582 | + function DropIndex($sTableName, $aColumnNames) |
|
583 | 583 | { |
584 | 584 | if (is_array($aColumnNames)) |
585 | 585 | { |
@@ -589,13 +589,13 @@ discard block |
||
589 | 589 | { |
590 | 590 | // if MetaIndexes is not availible for the DB, we try the name the index was created with |
591 | 591 | // this fails if one of the columns have been renamed |
592 | - $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
|
592 | + $sIdxName = $this->_index_name($sTableName, $aColumnNames); |
|
593 | 593 | } |
594 | 594 | else |
595 | 595 | { |
596 | - foreach($indexes as $idx => $idx_data) |
|
596 | + foreach ($indexes as $idx => $idx_data) |
|
597 | 597 | { |
598 | - if (strtolower(implode(':',$idx_data['columns'])) == implode(':',$aColumnNames)) |
|
598 | + if (strtolower(implode(':', $idx_data['columns'])) == implode(':', $aColumnNames)) |
|
599 | 599 | { |
600 | 600 | $sIdxName = $idx; |
601 | 601 | break; |
@@ -607,13 +607,13 @@ discard block |
||
607 | 607 | { |
608 | 608 | $sIdxName = $aColumnNames; |
609 | 609 | } |
610 | - if(!$sIdxName) |
|
610 | + if (!$sIdxName) |
|
611 | 611 | { |
612 | 612 | return True; |
613 | 613 | } |
614 | - $aSql = $this->dict->DropIndexSQL($sIdxName,$sTableName); |
|
614 | + $aSql = $this->dict->DropIndexSQL($sIdxName, $sTableName); |
|
615 | 615 | |
616 | - return $this->ExecuteSQLArray($aSql,2,'DropIndexSQL(%1(%2),%3) sql=%4',False,$sIdxName,$aColumnNames,$sTableName,$aSql); |
|
616 | + return $this->ExecuteSQLArray($aSql, 2, 'DropIndexSQL(%1(%2),%3) sql=%4', False, $sIdxName, $aColumnNames, $sTableName, $aSql); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -621,22 +621,22 @@ discard block |
||
621 | 621 | * @param string $sTableName table-name |
622 | 622 | * @param string $sColumnName column-name, which default is set to nextval() |
623 | 623 | */ |
624 | - function UpdateSequence($sTableName,$sColumnName) |
|
624 | + function UpdateSequence($sTableName, $sColumnName) |
|
625 | 625 | { |
626 | - switch($this->sType) |
|
626 | + switch ($this->sType) |
|
627 | 627 | { |
628 | 628 | case 'pgsql': |
629 | 629 | // identify the sequence name, ADOdb uses a different name or it might be renamed |
630 | 630 | $columns = $this->dict->MetaColumns($sTableName); |
631 | 631 | $seq_name = 'seq_'.$sTableName; |
632 | 632 | $matches = null; |
633 | - if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$columns[strtoupper($sColumnName)]->default_value,$matches)) |
|
633 | + if (preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $columns[strtoupper($sColumnName)]->default_value, $matches)) |
|
634 | 634 | { |
635 | 635 | $seq_name = $matches[1]; |
636 | 636 | } |
637 | 637 | $sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName"; |
638 | - if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
639 | - return $this->query($sql,__LINE__,__FILE__); |
|
638 | + if ($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
639 | + return $this->query($sql, __LINE__, __FILE__); |
|
640 | 640 | } |
641 | 641 | return True; |
642 | 642 | } |
@@ -653,9 +653,9 @@ discard block |
||
653 | 653 | * @param array $aTableDef eGW table-defintion |
654 | 654 | * @param array|boolean $aDefaults array with default for the colums during copying, values are either (old) column-names or quoted string-literals |
655 | 655 | */ |
656 | - function RefreshTable($sTableName, $aTableDef, $aDefaults=False) |
|
656 | + function RefreshTable($sTableName, $aTableDef, $aDefaults = False) |
|
657 | 657 | { |
658 | - if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
658 | + if ($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef, False).")\n"; } |
|
659 | 659 | |
660 | 660 | $old_table_def = $this->GetTableDefinition($sTableName); |
661 | 661 | |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | |
665 | 665 | $select = array(); |
666 | 666 | $blob_column_included = $auto_column_included = False; |
667 | - foreach($aTableDef['fd'] as $name => $data) |
|
667 | + foreach ($aTableDef['fd'] as $name => $data) |
|
668 | 668 | { |
669 | 669 | // new auto column with no default or explicit NULL as default (can be an existing column too!) |
670 | 670 | if ($data['type'] == 'auto' && |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | $aDefaults && strtoupper($aDefaults[$name]) == 'NULL')) |
673 | 673 | { |
674 | 674 | $sequence_name = $sTableName.'_'.$name.'_seq'; |
675 | - switch($GLOBALS['egw_setup']->db->Type) |
|
675 | + switch ($GLOBALS['egw_setup']->db->Type) |
|
676 | 676 | { |
677 | 677 | case 'mysql': |
678 | 678 | $value = 'NULL'; break; |
@@ -693,25 +693,25 @@ discard block |
||
693 | 693 | if ($this->sType == 'pgsql') // some postgres specific code |
694 | 694 | { |
695 | 695 | // this is eg. necessary to change a varchar into an int column under postgres |
696 | - if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) && |
|
697 | - in_array($data['type'],array('int','decimal'))) |
|
696 | + if (in_array($old_table_def['fd'][$name]['type'], array('char', 'varchar', 'text', 'blob')) && |
|
697 | + in_array($data['type'], array('int', 'decimal'))) |
|
698 | 698 | { |
699 | 699 | $value = "to_number($name,'S9999999999999D99')"; |
700 | 700 | } |
701 | 701 | // blobs cant be casted to text |
702 | - elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
|
702 | + elseif ($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
|
703 | 703 | { |
704 | 704 | $value = "ENCODE($value,'escape')"; |
705 | 705 | } |
706 | 706 | // varchar or ascii column shortened, use substring to avoid error if current content is to long |
707 | - elseif(in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) && |
|
707 | + elseif (in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) && |
|
708 | 708 | in_array($data['type'], array('varchar', 'ascii')) && |
709 | 709 | $old_table_def['fd'][$name]['precision'] > $data['precision']) |
710 | 710 | { |
711 | 711 | $value = "SUBSTRING($value FROM 1 FOR ".(int)$data['precision'].')'; |
712 | 712 | } |
713 | 713 | // cast everything which is a different type |
714 | - elseif($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type']))) |
|
714 | + elseif ($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type']))) |
|
715 | 715 | { |
716 | 716 | $value = "CAST($value AS $type_translated)"; |
717 | 717 | } |
@@ -724,42 +724,42 @@ discard block |
||
724 | 724 | $value = 'NULL'; |
725 | 725 | } |
726 | 726 | // some stuff is NOT to be quoted |
727 | - elseif (in_array(strtoupper($data['default']),array('CURRENT_TIMESTAMP','CURRENT_DATE','NULL','NOW()'))) |
|
727 | + elseif (in_array(strtoupper($data['default']), array('CURRENT_TIMESTAMP', 'CURRENT_DATE', 'NULL', 'NOW()'))) |
|
728 | 728 | { |
729 | 729 | $value = $data['default']; |
730 | 730 | } |
731 | 731 | else |
732 | 732 | { |
733 | - $value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '',$data['type']); |
|
733 | + $value = $this->m_odb->quote(isset($data['default']) ? $data['default'] : '', $data['type']); |
|
734 | 734 | } |
735 | 735 | if ($this->sType == 'pgsql') |
736 | 736 | { |
737 | 737 | // fix for postgres error "no '<' operator for type 'unknown'" |
738 | - if(($type_translated = $this->TranslateType($data['type']))) |
|
738 | + if (($type_translated = $this->TranslateType($data['type']))) |
|
739 | 739 | { |
740 | 740 | $value = "CAST($value AS $type_translated)"; |
741 | 741 | } |
742 | 742 | } |
743 | 743 | } |
744 | - $blob_column_included = $blob_column_included || in_array($data['type'],array('blob','text','longtext')); |
|
744 | + $blob_column_included = $blob_column_included || in_array($data['type'], array('blob', 'text', 'longtext')); |
|
745 | 745 | $auto_column_included = $auto_column_included || $data['type'] == 'auto'; |
746 | 746 | $select[] = $value; |
747 | 747 | } |
748 | 748 | |
749 | 749 | $extra = ''; |
750 | 750 | $distinct = 'DISTINCT'; |
751 | - switch($this->sType) |
|
751 | + switch ($this->sType) |
|
752 | 752 | { |
753 | 753 | case 'mssql': |
754 | 754 | if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
755 | - if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
755 | + if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
756 | 756 | break; |
757 | 757 | } |
758 | 758 | // because of all the trouble with sequences and indexes in the global namespace, |
759 | 759 | // we use an additional temp. table for postgres and not rename the existing one, but drop it. |
760 | 760 | if ($this->sType == 'pgsql') |
761 | 761 | { |
762 | - $Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName",__LINE__,__FILE__) && |
|
762 | + $Ok = $this->m_odb->query("SELEcT * INTO TEMPORARY TABLE $tmp_name FROM $sTableName", __LINE__, __FILE__) && |
|
763 | 763 | $this->DropTable($sTableName); |
764 | 764 | } |
765 | 765 | else |
@@ -769,12 +769,12 @@ discard block |
||
769 | 769 | { |
770 | 770 | $this->DropTable($tmp_name); |
771 | 771 | } |
772 | - $Ok = $this->RenameTable($sTableName,$tmp_name); |
|
772 | + $Ok = $this->RenameTable($sTableName, $tmp_name); |
|
773 | 773 | } |
774 | - $Ok = $Ok && $this->CreateTable($sTableName,$aTableDef) && |
|
775 | - $this->m_odb->query($sql_copy_data="$extra INSERT INTO $sTableName (". |
|
776 | - implode(',',array_keys($aTableDef['fd'])). |
|
777 | - ") SELEcT $distinct ".implode(',',$select)." FROM $tmp_name",__LINE__,__FILE__) && |
|
774 | + $Ok = $Ok && $this->CreateTable($sTableName, $aTableDef) && |
|
775 | + $this->m_odb->query($sql_copy_data = "$extra INSERT INTO $sTableName (". |
|
776 | + implode(',', array_keys($aTableDef['fd'])). |
|
777 | + ") SELEcT $distinct ".implode(',', $select)." FROM $tmp_name", __LINE__, __FILE__) && |
|
778 | 778 | $this->DropTable($tmp_name); |
779 | 779 | //error_log($sql_copy_data); |
780 | 780 | |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | // do we need to update the new sequences value ? |
787 | 787 | if (count($aTableDef['pk']) == 1 && $aTableDef['fd'][$aTableDef['pk'][0]]['type'] == 'auto') |
788 | 788 | { |
789 | - $this->UpdateSequence($sTableName,$aTableDef['pk'][0]); |
|
789 | + $this->UpdateSequence($sTableName, $aTableDef['pk'][0]); |
|
790 | 790 | } |
791 | 791 | $this->m_odb->transaction_commit(); |
792 | 792 | |
@@ -809,9 +809,9 @@ discard block |
||
809 | 809 | * @param boolean $bOutputHTML =false should we give diagnostics, default False |
810 | 810 | * @return boolean True on success, False if an (fatal) error occured |
811 | 811 | */ |
812 | - function ExecuteScripts($aTables, $bOutputHTML=False) |
|
812 | + function ExecuteScripts($aTables, $bOutputHTML = False) |
|
813 | 813 | { |
814 | - if(!is_array($aTables) || !IsSet($this->m_odb)) |
|
814 | + if (!is_array($aTables) || !IsSet($this->m_odb)) |
|
815 | 815 | { |
816 | 816 | return False; |
817 | 817 | } |
@@ -819,20 +819,20 @@ discard block |
||
819 | 819 | if ($this->debug) $bOutputHTML = True; |
820 | 820 | if ($bOutputHTML && !$this->debug) $this->debug = 2; |
821 | 821 | |
822 | - foreach($aTables as $sTableName => $aTableDef) |
|
822 | + foreach ($aTables as $sTableName => $aTableDef) |
|
823 | 823 | { |
824 | - if($this->CreateTable($sTableName, $aTableDef)) |
|
824 | + if ($this->CreateTable($sTableName, $aTableDef)) |
|
825 | 825 | { |
826 | - if($bOutputHTML) |
|
826 | + if ($bOutputHTML) |
|
827 | 827 | { |
828 | - echo '<br>Create Table <b>' . $sTableName . '</b>'; |
|
828 | + echo '<br>Create Table <b>'.$sTableName.'</b>'; |
|
829 | 829 | } |
830 | 830 | } |
831 | 831 | else |
832 | 832 | { |
833 | - if($bOutputHTML) |
|
833 | + if ($bOutputHTML) |
|
834 | 834 | { |
835 | - echo '<br>Create Table Failed For <b>' . $sTableName . '</b>'; |
|
835 | + echo '<br>Create Table Failed For <b>'.$sTableName.'</b>'; |
|
836 | 836 | } |
837 | 837 | |
838 | 838 | return False; |
@@ -849,13 +849,13 @@ discard block |
||
849 | 849 | * @deprecated use result-set returned by query/select |
850 | 850 | * @return string the field value |
851 | 851 | */ |
852 | - function f($value,$strip_slashes=False) |
|
852 | + function f($value, $strip_slashes = False) |
|
853 | 853 | { |
854 | 854 | if (!($this->m_odb instanceof Deprecated)) |
855 | 855 | { |
856 | 856 | throw new Api\Exception\AssertionFailed(__METHOD__.' requires an EGroupware\Api\Db\Deprecated object!'); |
857 | 857 | } |
858 | - return $this->m_odb->f($value,$strip_slashes); |
|
858 | + return $this->m_odb->f($value, $strip_slashes); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | /** |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | * @param int $num_rows number of rows to return (optional), if unset will use $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] |
899 | 899 | * @return ADORecordSet or false, if the query fails |
900 | 900 | */ |
901 | - function query($sQuery, $line='', $file='') |
|
901 | + function query($sQuery, $line = '', $file = '') |
|
902 | 902 | { |
903 | 903 | return $this->m_odb->query($sQuery, $line, $file); |
904 | 904 | } |
@@ -915,9 +915,9 @@ discard block |
||
915 | 915 | * @param string $app=false string with name of app, this need to be set in setup anyway!!! |
916 | 916 | * @return ADORecordSet or false, if the query fails |
917 | 917 | */ |
918 | - function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false) |
|
918 | + function insert($table, $data, $where, $line, $file, $app = False, $use_prepared_statement = false) |
|
919 | 919 | { |
920 | - return $this->m_odb->insert($table,$data,$where,$line,$file,$app,$use_prepared_statement); |
|
920 | + return $this->m_odb->insert($table, $data, $where, $line, $file, $app, $use_prepared_statement); |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | /** |
@@ -928,14 +928,14 @@ discard block |
||
928 | 928 | * @param string $debug variable number of arguments for the debug_message functions in case of an error |
929 | 929 | * @return int 2: no error, 1: errors, but continued, 0: errors aborted |
930 | 930 | */ |
931 | - function ExecuteSqlArray($aSql,$debug_level) |
|
931 | + function ExecuteSqlArray($aSql, $debug_level) |
|
932 | 932 | { |
933 | 933 | if ($this->m_odb->query_log) // we use Db::query to log the queries |
934 | 934 | { |
935 | 935 | $retval = 2; |
936 | - foreach($aSql as $sql) |
|
936 | + foreach ($aSql as $sql) |
|
937 | 937 | { |
938 | - if (!$this->m_odb->query($sql,__LINE__,__FILE__)) |
|
938 | + if (!$this->m_odb->query($sql, __LINE__, __FILE__)) |
|
939 | 939 | { |
940 | 940 | $retval = 1; |
941 | 941 | } |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | $debug_params = func_get_args(); |
951 | 951 | array_shift($debug_params); |
952 | 952 | array_shift($debug_params); |
953 | - call_user_func_array(array($this,'debug_message'),$debug_params); |
|
953 | + call_user_func_array(array($this, 'debug_message'), $debug_params); |
|
954 | 954 | if ($retval < 2 && !$this->dict->debug) |
955 | 955 | { |
956 | 956 | echo '<p><b>'.$this->adodb->ErrorMsg()."</b></p>\n"; |
@@ -971,7 +971,7 @@ discard block |
||
971 | 971 | * @param $aColumnNames array of column-names or string with a single column-name |
972 | 972 | * @return string the index-name |
973 | 973 | */ |
974 | - function _index_name($sTableName,$aColumnNames) |
|
974 | + function _index_name($sTableName, $aColumnNames) |
|
975 | 975 | { |
976 | 976 | // this code creates extrem short index-names, eg. for MaxDB |
977 | 977 | // if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32) |
@@ -996,28 +996,28 @@ discard block |
||
996 | 996 | // return $name; |
997 | 997 | // } |
998 | 998 | // This code creates longer index-names incl. the table-names and the used columns |
999 | - $table = str_replace(array('phpgw_','egw_'),'',$sTableName); |
|
999 | + $table = str_replace(array('phpgw_', 'egw_'), '', $sTableName); |
|
1000 | 1000 | // if the table-name or a part of it is repeated in the column-name, remove it there |
1001 | 1001 | $remove[] = $table.'_'; |
1002 | 1002 | // also remove 3 or 4 letter shortcuts of the table- or app-name |
1003 | - $remove[] = substr($table,0,3).'_'; |
|
1004 | - $remove[] = substr($table,0,4).'_'; |
|
1003 | + $remove[] = substr($table, 0, 3).'_'; |
|
1004 | + $remove[] = substr($table, 0, 4).'_'; |
|
1005 | 1005 | // if the table-name consists of '_' limtied parts, remove occurences of these parts too |
1006 | - foreach (explode('_',$table) as $part) |
|
1006 | + foreach (explode('_', $table) as $part) |
|
1007 | 1007 | { |
1008 | 1008 | $remove[] = $part.'_'; |
1009 | 1009 | } |
1010 | - $cols = str_replace($remove,'',$aColumnNames); |
|
1010 | + $cols = str_replace($remove, '', $aColumnNames); |
|
1011 | 1011 | |
1012 | - $name = $sTableName.'_'.(is_array($cols) ? implode('_',$cols) : $cols); |
|
1012 | + $name = $sTableName.'_'.(is_array($cols) ? implode('_', $cols) : $cols); |
|
1013 | 1013 | // remove length limits from column names |
1014 | - $name = preg_replace('/ *\(\d+\)/','',$name); |
|
1014 | + $name = preg_replace('/ *\(\d+\)/', '', $name); |
|
1015 | 1015 | |
1016 | 1016 | // this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle |
1017 | 1017 | if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 || |
1018 | 1018 | strlen($name) >= 64) // even mysql has a limit here ;-) |
1019 | 1019 | { |
1020 | - $name = "i".substr(md5($name),0,29); |
|
1020 | + $name = "i".substr(md5($name), 0, 29); |
|
1021 | 1021 | } |
1022 | 1022 | return $name; |
1023 | 1023 | } |
@@ -1058,19 +1058,19 @@ discard block |
||
1058 | 1058 | * @param $param mixed a variable number of parameters, to be inserted in $msg |
1059 | 1059 | * arrays get serialized with print_r() ! |
1060 | 1060 | */ |
1061 | - function debug_message($msg,$backtrace=True) |
|
1061 | + function debug_message($msg, $backtrace = True) |
|
1062 | 1062 | { |
1063 | - for($i = 2; $i < func_num_args(); ++$i) |
|
1063 | + for ($i = 2; $i < func_num_args(); ++$i) |
|
1064 | 1064 | { |
1065 | 1065 | $param = func_get_arg($i); |
1066 | 1066 | |
1067 | 1067 | if (is_null($param)) |
1068 | 1068 | { |
1069 | - $param='NULL'; |
|
1069 | + $param = 'NULL'; |
|
1070 | 1070 | } |
1071 | 1071 | else |
1072 | 1072 | { |
1073 | - switch(gettype($param)) |
|
1073 | + switch (gettype($param)) |
|
1074 | 1074 | { |
1075 | 1075 | case 'string': |
1076 | 1076 | $param = "'$param'"; |
@@ -1078,15 +1078,15 @@ discard block |
||
1078 | 1078 | case 'array': |
1079 | 1079 | case 'object': |
1080 | 1080 | list(,$content) = @each($param); |
1081 | - $do_pre = is_array($param) ? count($param) > 6 || is_array($content)&&count($content) : True; |
|
1082 | - $param = ($do_pre ? '<pre>' : '').print_r($param,True).($do_pre ? '</pre>' : ''); |
|
1081 | + $do_pre = is_array($param) ? count($param) > 6 || is_array($content) && count($content) : True; |
|
1082 | + $param = ($do_pre ? '<pre>' : '').print_r($param, True).($do_pre ? '</pre>' : ''); |
|
1083 | 1083 | break; |
1084 | 1084 | case 'boolean': |
1085 | 1085 | $param = $param ? 'True' : 'False'; |
1086 | 1086 | break; |
1087 | 1087 | } |
1088 | 1088 | } |
1089 | - $msg = str_replace('%'.($i-1),$param,$msg); |
|
1089 | + $msg = str_replace('%'.($i - 1), $param, $msg); |
|
1090 | 1090 | } |
1091 | 1091 | echo '<p>'.$msg."<br>\n".($backtrace ? 'Backtrace: '.function_backtrace(1)."</p>\n" : ''); |
1092 | 1092 | } |
@@ -1101,15 +1101,15 @@ discard block |
||
1101 | 1101 | function _egw2adodb_columndef($aTableDef) |
1102 | 1102 | { |
1103 | 1103 | $ado_defs = array(); |
1104 | - foreach($aTableDef['fd'] as $col => $col_data) |
|
1104 | + foreach ($aTableDef['fd'] as $col => $col_data) |
|
1105 | 1105 | { |
1106 | 1106 | $ado_col = False; |
1107 | 1107 | |
1108 | - switch($col_data['type']) |
|
1108 | + switch ($col_data['type']) |
|
1109 | 1109 | { |
1110 | 1110 | case 'auto': |
1111 | 1111 | $ado_col = 'I AUTOINCREMENT NOTNULL'; |
1112 | - unset($col_data['nullable']); // else we set it twice |
|
1112 | + unset($col_data['nullable']); // else we set it twice |
|
1113 | 1113 | break; |
1114 | 1114 | case 'binary': // varbinary column for MySQL/MariaDB |
1115 | 1115 | if ($this->sType == 'mysql' && $col_data['precision'] <= $this->max_varchar_length) |
@@ -1129,11 +1129,11 @@ discard block |
||
1129 | 1129 | case 'ascii': |
1130 | 1130 | case 'varchar': |
1131 | 1131 | $ado_col = "C"; |
1132 | - if(0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length) |
|
1132 | + if (0 < $col_data['precision'] && $col_data['precision'] <= $this->max_varchar_length) |
|
1133 | 1133 | { |
1134 | 1134 | $ado_col .= "($col_data[precision])"; |
1135 | 1135 | } |
1136 | - if($col_data['precision'] > $this->max_varchar_length) |
|
1136 | + if ($col_data['precision'] > $this->max_varchar_length) |
|
1137 | 1137 | { |
1138 | 1138 | $ado_col = 'X'; |
1139 | 1139 | } |
@@ -1145,7 +1145,7 @@ discard block |
||
1145 | 1145 | case 'date': |
1146 | 1146 | $ado_col = 'D'; |
1147 | 1147 | // allow to use now() beside current_date, as Postgres backups contain it and it's easier to remember anyway |
1148 | - if (in_array($col_data['default'],array('current_date','now()'))) |
|
1148 | + if (in_array($col_data['default'], array('current_date', 'now()'))) |
|
1149 | 1149 | { |
1150 | 1150 | $ado_col .= ' DEFDATE'; |
1151 | 1151 | unset($col_data['default']); |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | break; |
1162 | 1162 | case 'int': |
1163 | 1163 | $ado_col = 'I'; |
1164 | - switch($col_data['precision']) |
|
1164 | + switch ($col_data['precision']) |
|
1165 | 1165 | { |
1166 | 1166 | case 1: |
1167 | 1167 | case 2: |
@@ -1180,7 +1180,7 @@ discard block |
||
1180 | 1180 | case 'timestamp': |
1181 | 1181 | $ado_col = 'T'; |
1182 | 1182 | // allow to use now() beside current_timestamp, as Postgres backups contain it and it's easier to remember anyway |
1183 | - if (in_array($col_data['default'],array('current_timestamp','now()'))) |
|
1183 | + if (in_array($col_data['default'], array('current_timestamp', 'now()'))) |
|
1184 | 1184 | { |
1185 | 1185 | $ado_col .= ' DEFTIMESTAMP'; |
1186 | 1186 | unset($col_data['default']); |
@@ -1198,17 +1198,17 @@ discard block |
||
1198 | 1198 | } |
1199 | 1199 | if (isset($col_data['default'])) |
1200 | 1200 | { |
1201 | - $ado_col .= (in_array($col_data['type'],array('bool','int','decimal','float','double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : ''). |
|
1202 | - ' DEFAULT '.$this->m_odb->quote($col_data['default'],$col_data['type']); |
|
1201 | + $ado_col .= (in_array($col_data['type'], array('bool', 'int', 'decimal', 'float', 'double')) && $col_data['default'] != 'NULL' ? ' NOQUOTE' : ''). |
|
1202 | + ' DEFAULT '.$this->m_odb->quote($col_data['default'], $col_data['type']); |
|
1203 | 1203 | } |
1204 | - if (in_array($col,$aTableDef['pk'])) |
|
1204 | + if (in_array($col, $aTableDef['pk'])) |
|
1205 | 1205 | { |
1206 | 1206 | $ado_col .= ' PRIMARY'; |
1207 | 1207 | } |
1208 | - $ado_defs[] = $col . ' ' . $ado_col; |
|
1208 | + $ado_defs[] = $col.' '.$ado_col; |
|
1209 | 1209 | } |
1210 | 1210 | //print_r($aTableDef); echo implode(",\n",$ado_defs)."\n"; |
1211 | - return implode(",\n",$ado_defs); |
|
1211 | + return implode(",\n", $ado_defs); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1224,7 +1224,7 @@ discard block |
||
1224 | 1224 | 'pk' => array(), |
1225 | 1225 | )); |
1226 | 1226 | $matches = null; |
1227 | - return preg_match('/test ([A-Z0-9]+)/i',$ado_col,$matches) ? $this->dict->ActualType($matches[1]) : false; |
|
1227 | + return preg_match('/test ([A-Z0-9]+)/i', $ado_col, $matches) ? $this->dict->ActualType($matches[1]) : false; |
|
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | /** |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | // MetaType returns all varchar >= blobSize as blob, it's by default 100, which is wrong |
1241 | 1241 | $this->dict->blobSize = $this->max_varchar_length; |
1242 | 1242 | |
1243 | - if (!method_exists($this->dict,'MetaColumns') || |
|
1243 | + if (!method_exists($this->dict, 'MetaColumns') || |
|
1244 | 1244 | !($columns = $this->dict->MetaColumns($sTableName))) |
1245 | 1245 | { |
1246 | 1246 | return False; |
@@ -1253,11 +1253,11 @@ discard block |
||
1253 | 1253 | 'uc' => array(), |
1254 | 1254 | ); |
1255 | 1255 | //echo "$sTableName: <pre>".print_r($columns,true)."</pre>"; |
1256 | - foreach($columns as $column) |
|
1256 | + foreach ($columns as $column) |
|
1257 | 1257 | { |
1258 | 1258 | $name = $this->capabilities['name_case'] == 'upper' ? strtolower($column->name) : $column->name; |
1259 | 1259 | |
1260 | - $type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
|
1260 | + $type = method_exists($this->dict, 'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
|
1261 | 1261 | |
1262 | 1262 | // fix longtext not correctly handled by ADOdb |
1263 | 1263 | if ($type == 'X' && $column->type == 'longtext') $type = 'XL'; |
@@ -1279,11 +1279,11 @@ discard block |
||
1279 | 1279 | ); |
1280 | 1280 | $definition['fd'][$name]['type'] = $ado_type2egw[$type]; |
1281 | 1281 | |
1282 | - switch($type) |
|
1282 | + switch ($type) |
|
1283 | 1283 | { |
1284 | 1284 | case 'D': case 'T': |
1285 | 1285 | // detecting the automatic timestamps again |
1286 | - if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i',$column->default_value)) |
|
1286 | + if ($column->has_default && preg_match('/(0000-00-00|timestamp)/i', $column->default_value)) |
|
1287 | 1287 | { |
1288 | 1288 | $column->default_value = $type == 'D' ? 'current_date' : 'current_timestamp'; |
1289 | 1289 | } |
@@ -1310,10 +1310,10 @@ discard block |
||
1310 | 1310 | $column->auto_increment = true; |
1311 | 1311 | // fall-through |
1312 | 1312 | case 'I': case 'I1': case 'I2': case 'I4': case 'I8': |
1313 | - switch($type) |
|
1313 | + switch ($type) |
|
1314 | 1314 | { |
1315 | 1315 | case 'I1': case 'I2': case 'I4': case 'I8': |
1316 | - $definition['fd'][$name]['precision'] = (int) $type[1]; |
|
1316 | + $definition['fd'][$name]['precision'] = (int)$type[1]; |
|
1317 | 1317 | break; |
1318 | 1318 | default: |
1319 | 1319 | if ($column->max_length > 11) |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | $definition['fd'][$name]['type'] = 'int'; |
1350 | 1350 | // detect postgres type-spec and remove it |
1351 | 1351 | $matches = null; |
1352 | - if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/',$column->default_value,$matches)) |
|
1352 | + if ($this->sType == 'pgsql' && $column->has_default && preg_match('/\(([^)])\)::/', $column->default_value, $matches)) |
|
1353 | 1353 | { |
1354 | 1354 | $definition['fd'][$name]['default'] = $matches[1]; |
1355 | 1355 | $column->has_default = False; |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | } |
1368 | 1368 | if ($column->has_default) |
1369 | 1369 | { |
1370 | - if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) // postgres |
|
1370 | + if (preg_match("/^'(.*)'::.*$/", $column->default_value, $matches)) // postgres |
|
1371 | 1371 | { |
1372 | 1372 | $column->default_value = $matches[1]; |
1373 | 1373 | } |
@@ -1377,18 +1377,18 @@ discard block |
||
1377 | 1377 | { |
1378 | 1378 | $definition['fd'][$name]['nullable'] = False; |
1379 | 1379 | } |
1380 | - if ($column->primary_key && !in_array($name,$definition['pk'])) |
|
1380 | + if ($column->primary_key && !in_array($name, $definition['pk'])) |
|
1381 | 1381 | { |
1382 | 1382 | $definition['pk'][] = $name; |
1383 | 1383 | } |
1384 | 1384 | } |
1385 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
1385 | + if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2", False, $sTableName, $columns); |
|
1386 | 1386 | |
1387 | 1387 | // not all DB's (odbc) return the primary keys via MetaColumns |
1388 | - if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') && |
|
1388 | + if (!count($definition['pk']) && method_exists($this->dict, 'MetaPrimaryKeys') && |
|
1389 | 1389 | is_array($primary = $this->dict->MetaPrimaryKeys($sTableName)) && count($primary)) |
1390 | 1390 | { |
1391 | - if($this->capabilities['name_case'] == 'upper') |
|
1391 | + if ($this->capabilities['name_case'] == 'upper') |
|
1392 | 1392 | { |
1393 | 1393 | array_walk($primary, function(&$s) |
1394 | 1394 | { |
@@ -1397,10 +1397,10 @@ discard block |
||
1397 | 1397 | } |
1398 | 1398 | $definition['pk'] = $primary; |
1399 | 1399 | } |
1400 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
1400 | + if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2", False, $sTableName, $primary); |
|
1401 | 1401 | |
1402 | 1402 | $this->GetIndexes($sTableName, $definition); |
1403 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
1403 | + if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2", False, $sTableName, $definition); |
|
1404 | 1404 | |
1405 | 1405 | return $definition; |
1406 | 1406 | } |
@@ -1412,35 +1412,35 @@ discard block |
||
1412 | 1412 | * @param array& $definition=array() |
1413 | 1413 | * @return array of arrays with keys 'ix' and 'uc' |
1414 | 1414 | */ |
1415 | - public function GetIndexes($sTableName, array &$definition=array()) |
|
1415 | + public function GetIndexes($sTableName, array &$definition = array()) |
|
1416 | 1416 | { |
1417 | - if (method_exists($this->dict,'MetaIndexes') && |
|
1417 | + if (method_exists($this->dict, 'MetaIndexes') && |
|
1418 | 1418 | is_array($indexes = $this->dict->MetaIndexes($sTableName)) && count($indexes)) |
1419 | 1419 | { |
1420 | - foreach($indexes as $index) |
|
1420 | + foreach ($indexes as $index) |
|
1421 | 1421 | { |
1422 | 1422 | // append (optional) length of index in brackets to column |
1423 | - foreach((array)$index['length'] as $col => $length) |
|
1423 | + foreach ((array)$index['length'] as $col => $length) |
|
1424 | 1424 | { |
1425 | 1425 | if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')'; |
1426 | 1426 | } |
1427 | - if($this->capabilities['name_case'] == 'upper') |
|
1427 | + if ($this->capabilities['name_case'] == 'upper') |
|
1428 | 1428 | { |
1429 | 1429 | array_walk($index['columns'], function(&$s) |
1430 | 1430 | { |
1431 | 1431 | $s = strtolower($s); |
1432 | 1432 | }); |
1433 | 1433 | } |
1434 | - if (!empty($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) || |
|
1435 | - $index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk']))) |
|
1434 | + if (!empty($definition['pk']) && (implode(':', $definition['pk']) == implode(':', $index['columns']) || |
|
1435 | + $index['unique'] && count(array_intersect($definition['pk'], $index['columns'])) == count($definition['pk']))) |
|
1436 | 1436 | { |
1437 | - continue; // is already the primary key => ignore it |
|
1437 | + continue; // is already the primary key => ignore it |
|
1438 | 1438 | } |
1439 | 1439 | $kind = $index['unique'] ? 'uc' : 'ix'; |
1440 | 1440 | |
1441 | 1441 | $definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0]; |
1442 | 1442 | } |
1443 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
1443 | + if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2", False, $sTableName, $indexes); |
|
1444 | 1444 | } |
1445 | 1445 | return $definition; |
1446 | 1446 | } |
@@ -1454,7 +1454,7 @@ discard block |
||
1454 | 1454 | */ |
1455 | 1455 | function CheckCreateIndexes() |
1456 | 1456 | { |
1457 | - foreach($this->adodb->MetaTables('TABLES') as $table) |
|
1457 | + foreach ($this->adodb->MetaTables('TABLES') as $table) |
|
1458 | 1458 | { |
1459 | 1459 | if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue; |
1460 | 1460 | |
@@ -1463,9 +1463,9 @@ discard block |
||
1463 | 1463 | $current = $this->m_odb->metadata($table, true); |
1464 | 1464 | |
1465 | 1465 | // iterate though indexes we should have according to tables_current |
1466 | - foreach(array('uc', 'ix') as $type) |
|
1466 | + foreach (array('uc', 'ix') as $type) |
|
1467 | 1467 | { |
1468 | - foreach($table_def[$type] as $columns) |
|
1468 | + foreach ($table_def[$type] as $columns) |
|
1469 | 1469 | { |
1470 | 1470 | // sometimes primary key is listed as (unique) index too --> ignore it |
1471 | 1471 | if ($this->_in_index($columns, array($table_def['pk']), true)) continue; |
@@ -1502,27 +1502,26 @@ discard block |
||
1502 | 1502 | * old translator function, use GetTableDefition() instead |
1503 | 1503 | * @depricated |
1504 | 1504 | */ |
1505 | - function _GetColumns($oProc,$sTableName,&$sColumns) |
|
1505 | + function _GetColumns($oProc, $sTableName, &$sColumns) |
|
1506 | 1506 | { |
1507 | - unset($oProc); // unused, but required by function signature |
|
1507 | + unset($oProc); // unused, but required by function signature |
|
1508 | 1508 | $this->sCol = $this->pk = $this->fk = $this->ix = $this->uc = array(); |
1509 | 1509 | |
1510 | 1510 | $tabledef = $this->GetTableDefinition($sTableName); |
1511 | 1511 | |
1512 | - $sColumns = implode(',',array_keys($tabledef['fd'])); |
|
1512 | + $sColumns = implode(',', array_keys($tabledef['fd'])); |
|
1513 | 1513 | |
1514 | - foreach($tabledef['fd'] as $column => $data) |
|
1514 | + foreach ($tabledef['fd'] as $column => $data) |
|
1515 | 1515 | { |
1516 | 1516 | $col_def = "'type' => '$data[type]'"; |
1517 | 1517 | unset($data['type']); |
1518 | - foreach($data as $key => $val) |
|
1518 | + foreach ($data as $key => $val) |
|
1519 | 1519 | { |
1520 | - $col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : |
|
1521 | - (is_int($val) ? $val : "'$val'")); |
|
1520 | + $col_def .= ", '$key' => ".(is_bool($val) ? ($val ? 'true' : 'false') : (is_int($val) ? $val : "'$val'")); |
|
1522 | 1521 | } |
1523 | 1522 | $this->sCol[] = "\t\t\t\t'$column' => array($col_def),\n"; |
1524 | 1523 | } |
1525 | - foreach(array('pk','fk','ix','uc') as $kind) |
|
1524 | + foreach (array('pk', 'fk', 'ix', 'uc') as $kind) |
|
1526 | 1525 | { |
1527 | 1526 | $this->$kind = $tabledef[$kind]; |
1528 | 1527 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | function __construct($dbms=False, Api\Db $db=null) |
102 | 102 | { |
103 | 103 | if(is_object($db)) |
104 | - { |
|
104 | + { |
|
105 | 105 | $this->m_odb = $db; |
106 | 106 | } |
107 | 107 | else |
@@ -120,7 +120,10 @@ discard block |
||
120 | 120 | $this->dict = NewDataDictionary($this->adodb); |
121 | 121 | |
122 | 122 | // enable the debuging in ADOdb's datadictionary if the debug-level is greater then 1 |
123 | - if ($this->debug > 1) $this->dict->debug = True; |
|
123 | + if ($this->debug > 1) |
|
124 | + { |
|
125 | + $this->dict->debug = True; |
|
126 | + } |
|
124 | 127 | |
125 | 128 | // to allow some of the former translator-functions to be called, we assign ourself as the translator |
126 | 129 | $this->m_oTranslator = &$this; |
@@ -163,7 +166,10 @@ discard block |
||
163 | 166 | { |
164 | 167 | unset($columns['options']); |
165 | 168 | $columns = implode('-',$columns); |
166 | - if ($ignore_length_limit) $columns = preg_replace('/\(\d+\)/', '', $columns); |
|
169 | + if ($ignore_length_limit) |
|
170 | + { |
|
171 | + $columns = preg_replace('/\(\d+\)/', '', $columns); |
|
172 | + } |
|
167 | 173 | } |
168 | 174 | foreach($indexs as $index) |
169 | 175 | { |
@@ -172,8 +178,14 @@ discard block |
||
172 | 178 | unset($index['options']); |
173 | 179 | $index = implode('-',$index); |
174 | 180 | } |
175 | - if ($ignore_length_limit) $index = preg_replace('/\(\d+\)/', '', $index); |
|
176 | - if ($columns == $index) return true; |
|
181 | + if ($ignore_length_limit) |
|
182 | + { |
|
183 | + $index = preg_replace('/\(\d+\)/', '', $index); |
|
184 | + } |
|
185 | + if ($columns == $index) |
|
186 | + { |
|
187 | + return true; |
|
188 | + } |
|
177 | 189 | } |
178 | 190 | return false; |
179 | 191 | } |
@@ -235,12 +247,20 @@ discard block |
||
235 | 247 | $options = False; |
236 | 248 | if (is_array($mFields)) |
237 | 249 | { |
238 | - if (isset($mFields['options'])) // array sets additional options |
|
250 | + if (isset($mFields['options'])) |
|
251 | + { |
|
252 | + // array sets additional options |
|
239 | 253 | { |
240 | 254 | if (isset($mFields['options'][$this->sType])) |
241 | 255 | { |
242 | - $options = $mFields['options'][$this->sType]; // db-specific options, eg. index-type |
|
243 | - if (!$options) continue; // no index for our db-type |
|
256 | + $options = $mFields['options'][$this->sType]; |
|
257 | + } |
|
258 | + // db-specific options, eg. index-type |
|
259 | + if (!$options) |
|
260 | + { |
|
261 | + continue; |
|
262 | + } |
|
263 | + // no index for our db-type |
|
244 | 264 | } |
245 | 265 | unset($mFields['options']); |
246 | 266 | } |
@@ -251,15 +271,22 @@ discard block |
||
251 | 271 | // most DB's cant do them and give errors |
252 | 272 | if (in_array($aTableDef['fd'][$col]['type'],array('text','longtext'))) |
253 | 273 | { |
254 | - if (is_array($mFields)) // index over multiple columns including a text column |
|
274 | + if (is_array($mFields)) |
|
255 | 275 | { |
256 | - $mFields[$k] .= '(32)'; // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
276 | + // index over multiple columns including a text column |
|
277 | + { |
|
278 | + $mFields[$k] .= '(32)'; |
|
279 | + } |
|
280 | + // 32=limit of egw_addressbook_extra.extra_value to fix old backups |
|
257 | 281 | } |
258 | - elseif (!$options) // index over a single text column and no options given |
|
282 | + elseif (!$options) |
|
283 | + { |
|
284 | + // index over a single text column and no options given |
|
259 | 285 | { |
260 | 286 | if ($this->sType == 'mysql') |
261 | 287 | { |
262 | 288 | $options = 'FULLTEXT'; |
289 | + } |
|
263 | 290 | } |
264 | 291 | else |
265 | 292 | { |
@@ -300,8 +327,14 @@ discard block |
||
300 | 327 | return False; |
301 | 328 | } |
302 | 329 | // set our debug-mode or $bOutputHTML is the other one is set |
303 | - if ($this->debug) $bOutputHTML = True; |
|
304 | - if ($bOutputHTML && !$this->debug) $this->debug = 2; |
|
330 | + if ($this->debug) |
|
331 | + { |
|
332 | + $bOutputHTML = True; |
|
333 | + } |
|
334 | + if ($bOutputHTML && !$this->debug) |
|
335 | + { |
|
336 | + $this->debug = 2; |
|
337 | + } |
|
305 | 338 | |
306 | 339 | foreach(array_keys($aTables) as $sTableName) |
307 | 340 | { |
@@ -328,7 +361,10 @@ discard block |
||
328 | 361 | */ |
329 | 362 | function DropTable($sTableName) |
330 | 363 | { |
331 | - if ($this->sType == 'pgsql') $this->_PostgresTestDropOldSequence($sTableName); |
|
364 | + if ($this->sType == 'pgsql') |
|
365 | + { |
|
366 | + $this->_PostgresTestDropOldSequence($sTableName); |
|
367 | + } |
|
332 | 368 | |
333 | 369 | $aSql = $this->dict->DropTableSql($sTableName); |
334 | 370 | |
@@ -347,7 +383,10 @@ discard block |
||
347 | 383 | { |
348 | 384 | unset($aTableDef); // not used, but required by function signature |
349 | 385 | |
350 | - if (!($table_def = $this->GetTableDefinition($sTableName))) return 0; |
|
386 | + if (!($table_def = $this->GetTableDefinition($sTableName))) |
|
387 | + { |
|
388 | + return 0; |
|
389 | + } |
|
351 | 390 | unset($table_def['fd'][$sColumnName]); |
352 | 391 | |
353 | 392 | $aSql = $this->dict->DropColumnSql($sTableName,$sColumnName,$ado_table=$this->_egw2adodb_columndef($table_def)); |
@@ -368,7 +407,10 @@ discard block |
||
368 | 407 | // we create a new table, copy the content and drop the old one |
369 | 408 | if ($this->sType == 'pgsql') |
370 | 409 | { |
371 | - if (!($table_def = $this->GetTableDefinition($sOldTableName))) return 0; |
|
410 | + if (!($table_def = $this->GetTableDefinition($sOldTableName))) |
|
411 | + { |
|
412 | + return 0; |
|
413 | + } |
|
372 | 414 | |
373 | 415 | // only use old PostgreSQL stuff, if we have an old sequence, otherwise rely on it being new enough |
374 | 416 | if ($this->_PostgresHasOldSequence($sOldTableName,True) && |
@@ -402,7 +444,10 @@ discard block |
||
402 | 444 | */ |
403 | 445 | function _PostgresHasOldSequence($sTableName,$preserveValue=False) |
404 | 446 | { |
405 | - if ($this->sType != 'pgsql') return false; |
|
447 | + if ($this->sType != 'pgsql') |
|
448 | + { |
|
449 | + return false; |
|
450 | + } |
|
406 | 451 | |
407 | 452 | $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"); |
408 | 453 | $seq2 = $this->adodb->GetOne("SELECT d.adsrc FROM pg_attribute a, pg_class c, pg_attrdef d WHERE c.relname='$sTableName' AND c.oid=d.adrelid AND d.adsrc LIKE '%$sTableName%_seq''::text)' AND a.attrelid=c.oid AND d.adnum=a.attnum"); |
@@ -410,12 +455,18 @@ discard block |
||
410 | 455 | $matches = null; |
411 | 456 | if ($seq && preg_match('/^nextval\(\'(.*)\'/',$seq,$matches)) |
412 | 457 | { |
413 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
458 | + if ($preserveValue) |
|
459 | + { |
|
460 | + $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
461 | + } |
|
414 | 462 | return $matches[1]; |
415 | 463 | } |
416 | 464 | if ($seq2 && preg_match('/^nextval\(\'public\.(.*)\'/',$seq2,$matches)) |
417 | 465 | { |
418 | - if ($preserveValue) $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
466 | + if ($preserveValue) |
|
467 | + { |
|
468 | + $this->pgsql_old_seq = $this->adodb->GetOne("SELECT last_value FROM " . $matches[1]); |
|
469 | + } |
|
419 | 470 | return $matches[1]; |
420 | 471 | } |
421 | 472 | return false; |
@@ -449,7 +500,10 @@ discard block |
||
449 | 500 | */ |
450 | 501 | function AlterColumn($sTableName, $sColumnName, $aColumnDef) |
451 | 502 | { |
452 | - if (!($table_def = $this->GetTableDefinition($sTableName))) return 0; |
|
503 | + if (!($table_def = $this->GetTableDefinition($sTableName))) |
|
504 | + { |
|
505 | + return 0; |
|
506 | + } |
|
453 | 507 | |
454 | 508 | // PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long |
455 | 509 | if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) && |
@@ -552,8 +606,14 @@ discard block |
||
552 | 606 | { |
553 | 607 | $sIdxName = $this->_index_name($sTableName,$aColumnNames); |
554 | 608 | } |
555 | - if (!is_array($options)) $options = $options ? array($options) : array(); |
|
556 | - if ($bUnique) $options[] = 'UNIQUE'; |
|
609 | + if (!is_array($options)) |
|
610 | + { |
|
611 | + $options = $options ? array($options) : array(); |
|
612 | + } |
|
613 | + if ($bUnique) |
|
614 | + { |
|
615 | + $options[] = 'UNIQUE'; |
|
616 | + } |
|
557 | 617 | |
558 | 618 | // if index already exists drop it first |
559 | 619 | $definition = array(); |
@@ -635,7 +695,9 @@ discard block |
||
635 | 695 | $seq_name = $matches[1]; |
636 | 696 | } |
637 | 697 | $sql = "SELECT setval('$seq_name',MAX($sColumnName)) FROM $sTableName"; |
638 | - if($this->debug) { echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
698 | + if($this->debug) |
|
699 | + { |
|
700 | +echo "<br>Updating sequence '$seq_name using: $sql"; } |
|
639 | 701 | return $this->query($sql,__LINE__,__FILE__); |
640 | 702 | } |
641 | 703 | return True; |
@@ -655,7 +717,9 @@ discard block |
||
655 | 717 | */ |
656 | 718 | function RefreshTable($sTableName, $aTableDef, $aDefaults=False) |
657 | 719 | { |
658 | - if($this->debug) { echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
720 | + if($this->debug) |
|
721 | + { |
|
722 | +echo "<p>schema_proc::RefreshTable('$sTableName',"._debug_array($aTableDef,False).")\n"; } |
|
659 | 723 | |
660 | 724 | $old_table_def = $this->GetTableDefinition($sTableName); |
661 | 725 | |
@@ -682,21 +746,30 @@ discard block |
||
682 | 746 | $value = "nextval('$sequence_name')"; break; |
683 | 747 | } |
684 | 748 | } |
685 | - elseif ($aDefaults && isset($aDefaults[$name])) // use given default |
|
749 | + elseif ($aDefaults && isset($aDefaults[$name])) |
|
750 | + { |
|
751 | + // use given default |
|
686 | 752 | { |
687 | 753 | $value = $aDefaults[$name]; |
688 | 754 | } |
689 | - elseif (isset($old_table_def['fd'][$name])) // existing column, use its value => column-name in query |
|
755 | + } |
|
756 | + elseif (isset($old_table_def['fd'][$name])) |
|
757 | + { |
|
758 | + // existing column, use its value => column-name in query |
|
690 | 759 | { |
691 | 760 | $value = $name; |
761 | + } |
|
692 | 762 | |
693 | - if ($this->sType == 'pgsql') // some postgres specific code |
|
763 | + if ($this->sType == 'pgsql') |
|
764 | + { |
|
765 | + // some postgres specific code |
|
694 | 766 | { |
695 | 767 | // this is eg. necessary to change a varchar into an int column under postgres |
696 | 768 | if (in_array($old_table_def['fd'][$name]['type'],array('char','varchar','text','blob')) && |
697 | 769 | in_array($data['type'],array('int','decimal'))) |
698 | 770 | { |
699 | 771 | $value = "to_number($name,'S9999999999999D99')"; |
772 | + } |
|
700 | 773 | } |
701 | 774 | // blobs cant be casted to text |
702 | 775 | elseif($old_table_def['fd'][$name]['type'] == 'blob' && $data['type'] == 'text') |
@@ -751,8 +824,15 @@ discard block |
||
751 | 824 | switch($this->sType) |
752 | 825 | { |
753 | 826 | case 'mssql': |
754 | - if ($auto_column_included) $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
|
755 | - if ($blob_column_included) $distinct = ''; // no distinct on blob-columns |
|
827 | + if ($auto_column_included) |
|
828 | + { |
|
829 | + $extra = "SET IDENTITY_INSERT $sTableName ON\n"; |
|
830 | + } |
|
831 | + if ($blob_column_included) |
|
832 | + { |
|
833 | + $distinct = ''; |
|
834 | + } |
|
835 | + // no distinct on blob-columns |
|
756 | 836 | break; |
757 | 837 | } |
758 | 838 | // because of all the trouble with sequences and indexes in the global namespace, |
@@ -816,8 +896,14 @@ discard block |
||
816 | 896 | return False; |
817 | 897 | } |
818 | 898 | // set our debug-mode or $bOutputHTML is the other one is set |
819 | - if ($this->debug) $bOutputHTML = True; |
|
820 | - if ($bOutputHTML && !$this->debug) $this->debug = 2; |
|
899 | + if ($this->debug) |
|
900 | + { |
|
901 | + $bOutputHTML = True; |
|
902 | + } |
|
903 | + if ($bOutputHTML && !$this->debug) |
|
904 | + { |
|
905 | + $this->debug = 2; |
|
906 | + } |
|
821 | 907 | |
822 | 908 | foreach($aTables as $sTableName => $aTableDef) |
823 | 909 | { |
@@ -930,9 +1016,12 @@ discard block |
||
930 | 1016 | */ |
931 | 1017 | function ExecuteSqlArray($aSql,$debug_level) |
932 | 1018 | { |
933 | - if ($this->m_odb->query_log) // we use Db::query to log the queries |
|
1019 | + if ($this->m_odb->query_log) |
|
1020 | + { |
|
1021 | + // we use Db::query to log the queries |
|
934 | 1022 | { |
935 | 1023 | $retval = 2; |
1024 | + } |
|
936 | 1025 | foreach($aSql as $sql) |
937 | 1026 | { |
938 | 1027 | if (!$this->m_odb->query($sql,__LINE__,__FILE__)) |
@@ -1015,10 +1104,13 @@ discard block |
||
1015 | 1104 | |
1016 | 1105 | // this code creates a fixed short index-names (30 chars) from the long and unique name, eg. for MaxDB or Oracle |
1017 | 1106 | if (isset($this->max_index_length[$this->sType]) && $this->max_index_length[$this->sType] <= 32 && strlen($name) > 30 || |
1018 | - strlen($name) >= 64) // even mysql has a limit here ;-) |
|
1107 | + strlen($name) >= 64) |
|
1108 | + { |
|
1109 | + // even mysql has a limit here ;-) |
|
1019 | 1110 | { |
1020 | 1111 | $name = "i".substr(md5($name),0,29); |
1021 | 1112 | } |
1113 | + } |
|
1022 | 1114 | return $name; |
1023 | 1115 | } |
1024 | 1116 | |
@@ -1260,7 +1352,10 @@ discard block |
||
1260 | 1352 | $type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); |
1261 | 1353 | |
1262 | 1354 | // fix longtext not correctly handled by ADOdb |
1263 | - if ($type == 'X' && $column->type == 'longtext') $type = 'XL'; |
|
1355 | + if ($type == 'X' && $column->type == 'longtext') |
|
1356 | + { |
|
1357 | + $type = 'XL'; |
|
1358 | + } |
|
1264 | 1359 | |
1265 | 1360 | static $ado_type2egw = array( |
1266 | 1361 | 'C' => 'varchar', |
@@ -1367,10 +1462,13 @@ discard block |
||
1367 | 1462 | } |
1368 | 1463 | if ($column->has_default) |
1369 | 1464 | { |
1370 | - if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) // postgres |
|
1465 | + if (preg_match("/^'(.*)'::.*$/",$column->default_value,$matches)) |
|
1466 | + { |
|
1467 | + // postgres |
|
1371 | 1468 | { |
1372 | 1469 | $column->default_value = $matches[1]; |
1373 | 1470 | } |
1471 | + } |
|
1374 | 1472 | $definition['fd'][$name]['default'] = $column->default_value; |
1375 | 1473 | } |
1376 | 1474 | if ($column->not_null) |
@@ -1382,7 +1480,10 @@ discard block |
||
1382 | 1480 | $definition['pk'][] = $name; |
1383 | 1481 | } |
1384 | 1482 | } |
1385 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
1483 | + if ($this->debug > 2) |
|
1484 | + { |
|
1485 | + $this->debug_message("schema_proc::GetTableDefintion: MetaColumns(%1) = %2",False,$sTableName,$columns); |
|
1486 | + } |
|
1386 | 1487 | |
1387 | 1488 | // not all DB's (odbc) return the primary keys via MetaColumns |
1388 | 1489 | if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') && |
@@ -1397,10 +1498,16 @@ discard block |
||
1397 | 1498 | } |
1398 | 1499 | $definition['pk'] = $primary; |
1399 | 1500 | } |
1400 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
1501 | + if ($this->debug > 1) |
|
1502 | + { |
|
1503 | + $this->debug_message("schema_proc::GetTableDefintion: MetaPrimaryKeys(%1) = %2",False,$sTableName,$primary); |
|
1504 | + } |
|
1401 | 1505 | |
1402 | 1506 | $this->GetIndexes($sTableName, $definition); |
1403 | - if ($this->debug > 1) $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
1507 | + if ($this->debug > 1) |
|
1508 | + { |
|
1509 | + $this->debug_message("schema_proc::GetTableDefintion(%1) = %2",False,$sTableName,$definition); |
|
1510 | + } |
|
1404 | 1511 | |
1405 | 1512 | return $definition; |
1406 | 1513 | } |
@@ -1422,7 +1529,10 @@ discard block |
||
1422 | 1529 | // append (optional) length of index in brackets to column |
1423 | 1530 | foreach((array)$index['length'] as $col => $length) |
1424 | 1531 | { |
1425 | - if (($key = array_search($col, $index['columns']))) $index['columns'][$key] .= '('.$length.')'; |
|
1532 | + if (($key = array_search($col, $index['columns']))) |
|
1533 | + { |
|
1534 | + $index['columns'][$key] .= '('.$length.')'; |
|
1535 | + } |
|
1426 | 1536 | } |
1427 | 1537 | if($this->capabilities['name_case'] == 'upper') |
1428 | 1538 | { |
@@ -1440,7 +1550,10 @@ discard block |
||
1440 | 1550 | |
1441 | 1551 | $definition[$kind][] = count($index['columns']) > 1 ? $index['columns'] : $index['columns'][0]; |
1442 | 1552 | } |
1443 | - if ($this->debug > 2) $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
1553 | + if ($this->debug > 2) |
|
1554 | + { |
|
1555 | + $this->debug_message("schema_proc::GetTableDefintion: MetaIndexes(%1) = %2",False,$sTableName,$indexes); |
|
1556 | + } |
|
1444 | 1557 | } |
1445 | 1558 | return $definition; |
1446 | 1559 | } |
@@ -1456,7 +1569,10 @@ discard block |
||
1456 | 1569 | { |
1457 | 1570 | foreach($this->adodb->MetaTables('TABLES') as $table) |
1458 | 1571 | { |
1459 | - if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) continue; |
|
1572 | + if (!($table_def = $this->m_odb->get_table_definitions(true, $table))) |
|
1573 | + { |
|
1574 | + continue; |
|
1575 | + } |
|
1460 | 1576 | |
1461 | 1577 | $definition = array(); |
1462 | 1578 | $this->GetIndexes($table, $definition); |
@@ -1468,7 +1584,10 @@ discard block |
||
1468 | 1584 | foreach($table_def[$type] as $columns) |
1469 | 1585 | { |
1470 | 1586 | // sometimes primary key is listed as (unique) index too --> ignore it |
1471 | - if ($this->_in_index($columns, array($table_def['pk']), true)) continue; |
|
1587 | + if ($this->_in_index($columns, array($table_def['pk']), true)) |
|
1588 | + { |
|
1589 | + continue; |
|
1590 | + } |
|
1472 | 1591 | |
1473 | 1592 | // current table does NOT contain all columns, eg. not yet updated --> ignore index |
1474 | 1593 | if (array_diff((array)$columns, array_keys($current['meta']))) |
@@ -1485,7 +1604,10 @@ discard block |
||
1485 | 1604 | if ($this->_in_index($columns, $definition[$type], true)) |
1486 | 1605 | { |
1487 | 1606 | // for PostgreSQL we dont use length-limited indexes --> nothing to do |
1488 | - if ($this->m_odb->Type == 'pgsql') continue; |
|
1607 | + if ($this->m_odb->Type == 'pgsql') |
|
1608 | + { |
|
1609 | + continue; |
|
1610 | + } |
|
1489 | 1611 | // for MySQL we drop current index and create it with correct length |
1490 | 1612 | $this->DropIndex($table, $columns); |
1491 | 1613 | } |
@@ -543,7 +543,7 @@ |
||
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 | */ |
@@ -47,14 +47,24 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | $this->children = array($template); |
163 | 188 | $template->run('beforeSendToClient', array('', array('cont'=>$content))); |
164 | 189 | |
@@ -203,10 +228,13 @@ discard block |
||
203 | 228 | 'data' => $data, |
204 | 229 | 'DOMNodeID' => $dom_id, |
205 | 230 | ); |
206 | - if (self::$response) // call is within an ajax event / form submit |
|
231 | + if (self::$response) |
|
232 | + { |
|
233 | + // call is within an ajax event / form submit |
|
207 | 234 | { |
208 | 235 | //error_log("Ajax " . __LINE__); |
209 | 236 | self::$response->generic('et2_load', $load_array+Framework::get_extra()); |
237 | + } |
|
210 | 238 | Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
211 | 239 | } |
212 | 240 | else // first call |
@@ -269,7 +297,10 @@ discard block |
||
269 | 297 | echo $GLOBALS['egw']->framework->footer(); |
270 | 298 | } |
271 | 299 | ob_flush(); |
272 | - if ($output_mode == 1) return $form; |
|
300 | + if ($output_mode == 1) |
|
301 | + { |
|
302 | + return $form; |
|
303 | + } |
|
273 | 304 | } |
274 | 305 | self::$request = null; |
275 | 306 | } |
@@ -284,7 +315,10 @@ discard block |
||
284 | 315 | { |
285 | 316 | foreach($sel_options as &$options) |
286 | 317 | { |
287 | - if (!is_array($options)||empty($options)) continue; |
|
318 | + if (!is_array($options)||empty($options)) |
|
319 | + { |
|
320 | + continue; |
|
321 | + } |
|
288 | 322 | foreach($options as $key => $value) |
289 | 323 | { |
290 | 324 | if (is_numeric($key) && (!is_array($value) || !isset($value['value']))) |
@@ -325,7 +359,10 @@ discard block |
||
325 | 359 | |
326 | 360 | // Set current app for validation |
327 | 361 | list($app) = explode('.',self::$request->method); |
328 | - if(!$app) list($app) = explode('::',self::$request->method); |
|
362 | + if(!$app) |
|
363 | + { |
|
364 | + list($app) = explode('::',self::$request->method); |
|
365 | + } |
|
329 | 366 | if($app) |
330 | 367 | { |
331 | 368 | Translation::add_app($app); |
@@ -356,7 +393,10 @@ discard block |
||
356 | 393 | 'location_name' => $template->id, |
357 | 394 | ) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras) |
358 | 395 | { |
359 | - if (!$extras) continue; |
|
396 | + if (!$extras) |
|
397 | + { |
|
398 | + continue; |
|
399 | + } |
|
360 | 400 | |
361 | 401 | foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
362 | 402 | { |
@@ -394,10 +434,15 @@ discard block |
||
394 | 434 | { |
395 | 435 | foreach($hook_data as $extras) |
396 | 436 | { |
397 | - if (!$extras) continue; |
|
437 | + if (!$extras) |
|
438 | + { |
|
439 | + continue; |
|
440 | + } |
|
398 | 441 | |
399 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
400 | - if ($extra['data'] && is_array($extra['data'])) { |
|
442 | + foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
|
443 | + { |
|
444 | + if ($extra['data'] && is_array($extra['data'])) |
|
445 | + { |
|
401 | 446 | $content = array_merge($content, $extra['data']); |
402 | 447 | } |
403 | 448 | } |
@@ -436,7 +481,10 @@ discard block |
||
436 | 481 | */ |
437 | 482 | static public function process_exec() |
438 | 483 | { |
439 | - if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']); |
|
484 | + if (get_magic_quotes_gpc()) |
|
485 | + { |
|
486 | + $_POST['value'] = stripslashes($_POST['value']); |
|
487 | + } |
|
440 | 488 | $content = json_decode($_POST['value'],true); |
441 | 489 | //error_log(__METHOD__."(".array2string($content).")"); |
442 | 490 | |
@@ -599,16 +647,22 @@ discard block |
||
599 | 647 | { |
600 | 648 | if (is_array($new)) |
601 | 649 | { |
602 | - if (!is_array($old)) $old = (array) $old; |
|
650 | + if (!is_array($old)) |
|
651 | + { |
|
652 | + $old = (array) $old; |
|
653 | + } |
|
603 | 654 | |
604 | 655 | foreach($new as $k => $v) |
605 | 656 | { |
606 | 657 | if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
607 | 658 | isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1]) || // or no associative array, eg. selecting multiple accounts |
608 | - is_array($v) && count($v) == 0) // Empty array replacing non-empty |
|
659 | + is_array($v) && count($v) == 0) |
|
660 | + { |
|
661 | + // Empty array replacing non-empty |
|
609 | 662 | { |
610 | 663 | $old[$k] = $v; |
611 | 664 | } |
665 | + } |
|
612 | 666 | else |
613 | 667 | { |
614 | 668 | $old[$k] = self::complete_array_merge($old[$k],$v); |
@@ -661,10 +715,16 @@ discard block |
||
661 | 715 | if (is_null($dec_separator)) |
662 | 716 | { |
663 | 717 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
664 | - if (empty($dec_separator)) $dec_separator = '.'; |
|
718 | + if (empty($dec_separator)) |
|
719 | + { |
|
720 | + $dec_separator = '.'; |
|
721 | + } |
|
665 | 722 | $thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1]; |
666 | 723 | } |
667 | - if ((string)$number === '') return ''; |
|
724 | + if ((string)$number === '') |
|
725 | + { |
|
726 | + return ''; |
|
727 | + } |
|
668 | 728 | |
669 | 729 | return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : ''); |
670 | 730 | } |
@@ -158,7 +158,7 @@ |
||
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 | $this->children = array($template); |
163 | 163 | $template->run('beforeSendToClient', array('', array('cont'=>$content))); |
164 | 164 |
@@ -29,7 +29,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | { |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $output_mode = 0; |
149 | 149 | self::$response = Json\Response::get(); |
150 | 150 | } |
151 | - self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup |
|
151 | + self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup |
|
152 | 152 | self::$request->content = self::$cont = $content; |
153 | 153 | self::$request->changes = $changes; |
154 | 154 | self::$request->sel_options = is_array($sel_options) ? self::fix_sel_options($sel_options) : array(); |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | |
173 | 173 | // compile required translations translations |
174 | 174 | $currentapp = $GLOBALS['egw_info']['flags']['currentapp']; |
175 | - $langRequire = array('common' => array(), 'etemplate' => array()); // keep that order |
|
176 | - foreach(Translation::$loaded_apps as $l_app => $lang) |
|
175 | + $langRequire = array('common' => array(), 'etemplate' => array()); // keep that order |
|
176 | + foreach (Translation::$loaded_apps as $l_app => $lang) |
|
177 | 177 | { |
178 | 178 | if (!in_array($l_app, array($currentapp, 'custom'))) |
179 | 179 | { |
180 | 180 | $langRequire[$l_app] = array('app' => $l_app, 'lang' => $lang, 'etag' => Translation::etag($l_app, $lang)); |
181 | 181 | } |
182 | 182 | } |
183 | - foreach(array($currentapp, 'custom') as $l_app) |
|
183 | + foreach (array($currentapp, 'custom') as $l_app) |
|
184 | 184 | { |
185 | 185 | if (isset(Translation::$loaded_apps[$l_app])) |
186 | 186 | { |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | ); |
202 | 202 | |
203 | 203 | // Info required to load the etemplate client-side |
204 | - $dom_id = str_replace('.','-',$this->dom_id); |
|
204 | + $dom_id = str_replace('.', '-', $this->dom_id); |
|
205 | 205 | $load_array = array( |
206 | 206 | 'name' => $this->name, |
207 | 207 | 'url' => self::rel2url($this->rel_path), |
@@ -211,16 +211,16 @@ discard block |
||
211 | 211 | if (self::$response) // call is within an ajax event / form submit |
212 | 212 | { |
213 | 213 | //error_log("Ajax " . __LINE__); |
214 | - self::$response->generic('et2_load', $load_array+Framework::get_extra()); |
|
215 | - Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
214 | + self::$response->generic('et2_load', $load_array + Framework::get_extra()); |
|
215 | + Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
216 | 216 | } |
217 | 217 | else // first call |
218 | 218 | { |
219 | 219 | // check if application of template has a app.js file --> load it |
220 | - list($app) = explode('.',$this->name); |
|
220 | + list($app) = explode('.', $this->name); |
|
221 | 221 | if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/js/app.js')) |
222 | 222 | { |
223 | - Framework::includeJS('.','app',$app,true); |
|
223 | + Framework::includeJS('.', 'app', $app, true); |
|
224 | 224 | } |
225 | 225 | // Category styles |
226 | 226 | Categories::css($app); |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | $content = '<form target="egw_iframe_autocomplete_helper" action="'.$form_action.'" id="'.$dom_id.'" class="et2_container"></form>'."\n". |
239 | 239 | '<iframe name="egw_iframe_autocomplete_helper" style="width:0;height:0;position: absolute;visibility:hidden;"></iframe>'; |
240 | 240 | $GLOBALS['egw']->framework->response->generic("data", array($content)); |
241 | - $GLOBALS['egw']->framework->response->generic('et2_load',$load_array+Framework::get_extra()); |
|
242 | - Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
241 | + $GLOBALS['egw']->framework->response->generic('et2_load', $load_array + Framework::get_extra()); |
|
242 | + Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view) |
|
243 | 243 | return; |
244 | 244 | } |
245 | 245 | // let framework know, if we are a popup or not ('popup' not true, which is allways used by index.php!) |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | echo '<div id="popupMainDiv" class="popupMainDiv">'."\n"; |
258 | 258 | } |
259 | 259 | // Send any accumulated json responses - after flush to avoid sending the buffer as a response |
260 | - if(Json\Response::isJSONResponse()) |
|
260 | + if (Json\Response::isJSONResponse()) |
|
261 | 261 | { |
262 | 262 | $load_array['response'] = Json\Response::get()->returnResult(); |
263 | 263 | } |
@@ -286,10 +286,10 @@ discard block |
||
286 | 286 | */ |
287 | 287 | static protected function fix_sel_options(array $sel_options) |
288 | 288 | { |
289 | - foreach($sel_options as &$options) |
|
289 | + foreach ($sel_options as &$options) |
|
290 | 290 | { |
291 | - if (!is_array($options)||empty($options)) continue; |
|
292 | - foreach($options as $key => $value) |
|
291 | + if (!is_array($options) || empty($options)) continue; |
|
292 | + foreach ($options as $key => $value) |
|
293 | 293 | { |
294 | 294 | if (is_numeric($key) && (!is_array($value) || !isset($value['value']))) |
295 | 295 | { |
@@ -328,9 +328,9 @@ discard block |
||
328 | 328 | $GLOBALS['egw']->session->set_action('Etemplate: '.self::$request->method); |
329 | 329 | |
330 | 330 | // Set current app for validation |
331 | - list($app) = explode('.',self::$request->method); |
|
332 | - if(!$app) list($app) = explode('::',self::$request->method); |
|
333 | - if($app) |
|
331 | + list($app) = explode('.', self::$request->method); |
|
332 | + if (!$app) list($app) = explode('::', self::$request->method); |
|
333 | + if ($app) |
|
334 | 334 | { |
335 | 335 | Translation::add_app($app); |
336 | 336 | $GLOBALS['egw_info']['flags']['currentapp'] = $app; |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | $expand = array( |
340 | 340 | 'cont' => &self::$request->content, |
341 | 341 | ); |
342 | - $template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
342 | + $template->run('validate', array('', $expand, $_content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
343 | 343 | |
344 | 344 | if ($no_validation) |
345 | 345 | { |
@@ -355,14 +355,14 @@ discard block |
||
355 | 355 | // tell request call to remove request, if it is not modified eg. by call to exec in callback |
356 | 356 | self::$request->remove_if_not_modified(); |
357 | 357 | |
358 | - foreach(Hooks::process(array( |
|
358 | + foreach (Hooks::process(array( |
|
359 | 359 | 'hook_location' => 'etemplate2_before_process', |
360 | 360 | 'location_name' => $template->id, |
361 | 361 | ) + self::complete_array_merge(self::$request->preserv, $validated)) as $extras) |
362 | 362 | { |
363 | 363 | if (!$extras) continue; |
364 | 364 | |
365 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) |
|
365 | + foreach (isset($extras[0]) ? $extras : array($extras) as $extra) |
|
366 | 366 | { |
367 | 367 | if ($extra['data'] && is_array($extra['data'])) |
368 | 368 | { |
@@ -373,9 +373,9 @@ discard block |
||
373 | 373 | |
374 | 374 | //error_log(__METHOD__."(,".array2string($content).')'); |
375 | 375 | //error_log(' validated='.array2string($validated)); |
376 | - if(is_callable(self::$request->method)) |
|
376 | + if (is_callable(self::$request->method)) |
|
377 | 377 | { |
378 | - call_user_func(self::$request->method,self::complete_array_merge(self::$request->preserv, $validated)); |
|
378 | + call_user_func(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated)); |
|
379 | 379 | } |
380 | 380 | else |
381 | 381 | { |
@@ -383,8 +383,7 @@ discard block |
||
383 | 383 | $content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated)); |
384 | 384 | } |
385 | 385 | |
386 | - $tcontent = is_array($content) ? $content : |
|
387 | - self::complete_array_merge(self::$request->preserv, $validated); |
|
386 | + $tcontent = is_array($content) ? $content : self::complete_array_merge(self::$request->preserv, $validated); |
|
388 | 387 | |
389 | 388 | $hook_data = Hooks::process( |
390 | 389 | array( |
@@ -396,11 +395,11 @@ discard block |
||
396 | 395 | |
397 | 396 | if (is_array($content)) |
398 | 397 | { |
399 | - foreach($hook_data as $extras) |
|
398 | + foreach ($hook_data as $extras) |
|
400 | 399 | { |
401 | 400 | if (!$extras) continue; |
402 | 401 | |
403 | - foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
402 | + foreach (isset($extras[0]) ? $extras : array($extras) as $extra) { |
|
404 | 403 | if ($extra['data'] && is_array($extra['data'])) { |
405 | 404 | $content = array_merge($content, $extra['data']); |
406 | 405 | } |
@@ -412,7 +411,7 @@ discard block |
||
412 | 411 | if (isset($GLOBALS['egw_info']['flags']['java_script'])) |
413 | 412 | { |
414 | 413 | // Strip out any script tags |
415 | - $GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']); |
|
414 | + $GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']); |
|
416 | 415 | self::$response->script($GLOBALS['egw_info']['flags']['java_script']); |
417 | 416 | //error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use Json\Response->script() instead.'); |
418 | 417 | } |
@@ -441,7 +440,7 @@ discard block |
||
441 | 440 | static public function process_exec() |
442 | 441 | { |
443 | 442 | if (get_magic_quotes_gpc()) $_POST['value'] = stripslashes($_POST['value']); |
444 | - $content = json_decode($_POST['value'],true); |
|
443 | + $content = json_decode($_POST['value'], true); |
|
445 | 444 | //error_log(__METHOD__."(".array2string($content).")"); |
446 | 445 | |
447 | 446 | self::$request = Etemplate\Request::read($_POST['etemplate_exec_id']); |
@@ -455,7 +454,7 @@ discard block |
||
455 | 454 | $expand = array( |
456 | 455 | 'cont' => &self::$request->content, |
457 | 456 | ); |
458 | - $template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
457 | + $template->run('validate', array('', $expand, $content, &$validated), true); // $respect_disabled=true: do NOT validate disabled widgets and children |
|
459 | 458 | if (self::validation_errors(self::$request->ignore_validation)) |
460 | 459 | { |
461 | 460 | error_log(__METHOD__."(,".array2string($content).') validation_errors='.array2string(self::$validation_errors)); |
@@ -491,7 +490,7 @@ discard block |
||
491 | 490 | * |
492 | 491 | * @ToDo supported customized templates stored in DB |
493 | 492 | */ |
494 | - public function read($name,$template_set=null,$lang='default',$group=0,$version='',$load_via='') |
|
493 | + public function read($name, $template_set = null, $lang = 'default', $group = 0, $version = '', $load_via = '') |
|
495 | 494 | { |
496 | 495 | |
497 | 496 | // For mobile experience try to load custom mobile templates |
@@ -500,9 +499,9 @@ discard block |
||
500 | 499 | $template_set = "mobile"; |
501 | 500 | } |
502 | 501 | |
503 | - unset($lang); unset($group); // not used, but in old signature |
|
504 | - $this->rel_path = self::relPath($this->name=$name, $this->template_set=$template_set, |
|
505 | - $this->version=$version, $this->laod_via = $load_via); |
|
502 | + unset($lang); unset($group); // not used, but in old signature |
|
503 | + $this->rel_path = self::relPath($this->name = $name, $this->template_set = $template_set, |
|
504 | + $this->version = $version, $this->laod_via = $load_via); |
|
506 | 505 | //error_log(__METHOD__."('$name', '$template_set', '$lang', $group, '$version', '$load_via') rel_path=".array2string($this->rel_path)); |
507 | 506 | |
508 | 507 | $this->dom_id = $name; |
@@ -557,7 +556,7 @@ discard block |
||
557 | 556 | * @return mixed reference to attribute, usually NULL |
558 | 557 | * @deprecated use getElementAttribute($name, $attr) |
559 | 558 | */ |
560 | - public function &get_cell_attribute($name,$attr) |
|
559 | + public function &get_cell_attribute($name, $attr) |
|
561 | 560 | { |
562 | 561 | return self::getElementAttribute($name, $attr); |
563 | 562 | } |
@@ -571,7 +570,7 @@ discard block |
||
571 | 570 | * @return reference to attribute |
572 | 571 | * @deprecated use setElementAttribute($name, $attr, $val) |
573 | 572 | */ |
574 | - public function &set_cell_attribute($name,$attr,$val) |
|
573 | + public function &set_cell_attribute($name, $attr, $val) |
|
575 | 574 | { |
576 | 575 | return self::setElementAttribute($name, $attr, $val); |
577 | 576 | } |
@@ -584,7 +583,7 @@ discard block |
||
584 | 583 | * @return reference to attribute |
585 | 584 | * @deprecated use disableElement($name, $disabled=true) |
586 | 585 | */ |
587 | - public function disable_cells($name,$disabled=True) |
|
586 | + public function disable_cells($name, $disabled = True) |
|
588 | 587 | { |
589 | 588 | return self::disableElement($name, $disabled); |
590 | 589 | } |
@@ -600,23 +599,23 @@ discard block |
||
600 | 599 | * @param array $new |
601 | 600 | * @return array the merged array |
602 | 601 | */ |
603 | - public static function complete_array_merge($old,$new) |
|
602 | + public static function complete_array_merge($old, $new) |
|
604 | 603 | { |
605 | 604 | if (is_array($new)) |
606 | 605 | { |
607 | - if (!is_array($old)) $old = (array) $old; |
|
606 | + if (!is_array($old)) $old = (array)$old; |
|
608 | 607 | |
609 | - foreach($new as $k => $v) |
|
608 | + foreach ($new as $k => $v) |
|
610 | 609 | { |
611 | - if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
|
612 | - isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1]) || // or no associative array, eg. selecting multiple accounts |
|
610 | + if (!is_array($v) || !isset($old[$k]) || // no array or a new array |
|
611 | + isset($v[0]) && !is_array($v[0]) && isset($v[count($v) - 1]) || // or no associative array, eg. selecting multiple accounts |
|
613 | 612 | is_array($v) && count($v) == 0) // Empty array replacing non-empty |
614 | 613 | { |
615 | 614 | $old[$k] = $v; |
616 | 615 | } |
617 | 616 | else |
618 | 617 | { |
619 | - $old[$k] = self::complete_array_merge($old[$k],$v); |
|
618 | + $old[$k] = self::complete_array_merge($old[$k], $v); |
|
620 | 619 | } |
621 | 620 | } |
622 | 621 | } |
@@ -628,7 +627,7 @@ discard block |
||
628 | 627 | * |
629 | 628 | * @param array $content =null |
630 | 629 | */ |
631 | - public function debug(array $content=null) |
|
630 | + public function debug(array $content = null) |
|
632 | 631 | { |
633 | 632 | $GLOBALS['egw']->framework->render(print_r($content, true)); |
634 | 633 | } |
@@ -642,11 +641,11 @@ discard block |
||
642 | 641 | * @param int &$max_upload=null on return max. upload size in byte |
643 | 642 | * @return string |
644 | 643 | */ |
645 | - static function max_upload_size_message(&$max_upload=null) |
|
644 | + static function max_upload_size_message(&$max_upload = null) |
|
646 | 645 | { |
647 | 646 | $upload_max_filesize = ini_get('upload_max_filesize'); |
648 | 647 | $post_max_size = ini_get('post_max_size'); |
649 | - $max_upload = min(self::km2int($upload_max_filesize),self::km2int($post_max_size)-2800); |
|
648 | + $max_upload = min(self::km2int($upload_max_filesize), self::km2int($post_max_size) - 2800); |
|
650 | 649 | |
651 | 650 | return lang('Maximum size for uploads').': '.Vfs::hsize($max_upload). |
652 | 651 | " (php.ini: upload_max_filesize=$upload_max_filesize, post_max_size=$post_max_size)"; |
@@ -660,9 +659,9 @@ discard block |
||
660 | 659 | * @param boolean $readonly =true |
661 | 660 | * @return string |
662 | 661 | */ |
663 | - static public function number_format($number,$num_decimal_places=2,$readonly=true) |
|
662 | + static public function number_format($number, $num_decimal_places = 2, $readonly = true) |
|
664 | 663 | { |
665 | - static $dec_separator=null,$thousands_separator=null; |
|
664 | + static $dec_separator = null, $thousands_separator = null; |
|
666 | 665 | if (is_null($dec_separator)) |
667 | 666 | { |
668 | 667 | $dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
@@ -671,7 +670,7 @@ discard block |
||
671 | 670 | } |
672 | 671 | if ((string)$number === '') return ''; |
673 | 672 | |
674 | - return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : ''); |
|
673 | + return number_format(str_replace(' ', '', $number), $num_decimal_places, $dec_separator, $readonly ? $thousands_separator : ''); |
|
675 | 674 | } |
676 | 675 | |
677 | 676 | /** |
@@ -684,13 +683,13 @@ discard block |
||
684 | 683 | { |
685 | 684 | if (!is_numeric($size)) |
686 | 685 | { |
687 | - switch(strtolower(substr($size,-1))) |
|
686 | + switch (strtolower(substr($size, -1))) |
|
688 | 687 | { |
689 | 688 | case 'm': |
690 | - $size = 1024*1024*(int)$size; |
|
689 | + $size = 1024 * 1024 * (int)$size; |
|
691 | 690 | break; |
692 | 691 | case 'k': |
693 | - $size = 1024*(int)$size; |
|
692 | + $size = 1024 * (int)$size; |
|
694 | 693 | break; |
695 | 694 | } |
696 | 695 | } |
@@ -155,7 +155,7 @@ |
||
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 | { |
@@ -903,12 +903,12 @@ |
||
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; |
@@ -99,9 +99,9 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @param boolean $cloned =true true: object does NOT need to be cloned, false: to set attribute, set them in cloned object |
159 | 159 | * @return Template current object or clone, if any attribute was set |
160 | 160 | */ |
161 | - public function set_attrs($xml, $cloned=true) |
|
161 | + public function set_attrs($xml, $cloned = true) |
|
162 | 162 | { |
163 | 163 | $reader = self::get_reader($xml); |
164 | 164 | |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | |
176 | 176 | // read and set all attributes |
177 | 177 | $template = $this; |
178 | - while($reader->moveToNextAttribute()) |
|
178 | + while ($reader->moveToNextAttribute()) |
|
179 | 179 | { |
180 | 180 | if ($reader->name != 'id' && $template->attr[$reader->name] != $reader->value) |
181 | 181 | { |
182 | 182 | if (!$cloned) |
183 | 183 | { |
184 | 184 | $template = clone($this); |
185 | - $cloned = true; // only clone it once, otherwise we loose attributes! |
|
185 | + $cloned = true; // only clone it once, otherwise we loose attributes! |
|
186 | 186 | } |
187 | 187 | // $reader->value is an object and therefore assigned by reference |
188 | 188 | // this is important to not loose content when validating dynamic generated tabs as in settings! |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | if ($legacy_options && $reader->name == 'options') |
200 | 200 | { |
201 | 201 | $legacy_options = explode(',', $legacy_options); |
202 | - foreach(self::csv_split($value, count($legacy_options)) as $n => $val) |
|
202 | + foreach (self::csv_split($value, count($legacy_options)) as $n => $val) |
|
203 | 203 | { |
204 | 204 | if ($legacy_options[$n] && (string)$val !== '') $template->attrs[$legacy_options[$n]] = $val; |
205 | 205 | } |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | } |
209 | 209 | |
210 | 210 | // Add in anything in the modification array |
211 | - if(is_array(self::$request->modifications[$this->id])) |
|
211 | + if (is_array(self::$request->modifications[$this->id])) |
|
212 | 212 | { |
213 | - $this->attrs = array_merge($this->attrs,self::$request->modifications[$this->id]); |
|
213 | + $this->attrs = array_merge($this->attrs, self::$request->modifications[$this->id]); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return $template; |
@@ -231,32 +231,32 @@ discard block |
||
231 | 231 | * @param string $enclosure ='"' |
232 | 232 | * @return array |
233 | 233 | */ |
234 | - public static function csv_split($str,$num=null,$delimiter=',',$enclosure='"') |
|
234 | + public static function csv_split($str, $num = null, $delimiter = ',', $enclosure = '"') |
|
235 | 235 | { |
236 | - if (strpos($str,$enclosure) === false) |
|
236 | + if (strpos($str, $enclosure) === false) |
|
237 | 237 | { |
238 | - return is_null($num) ? explode($delimiter,$str) : explode($delimiter,$str,$num); // no need to run this more expensive code |
|
238 | + return is_null($num) ? explode($delimiter, $str) : explode($delimiter, $str, $num); // no need to run this more expensive code |
|
239 | 239 | } |
240 | - $parts = explode($delimiter,$str); |
|
241 | - for($n = 0; isset($parts[$n]); ++$n) |
|
240 | + $parts = explode($delimiter, $str); |
|
241 | + for ($n = 0; isset($parts[$n]); ++$n) |
|
242 | 242 | { |
243 | - $part =& $parts[$n]; |
|
243 | + $part = & $parts[$n]; |
|
244 | 244 | if ($part[0] === $enclosure) |
245 | 245 | { |
246 | - while (isset($parts[$n+1]) && substr($part,-1) !== $enclosure) |
|
246 | + while (isset($parts[$n + 1]) && substr($part, -1) !== $enclosure) |
|
247 | 247 | { |
248 | 248 | $part .= $delimiter.$parts[++$n]; |
249 | 249 | unset($parts[$n]); |
250 | 250 | } |
251 | - $part = substr(str_replace($enclosure.$enclosure,$enclosure,$part),1,-1); |
|
251 | + $part = substr(str_replace($enclosure.$enclosure, $enclosure, $part), 1, -1); |
|
252 | 252 | } |
253 | 253 | } |
254 | - $parts_renum = array_values($parts); // renumber the parts (in case we had to concat them) |
|
254 | + $parts_renum = array_values($parts); // renumber the parts (in case we had to concat them) |
|
255 | 255 | |
256 | 256 | if ($num > 0 && count($parts_renum) > $num) |
257 | 257 | { |
258 | - $parts_renum[$num-1] = implode($delimiter,array_slice($parts_renum,$num-1,count($parts_renum)-$num+1)); |
|
259 | - $parts_renum = array_slice($parts_renum,0,$num); |
|
258 | + $parts_renum[$num - 1] = implode($delimiter, array_slice($parts_renum, $num - 1, count($parts_renum) - $num + 1)); |
|
259 | + $parts_renum = array_slice($parts_renum, 0, $num); |
|
260 | 260 | } |
261 | 261 | return $parts_renum; |
262 | 262 | } |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | { |
284 | 284 | throw new Api\Exception\WrongParameter(__METHOD__."('$class', ".array2string($widgets).") $class is no subclass of ".__CLASS__.'!'); |
285 | 285 | } |
286 | - foreach((array)$widgets as $widget) |
|
286 | + foreach ((array)$widgets as $widget) |
|
287 | 287 | { |
288 | 288 | self::$widget_registry[$widget] = $class; |
289 | 289 | } |
@@ -308,19 +308,19 @@ discard block |
||
308 | 308 | |
309 | 309 | if (!$widget_registry) // not in instance cache --> rescan from filesystem |
310 | 310 | { |
311 | - foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path) |
|
311 | + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path) |
|
312 | 312 | { |
313 | - if(strpos($path, 'tests/') !== FALSE) |
|
313 | + if (strpos($path, 'tests/') !== FALSE) |
|
314 | 314 | { |
315 | 315 | continue; |
316 | 316 | } |
317 | - if(substr($path, -4) == '.php') |
|
317 | + if (substr($path, -4) == '.php') |
|
318 | 318 | { |
319 | 319 | try |
320 | 320 | { |
321 | 321 | include_once($path); |
322 | 322 | } |
323 | - catch(\Exception $e) |
|
323 | + catch (\Exception $e) |
|
324 | 324 | { |
325 | 325 | error_log($e->getMessage()); |
326 | 326 | } |
@@ -328,18 +328,18 @@ discard block |
||
328 | 328 | } |
329 | 329 | |
330 | 330 | // Use hook to load custom widgets from other apps |
331 | - $widgets = Api\Hooks::process('etemplate2_register_widgets',array(),true); |
|
332 | - foreach($widgets as $list) |
|
331 | + $widgets = Api\Hooks::process('etemplate2_register_widgets', array(), true); |
|
332 | + foreach ($widgets as $list) |
|
333 | 333 | { |
334 | 334 | if (is_array($list)) |
335 | 335 | { |
336 | - foreach($list as $class) |
|
336 | + foreach ($list as $class) |
|
337 | 337 | { |
338 | 338 | try |
339 | 339 | { |
340 | - class_exists($class); // trigger autoloader |
|
340 | + class_exists($class); // trigger autoloader |
|
341 | 341 | } |
342 | - catch(\Exception $e) |
|
342 | + catch (\Exception $e) |
|
343 | 343 | { |
344 | 344 | error_log($e->getMessage()); |
345 | 345 | } |
@@ -362,22 +362,22 @@ discard block |
||
362 | 362 | * @param string|XMLReader $xml |
363 | 363 | * @param string $id =null |
364 | 364 | */ |
365 | - public static function factory($type, $xml, $id=null) |
|
365 | + public static function factory($type, $xml, $id = null) |
|
366 | 366 | { |
367 | - $class_name =& self::$widget_registry[$type]; |
|
367 | + $class_name = & self::$widget_registry[$type]; |
|
368 | 368 | |
369 | 369 | if (!isset($class_name)) |
370 | 370 | { |
371 | - list($basetype) = explode('-',$type); |
|
371 | + list($basetype) = explode('-', $type); |
|
372 | 372 | if (//dont think this is used: !class_exists($class_name = 'etemplate_widget_'.str_replace('-','_',$type)) && |
373 | 373 | !class_exists($class_name = __CLASS__.'\\'.ucfirst($basetype)) && |
374 | 374 | // widgets supplied by application in class ${app}_widget_etemplate or ${app}_${subtype}_widget_etemplate |
375 | 375 | !(isset($GLOBALS['egw_info']['apps'][$basetype]) && |
376 | - (class_exists($class_name = str_replace('-','_',$type).'_etemplate_widget') || |
|
376 | + (class_exists($class_name = str_replace('-', '_', $type).'_etemplate_widget') || |
|
377 | 377 | class_exists($class_name = $basetype.'_etemplate_widget')))) |
378 | 378 | { |
379 | 379 | // Try for base type, it's probably better than the root |
380 | - if(self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
380 | + if (self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
381 | 381 | { |
382 | 382 | $class_name = self::$widget_registry[$basetype]; |
383 | 383 | } |
@@ -398,22 +398,22 @@ discard block |
||
398 | 398 | { |
399 | 399 | // Class in widget registry, but not loaded |
400 | 400 | // Try for a base class |
401 | - $subtypes = explode('-',$type); |
|
401 | + $subtypes = explode('-', $type); |
|
402 | 402 | $basetype = $subtypes[0]; |
403 | - $class_name = __CLASS__.'\\'.implode('\\',array_map('ucfirst',$subtypes)); |
|
404 | - if(!class_exists($class_name) && self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
403 | + $class_name = __CLASS__.'\\'.implode('\\', array_map('ucfirst', $subtypes)); |
|
404 | + if (!class_exists($class_name) && self::$widget_registry[$basetype] && self::$widget_registry[$basetype] != $class_name) |
|
405 | 405 | { |
406 | 406 | // Try for base type, it's probably better than the root |
407 | 407 | $class_name = self::$widget_registry[$basetype]; |
408 | 408 | } |
409 | - if(!class_exists($class_name)) |
|
409 | + if (!class_exists($class_name)) |
|
410 | 410 | { |
411 | 411 | // Fall back to widget class, we can not ignore it, as the widget may contain other widgets |
412 | 412 | $class_name = __CLASS__; |
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | - if(!$xml) |
|
416 | + if (!$xml) |
|
417 | 417 | { |
418 | 418 | if (empty($type)) $type = 'widget'; |
419 | 419 | $xml = "<$type id=\"$id\"/>"; |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | if ($type == 'template' && $id && ($template = Widget\Template::instance($id))) |
425 | 425 | { |
426 | 426 | // references can set different attributes like: class, span, content (namespace) |
427 | - return $template->set_attrs($xml, false); // false = need to clone template, if attributs are set! |
|
427 | + return $template->set_attrs($xml, false); // false = need to clone template, if attributs are set! |
|
428 | 428 | } |
429 | 429 | return new $class_name($xml); |
430 | 430 | } |
@@ -436,9 +436,9 @@ discard block |
||
436 | 436 | * @param string $type =null |
437 | 437 | * @return Widget|NULL |
438 | 438 | */ |
439 | - public function getElementById($id, $type=null) |
|
439 | + public function getElementById($id, $type = null) |
|
440 | 440 | { |
441 | - foreach($this->children as $child) |
|
441 | + foreach ($this->children as $child) |
|
442 | 442 | { |
443 | 443 | if ($child->id === $id && (is_null($type) || $child->type === $type)) |
444 | 444 | { |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | public function getElementsByType($type) |
462 | 462 | { |
463 | 463 | $elements = array(); |
464 | - foreach($this->children as $child) |
|
464 | + foreach ($this->children as $child) |
|
465 | 465 | { |
466 | 466 | if ($child->type === $type) |
467 | 467 | { |
@@ -481,14 +481,14 @@ discard block |
||
481 | 481 | * @param array $params =array('') parameter(s) first parameter has to be the cname, second $expand! |
482 | 482 | * @param boolean $respect_disabled =false false (default): ignore disabled, true: method is NOT run for disabled widgets AND their children |
483 | 483 | */ |
484 | - public function run($method_name, $params=array(''), $respect_disabled=false) |
|
484 | + public function run($method_name, $params = array(''), $respect_disabled = false) |
|
485 | 485 | { |
486 | 486 | // maintain $expand array name-expansion |
487 | 487 | $cname = $params[0]; |
488 | - $expand =& $params[1]; |
|
488 | + $expand = & $params[1]; |
|
489 | 489 | if ($expand['cname'] && $expand['cname'] !== $cname) |
490 | 490 | { |
491 | - $expand['cont'] =& self::get_array(self::$request->content, $cname); |
|
491 | + $expand['cont'] = & self::get_array(self::$request->content, $cname); |
|
492 | 492 | $expand['cname'] = $cname; |
493 | 493 | } |
494 | 494 | if ($respect_disabled && ($disabled = $this->attrs['disabled'] && self::check_disabled($this->attrs['disabled'], $expand))) |
@@ -501,22 +501,22 @@ discard block |
||
501 | 501 | // Some parameter checking to avoid fatal errors |
502 | 502 | $call = true; |
503 | 503 | $method = new ReflectionMethod($this, $method_name); |
504 | - foreach($method->getParameters() as $index => $param) |
|
504 | + foreach ($method->getParameters() as $index => $param) |
|
505 | 505 | { |
506 | - if(!$param->isOptional() && !array_key_exists($index,$params)) |
|
506 | + if (!$param->isOptional() && !array_key_exists($index, $params)) |
|
507 | 507 | { |
508 | 508 | error_log("Missing required parameter {$param->getPosition()}: {$param->getName()}"); |
509 | 509 | $call = false; |
510 | 510 | } |
511 | - if($param->isArray() && !is_array($params[$index])) |
|
511 | + if ($param->isArray() && !is_array($params[$index])) |
|
512 | 512 | { |
513 | 513 | error_log("$method_name expects an array for {$param->getPosition()}: {$param->getName()}"); |
514 | 514 | $params[$index] = (array)$params[$index]; |
515 | 515 | } |
516 | 516 | } |
517 | - if($call) call_user_func_array(array($this, $method_name), $params); |
|
517 | + if ($call) call_user_func_array(array($this, $method_name), $params); |
|
518 | 518 | } |
519 | - foreach($this->children as $child) |
|
519 | + foreach ($this->children as $child) |
|
520 | 520 | { |
521 | 521 | // If type has something that can be expanded, we need to expand it so the correct method is run |
522 | 522 | $this->expand_widget($child, $expand); |
@@ -533,13 +533,13 @@ discard block |
||
533 | 533 | */ |
534 | 534 | protected function expand_widget(Widget &$child, array &$expand) |
535 | 535 | { |
536 | - if(strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false) |
|
536 | + if (strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false) |
|
537 | 537 | { |
538 | - $type = self::expand_name($child->attrs['type'],$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
539 | - $id = self::expand_name($child->id,$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
538 | + $type = self::expand_name($child->attrs['type'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
539 | + $id = self::expand_name($child->id, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
|
540 | 540 | $attrs = $child->attrs; |
541 | 541 | unset($attrs['type']); |
542 | - $expanded_child = self::factory($type, false,$id); |
|
542 | + $expanded_child = self::factory($type, false, $id); |
|
543 | 543 | $expanded_child->id = $id; |
544 | 544 | $expanded_child->type = $type; |
545 | 545 | $expanded_child->attrs = $attrs + array('type' => $type); |
@@ -562,14 +562,14 @@ discard block |
||
562 | 562 | { |
563 | 563 | if (($not = $disabled[0] == '!')) |
564 | 564 | { |
565 | - $disabled = substr($disabled,1); |
|
565 | + $disabled = substr($disabled, 1); |
|
566 | 566 | } |
567 | - list($value,$check) = $vals = explode('=',$disabled); |
|
567 | + list($value, $check) = $vals = explode('=', $disabled); |
|
568 | 568 | |
569 | 569 | // use expand_name to be able to use @ or $ |
570 | 570 | $val = self::expand_name($value, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
571 | 571 | $check_val = self::expand_name($check, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
572 | - $result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val,$val) : $val == $check_val); |
|
572 | + $result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val, $val) : $val == $check_val); |
|
573 | 573 | if ($not) $result = !$result; |
574 | 574 | |
575 | 575 | //error_log(__METHOD__."('".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False')); |
@@ -611,33 +611,33 @@ discard block |
||
611 | 611 | * "del[$cont[id]]" expands to "del[123]" if $cont = array('id' => 123) |
612 | 612 | * @return string the expanded name |
613 | 613 | */ |
614 | - protected static function expand_name($name,$c,$row,$c_='',$row_='',$cont='') |
|
614 | + protected static function expand_name($name, $c, $row, $c_ = '', $row_ = '', $cont = '') |
|
615 | 615 | { |
616 | 616 | $is_index_in_content = $name[0] == '@'; |
617 | - if (($pos_var=strpos($name,'$')) !== false) |
|
617 | + if (($pos_var = strpos($name, '$')) !== false) |
|
618 | 618 | { |
619 | 619 | if (!$cont) |
620 | 620 | { |
621 | 621 | $cont = array(); |
622 | 622 | } |
623 | 623 | if (!is_numeric($c)) $c = self::chrs2num($c); |
624 | - $col = self::num2chrs($c-1); // $c-1 to get: 0:'@', 1:'A', ... |
|
625 | - if (is_numeric($c_)) $col_ = self::num2chrs($c_-1); |
|
624 | + $col = self::num2chrs($c - 1); // $c-1 to get: 0:'@', 1:'A', ... |
|
625 | + if (is_numeric($c_)) $col_ = self::num2chrs($c_ - 1); |
|
626 | 626 | $row_cont = $cont[$row]; |
627 | 627 | $col_row_cont = $cont[$col.$row]; |
628 | 628 | |
629 | - eval('$name = "'.str_replace('"','\\"',$name).'";'); |
|
630 | - unset($col_, $row_, $row_cont, $col_row_cont); // quiten IDE warning about used vars, they might be used in above eval! |
|
629 | + eval('$name = "'.str_replace('"', '\\"', $name).'";'); |
|
630 | + unset($col_, $row_, $row_cont, $col_row_cont); // quiten IDE warning about used vars, they might be used in above eval! |
|
631 | 631 | } |
632 | 632 | if ($is_index_in_content) |
633 | 633 | { |
634 | 634 | if ($name[1] == '@' && is_array(self::$request->content)) |
635 | 635 | { |
636 | - $name = self::get_array(self::$request->content,substr($name,2)); |
|
636 | + $name = self::get_array(self::$request->content, substr($name, 2)); |
|
637 | 637 | } |
638 | - elseif(is_array($cont)) |
|
638 | + elseif (is_array($cont)) |
|
639 | 639 | { |
640 | - $name = self::get_array($cont,substr($name,1)); |
|
640 | + $name = self::get_array($cont, substr($name, 1)); |
|
641 | 641 | } |
642 | 642 | else |
643 | 643 | { |
@@ -659,11 +659,11 @@ discard block |
||
659 | 659 | $min = ord('A'); |
660 | 660 | $max = ord('Z') - $min + 1; |
661 | 661 | |
662 | - $num = 1+ord($chrs{0})-$min; |
|
662 | + $num = 1 + ord($chrs{0}) - $min; |
|
663 | 663 | if (strlen($chrs) > 1) |
664 | 664 | { |
665 | 665 | $num *= 1 + $max - $min; |
666 | - $num += 1+ord($chrs{1})-$min; |
|
666 | + $num += 1 + ord($chrs{1}) - $min; |
|
667 | 667 | } |
668 | 668 | return $num; |
669 | 669 | } |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | */ |
695 | 695 | public function __toString() |
696 | 696 | { |
697 | - return '['.get_class($this).'] ' . |
|
697 | + return '['.get_class($this).'] '. |
|
698 | 698 | $this->type.($this->attrs['type'] && $this->attrs['type'] != $this->type ? '('.$this->attrs['type'].')' : '').'#'.$this->id; |
699 | 699 | } |
700 | 700 | |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | */ |
704 | 704 | public function __clone() |
705 | 705 | { |
706 | - foreach($this->children as $child_num => $child) { |
|
706 | + foreach ($this->children as $child_num => $child) { |
|
707 | 707 | $this->children[$child_num] = clone $child; |
708 | 708 | } |
709 | 709 | } |
@@ -714,16 +714,16 @@ discard block |
||
714 | 714 | * @param string $indent ='' |
715 | 715 | * @return string |
716 | 716 | */ |
717 | - public function toXml($indent='') |
|
717 | + public function toXml($indent = '') |
|
718 | 718 | { |
719 | 719 | echo "$indent<$this->type"; |
720 | 720 | if ($this->id) echo ' id="'.htmlspecialchars($this->id).'"'; |
721 | - foreach($this->attrs as $name => $value) |
|
721 | + foreach ($this->attrs as $name => $value) |
|
722 | 722 | { |
723 | 723 | if ($name == 'options' && $this->legacy_options && (!is_array($this->legacy_options) || |
724 | 724 | isset($this->legacy_options[$this->attrs['type'] ? $this->attrs['type'] : $this->type]))) |
725 | 725 | { |
726 | - continue; // do NOT output already converted legacy options |
|
726 | + continue; // do NOT output already converted legacy options |
|
727 | 727 | } |
728 | 728 | echo ' '.$name.'="'.htmlspecialchars($value).'"'; |
729 | 729 | } |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | if ($this->children) |
733 | 733 | { |
734 | 734 | echo ">\n"; |
735 | - foreach($this->children as $child) |
|
735 | + foreach ($this->children as $child) |
|
736 | 736 | { |
737 | 737 | $child->toXml($indent."\t"); |
738 | 738 | } |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | * @param array $expand =null values for keys 'c', 'row', 'c_', 'row_', 'cont' |
756 | 756 | * @return string complete form-name |
757 | 757 | */ |
758 | - static function form_name($cname,$name,array $expand=null) |
|
758 | + static function form_name($cname, $name, array $expand = null) |
|
759 | 759 | { |
760 | 760 | if ($expand && !empty($name)) |
761 | 761 | { |
@@ -763,18 +763,18 @@ discard block |
||
763 | 763 | } |
764 | 764 | if (count($name_parts = explode('[', $name, 2)) > 1) |
765 | 765 | { |
766 | - $name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1],0,-1))); |
|
766 | + $name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1], 0, -1))); |
|
767 | 767 | } |
768 | 768 | if (!empty($cname)) |
769 | 769 | { |
770 | - array_unshift($name_parts,$cname); |
|
770 | + array_unshift($name_parts, $cname); |
|
771 | 771 | } |
772 | 772 | $form_name = array_shift($name_parts); |
773 | 773 | if (count($name_parts)) |
774 | 774 | { |
775 | 775 | // RB: not sure why this business with entity encoding for square brakets, it messes up validation |
776 | 776 | //$form_name .= '['.implode('][',$name_parts).']'; |
777 | - $form_name .= '['.implode('][',$name_parts).']'; |
|
777 | + $form_name .= '['.implode('][', $name_parts).']'; |
|
778 | 778 | } |
779 | 779 | return $form_name; |
780 | 780 | } |
@@ -791,36 +791,36 @@ discard block |
||
791 | 791 | * @param bool $skip_empty returns false if $idx is not present in $arr |
792 | 792 | * @return mixed reference to $arr[$idx] or null if $idx is not set and not $reference_into |
793 | 793 | */ |
794 | - static function &get_array(&$arr,$_idx,$reference_into=False,$skip_empty=False) |
|
794 | + static function &get_array(&$arr, $_idx, $reference_into = False, $skip_empty = False) |
|
795 | 795 | { |
796 | 796 | if (!is_array($arr)) |
797 | 797 | { |
798 | 798 | throw new Api\Exception\AssertionFailed(__METHOD__."(\$arr,'$_idx',$reference_into,$skip_empty) \$arr is no array!"); |
799 | 799 | } |
800 | - if (is_object($_idx)) return false; // given an error in php5.2 |
|
800 | + if (is_object($_idx)) return false; // given an error in php5.2 |
|
801 | 801 | |
802 | 802 | // Make sure none of these are left |
803 | - $idx = str_replace(array('[',']'), array('[',']'), $_idx); |
|
803 | + $idx = str_replace(array('[', ']'), array('[', ']'), $_idx); |
|
804 | 804 | |
805 | 805 | // Handle things expecting arrays - ends in [] |
806 | - if(substr($idx,-2) == "[]") |
|
806 | + if (substr($idx, -2) == "[]") |
|
807 | 807 | { |
808 | - $idx = substr($idx,0,-2); |
|
808 | + $idx = substr($idx, 0, -2); |
|
809 | 809 | } |
810 | 810 | |
811 | 811 | if (count($idxs = explode('[', $idx, 2)) > 1) |
812 | 812 | { |
813 | - $idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1],0,-1))); |
|
813 | + $idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1], 0, -1))); |
|
814 | 814 | } |
815 | 815 | $pos = &$arr; |
816 | - foreach($idxs as $idx) |
|
816 | + foreach ($idxs as $idx) |
|
817 | 817 | { |
818 | 818 | if (!is_array($pos) && (!$reference_into || $reference_into && isset($pos))) |
819 | 819 | { |
820 | 820 | //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()); |
821 | 821 | return null; |
822 | 822 | } |
823 | - if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null; |
|
823 | + if ($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null; |
|
824 | 824 | $pos = &$pos[$idx]; |
825 | 825 | } |
826 | 826 | return $pos; |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | */ |
839 | 839 | static function set_array(&$_arr, $_idx, $_value) |
840 | 840 | { |
841 | - $ref =& self::get_array($_arr, $_idx, true); |
|
841 | + $ref = & self::get_array($_arr, $_idx, true); |
|
842 | 842 | if (true) $ref = $_value; |
843 | 843 | } |
844 | 844 | |
@@ -852,7 +852,7 @@ discard block |
||
852 | 852 | * @param string $form_name =null form_name, to not calculate him again |
853 | 853 | * @return boolean |
854 | 854 | */ |
855 | - public function is_readonly($cname='', $form_name=null) |
|
855 | + public function is_readonly($cname = '', $form_name = null) |
|
856 | 856 | { |
857 | 857 | if (!isset($form_name)) |
858 | 858 | { |
@@ -862,11 +862,11 @@ discard block |
||
862 | 862 | $form_name = self::form_name($cname, $this->id, $expand); |
863 | 863 | } |
864 | 864 | $readonly = $this->attrs['readonly'] || self::$request->readonlys[$form_name] || |
865 | - self::get_array(self::$request->readonlys,$form_name) === true || |
|
865 | + self::get_array(self::$request->readonlys, $form_name) === true || |
|
866 | 866 | isset(self::$request->readonlys['__ALL__']) && ( |
867 | 867 | // Exceptions to all |
868 | 868 | self::$request->readonlys[$form_name] !== false && |
869 | - self::get_array(self::$request->readonlys,$form_name) !== false |
|
869 | + self::get_array(self::$request->readonlys, $form_name) !== false |
|
870 | 870 | ); |
871 | 871 | |
872 | 872 | //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)); |
@@ -886,12 +886,12 @@ discard block |
||
886 | 886 | * @param string|boolean $error error-message already translated or false to reset all existing error for given name |
887 | 887 | * @param string $cname =null set it to '', if the name is already a form-name, defaults to self::$name_vars |
888 | 888 | */ |
889 | - public static function set_validation_error($name,$error,$cname=null) |
|
889 | + public static function set_validation_error($name, $error, $cname = null) |
|
890 | 890 | { |
891 | 891 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
892 | 892 | //error_log(__METHOD__."('$name','$error','$cname') ".function_backtrace()); |
893 | 893 | |
894 | - if ($cname) $name = self::form_name($cname,$name); |
|
894 | + if ($cname) $name = self::form_name($cname, $name); |
|
895 | 895 | |
896 | 896 | if ($error === false) |
897 | 897 | { |
@@ -914,18 +914,18 @@ discard block |
||
914 | 914 | * @param string $cname =null name-prefix, which need to be ignored, default self::$name_vars |
915 | 915 | * @return boolean true if there are not ignored validation errors, false otherwise |
916 | 916 | */ |
917 | - public static function validation_errors($ignore_validation='',$cname='') |
|
917 | + public static function validation_errors($ignore_validation = '', $cname = '') |
|
918 | 918 | { |
919 | 919 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
920 | 920 | //echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors); |
921 | 921 | if (!$ignore_validation) return count(self::$validation_errors) > 0; |
922 | 922 | |
923 | - foreach(array_values(self::$validation_errors) as $name) |
|
923 | + foreach (array_values(self::$validation_errors) as $name) |
|
924 | 924 | { |
925 | - if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name); |
|
925 | + if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/', '\\1\\2', $name); |
|
926 | 926 | |
927 | 927 | // treat $ignoare_validation only as regular expression, if it starts with a slash |
928 | - if ($ignore_validation[0] == '/' && !preg_match($ignore_validation,$name) || |
|
928 | + if ($ignore_validation[0] == '/' && !preg_match($ignore_validation, $name) || |
|
929 | 929 | $ignore_validation[0] != '/' && $ignore_validation != $name) |
930 | 930 | { |
931 | 931 | //echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') name='$name' ($error) not ignored!!!</p>\n"; |
@@ -962,14 +962,14 @@ discard block |
||
962 | 962 | * @param mixed $val if not NULL sets attribute else returns it |
963 | 963 | * @return reference to attribute |
964 | 964 | */ |
965 | - public static function &setElementAttribute($name,$attr,$val) |
|
965 | + public static function &setElementAttribute($name, $attr, $val) |
|
966 | 966 | { |
967 | 967 | //error_log(__METHOD__."('$name', '$attr', ...) request=".get_class(self::$request).", response=".get_class(self::$response).function_backtrace()); |
968 | - $ref =& self::$request->modifications[$name][$attr]; |
|
969 | - if(self::$request && self::$response) |
|
968 | + $ref = & self::$request->modifications[$name][$attr]; |
|
969 | + if (self::$request && self::$response) |
|
970 | 970 | { |
971 | 971 | // In an AJAX response - automatically add |
972 | - self::$response->generic('assign',array( |
|
972 | + self::$response->generic('assign', array( |
|
973 | 973 | 'etemplate_exec_id' => self::$request->id(), |
974 | 974 | 'id' => $name, |
975 | 975 | 'key' => $attr, |
@@ -992,7 +992,7 @@ discard block |
||
992 | 992 | * @param boolean $disabled =true disable or enable a cell, default true=disable |
993 | 993 | * @return reference to attribute |
994 | 994 | */ |
995 | - public function disableElement($name,$disabled=True) |
|
995 | + public function disableElement($name, $disabled = True) |
|
996 | 996 | { |
997 | 997 | return self::setElementAttribute($name, 'disabled', $disabled); |
998 | 998 | } |
@@ -100,7 +100,9 @@ discard block |
||
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 |
||
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 | } |
@@ -201,7 +204,10 @@ discard block |
||
201 | 204 | $legacy_options = explode(',', $legacy_options); |
202 | 205 | foreach(self::csv_split($value, count($legacy_options)) as $n => $val) |
203 | 206 | { |
204 | - if ($legacy_options[$n] && (string)$val !== '') $template->attrs[$legacy_options[$n]] = $val; |
|
207 | + if ($legacy_options[$n] && (string)$val !== '') |
|
208 | + { |
|
209 | + $template->attrs[$legacy_options[$n]] = $val; |
|
210 | + } |
|
205 | 211 | } |
206 | 212 | } |
207 | 213 | } |
@@ -306,13 +312,16 @@ discard block |
||
306 | 312 | |
307 | 313 | $widget_registry = Api\Cache::getInstance('etemplate', 'widget_registry'); |
308 | 314 | |
309 | - if (!$widget_registry) // not in instance cache --> rescan from filesystem |
|
315 | + if (!$widget_registry) |
|
316 | + { |
|
317 | + // not in instance cache --> rescan from filesystem |
|
310 | 318 | { |
311 | 319 | foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__.'/Widget')) as $path) |
312 | 320 | { |
313 | 321 | if(strpos($path, 'tests/') !== FALSE) |
314 | 322 | { |
315 | 323 | continue; |
324 | + } |
|
316 | 325 | } |
317 | 326 | if(substr($path, -4) == '.php') |
318 | 327 | { |
@@ -415,7 +424,10 @@ discard block |
||
415 | 424 | |
416 | 425 | if(!$xml) |
417 | 426 | { |
418 | - if (empty($type)) $type = 'widget'; |
|
427 | + if (empty($type)) |
|
428 | + { |
|
429 | + $type = 'widget'; |
|
430 | + } |
|
419 | 431 | $xml = "<$type id=\"$id\"/>"; |
420 | 432 | } |
421 | 433 | //error_log(__METHOD__."('$type', ..., '$id') using $class_name"); |
@@ -514,7 +526,10 @@ discard block |
||
514 | 526 | $params[$index] = (array)$params[$index]; |
515 | 527 | } |
516 | 528 | } |
517 | - if($call) call_user_func_array(array($this, $method_name), $params); |
|
529 | + if($call) |
|
530 | + { |
|
531 | + call_user_func_array(array($this, $method_name), $params); |
|
532 | + } |
|
518 | 533 | } |
519 | 534 | foreach($this->children as $child) |
520 | 535 | { |
@@ -570,7 +585,10 @@ discard block |
||
570 | 585 | $val = self::expand_name($value, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
571 | 586 | $check_val = self::expand_name($check, $expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']); |
572 | 587 | $result = count($vals) == 1 ? $val != '' : ($check_val[0] == '/' ? preg_match($check_val,$val) : $val == $check_val); |
573 | - if ($not) $result = !$result; |
|
588 | + if ($not) |
|
589 | + { |
|
590 | + $result = !$result; |
|
591 | + } |
|
574 | 592 | |
575 | 593 | //error_log(__METHOD__."('".($not?'!':'')."$disabled' = '$val' ".(count($vals) == 1 ? '' : ($not?'!':'=')."= '$check_val'")." = ".($result?'True':'False')); |
576 | 594 | return $result; |
@@ -620,9 +638,15 @@ discard block |
||
620 | 638 | { |
621 | 639 | $cont = array(); |
622 | 640 | } |
623 | - if (!is_numeric($c)) $c = self::chrs2num($c); |
|
641 | + if (!is_numeric($c)) |
|
642 | + { |
|
643 | + $c = self::chrs2num($c); |
|
644 | + } |
|
624 | 645 | $col = self::num2chrs($c-1); // $c-1 to get: 0:'@', 1:'A', ... |
625 | - if (is_numeric($c_)) $col_ = self::num2chrs($c_-1); |
|
646 | + if (is_numeric($c_)) |
|
647 | + { |
|
648 | + $col_ = self::num2chrs($c_-1); |
|
649 | + } |
|
626 | 650 | $row_cont = $cont[$row]; |
627 | 651 | $col_row_cont = $cont[$col.$row]; |
628 | 652 | |
@@ -703,7 +727,8 @@ discard block |
||
703 | 727 | */ |
704 | 728 | public function __clone() |
705 | 729 | { |
706 | - foreach($this->children as $child_num => $child) { |
|
730 | + foreach($this->children as $child_num => $child) |
|
731 | + { |
|
707 | 732 | $this->children[$child_num] = clone $child; |
708 | 733 | } |
709 | 734 | } |
@@ -717,7 +742,10 @@ discard block |
||
717 | 742 | public function toXml($indent='') |
718 | 743 | { |
719 | 744 | echo "$indent<$this->type"; |
720 | - if ($this->id) echo ' id="'.htmlspecialchars($this->id).'"'; |
|
745 | + if ($this->id) |
|
746 | + { |
|
747 | + echo ' id="'.htmlspecialchars($this->id).'"'; |
|
748 | + } |
|
721 | 749 | foreach($this->attrs as $name => $value) |
722 | 750 | { |
723 | 751 | if ($name == 'options' && $this->legacy_options && (!is_array($this->legacy_options) || |
@@ -797,7 +825,11 @@ discard block |
||
797 | 825 | { |
798 | 826 | throw new Api\Exception\AssertionFailed(__METHOD__."(\$arr,'$_idx',$reference_into,$skip_empty) \$arr is no array!"); |
799 | 827 | } |
800 | - if (is_object($_idx)) return false; // given an error in php5.2 |
|
828 | + if (is_object($_idx)) |
|
829 | + { |
|
830 | + return false; |
|
831 | + } |
|
832 | + // given an error in php5.2 |
|
801 | 833 | |
802 | 834 | // Make sure none of these are left |
803 | 835 | $idx = str_replace(array('[',']'), array('[',']'), $_idx); |
@@ -820,7 +852,10 @@ discard block |
||
820 | 852 | //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()); |
821 | 853 | return null; |
822 | 854 | } |
823 | - if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) return null; |
|
855 | + if($skip_empty && (!is_array($pos) || !isset($pos[$idx]))) |
|
856 | + { |
|
857 | + return null; |
|
858 | + } |
|
824 | 859 | $pos = &$pos[$idx]; |
825 | 860 | } |
826 | 861 | return $pos; |
@@ -839,7 +874,10 @@ discard block |
||
839 | 874 | static function set_array(&$_arr, $_idx, $_value) |
840 | 875 | { |
841 | 876 | $ref =& self::get_array($_arr, $_idx, true); |
842 | - if (true) $ref = $_value; |
|
877 | + if (true) |
|
878 | + { |
|
879 | + $ref = $_value; |
|
880 | + } |
|
843 | 881 | } |
844 | 882 | |
845 | 883 | /** |
@@ -891,7 +929,10 @@ discard block |
||
891 | 929 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
892 | 930 | //error_log(__METHOD__."('$name','$error','$cname') ".function_backtrace()); |
893 | 931 | |
894 | - if ($cname) $name = self::form_name($cname,$name); |
|
932 | + if ($cname) |
|
933 | + { |
|
934 | + $name = self::form_name($cname,$name); |
|
935 | + } |
|
895 | 936 | |
896 | 937 | if ($error === false) |
897 | 938 | { |
@@ -918,11 +959,17 @@ discard block |
||
918 | 959 | { |
919 | 960 | // not yet used: if (is_null($cname)) $cname = self::$name_vars; |
920 | 961 | //echo "<p>uietemplate::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors); |
921 | - if (!$ignore_validation) return count(self::$validation_errors) > 0; |
|
962 | + if (!$ignore_validation) |
|
963 | + { |
|
964 | + return count(self::$validation_errors) > 0; |
|
965 | + } |
|
922 | 966 | |
923 | 967 | foreach(array_values(self::$validation_errors) as $name) |
924 | 968 | { |
925 | - if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name); |
|
969 | + if ($cname) |
|
970 | + { |
|
971 | + $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name); |
|
972 | + } |
|
926 | 973 | |
927 | 974 | // treat $ignoare_validation only as regular expression, if it starts with a slash |
928 | 975 | if ($ignore_validation[0] == '/' && !preg_match($ignore_validation,$name) || |
@@ -979,7 +1026,10 @@ discard block |
||
979 | 1026 | self::$request->unset_to_process(''); |
980 | 1027 | //error_log(__METHOD__."('$name', '$attr', ...) ".function_backtrace()); |
981 | 1028 | } |
982 | - if (!is_null($val)) $ref = $val; |
|
1029 | + if (!is_null($val)) |
|
1030 | + { |
|
1031 | + $ref = $val; |
|
1032 | + } |
|
983 | 1033 | |
984 | 1034 | //error_log(__METHOD__."('$name', '$attr', ".array2string($val).')'); |
985 | 1035 | return $ref; |
@@ -42,7 +42,7 @@ |
||
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 | { |
@@ -44,7 +44,7 @@ discard block |
||
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 |
||
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 |
||
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)) |
@@ -56,7 +56,11 @@ discard block |
||
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 |
||
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 |
||
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 | { |
@@ -101,7 +101,6 @@ discard block |
||
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 |
||
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 | { |
@@ -88,7 +88,7 @@ |
||
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 |
@@ -90,12 +90,18 @@ discard block |
||
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 |
||
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']) |
111 | 121 | { |
@@ -145,9 +155,12 @@ discard block |
||
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($value) |
@@ -232,10 +245,13 @@ discard block |
||
232 | 245 | // Not null, blank |
233 | 246 | $value = ''; |
234 | 247 | } |
235 | - elseif ($date && empty($this->attrs['dataformat'])) // integer timestamp |
|
248 | + elseif ($date && empty($this->attrs['dataformat'])) |
|
249 | + { |
|
250 | + // integer timestamp |
|
236 | 251 | { |
237 | 252 | $valid = $date->format('ts'); |
238 | 253 | } |
254 | + } |
|
239 | 255 | // string with formatting letters like for php's date() method |
240 | 256 | elseif ($date && ($valid = $date->format($this->attrs['dataformat']))) |
241 | 257 | { |
@@ -60,17 +60,17 @@ discard block |
||
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 |
||
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 |
||
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']) |
111 | 111 | { |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | { |
116 | 116 | $date = new Api\DateTime($value); |
117 | 117 | } |
118 | - if($this->type == 'date-timeonly' && $date) |
|
118 | + if ($this->type == 'date-timeonly' && $date) |
|
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,34 +141,34 @@ discard block |
||
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 | - if($value) |
|
153 | + if ($value) |
|
154 | 154 | { |
155 | 155 | try |
156 | 156 | { |
157 | 157 | $date = new Api\DateTime($value); |
158 | 158 | } |
159 | - catch(\Exception $e) |
|
159 | + catch (\Exception $e) |
|
160 | 160 | { |
161 | 161 | unset($e); |
162 | 162 | $date = null; |
163 | 163 | $value = ''; |
164 | 164 | // this is not really a user error, but one of the clientside engine |
165 | - self::set_validation_error($form_name,lang("'%1' is not a valid date !!!", $value).' '.$this->dataformat); |
|
165 | + self::set_validation_error($form_name, lang("'%1' is not a valid date !!!", $value).' '.$this->dataformat); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | 169 | if ((string)$value === '' && $this->attrs['needed']) |
170 | 170 | { |
171 | - self::set_validation_error($form_name,lang('Field must not be empty !!!')); |
|
171 | + self::set_validation_error($form_name, lang('Field must not be empty !!!')); |
|
172 | 172 | } |
173 | 173 | elseif (is_null($value)) |
174 | 174 | { |
@@ -181,53 +181,53 @@ discard block |
||
181 | 181 | |
182 | 182 | if (!empty($this->attrs['min'])) |
183 | 183 | { |
184 | - if(is_numeric($this->attrs['min'])) |
|
184 | + if (is_numeric($this->attrs['min'])) |
|
185 | 185 | { |
186 | - $min = new Api\DateTime(strtotime( $this->attrs['min'] . 'days')); |
|
186 | + $min = new Api\DateTime(strtotime($this->attrs['min'].'days')); |
|
187 | 187 | } |
188 | - elseif (preg_match('/[+-][[:digit:]]+[ymwd]/',$this->attrs['min'])) |
|
188 | + elseif (preg_match('/[+-][[:digit:]]+[ymwd]/', $this->attrs['min'])) |
|
189 | 189 | { |
190 | 190 | // Relative date with periods |
191 | - $min = new Api\DateTime(strtotime(str_replace(array('y','m','w','d'), array('years','months','weeks','days'), $this->attrs['min']))); |
|
191 | + $min = new Api\DateTime(strtotime(str_replace(array('y', 'm', 'w', 'd'), array('years', 'months', 'weeks', 'days'), $this->attrs['min']))); |
|
192 | 192 | } |
193 | 193 | else |
194 | 194 | { |
195 | 195 | $min = new Api\DateTime(strtotime($this->attrs['min'])); |
196 | 196 | } |
197 | - if($date < $min) |
|
197 | + if ($date < $min) |
|
198 | 198 | { |
199 | - self::set_validation_error($form_name,lang( |
|
199 | + self::set_validation_error($form_name, lang( |
|
200 | 200 | "Value has to be at least '%1' !!!", |
201 | 201 | $min->format($this->type != 'date') |
202 | - ),''); |
|
202 | + ), ''); |
|
203 | 203 | $value = $min; |
204 | 204 | } |
205 | 205 | } |
206 | 206 | if (!empty($this->attrs['max'])) |
207 | 207 | { |
208 | - if(is_numeric($this->attrs['max'])) |
|
208 | + if (is_numeric($this->attrs['max'])) |
|
209 | 209 | { |
210 | - $max = new Api\DateTime(strtotime( $this->attrs['max'] . 'days')); |
|
210 | + $max = new Api\DateTime(strtotime($this->attrs['max'].'days')); |
|
211 | 211 | } |
212 | - elseif (preg_match('/[+-][[:digit:]]+[ymwd]/',$this->attrs['max'])) |
|
212 | + elseif (preg_match('/[+-][[:digit:]]+[ymwd]/', $this->attrs['max'])) |
|
213 | 213 | { |
214 | 214 | // Relative date with periods |
215 | - $max = new Api\DateTime(strtotime(str_replace(array('y','m','w','d'), array('years','months','weeks','days'), $this->attrs['max']))); |
|
215 | + $max = new Api\DateTime(strtotime(str_replace(array('y', 'm', 'w', 'd'), array('years', 'months', 'weeks', 'days'), $this->attrs['max']))); |
|
216 | 216 | } |
217 | 217 | else |
218 | 218 | { |
219 | 219 | $max = new Api\DateTime(strtotime($this->attrs['max'])); |
220 | 220 | } |
221 | - if($date > $max) |
|
221 | + if ($date > $max) |
|
222 | 222 | { |
223 | - self::set_validation_error($form_name,lang( |
|
223 | + self::set_validation_error($form_name, lang( |
|
224 | 224 | "Value has to be at maximum '%1' !!!", |
225 | 225 | $max->format($this->type != 'date') |
226 | - ),''); |
|
226 | + ), ''); |
|
227 | 227 | $value = $max; |
228 | 228 | } |
229 | 229 | } |
230 | - if(!$value) |
|
230 | + if (!$value) |
|
231 | 231 | { |
232 | 232 | // Not null, blank |
233 | 233 | $value = ''; |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | else |
245 | 245 | { |
246 | 246 | // this is not really a user error, but one of the clientside engine |
247 | - self::set_validation_error($form_name,lang("'%1' is not a valid date !!!", $value).' '.$this->dataformat); |
|
247 | + self::set_validation_error($form_name, lang("'%1' is not a valid date !!!", $value).' '.$this->dataformat); |
|
248 | 248 | } |
249 | 249 | //error_log("$this : ($valid)" . Api\DateTime::to($valid)); |
250 | 250 | } |