@@ -702,6 +702,10 @@ discard block |
||
| 702 | 702 | |
| 703 | 703 | |
| 704 | 704 | // returns queryID or false |
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * @param boolean $inputarr |
|
| 708 | + */ |
|
| 705 | 709 | function _query($sql,$inputarr) |
| 706 | 710 | { |
| 707 | 711 | |
@@ -782,6 +786,10 @@ discard block |
||
| 782 | 786 | |
| 783 | 787 | |
| 784 | 788 | /* Returns: the last error message from previous database operation */ |
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * @return boolean|string |
|
| 792 | + */ |
|
| 785 | 793 | function ErrorMsg() |
| 786 | 794 | { |
| 787 | 795 | if ($this->_errorMsg !== false) return $this->_errorMsg; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | var $_resultid = false; |
| 62 | 62 | var $concat_operator='||'; |
| 63 | 63 | var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1"; |
| 64 | - var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
|
| 64 | + var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
|
| 65 | 65 | and tablename not in ('sql_features', 'sql_implementation_info', 'sql_languages', |
| 66 | 66 | 'sql_packages', 'sql_sizing', 'sql_sizing_profiles') |
| 67 | 67 | union |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | $info = $this->ServerInfo(); |
| 228 | 228 | if ($info['version'] >= 7.3) { |
| 229 | - $this->metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
|
| 229 | + $this->metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
|
| 230 | 230 | and schemaname not in ( 'pg_catalog','information_schema') |
| 231 | 231 | union |
| 232 | 232 | select viewname,'V' from pg_views where viewname not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema') "; |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | { |
| 444 | 444 | |
| 445 | 445 | if ($blobtype == 'CLOB') { |
| 446 | - return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
| 446 | + return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
| 447 | 447 | } |
| 448 | 448 | // do not use bind params which uses qstr(), as blobencode() already quotes data |
| 449 | 449 | return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); |
@@ -573,8 +573,8 @@ discard block |
||
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | function &MetaIndexes ($table, $primary = FALSE) |
| 576 | - { |
|
| 577 | - global $ADODB_FETCH_MODE; |
|
| 576 | + { |
|
| 577 | + global $ADODB_FETCH_MODE; |
|
| 578 | 578 | |
| 579 | 579 | // table-name must NOT be quoted, otherwise we will not find any index |
| 580 | 580 | $table = str_replace($this->nameQuote, '', $table); |
@@ -591,50 +591,50 @@ discard block |
||
| 591 | 591 | ,pg_namespace n |
| 592 | 592 | WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\')) and c.relnamespace=c2.relnamespace and c.relnamespace=n.oid and n.nspname=\'%s\' AND i.indisprimary=false'; |
| 593 | 593 | } else { |
| 594 | - $sql = ' |
|
| 594 | + $sql = ' |
|
| 595 | 595 | SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" |
| 596 | 596 | FROM pg_catalog.pg_class c |
| 597 | 597 | JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid |
| 598 | 598 | JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid |
| 599 | 599 | WHERE c2.relname=\'%s\' or c2.relname=lower(\'%s\')'; |
| 600 | - } |
|
| 601 | - |
|
| 602 | - if ($primary == FALSE) { |
|
| 603 | - $sql .= ' AND i.indisprimary=false;'; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - $save = $ADODB_FETCH_MODE; |
|
| 607 | - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
| 608 | - if ($this->fetchMode !== FALSE) { |
|
| 609 | - $savem = $this->SetFetchMode(FALSE); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); |
|
| 613 | - if (isset($savem)) { |
|
| 614 | - $this->SetFetchMode($savem); |
|
| 615 | - } |
|
| 616 | - $ADODB_FETCH_MODE = $save; |
|
| 617 | - |
|
| 618 | - if (!is_object($rs)) { |
|
| 619 | - $false = false; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + if ($primary == FALSE) { |
|
| 603 | + $sql .= ' AND i.indisprimary=false;'; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + $save = $ADODB_FETCH_MODE; |
|
| 607 | + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
| 608 | + if ($this->fetchMode !== FALSE) { |
|
| 609 | + $savem = $this->SetFetchMode(FALSE); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); |
|
| 613 | + if (isset($savem)) { |
|
| 614 | + $this->SetFetchMode($savem); |
|
| 615 | + } |
|
| 616 | + $ADODB_FETCH_MODE = $save; |
|
| 617 | + |
|
| 618 | + if (!is_object($rs)) { |
|
| 619 | + $false = false; |
|
| 620 | 620 | return $false; |
| 621 | - } |
|
| 622 | - |
|
| 623 | - $col_names = $this->MetaColumnNames($table,true); |
|
| 624 | - $indexes = array(); |
|
| 625 | - while ($row = $rs->FetchRow()) { |
|
| 626 | - $columns = array(); |
|
| 627 | - foreach (explode(' ', $row[2]) as $col) { |
|
| 628 | - $columns[] = $col_names[$col - 1]; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - $indexes[$row[0]] = array( |
|
| 632 | - 'unique' => ($row[1] == 't'), |
|
| 633 | - 'columns' => $columns |
|
| 634 | - ); |
|
| 635 | - } |
|
| 636 | - return $indexes; |
|
| 637 | - } |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + $col_names = $this->MetaColumnNames($table,true); |
|
| 624 | + $indexes = array(); |
|
| 625 | + while ($row = $rs->FetchRow()) { |
|
| 626 | + $columns = array(); |
|
| 627 | + foreach (explode(' ', $row[2]) as $col) { |
|
| 628 | + $columns[] = $col_names[$col - 1]; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + $indexes[$row[0]] = array( |
|
| 632 | + 'unique' => ($row[1] == 't'), |
|
| 633 | + 'columns' => $columns |
|
| 634 | + ); |
|
| 635 | + } |
|
| 636 | + return $indexes; |
|
| 637 | + } |
|
| 638 | 638 | |
| 639 | 639 | // returns true or false |
| 640 | 640 | // |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | { |
| 968 | 968 | |
| 969 | 969 | if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) |
| 970 | - return false; |
|
| 970 | + return false; |
|
| 971 | 971 | |
| 972 | 972 | $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
| 973 | 973 | |
@@ -287,64 +287,64 @@ discard block |
||
| 287 | 287 | for ($i=0; $i < $len; $i++) { |
| 288 | 288 | $ch = $fmt[$i]; |
| 289 | 289 | switch($ch) { |
| 290 | - case 'Y': |
|
| 291 | - case 'y': |
|
| 292 | - $s .= 'YYYY'; |
|
| 293 | - break; |
|
| 294 | - case 'Q': |
|
| 295 | - case 'q': |
|
| 296 | - $s .= 'Q'; |
|
| 297 | - break; |
|
| 298 | - |
|
| 299 | - case 'M': |
|
| 300 | - $s .= 'Mon'; |
|
| 301 | - break; |
|
| 302 | - |
|
| 303 | - case 'm': |
|
| 304 | - $s .= 'MM'; |
|
| 305 | - break; |
|
| 306 | - case 'D': |
|
| 307 | - case 'd': |
|
| 308 | - $s .= 'DD'; |
|
| 309 | - break; |
|
| 310 | - |
|
| 311 | - case 'H': |
|
| 312 | - $s.= 'HH24'; |
|
| 313 | - break; |
|
| 314 | - |
|
| 315 | - case 'h': |
|
| 316 | - $s .= 'HH'; |
|
| 317 | - break; |
|
| 318 | - |
|
| 319 | - case 'i': |
|
| 320 | - $s .= 'MI'; |
|
| 321 | - break; |
|
| 322 | - |
|
| 323 | - case 's': |
|
| 324 | - $s .= 'SS'; |
|
| 325 | - break; |
|
| 326 | - |
|
| 327 | - case 'a': |
|
| 328 | - case 'A': |
|
| 329 | - $s .= 'AM'; |
|
| 330 | - break; |
|
| 331 | - |
|
| 332 | - case 'w': |
|
| 333 | - $s .= 'D'; |
|
| 334 | - break; |
|
| 335 | - |
|
| 336 | - case 'l': |
|
| 337 | - $s .= 'DAY'; |
|
| 338 | - break; |
|
| 339 | - |
|
| 340 | - default: |
|
| 341 | - // handle escape characters... |
|
| 342 | - if ($ch == '\\') { |
|
| 343 | - $i++; |
|
| 344 | - $ch = substr($fmt,$i,1); |
|
| 345 | - } |
|
| 346 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
| 347 | - else $s .= '"'.$ch.'"'; |
|
| 290 | + case 'Y': |
|
| 291 | + case 'y': |
|
| 292 | + $s .= 'YYYY'; |
|
| 293 | + break; |
|
| 294 | + case 'Q': |
|
| 295 | + case 'q': |
|
| 296 | + $s .= 'Q'; |
|
| 297 | + break; |
|
| 298 | + |
|
| 299 | + case 'M': |
|
| 300 | + $s .= 'Mon'; |
|
| 301 | + break; |
|
| 302 | + |
|
| 303 | + case 'm': |
|
| 304 | + $s .= 'MM'; |
|
| 305 | + break; |
|
| 306 | + case 'D': |
|
| 307 | + case 'd': |
|
| 308 | + $s .= 'DD'; |
|
| 309 | + break; |
|
| 310 | + |
|
| 311 | + case 'H': |
|
| 312 | + $s.= 'HH24'; |
|
| 313 | + break; |
|
| 314 | + |
|
| 315 | + case 'h': |
|
| 316 | + $s .= 'HH'; |
|
| 317 | + break; |
|
| 318 | + |
|
| 319 | + case 'i': |
|
| 320 | + $s .= 'MI'; |
|
| 321 | + break; |
|
| 322 | + |
|
| 323 | + case 's': |
|
| 324 | + $s .= 'SS'; |
|
| 325 | + break; |
|
| 326 | + |
|
| 327 | + case 'a': |
|
| 328 | + case 'A': |
|
| 329 | + $s .= 'AM'; |
|
| 330 | + break; |
|
| 331 | + |
|
| 332 | + case 'w': |
|
| 333 | + $s .= 'D'; |
|
| 334 | + break; |
|
| 335 | + |
|
| 336 | + case 'l': |
|
| 337 | + $s .= 'DAY'; |
|
| 338 | + break; |
|
| 339 | + |
|
| 340 | + default: |
|
| 341 | + // handle escape characters... |
|
| 342 | + if ($ch == '\\') { |
|
| 343 | + $i++; |
|
| 344 | + $ch = substr($fmt,$i,1); |
|
| 345 | + } |
|
| 346 | + if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
| 347 | + else $s .= '"'.$ch.'"'; |
|
| 348 | 348 | |
| 349 | 349 | } |
| 350 | 350 | } |
@@ -859,12 +859,12 @@ discard block |
||
| 859 | 859 | } |
| 860 | 860 | switch ($mode) |
| 861 | 861 | { |
| 862 | - case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break; |
|
| 863 | - case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break; |
|
| 862 | + case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break; |
|
| 863 | + case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break; |
|
| 864 | 864 | |
| 865 | - case ADODB_FETCH_DEFAULT: |
|
| 866 | - case ADODB_FETCH_BOTH: |
|
| 867 | - default: $this->fetchMode = PGSQL_BOTH; break; |
|
| 865 | + case ADODB_FETCH_DEFAULT: |
|
| 866 | + case ADODB_FETCH_BOTH: |
|
| 867 | + default: $this->fetchMode = PGSQL_BOTH; break; |
|
| 868 | 868 | } |
| 869 | 869 | $this->adodbFetchMode = $mode; |
| 870 | 870 | $this->ADORecordSet($queryID); |
@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $len = strlen($s); |
| 51 | 51 | if ($len == 0) return "''"; |
| 52 | - if (strncmp($s,"'",1) === 0 && substr(s,$len-1) == "'") return $s; // already quoted |
|
| 52 | + if (strncmp($s, "'", 1) === 0 && substr(s, $len - 1) == "'") return $s; // already quoted |
|
| 53 | 53 | |
| 54 | 54 | return "'".addslashes($s)."'"; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | -class ADODB_postgres64 extends ADOConnection{ |
|
| 57 | +class ADODB_postgres64 extends ADOConnection { |
|
| 58 | 58 | var $databaseType = 'postgres64'; |
| 59 | 59 | var $dataProvider = 'postgres'; |
| 60 | 60 | var $hasInsertID = true; |
| 61 | 61 | var $_resultid = false; |
| 62 | - var $concat_operator='||'; |
|
| 62 | + var $concat_operator = '||'; |
|
| 63 | 63 | var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1"; |
| 64 | 64 | var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
| 65 | 65 | and tablename not in ('sql_features', 'sql_implementation_info', 'sql_languages', |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'"; |
| 90 | 90 | |
| 91 | 91 | var $hasAffectedRows = true; |
| 92 | - var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 |
|
| 92 | + var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 |
|
| 93 | 93 | // below suggested by Freek Dijkstra |
| 94 | - var $true = 'TRUE'; // string that represents TRUE for a database |
|
| 95 | - var $false = 'FALSE'; // string that represents FALSE for a database |
|
| 96 | - var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database |
|
| 94 | + var $true = 'TRUE'; // string that represents TRUE for a database |
|
| 95 | + var $false = 'FALSE'; // string that represents FALSE for a database |
|
| 96 | + var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database |
|
| 97 | 97 | var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt. |
| 98 | 98 | var $hasMoveFirst = true; |
| 99 | 99 | var $hasGenID = true; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | var $_genSeqSQL = "CREATE SEQUENCE %s START %s"; |
| 102 | 102 | var $_dropSeqSQL = "DROP SEQUENCE %s"; |
| 103 | 103 | var $metaDefaultsSQL = "SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum"; |
| 104 | - var $random = 'random()'; /// random function |
|
| 104 | + var $random = 'random()'; /// random function |
|
| 105 | 105 | var $autoRollback = true; // apparently pgsql does not autorollback properly before php 4.3.4 |
| 106 | 106 | // http://bugs.php.net/bug.php?id=25404 |
| 107 | 107 | |
@@ -131,17 +131,17 @@ discard block |
||
| 131 | 131 | return $arr; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - function IfNull( $field, $ifNull ) |
|
| 134 | + function IfNull($field, $ifNull) |
|
| 135 | 135 | { |
| 136 | 136 | return " coalesce($field, $ifNull) "; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // get the last id - never tested |
| 140 | - function pg_insert_id($tablename,$fieldname) |
|
| 140 | + function pg_insert_id($tablename, $fieldname) |
|
| 141 | 141 | { |
| 142 | - $result=pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq"); |
|
| 142 | + $result = pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq"); |
|
| 143 | 143 | if ($result) { |
| 144 | - $arr = @pg_fetch_row($result,0); |
|
| 144 | + $arr = @pg_fetch_row($result, 0); |
|
| 145 | 145 | pg_freeresult($result); |
| 146 | 146 | if (isset($arr[0])) return $arr[0]; |
| 147 | 147 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | Using a OID as a unique identifier is not generally wise. |
| 153 | 153 | Unless you are very careful, you might end up with a tuple having |
| 154 | 154 | a different OID if a database must be reloaded. */ |
| 155 | - function _insertid($table,$column,$try_oid=false) |
|
| 155 | + function _insertid($table, $column, $try_oid = false) |
|
| 156 | 156 | { |
| 157 | 157 | if ($try_oid) |
| 158 | 158 | { |
@@ -166,13 +166,13 @@ discard block |
||
| 166 | 166 | if ($oid === false && $table && $column) // table might not use oid's, default for 8.1+ |
| 167 | 167 | { |
| 168 | 168 | // try the standard sequence name first, due to table renames etc. this might not be the correct one |
| 169 | - if (!($ret = $this->GetOne($sql='SELECT currval('.$this->qstr($table.'_'.$column.'_seq').')'))) { |
|
| 169 | + if (!($ret = $this->GetOne($sql = 'SELECT currval('.$this->qstr($table.'_'.$column.'_seq').')'))) { |
|
| 170 | 170 | // now we read the sequence name from the database itself, that is a lot slower! |
| 171 | 171 | $cols = $this->MetaColumns($table); |
| 172 | 172 | $fld = $cols[strtoupper($column)]; |
| 173 | 173 | if ($fld->primary_key && $fld->has_default && |
| 174 | - preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) { |
|
| 175 | - $ret = $this->GetOne($sql='SELECT currval('.$this->qstr($matches[1]).')'); |
|
| 174 | + preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $fld->default_value, $matches)) { |
|
| 175 | + $ret = $this->GetOne($sql = 'SELECT currval('.$this->qstr($matches[1]).')'); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | return $ret; |
@@ -198,14 +198,14 @@ discard block |
||
| 198 | 198 | return @pg_Exec($this->_connectionID, "begin"); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - function RowLock($tables,$where,$flds='1 as ignore') |
|
| 201 | + function RowLock($tables, $where, $flds = '1 as ignore') |
|
| 202 | 202 | { |
| 203 | 203 | if (!$this->transCnt) $this->BeginTrans(); |
| 204 | 204 | return $this->GetOne("select $flds from $tables where $where for update"); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | // returns true/false. |
| 208 | - function CommitTrans($ok=true) |
|
| 208 | + function CommitTrans($ok = true) |
|
| 209 | 209 | { |
| 210 | 210 | if ($this->transOff) return true; |
| 211 | 211 | if (!$ok) return $this->RollbackTrans(); |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | return @pg_Exec($this->_connectionID, "rollback"); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - function &MetaTables($ttype=false,$showSchema=false,$mask=false) |
|
| 225 | + function &MetaTables($ttype = false, $showSchema = false, $mask = false) |
|
| 226 | 226 | { |
| 227 | 227 | $info = $this->ServerInfo(); |
| 228 | 228 | if ($info['version'] >= 7.3) { |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | if ($mask) { |
| 235 | 235 | $save = $this->metaTablesSQL; |
| 236 | 236 | $mask = $this->qstr(strtolower($mask)); |
| 237 | - if ($info['version']>=7.3) |
|
| 237 | + if ($info['version'] >= 7.3) |
|
| 238 | 238 | $this->metaTablesSQL = " |
| 239 | 239 | select tablename,'T' from pg_tables where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema') |
| 240 | 240 | union |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | union |
| 246 | 246 | select viewname,'V' from pg_views where viewname like $mask"; |
| 247 | 247 | } |
| 248 | - $ret =& ADOConnection::MetaTables($ttype,$showSchema); |
|
| 248 | + $ret = & ADOConnection::MetaTables($ttype, $showSchema); |
|
| 249 | 249 | |
| 250 | 250 | if ($mask) { |
| 251 | 251 | $this->metaTablesSQL = $save; |
@@ -254,39 +254,39 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // if magic quotes disabled, use pg_escape_string() |
| 257 | - function qstr($s,$magic_quotes=false) |
|
| 257 | + function qstr($s, $magic_quotes = false) |
|
| 258 | 258 | { |
| 259 | 259 | if (is_bool($s)) return $s ? 'true' : 'false'; |
| 260 | 260 | |
| 261 | 261 | if (!$magic_quotes) { |
| 262 | 262 | if (ADODB_PHPVER >= 0x5200) { |
| 263 | - return "'".pg_escape_string($this->_connectionID,$s)."'"; |
|
| 263 | + return "'".pg_escape_string($this->_connectionID, $s)."'"; |
|
| 264 | 264 | } |
| 265 | 265 | if (ADODB_PHPVER >= 0x4200) { |
| 266 | 266 | return "'".pg_escape_string($s)."'"; |
| 267 | 267 | } |
| 268 | - if ($this->replaceQuote[0] == '\\'){ |
|
| 269 | - $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\\000"),$s); |
|
| 268 | + if ($this->replaceQuote[0] == '\\') { |
|
| 269 | + $s = adodb_str_replace(array('\\', "\0"), array('\\\\', "\\\\000"), $s); |
|
| 270 | 270 | } |
| 271 | - return "'".str_replace("'",$this->replaceQuote,$s)."'"; |
|
| 271 | + return "'".str_replace("'", $this->replaceQuote, $s)."'"; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // undo magic quotes for " |
| 275 | - $s = str_replace('\\"','"',$s); |
|
| 275 | + $s = str_replace('\\"', '"', $s); |
|
| 276 | 276 | return "'$s'"; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
| 280 | 280 | // Format date column in sql string given an input format that understands Y M D |
| 281 | - function SQLDate($fmt, $col=false) |
|
| 281 | + function SQLDate($fmt, $col = false) |
|
| 282 | 282 | { |
| 283 | 283 | if (!$col) $col = $this->sysTimeStamp; |
| 284 | 284 | $s = 'TO_CHAR('.$col.",'"; |
| 285 | 285 | |
| 286 | 286 | $len = strlen($fmt); |
| 287 | - for ($i=0; $i < $len; $i++) { |
|
| 287 | + for ($i = 0; $i < $len; $i++) { |
|
| 288 | 288 | $ch = $fmt[$i]; |
| 289 | - switch($ch) { |
|
| 289 | + switch ($ch) { |
|
| 290 | 290 | case 'Y': |
| 291 | 291 | case 'y': |
| 292 | 292 | $s .= 'YYYY'; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | break; |
| 310 | 310 | |
| 311 | 311 | case 'H': |
| 312 | - $s.= 'HH24'; |
|
| 312 | + $s .= 'HH24'; |
|
| 313 | 313 | break; |
| 314 | 314 | |
| 315 | 315 | case 'h': |
@@ -341,14 +341,14 @@ discard block |
||
| 341 | 341 | // handle escape characters... |
| 342 | 342 | if ($ch == '\\') { |
| 343 | 343 | $i++; |
| 344 | - $ch = substr($fmt,$i,1); |
|
| 344 | + $ch = substr($fmt, $i, 1); |
|
| 345 | 345 | } |
| 346 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
| 346 | + if (strpos('-/.:;, ', $ch) !== false) $s .= $ch; |
|
| 347 | 347 | else $s .= '"'.$ch.'"'; |
| 348 | 348 | |
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | - return $s. "')"; |
|
| 351 | + return $s."')"; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -361,12 +361,12 @@ discard block |
||
| 361 | 361 | * contributed by Mattia Rossi [email protected] |
| 362 | 362 | * modified for safe mode by juraj chlebec |
| 363 | 363 | */ |
| 364 | - function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') |
|
| 364 | + function UpdateBlobFile($table, $column, $path, $where, $blobtype = 'BLOB') |
|
| 365 | 365 | { |
| 366 | - pg_exec ($this->_connectionID, "begin"); |
|
| 366 | + pg_exec($this->_connectionID, "begin"); |
|
| 367 | 367 | |
| 368 | - $fd = fopen($path,'r'); |
|
| 369 | - $contents = fread($fd,filesize($path)); |
|
| 368 | + $fd = fopen($path, 'r'); |
|
| 369 | + $contents = fread($fd, filesize($path)); |
|
| 370 | 370 | fclose($fd); |
| 371 | 371 | |
| 372 | 372 | $oid = pg_lo_create($this->_connectionID); |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | |
| 377 | 377 | // $oid = pg_lo_import ($path); |
| 378 | 378 | pg_exec($this->_connectionID, "commit"); |
| 379 | - $rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype); |
|
| 379 | + $rs = ADOConnection::UpdateBlob($table, $column, $oid, $where, $blobtype); |
|
| 380 | 380 | $rez = !empty($rs); |
| 381 | 381 | return $rez; |
| 382 | 382 | } |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | */ |
| 387 | 387 | function GuessOID($oid) |
| 388 | 388 | { |
| 389 | - if (strlen($oid)>16) return false; |
|
| 389 | + if (strlen($oid) > 16) return false; |
|
| 390 | 390 | return is_numeric($oid); |
| 391 | 391 | } |
| 392 | 392 | |
@@ -402,20 +402,20 @@ discard block |
||
| 402 | 402 | * Since adodb 4.54, this returns the blob, instead of sending it to stdout. Also |
| 403 | 403 | * added maxsize parameter, which defaults to $db->maxblobsize if not defined. |
| 404 | 404 | */ |
| 405 | - function BlobDecode($blob,$maxsize=false,$hastrans=true) |
|
| 405 | + function BlobDecode($blob, $maxsize = false, $hastrans = true) |
|
| 406 | 406 | { |
| 407 | 407 | if (!$this->GuessOID($blob)) return $blob; |
| 408 | 408 | |
| 409 | - if ($hastrans) @pg_exec($this->_connectionID,"begin"); |
|
| 410 | - $fd = @pg_lo_open($this->_connectionID,$blob,"r"); |
|
| 409 | + if ($hastrans) @pg_exec($this->_connectionID, "begin"); |
|
| 410 | + $fd = @pg_lo_open($this->_connectionID, $blob, "r"); |
|
| 411 | 411 | if ($fd === false) { |
| 412 | - if ($hastrans) @pg_exec($this->_connectionID,"commit"); |
|
| 412 | + if ($hastrans) @pg_exec($this->_connectionID, "commit"); |
|
| 413 | 413 | return $blob; |
| 414 | 414 | } |
| 415 | 415 | if (!$maxsize) $maxsize = $this->maxblobsize; |
| 416 | - $realblob = @pg_loread($fd,$maxsize); |
|
| 416 | + $realblob = @pg_loread($fd, $maxsize); |
|
| 417 | 417 | @pg_loclose($fd); |
| 418 | - if ($hastrans) @pg_exec($this->_connectionID,"commit"); |
|
| 418 | + if ($hastrans) @pg_exec($this->_connectionID, "commit"); |
|
| 419 | 419 | return $realblob; |
| 420 | 420 | } |
| 421 | 421 | |
@@ -431,25 +431,25 @@ discard block |
||
| 431 | 431 | if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob); |
| 432 | 432 | |
| 433 | 433 | /*92=backslash, 0=null, 39=single-quote*/ |
| 434 | - $badch = array(chr(92),chr(0),chr(39)); # \ null ' |
|
| 435 | - $fixch = array('\\\\134','\\\\000','\\\\047'); |
|
| 436 | - return adodb_str_replace($badch,$fixch,$blob); |
|
| 434 | + $badch = array(chr(92), chr(0), chr(39)); # \ null ' |
|
| 435 | + $fixch = array('\\\\134', '\\\\000', '\\\\047'); |
|
| 436 | + return adodb_str_replace($badch, $fixch, $blob); |
|
| 437 | 437 | |
| 438 | 438 | // note that there is a pg_escape_bytea function only for php 4.2.0 or later |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | // assumes bytea for blob, and varchar for clob |
| 442 | - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
|
| 442 | + function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB') |
|
| 443 | 443 | { |
| 444 | 444 | |
| 445 | 445 | if ($blobtype == 'CLOB') { |
| 446 | - return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
| 446 | + return $this->Execute("UPDATE $table SET $column=".$this->qstr($val)." WHERE $where"); |
|
| 447 | 447 | } |
| 448 | 448 | // do not use bind params which uses qstr(), as blobencode() already quotes data |
| 449 | 449 | return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - function OffsetDate($dayFraction,$date=false) |
|
| 452 | + function OffsetDate($dayFraction, $date = false) |
|
| 453 | 453 | { |
| 454 | 454 | if (!$date) $date = $this->sysDate; |
| 455 | 455 | return "($date+interval'$dayFraction days')"; |
@@ -458,14 +458,14 @@ discard block |
||
| 458 | 458 | |
| 459 | 459 | // for schema support, pass in the $table param "$schema.$tabname". |
| 460 | 460 | // converts field names to lowercase, $upper is ignored |
| 461 | - function &MetaColumns($table,$normalize=true) |
|
| 461 | + function &MetaColumns($table, $normalize = true) |
|
| 462 | 462 | { |
| 463 | 463 | global $ADODB_FETCH_MODE; |
| 464 | 464 | //if tablenames are quoted, remove the quotes as the tablenames here are used for comparsion of content of fields in postgres system tables |
| 465 | - if (!empty($this->nameQuote) && !(strpos($table,$this->nameQuote)===false)) $table = str_replace($this->nameQuote,'',$table); |
|
| 465 | + if (!empty($this->nameQuote) && !(strpos($table, $this->nameQuote) === false)) $table = str_replace($this->nameQuote, '', $table); |
|
| 466 | 466 | $schema = false; |
| 467 | 467 | $false = false; |
| 468 | - $this->_findschema($table,$schema); |
|
| 468 | + $this->_findschema($table, $schema); |
|
| 469 | 469 | |
| 470 | 470 | if ($normalize) $table = strtolower($table); |
| 471 | 471 | |
@@ -473,8 +473,8 @@ discard block |
||
| 473 | 473 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 474 | 474 | if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); |
| 475 | 475 | |
| 476 | - if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); |
|
| 477 | - else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); |
|
| 476 | + if ($schema) $rs = & $this->Execute(sprintf($this->metaColumnsSQL1, $table, $table, $schema)); |
|
| 477 | + else $rs = & $this->Execute(sprintf($this->metaColumnsSQL, $table, $table)); |
|
| 478 | 478 | if (isset($savem)) $this->SetFetchMode($savem); |
| 479 | 479 | $ADODB_FETCH_MODE = $save; |
| 480 | 480 | |
@@ -489,9 +489,9 @@ discard block |
||
| 489 | 489 | |
| 490 | 490 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
| 491 | 491 | |
| 492 | - $rskey = $this->Execute(sprintf($this->metaKeySQL,($table))); |
|
| 492 | + $rskey = $this->Execute(sprintf($this->metaKeySQL, ($table))); |
|
| 493 | 493 | // fetch all result in once for performance. |
| 494 | - $keys =& $rskey->GetArray(); |
|
| 494 | + $keys = & $rskey->GetArray(); |
|
| 495 | 495 | if (isset($savem)) $this->SetFetchMode($savem); |
| 496 | 496 | $ADODB_FETCH_MODE = $save; |
| 497 | 497 | |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | while (!$rsdef->EOF) { |
| 512 | 512 | $num = $rsdef->fields['num']; |
| 513 | 513 | $s = $rsdef->fields['def']; |
| 514 | - if (strpos($s,'::')===false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ |
|
| 514 | + if (strpos($s, '::') === false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ |
|
| 515 | 515 | $s = substr($s, 1); |
| 516 | 516 | $s = substr($s, 0, strlen($s) - 1); |
| 517 | 517 | } |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | $rsdef->MoveNext(); |
| 521 | 521 | } |
| 522 | 522 | } else { |
| 523 | - ADOConnection::outp( "==> SQL => " . $sql); |
|
| 523 | + ADOConnection::outp("==> SQL => ".$sql); |
|
| 524 | 524 | } |
| 525 | 525 | unset($rsdef); |
| 526 | 526 | } |
@@ -531,10 +531,10 @@ discard block |
||
| 531 | 531 | $fld->name = $rs->fields[0]; |
| 532 | 532 | $fld->type = $rs->fields[1]; |
| 533 | 533 | $fld->max_length = $rs->fields[2]; |
| 534 | - if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4; |
|
| 534 | + if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3] - 4; |
|
| 535 | 535 | if ($fld->max_length <= 0) $fld->max_length = -1; |
| 536 | 536 | if ($fld->type == 'numeric') { |
| 537 | - $fld->scale = $fld->max_length & 0xFFFF; |
|
| 537 | + $fld->scale = $fld->max_length&0xFFFF; |
|
| 538 | 538 | $fld->max_length >>= 16; |
| 539 | 539 | } |
| 540 | 540 | // dannym |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | |
| 552 | 552 | // Freek |
| 553 | 553 | if (is_array($keys)) { |
| 554 | - foreach($keys as $key) { |
|
| 554 | + foreach ($keys as $key) { |
|
| 555 | 555 | if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't') |
| 556 | 556 | $fld->primary_key = true; |
| 557 | 557 | if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't') |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - function &MetaIndexes ($table, $primary = FALSE) |
|
| 575 | + function &MetaIndexes($table, $primary = FALSE) |
|
| 576 | 576 | { |
| 577 | 577 | global $ADODB_FETCH_MODE; |
| 578 | 578 | |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | $table = str_replace($this->nameQuote, '', $table); |
| 581 | 581 | |
| 582 | 582 | $schema = false; |
| 583 | - $this->_findschema($table,$schema); |
|
| 583 | + $this->_findschema($table, $schema); |
|
| 584 | 584 | |
| 585 | 585 | if ($schema) { // requires pgsql 7.3+ - pg_namespace used. |
| 586 | 586 | $sql = ' |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | $savem = $this->SetFetchMode(FALSE); |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); |
|
| 612 | + $rs = $this->Execute(sprintf($sql, $table, $table, $schema)); |
|
| 613 | 613 | if (isset($savem)) { |
| 614 | 614 | $this->SetFetchMode($savem); |
| 615 | 615 | } |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | return $false; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - $col_names = $this->MetaColumnNames($table,true); |
|
| 623 | + $col_names = $this->MetaColumnNames($table, true); |
|
| 624 | 624 | $indexes = array(); |
| 625 | 625 | while ($row = $rs->FetchRow()) { |
| 626 | 626 | $columns = array(); |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | // examples: |
| 642 | 642 | // $db->Connect("host=host1 user=user1 password=secret port=4341"); |
| 643 | 643 | // $db->Connect('host1','user1','secret'); |
| 644 | - function _connect($str,$user='',$pwd='',$db='',$ctype=0) |
|
| 644 | + function _connect($str, $user = '', $pwd = '', $db = '', $ctype = 0) |
|
| 645 | 645 | { |
| 646 | 646 | |
| 647 | 647 | if (!function_exists('pg_pconnect')) return null; |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | $pwd = adodb_addslashes($pwd); |
| 654 | 654 | if (strlen($db) == 0) $db = 'template1'; |
| 655 | 655 | $db = adodb_addslashes($db); |
| 656 | - if ($str) { |
|
| 656 | + if ($str) { |
|
| 657 | 657 | $host = explode(":", $str); |
| 658 | 658 | if ($host[0]) $str = "host=".adodb_addslashes($host[0]); |
| 659 | 659 | else $str = 'host=localhost'; |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | if (empty($ncnt)) $ncnt = 1; |
| 677 | 677 | else $ncnt += 1; |
| 678 | 678 | |
| 679 | - $str .= str_repeat(' ',$ncnt); |
|
| 679 | + $str .= str_repeat(' ', $ncnt); |
|
| 680 | 680 | } |
| 681 | 681 | $this->_connectionID = pg_connect($str); |
| 682 | 682 | } |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | |
| 688 | 688 | function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName) |
| 689 | 689 | { |
| 690 | - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName,-1); |
|
| 690 | + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName, -1); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | // returns true or false |
@@ -695,14 +695,14 @@ discard block |
||
| 695 | 695 | // examples: |
| 696 | 696 | // $db->PConnect("host=host1 user=user1 password=secret port=4341"); |
| 697 | 697 | // $db->PConnect('host1','user1','secret'); |
| 698 | - function _pconnect($str,$user='',$pwd='',$db='') |
|
| 698 | + function _pconnect($str, $user = '', $pwd = '', $db = '') |
|
| 699 | 699 | { |
| 700 | - return $this->_connect($str,$user,$pwd,$db,1); |
|
| 700 | + return $this->_connect($str, $user, $pwd, $db, 1); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | |
| 704 | 704 | // returns queryID or false |
| 705 | - function _query($sql,$inputarr) |
|
| 705 | + function _query($sql, $inputarr) |
|
| 706 | 706 | { |
| 707 | 707 | |
| 708 | 708 | if ($inputarr) { |
@@ -722,10 +722,10 @@ discard block |
||
| 722 | 722 | $plan = 'P'.md5($sql); |
| 723 | 723 | |
| 724 | 724 | $execp = ''; |
| 725 | - foreach($inputarr as $v) { |
|
| 725 | + foreach ($inputarr as $v) { |
|
| 726 | 726 | if ($execp) $execp .= ','; |
| 727 | 727 | if (is_string($v)) { |
| 728 | - if (strncmp($v,"'",1) !== 0) $execp .= $this->qstr($v); |
|
| 728 | + if (strncmp($v, "'", 1) !== 0) $execp .= $this->qstr($v); |
|
| 729 | 729 | } else { |
| 730 | 730 | $execp .= $v; |
| 731 | 731 | } |
@@ -734,11 +734,11 @@ discard block |
||
| 734 | 734 | if ($execp) $exsql = "EXECUTE $plan ($execp)"; |
| 735 | 735 | else $exsql = "EXECUTE $plan"; |
| 736 | 736 | |
| 737 | - $rez = @pg_exec($this->_connectionID,$exsql); |
|
| 737 | + $rez = @pg_exec($this->_connectionID, $exsql); |
|
| 738 | 738 | if (!$rez) { |
| 739 | 739 | # Perhaps plan does not exist? Prepare/compile plan. |
| 740 | 740 | $params = ''; |
| 741 | - foreach($inputarr as $v) { |
|
| 741 | + foreach ($inputarr as $v) { |
|
| 742 | 742 | if ($params) $params .= ','; |
| 743 | 743 | if (is_string($v)) { |
| 744 | 744 | $params .= 'VARCHAR'; |
@@ -748,25 +748,25 @@ discard block |
||
| 748 | 748 | $params .= "REAL"; |
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | - $sqlarr = explode('?',$sql); |
|
| 751 | + $sqlarr = explode('?', $sql); |
|
| 752 | 752 | //print_r($sqlarr); |
| 753 | 753 | $sql = ''; |
| 754 | 754 | $i = 1; |
| 755 | - foreach($sqlarr as $v) { |
|
| 755 | + foreach ($sqlarr as $v) { |
|
| 756 | 756 | $sql .= $v.' $'.$i; |
| 757 | 757 | $i++; |
| 758 | 758 | } |
| 759 | - $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2); |
|
| 759 | + $s = "PREPARE $plan ($params) AS ".substr($sql, 0, strlen($sql) - 2); |
|
| 760 | 760 | //adodb_pr($s); |
| 761 | - pg_exec($this->_connectionID,$s); |
|
| 761 | + pg_exec($this->_connectionID, $s); |
|
| 762 | 762 | echo $this->ErrorMsg(); |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | - $rez = pg_exec($this->_connectionID,$exsql); |
|
| 765 | + $rez = pg_exec($this->_connectionID, $exsql); |
|
| 766 | 766 | } else { |
| 767 | 767 | $this->_errorMsg = false; |
| 768 | 768 | //adodb_backtrace(); |
| 769 | - $rez = pg_exec($this->_connectionID,$sql); |
|
| 769 | + $rez = pg_exec($this->_connectionID, $sql); |
|
| 770 | 770 | } |
| 771 | 771 | // check if no data returned, then no need to create real recordset |
| 772 | 772 | if ($rez && pg_numfields($rez) <= 0) { |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | */ |
| 830 | 830 | function CharMax() |
| 831 | 831 | { |
| 832 | - return 1000000000; // should be 1 Gb? |
|
| 832 | + return 1000000000; // should be 1 Gb? |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /* |
@@ -847,11 +847,11 @@ discard block |
||
| 847 | 847 | Class Name: Recordset |
| 848 | 848 | --------------------------------------------------------------------------------------*/ |
| 849 | 849 | |
| 850 | -class ADORecordSet_postgres64 extends ADORecordSet{ |
|
| 850 | +class ADORecordSet_postgres64 extends ADORecordSet { |
|
| 851 | 851 | var $_blobArr; |
| 852 | 852 | var $databaseType = "postgres64"; |
| 853 | 853 | var $canSeek = true; |
| 854 | - function ADORecordSet_postgres64($queryID,$mode=false) |
|
| 854 | + function ADORecordSet_postgres64($queryID, $mode = false) |
|
| 855 | 855 | { |
| 856 | 856 | if ($mode === false) { |
| 857 | 857 | global $ADODB_FETCH_MODE; |
@@ -870,10 +870,10 @@ discard block |
||
| 870 | 870 | $this->ADORecordSet($queryID); |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | - function &GetRowAssoc($upper=true) |
|
| 873 | + function &GetRowAssoc($upper = true) |
|
| 874 | 874 | { |
| 875 | 875 | if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields; |
| 876 | - $row =& ADORecordSet::GetRowAssoc($upper); |
|
| 876 | + $row = & ADORecordSet::GetRowAssoc($upper); |
|
| 877 | 877 | return $row; |
| 878 | 878 | } |
| 879 | 879 | |
@@ -881,15 +881,15 @@ discard block |
||
| 881 | 881 | { |
| 882 | 882 | global $ADODB_COUNTRECS; |
| 883 | 883 | $qid = $this->_queryID; |
| 884 | - $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($qid):-1; |
|
| 884 | + $this->_numOfRows = ($ADODB_COUNTRECS) ? @pg_numrows($qid) : -1; |
|
| 885 | 885 | $this->_numOfFields = @pg_numfields($qid); |
| 886 | 886 | |
| 887 | 887 | // cache types for blob decode check |
| 888 | 888 | // apparently pg_fieldtype actually performs an sql query on the database to get the type. |
| 889 | 889 | if (empty($this->connection->noBlobs)) |
| 890 | - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 891 | - if (pg_fieldtype($qid,$i) == 'bytea') { |
|
| 892 | - $this->_blobArr[$i] = pg_fieldname($qid,$i); |
|
| 890 | + for ($i = 0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 891 | + if (pg_fieldtype($qid, $i) == 'bytea') { |
|
| 892 | + $this->_blobArr[$i] = pg_fieldname($qid, $i); |
|
| 893 | 893 | } |
| 894 | 894 | } |
| 895 | 895 | } |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | |
| 902 | 902 | if (!$this->bind) { |
| 903 | 903 | $this->bind = array(); |
| 904 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 904 | + for ($i = 0; $i < $this->_numOfFields; $i++) { |
|
| 905 | 905 | $o = $this->FetchField($i); |
| 906 | 906 | $this->bind[strtoupper($o->name)] = $i; |
| 907 | 907 | } |
@@ -913,16 +913,16 @@ discard block |
||
| 913 | 913 | { |
| 914 | 914 | // offsets begin at 0 |
| 915 | 915 | |
| 916 | - $o= new ADOFieldObject(); |
|
| 917 | - $o->name = @pg_fieldname($this->_queryID,$off); |
|
| 918 | - $o->type = @pg_fieldtype($this->_queryID,$off); |
|
| 919 | - $o->max_length = @pg_fieldsize($this->_queryID,$off); |
|
| 916 | + $o = new ADOFieldObject(); |
|
| 917 | + $o->name = @pg_fieldname($this->_queryID, $off); |
|
| 918 | + $o->type = @pg_fieldtype($this->_queryID, $off); |
|
| 919 | + $o->max_length = @pg_fieldsize($this->_queryID, $off); |
|
| 920 | 920 | return $o; |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | function _seek($row) |
| 924 | 924 | { |
| 925 | - return @pg_fetch_row($this->_queryID,$row); |
|
| 925 | + return @pg_fetch_row($this->_queryID, $row); |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | function _decode($blob) |
@@ -934,12 +934,12 @@ discard block |
||
| 934 | 934 | function _fixblobs() |
| 935 | 935 | { |
| 936 | 936 | if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) { |
| 937 | - foreach($this->_blobArr as $k => $v) { |
|
| 937 | + foreach ($this->_blobArr as $k => $v) { |
|
| 938 | 938 | $this->fields[$k] = ADORecordSet_postgres64::_decode($this->fields[$k]); |
| 939 | 939 | } |
| 940 | 940 | } |
| 941 | 941 | if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) { |
| 942 | - foreach($this->_blobArr as $k => $v) { |
|
| 942 | + foreach ($this->_blobArr as $k => $v) { |
|
| 943 | 943 | $this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]); |
| 944 | 944 | } |
| 945 | 945 | } |
@@ -951,7 +951,7 @@ discard block |
||
| 951 | 951 | if (!$this->EOF) { |
| 952 | 952 | $this->_currentRow++; |
| 953 | 953 | if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { |
| 954 | - $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
|
| 954 | + $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow, $this->fetchMode); |
|
| 955 | 955 | if (is_array($this->fields) && $this->fields) { |
| 956 | 956 | if (isset($this->_blobArr)) $this->_fixblobs(); |
| 957 | 957 | return true; |
@@ -969,7 +969,7 @@ discard block |
||
| 969 | 969 | if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) |
| 970 | 970 | return false; |
| 971 | 971 | |
| 972 | - $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
|
| 972 | + $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow, $this->fetchMode); |
|
| 973 | 973 | |
| 974 | 974 | if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); |
| 975 | 975 | |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | return @pg_freeresult($this->_queryID); |
| 982 | 982 | } |
| 983 | 983 | |
| 984 | - function MetaType($t,$len=-1,$fieldobj=false) |
|
| 984 | + function MetaType($t, $len = -1, $fieldobj = false) |
|
| 985 | 985 | { |
| 986 | 986 | if (is_object($t)) { |
| 987 | 987 | $fieldobj = $t; |
@@ -43,18 +43,29 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | |
| 45 | 45 | // security - hide paths |
| 46 | -if (!defined('ADODB_DIR')) die(); |
|
| 46 | +if (!defined('ADODB_DIR')) |
|
| 47 | +{ |
|
| 48 | + die(); |
|
| 49 | +} |
|
| 47 | 50 | |
| 48 | 51 | function adodb_addslashes($s) |
| 49 | 52 | { |
| 50 | 53 | $len = strlen($s); |
| 51 | - if ($len == 0) return "''"; |
|
| 52 | - if (strncmp($s,"'",1) === 0 && substr(s,$len-1) == "'") return $s; // already quoted |
|
| 54 | + if ($len == 0) |
|
| 55 | + { |
|
| 56 | + return "''"; |
|
| 57 | + } |
|
| 58 | + if (strncmp($s,"'",1) === 0 && substr(s,$len-1) == "'") |
|
| 59 | + { |
|
| 60 | + return $s; |
|
| 61 | + } |
|
| 62 | + // already quoted |
|
| 53 | 63 | |
| 54 | 64 | return "'".addslashes($s)."'"; |
| 55 | 65 | } |
| 56 | 66 | |
| 57 | -class ADODB_postgres64 extends ADOConnection{ |
|
| 67 | +class ADODB_postgres64 extends ADOConnection |
|
| 68 | +{ |
|
| 58 | 69 | var $databaseType = 'postgres64'; |
| 59 | 70 | var $dataProvider = 'postgres'; |
| 60 | 71 | var $hasInsertID = true; |
@@ -123,7 +134,10 @@ discard block |
||
| 123 | 134 | |
| 124 | 135 | function ServerInfo() |
| 125 | 136 | { |
| 126 | - if (isset($this->version)) return $this->version; |
|
| 137 | + if (isset($this->version)) |
|
| 138 | + { |
|
| 139 | + return $this->version; |
|
| 140 | + } |
|
| 127 | 141 | |
| 128 | 142 | $arr['description'] = $this->GetOne("select version()"); |
| 129 | 143 | $arr['version'] = ADOConnection::_findvers($arr['description']); |
@@ -140,10 +154,14 @@ discard block |
||
| 140 | 154 | function pg_insert_id($tablename,$fieldname) |
| 141 | 155 | { |
| 142 | 156 | $result=pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq"); |
| 143 | - if ($result) { |
|
| 157 | + if ($result) |
|
| 158 | + { |
|
| 144 | 159 | $arr = @pg_fetch_row($result,0); |
| 145 | 160 | pg_freeresult($result); |
| 146 | - if (isset($arr[0])) return $arr[0]; |
|
| 161 | + if (isset($arr[0])) |
|
| 162 | + { |
|
| 163 | + return $arr[0]; |
|
| 164 | + } |
|
| 147 | 165 | } |
| 148 | 166 | return false; |
| 149 | 167 | } |
@@ -156,22 +174,29 @@ discard block |
||
| 156 | 174 | { |
| 157 | 175 | if ($try_oid) |
| 158 | 176 | { |
| 159 | - if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; |
|
| 177 | + if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') |
|
| 178 | + { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 160 | 181 | $oid = pg_getlastoid($this->_resultid); |
| 161 | 182 | } |
| 162 | 183 | else |
| 163 | 184 | { |
| 164 | 185 | $oid = false; |
| 165 | 186 | } |
| 166 | - if ($oid === false && $table && $column) // table might not use oid's, default for 8.1+ |
|
| 187 | + if ($oid === false && $table && $column) |
|
| 188 | + { |
|
| 189 | + // table might not use oid's, default for 8.1+ |
|
| 167 | 190 | { |
| 168 | 191 | // try the standard sequence name first, due to table renames etc. this might not be the correct one |
| 169 | 192 | if (!($ret = $this->GetOne($sql='SELECT currval('.$this->qstr($table.'_'.$column.'_seq').')'))) { |
| 170 | 193 | // now we read the sequence name from the database itself, that is a lot slower! |
| 171 | 194 | $cols = $this->MetaColumns($table); |
| 195 | + } |
|
| 172 | 196 | $fld = $cols[strtoupper($column)]; |
| 173 | 197 | if ($fld->primary_key && $fld->has_default && |
| 174 | - preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) { |
|
| 198 | + preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) |
|
| 199 | + { |
|
| 175 | 200 | $ret = $this->GetOne($sql='SELECT currval('.$this->qstr($matches[1]).')'); |
| 176 | 201 | } |
| 177 | 202 | } |
@@ -185,7 +210,10 @@ discard block |
||
| 185 | 210 | // Warning: This compilation does not support pg_cmdtuples() in d:/inetpub/wwwroot/php/adodb/adodb-postgres.inc.php on line 44 |
| 186 | 211 | function _affectedrows() |
| 187 | 212 | { |
| 188 | - if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; |
|
| 213 | + if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') |
|
| 214 | + { |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 189 | 217 | return pg_cmdtuples($this->_resultid); |
| 190 | 218 | } |
| 191 | 219 | |
@@ -193,22 +221,34 @@ discard block |
||
| 193 | 221 | // returns true/false |
| 194 | 222 | function BeginTrans() |
| 195 | 223 | { |
| 196 | - if ($this->transOff) return true; |
|
| 224 | + if ($this->transOff) |
|
| 225 | + { |
|
| 226 | + return true; |
|
| 227 | + } |
|
| 197 | 228 | $this->transCnt += 1; |
| 198 | 229 | return @pg_Exec($this->_connectionID, "begin"); |
| 199 | 230 | } |
| 200 | 231 | |
| 201 | 232 | function RowLock($tables,$where,$flds='1 as ignore') |
| 202 | 233 | { |
| 203 | - if (!$this->transCnt) $this->BeginTrans(); |
|
| 234 | + if (!$this->transCnt) |
|
| 235 | + { |
|
| 236 | + $this->BeginTrans(); |
|
| 237 | + } |
|
| 204 | 238 | return $this->GetOne("select $flds from $tables where $where for update"); |
| 205 | 239 | } |
| 206 | 240 | |
| 207 | 241 | // returns true/false. |
| 208 | 242 | function CommitTrans($ok=true) |
| 209 | 243 | { |
| 210 | - if ($this->transOff) return true; |
|
| 211 | - if (!$ok) return $this->RollbackTrans(); |
|
| 244 | + if ($this->transOff) |
|
| 245 | + { |
|
| 246 | + return true; |
|
| 247 | + } |
|
| 248 | + if (!$ok) |
|
| 249 | + { |
|
| 250 | + return $this->RollbackTrans(); |
|
| 251 | + } |
|
| 212 | 252 | |
| 213 | 253 | $this->transCnt -= 1; |
| 214 | 254 | return @pg_Exec($this->_connectionID, "commit"); |
@@ -217,7 +257,10 @@ discard block |
||
| 217 | 257 | // returns true/false |
| 218 | 258 | function RollbackTrans() |
| 219 | 259 | { |
| 220 | - if ($this->transOff) return true; |
|
| 260 | + if ($this->transOff) |
|
| 261 | + { |
|
| 262 | + return true; |
|
| 263 | + } |
|
| 221 | 264 | $this->transCnt -= 1; |
| 222 | 265 | return @pg_Exec($this->_connectionID, "rollback"); |
| 223 | 266 | } |
@@ -225,29 +268,35 @@ discard block |
||
| 225 | 268 | function &MetaTables($ttype=false,$showSchema=false,$mask=false) |
| 226 | 269 | { |
| 227 | 270 | $info = $this->ServerInfo(); |
| 228 | - if ($info['version'] >= 7.3) { |
|
| 271 | + if ($info['version'] >= 7.3) |
|
| 272 | + { |
|
| 229 | 273 | $this->metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' |
| 230 | 274 | and schemaname not in ( 'pg_catalog','information_schema') |
| 231 | 275 | union |
| 232 | 276 | select viewname,'V' from pg_views where viewname not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema') "; |
| 233 | 277 | } |
| 234 | - if ($mask) { |
|
| 278 | + if ($mask) |
|
| 279 | + { |
|
| 235 | 280 | $save = $this->metaTablesSQL; |
| 236 | 281 | $mask = $this->qstr(strtolower($mask)); |
| 237 | 282 | if ($info['version']>=7.3) |
| 238 | - $this->metaTablesSQL = " |
|
| 283 | + { |
|
| 284 | + $this->metaTablesSQL = " |
|
| 239 | 285 | select tablename,'T' from pg_tables where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema') |
| 240 | 286 | union |
| 241 | 287 | select viewname,'V' from pg_views where viewname like $mask and schemaname not in ( 'pg_catalog','information_schema') "; |
| 242 | - else |
|
| 243 | - $this->metaTablesSQL = " |
|
| 288 | + } |
|
| 289 | + else { |
|
| 290 | + $this->metaTablesSQL = " |
|
| 244 | 291 | select tablename,'T' from pg_tables where tablename like $mask |
| 245 | 292 | union |
| 246 | 293 | select viewname,'V' from pg_views where viewname like $mask"; |
| 294 | + } |
|
| 247 | 295 | } |
| 248 | 296 | $ret =& ADOConnection::MetaTables($ttype,$showSchema); |
| 249 | 297 | |
| 250 | - if ($mask) { |
|
| 298 | + if ($mask) |
|
| 299 | + { |
|
| 251 | 300 | $this->metaTablesSQL = $save; |
| 252 | 301 | } |
| 253 | 302 | return $ret; |
@@ -256,16 +305,23 @@ discard block |
||
| 256 | 305 | // if magic quotes disabled, use pg_escape_string() |
| 257 | 306 | function qstr($s,$magic_quotes=false) |
| 258 | 307 | { |
| 259 | - if (is_bool($s)) return $s ? 'true' : 'false'; |
|
| 308 | + if (is_bool($s)) |
|
| 309 | + { |
|
| 310 | + return $s ? 'true' : 'false'; |
|
| 311 | + } |
|
| 260 | 312 | |
| 261 | - if (!$magic_quotes) { |
|
| 262 | - if (ADODB_PHPVER >= 0x5200) { |
|
| 313 | + if (!$magic_quotes) |
|
| 314 | + { |
|
| 315 | + if (ADODB_PHPVER >= 0x5200) |
|
| 316 | + { |
|
| 263 | 317 | return "'".pg_escape_string($this->_connectionID,$s)."'"; |
| 264 | 318 | } |
| 265 | - if (ADODB_PHPVER >= 0x4200) { |
|
| 319 | + if (ADODB_PHPVER >= 0x4200) |
|
| 320 | + { |
|
| 266 | 321 | return "'".pg_escape_string($s)."'"; |
| 267 | 322 | } |
| 268 | - if ($this->replaceQuote[0] == '\\'){ |
|
| 323 | + if ($this->replaceQuote[0] == '\\') |
|
| 324 | + { |
|
| 269 | 325 | $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\\000"),$s); |
| 270 | 326 | } |
| 271 | 327 | return "'".str_replace("'",$this->replaceQuote,$s)."'"; |
@@ -280,13 +336,18 @@ discard block |
||
| 280 | 336 | // Format date column in sql string given an input format that understands Y M D |
| 281 | 337 | function SQLDate($fmt, $col=false) |
| 282 | 338 | { |
| 283 | - if (!$col) $col = $this->sysTimeStamp; |
|
| 339 | + if (!$col) |
|
| 340 | + { |
|
| 341 | + $col = $this->sysTimeStamp; |
|
| 342 | + } |
|
| 284 | 343 | $s = 'TO_CHAR('.$col.",'"; |
| 285 | 344 | |
| 286 | 345 | $len = strlen($fmt); |
| 287 | - for ($i=0; $i < $len; $i++) { |
|
| 346 | + for ($i=0; $i < $len; $i++) |
|
| 347 | + { |
|
| 288 | 348 | $ch = $fmt[$i]; |
| 289 | - switch($ch) { |
|
| 349 | + switch($ch) |
|
| 350 | + { |
|
| 290 | 351 | case 'Y': |
| 291 | 352 | case 'y': |
| 292 | 353 | $s .= 'YYYY'; |
@@ -339,12 +400,18 @@ discard block |
||
| 339 | 400 | |
| 340 | 401 | default: |
| 341 | 402 | // handle escape characters... |
| 342 | - if ($ch == '\\') { |
|
| 403 | + if ($ch == '\\') |
|
| 404 | + { |
|
| 343 | 405 | $i++; |
| 344 | 406 | $ch = substr($fmt,$i,1); |
| 345 | 407 | } |
| 346 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
| 347 | - else $s .= '"'.$ch.'"'; |
|
| 408 | + if (strpos('-/.:;, ',$ch) !== false) |
|
| 409 | + { |
|
| 410 | + $s .= $ch; |
|
| 411 | + } |
|
| 412 | + else { |
|
| 413 | + $s .= '"'.$ch.'"'; |
|
| 414 | + } |
|
| 348 | 415 | |
| 349 | 416 | } |
| 350 | 417 | } |
@@ -386,7 +453,10 @@ discard block |
||
| 386 | 453 | */ |
| 387 | 454 | function GuessOID($oid) |
| 388 | 455 | { |
| 389 | - if (strlen($oid)>16) return false; |
|
| 456 | + if (strlen($oid)>16) |
|
| 457 | + { |
|
| 458 | + return false; |
|
| 459 | + } |
|
| 390 | 460 | return is_numeric($oid); |
| 391 | 461 | } |
| 392 | 462 | |
@@ -404,18 +474,34 @@ discard block |
||
| 404 | 474 | */ |
| 405 | 475 | function BlobDecode($blob,$maxsize=false,$hastrans=true) |
| 406 | 476 | { |
| 407 | - if (!$this->GuessOID($blob)) return $blob; |
|
| 477 | + if (!$this->GuessOID($blob)) |
|
| 478 | + { |
|
| 479 | + return $blob; |
|
| 480 | + } |
|
| 408 | 481 | |
| 409 | - if ($hastrans) @pg_exec($this->_connectionID,"begin"); |
|
| 482 | + if ($hastrans) |
|
| 483 | + { |
|
| 484 | + @pg_exec($this->_connectionID,"begin"); |
|
| 485 | + } |
|
| 410 | 486 | $fd = @pg_lo_open($this->_connectionID,$blob,"r"); |
| 411 | - if ($fd === false) { |
|
| 412 | - if ($hastrans) @pg_exec($this->_connectionID,"commit"); |
|
| 487 | + if ($fd === false) |
|
| 488 | + { |
|
| 489 | + if ($hastrans) |
|
| 490 | + { |
|
| 491 | + @pg_exec($this->_connectionID,"commit"); |
|
| 492 | + } |
|
| 413 | 493 | return $blob; |
| 414 | 494 | } |
| 415 | - if (!$maxsize) $maxsize = $this->maxblobsize; |
|
| 495 | + if (!$maxsize) |
|
| 496 | + { |
|
| 497 | + $maxsize = $this->maxblobsize; |
|
| 498 | + } |
|
| 416 | 499 | $realblob = @pg_loread($fd,$maxsize); |
| 417 | 500 | @pg_loclose($fd); |
| 418 | - if ($hastrans) @pg_exec($this->_connectionID,"commit"); |
|
| 501 | + if ($hastrans) |
|
| 502 | + { |
|
| 503 | + @pg_exec($this->_connectionID,"commit"); |
|
| 504 | + } |
|
| 419 | 505 | return $realblob; |
| 420 | 506 | } |
| 421 | 507 | |
@@ -428,7 +514,10 @@ discard block |
||
| 428 | 514 | */ |
| 429 | 515 | function BlobEncode($blob) |
| 430 | 516 | { |
| 431 | - if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob); |
|
| 517 | + if (ADODB_PHPVER >= 0x4200) |
|
| 518 | + { |
|
| 519 | + return pg_escape_bytea($blob); |
|
| 520 | + } |
|
| 432 | 521 | |
| 433 | 522 | /*92=backslash, 0=null, 39=single-quote*/ |
| 434 | 523 | $badch = array(chr(92),chr(0),chr(39)); # \ null ' |
@@ -442,7 +531,8 @@ discard block |
||
| 442 | 531 | function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
| 443 | 532 | { |
| 444 | 533 | |
| 445 | - if ($blobtype == 'CLOB') { |
|
| 534 | + if ($blobtype == 'CLOB') |
|
| 535 | + { |
|
| 446 | 536 | return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
| 447 | 537 | } |
| 448 | 538 | // do not use bind params which uses qstr(), as blobencode() already quotes data |
@@ -451,7 +541,10 @@ discard block |
||
| 451 | 541 | |
| 452 | 542 | function OffsetDate($dayFraction,$date=false) |
| 453 | 543 | { |
| 454 | - if (!$date) $date = $this->sysDate; |
|
| 544 | + if (!$date) |
|
| 545 | + { |
|
| 546 | + $date = $this->sysDate; |
|
| 547 | + } |
|
| 455 | 548 | return "($date+interval'$dayFraction days')"; |
| 456 | 549 | } |
| 457 | 550 | |
@@ -462,26 +555,45 @@ discard block |
||
| 462 | 555 | { |
| 463 | 556 | global $ADODB_FETCH_MODE; |
| 464 | 557 | //if tablenames are quoted, remove the quotes as the tablenames here are used for comparsion of content of fields in postgres system tables |
| 465 | - if (!empty($this->nameQuote) && !(strpos($table,$this->nameQuote)===false)) $table = str_replace($this->nameQuote,'',$table); |
|
| 558 | + if (!empty($this->nameQuote) && !(strpos($table,$this->nameQuote)===false)) |
|
| 559 | + { |
|
| 560 | + $table = str_replace($this->nameQuote,'',$table); |
|
| 561 | + } |
|
| 466 | 562 | $schema = false; |
| 467 | 563 | $false = false; |
| 468 | 564 | $this->_findschema($table,$schema); |
| 469 | 565 | |
| 470 | - if ($normalize) $table = strtolower($table); |
|
| 566 | + if ($normalize) |
|
| 567 | + { |
|
| 568 | + $table = strtolower($table); |
|
| 569 | + } |
|
| 471 | 570 | |
| 472 | 571 | $save = $ADODB_FETCH_MODE; |
| 473 | 572 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 474 | - if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); |
|
| 573 | + if ($this->fetchMode !== false) |
|
| 574 | + { |
|
| 575 | + $savem = $this->SetFetchMode(false); |
|
| 576 | + } |
|
| 475 | 577 | |
| 476 | - if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); |
|
| 477 | - else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); |
|
| 478 | - if (isset($savem)) $this->SetFetchMode($savem); |
|
| 578 | + if ($schema) |
|
| 579 | + { |
|
| 580 | + $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); |
|
| 581 | + } |
|
| 582 | + else { |
|
| 583 | + $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); |
|
| 584 | + } |
|
| 585 | + if (isset($savem)) |
|
| 586 | + { |
|
| 587 | + $this->SetFetchMode($savem); |
|
| 588 | + } |
|
| 479 | 589 | $ADODB_FETCH_MODE = $save; |
| 480 | 590 | |
| 481 | - if ($rs === false) { |
|
| 591 | + if ($rs === false) |
|
| 592 | + { |
|
| 482 | 593 | return $false; |
| 483 | 594 | } |
| 484 | - if (!empty($this->metaKeySQL)) { |
|
| 595 | + if (!empty($this->metaKeySQL)) |
|
| 596 | + { |
|
| 485 | 597 | // If we want the primary keys, we have to issue a separate query |
| 486 | 598 | // Of course, a modified version of the metaColumnsSQL query using a |
| 487 | 599 | // LEFT JOIN would have been much more elegant, but postgres does |
@@ -492,7 +604,10 @@ discard block |
||
| 492 | 604 | $rskey = $this->Execute(sprintf($this->metaKeySQL,($table))); |
| 493 | 605 | // fetch all result in once for performance. |
| 494 | 606 | $keys =& $rskey->GetArray(); |
| 495 | - if (isset($savem)) $this->SetFetchMode($savem); |
|
| 607 | + if (isset($savem)) |
|
| 608 | + { |
|
| 609 | + $this->SetFetchMode($savem); |
|
| 610 | + } |
|
| 496 | 611 | $ADODB_FETCH_MODE = $save; |
| 497 | 612 | |
| 498 | 613 | $rskey->Close(); |
@@ -500,18 +615,26 @@ discard block |
||
| 500 | 615 | } |
| 501 | 616 | |
| 502 | 617 | $rsdefa = array(); |
| 503 | - if (!empty($this->metaDefaultsSQL)) { |
|
| 618 | + if (!empty($this->metaDefaultsSQL)) |
|
| 619 | + { |
|
| 504 | 620 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
| 505 | 621 | $sql = sprintf($this->metaDefaultsSQL, ($table)); |
| 506 | 622 | $rsdef = $this->Execute($sql); |
| 507 | - if (isset($savem)) $this->SetFetchMode($savem); |
|
| 623 | + if (isset($savem)) |
|
| 624 | + { |
|
| 625 | + $this->SetFetchMode($savem); |
|
| 626 | + } |
|
| 508 | 627 | $ADODB_FETCH_MODE = $save; |
| 509 | 628 | |
| 510 | - if ($rsdef) { |
|
| 511 | - while (!$rsdef->EOF) { |
|
| 629 | + if ($rsdef) |
|
| 630 | + { |
|
| 631 | + while (!$rsdef->EOF) |
|
| 632 | + { |
|
| 512 | 633 | $num = $rsdef->fields['num']; |
| 513 | 634 | $s = $rsdef->fields['def']; |
| 514 | - if (strpos($s,'::')===false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ |
|
| 635 | + if (strpos($s,'::')===false && substr($s, 0, 1) == "'") |
|
| 636 | + { |
|
| 637 | +/* quoted strings hack... for now... fixme */ |
|
| 515 | 638 | $s = substr($s, 1); |
| 516 | 639 | $s = substr($s, 0, strlen($s) - 1); |
| 517 | 640 | } |
@@ -519,56 +642,83 @@ discard block |
||
| 519 | 642 | $rsdefa[$num] = $s; |
| 520 | 643 | $rsdef->MoveNext(); |
| 521 | 644 | } |
| 522 | - } else { |
|
| 645 | + } |
|
| 646 | + else |
|
| 647 | + { |
|
| 523 | 648 | ADOConnection::outp( "==> SQL => " . $sql); |
| 524 | 649 | } |
| 525 | 650 | unset($rsdef); |
| 526 | 651 | } |
| 527 | 652 | |
| 528 | 653 | $retarr = array(); |
| 529 | - while (!$rs->EOF) { |
|
| 654 | + while (!$rs->EOF) |
|
| 655 | + { |
|
| 530 | 656 | $fld = new ADOFieldObject(); |
| 531 | 657 | $fld->name = $rs->fields[0]; |
| 532 | 658 | $fld->type = $rs->fields[1]; |
| 533 | 659 | $fld->max_length = $rs->fields[2]; |
| 534 | - if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4; |
|
| 535 | - if ($fld->max_length <= 0) $fld->max_length = -1; |
|
| 536 | - if ($fld->type == 'numeric') { |
|
| 660 | + if ($fld->max_length <= 0) |
|
| 661 | + { |
|
| 662 | + $fld->max_length = $rs->fields[3]-4; |
|
| 663 | + } |
|
| 664 | + if ($fld->max_length <= 0) |
|
| 665 | + { |
|
| 666 | + $fld->max_length = -1; |
|
| 667 | + } |
|
| 668 | + if ($fld->type == 'numeric') |
|
| 669 | + { |
|
| 537 | 670 | $fld->scale = $fld->max_length & 0xFFFF; |
| 538 | 671 | $fld->max_length >>= 16; |
| 539 | 672 | } |
| 540 | 673 | // dannym |
| 541 | 674 | // 5 hasdefault; 6 num-of-column |
| 542 | 675 | $fld->has_default = ($rs->fields[5] == 't'); |
| 543 | - if ($fld->has_default) { |
|
| 676 | + if ($fld->has_default) |
|
| 677 | + { |
|
| 544 | 678 | $fld->default_value = $rsdefa[$rs->fields[6]]; |
| 545 | 679 | } |
| 546 | 680 | |
| 547 | 681 | //Freek |
| 548 | - if ($rs->fields[4] == 't') { |
|
| 682 | + if ($rs->fields[4] == 't') |
|
| 683 | + { |
|
| 549 | 684 | $fld->not_null = true; |
| 550 | 685 | } |
| 551 | 686 | |
| 552 | 687 | // Freek |
| 553 | - if (is_array($keys)) { |
|
| 554 | - foreach($keys as $key) { |
|
| 688 | + if (is_array($keys)) |
|
| 689 | + { |
|
| 690 | + foreach($keys as $key) |
|
| 691 | + { |
|
| 555 | 692 | if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't') |
| 556 | - $fld->primary_key = true; |
|
| 693 | + { |
|
| 694 | + $fld->primary_key = true; |
|
| 695 | + } |
|
| 557 | 696 | if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't') |
| 558 | - $fld->unique = true; // What name is more compatible? |
|
| 697 | + { |
|
| 698 | + $fld->unique = true; |
|
| 699 | + } |
|
| 700 | + // What name is more compatible? |
|
| 559 | 701 | } |
| 560 | 702 | } |
| 561 | 703 | |
| 562 | - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; |
|
| 563 | - else $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld; |
|
| 704 | + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) |
|
| 705 | + { |
|
| 706 | + $retarr[] = $fld; |
|
| 707 | + } |
|
| 708 | + else { |
|
| 709 | + $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld; |
|
| 710 | + } |
|
| 564 | 711 | |
| 565 | 712 | $rs->MoveNext(); |
| 566 | 713 | } |
| 567 | 714 | $rs->Close(); |
| 568 | 715 | if (empty($retarr)) |
| 569 | - return $false; |
|
| 570 | - else |
|
| 571 | - return $retarr; |
|
| 716 | + { |
|
| 717 | + return $false; |
|
| 718 | + } |
|
| 719 | + else { |
|
| 720 | + return $retarr; |
|
| 721 | + } |
|
| 572 | 722 | |
| 573 | 723 | } |
| 574 | 724 | |
@@ -582,7 +732,9 @@ discard block |
||
| 582 | 732 | $schema = false; |
| 583 | 733 | $this->_findschema($table,$schema); |
| 584 | 734 | |
| 585 | - if ($schema) { // requires pgsql 7.3+ - pg_namespace used. |
|
| 735 | + if ($schema) |
|
| 736 | + { |
|
| 737 | +// requires pgsql 7.3+ - pg_namespace used. |
|
| 586 | 738 | $sql = ' |
| 587 | 739 | SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" |
| 588 | 740 | FROM pg_catalog.pg_class c |
@@ -590,7 +742,9 @@ discard block |
||
| 590 | 742 | JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid |
| 591 | 743 | ,pg_namespace n |
| 592 | 744 | WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\')) and c.relnamespace=c2.relnamespace and c.relnamespace=n.oid and n.nspname=\'%s\' AND i.indisprimary=false'; |
| 593 | - } else { |
|
| 745 | + } |
|
| 746 | + else |
|
| 747 | + { |
|
| 594 | 748 | $sql = ' |
| 595 | 749 | SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" |
| 596 | 750 | FROM pg_catalog.pg_class c |
@@ -599,32 +753,38 @@ discard block |
||
| 599 | 753 | WHERE c2.relname=\'%s\' or c2.relname=lower(\'%s\')'; |
| 600 | 754 | } |
| 601 | 755 | |
| 602 | - if ($primary == FALSE) { |
|
| 756 | + if ($primary == FALSE) |
|
| 757 | + { |
|
| 603 | 758 | $sql .= ' AND i.indisprimary=false;'; |
| 604 | 759 | } |
| 605 | 760 | |
| 606 | 761 | $save = $ADODB_FETCH_MODE; |
| 607 | 762 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 608 | - if ($this->fetchMode !== FALSE) { |
|
| 763 | + if ($this->fetchMode !== FALSE) |
|
| 764 | + { |
|
| 609 | 765 | $savem = $this->SetFetchMode(FALSE); |
| 610 | 766 | } |
| 611 | 767 | |
| 612 | 768 | $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); |
| 613 | - if (isset($savem)) { |
|
| 769 | + if (isset($savem)) |
|
| 770 | + { |
|
| 614 | 771 | $this->SetFetchMode($savem); |
| 615 | 772 | } |
| 616 | 773 | $ADODB_FETCH_MODE = $save; |
| 617 | 774 | |
| 618 | - if (!is_object($rs)) { |
|
| 775 | + if (!is_object($rs)) |
|
| 776 | + { |
|
| 619 | 777 | $false = false; |
| 620 | 778 | return $false; |
| 621 | 779 | } |
| 622 | 780 | |
| 623 | 781 | $col_names = $this->MetaColumnNames($table,true); |
| 624 | 782 | $indexes = array(); |
| 625 | - while ($row = $rs->FetchRow()) { |
|
| 783 | + while ($row = $rs->FetchRow()) |
|
| 784 | + { |
|
| 626 | 785 | $columns = array(); |
| 627 | - foreach (explode(' ', $row[2]) as $col) { |
|
| 786 | + foreach (explode(' ', $row[2]) as $col) |
|
| 787 | + { |
|
| 628 | 788 | $columns[] = $col_names[$col - 1]; |
| 629 | 789 | } |
| 630 | 790 | |
@@ -644,43 +804,85 @@ discard block |
||
| 644 | 804 | function _connect($str,$user='',$pwd='',$db='',$ctype=0) |
| 645 | 805 | { |
| 646 | 806 | |
| 647 | - if (!function_exists('pg_pconnect')) return null; |
|
| 807 | + if (!function_exists('pg_pconnect')) |
|
| 808 | + { |
|
| 809 | + return null; |
|
| 810 | + } |
|
| 648 | 811 | |
| 649 | 812 | $this->_errorMsg = false; |
| 650 | 813 | |
| 651 | - if ($user || $pwd || $db) { |
|
| 814 | + if ($user || $pwd || $db) |
|
| 815 | + { |
|
| 652 | 816 | $user = adodb_addslashes($user); |
| 653 | 817 | $pwd = adodb_addslashes($pwd); |
| 654 | - if (strlen($db) == 0) $db = 'template1'; |
|
| 818 | + if (strlen($db) == 0) |
|
| 819 | + { |
|
| 820 | + $db = 'template1'; |
|
| 821 | + } |
|
| 655 | 822 | $db = adodb_addslashes($db); |
| 656 | - if ($str) { |
|
| 823 | + if ($str) |
|
| 824 | + { |
|
| 657 | 825 | $host = explode(":", $str); |
| 658 | - if ($host[0]) $str = "host=".adodb_addslashes($host[0]); |
|
| 659 | - else $str = 'host=localhost'; |
|
| 660 | - if (isset($host[1])) $str .= " port=$host[1]"; |
|
| 661 | - else if (!empty($this->port)) $str .= " port=".$this->port; |
|
| 826 | + if ($host[0]) |
|
| 827 | + { |
|
| 828 | + $str = "host=".adodb_addslashes($host[0]); |
|
| 829 | + } |
|
| 830 | + else { |
|
| 831 | + $str = 'host=localhost'; |
|
| 832 | + } |
|
| 833 | + if (isset($host[1])) |
|
| 834 | + { |
|
| 835 | + $str .= " port=$host[1]"; |
|
| 836 | + } |
|
| 837 | + else if (!empty($this->port)) |
|
| 838 | + { |
|
| 839 | + $str .= " port=".$this->port; |
|
| 840 | + } |
|
| 662 | 841 | } |
| 663 | - if ($user) $str .= " user=".$user; |
|
| 664 | - if ($pwd) $str .= " password=".$pwd; |
|
| 665 | - if ($db) $str .= " dbname=".$db; |
|
| 842 | + if ($user) |
|
| 843 | + { |
|
| 844 | + $str .= " user=".$user; |
|
| 845 | + } |
|
| 846 | + if ($pwd) |
|
| 847 | + { |
|
| 848 | + $str .= " password=".$pwd; |
|
| 849 | + } |
|
| 850 | + if ($db) |
|
| 851 | + { |
|
| 852 | + $str .= " dbname=".$db; |
|
| 853 | + } |
|
| 666 | 854 | } |
| 667 | 855 | |
| 668 | 856 | //if ($user) $linea = "user=$user host=$linea password=$pwd dbname=$db port=5432"; |
| 669 | 857 | |
| 670 | - if ($ctype === 1) { // persistent |
|
| 858 | + if ($ctype === 1) |
|
| 859 | + { |
|
| 860 | +// persistent |
|
| 671 | 861 | $this->_connectionID = pg_pconnect($str); |
| 672 | - } else { |
|
| 673 | - if ($ctype === -1) { // nconnect, we trick pgsql ext by changing the connection str |
|
| 862 | + } |
|
| 863 | + else |
|
| 864 | + { |
|
| 865 | + if ($ctype === -1) |
|
| 866 | + { |
|
| 867 | +// nconnect, we trick pgsql ext by changing the connection str |
|
| 674 | 868 | static $ncnt; |
| 675 | 869 | |
| 676 | - if (empty($ncnt)) $ncnt = 1; |
|
| 677 | - else $ncnt += 1; |
|
| 870 | + if (empty($ncnt)) |
|
| 871 | + { |
|
| 872 | + $ncnt = 1; |
|
| 873 | + } |
|
| 874 | + else { |
|
| 875 | + $ncnt += 1; |
|
| 876 | + } |
|
| 678 | 877 | |
| 679 | 878 | $str .= str_repeat(' ',$ncnt); |
| 680 | 879 | } |
| 681 | 880 | $this->_connectionID = pg_connect($str); |
| 682 | 881 | } |
| 683 | - if ($this->_connectionID === false) return false; |
|
| 882 | + if ($this->_connectionID === false) |
|
| 883 | + { |
|
| 884 | + return false; |
|
| 885 | + } |
|
| 684 | 886 | $this->Execute("set datestyle='ISO'"); |
| 685 | 887 | return true; |
| 686 | 888 | } |
@@ -705,7 +907,8 @@ discard block |
||
| 705 | 907 | function _query($sql,$inputarr) |
| 706 | 908 | { |
| 707 | 909 | |
| 708 | - if ($inputarr) { |
|
| 910 | + if ($inputarr) |
|
| 911 | + { |
|
| 709 | 912 | /* |
| 710 | 913 | It appears that PREPARE/EXECUTE is slower for many queries. |
| 711 | 914 | |
@@ -722,29 +925,54 @@ discard block |
||
| 722 | 925 | $plan = 'P'.md5($sql); |
| 723 | 926 | |
| 724 | 927 | $execp = ''; |
| 725 | - foreach($inputarr as $v) { |
|
| 726 | - if ($execp) $execp .= ','; |
|
| 727 | - if (is_string($v)) { |
|
| 728 | - if (strncmp($v,"'",1) !== 0) $execp .= $this->qstr($v); |
|
| 729 | - } else { |
|
| 928 | + foreach($inputarr as $v) |
|
| 929 | + { |
|
| 930 | + if ($execp) |
|
| 931 | + { |
|
| 932 | + $execp .= ','; |
|
| 933 | + } |
|
| 934 | + if (is_string($v)) |
|
| 935 | + { |
|
| 936 | + if (strncmp($v,"'",1) !== 0) |
|
| 937 | + { |
|
| 938 | + $execp .= $this->qstr($v); |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | + else |
|
| 942 | + { |
|
| 730 | 943 | $execp .= $v; |
| 731 | 944 | } |
| 732 | 945 | } |
| 733 | 946 | |
| 734 | - if ($execp) $exsql = "EXECUTE $plan ($execp)"; |
|
| 735 | - else $exsql = "EXECUTE $plan"; |
|
| 947 | + if ($execp) |
|
| 948 | + { |
|
| 949 | + $exsql = "EXECUTE $plan ($execp)"; |
|
| 950 | + } |
|
| 951 | + else { |
|
| 952 | + $exsql = "EXECUTE $plan"; |
|
| 953 | + } |
|
| 736 | 954 | |
| 737 | 955 | $rez = @pg_exec($this->_connectionID,$exsql); |
| 738 | - if (!$rez) { |
|
| 956 | + if (!$rez) |
|
| 957 | + { |
|
| 739 | 958 | # Perhaps plan does not exist? Prepare/compile plan. |
| 740 | 959 | $params = ''; |
| 741 | - foreach($inputarr as $v) { |
|
| 742 | - if ($params) $params .= ','; |
|
| 743 | - if (is_string($v)) { |
|
| 960 | + foreach($inputarr as $v) |
|
| 961 | + { |
|
| 962 | + if ($params) |
|
| 963 | + { |
|
| 964 | + $params .= ','; |
|
| 965 | + } |
|
| 966 | + if (is_string($v)) |
|
| 967 | + { |
|
| 744 | 968 | $params .= 'VARCHAR'; |
| 745 | - } else if (is_integer($v)) { |
|
| 969 | + } |
|
| 970 | + else if (is_integer($v)) |
|
| 971 | + { |
|
| 746 | 972 | $params .= 'INTEGER'; |
| 747 | - } else { |
|
| 973 | + } |
|
| 974 | + else |
|
| 975 | + { |
|
| 748 | 976 | $params .= "REAL"; |
| 749 | 977 | } |
| 750 | 978 | } |
@@ -752,7 +980,8 @@ discard block |
||
| 752 | 980 | //print_r($sqlarr); |
| 753 | 981 | $sql = ''; |
| 754 | 982 | $i = 1; |
| 755 | - foreach($sqlarr as $v) { |
|
| 983 | + foreach($sqlarr as $v) |
|
| 984 | + { |
|
| 756 | 985 | $sql .= $v.' $'.$i; |
| 757 | 986 | $i++; |
| 758 | 987 | } |
@@ -763,14 +992,18 @@ discard block |
||
| 763 | 992 | } |
| 764 | 993 | |
| 765 | 994 | $rez = pg_exec($this->_connectionID,$exsql); |
| 766 | - } else { |
|
| 995 | + } |
|
| 996 | + else |
|
| 997 | + { |
|
| 767 | 998 | $this->_errorMsg = false; |
| 768 | 999 | //adodb_backtrace(); |
| 769 | 1000 | $rez = pg_exec($this->_connectionID,$sql); |
| 770 | 1001 | } |
| 771 | 1002 | // check if no data returned, then no need to create real recordset |
| 772 | - if ($rez && pg_numfields($rez) <= 0) { |
|
| 773 | - if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') { |
|
| 1003 | + if ($rez && pg_numfields($rez) <= 0) |
|
| 1004 | + { |
|
| 1005 | + if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') |
|
| 1006 | + { |
|
| 774 | 1007 | pg_freeresult($this->_resultid); |
| 775 | 1008 | } |
| 776 | 1009 | $this->_resultid = $rez; |
@@ -784,19 +1017,38 @@ discard block |
||
| 784 | 1017 | /* Returns: the last error message from previous database operation */ |
| 785 | 1018 | function ErrorMsg() |
| 786 | 1019 | { |
| 787 | - if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
| 788 | - if (ADODB_PHPVER >= 0x4300) { |
|
| 789 | - if (!empty($this->_resultid)) { |
|
| 1020 | + if ($this->_errorMsg !== false) |
|
| 1021 | + { |
|
| 1022 | + return $this->_errorMsg; |
|
| 1023 | + } |
|
| 1024 | + if (ADODB_PHPVER >= 0x4300) |
|
| 1025 | + { |
|
| 1026 | + if (!empty($this->_resultid)) |
|
| 1027 | + { |
|
| 790 | 1028 | $this->_errorMsg = @pg_result_error($this->_resultid); |
| 791 | - if ($this->_errorMsg) return $this->_errorMsg; |
|
| 1029 | + if ($this->_errorMsg) |
|
| 1030 | + { |
|
| 1031 | + return $this->_errorMsg; |
|
| 1032 | + } |
|
| 792 | 1033 | } |
| 793 | 1034 | |
| 794 | - if (!empty($this->_connectionID)) { |
|
| 1035 | + if (!empty($this->_connectionID)) |
|
| 1036 | + { |
|
| 795 | 1037 | $this->_errorMsg = @pg_last_error($this->_connectionID); |
| 796 | - } else $this->_errorMsg = @pg_last_error(); |
|
| 797 | - } else { |
|
| 798 | - if (empty($this->_connectionID)) $this->_errorMsg = @pg_errormessage(); |
|
| 799 | - else $this->_errorMsg = @pg_errormessage($this->_connectionID); |
|
| 1038 | + } |
|
| 1039 | + else { |
|
| 1040 | + $this->_errorMsg = @pg_last_error(); |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + else |
|
| 1044 | + { |
|
| 1045 | + if (empty($this->_connectionID)) |
|
| 1046 | + { |
|
| 1047 | + $this->_errorMsg = @pg_errormessage(); |
|
| 1048 | + } |
|
| 1049 | + else { |
|
| 1050 | + $this->_errorMsg = @pg_errormessage($this->_connectionID); |
|
| 1051 | + } |
|
| 800 | 1052 | } |
| 801 | 1053 | return $this->_errorMsg; |
| 802 | 1054 | } |
@@ -804,7 +1056,8 @@ discard block |
||
| 804 | 1056 | function ErrorNo() |
| 805 | 1057 | { |
| 806 | 1058 | $e = $this->ErrorMsg(); |
| 807 | - if (strlen($e)) { |
|
| 1059 | + if (strlen($e)) |
|
| 1060 | + { |
|
| 808 | 1061 | return ADOConnection::MetaError($e); |
| 809 | 1062 | } |
| 810 | 1063 | return 0; |
@@ -813,8 +1066,12 @@ discard block |
||
| 813 | 1066 | // returns true or false |
| 814 | 1067 | function _close() |
| 815 | 1068 | { |
| 816 | - if ($this->transCnt) $this->RollbackTrans(); |
|
| 817 | - if ($this->_resultid) { |
|
| 1069 | + if ($this->transCnt) |
|
| 1070 | + { |
|
| 1071 | + $this->RollbackTrans(); |
|
| 1072 | + } |
|
| 1073 | + if ($this->_resultid) |
|
| 1074 | + { |
|
| 818 | 1075 | @pg_freeresult($this->_resultid); |
| 819 | 1076 | $this->_resultid = false; |
| 820 | 1077 | } |
@@ -847,13 +1104,15 @@ discard block |
||
| 847 | 1104 | Class Name: Recordset |
| 848 | 1105 | --------------------------------------------------------------------------------------*/ |
| 849 | 1106 | |
| 850 | -class ADORecordSet_postgres64 extends ADORecordSet{ |
|
| 1107 | +class ADORecordSet_postgres64 extends ADORecordSet |
|
| 1108 | +{ |
|
| 851 | 1109 | var $_blobArr; |
| 852 | 1110 | var $databaseType = "postgres64"; |
| 853 | 1111 | var $canSeek = true; |
| 854 | 1112 | function ADORecordSet_postgres64($queryID,$mode=false) |
| 855 | 1113 | { |
| 856 | - if ($mode === false) { |
|
| 1114 | + if ($mode === false) |
|
| 1115 | + { |
|
| 857 | 1116 | global $ADODB_FETCH_MODE; |
| 858 | 1117 | $mode = $ADODB_FETCH_MODE; |
| 859 | 1118 | } |
@@ -872,7 +1131,10 @@ discard block |
||
| 872 | 1131 | |
| 873 | 1132 | function &GetRowAssoc($upper=true) |
| 874 | 1133 | { |
| 875 | - if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields; |
|
| 1134 | + if ($this->fetchMode == PGSQL_ASSOC && !$upper) |
|
| 1135 | + { |
|
| 1136 | + return $this->fields; |
|
| 1137 | + } |
|
| 876 | 1138 | $row =& ADORecordSet::GetRowAssoc($upper); |
| 877 | 1139 | return $row; |
| 878 | 1140 | } |
@@ -887,8 +1149,13 @@ discard block |
||
| 887 | 1149 | // cache types for blob decode check |
| 888 | 1150 | // apparently pg_fieldtype actually performs an sql query on the database to get the type. |
| 889 | 1151 | if (empty($this->connection->noBlobs)) |
| 890 | - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 891 | - if (pg_fieldtype($qid,$i) == 'bytea') { |
|
| 1152 | + { |
|
| 1153 | + for ($i=0, $max = $this->_numOfFields; |
|
| 1154 | + } |
|
| 1155 | + $i < $max; $i++) |
|
| 1156 | + { |
|
| 1157 | + if (pg_fieldtype($qid,$i) == 'bytea') |
|
| 1158 | + { |
|
| 892 | 1159 | $this->_blobArr[$i] = pg_fieldname($qid,$i); |
| 893 | 1160 | } |
| 894 | 1161 | } |
@@ -897,11 +1164,16 @@ discard block |
||
| 897 | 1164 | /* Use associative array to get fields array */ |
| 898 | 1165 | function Fields($colname) |
| 899 | 1166 | { |
| 900 | - if ($this->fetchMode != PGSQL_NUM) return @$this->fields[$colname]; |
|
| 1167 | + if ($this->fetchMode != PGSQL_NUM) |
|
| 1168 | + { |
|
| 1169 | + return @$this->fields[$colname]; |
|
| 1170 | + } |
|
| 901 | 1171 | |
| 902 | - if (!$this->bind) { |
|
| 1172 | + if (!$this->bind) |
|
| 1173 | + { |
|
| 903 | 1174 | $this->bind = array(); |
| 904 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 1175 | + for ($i=0; $i < $this->_numOfFields; $i++) |
|
| 1176 | + { |
|
| 905 | 1177 | $o = $this->FetchField($i); |
| 906 | 1178 | $this->bind[strtoupper($o->name)] = $i; |
| 907 | 1179 | } |
@@ -927,19 +1199,26 @@ discard block |
||
| 927 | 1199 | |
| 928 | 1200 | function _decode($blob) |
| 929 | 1201 | { |
| 930 | - if ($blob === NULL) return NULL; |
|
| 1202 | + if ($blob === NULL) |
|
| 1203 | + { |
|
| 1204 | + return NULL; |
|
| 1205 | + } |
|
| 931 | 1206 | return pg_unescape_bytea($blob); |
| 932 | 1207 | } |
| 933 | 1208 | |
| 934 | 1209 | function _fixblobs() |
| 935 | 1210 | { |
| 936 | - if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) { |
|
| 937 | - foreach($this->_blobArr as $k => $v) { |
|
| 1211 | + if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) |
|
| 1212 | + { |
|
| 1213 | + foreach($this->_blobArr as $k => $v) |
|
| 1214 | + { |
|
| 938 | 1215 | $this->fields[$k] = ADORecordSet_postgres64::_decode($this->fields[$k]); |
| 939 | 1216 | } |
| 940 | 1217 | } |
| 941 | - if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) { |
|
| 942 | - foreach($this->_blobArr as $k => $v) { |
|
| 1218 | + if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) |
|
| 1219 | + { |
|
| 1220 | + foreach($this->_blobArr as $k => $v) |
|
| 1221 | + { |
|
| 943 | 1222 | $this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]); |
| 944 | 1223 | } |
| 945 | 1224 | } |
@@ -948,12 +1227,18 @@ discard block |
||
| 948 | 1227 | // 10% speedup to move MoveNext to child class |
| 949 | 1228 | function MoveNext() |
| 950 | 1229 | { |
| 951 | - if (!$this->EOF) { |
|
| 1230 | + if (!$this->EOF) |
|
| 1231 | + { |
|
| 952 | 1232 | $this->_currentRow++; |
| 953 | - if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { |
|
| 1233 | + if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) |
|
| 1234 | + { |
|
| 954 | 1235 | $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
| 955 | - if (is_array($this->fields) && $this->fields) { |
|
| 956 | - if (isset($this->_blobArr)) $this->_fixblobs(); |
|
| 1236 | + if (is_array($this->fields) && $this->fields) |
|
| 1237 | + { |
|
| 1238 | + if (isset($this->_blobArr)) |
|
| 1239 | + { |
|
| 1240 | + $this->_fixblobs(); |
|
| 1241 | + } |
|
| 957 | 1242 | return true; |
| 958 | 1243 | } |
| 959 | 1244 | } |
@@ -967,11 +1252,16 @@ discard block |
||
| 967 | 1252 | { |
| 968 | 1253 | |
| 969 | 1254 | if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) |
| 970 | - return false; |
|
| 1255 | + { |
|
| 1256 | + return false; |
|
| 1257 | + } |
|
| 971 | 1258 | |
| 972 | 1259 | $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); |
| 973 | 1260 | |
| 974 | - if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); |
|
| 1261 | + if ($this->fields && isset($this->_blobArr)) |
|
| 1262 | + { |
|
| 1263 | + $this->_fixblobs(); |
|
| 1264 | + } |
|
| 975 | 1265 | |
| 976 | 1266 | return (is_array($this->fields)); |
| 977 | 1267 | } |
@@ -983,12 +1273,14 @@ discard block |
||
| 983 | 1273 | |
| 984 | 1274 | function MetaType($t,$len=-1,$fieldobj=false) |
| 985 | 1275 | { |
| 986 | - if (is_object($t)) { |
|
| 1276 | + if (is_object($t)) |
|
| 1277 | + { |
|
| 987 | 1278 | $fieldobj = $t; |
| 988 | 1279 | $t = $fieldobj->type; |
| 989 | 1280 | $len = $fieldobj->max_length; |
| 990 | 1281 | } |
| 991 | - switch (strtoupper($t)) { |
|
| 1282 | + switch (strtoupper($t)) |
|
| 1283 | + { |
|
| 992 | 1284 | case 'MONEY': // stupid, postgres expects money to be a string |
| 993 | 1285 | case 'INTERVAL': |
| 994 | 1286 | case 'CHAR': |
@@ -998,7 +1290,10 @@ discard block |
||
| 998 | 1290 | case 'BPCHAR': |
| 999 | 1291 | case '_VARCHAR': |
| 1000 | 1292 | case 'INET': |
| 1001 | - if ($len <= $this->blobSize) return 'C'; |
|
| 1293 | + if ($len <= $this->blobSize) |
|
| 1294 | + { |
|
| 1295 | + return 'C'; |
|
| 1296 | + } |
|
| 1002 | 1297 | |
| 1003 | 1298 | case 'TEXT': |
| 1004 | 1299 | return 'X'; |
@@ -1030,7 +1325,10 @@ discard block |
||
| 1030 | 1325 | case 'INT4': |
| 1031 | 1326 | case 'INT2': |
| 1032 | 1327 | if (isset($fieldobj) && |
| 1033 | - empty($fieldobj->primary_key) && empty($fieldobj->unique)) return 'I'; |
|
| 1328 | + empty($fieldobj->primary_key) && empty($fieldobj->unique)) |
|
| 1329 | + { |
|
| 1330 | + return 'I'; |
|
| 1331 | + } |
|
| 1034 | 1332 | |
| 1035 | 1333 | case 'OID': |
| 1036 | 1334 | case 'SERIAL': |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | return $ret; |
| 179 | 179 | } |
| 180 | 180 | // to really return the id, we need the table and column-name, else we can only return the oid != id |
| 181 | - return empty($table) || empty($column) ? $oid : $this->GetOne("SELECT $column FROM $table WHERE oid=".(int)$oid); |
|
| 181 | + return empty($table) || empty($column) ? $oid : $this->GetOne("select $column FROM $table WHERE oid=".(int)$oid); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // I get this error with PHP before 4.0.6 - jlim |
@@ -443,10 +443,10 @@ discard block |
||
| 443 | 443 | { |
| 444 | 444 | |
| 445 | 445 | if ($blobtype == 'CLOB') { |
| 446 | - return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
| 446 | + return $this->Execute("update $table SET $column=" . $this->qstr($val) . " WHERE $where"); |
|
| 447 | 447 | } |
| 448 | 448 | // do not use bind params which uses qstr(), as blobencode() already quotes data |
| 449 | - return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); |
|
| 449 | + return $this->Execute("update $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | function OffsetDate($dayFraction,$date=false) |
@@ -552,9 +552,9 @@ discard block |
||
| 552 | 552 | // Freek |
| 553 | 553 | if (is_array($keys)) { |
| 554 | 554 | foreach($keys as $key) { |
| 555 | - if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't') |
|
| 555 | + if ($fld->name == $key['column_name'] and $key['primary_key'] == 't') |
|
| 556 | 556 | $fld->primary_key = true; |
| 557 | - if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't') |
|
| 557 | + if ($fld->name == $key['column_name'] and $key['unique_key'] == 't') |
|
| 558 | 558 | $fld->unique = true; // What name is more compatible? |
| 559 | 559 | } |
| 560 | 560 | } |
@@ -731,8 +731,8 @@ discard block |
||
| 731 | 731 | } |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - if ($execp) $exsql = "EXECUTE $plan ($execp)"; |
|
| 735 | - else $exsql = "EXECUTE $plan"; |
|
| 734 | + if ($execp) $exsql = "execute $plan ($execp)"; |
|
| 735 | + else $exsql = "execute $plan"; |
|
| 736 | 736 | |
| 737 | 737 | $rez = @pg_exec($this->_connectionID,$exsql); |
| 738 | 738 | if (!$rez) { |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | $sql .= $v.' $'.$i; |
| 757 | 757 | $i++; |
| 758 | 758 | } |
| 759 | - $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2); |
|
| 759 | + $s = "prepare $plan ($params) AS ".substr($sql,0,strlen($sql)-2); |
|
| 760 | 760 | //adodb_pr($s); |
| 761 | 761 | pg_exec($this->_connectionID,$s); |
| 762 | 762 | echo $this->ErrorMsg(); |
@@ -65,11 +65,17 @@ discard block |
||
| 65 | 65 | return $this->GetOne('select @@identity'); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | + /** |
|
| 69 | + * @param string $blobVarName |
|
| 70 | + */ |
|
| 68 | 71 | function create_blobvar($blobVarName) { |
| 69 | 72 | $this->Execute("create variable $blobVarName long binary"); |
| 70 | 73 | return; |
| 71 | 74 | } |
| 72 | 75 | |
| 76 | + /** |
|
| 77 | + * @param string $blobVarName |
|
| 78 | + */ |
|
| 73 | 79 | function drop_blobvar($blobVarName) { |
| 74 | 80 | $this->Execute("drop variable $blobVarName"); |
| 75 | 81 | return; |
@@ -105,6 +111,9 @@ discard block |
||
| 105 | 111 | return; |
| 106 | 112 | } |
| 107 | 113 | |
| 114 | + /** |
|
| 115 | + * @param string $blobVarName |
|
| 116 | + */ |
|
| 108 | 117 | function load_blobvar_from_var($blobVarName, &$varName) { |
| 109 | 118 | $chunk_size = 1000; |
| 110 | 119 | |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | -if (!defined('ADODB_SYBASE_SQLANYWHERE')){ |
|
| 51 | +if (!defined('ADODB_SYBASE_SQLANYWHERE')) { |
|
| 52 | 52 | |
| 53 | - define('ADODB_SYBASE_SQLANYWHERE',1); |
|
| 53 | + define('ADODB_SYBASE_SQLANYWHERE', 1); |
|
| 54 | 54 | |
| 55 | 55 | class ADODB_sqlanywhere extends ADODB_odbc { |
| 56 | 56 | var $databaseType = "sqlanywhere"; |
@@ -78,30 +78,30 @@ discard block |
||
| 78 | 78 | function load_blobvar_from_file($blobVarName, $filename) { |
| 79 | 79 | $chunk_size = 1000; |
| 80 | 80 | |
| 81 | - $fd = fopen ($filename, "rb"); |
|
| 81 | + $fd = fopen($filename, "rb"); |
|
| 82 | 82 | |
| 83 | 83 | $integer_chunks = (integer)filesize($filename) / $chunk_size; |
| 84 | 84 | $modulus = filesize($filename) % $chunk_size; |
| 85 | - if ($modulus != 0){ |
|
| 85 | + if ($modulus != 0) { |
|
| 86 | 86 | $integer_chunks += 1; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - for($loop=1;$loop<=$integer_chunks;$loop++){ |
|
| 90 | - $contents = fread ($fd, $chunk_size); |
|
| 89 | + for ($loop = 1; $loop <= $integer_chunks; $loop++) { |
|
| 90 | + $contents = fread($fd, $chunk_size); |
|
| 91 | 91 | $contents = bin2hex($contents); |
| 92 | 92 | |
| 93 | 93 | $hexstring = ''; |
| 94 | 94 | |
| 95 | - for($loop2=0;$loop2<strlen($contents);$loop2+=2){ |
|
| 96 | - $hexstring .= '\x' . substr($contents,$loop2,2); |
|
| 95 | + for ($loop2 = 0; $loop2 < strlen($contents); $loop2 += 2) { |
|
| 96 | + $hexstring .= '\x'.substr($contents, $loop2, 2); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | $hexstring = $this->qstr($hexstring); |
| 100 | 100 | |
| 101 | - $this->Execute("set $blobVarName = $blobVarName || " . $hexstring); |
|
| 101 | + $this->Execute("set $blobVarName = $blobVarName || ".$hexstring); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - fclose ($fd); |
|
| 104 | + fclose($fd); |
|
| 105 | 105 | return; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -110,23 +110,23 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $integer_chunks = (integer)strlen($varName) / $chunk_size; |
| 112 | 112 | $modulus = strlen($varName) % $chunk_size; |
| 113 | - if ($modulus != 0){ |
|
| 113 | + if ($modulus != 0) { |
|
| 114 | 114 | $integer_chunks += 1; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - for($loop=1;$loop<=$integer_chunks;$loop++){ |
|
| 118 | - $contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size); |
|
| 117 | + for ($loop = 1; $loop <= $integer_chunks; $loop++) { |
|
| 118 | + $contents = substr($varName, (($loop - 1) * $chunk_size), $chunk_size); |
|
| 119 | 119 | $contents = bin2hex($contents); |
| 120 | 120 | |
| 121 | 121 | $hexstring = ''; |
| 122 | 122 | |
| 123 | - for($loop2=0;$loop2<strlen($contents);$loop2+=2){ |
|
| 124 | - $hexstring .= '\x' . substr($contents,$loop2,2); |
|
| 123 | + for ($loop2 = 0; $loop2 < strlen($contents); $loop2 += 2) { |
|
| 124 | + $hexstring .= '\x'.substr($contents, $loop2, 2); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $hexstring = $this->qstr($hexstring); |
| 128 | 128 | |
| 129 | - $this->Execute("set $blobVarName = $blobVarName || " . $hexstring); |
|
| 129 | + $this->Execute("set $blobVarName = $blobVarName || ".$hexstring); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); |
| 142 | 142 | $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); |
| 143 | 143 | */ |
| 144 | - function UpdateBlob($table,$column,&$val,$where,$blobtype='BLOB') |
|
| 144 | + function UpdateBlob($table, $column, &$val, $where, $blobtype = 'BLOB') |
|
| 145 | 145 | { |
| 146 | 146 | $blobVarName = 'hold_blob'; |
| 147 | 147 | $this->create_blobvar($blobVarName); |
@@ -156,9 +156,9 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | var $databaseType = "sqlanywhere"; |
| 158 | 158 | |
| 159 | - function ADORecordSet_sqlanywhere($id,$mode=false) |
|
| 159 | + function ADORecordSet_sqlanywhere($id, $mode = false) |
|
| 160 | 160 | { |
| 161 | - $this->ADORecordSet_odbc($id,$mode); |
|
| 161 | + $this->ADORecordSet_odbc($id, $mode); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -42,17 +42,23 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | |
| 44 | 44 | // security - hide paths |
| 45 | -if (!defined('ADODB_DIR')) die(); |
|
| 45 | +if (!defined('ADODB_DIR')) |
|
| 46 | +{ |
|
| 47 | + die(); |
|
| 48 | +} |
|
| 46 | 49 | |
| 47 | -if (!defined('_ADODB_ODBC_LAYER')) { |
|
| 50 | +if (!defined('_ADODB_ODBC_LAYER')) |
|
| 51 | +{ |
|
| 48 | 52 | include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); |
| 49 | 53 | } |
| 50 | 54 | |
| 51 | -if (!defined('ADODB_SYBASE_SQLANYWHERE')){ |
|
| 55 | +if (!defined('ADODB_SYBASE_SQLANYWHERE')) |
|
| 56 | +{ |
|
| 52 | 57 | |
| 53 | 58 | define('ADODB_SYBASE_SQLANYWHERE',1); |
| 54 | 59 | |
| 55 | - class ADODB_sqlanywhere extends ADODB_odbc { |
|
| 60 | + class ADODB_sqlanywhere extends ADODB_odbc |
|
| 61 | + { |
|
| 56 | 62 | var $databaseType = "sqlanywhere"; |
| 57 | 63 | var $hasInsertID = true; |
| 58 | 64 | |
@@ -61,38 +67,45 @@ discard block |
||
| 61 | 67 | $this->ADODB_odbc(); |
| 62 | 68 | } |
| 63 | 69 | |
| 64 | - function _insertid() { |
|
| 70 | + function _insertid() |
|
| 71 | + { |
|
| 65 | 72 | return $this->GetOne('select @@identity'); |
| 66 | 73 | } |
| 67 | 74 | |
| 68 | - function create_blobvar($blobVarName) { |
|
| 75 | + function create_blobvar($blobVarName) |
|
| 76 | + { |
|
| 69 | 77 | $this->Execute("create variable $blobVarName long binary"); |
| 70 | 78 | return; |
| 71 | 79 | } |
| 72 | 80 | |
| 73 | - function drop_blobvar($blobVarName) { |
|
| 81 | + function drop_blobvar($blobVarName) |
|
| 82 | + { |
|
| 74 | 83 | $this->Execute("drop variable $blobVarName"); |
| 75 | 84 | return; |
| 76 | 85 | } |
| 77 | 86 | |
| 78 | - function load_blobvar_from_file($blobVarName, $filename) { |
|
| 87 | + function load_blobvar_from_file($blobVarName, $filename) |
|
| 88 | + { |
|
| 79 | 89 | $chunk_size = 1000; |
| 80 | 90 | |
| 81 | 91 | $fd = fopen ($filename, "rb"); |
| 82 | 92 | |
| 83 | 93 | $integer_chunks = (integer)filesize($filename) / $chunk_size; |
| 84 | 94 | $modulus = filesize($filename) % $chunk_size; |
| 85 | - if ($modulus != 0){ |
|
| 95 | + if ($modulus != 0) |
|
| 96 | + { |
|
| 86 | 97 | $integer_chunks += 1; |
| 87 | 98 | } |
| 88 | 99 | |
| 89 | - for($loop=1;$loop<=$integer_chunks;$loop++){ |
|
| 100 | + for($loop=1;$loop<=$integer_chunks;$loop++) |
|
| 101 | + { |
|
| 90 | 102 | $contents = fread ($fd, $chunk_size); |
| 91 | 103 | $contents = bin2hex($contents); |
| 92 | 104 | |
| 93 | 105 | $hexstring = ''; |
| 94 | 106 | |
| 95 | - for($loop2=0;$loop2<strlen($contents);$loop2+=2){ |
|
| 107 | + for($loop2=0;$loop2<strlen($contents);$loop2+=2) |
|
| 108 | + { |
|
| 96 | 109 | $hexstring .= '\x' . substr($contents,$loop2,2); |
| 97 | 110 | } |
| 98 | 111 | |
@@ -105,22 +118,26 @@ discard block |
||
| 105 | 118 | return; |
| 106 | 119 | } |
| 107 | 120 | |
| 108 | - function load_blobvar_from_var($blobVarName, &$varName) { |
|
| 121 | + function load_blobvar_from_var($blobVarName, &$varName) |
|
| 122 | + { |
|
| 109 | 123 | $chunk_size = 1000; |
| 110 | 124 | |
| 111 | 125 | $integer_chunks = (integer)strlen($varName) / $chunk_size; |
| 112 | 126 | $modulus = strlen($varName) % $chunk_size; |
| 113 | - if ($modulus != 0){ |
|
| 127 | + if ($modulus != 0) |
|
| 128 | + { |
|
| 114 | 129 | $integer_chunks += 1; |
| 115 | 130 | } |
| 116 | 131 | |
| 117 | - for($loop=1;$loop<=$integer_chunks;$loop++){ |
|
| 132 | + for($loop=1;$loop<=$integer_chunks;$loop++) |
|
| 133 | + { |
|
| 118 | 134 | $contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size); |
| 119 | 135 | $contents = bin2hex($contents); |
| 120 | 136 | |
| 121 | 137 | $hexstring = ''; |
| 122 | 138 | |
| 123 | - for($loop2=0;$loop2<strlen($contents);$loop2+=2){ |
|
| 139 | + for($loop2=0;$loop2<strlen($contents);$loop2+=2) |
|
| 140 | + { |
|
| 124 | 141 | $hexstring .= '\x' . substr($contents,$loop2,2); |
| 125 | 142 | } |
| 126 | 143 | |
@@ -152,7 +169,8 @@ discard block |
||
| 152 | 169 | } |
| 153 | 170 | }; //class |
| 154 | 171 | |
| 155 | - class ADORecordSet_sqlanywhere extends ADORecordSet_odbc { |
|
| 172 | + class ADORecordSet_sqlanywhere extends ADORecordSet_odbc |
|
| 173 | + { |
|
| 156 | 174 | |
| 157 | 175 | var $databaseType = "sqlanywhere"; |
| 158 | 176 | |
@@ -146,7 +146,7 @@ |
||
| 146 | 146 | $blobVarName = 'hold_blob'; |
| 147 | 147 | $this->create_blobvar($blobVarName); |
| 148 | 148 | $this->load_blobvar_from_var($blobVarName, $val); |
| 149 | - $this->Execute("UPDATE $table SET $column=$blobVarName WHERE $where"); |
|
| 149 | + $this->Execute("update $table SET $column=$blobVarName WHERE $where"); |
|
| 150 | 150 | $this->drop_blobvar($blobVarName); |
| 151 | 151 | return true; |
| 152 | 152 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * the database. If that's not the case, a new connection is opened. |
| 132 | 132 | * |
| 133 | 133 | * @access private |
| 134 | - * @return mixed True or a DB error object. |
|
| 134 | + * @return boolean True or a DB error object. |
|
| 135 | 135 | */ |
| 136 | 136 | function _prepare() |
| 137 | 137 | { |
@@ -153,6 +153,7 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @access public |
| 155 | 155 | * @param string Query string |
| 156 | + * @param string $query |
|
| 156 | 157 | * @return mixed a DB_result object or DB_OK on success, a DB |
| 157 | 158 | * or PEAR error on failure |
| 158 | 159 | */ |
@@ -40,365 +40,365 @@ |
||
| 40 | 40 | class Auth_Container_ADOdb extends Auth_Container |
| 41 | 41 | { |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Additional options for the storage container |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - var $options = array(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * DB object |
|
| 51 | - * @var object |
|
| 52 | - */ |
|
| 53 | - var $db = null; |
|
| 54 | - var $dsn = ''; |
|
| 43 | + /** |
|
| 44 | + * Additional options for the storage container |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + var $options = array(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * DB object |
|
| 51 | + * @var object |
|
| 52 | + */ |
|
| 53 | + var $db = null; |
|
| 54 | + var $dsn = ''; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * User that is currently selected from the DB. |
|
| 58 | - * @var string |
|
| 59 | - */ |
|
| 60 | - var $activeUser = ''; |
|
| 61 | - |
|
| 62 | - // {{{ Constructor |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Constructor of the container class |
|
| 66 | - * |
|
| 67 | - * Initate connection to the database via PEAR::ADOdb |
|
| 68 | - * |
|
| 69 | - * @param string Connection data or DB object |
|
| 70 | - * @return object Returns an error object if something went wrong |
|
| 71 | - */ |
|
| 72 | - function Auth_Container_ADOdb($dsn) |
|
| 73 | - { |
|
| 74 | - $this->_setDefaults(); |
|
| 56 | + /** |
|
| 57 | + * User that is currently selected from the DB. |
|
| 58 | + * @var string |
|
| 59 | + */ |
|
| 60 | + var $activeUser = ''; |
|
| 61 | + |
|
| 62 | + // {{{ Constructor |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Constructor of the container class |
|
| 66 | + * |
|
| 67 | + * Initate connection to the database via PEAR::ADOdb |
|
| 68 | + * |
|
| 69 | + * @param string Connection data or DB object |
|
| 70 | + * @return object Returns an error object if something went wrong |
|
| 71 | + */ |
|
| 72 | + function Auth_Container_ADOdb($dsn) |
|
| 73 | + { |
|
| 74 | + $this->_setDefaults(); |
|
| 75 | 75 | |
| 76 | - if (is_array($dsn)) { |
|
| 77 | - $this->_parseOptions($dsn); |
|
| 78 | - |
|
| 79 | - if (empty($this->options['dsn'])) { |
|
| 80 | - PEAR::raiseError('No connection parameters specified!'); |
|
| 81 | - } |
|
| 82 | - } else { |
|
| 83 | - // Extract db_type from dsn string. |
|
| 84 | - $this->options['dsn'] = $dsn; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // }}} |
|
| 89 | - // {{{ _connect() |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Connect to database by using the given DSN string |
|
| 93 | - * |
|
| 94 | - * @access private |
|
| 95 | - * @param string DSN string |
|
| 96 | - * @return mixed Object on error, otherwise bool |
|
| 97 | - */ |
|
| 98 | - function _connect($dsn) |
|
| 99 | - { |
|
| 100 | - if (is_string($dsn) || is_array($dsn)) { |
|
| 101 | - if(!$this->db) { |
|
| 102 | - $this->db = &ADONewConnection($dsn); |
|
| 103 | - if( $err = ADODB_Pear_error() ) { |
|
| 104 | - return PEAR::raiseError($err); |
|
| 105 | - } |
|
| 106 | - } |
|
| 76 | + if (is_array($dsn)) { |
|
| 77 | + $this->_parseOptions($dsn); |
|
| 78 | + |
|
| 79 | + if (empty($this->options['dsn'])) { |
|
| 80 | + PEAR::raiseError('No connection parameters specified!'); |
|
| 81 | + } |
|
| 82 | + } else { |
|
| 83 | + // Extract db_type from dsn string. |
|
| 84 | + $this->options['dsn'] = $dsn; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // }}} |
|
| 89 | + // {{{ _connect() |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Connect to database by using the given DSN string |
|
| 93 | + * |
|
| 94 | + * @access private |
|
| 95 | + * @param string DSN string |
|
| 96 | + * @return mixed Object on error, otherwise bool |
|
| 97 | + */ |
|
| 98 | + function _connect($dsn) |
|
| 99 | + { |
|
| 100 | + if (is_string($dsn) || is_array($dsn)) { |
|
| 101 | + if(!$this->db) { |
|
| 102 | + $this->db = &ADONewConnection($dsn); |
|
| 103 | + if( $err = ADODB_Pear_error() ) { |
|
| 104 | + return PEAR::raiseError($err); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - } else { |
|
| 109 | - return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, |
|
| 110 | - 41, |
|
| 111 | - PEAR_ERROR_RETURN, |
|
| 112 | - null, |
|
| 113 | - null |
|
| 114 | - ); |
|
| 115 | - } |
|
| 108 | + } else { |
|
| 109 | + return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, |
|
| 110 | + 41, |
|
| 111 | + PEAR_ERROR_RETURN, |
|
| 112 | + null, |
|
| 113 | + null |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - if(!$this->db) { |
|
| 118 | - return PEAR::raiseError(ADODB_Pear_error()); |
|
| 119 | - } else { |
|
| 120 | - return true; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // }}} |
|
| 125 | - // {{{ _prepare() |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Prepare database connection |
|
| 129 | - * |
|
| 130 | - * This function checks if we have already opened a connection to |
|
| 131 | - * the database. If that's not the case, a new connection is opened. |
|
| 132 | - * |
|
| 133 | - * @access private |
|
| 134 | - * @return mixed True or a DB error object. |
|
| 135 | - */ |
|
| 136 | - function _prepare() |
|
| 137 | - { |
|
| 138 | - if(!$this->db) { |
|
| 139 | - $res = $this->_connect($this->options['dsn']); |
|
| 140 | - } |
|
| 141 | - return true; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // }}} |
|
| 145 | - // {{{ query() |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Prepare query to the database |
|
| 149 | - * |
|
| 150 | - * This function checks if we have already opened a connection to |
|
| 151 | - * the database. If that's not the case, a new connection is opened. |
|
| 152 | - * After that the query is passed to the database. |
|
| 153 | - * |
|
| 154 | - * @access public |
|
| 155 | - * @param string Query string |
|
| 156 | - * @return mixed a DB_result object or DB_OK on success, a DB |
|
| 157 | - * or PEAR error on failure |
|
| 158 | - */ |
|
| 159 | - function query($query) |
|
| 160 | - { |
|
| 161 | - $err = $this->_prepare(); |
|
| 162 | - if ($err !== true) { |
|
| 163 | - return $err; |
|
| 164 | - } |
|
| 165 | - return $this->db->query($query); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // }}} |
|
| 169 | - // {{{ _setDefaults() |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Set some default options |
|
| 173 | - * |
|
| 174 | - * @access private |
|
| 175 | - * @return void |
|
| 176 | - */ |
|
| 177 | - function _setDefaults() |
|
| 178 | - { |
|
| 179 | - $this->options['db_type'] = 'mysql'; |
|
| 180 | - $this->options['table'] = 'auth'; |
|
| 181 | - $this->options['usernamecol'] = 'username'; |
|
| 182 | - $this->options['passwordcol'] = 'password'; |
|
| 183 | - $this->options['dsn'] = ''; |
|
| 184 | - $this->options['db_fields'] = ''; |
|
| 185 | - $this->options['cryptType'] = 'md5'; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // }}} |
|
| 189 | - // {{{ _parseOptions() |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Parse options passed to the container class |
|
| 193 | - * |
|
| 194 | - * @access private |
|
| 195 | - * @param array |
|
| 196 | - */ |
|
| 197 | - function _parseOptions($array) |
|
| 198 | - { |
|
| 199 | - foreach ($array as $key => $value) { |
|
| 200 | - if (isset($this->options[$key])) { |
|
| 201 | - $this->options[$key] = $value; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /* Include additional fields if they exist */ |
|
| 206 | - if(!empty($this->options['db_fields'])){ |
|
| 207 | - if(is_array($this->options['db_fields'])){ |
|
| 208 | - $this->options['db_fields'] = join($this->options['db_fields'], ', '); |
|
| 209 | - } |
|
| 210 | - $this->options['db_fields'] = ', '.$this->options['db_fields']; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // }}} |
|
| 215 | - // {{{ fetchData() |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Get user information from database |
|
| 219 | - * |
|
| 220 | - * This function uses the given username to fetch |
|
| 221 | - * the corresponding login data from the database |
|
| 222 | - * table. If an account that matches the passed username |
|
| 223 | - * and password is found, the function returns true. |
|
| 224 | - * Otherwise it returns false. |
|
| 225 | - * |
|
| 226 | - * @param string Username |
|
| 227 | - * @param string Password |
|
| 228 | - * @return mixed Error object or boolean |
|
| 229 | - */ |
|
| 230 | - function fetchData($username, $password) |
|
| 231 | - { |
|
| 232 | - // Prepare for a database query |
|
| 233 | - $err = $this->_prepare(); |
|
| 234 | - if ($err !== true) { |
|
| 235 | - return PEAR::raiseError($err->getMessage(), $err->getCode()); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - // Find if db_fields contains a *, i so assume all col are selected |
|
| 239 | - if(strstr($this->options['db_fields'], '*')){ |
|
| 240 | - $sql_from = "*"; |
|
| 241 | - } |
|
| 242 | - else{ |
|
| 243 | - $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
| 244 | - } |
|
| 117 | + if(!$this->db) { |
|
| 118 | + return PEAR::raiseError(ADODB_Pear_error()); |
|
| 119 | + } else { |
|
| 120 | + return true; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // }}} |
|
| 125 | + // {{{ _prepare() |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Prepare database connection |
|
| 129 | + * |
|
| 130 | + * This function checks if we have already opened a connection to |
|
| 131 | + * the database. If that's not the case, a new connection is opened. |
|
| 132 | + * |
|
| 133 | + * @access private |
|
| 134 | + * @return mixed True or a DB error object. |
|
| 135 | + */ |
|
| 136 | + function _prepare() |
|
| 137 | + { |
|
| 138 | + if(!$this->db) { |
|
| 139 | + $res = $this->_connect($this->options['dsn']); |
|
| 140 | + } |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // }}} |
|
| 145 | + // {{{ query() |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Prepare query to the database |
|
| 149 | + * |
|
| 150 | + * This function checks if we have already opened a connection to |
|
| 151 | + * the database. If that's not the case, a new connection is opened. |
|
| 152 | + * After that the query is passed to the database. |
|
| 153 | + * |
|
| 154 | + * @access public |
|
| 155 | + * @param string Query string |
|
| 156 | + * @return mixed a DB_result object or DB_OK on success, a DB |
|
| 157 | + * or PEAR error on failure |
|
| 158 | + */ |
|
| 159 | + function query($query) |
|
| 160 | + { |
|
| 161 | + $err = $this->_prepare(); |
|
| 162 | + if ($err !== true) { |
|
| 163 | + return $err; |
|
| 164 | + } |
|
| 165 | + return $this->db->query($query); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // }}} |
|
| 169 | + // {{{ _setDefaults() |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Set some default options |
|
| 173 | + * |
|
| 174 | + * @access private |
|
| 175 | + * @return void |
|
| 176 | + */ |
|
| 177 | + function _setDefaults() |
|
| 178 | + { |
|
| 179 | + $this->options['db_type'] = 'mysql'; |
|
| 180 | + $this->options['table'] = 'auth'; |
|
| 181 | + $this->options['usernamecol'] = 'username'; |
|
| 182 | + $this->options['passwordcol'] = 'password'; |
|
| 183 | + $this->options['dsn'] = ''; |
|
| 184 | + $this->options['db_fields'] = ''; |
|
| 185 | + $this->options['cryptType'] = 'md5'; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // }}} |
|
| 189 | + // {{{ _parseOptions() |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Parse options passed to the container class |
|
| 193 | + * |
|
| 194 | + * @access private |
|
| 195 | + * @param array |
|
| 196 | + */ |
|
| 197 | + function _parseOptions($array) |
|
| 198 | + { |
|
| 199 | + foreach ($array as $key => $value) { |
|
| 200 | + if (isset($this->options[$key])) { |
|
| 201 | + $this->options[$key] = $value; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /* Include additional fields if they exist */ |
|
| 206 | + if(!empty($this->options['db_fields'])){ |
|
| 207 | + if(is_array($this->options['db_fields'])){ |
|
| 208 | + $this->options['db_fields'] = join($this->options['db_fields'], ', '); |
|
| 209 | + } |
|
| 210 | + $this->options['db_fields'] = ', '.$this->options['db_fields']; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // }}} |
|
| 215 | + // {{{ fetchData() |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Get user information from database |
|
| 219 | + * |
|
| 220 | + * This function uses the given username to fetch |
|
| 221 | + * the corresponding login data from the database |
|
| 222 | + * table. If an account that matches the passed username |
|
| 223 | + * and password is found, the function returns true. |
|
| 224 | + * Otherwise it returns false. |
|
| 225 | + * |
|
| 226 | + * @param string Username |
|
| 227 | + * @param string Password |
|
| 228 | + * @return mixed Error object or boolean |
|
| 229 | + */ |
|
| 230 | + function fetchData($username, $password) |
|
| 231 | + { |
|
| 232 | + // Prepare for a database query |
|
| 233 | + $err = $this->_prepare(); |
|
| 234 | + if ($err !== true) { |
|
| 235 | + return PEAR::raiseError($err->getMessage(), $err->getCode()); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + // Find if db_fields contains a *, i so assume all col are selected |
|
| 239 | + if(strstr($this->options['db_fields'], '*')){ |
|
| 240 | + $sql_from = "*"; |
|
| 241 | + } |
|
| 242 | + else{ |
|
| 243 | + $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - $query = "SELECT ".$sql_from. |
|
| 247 | - " FROM ".$this->options['table']. |
|
| 248 | - " WHERE ".$this->options['usernamecol']." = " . $this->db->Quote($username); |
|
| 246 | + $query = "SELECT ".$sql_from. |
|
| 247 | + " FROM ".$this->options['table']. |
|
| 248 | + " WHERE ".$this->options['usernamecol']." = " . $this->db->Quote($username); |
|
| 249 | 249 | |
| 250 | - $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|
| 251 | - $rset = $this->db->Execute( $query ); |
|
| 252 | - $res = $rset->fetchRow(); |
|
| 253 | - |
|
| 254 | - if (DB::isError($res)) { |
|
| 255 | - return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
| 256 | - } |
|
| 257 | - if (!is_array($res)) { |
|
| 258 | - $this->activeUser = ''; |
|
| 259 | - return false; |
|
| 260 | - } |
|
| 261 | - if ($this->verifyPassword(trim($password, "\r\n"), |
|
| 262 | - trim($res[$this->options['passwordcol']], "\r\n"), |
|
| 263 | - $this->options['cryptType'])) { |
|
| 264 | - // Store additional field values in the session |
|
| 265 | - foreach ($res as $key => $value) { |
|
| 266 | - if ($key == $this->options['passwordcol'] || |
|
| 267 | - $key == $this->options['usernamecol']) { |
|
| 268 | - continue; |
|
| 269 | - } |
|
| 270 | - // Use reference to the auth object if exists |
|
| 271 | - // This is because the auth session variable can change so a static call to setAuthData does not make sence |
|
| 272 | - if(is_object($this->_auth_obj)){ |
|
| 273 | - $this->_auth_obj->setAuthData($key, $value); |
|
| 274 | - } else { |
|
| 275 | - Auth::setAuthData($key, $value); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return true; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - $this->activeUser = $res[$this->options['usernamecol']]; |
|
| 283 | - return false; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // }}} |
|
| 287 | - // {{{ listUsers() |
|
| 288 | - |
|
| 289 | - function listUsers() |
|
| 290 | - { |
|
| 291 | - $err = $this->_prepare(); |
|
| 292 | - if ($err !== true) { |
|
| 293 | - return PEAR::raiseError($err->getMessage(), $err->getCode()); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - $retVal = array(); |
|
| 297 | - |
|
| 298 | - // Find if db_fileds contains a *, i so assume all col are selected |
|
| 299 | - if(strstr($this->options['db_fields'], '*')){ |
|
| 300 | - $sql_from = "*"; |
|
| 301 | - } |
|
| 302 | - else{ |
|
| 303 | - $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $query = sprintf("SELECT %s FROM %s", |
|
| 307 | - $sql_from, |
|
| 308 | - $this->options['table'] |
|
| 309 | - ); |
|
| 310 | - $res = $this->db->getAll($query, null, DB_FETCHMODE_ASSOC); |
|
| 311 | - |
|
| 312 | - if (DB::isError($res)) { |
|
| 313 | - return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
| 314 | - } else { |
|
| 315 | - foreach ($res as $user) { |
|
| 316 | - $user['username'] = $user[$this->options['usernamecol']]; |
|
| 317 | - $retVal[] = $user; |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - return $retVal; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - // }}} |
|
| 324 | - // {{{ addUser() |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Add user to the storage container |
|
| 328 | - * |
|
| 329 | - * @access public |
|
| 330 | - * @param string Username |
|
| 331 | - * @param string Password |
|
| 332 | - * @param mixed Additional information that are stored in the DB |
|
| 333 | - * |
|
| 334 | - * @return mixed True on success, otherwise error object |
|
| 335 | - */ |
|
| 336 | - function addUser($username, $password, $additional = "") |
|
| 337 | - { |
|
| 338 | - if (function_exists($this->options['cryptType'])) { |
|
| 339 | - $cryptFunction = $this->options['cryptType']; |
|
| 340 | - } else { |
|
| 341 | - $cryptFunction = 'md5'; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - $additional_key = ''; |
|
| 345 | - $additional_value = ''; |
|
| 346 | - |
|
| 347 | - if (is_array($additional)) { |
|
| 348 | - foreach ($additional as $key => $value) { |
|
| 349 | - $additional_key .= ', ' . $key; |
|
| 350 | - $additional_value .= ", '" . $value . "'"; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $query = sprintf("INSERT INTO %s (%s, %s%s) VALUES ('%s', '%s'%s)", |
|
| 355 | - $this->options['table'], |
|
| 356 | - $this->options['usernamecol'], |
|
| 357 | - $this->options['passwordcol'], |
|
| 358 | - $additional_key, |
|
| 359 | - $username, |
|
| 360 | - $cryptFunction($password), |
|
| 361 | - $additional_value |
|
| 362 | - ); |
|
| 363 | - |
|
| 364 | - $res = $this->query($query); |
|
| 365 | - |
|
| 366 | - if (DB::isError($res)) { |
|
| 367 | - return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
| 368 | - } else { |
|
| 369 | - return true; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - // }}} |
|
| 374 | - // {{{ removeUser() |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Remove user from the storage container |
|
| 378 | - * |
|
| 379 | - * @access public |
|
| 380 | - * @param string Username |
|
| 381 | - * |
|
| 382 | - * @return mixed True on success, otherwise error object |
|
| 383 | - */ |
|
| 384 | - function removeUser($username) |
|
| 385 | - { |
|
| 386 | - $query = sprintf("DELETE FROM %s WHERE %s = '%s'", |
|
| 387 | - $this->options['table'], |
|
| 388 | - $this->options['usernamecol'], |
|
| 389 | - $username |
|
| 390 | - ); |
|
| 391 | - |
|
| 392 | - $res = $this->query($query); |
|
| 393 | - |
|
| 394 | - if (DB::isError($res)) { |
|
| 395 | - return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
| 396 | - } else { |
|
| 397 | - return true; |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // }}} |
|
| 250 | + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|
| 251 | + $rset = $this->db->Execute( $query ); |
|
| 252 | + $res = $rset->fetchRow(); |
|
| 253 | + |
|
| 254 | + if (DB::isError($res)) { |
|
| 255 | + return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
| 256 | + } |
|
| 257 | + if (!is_array($res)) { |
|
| 258 | + $this->activeUser = ''; |
|
| 259 | + return false; |
|
| 260 | + } |
|
| 261 | + if ($this->verifyPassword(trim($password, "\r\n"), |
|
| 262 | + trim($res[$this->options['passwordcol']], "\r\n"), |
|
| 263 | + $this->options['cryptType'])) { |
|
| 264 | + // Store additional field values in the session |
|
| 265 | + foreach ($res as $key => $value) { |
|
| 266 | + if ($key == $this->options['passwordcol'] || |
|
| 267 | + $key == $this->options['usernamecol']) { |
|
| 268 | + continue; |
|
| 269 | + } |
|
| 270 | + // Use reference to the auth object if exists |
|
| 271 | + // This is because the auth session variable can change so a static call to setAuthData does not make sence |
|
| 272 | + if(is_object($this->_auth_obj)){ |
|
| 273 | + $this->_auth_obj->setAuthData($key, $value); |
|
| 274 | + } else { |
|
| 275 | + Auth::setAuthData($key, $value); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return true; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + $this->activeUser = $res[$this->options['usernamecol']]; |
|
| 283 | + return false; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // }}} |
|
| 287 | + // {{{ listUsers() |
|
| 288 | + |
|
| 289 | + function listUsers() |
|
| 290 | + { |
|
| 291 | + $err = $this->_prepare(); |
|
| 292 | + if ($err !== true) { |
|
| 293 | + return PEAR::raiseError($err->getMessage(), $err->getCode()); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + $retVal = array(); |
|
| 297 | + |
|
| 298 | + // Find if db_fileds contains a *, i so assume all col are selected |
|
| 299 | + if(strstr($this->options['db_fields'], '*')){ |
|
| 300 | + $sql_from = "*"; |
|
| 301 | + } |
|
| 302 | + else{ |
|
| 303 | + $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $query = sprintf("SELECT %s FROM %s", |
|
| 307 | + $sql_from, |
|
| 308 | + $this->options['table'] |
|
| 309 | + ); |
|
| 310 | + $res = $this->db->getAll($query, null, DB_FETCHMODE_ASSOC); |
|
| 311 | + |
|
| 312 | + if (DB::isError($res)) { |
|
| 313 | + return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
| 314 | + } else { |
|
| 315 | + foreach ($res as $user) { |
|
| 316 | + $user['username'] = $user[$this->options['usernamecol']]; |
|
| 317 | + $retVal[] = $user; |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + return $retVal; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + // }}} |
|
| 324 | + // {{{ addUser() |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Add user to the storage container |
|
| 328 | + * |
|
| 329 | + * @access public |
|
| 330 | + * @param string Username |
|
| 331 | + * @param string Password |
|
| 332 | + * @param mixed Additional information that are stored in the DB |
|
| 333 | + * |
|
| 334 | + * @return mixed True on success, otherwise error object |
|
| 335 | + */ |
|
| 336 | + function addUser($username, $password, $additional = "") |
|
| 337 | + { |
|
| 338 | + if (function_exists($this->options['cryptType'])) { |
|
| 339 | + $cryptFunction = $this->options['cryptType']; |
|
| 340 | + } else { |
|
| 341 | + $cryptFunction = 'md5'; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + $additional_key = ''; |
|
| 345 | + $additional_value = ''; |
|
| 346 | + |
|
| 347 | + if (is_array($additional)) { |
|
| 348 | + foreach ($additional as $key => $value) { |
|
| 349 | + $additional_key .= ', ' . $key; |
|
| 350 | + $additional_value .= ", '" . $value . "'"; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $query = sprintf("INSERT INTO %s (%s, %s%s) VALUES ('%s', '%s'%s)", |
|
| 355 | + $this->options['table'], |
|
| 356 | + $this->options['usernamecol'], |
|
| 357 | + $this->options['passwordcol'], |
|
| 358 | + $additional_key, |
|
| 359 | + $username, |
|
| 360 | + $cryptFunction($password), |
|
| 361 | + $additional_value |
|
| 362 | + ); |
|
| 363 | + |
|
| 364 | + $res = $this->query($query); |
|
| 365 | + |
|
| 366 | + if (DB::isError($res)) { |
|
| 367 | + return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
| 368 | + } else { |
|
| 369 | + return true; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + // }}} |
|
| 374 | + // {{{ removeUser() |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Remove user from the storage container |
|
| 378 | + * |
|
| 379 | + * @access public |
|
| 380 | + * @param string Username |
|
| 381 | + * |
|
| 382 | + * @return mixed True on success, otherwise error object |
|
| 383 | + */ |
|
| 384 | + function removeUser($username) |
|
| 385 | + { |
|
| 386 | + $query = sprintf("DELETE FROM %s WHERE %s = '%s'", |
|
| 387 | + $this->options['table'], |
|
| 388 | + $this->options['usernamecol'], |
|
| 389 | + $username |
|
| 390 | + ); |
|
| 391 | + |
|
| 392 | + $res = $this->query($query); |
|
| 393 | + |
|
| 394 | + if (DB::isError($res)) { |
|
| 395 | + return PEAR::raiseError($res->getMessage(), $res->getCode()); |
|
| 396 | + } else { |
|
| 397 | + return true; |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // }}} |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | function showDbg( $string ) { |
@@ -98,15 +98,15 @@ discard block |
||
| 98 | 98 | function _connect($dsn) |
| 99 | 99 | { |
| 100 | 100 | if (is_string($dsn) || is_array($dsn)) { |
| 101 | - if(!$this->db) { |
|
| 101 | + if (!$this->db) { |
|
| 102 | 102 | $this->db = &ADONewConnection($dsn); |
| 103 | - if( $err = ADODB_Pear_error() ) { |
|
| 103 | + if ($err = ADODB_Pear_error()) { |
|
| 104 | 104 | return PEAR::raiseError($err); |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | } else { |
| 109 | - return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, |
|
| 109 | + return PEAR::raiseError('The given dsn was not valid in file '.__FILE__.' at line '.__LINE__, |
|
| 110 | 110 | 41, |
| 111 | 111 | PEAR_ERROR_RETURN, |
| 112 | 112 | null, |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | ); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if(!$this->db) { |
|
| 117 | + if (!$this->db) { |
|
| 118 | 118 | return PEAR::raiseError(ADODB_Pear_error()); |
| 119 | 119 | } else { |
| 120 | 120 | return true; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | function _prepare() |
| 137 | 137 | { |
| 138 | - if(!$this->db) { |
|
| 138 | + if (!$this->db) { |
|
| 139 | 139 | $res = $this->_connect($this->options['dsn']); |
| 140 | 140 | } |
| 141 | 141 | return true; |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | function _setDefaults() |
| 178 | 178 | { |
| 179 | - $this->options['db_type'] = 'mysql'; |
|
| 179 | + $this->options['db_type'] = 'mysql'; |
|
| 180 | 180 | $this->options['table'] = 'auth'; |
| 181 | 181 | $this->options['usernamecol'] = 'username'; |
| 182 | 182 | $this->options['passwordcol'] = 'password'; |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /* Include additional fields if they exist */ |
| 206 | - if(!empty($this->options['db_fields'])){ |
|
| 207 | - if(is_array($this->options['db_fields'])){ |
|
| 206 | + if (!empty($this->options['db_fields'])) { |
|
| 207 | + if (is_array($this->options['db_fields'])) { |
|
| 208 | 208 | $this->options['db_fields'] = join($this->options['db_fields'], ', '); |
| 209 | 209 | } |
| 210 | 210 | $this->options['db_fields'] = ', '.$this->options['db_fields']; |
@@ -236,19 +236,19 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // Find if db_fields contains a *, i so assume all col are selected |
| 239 | - if(strstr($this->options['db_fields'], '*')){ |
|
| 239 | + if (strstr($this->options['db_fields'], '*')) { |
|
| 240 | 240 | $sql_from = "*"; |
| 241 | 241 | } |
| 242 | - else{ |
|
| 243 | - $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
| 242 | + else { |
|
| 243 | + $sql_from = $this->options['usernamecol'].", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | $query = "SELECT ".$sql_from. |
| 247 | 247 | " FROM ".$this->options['table']. |
| 248 | - " WHERE ".$this->options['usernamecol']." = " . $this->db->Quote($username); |
|
| 248 | + " WHERE ".$this->options['usernamecol']." = ".$this->db->Quote($username); |
|
| 249 | 249 | |
| 250 | 250 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
| 251 | - $rset = $this->db->Execute( $query ); |
|
| 251 | + $rset = $this->db->Execute($query); |
|
| 252 | 252 | $res = $rset->fetchRow(); |
| 253 | 253 | |
| 254 | 254 | if (DB::isError($res)) { |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | // Use reference to the auth object if exists |
| 271 | 271 | // This is because the auth session variable can change so a static call to setAuthData does not make sence |
| 272 | - if(is_object($this->_auth_obj)){ |
|
| 272 | + if (is_object($this->_auth_obj)) { |
|
| 273 | 273 | $this->_auth_obj->setAuthData($key, $value); |
| 274 | 274 | } else { |
| 275 | 275 | Auth::setAuthData($key, $value); |
@@ -296,11 +296,11 @@ discard block |
||
| 296 | 296 | $retVal = array(); |
| 297 | 297 | |
| 298 | 298 | // Find if db_fileds contains a *, i so assume all col are selected |
| 299 | - if(strstr($this->options['db_fields'], '*')){ |
|
| 299 | + if (strstr($this->options['db_fields'], '*')) { |
|
| 300 | 300 | $sql_from = "*"; |
| 301 | 301 | } |
| 302 | - else{ |
|
| 303 | - $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
| 302 | + else { |
|
| 303 | + $sql_from = $this->options['usernamecol'].", ".$this->options['passwordcol'].$this->options['db_fields']; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | $query = sprintf("SELECT %s FROM %s", |
@@ -346,8 +346,8 @@ discard block |
||
| 346 | 346 | |
| 347 | 347 | if (is_array($additional)) { |
| 348 | 348 | foreach ($additional as $key => $value) { |
| 349 | - $additional_key .= ', ' . $key; |
|
| 350 | - $additional_value .= ", '" . $value . "'"; |
|
| 349 | + $additional_key .= ', '.$key; |
|
| 350 | + $additional_value .= ", '".$value."'"; |
|
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
@@ -401,13 +401,13 @@ discard block |
||
| 401 | 401 | // }}} |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | -function showDbg( $string ) { |
|
| 404 | +function showDbg($string) { |
|
| 405 | 405 | print " |
| 406 | 406 | -- $string</P>"; |
| 407 | 407 | } |
| 408 | -function dump( $var, $str, $vardump = false ) { |
|
| 408 | +function dump($var, $str, $vardump = false) { |
|
| 409 | 409 | print "<H4>$str</H4><pre>"; |
| 410 | - ( !$vardump ) ? ( print_r( $var )) : ( var_dump( $var )); |
|
| 410 | + (!$vardump) ? (print_r($var)) : (var_dump($var)); |
|
| 411 | 411 | print "</pre>"; |
| 412 | 412 | } |
| 413 | 413 | ?> |
@@ -73,13 +73,17 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $this->_setDefaults(); |
| 75 | 75 | |
| 76 | - if (is_array($dsn)) { |
|
| 76 | + if (is_array($dsn)) |
|
| 77 | + { |
|
| 77 | 78 | $this->_parseOptions($dsn); |
| 78 | 79 | |
| 79 | - if (empty($this->options['dsn'])) { |
|
| 80 | + if (empty($this->options['dsn'])) |
|
| 81 | + { |
|
| 80 | 82 | PEAR::raiseError('No connection parameters specified!'); |
| 81 | 83 | } |
| 82 | - } else { |
|
| 84 | + } |
|
| 85 | + else |
|
| 86 | + { |
|
| 83 | 87 | // Extract db_type from dsn string. |
| 84 | 88 | $this->options['dsn'] = $dsn; |
| 85 | 89 | } |
@@ -96,16 +100,21 @@ discard block |
||
| 96 | 100 | * @return mixed Object on error, otherwise bool |
| 97 | 101 | */ |
| 98 | 102 | function _connect($dsn) |
| 99 | - { |
|
| 100 | - if (is_string($dsn) || is_array($dsn)) { |
|
| 101 | - if(!$this->db) { |
|
| 103 | + { |
|
| 104 | + if (is_string($dsn) || is_array($dsn)) |
|
| 105 | + { |
|
| 106 | + if(!$this->db) |
|
| 107 | + { |
|
| 102 | 108 | $this->db = &ADONewConnection($dsn); |
| 103 | - if( $err = ADODB_Pear_error() ) { |
|
| 109 | + if( $err = ADODB_Pear_error() ) |
|
| 110 | + { |
|
| 104 | 111 | return PEAR::raiseError($err); |
| 105 | 112 | } |
| 106 | 113 | } |
| 107 | 114 | |
| 108 | - } else { |
|
| 115 | + } |
|
| 116 | + else |
|
| 117 | + { |
|
| 109 | 118 | return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, |
| 110 | 119 | 41, |
| 111 | 120 | PEAR_ERROR_RETURN, |
@@ -114,9 +123,12 @@ discard block |
||
| 114 | 123 | ); |
| 115 | 124 | } |
| 116 | 125 | |
| 117 | - if(!$this->db) { |
|
| 126 | + if(!$this->db) |
|
| 127 | + { |
|
| 118 | 128 | return PEAR::raiseError(ADODB_Pear_error()); |
| 119 | - } else { |
|
| 129 | + } |
|
| 130 | + else |
|
| 131 | + { |
|
| 120 | 132 | return true; |
| 121 | 133 | } |
| 122 | 134 | } |
@@ -135,7 +147,8 @@ discard block |
||
| 135 | 147 | */ |
| 136 | 148 | function _prepare() |
| 137 | 149 | { |
| 138 | - if(!$this->db) { |
|
| 150 | + if(!$this->db) |
|
| 151 | + { |
|
| 139 | 152 | $res = $this->_connect($this->options['dsn']); |
| 140 | 153 | } |
| 141 | 154 | return true; |
@@ -159,7 +172,8 @@ discard block |
||
| 159 | 172 | function query($query) |
| 160 | 173 | { |
| 161 | 174 | $err = $this->_prepare(); |
| 162 | - if ($err !== true) { |
|
| 175 | + if ($err !== true) |
|
| 176 | + { |
|
| 163 | 177 | return $err; |
| 164 | 178 | } |
| 165 | 179 | return $this->db->query($query); |
@@ -196,15 +210,19 @@ discard block |
||
| 196 | 210 | */ |
| 197 | 211 | function _parseOptions($array) |
| 198 | 212 | { |
| 199 | - foreach ($array as $key => $value) { |
|
| 200 | - if (isset($this->options[$key])) { |
|
| 213 | + foreach ($array as $key => $value) |
|
| 214 | + { |
|
| 215 | + if (isset($this->options[$key])) |
|
| 216 | + { |
|
| 201 | 217 | $this->options[$key] = $value; |
| 202 | 218 | } |
| 203 | 219 | } |
| 204 | 220 | |
| 205 | 221 | /* Include additional fields if they exist */ |
| 206 | - if(!empty($this->options['db_fields'])){ |
|
| 207 | - if(is_array($this->options['db_fields'])){ |
|
| 222 | + if(!empty($this->options['db_fields'])) |
|
| 223 | + { |
|
| 224 | + if(is_array($this->options['db_fields'])) |
|
| 225 | + { |
|
| 208 | 226 | $this->options['db_fields'] = join($this->options['db_fields'], ', '); |
| 209 | 227 | } |
| 210 | 228 | $this->options['db_fields'] = ', '.$this->options['db_fields']; |
@@ -231,15 +249,18 @@ discard block |
||
| 231 | 249 | { |
| 232 | 250 | // Prepare for a database query |
| 233 | 251 | $err = $this->_prepare(); |
| 234 | - if ($err !== true) { |
|
| 252 | + if ($err !== true) |
|
| 253 | + { |
|
| 235 | 254 | return PEAR::raiseError($err->getMessage(), $err->getCode()); |
| 236 | 255 | } |
| 237 | 256 | |
| 238 | 257 | // Find if db_fields contains a *, i so assume all col are selected |
| 239 | - if(strstr($this->options['db_fields'], '*')){ |
|
| 258 | + if(strstr($this->options['db_fields'], '*')) |
|
| 259 | + { |
|
| 240 | 260 | $sql_from = "*"; |
| 241 | 261 | } |
| 242 | - else{ |
|
| 262 | + else |
|
| 263 | + { |
|
| 243 | 264 | $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
| 244 | 265 | } |
| 245 | 266 | |
@@ -251,27 +272,35 @@ discard block |
||
| 251 | 272 | $rset = $this->db->Execute( $query ); |
| 252 | 273 | $res = $rset->fetchRow(); |
| 253 | 274 | |
| 254 | - if (DB::isError($res)) { |
|
| 275 | + if (DB::isError($res)) |
|
| 276 | + { |
|
| 255 | 277 | return PEAR::raiseError($res->getMessage(), $res->getCode()); |
| 256 | 278 | } |
| 257 | - if (!is_array($res)) { |
|
| 279 | + if (!is_array($res)) |
|
| 280 | + { |
|
| 258 | 281 | $this->activeUser = ''; |
| 259 | 282 | return false; |
| 260 | 283 | } |
| 261 | 284 | if ($this->verifyPassword(trim($password, "\r\n"), |
| 262 | 285 | trim($res[$this->options['passwordcol']], "\r\n"), |
| 263 | - $this->options['cryptType'])) { |
|
| 286 | + $this->options['cryptType'])) |
|
| 287 | + { |
|
| 264 | 288 | // Store additional field values in the session |
| 265 | - foreach ($res as $key => $value) { |
|
| 289 | + foreach ($res as $key => $value) |
|
| 290 | + { |
|
| 266 | 291 | if ($key == $this->options['passwordcol'] || |
| 267 | - $key == $this->options['usernamecol']) { |
|
| 292 | + $key == $this->options['usernamecol']) |
|
| 293 | + { |
|
| 268 | 294 | continue; |
| 269 | 295 | } |
| 270 | 296 | // Use reference to the auth object if exists |
| 271 | 297 | // This is because the auth session variable can change so a static call to setAuthData does not make sence |
| 272 | - if(is_object($this->_auth_obj)){ |
|
| 298 | + if(is_object($this->_auth_obj)) |
|
| 299 | + { |
|
| 273 | 300 | $this->_auth_obj->setAuthData($key, $value); |
| 274 | - } else { |
|
| 301 | + } |
|
| 302 | + else |
|
| 303 | + { |
|
| 275 | 304 | Auth::setAuthData($key, $value); |
| 276 | 305 | } |
| 277 | 306 | } |
@@ -289,17 +318,20 @@ discard block |
||
| 289 | 318 | function listUsers() |
| 290 | 319 | { |
| 291 | 320 | $err = $this->_prepare(); |
| 292 | - if ($err !== true) { |
|
| 321 | + if ($err !== true) |
|
| 322 | + { |
|
| 293 | 323 | return PEAR::raiseError($err->getMessage(), $err->getCode()); |
| 294 | 324 | } |
| 295 | 325 | |
| 296 | 326 | $retVal = array(); |
| 297 | 327 | |
| 298 | 328 | // Find if db_fileds contains a *, i so assume all col are selected |
| 299 | - if(strstr($this->options['db_fields'], '*')){ |
|
| 329 | + if(strstr($this->options['db_fields'], '*')) |
|
| 330 | + { |
|
| 300 | 331 | $sql_from = "*"; |
| 301 | 332 | } |
| 302 | - else{ |
|
| 333 | + else |
|
| 334 | + { |
|
| 303 | 335 | $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].$this->options['db_fields']; |
| 304 | 336 | } |
| 305 | 337 | |
@@ -309,10 +341,14 @@ discard block |
||
| 309 | 341 | ); |
| 310 | 342 | $res = $this->db->getAll($query, null, DB_FETCHMODE_ASSOC); |
| 311 | 343 | |
| 312 | - if (DB::isError($res)) { |
|
| 344 | + if (DB::isError($res)) |
|
| 345 | + { |
|
| 313 | 346 | return PEAR::raiseError($res->getMessage(), $res->getCode()); |
| 314 | - } else { |
|
| 315 | - foreach ($res as $user) { |
|
| 347 | + } |
|
| 348 | + else |
|
| 349 | + { |
|
| 350 | + foreach ($res as $user) |
|
| 351 | + { |
|
| 316 | 352 | $user['username'] = $user[$this->options['usernamecol']]; |
| 317 | 353 | $retVal[] = $user; |
| 318 | 354 | } |
@@ -335,17 +371,22 @@ discard block |
||
| 335 | 371 | */ |
| 336 | 372 | function addUser($username, $password, $additional = "") |
| 337 | 373 | { |
| 338 | - if (function_exists($this->options['cryptType'])) { |
|
| 374 | + if (function_exists($this->options['cryptType'])) |
|
| 375 | + { |
|
| 339 | 376 | $cryptFunction = $this->options['cryptType']; |
| 340 | - } else { |
|
| 377 | + } |
|
| 378 | + else |
|
| 379 | + { |
|
| 341 | 380 | $cryptFunction = 'md5'; |
| 342 | 381 | } |
| 343 | 382 | |
| 344 | 383 | $additional_key = ''; |
| 345 | 384 | $additional_value = ''; |
| 346 | 385 | |
| 347 | - if (is_array($additional)) { |
|
| 348 | - foreach ($additional as $key => $value) { |
|
| 386 | + if (is_array($additional)) |
|
| 387 | + { |
|
| 388 | + foreach ($additional as $key => $value) |
|
| 389 | + { |
|
| 349 | 390 | $additional_key .= ', ' . $key; |
| 350 | 391 | $additional_value .= ", '" . $value . "'"; |
| 351 | 392 | } |
@@ -363,9 +404,12 @@ discard block |
||
| 363 | 404 | |
| 364 | 405 | $res = $this->query($query); |
| 365 | 406 | |
| 366 | - if (DB::isError($res)) { |
|
| 407 | + if (DB::isError($res)) |
|
| 408 | + { |
|
| 367 | 409 | return PEAR::raiseError($res->getMessage(), $res->getCode()); |
| 368 | - } else { |
|
| 410 | + } |
|
| 411 | + else |
|
| 412 | + { |
|
| 369 | 413 | return true; |
| 370 | 414 | } |
| 371 | 415 | } |
@@ -391,9 +435,12 @@ discard block |
||
| 391 | 435 | |
| 392 | 436 | $res = $this->query($query); |
| 393 | 437 | |
| 394 | - if (DB::isError($res)) { |
|
| 438 | + if (DB::isError($res)) |
|
| 439 | + { |
|
| 395 | 440 | return PEAR::raiseError($res->getMessage(), $res->getCode()); |
| 396 | - } else { |
|
| 441 | + } |
|
| 442 | + else |
|
| 443 | + { |
|
| 397 | 444 | return true; |
| 398 | 445 | } |
| 399 | 446 | } |
@@ -401,11 +448,13 @@ discard block |
||
| 401 | 448 | // }}} |
| 402 | 449 | } |
| 403 | 450 | |
| 404 | -function showDbg( $string ) { |
|
| 451 | +function showDbg( $string ) |
|
| 452 | +{ |
|
| 405 | 453 | print " |
| 406 | 454 | -- $string</P>"; |
| 407 | 455 | } |
| 408 | -function dump( $var, $str, $vardump = false ) { |
|
| 456 | +function dump( $var, $str, $vardump = false ) |
|
| 457 | +{ |
|
| 409 | 458 | print "<H4>$str</H4><pre>"; |
| 410 | 459 | ( !$vardump ) ? ( print_r( $var )) : ( var_dump( $var )); |
| 411 | 460 | print "</pre>"; |
@@ -320,6 +320,10 @@ |
||
| 320 | 320 | /* |
| 321 | 321 | Generate html for suspicious/expensive sql |
| 322 | 322 | */ |
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @param string $type |
|
| 326 | + */ |
|
| 323 | 327 | function tohtml(&$rs,$type) |
| 324 | 328 | { |
| 325 | 329 | $o1 = $rs->FetchField(0); |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | // security - hide paths |
| 16 | 16 | if (!defined('ADODB_DIR')) die(); |
| 17 | 17 | |
| 18 | -class perf_oci8 extends ADODB_perf{ |
|
| 18 | +class perf_oci8 extends ADODB_perf { |
|
| 19 | 19 | |
| 20 | 20 | var $tablesSQL = "select segment_name as \"tablename\", sum(bytes)/1024 as \"size_in_k\",tablespace_name as \"tablespace\",count(*) \"extents\" from sys.user_extents |
| 21 | 21 | group by segment_name,tablespace_name"; |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | phy.name = 'physical reads'", |
| 41 | 41 | '=WarnCacheRatio'), |
| 42 | 42 | |
| 43 | - 'sql cache hit ratio' => array( 'RATIOH', |
|
| 43 | + 'sql cache hit ratio' => array('RATIOH', |
|
| 44 | 44 | 'select round(100*(sum(pins)-sum(reloads))/sum(pins),2) from v$librarycache', |
| 45 | 45 | 'increase <i>shared_pool_size</i> if too ratio low'), |
| 46 | 46 | |
@@ -68,37 +68,37 @@ discard block |
||
| 68 | 68 | "select value from v\$sysstat where name='physical writes'"), |
| 69 | 69 | |
| 70 | 70 | 'Data Cache', |
| 71 | - 'data cache buffers' => array( 'DATAC', |
|
| 71 | + 'data cache buffers' => array('DATAC', |
|
| 72 | 72 | "select a.value/b.value from v\$parameter a, v\$parameter b |
| 73 | 73 | where a.name = 'db_cache_size' and b.name= 'db_block_size'", |
| 74 | 74 | 'Number of cache buffers. Tune <i>db_cache_size</i> if the <i>data cache hit ratio</i> is too low.'), |
| 75 | 75 | 'data cache blocksize' => array('DATAC', |
| 76 | 76 | "select value from v\$parameter where name='db_block_size'", |
| 77 | - '' ), |
|
| 77 | + ''), |
|
| 78 | 78 | 'Memory Pools', |
| 79 | 79 | 'data cache size' => array('DATAC', |
| 80 | 80 | "select value from v\$parameter where name = 'db_cache_size'", |
| 81 | - 'db_cache_size' ), |
|
| 81 | + 'db_cache_size'), |
|
| 82 | 82 | 'shared pool size' => array('DATAC', |
| 83 | 83 | "select value from v\$parameter where name = 'shared_pool_size'", |
| 84 | - 'shared_pool_size, which holds shared sql, stored procedures, dict cache and similar shared structs' ), |
|
| 84 | + 'shared_pool_size, which holds shared sql, stored procedures, dict cache and similar shared structs'), |
|
| 85 | 85 | 'java pool size' => array('DATAJ', |
| 86 | 86 | "select value from v\$parameter where name = 'java_pool_size'", |
| 87 | - 'java_pool_size' ), |
|
| 87 | + 'java_pool_size'), |
|
| 88 | 88 | 'large pool buffer size' => array('CACHE', |
| 89 | 89 | "select value from v\$parameter where name='large_pool_size'", |
| 90 | - 'this pool is for large mem allocations (not because it is larger than shared pool), for MTS sessions, parallel queries, io buffers (large_pool_size) ' ), |
|
| 90 | + 'this pool is for large mem allocations (not because it is larger than shared pool), for MTS sessions, parallel queries, io buffers (large_pool_size) '), |
|
| 91 | 91 | |
| 92 | 92 | 'pga buffer size' => array('CACHE', |
| 93 | 93 | "select value from v\$parameter where name='pga_aggregate_target'", |
| 94 | - 'program global area is private memory for sorting, and hash and bitmap merges - since oracle 9i (pga_aggregate_target)' ), |
|
| 94 | + 'program global area is private memory for sorting, and hash and bitmap merges - since oracle 9i (pga_aggregate_target)'), |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | 'Connections', |
| 98 | 98 | 'current connections' => array('SESS', |
| 99 | 99 | 'select count(*) from sys.v_$session where username is not null', |
| 100 | 100 | ''), |
| 101 | - 'max connections' => array( 'SESS', |
|
| 101 | + 'max connections' => array('SESS', |
|
| 102 | 102 | "select value from v\$parameter where name='sessions'", |
| 103 | 103 | ''), |
| 104 | 104 | |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | 'Percentage of large_pool actually in use - too low is bad, too high is worse'), |
| 124 | 124 | 'sort buffer size' => array('CACHE', |
| 125 | 125 | "select value from v\$parameter where name='sort_area_size'", |
| 126 | - 'max in-mem sort_area_size (per query), uses memory in pga' ), |
|
| 126 | + 'max in-mem sort_area_size (per query), uses memory in pga'), |
|
| 127 | 127 | |
| 128 | 128 | 'pga usage at peak' => array('RATIOU', |
| 129 | - '=PGA','Mb utilization at peak transactions (requires Oracle 9i+)'), |
|
| 129 | + '=PGA', 'Mb utilization at peak transactions (requires Oracle 9i+)'), |
|
| 130 | 130 | 'Transactions', |
| 131 | 131 | 'rollback segments' => array('ROLLBACK', |
| 132 | 132 | "select count(*) from sys.v_\$rollstat", |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $savelog = $conn->LogSQL(false); |
| 168 | 168 | $this->version = $conn->ServerInfo(); |
| 169 | 169 | $conn->LogSQL($savelog); |
| 170 | - $this->conn =& $conn; |
|
| 170 | + $this->conn = & $conn; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | function WarnPageCost($val) |
@@ -208,10 +208,10 @@ discard block |
||
| 208 | 208 | return reset($rs->fields); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - function Explain($sql,$partial=false) |
|
| 211 | + function Explain($sql, $partial = false) |
|
| 212 | 212 | { |
| 213 | 213 | $savelog = $this->conn->LogSQL(false); |
| 214 | - $rs =& $this->conn->SelectLimit("select ID FROM PLAN_TABLE"); |
|
| 214 | + $rs = & $this->conn->SelectLimit("select ID FROM PLAN_TABLE"); |
|
| 215 | 215 | if (!$rs) { |
| 216 | 216 | echo "<p><b>Missing PLAN_TABLE</b></p> |
| 217 | 217 | <pre> |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $sqlq = $this->conn->qstr($sql.'%'); |
| 253 | 253 | $arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like $sqlq"); |
| 254 | 254 | if ($arr) { |
| 255 | - foreach($arr as $row) { |
|
| 255 | + foreach ($arr as $row) { |
|
| 256 | 256 | $sql = reset($row); |
| 257 | 257 | if (crc32($sql) == $partial) break; |
| 258 | 258 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | $this->conn->BeginTrans(); |
| 265 | 265 | $id = "ADODB ".microtime(); |
| 266 | 266 | |
| 267 | - $rs =& $this->conn->Execute("EXPLAIN PLAN SET STATEMENT_ID='$id' FOR $sql"); |
|
| 267 | + $rs = & $this->conn->Execute("EXPLAIN PLAN SET STATEMENT_ID='$id' FOR $sql"); |
|
| 268 | 268 | $m = $this->conn->ErrorMsg(); |
| 269 | 269 | if ($m) { |
| 270 | 270 | $this->conn->RollbackTrans(); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | $s .= "<p>$m</p>"; |
| 273 | 273 | return $s; |
| 274 | 274 | } |
| 275 | - $rs =& $this->conn->Execute(" |
|
| 275 | + $rs = & $this->conn->Execute(" |
|
| 276 | 276 | select |
| 277 | 277 | '<pre>'||lpad('--', (level-1)*2,'-') || trim(operation) || ' ' || trim(options)||'</pre>' as Operation, |
| 278 | 278 | object_name,COST,CARDINALITY,bytes |
@@ -280,10 +280,10 @@ discard block |
||
| 280 | 280 | START WITH id = 0 and STATEMENT_ID='$id' |
| 281 | 281 | CONNECT BY prior id=parent_id and statement_id='$id'"); |
| 282 | 282 | |
| 283 | - $s .= rs2html($rs,false,false,false,false); |
|
| 283 | + $s .= rs2html($rs, false, false, false, false); |
|
| 284 | 284 | $this->conn->RollbackTrans(); |
| 285 | 285 | $this->conn->LogSQL($savelog); |
| 286 | - $s .= $this->Tracer($sql,$partial); |
|
| 286 | + $s .= $this->Tracer($sql, $partial); |
|
| 287 | 287 | return $s; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | { |
| 293 | 293 | if ($this->version['version'] < 9) return 'Oracle 9i or later required'; |
| 294 | 294 | |
| 295 | - $rs =& $this->conn->Execute(" |
|
| 295 | + $rs = & $this->conn->Execute(" |
|
| 296 | 296 | select a.size_for_estimate as cache_mb_estimate, |
| 297 | 297 | case when a.size_factor=1 then |
| 298 | 298 | '<<= current' |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | $s .= "<p>Cache that is 50% of current size is still too big</p>"; |
| 313 | 313 | } else { |
| 314 | 314 | $s .= "Ideal size of Data Cache is when \"best_when_0\" changes from a positive number and becomes zero."; |
| 315 | - $s .= rs2html($rs,false,false,false,false); |
|
| 315 | + $s .= rs2html($rs, false, false, false, false); |
|
| 316 | 316 | } |
| 317 | 317 | return $s; |
| 318 | 318 | } |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | /* |
| 321 | 321 | Generate html for suspicious/expensive sql |
| 322 | 322 | */ |
| 323 | - function tohtml(&$rs,$type) |
|
| 323 | + function tohtml(&$rs, $type) |
|
| 324 | 324 | { |
| 325 | 325 | $o1 = $rs->FetchField(0); |
| 326 | 326 | $o2 = $rs->FetchField(1); |
@@ -332,33 +332,33 @@ discard block |
||
| 332 | 332 | while (!$rs->EOF) { |
| 333 | 333 | if ($check != $rs->fields[0].'::'.$rs->fields[1]) { |
| 334 | 334 | if ($check) { |
| 335 | - $carr = explode('::',$check); |
|
| 335 | + $carr = explode('::', $check); |
|
| 336 | 336 | $prefix = "<a href=\"?$type=1&sql=".rawurlencode($sql).'&x#explain">'; |
| 337 | 337 | $suffix = '</a>'; |
| 338 | - if (strlen($prefix)>2000) { |
|
| 338 | + if (strlen($prefix) > 2000) { |
|
| 339 | 339 | $prefix = ''; |
| 340 | 340 | $suffix = ''; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - $s .= "\n<tr><td align=right>".$carr[0].'</td><td align=right>'.$carr[1].'</td><td>'.$prefix.$sql.$suffix.'</td></tr>'; |
|
| 343 | + $s .= "\n<tr><td align=right>".$carr[0].'</td><td align=right>'.$carr[1].'</td><td>'.$prefix.$sql.$suffix.'</td></tr>'; |
|
| 344 | 344 | } |
| 345 | 345 | $sql = $rs->fields[2]; |
| 346 | 346 | $check = $rs->fields[0].'::'.$rs->fields[1]; |
| 347 | 347 | } else |
| 348 | 348 | $sql .= $rs->fields[2]; |
| 349 | - if (substr($sql,strlen($sql)-1) == "\0") $sql = substr($sql,0,strlen($sql)-1); |
|
| 349 | + if (substr($sql, strlen($sql) - 1) == "\0") $sql = substr($sql, 0, strlen($sql) - 1); |
|
| 350 | 350 | $rs->MoveNext(); |
| 351 | 351 | } |
| 352 | 352 | $rs->Close(); |
| 353 | 353 | |
| 354 | - $carr = explode('::',$check); |
|
| 354 | + $carr = explode('::', $check); |
|
| 355 | 355 | $prefix = "<a target=".rand()." href=\"?&hidem=1&$type=1&sql=".rawurlencode($sql).'&x#explain">'; |
| 356 | 356 | $suffix = '</a>'; |
| 357 | - if (strlen($prefix)>2000) { |
|
| 357 | + if (strlen($prefix) > 2000) { |
|
| 358 | 358 | $prefix = ''; |
| 359 | 359 | $suffix = ''; |
| 360 | 360 | } |
| 361 | - $s .= "\n<tr><td align=right>".$carr[0].'</td><td align=right>'.$carr[1].'</td><td>'.$prefix.$sql.$suffix.'</td></tr>'; |
|
| 361 | + $s .= "\n<tr><td align=right>".$carr[0].'</td><td align=right>'.$carr[1].'</td><td>'.$prefix.$sql.$suffix.'</td></tr>'; |
|
| 362 | 362 | |
| 363 | 363 | return $s."</table>\n\n"; |
| 364 | 364 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | // code thanks to Ixora. |
| 367 | 367 | // http://www.ixora.com.au/scripts/query_opt.htm |
| 368 | 368 | // requires oracle 8.1.7 or later |
| 369 | - function SuspiciousSQL($numsql=10) |
|
| 369 | + function SuspiciousSQL($numsql = 10) |
|
| 370 | 370 | { |
| 371 | 371 | $sql = " |
| 372 | 372 | select |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | global $ADODB_CACHE_MODE; |
| 407 | 407 | if (isset($_GET['expsixora']) && isset($_GET['sql'])) { |
| 408 | 408 | $partial = empty($_GET['part']); |
| 409 | - echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
|
| 409 | + echo "<a name=explain></a>".$this->Explain($_GET['sql'], $partial)."\n"; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | if (isset($_GET['sql'])) return $this->_SuspiciousSQL($numsql); |
@@ -420,14 +420,14 @@ discard block |
||
| 420 | 420 | if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
| 421 | 421 | |
| 422 | 422 | $savelog = $this->conn->LogSQL(false); |
| 423 | - $rs =& $this->conn->SelectLimit($sql); |
|
| 423 | + $rs = & $this->conn->SelectLimit($sql); |
|
| 424 | 424 | $this->conn->LogSQL($savelog); |
| 425 | 425 | |
| 426 | 426 | if (isset($savem)) $this->conn->SetFetchMode($savem); |
| 427 | 427 | $ADODB_CACHE_MODE = $save; |
| 428 | 428 | if ($rs) { |
| 429 | 429 | $s .= "\n<h3>Ixora Suspicious SQL</h3>"; |
| 430 | - $s .= $this->tohtml($rs,'expsixora'); |
|
| 430 | + $s .= $this->tohtml($rs, 'expsixora'); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | return $s; |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | global $ADODB_CACHE_MODE; |
| 477 | 477 | if (isset($_GET['expeixora']) && isset($_GET['sql'])) { |
| 478 | 478 | $partial = empty($_GET['part']); |
| 479 | - echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
|
| 479 | + echo "<a name=explain></a>".$this->Explain($_GET['sql'], $partial)."\n"; |
|
| 480 | 480 | } |
| 481 | 481 | if (isset($_GET['sql'])) { |
| 482 | 482 | $var = $this->_ExpensiveSQL($numsql); |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
| 492 | 492 | |
| 493 | 493 | $savelog = $this->conn->LogSQL(false); |
| 494 | - $rs =& $this->conn->Execute($sql); |
|
| 494 | + $rs = & $this->conn->Execute($sql); |
|
| 495 | 495 | $this->conn->LogSQL($savelog); |
| 496 | 496 | |
| 497 | 497 | if (isset($savem)) $this->conn->SetFetchMode($savem); |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | |
| 500 | 500 | if ($rs) { |
| 501 | 501 | $s .= "\n<h3>Ixora Expensive SQL</h3>"; |
| 502 | - $s .= $this->tohtml($rs,'expeixora'); |
|
| 502 | + $s .= $this->tohtml($rs, 'expeixora'); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | return $s; |
@@ -13,9 +13,13 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | // security - hide paths |
| 16 | -if (!defined('ADODB_DIR')) die(); |
|
| 16 | +if (!defined('ADODB_DIR')) |
|
| 17 | +{ |
|
| 18 | + die(); |
|
| 19 | +} |
|
| 17 | 20 | |
| 18 | -class perf_oci8 extends ADODB_perf{ |
|
| 21 | +class perf_oci8 extends ADODB_perf |
|
| 22 | +{ |
|
| 19 | 23 | |
| 20 | 24 | var $tablesSQL = "select segment_name as \"tablename\", sum(bytes)/1024 as \"size_in_k\",tablespace_name as \"tablespace\",count(*) \"extents\" from sys.user_extents |
| 21 | 25 | group by segment_name,tablespace_name"; |
@@ -172,16 +176,26 @@ discard block |
||
| 172 | 176 | |
| 173 | 177 | function WarnPageCost($val) |
| 174 | 178 | { |
| 175 | - if ($val == 100) $s = '<font color=red><b>Too High</b>. </font>'; |
|
| 176 | - else $s = ''; |
|
| 179 | + if ($val == 100) |
|
| 180 | + { |
|
| 181 | + $s = '<font color=red><b>Too High</b>. </font>'; |
|
| 182 | + } |
|
| 183 | + else { |
|
| 184 | + $s = ''; |
|
| 185 | + } |
|
| 177 | 186 | |
| 178 | 187 | return $s.'Recommended is 20-50 for TP, and 50 for data warehouses. Default is 100. See <a href=http://www.dba-oracle.com/oracle_tips_cost_adj.htm>optimizer_index_cost_adj</a>. '; |
| 179 | 188 | } |
| 180 | 189 | |
| 181 | 190 | function WarnIndexCost($val) |
| 182 | 191 | { |
| 183 | - if ($val == 0) $s = '<font color=red><b>Too Low</b>. </font>'; |
|
| 184 | - else $s = ''; |
|
| 192 | + if ($val == 0) |
|
| 193 | + { |
|
| 194 | + $s = '<font color=red><b>Too Low</b>. </font>'; |
|
| 195 | + } |
|
| 196 | + else { |
|
| 197 | + $s = ''; |
|
| 198 | + } |
|
| 185 | 199 | |
| 186 | 200 | return $s.'Percentage of indexed data blocks expected in the cache. |
| 187 | 201 | Recommended is 20 (fast disk array) to 50 (slower hard disks). Default is 0. |
@@ -190,7 +204,10 @@ discard block |
||
| 190 | 204 | |
| 191 | 205 | function PGA() |
| 192 | 206 | { |
| 193 | - if ($this->version['version'] < 9) return 'Oracle 9i or later required'; |
|
| 207 | + if ($this->version['version'] < 9) |
|
| 208 | + { |
|
| 209 | + return 'Oracle 9i or later required'; |
|
| 210 | + } |
|
| 194 | 211 | |
| 195 | 212 | $rs = $this->conn->Execute("select a.mb,a.targ as pga_size_pct,a.pct from |
| 196 | 213 | (select round(pga_target_for_estimate/1024.0/1024.0,0) Mb, |
@@ -201,18 +218,25 @@ discard block |
||
| 201 | 218 | from v\$pga_target_advice) b on |
| 202 | 219 | a.r = b.r+1 where |
| 203 | 220 | b.pct < 100"); |
| 204 | - if (!$rs) return "Only in 9i or later"; |
|
| 221 | + if (!$rs) |
|
| 222 | + { |
|
| 223 | + return "Only in 9i or later"; |
|
| 224 | + } |
|
| 205 | 225 | $rs->Close(); |
| 206 | - if ($rs->EOF) return "PGA could be too big"; |
|
| 226 | + if ($rs->EOF) |
|
| 227 | + { |
|
| 228 | + return "PGA could be too big"; |
|
| 229 | + } |
|
| 207 | 230 | |
| 208 | 231 | return reset($rs->fields); |
| 209 | 232 | } |
| 210 | 233 | |
| 211 | - function Explain($sql,$partial=false) |
|
| 234 | + function Explain($sql,$partial=false) |
|
| 212 | 235 | { |
| 213 | 236 | $savelog = $this->conn->LogSQL(false); |
| 214 | 237 | $rs =& $this->conn->SelectLimit("select ID FROM PLAN_TABLE"); |
| 215 | - if (!$rs) { |
|
| 238 | + if (!$rs) |
|
| 239 | + { |
|
| 216 | 240 | echo "<p><b>Missing PLAN_TABLE</b></p> |
| 217 | 241 | <pre> |
| 218 | 242 | CREATE TABLE PLAN_TABLE ( |
@@ -248,13 +272,19 @@ discard block |
||
| 248 | 272 | $rs->Close(); |
| 249 | 273 | // $this->conn->debug=1; |
| 250 | 274 | |
| 251 | - if ($partial) { |
|
| 275 | + if ($partial) |
|
| 276 | + { |
|
| 252 | 277 | $sqlq = $this->conn->qstr($sql.'%'); |
| 253 | 278 | $arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like $sqlq"); |
| 254 | - if ($arr) { |
|
| 255 | - foreach($arr as $row) { |
|
| 279 | + if ($arr) |
|
| 280 | + { |
|
| 281 | + foreach($arr as $row) |
|
| 282 | + { |
|
| 256 | 283 | $sql = reset($row); |
| 257 | - if (crc32($sql) == $partial) break; |
|
| 284 | + if (crc32($sql) == $partial) |
|
| 285 | + { |
|
| 286 | + break; |
|
| 287 | + } |
|
| 258 | 288 | } |
| 259 | 289 | } |
| 260 | 290 | } |
@@ -266,7 +296,8 @@ discard block |
||
| 266 | 296 | |
| 267 | 297 | $rs =& $this->conn->Execute("EXPLAIN PLAN SET STATEMENT_ID='$id' FOR $sql"); |
| 268 | 298 | $m = $this->conn->ErrorMsg(); |
| 269 | - if ($m) { |
|
| 299 | + if ($m) |
|
| 300 | + { |
|
| 270 | 301 | $this->conn->RollbackTrans(); |
| 271 | 302 | $this->conn->LogSQL($savelog); |
| 272 | 303 | $s .= "<p>$m</p>"; |
@@ -290,7 +321,10 @@ discard block |
||
| 290 | 321 | |
| 291 | 322 | function CheckMemory() |
| 292 | 323 | { |
| 293 | - if ($this->version['version'] < 9) return 'Oracle 9i or later required'; |
|
| 324 | + if ($this->version['version'] < 9) |
|
| 325 | + { |
|
| 326 | + return 'Oracle 9i or later required'; |
|
| 327 | + } |
|
| 294 | 328 | |
| 295 | 329 | $rs =& $this->conn->Execute(" |
| 296 | 330 | select a.size_for_estimate as cache_mb_estimate, |
@@ -302,15 +336,21 @@ discard block |
||
| 302 | 336 | a.estd_physical_read_factor-b.estd_physical_read_factor as best_when_0 |
| 303 | 337 | from (select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$db_cache_advice) a , |
| 304 | 338 | (select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$db_cache_advice) b where a.r = b.r-1"); |
| 305 | - if (!$rs) return false; |
|
| 339 | + if (!$rs) |
|
| 340 | + { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 306 | 343 | |
| 307 | 344 | /* |
| 308 | 345 | The v$db_cache_advice utility show the marginal changes in physical data block reads for different sizes of db_cache_size |
| 309 | 346 | */ |
| 310 | 347 | $s = "<h3>Data Cache Estimate</h3>"; |
| 311 | - if ($rs->EOF) { |
|
| 348 | + if ($rs->EOF) |
|
| 349 | + { |
|
| 312 | 350 | $s .= "<p>Cache that is 50% of current size is still too big</p>"; |
| 313 | - } else { |
|
| 351 | + } |
|
| 352 | + else |
|
| 353 | + { |
|
| 314 | 354 | $s .= "Ideal size of Data Cache is when \"best_when_0\" changes from a positive number and becomes zero."; |
| 315 | 355 | $s .= rs2html($rs,false,false,false,false); |
| 316 | 356 | } |
@@ -325,17 +365,24 @@ discard block |
||
| 325 | 365 | $o1 = $rs->FetchField(0); |
| 326 | 366 | $o2 = $rs->FetchField(1); |
| 327 | 367 | $o3 = $rs->FetchField(2); |
| 328 | - if ($rs->EOF) return '<p>None found</p>'; |
|
| 368 | + if ($rs->EOF) |
|
| 369 | + { |
|
| 370 | + return '<p>None found</p>'; |
|
| 371 | + } |
|
| 329 | 372 | $check = ''; |
| 330 | 373 | $sql = ''; |
| 331 | 374 | $s = "\n\n<table border=1 bgcolor=white><tr><td><b>".$o1->name.'</b></td><td><b>'.$o2->name.'</b></td><td><b>'.$o3->name.'</b></td></tr>'; |
| 332 | - while (!$rs->EOF) { |
|
| 333 | - if ($check != $rs->fields[0].'::'.$rs->fields[1]) { |
|
| 334 | - if ($check) { |
|
| 375 | + while (!$rs->EOF) |
|
| 376 | + { |
|
| 377 | + if ($check != $rs->fields[0].'::'.$rs->fields[1]) |
|
| 378 | + { |
|
| 379 | + if ($check) |
|
| 380 | + { |
|
| 335 | 381 | $carr = explode('::',$check); |
| 336 | 382 | $prefix = "<a href=\"?$type=1&sql=".rawurlencode($sql).'&x#explain">'; |
| 337 | 383 | $suffix = '</a>'; |
| 338 | - if (strlen($prefix)>2000) { |
|
| 384 | + if (strlen($prefix)>2000) |
|
| 385 | + { |
|
| 339 | 386 | $prefix = ''; |
| 340 | 387 | $suffix = ''; |
| 341 | 388 | } |
@@ -344,9 +391,14 @@ discard block |
||
| 344 | 391 | } |
| 345 | 392 | $sql = $rs->fields[2]; |
| 346 | 393 | $check = $rs->fields[0].'::'.$rs->fields[1]; |
| 347 | - } else |
|
| 348 | - $sql .= $rs->fields[2]; |
|
| 349 | - if (substr($sql,strlen($sql)-1) == "\0") $sql = substr($sql,0,strlen($sql)-1); |
|
| 394 | + } |
|
| 395 | + else { |
|
| 396 | + $sql .= $rs->fields[2]; |
|
| 397 | + } |
|
| 398 | + if (substr($sql,strlen($sql)-1) == "\0") |
|
| 399 | + { |
|
| 400 | + $sql = substr($sql,0,strlen($sql)-1); |
|
| 401 | + } |
|
| 350 | 402 | $rs->MoveNext(); |
| 351 | 403 | } |
| 352 | 404 | $rs->Close(); |
@@ -354,7 +406,8 @@ discard block |
||
| 354 | 406 | $carr = explode('::',$check); |
| 355 | 407 | $prefix = "<a target=".rand()." href=\"?&hidem=1&$type=1&sql=".rawurlencode($sql).'&x#explain">'; |
| 356 | 408 | $suffix = '</a>'; |
| 357 | - if (strlen($prefix)>2000) { |
|
| 409 | + if (strlen($prefix)>2000) |
|
| 410 | + { |
|
| 358 | 411 | $prefix = ''; |
| 359 | 412 | $suffix = ''; |
| 360 | 413 | } |
@@ -404,12 +457,16 @@ discard block |
||
| 404 | 457 | 1 desc, s.address, p.piece"; |
| 405 | 458 | |
| 406 | 459 | global $ADODB_CACHE_MODE; |
| 407 | - if (isset($_GET['expsixora']) && isset($_GET['sql'])) { |
|
| 460 | + if (isset($_GET['expsixora']) && isset($_GET['sql'])) |
|
| 461 | + { |
|
| 408 | 462 | $partial = empty($_GET['part']); |
| 409 | 463 | echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
| 410 | 464 | } |
| 411 | 465 | |
| 412 | - if (isset($_GET['sql'])) return $this->_SuspiciousSQL($numsql); |
|
| 466 | + if (isset($_GET['sql'])) |
|
| 467 | + { |
|
| 468 | + return $this->_SuspiciousSQL($numsql); |
|
| 469 | + } |
|
| 413 | 470 | |
| 414 | 471 | $s = ''; |
| 415 | 472 | $s .= $this->_SuspiciousSQL($numsql); |
@@ -417,15 +474,22 @@ discard block |
||
| 417 | 474 | |
| 418 | 475 | $save = $ADODB_CACHE_MODE; |
| 419 | 476 | $ADODB_CACHE_MODE = ADODB_FETCH_NUM; |
| 420 | - if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
|
| 477 | + if ($this->conn->fetchMode !== false) |
|
| 478 | + { |
|
| 479 | + $savem = $this->conn->SetFetchMode(false); |
|
| 480 | + } |
|
| 421 | 481 | |
| 422 | 482 | $savelog = $this->conn->LogSQL(false); |
| 423 | 483 | $rs =& $this->conn->SelectLimit($sql); |
| 424 | 484 | $this->conn->LogSQL($savelog); |
| 425 | 485 | |
| 426 | - if (isset($savem)) $this->conn->SetFetchMode($savem); |
|
| 486 | + if (isset($savem)) |
|
| 487 | + { |
|
| 488 | + $this->conn->SetFetchMode($savem); |
|
| 489 | + } |
|
| 427 | 490 | $ADODB_CACHE_MODE = $save; |
| 428 | - if ($rs) { |
|
| 491 | + if ($rs) |
|
| 492 | + { |
|
| 429 | 493 | $s .= "\n<h3>Ixora Suspicious SQL</h3>"; |
| 430 | 494 | $s .= $this->tohtml($rs,'expsixora'); |
| 431 | 495 | } |
@@ -474,11 +538,13 @@ discard block |
||
| 474 | 538 | 1 desc, s.address, p.piece |
| 475 | 539 | "; |
| 476 | 540 | global $ADODB_CACHE_MODE; |
| 477 | - if (isset($_GET['expeixora']) && isset($_GET['sql'])) { |
|
| 541 | + if (isset($_GET['expeixora']) && isset($_GET['sql'])) |
|
| 542 | + { |
|
| 478 | 543 | $partial = empty($_GET['part']); |
| 479 | 544 | echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
| 480 | 545 | } |
| 481 | - if (isset($_GET['sql'])) { |
|
| 546 | + if (isset($_GET['sql'])) |
|
| 547 | + { |
|
| 482 | 548 | $var = $this->_ExpensiveSQL($numsql); |
| 483 | 549 | return $var; |
| 484 | 550 | } |
@@ -488,16 +554,23 @@ discard block |
||
| 488 | 554 | $s .= '<p>'; |
| 489 | 555 | $save = $ADODB_CACHE_MODE; |
| 490 | 556 | $ADODB_CACHE_MODE = ADODB_FETCH_NUM; |
| 491 | - if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
|
| 557 | + if ($this->conn->fetchMode !== false) |
|
| 558 | + { |
|
| 559 | + $savem = $this->conn->SetFetchMode(false); |
|
| 560 | + } |
|
| 492 | 561 | |
| 493 | 562 | $savelog = $this->conn->LogSQL(false); |
| 494 | 563 | $rs =& $this->conn->Execute($sql); |
| 495 | 564 | $this->conn->LogSQL($savelog); |
| 496 | 565 | |
| 497 | - if (isset($savem)) $this->conn->SetFetchMode($savem); |
|
| 566 | + if (isset($savem)) |
|
| 567 | + { |
|
| 568 | + $this->conn->SetFetchMode($savem); |
|
| 569 | + } |
|
| 498 | 570 | $ADODB_CACHE_MODE = $save; |
| 499 | 571 | |
| 500 | - if ($rs) { |
|
| 572 | + if ($rs) |
|
| 573 | + { |
|
| 501 | 574 | $s .= "\n<h3>Ixora Expensive SQL</h3>"; |
| 502 | 575 | $s .= $this->tohtml($rs,'expeixora'); |
| 503 | 576 | } |
@@ -124,6 +124,10 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | /*! |
| 126 | 126 | */ |
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 127 | 131 | function driver($driver = null) { |
| 128 | 132 | static $_driver = 'mysql'; |
| 129 | 133 | static $set = false; |
@@ -302,6 +306,10 @@ discard block |
||
| 302 | 306 | |
| 303 | 307 | /*! |
| 304 | 308 | */ |
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 305 | 313 | function table($table = null) { |
| 306 | 314 | static $_table = 'sessions'; |
| 307 | 315 | static $set = false; |
@@ -359,6 +367,10 @@ discard block |
||
| 359 | 367 | |
| 360 | 368 | /*! |
| 361 | 369 | */ |
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @return string |
|
| 373 | + */ |
|
| 362 | 374 | function clob($clob = null) { |
| 363 | 375 | static $_clob = false; |
| 364 | 376 | static $set = false; |
@@ -405,6 +417,10 @@ discard block |
||
| 405 | 417 | |
| 406 | 418 | /*! |
| 407 | 419 | */ |
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * @return string |
|
| 423 | + */ |
|
| 408 | 424 | function encryptionKey($encryption_key = null) { |
| 409 | 425 | static $_encryption_key = 'CRYPTED ADODB SESSIONS ROCK!'; |
| 410 | 426 | |
@@ -427,6 +443,12 @@ discard block |
||
| 427 | 443 | |
| 428 | 444 | /*! |
| 429 | 445 | */ |
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * @param string $crc |
|
| 449 | + * |
|
| 450 | + * @return string |
|
| 451 | + */ |
|
| 430 | 452 | function _crc($crc = null) { |
| 431 | 453 | static $_crc = false; |
| 432 | 454 | |
@@ -498,6 +520,10 @@ discard block |
||
| 498 | 520 | |
| 499 | 521 | If $conn already exists, reuse that connection |
| 500 | 522 | */ |
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * @param boolean $persist |
|
| 526 | + */ |
|
| 501 | 527 | function open($save_path, $session_name, $persist = null) { |
| 502 | 528 | $conn =& ADODB_Session::_conn(); |
| 503 | 529 | |
@@ -93,15 +93,15 @@ |
||
| 93 | 93 | */ |
| 94 | 94 | function adodb_session_create_table($schemaFile=null,$conn = null) |
| 95 | 95 | { |
| 96 | - // set default values |
|
| 97 | - if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
| 98 | - if ($conn===null) $conn =& ADODB_Session::_conn(); |
|
| 96 | + // set default values |
|
| 97 | + if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
| 98 | + if ($conn===null) $conn =& ADODB_Session::_conn(); |
|
| 99 | 99 | |
| 100 | 100 | if (!$conn) return 0; |
| 101 | 101 | |
| 102 | - $schema = new adoSchema($conn); |
|
| 103 | - $schema->ParseSchema($schemaFile); |
|
| 104 | - return $schema->ExecuteSchema(); |
|
| 102 | + $schema = new adoSchema($conn); |
|
| 103 | + $schema->ParseSchema($schemaFile); |
|
| 104 | + return $schema->ExecuteSchema(); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /*! |
@@ -533,10 +533,10 @@ |
||
| 533 | 533 | |
| 534 | 534 | if ($persist) { |
| 535 | 535 | switch($persist) { |
| 536 | - default: |
|
| 537 | - case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; |
|
| 538 | - case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; |
|
| 539 | - case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; |
|
| 536 | + default: |
|
| 537 | + case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; |
|
| 538 | + case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; |
|
| 539 | + case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; |
|
| 540 | 540 | } |
| 541 | 541 | } else { |
| 542 | 542 | $ok = $conn->Connect($host, $user, $password, $database); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | 28 | if (!defined('_ADODB_LAYER')) { |
| 29 | - require_once realpath(dirname(__FILE__) . '/../adodb.inc.php'); |
|
| 29 | + require_once realpath(dirname(__FILE__).'/../adodb.inc.php'); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | if (defined('ADODB_SESSION')) return 1; |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | 3. After urldecode, run the serialized string through this function: |
| 44 | 44 | |
| 45 | 45 | */ |
| 46 | -function adodb_unserialize( $serialized_string ) |
|
| 46 | +function adodb_unserialize($serialized_string) |
|
| 47 | 47 | { |
| 48 | 48 | $variables = array( ); |
| 49 | - $a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); |
|
| 50 | - for( $i = 0; $i < count( $a ); $i = $i+2 ) { |
|
| 51 | - $variables[$a[$i]] = unserialize( $a[$i+1] ); |
|
| 49 | + $a = preg_split("/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); |
|
| 50 | + for ($i = 0; $i < count($a); $i = $i + 2) { |
|
| 51 | + $variables[$a[$i]] = unserialize($a[$i + 1]); |
|
| 52 | 52 | } |
| 53 | - return( $variables ); |
|
| 53 | + return($variables); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /* |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function adodb_session_regenerate_id() |
| 61 | 61 | { |
| 62 | - $conn =& ADODB_Session::_conn(); |
|
| 62 | + $conn = & ADODB_Session::_conn(); |
|
| 63 | 63 | if (!$conn) return false; |
| 64 | 64 | |
| 65 | 65 | $old_id = session_id(); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | //@session_start(); |
| 73 | 73 | } |
| 74 | 74 | $new_id = session_id(); |
| 75 | - $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); |
|
| 75 | + $ok = & $conn->Execute('UPDATE '.ADODB_Session::table().' SET sesskey='.$conn->qstr($new_id).' WHERE sesskey='.$conn->qstr($old_id)); |
|
| 76 | 76 | |
| 77 | 77 | /* it is possible that the update statement fails due to a collision */ |
| 78 | 78 | if (!$ok) { |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | @return 0 if failure, 1 if errors, 2 if successful. |
| 92 | 92 | @author Markus Staab http://www.public-4u.de |
| 93 | 93 | */ |
| 94 | -function adodb_session_create_table($schemaFile=null,$conn = null) |
|
| 94 | +function adodb_session_create_table($schemaFile = null, $conn = null) |
|
| 95 | 95 | { |
| 96 | 96 | // set default values |
| 97 | - if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
| 98 | - if ($conn===null) $conn =& ADODB_Session::_conn(); |
|
| 97 | + if ($schemaFile === null) $schemaFile = ADODB_SESSION.'/session_schema.xml'; |
|
| 98 | + if ($conn === null) $conn = & ADODB_Session::_conn(); |
|
| 99 | 99 | |
| 100 | 100 | if (!$conn) return 0; |
| 101 | 101 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | static $set = false; |
| 238 | 238 | |
| 239 | 239 | if (!is_null($lifetime)) { |
| 240 | - $_lifetime = (int) $lifetime; |
|
| 240 | + $_lifetime = (int)$lifetime; |
|
| 241 | 241 | $set = true; |
| 242 | 242 | } elseif (!$set) { |
| 243 | 243 | // backwards compatibility |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | static $set = false; |
| 265 | 265 | |
| 266 | 266 | if (!is_null($debug)) { |
| 267 | - $_debug = (bool) $debug; |
|
| 267 | + $_debug = (bool)$debug; |
|
| 268 | 268 | |
| 269 | 269 | $conn = ADODB_Session::_conn(); |
| 270 | 270 | if ($conn) { |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | static $set = false; |
| 327 | 327 | |
| 328 | 328 | if (!is_null($optimize)) { |
| 329 | - $_optimize = (bool) $optimize; |
|
| 329 | + $_optimize = (bool)$optimize; |
|
| 330 | 330 | $set = true; |
| 331 | 331 | } elseif (!$set) { |
| 332 | 332 | // backwards compatibility |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | static $set = false; |
| 346 | 346 | |
| 347 | 347 | if (!is_null($sync_seconds)) { |
| 348 | - $_sync_seconds = (int) $sync_seconds; |
|
| 348 | + $_sync_seconds = (int)$sync_seconds; |
|
| 349 | 349 | $set = true; |
| 350 | 350 | } elseif (!$set) { |
| 351 | 351 | // backwards compatibility |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | |
| 422 | 422 | /*! |
| 423 | 423 | */ |
| 424 | - function &_conn($conn=null) { |
|
| 424 | + function &_conn($conn = null) { |
|
| 425 | 425 | return $GLOBALS['ADODB_SESS_CONN']; |
| 426 | 426 | } |
| 427 | 427 | |
@@ -463,8 +463,8 @@ discard block |
||
| 463 | 463 | /*! |
| 464 | 464 | */ |
| 465 | 465 | function _dumprs($rs) { |
| 466 | - $conn =& ADODB_Session::_conn(); |
|
| 467 | - $debug = ADODB_Session::debug(); |
|
| 466 | + $conn = & ADODB_Session::_conn(); |
|
| 467 | + $debug = ADODB_Session::debug(); |
|
| 468 | 468 | |
| 469 | 469 | if (!$conn) { |
| 470 | 470 | return; |
@@ -499,17 +499,17 @@ discard block |
||
| 499 | 499 | If $conn already exists, reuse that connection |
| 500 | 500 | */ |
| 501 | 501 | function open($save_path, $session_name, $persist = null) { |
| 502 | - $conn =& ADODB_Session::_conn(); |
|
| 502 | + $conn = & ADODB_Session::_conn(); |
|
| 503 | 503 | |
| 504 | 504 | if ($conn) { |
| 505 | 505 | return true; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - $database = ADODB_Session::database(); |
|
| 509 | - $debug = ADODB_Session::debug(); |
|
| 510 | - $driver = ADODB_Session::driver(); |
|
| 508 | + $database = ADODB_Session::database(); |
|
| 509 | + $debug = ADODB_Session::debug(); |
|
| 510 | + $driver = ADODB_Session::driver(); |
|
| 511 | 511 | $host = ADODB_Session::host(); |
| 512 | - $password = ADODB_Session::password(); |
|
| 512 | + $password = ADODB_Session::password(); |
|
| 513 | 513 | $user = ADODB_Session::user(); |
| 514 | 514 | |
| 515 | 515 | if (!is_null($persist)) { |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | # assert('$host'); |
| 525 | 525 | |
| 526 | 526 | // cannot use =& below - do not know why... |
| 527 | - $conn =& ADONewConnection($driver); |
|
| 527 | + $conn = & ADONewConnection($driver); |
|
| 528 | 528 | |
| 529 | 529 | if ($debug) { |
| 530 | 530 | $conn->debug = true; |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | if ($persist) { |
| 535 | - switch($persist) { |
|
| 535 | + switch ($persist) { |
|
| 536 | 536 | default: |
| 537 | 537 | case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; |
| 538 | 538 | case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | $ok = $conn->Connect($host, $user, $password, $database); |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - if ($ok) $GLOBALS['ADODB_SESS_CONN'] =& $conn; |
|
| 545 | + if ($ok) $GLOBALS['ADODB_SESS_CONN'] = & $conn; |
|
| 546 | 546 | else |
| 547 | 547 | ADOConnection::outp('<p>Session: connection failed</p>', false); |
| 548 | 548 | |
@@ -565,10 +565,10 @@ discard block |
||
| 565 | 565 | Slurp in the session variables and return the serialized string |
| 566 | 566 | */ |
| 567 | 567 | function read($key) { |
| 568 | - $conn =& ADODB_Session::_conn(); |
|
| 568 | + $conn = & ADODB_Session::_conn(); |
|
| 569 | 569 | $data = ADODB_Session::dataFieldName(); |
| 570 | - $filter = ADODB_Session::filter(); |
|
| 571 | - $table = ADODB_Session::table(); |
|
| 570 | + $filter = ADODB_Session::filter(); |
|
| 571 | + $table = ADODB_Session::table(); |
|
| 572 | 572 | |
| 573 | 573 | if (!$conn) { |
| 574 | 574 | return ''; |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | $qkey = $conn->quote($key); |
| 580 | 580 | $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; |
| 581 | 581 | |
| 582 | - $sql = "SELECT $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= " . time(); |
|
| 582 | + $sql = "SELECT $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= ".time(); |
|
| 583 | 583 | /* Lock code does not work as it needs to hold transaction within whole page, and we don't know if |
| 584 | 584 | developer has commited elsewhere... :( |
| 585 | 585 | */ |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | # $rs =& $conn->RowLock($table, "$binary sesskey = $qkey AND expiry >= " . time(), $data); |
| 588 | 588 | #else |
| 589 | 589 | |
| 590 | - $rs =& $conn->Execute($sql); |
|
| 590 | + $rs = & $conn->Execute($sql); |
|
| 591 | 591 | //ADODB_Session::_dumprs($rs); |
| 592 | 592 | if ($rs) { |
| 593 | 593 | if ($rs->EOF) { |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | |
| 606 | 606 | $rs->Close(); |
| 607 | 607 | |
| 608 | - ADODB_Session::_crc(strlen($v) . crc32($v)); |
|
| 608 | + ADODB_Session::_crc(strlen($v).crc32($v)); |
|
| 609 | 609 | return $v; |
| 610 | 610 | } |
| 611 | 611 | |
@@ -619,15 +619,15 @@ discard block |
||
| 619 | 619 | */ |
| 620 | 620 | function write($key, $val) { |
| 621 | 621 | $clob = ADODB_Session::clob(); |
| 622 | - $conn =& ADODB_Session::_conn(); |
|
| 623 | - $crc = ADODB_Session::_crc(); |
|
| 622 | + $conn = & ADODB_Session::_conn(); |
|
| 623 | + $crc = ADODB_Session::_crc(); |
|
| 624 | 624 | $data = ADODB_Session::dataFieldName(); |
| 625 | - $debug = ADODB_Session::debug(); |
|
| 625 | + $debug = ADODB_Session::debug(); |
|
| 626 | 626 | $driver = ADODB_Session::driver(); |
| 627 | - $expire_notify = ADODB_Session::expireNotify(); |
|
| 627 | + $expire_notify = ADODB_Session::expireNotify(); |
|
| 628 | 628 | $filter = ADODB_Session::filter(); |
| 629 | - $lifetime = ADODB_Session::lifetime(); |
|
| 630 | - $table = ADODB_Session::table(); |
|
| 629 | + $lifetime = ADODB_Session::lifetime(); |
|
| 630 | + $table = ADODB_Session::table(); |
|
| 631 | 631 | |
| 632 | 632 | if (!$conn) { |
| 633 | 633 | return false; |
@@ -642,12 +642,12 @@ discard block |
||
| 642 | 642 | |
| 643 | 643 | // crc32 optimization since adodb 2.1 |
| 644 | 644 | // now we only update expiry date, thx to sebastian thom in adodb 2.32 |
| 645 | - if ($crc !== false && $crc == (strlen($val) . crc32($val))) { |
|
| 645 | + if ($crc !== false && $crc == (strlen($val).crc32($val))) { |
|
| 646 | 646 | if ($debug) { |
| 647 | 647 | echo '<p>Session: Only updating date - crc32 not changed</p>'; |
| 648 | 648 | } |
| 649 | 649 | $sql = "UPDATE $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2'); |
| 650 | - $rs =& $conn->Execute($sql,array($expiry,$key,time())); |
|
| 650 | + $rs = & $conn->Execute($sql, array($expiry, $key, time())); |
|
| 651 | 651 | ADODB_Session::_dumprs($rs); |
| 652 | 652 | if ($rs) { |
| 653 | 653 | $rs->Close(); |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | // do we insert or update? => as for sesskey |
| 695 | - $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey"); |
|
| 695 | + $rs = & $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey"); |
|
| 696 | 696 | ADODB_Session::_dumprs($rs); |
| 697 | 697 | if ($rs && reset($rs->fields) > 0) { |
| 698 | 698 | $sql = "UPDATE $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey"; |
@@ -704,12 +704,12 @@ discard block |
||
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | $err = ''; |
| 707 | - $rs1 =& $conn->Execute($sql); |
|
| 707 | + $rs1 = & $conn->Execute($sql); |
|
| 708 | 708 | ADODB_Session::_dumprs($rs1); |
| 709 | 709 | if (!$rs1) { |
| 710 | 710 | $err = $conn->ErrorMsg()."\n"; |
| 711 | 711 | } |
| 712 | - $rs2 =& $conn->UpdateBlob($table, $data, $val, " sesskey=$qkey", strtoupper($clob)); |
|
| 712 | + $rs2 = & $conn->UpdateBlob($table, $data, $val, " sesskey=$qkey", strtoupper($clob)); |
|
| 713 | 713 | ADODB_Session::_dumprs($rs2); |
| 714 | 714 | if (!$rs2) { |
| 715 | 715 | $err .= $conn->ErrorMsg()."\n"; |
@@ -724,14 +724,14 @@ discard block |
||
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | if (!$rs) { |
| 727 | - ADOConnection::outp('<p>Session Replace: ' . $conn->ErrorMsg() . '</p>', false); |
|
| 727 | + ADOConnection::outp('<p>Session Replace: '.$conn->ErrorMsg().'</p>', false); |
|
| 728 | 728 | return false; |
| 729 | - } else { |
|
| 729 | + } else { |
|
| 730 | 730 | // bug in access driver (could be odbc?) means that info is not committed |
| 731 | 731 | // properly unless select statement executed in Win2000 |
| 732 | 732 | if ($conn->databaseType == 'access') { |
| 733 | 733 | $sql = "SELECT sesskey FROM $table WHERE $binary sesskey = $qkey"; |
| 734 | - $rs =& $conn->Execute($sql); |
|
| 734 | + $rs = & $conn->Execute($sql); |
|
| 735 | 735 | ADODB_Session::_dumprs($rs); |
| 736 | 736 | if ($rs) { |
| 737 | 737 | $rs->Close(); |
@@ -747,9 +747,9 @@ discard block |
||
| 747 | 747 | /*! |
| 748 | 748 | */ |
| 749 | 749 | function destroy($key) { |
| 750 | - $conn =& ADODB_Session::_conn(); |
|
| 751 | - $table = ADODB_Session::table(); |
|
| 752 | - $expire_notify = ADODB_Session::expireNotify(); |
|
| 750 | + $conn = & ADODB_Session::_conn(); |
|
| 751 | + $table = ADODB_Session::table(); |
|
| 752 | + $expire_notify = ADODB_Session::expireNotify(); |
|
| 753 | 753 | |
| 754 | 754 | if (!$conn) { |
| 755 | 755 | return false; |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | $fn = next($expire_notify); |
| 766 | 766 | $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); |
| 767 | 767 | $sql = "SELECT expireref, sesskey FROM $table WHERE $binary sesskey = $qkey"; |
| 768 | - $rs =& $conn->Execute($sql); |
|
| 768 | + $rs = & $conn->Execute($sql); |
|
| 769 | 769 | ADODB_Session::_dumprs($rs); |
| 770 | 770 | $conn->SetFetchMode($savem); |
| 771 | 771 | if (!$rs) { |
@@ -782,7 +782,7 @@ discard block |
||
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | $sql = "DELETE FROM $table WHERE $binary sesskey = $qkey"; |
| 785 | - $rs =& $conn->Execute($sql); |
|
| 785 | + $rs = & $conn->Execute($sql); |
|
| 786 | 786 | ADODB_Session::_dumprs($rs); |
| 787 | 787 | if ($rs) { |
| 788 | 788 | $rs->Close(); |
@@ -794,12 +794,12 @@ discard block |
||
| 794 | 794 | /*! |
| 795 | 795 | */ |
| 796 | 796 | function gc($maxlifetime) { |
| 797 | - $conn =& ADODB_Session::_conn(); |
|
| 798 | - $debug = ADODB_Session::debug(); |
|
| 799 | - $expire_notify = ADODB_Session::expireNotify(); |
|
| 800 | - $optimize = ADODB_Session::optimize(); |
|
| 801 | - $sync_seconds = ADODB_Session::syncSeconds(); |
|
| 802 | - $table = ADODB_Session::table(); |
|
| 797 | + $conn = & ADODB_Session::_conn(); |
|
| 798 | + $debug = ADODB_Session::debug(); |
|
| 799 | + $expire_notify = ADODB_Session::expireNotify(); |
|
| 800 | + $optimize = ADODB_Session::optimize(); |
|
| 801 | + $sync_seconds = ADODB_Session::syncSeconds(); |
|
| 802 | + $table = ADODB_Session::table(); |
|
| 803 | 803 | |
| 804 | 804 | if (!$conn) { |
| 805 | 805 | return false; |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | $fn = next($expire_notify); |
| 817 | 817 | $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); |
| 818 | 818 | $sql = "SELECT expireref, sesskey FROM $table WHERE expiry < $time"; |
| 819 | - $rs =& $conn->Execute($sql); |
|
| 819 | + $rs = & $conn->Execute($sql); |
|
| 820 | 820 | ADODB_Session::_dumprs($rs); |
| 821 | 821 | $conn->SetFetchMode($savem); |
| 822 | 822 | if ($rs) { |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | } |
| 836 | 836 | } else { |
| 837 | 837 | $sql = "DELETE FROM $table WHERE expiry < $time"; |
| 838 | - $rs =& $conn->Execute($sql); |
|
| 838 | + $rs = & $conn->Execute($sql); |
|
| 839 | 839 | ADODB_Session::_dumprs($rs); |
| 840 | 840 | if ($rs) { |
| 841 | 841 | $rs->Close(); |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | } |
| 870 | 870 | $sql .= " FROM $table"; |
| 871 | 871 | |
| 872 | - $rs =& $conn->SelectLimit($sql, 1); |
|
| 872 | + $rs = & $conn->SelectLimit($sql, 1); |
|
| 873 | 873 | if ($rs && !$rs->EOF) { |
| 874 | 874 | $dbts = reset($rs->fields); |
| 875 | 875 | $rs->Close(); |
@@ -877,9 +877,9 @@ discard block |
||
| 877 | 877 | $t = time(); |
| 878 | 878 | |
| 879 | 879 | if (abs($dbt - $t) >= $sync_seconds) { |
| 880 | - $msg = __FILE__ . |
|
| 881 | - ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: " . |
|
| 882 | - " database=$dbt ($dbts), webserver=$t (diff=". (abs($dbt - $t) / 60) . ' minutes)'; |
|
| 880 | + $msg = __FILE__. |
|
| 881 | + ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: ". |
|
| 882 | + " database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt - $t) / 60).' minutes)'; |
|
| 883 | 883 | error_log($msg); |
| 884 | 884 | if ($debug) { |
| 885 | 885 | ADOConnection::outp("<p>$msg</p>"); |
@@ -25,11 +25,15 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | -if (!defined('_ADODB_LAYER')) { |
|
| 28 | +if (!defined('_ADODB_LAYER')) |
|
| 29 | +{ |
|
| 29 | 30 | require_once realpath(dirname(__FILE__) . '/../adodb.inc.php'); |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | -if (defined('ADODB_SESSION')) return 1; |
|
| 33 | +if (defined('ADODB_SESSION')) |
|
| 34 | +{ |
|
| 35 | + return 1; |
|
| 36 | +} |
|
| 33 | 37 | |
| 34 | 38 | define('ADODB_SESSION', dirname(__FILE__)); |
| 35 | 39 | |
@@ -43,11 +47,12 @@ discard block |
||
| 43 | 47 | 3. After urldecode, run the serialized string through this function: |
| 44 | 48 | |
| 45 | 49 | */ |
| 46 | -function adodb_unserialize( $serialized_string ) |
|
| 50 | +function adodb_unserialize( $serialized_string ) |
|
| 47 | 51 | { |
| 48 | 52 | $variables = array( ); |
| 49 | 53 | $a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); |
| 50 | - for( $i = 0; $i < count( $a ); $i = $i+2 ) { |
|
| 54 | + for( $i = 0; $i < count( $a ); $i = $i+2 ) |
|
| 55 | + { |
|
| 51 | 56 | $variables[$a[$i]] = unserialize( $a[$i+1] ); |
| 52 | 57 | } |
| 53 | 58 | return( $variables ); |
@@ -57,15 +62,21 @@ discard block |
||
| 57 | 62 | Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 |
| 58 | 63 | Since adodb 4.61. |
| 59 | 64 | */ |
| 60 | -function adodb_session_regenerate_id() |
|
| 65 | +function adodb_session_regenerate_id() |
|
| 61 | 66 | { |
| 62 | 67 | $conn =& ADODB_Session::_conn(); |
| 63 | - if (!$conn) return false; |
|
| 68 | + if (!$conn) |
|
| 69 | + { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 64 | 72 | |
| 65 | 73 | $old_id = session_id(); |
| 66 | - if (function_exists('session_regenerate_id')) { |
|
| 74 | + if (function_exists('session_regenerate_id')) |
|
| 75 | + { |
|
| 67 | 76 | session_regenerate_id(); |
| 68 | - } else { |
|
| 77 | + } |
|
| 78 | + else |
|
| 79 | + { |
|
| 69 | 80 | session_id(md5(uniqid(rand(), true))); |
| 70 | 81 | $ck = session_get_cookie_params(); |
| 71 | 82 | setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); |
@@ -75,9 +86,13 @@ discard block |
||
| 75 | 86 | $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); |
| 76 | 87 | |
| 77 | 88 | /* it is possible that the update statement fails due to a collision */ |
| 78 | - if (!$ok) { |
|
| 89 | + if (!$ok) |
|
| 90 | + { |
|
| 79 | 91 | session_id($old_id); |
| 80 | - if (empty($ck)) $ck = session_get_cookie_params(); |
|
| 92 | + if (empty($ck)) |
|
| 93 | + { |
|
| 94 | + $ck = session_get_cookie_params(); |
|
| 95 | + } |
|
| 81 | 96 | setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); |
| 82 | 97 | return false; |
| 83 | 98 | } |
@@ -94,10 +109,19 @@ discard block |
||
| 94 | 109 | function adodb_session_create_table($schemaFile=null,$conn = null) |
| 95 | 110 | { |
| 96 | 111 | // set default values |
| 97 | - if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
| 98 | - if ($conn===null) $conn =& ADODB_Session::_conn(); |
|
| 99 | - |
|
| 100 | - if (!$conn) return 0; |
|
| 112 | + if ($schemaFile===null) |
|
| 113 | + { |
|
| 114 | + $schemaFile = ADODB_SESSION . '/session_schema.xml'; |
|
| 115 | + } |
|
| 116 | + if ($conn===null) |
|
| 117 | + { |
|
| 118 | + $conn =& ADODB_Session::_conn(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if (!$conn) |
|
| 122 | + { |
|
| 123 | + return 0; |
|
| 124 | + } |
|
| 101 | 125 | |
| 102 | 126 | $schema = new adoSchema($conn); |
| 103 | 127 | $schema->ParseSchema($schemaFile); |
@@ -107,7 +131,8 @@ discard block |
||
| 107 | 131 | /*! |
| 108 | 132 | \static |
| 109 | 133 | */ |
| 110 | -class ADODB_Session { |
|
| 134 | +class ADODB_Session |
|
| 135 | +{ |
|
| 111 | 136 | ///////////////////// |
| 112 | 137 | // getter/setter methods |
| 113 | 138 | ///////////////////// |
@@ -124,16 +149,21 @@ discard block |
||
| 124 | 149 | */ |
| 125 | 150 | /*! |
| 126 | 151 | */ |
| 127 | - function driver($driver = null) { |
|
| 152 | + function driver($driver = null) |
|
| 153 | + { |
|
| 128 | 154 | static $_driver = 'mysql'; |
| 129 | 155 | static $set = false; |
| 130 | 156 | |
| 131 | - if (!is_null($driver)) { |
|
| 157 | + if (!is_null($driver)) |
|
| 158 | + { |
|
| 132 | 159 | $_driver = trim($driver); |
| 133 | 160 | $set = true; |
| 134 | - } elseif (!$set) { |
|
| 161 | + } |
|
| 162 | + elseif (!$set) |
|
| 163 | + { |
|
| 135 | 164 | // backwards compatibility |
| 136 | - if (isset($GLOBALS['ADODB_SESSION_DRIVER'])) { |
|
| 165 | + if (isset($GLOBALS['ADODB_SESSION_DRIVER'])) |
|
| 166 | + { |
|
| 137 | 167 | return $GLOBALS['ADODB_SESSION_DRIVER']; |
| 138 | 168 | } |
| 139 | 169 | } |
@@ -143,16 +173,21 @@ discard block |
||
| 143 | 173 | |
| 144 | 174 | /*! |
| 145 | 175 | */ |
| 146 | - function host($host = null) { |
|
| 176 | + function host($host = null) |
|
| 177 | + { |
|
| 147 | 178 | static $_host = 'localhost'; |
| 148 | 179 | static $set = false; |
| 149 | 180 | |
| 150 | - if (!is_null($host)) { |
|
| 181 | + if (!is_null($host)) |
|
| 182 | + { |
|
| 151 | 183 | $_host = trim($host); |
| 152 | 184 | $set = true; |
| 153 | - } elseif (!$set) { |
|
| 185 | + } |
|
| 186 | + elseif (!$set) |
|
| 187 | + { |
|
| 154 | 188 | // backwards compatibility |
| 155 | - if (isset($GLOBALS['ADODB_SESSION_CONNECT'])) { |
|
| 189 | + if (isset($GLOBALS['ADODB_SESSION_CONNECT'])) |
|
| 190 | + { |
|
| 156 | 191 | return $GLOBALS['ADODB_SESSION_CONNECT']; |
| 157 | 192 | } |
| 158 | 193 | } |
@@ -162,16 +197,21 @@ discard block |
||
| 162 | 197 | |
| 163 | 198 | /*! |
| 164 | 199 | */ |
| 165 | - function user($user = null) { |
|
| 200 | + function user($user = null) |
|
| 201 | + { |
|
| 166 | 202 | static $_user = 'root'; |
| 167 | 203 | static $set = false; |
| 168 | 204 | |
| 169 | - if (!is_null($user)) { |
|
| 205 | + if (!is_null($user)) |
|
| 206 | + { |
|
| 170 | 207 | $_user = trim($user); |
| 171 | 208 | $set = true; |
| 172 | - } elseif (!$set) { |
|
| 209 | + } |
|
| 210 | + elseif (!$set) |
|
| 211 | + { |
|
| 173 | 212 | // backwards compatibility |
| 174 | - if (isset($GLOBALS['ADODB_SESSION_USER'])) { |
|
| 213 | + if (isset($GLOBALS['ADODB_SESSION_USER'])) |
|
| 214 | + { |
|
| 175 | 215 | return $GLOBALS['ADODB_SESSION_USER']; |
| 176 | 216 | } |
| 177 | 217 | } |
@@ -181,16 +221,21 @@ discard block |
||
| 181 | 221 | |
| 182 | 222 | /*! |
| 183 | 223 | */ |
| 184 | - function password($password = null) { |
|
| 224 | + function password($password = null) |
|
| 225 | + { |
|
| 185 | 226 | static $_password = ''; |
| 186 | 227 | static $set = false; |
| 187 | 228 | |
| 188 | - if (!is_null($password)) { |
|
| 229 | + if (!is_null($password)) |
|
| 230 | + { |
|
| 189 | 231 | $_password = $password; |
| 190 | 232 | $set = true; |
| 191 | - } elseif (!$set) { |
|
| 233 | + } |
|
| 234 | + elseif (!$set) |
|
| 235 | + { |
|
| 192 | 236 | // backwards compatibility |
| 193 | - if (isset($GLOBALS['ADODB_SESSION_PWD'])) { |
|
| 237 | + if (isset($GLOBALS['ADODB_SESSION_PWD'])) |
|
| 238 | + { |
|
| 194 | 239 | return $GLOBALS['ADODB_SESSION_PWD']; |
| 195 | 240 | } |
| 196 | 241 | } |
@@ -200,16 +245,21 @@ discard block |
||
| 200 | 245 | |
| 201 | 246 | /*! |
| 202 | 247 | */ |
| 203 | - function database($database = null) { |
|
| 248 | + function database($database = null) |
|
| 249 | + { |
|
| 204 | 250 | static $_database = 'xphplens_2'; |
| 205 | 251 | static $set = false; |
| 206 | 252 | |
| 207 | - if (!is_null($database)) { |
|
| 253 | + if (!is_null($database)) |
|
| 254 | + { |
|
| 208 | 255 | $_database = trim($database); |
| 209 | 256 | $set = true; |
| 210 | - } elseif (!$set) { |
|
| 257 | + } |
|
| 258 | + elseif (!$set) |
|
| 259 | + { |
|
| 211 | 260 | // backwards compatibility |
| 212 | - if (isset($GLOBALS['ADODB_SESSION_DB'])) { |
|
| 261 | + if (isset($GLOBALS['ADODB_SESSION_DB'])) |
|
| 262 | + { |
|
| 213 | 263 | return $GLOBALS['ADODB_SESSION_DB']; |
| 214 | 264 | } |
| 215 | 265 | } |
@@ -219,11 +269,12 @@ discard block |
||
| 219 | 269 | |
| 220 | 270 | /*! |
| 221 | 271 | */ |
| 222 | - function persist($persist = null) |
|
| 272 | + function persist($persist = null) |
|
| 223 | 273 | { |
| 224 | 274 | static $_persist = true; |
| 225 | 275 | |
| 226 | - if (!is_null($persist)) { |
|
| 276 | + if (!is_null($persist)) |
|
| 277 | + { |
|
| 227 | 278 | $_persist = trim($persist); |
| 228 | 279 | } |
| 229 | 280 | |
@@ -232,22 +283,29 @@ discard block |
||
| 232 | 283 | |
| 233 | 284 | /*! |
| 234 | 285 | */ |
| 235 | - function lifetime($lifetime = null) { |
|
| 286 | + function lifetime($lifetime = null) |
|
| 287 | + { |
|
| 236 | 288 | static $_lifetime; |
| 237 | 289 | static $set = false; |
| 238 | 290 | |
| 239 | - if (!is_null($lifetime)) { |
|
| 291 | + if (!is_null($lifetime)) |
|
| 292 | + { |
|
| 240 | 293 | $_lifetime = (int) $lifetime; |
| 241 | 294 | $set = true; |
| 242 | - } elseif (!$set) { |
|
| 295 | + } |
|
| 296 | + elseif (!$set) |
|
| 297 | + { |
|
| 243 | 298 | // backwards compatibility |
| 244 | - if (isset($GLOBALS['ADODB_SESS_LIFE'])) { |
|
| 299 | + if (isset($GLOBALS['ADODB_SESS_LIFE'])) |
|
| 300 | + { |
|
| 245 | 301 | return $GLOBALS['ADODB_SESS_LIFE']; |
| 246 | 302 | } |
| 247 | 303 | } |
| 248 | - if (!$_lifetime) { |
|
| 304 | + if (!$_lifetime) |
|
| 305 | + { |
|
| 249 | 306 | $_lifetime = ini_get('session.gc_maxlifetime'); |
| 250 | - if ($_lifetime <= 1) { |
|
| 307 | + if ($_lifetime <= 1) |
|
| 308 | + { |
|
| 251 | 309 | // bug in PHP 4.0.3 pl 1 -- how about other versions? |
| 252 | 310 | //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $lifetime</h3>"; |
| 253 | 311 | $_lifetime = 1440; |
@@ -259,21 +317,27 @@ discard block |
||
| 259 | 317 | |
| 260 | 318 | /*! |
| 261 | 319 | */ |
| 262 | - function debug($debug = null) { |
|
| 320 | + function debug($debug = null) |
|
| 321 | + { |
|
| 263 | 322 | static $_debug = false; |
| 264 | 323 | static $set = false; |
| 265 | 324 | |
| 266 | - if (!is_null($debug)) { |
|
| 325 | + if (!is_null($debug)) |
|
| 326 | + { |
|
| 267 | 327 | $_debug = (bool) $debug; |
| 268 | 328 | |
| 269 | 329 | $conn = ADODB_Session::_conn(); |
| 270 | - if ($conn) { |
|
| 330 | + if ($conn) |
|
| 331 | + { |
|
| 271 | 332 | $conn->debug = $_debug; |
| 272 | 333 | } |
| 273 | 334 | $set = true; |
| 274 | - } elseif (!$set) { |
|
| 335 | + } |
|
| 336 | + elseif (!$set) |
|
| 337 | + { |
|
| 275 | 338 | // backwards compatibility |
| 276 | - if (isset($GLOBALS['ADODB_SESS_DEBUG'])) { |
|
| 339 | + if (isset($GLOBALS['ADODB_SESS_DEBUG'])) |
|
| 340 | + { |
|
| 277 | 341 | return $GLOBALS['ADODB_SESS_DEBUG']; |
| 278 | 342 | } |
| 279 | 343 | } |
@@ -283,16 +347,21 @@ discard block |
||
| 283 | 347 | |
| 284 | 348 | /*! |
| 285 | 349 | */ |
| 286 | - function expireNotify($expire_notify = null) { |
|
| 350 | + function expireNotify($expire_notify = null) |
|
| 351 | + { |
|
| 287 | 352 | static $_expire_notify; |
| 288 | 353 | static $set = false; |
| 289 | 354 | |
| 290 | - if (!is_null($expire_notify)) { |
|
| 355 | + if (!is_null($expire_notify)) |
|
| 356 | + { |
|
| 291 | 357 | $_expire_notify = $expire_notify; |
| 292 | 358 | $set = true; |
| 293 | - } elseif (!$set) { |
|
| 359 | + } |
|
| 360 | + elseif (!$set) |
|
| 361 | + { |
|
| 294 | 362 | // backwards compatibility |
| 295 | - if (isset($GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY'])) { |
|
| 363 | + if (isset($GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY'])) |
|
| 364 | + { |
|
| 296 | 365 | return $GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY']; |
| 297 | 366 | } |
| 298 | 367 | } |
@@ -302,16 +371,21 @@ discard block |
||
| 302 | 371 | |
| 303 | 372 | /*! |
| 304 | 373 | */ |
| 305 | - function table($table = null) { |
|
| 374 | + function table($table = null) |
|
| 375 | + { |
|
| 306 | 376 | static $_table = 'sessions'; |
| 307 | 377 | static $set = false; |
| 308 | 378 | |
| 309 | - if (!is_null($table)) { |
|
| 379 | + if (!is_null($table)) |
|
| 380 | + { |
|
| 310 | 381 | $_table = trim($table); |
| 311 | 382 | $set = true; |
| 312 | - } elseif (!$set) { |
|
| 383 | + } |
|
| 384 | + elseif (!$set) |
|
| 385 | + { |
|
| 313 | 386 | // backwards compatibility |
| 314 | - if (isset($GLOBALS['ADODB_SESSION_TBL'])) { |
|
| 387 | + if (isset($GLOBALS['ADODB_SESSION_TBL'])) |
|
| 388 | + { |
|
| 315 | 389 | return $GLOBALS['ADODB_SESSION_TBL']; |
| 316 | 390 | } |
| 317 | 391 | } |
@@ -321,16 +395,21 @@ discard block |
||
| 321 | 395 | |
| 322 | 396 | /*! |
| 323 | 397 | */ |
| 324 | - function optimize($optimize = null) { |
|
| 398 | + function optimize($optimize = null) |
|
| 399 | + { |
|
| 325 | 400 | static $_optimize = false; |
| 326 | 401 | static $set = false; |
| 327 | 402 | |
| 328 | - if (!is_null($optimize)) { |
|
| 403 | + if (!is_null($optimize)) |
|
| 404 | + { |
|
| 329 | 405 | $_optimize = (bool) $optimize; |
| 330 | 406 | $set = true; |
| 331 | - } elseif (!$set) { |
|
| 407 | + } |
|
| 408 | + elseif (!$set) |
|
| 409 | + { |
|
| 332 | 410 | // backwards compatibility |
| 333 | - if (defined('ADODB_SESSION_OPTIMIZE')) { |
|
| 411 | + if (defined('ADODB_SESSION_OPTIMIZE')) |
|
| 412 | + { |
|
| 334 | 413 | return true; |
| 335 | 414 | } |
| 336 | 415 | } |
@@ -340,16 +419,21 @@ discard block |
||
| 340 | 419 | |
| 341 | 420 | /*! |
| 342 | 421 | */ |
| 343 | - function syncSeconds($sync_seconds = null) { |
|
| 422 | + function syncSeconds($sync_seconds = null) |
|
| 423 | + { |
|
| 344 | 424 | static $_sync_seconds = 60; |
| 345 | 425 | static $set = false; |
| 346 | 426 | |
| 347 | - if (!is_null($sync_seconds)) { |
|
| 427 | + if (!is_null($sync_seconds)) |
|
| 428 | + { |
|
| 348 | 429 | $_sync_seconds = (int) $sync_seconds; |
| 349 | 430 | $set = true; |
| 350 | - } elseif (!$set) { |
|
| 431 | + } |
|
| 432 | + elseif (!$set) |
|
| 433 | + { |
|
| 351 | 434 | // backwards compatibility |
| 352 | - if (defined('ADODB_SESSION_SYNCH_SECS')) { |
|
| 435 | + if (defined('ADODB_SESSION_SYNCH_SECS')) |
|
| 436 | + { |
|
| 353 | 437 | return ADODB_SESSION_SYNCH_SECS; |
| 354 | 438 | } |
| 355 | 439 | } |
@@ -359,16 +443,21 @@ discard block |
||
| 359 | 443 | |
| 360 | 444 | /*! |
| 361 | 445 | */ |
| 362 | - function clob($clob = null) { |
|
| 446 | + function clob($clob = null) |
|
| 447 | + { |
|
| 363 | 448 | static $_clob = false; |
| 364 | 449 | static $set = false; |
| 365 | 450 | |
| 366 | - if (!is_null($clob)) { |
|
| 451 | + if (!is_null($clob)) |
|
| 452 | + { |
|
| 367 | 453 | $_clob = strtolower(trim($clob)); |
| 368 | 454 | $set = true; |
| 369 | - } elseif (!$set) { |
|
| 455 | + } |
|
| 456 | + elseif (!$set) |
|
| 457 | + { |
|
| 370 | 458 | // backwards compatibility |
| 371 | - if (isset($GLOBALS['ADODB_SESSION_USE_LOBS'])) { |
|
| 459 | + if (isset($GLOBALS['ADODB_SESSION_USE_LOBS'])) |
|
| 460 | + { |
|
| 372 | 461 | return $GLOBALS['ADODB_SESSION_USE_LOBS']; |
| 373 | 462 | } |
| 374 | 463 | } |
@@ -378,10 +467,12 @@ discard block |
||
| 378 | 467 | |
| 379 | 468 | /*! |
| 380 | 469 | */ |
| 381 | - function dataFieldName($data_field_name = null) { |
|
| 470 | + function dataFieldName($data_field_name = null) |
|
| 471 | + { |
|
| 382 | 472 | static $_data_field_name = 'data'; |
| 383 | 473 | |
| 384 | - if (!is_null($data_field_name)) { |
|
| 474 | + if (!is_null($data_field_name)) |
|
| 475 | + { |
|
| 385 | 476 | $_data_field_name = trim($data_field_name); |
| 386 | 477 | } |
| 387 | 478 | |
@@ -390,11 +481,14 @@ discard block |
||
| 390 | 481 | |
| 391 | 482 | /*! |
| 392 | 483 | */ |
| 393 | - function filter($filter = null) { |
|
| 484 | + function filter($filter = null) |
|
| 485 | + { |
|
| 394 | 486 | static $_filter = array(); |
| 395 | 487 | |
| 396 | - if (!is_null($filter)) { |
|
| 397 | - if (!is_array($filter)) { |
|
| 488 | + if (!is_null($filter)) |
|
| 489 | + { |
|
| 490 | + if (!is_array($filter)) |
|
| 491 | + { |
|
| 398 | 492 | $filter = array($filter); |
| 399 | 493 | } |
| 400 | 494 | $_filter = $filter; |
@@ -405,10 +499,12 @@ discard block |
||
| 405 | 499 | |
| 406 | 500 | /*! |
| 407 | 501 | */ |
| 408 | - function encryptionKey($encryption_key = null) { |
|
| 502 | + function encryptionKey($encryption_key = null) |
|
| 503 | + { |
|
| 409 | 504 | static $_encryption_key = 'CRYPTED ADODB SESSIONS ROCK!'; |
| 410 | 505 | |
| 411 | - if (!is_null($encryption_key)) { |
|
| 506 | + if (!is_null($encryption_key)) |
|
| 507 | + { |
|
| 412 | 508 | $_encryption_key = $encryption_key; |
| 413 | 509 | } |
| 414 | 510 | |
@@ -427,10 +523,12 @@ discard block |
||
| 427 | 523 | |
| 428 | 524 | /*! |
| 429 | 525 | */ |
| 430 | - function _crc($crc = null) { |
|
| 526 | + function _crc($crc = null) |
|
| 527 | + { |
|
| 431 | 528 | static $_crc = false; |
| 432 | 529 | |
| 433 | - if (!is_null($crc)) { |
|
| 530 | + if (!is_null($crc)) |
|
| 531 | + { |
|
| 434 | 532 | $_crc = $crc; |
| 435 | 533 | } |
| 436 | 534 | |
@@ -439,7 +537,8 @@ discard block |
||
| 439 | 537 | |
| 440 | 538 | /*! |
| 441 | 539 | */ |
| 442 | - function _init() { |
|
| 540 | + function _init() |
|
| 541 | + { |
|
| 443 | 542 | session_module_name('user'); |
| 444 | 543 | session_set_save_handler( |
| 445 | 544 | array('ADODB_Session', 'open'), |
@@ -454,7 +553,8 @@ discard block |
||
| 454 | 553 | |
| 455 | 554 | /*! |
| 456 | 555 | */ |
| 457 | - function _sessionKey() { |
|
| 556 | + function _sessionKey() |
|
| 557 | + { |
|
| 458 | 558 | // use this function to create the encryption key for crypted sessions |
| 459 | 559 | // crypt the used key, ADODB_Session::encryptionKey() as key and session_id() as salt |
| 460 | 560 | return crypt(ADODB_Session::encryptionKey(), session_id()); |
@@ -462,26 +562,31 @@ discard block |
||
| 462 | 562 | |
| 463 | 563 | /*! |
| 464 | 564 | */ |
| 465 | - function _dumprs($rs) { |
|
| 565 | + function _dumprs($rs) |
|
| 566 | + { |
|
| 466 | 567 | $conn =& ADODB_Session::_conn(); |
| 467 | 568 | $debug = ADODB_Session::debug(); |
| 468 | 569 | |
| 469 | - if (!$conn) { |
|
| 570 | + if (!$conn) |
|
| 571 | + { |
|
| 470 | 572 | return; |
| 471 | 573 | } |
| 472 | 574 | |
| 473 | - if (!$debug) { |
|
| 575 | + if (!$debug) |
|
| 576 | + { |
|
| 474 | 577 | return; |
| 475 | 578 | } |
| 476 | 579 | |
| 477 | - if (!$rs) { |
|
| 580 | + if (!$rs) |
|
| 581 | + { |
|
| 478 | 582 | echo "<br />\$rs is null or false<br />\n"; |
| 479 | 583 | return; |
| 480 | 584 | } |
| 481 | 585 | |
| 482 | 586 | //echo "<br />\nAffected_Rows=",$conn->Affected_Rows(),"<br />\n"; |
| 483 | 587 | |
| 484 | - if (!is_object($rs)) { |
|
| 588 | + if (!is_object($rs)) |
|
| 589 | + { |
|
| 485 | 590 | return; |
| 486 | 591 | } |
| 487 | 592 | |
@@ -498,10 +603,12 @@ discard block |
||
| 498 | 603 | |
| 499 | 604 | If $conn already exists, reuse that connection |
| 500 | 605 | */ |
| 501 | - function open($save_path, $session_name, $persist = null) { |
|
| 606 | + function open($save_path, $session_name, $persist = null) |
|
| 607 | + { |
|
| 502 | 608 | $conn =& ADODB_Session::_conn(); |
| 503 | 609 | |
| 504 | - if ($conn) { |
|
| 610 | + if ($conn) |
|
| 611 | + { |
|
| 505 | 612 | return true; |
| 506 | 613 | } |
| 507 | 614 | |
@@ -512,9 +619,12 @@ discard block |
||
| 512 | 619 | $password = ADODB_Session::password(); |
| 513 | 620 | $user = ADODB_Session::user(); |
| 514 | 621 | |
| 515 | - if (!is_null($persist)) { |
|
| 622 | + if (!is_null($persist)) |
|
| 623 | + { |
|
| 516 | 624 | ADODB_Session::persist($persist); |
| 517 | - } else { |
|
| 625 | + } |
|
| 626 | + else |
|
| 627 | + { |
|
| 518 | 628 | $persist = ADODB_Session::persist(); |
| 519 | 629 | } |
| 520 | 630 | |
@@ -526,25 +636,34 @@ discard block |
||
| 526 | 636 | // cannot use =& below - do not know why... |
| 527 | 637 | $conn =& ADONewConnection($driver); |
| 528 | 638 | |
| 529 | - if ($debug) { |
|
| 639 | + if ($debug) |
|
| 640 | + { |
|
| 530 | 641 | $conn->debug = true; |
| 531 | 642 | // ADOConnection::outp( " driver=$driver user=$user pwd=$password db=$database "); |
| 532 | 643 | } |
| 533 | 644 | |
| 534 | - if ($persist) { |
|
| 535 | - switch($persist) { |
|
| 645 | + if ($persist) |
|
| 646 | + { |
|
| 647 | + switch($persist) |
|
| 648 | + { |
|
| 536 | 649 | default: |
| 537 | 650 | case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; |
| 538 | 651 | case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; |
| 539 | 652 | case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; |
| 540 | 653 | } |
| 541 | - } else { |
|
| 654 | + } |
|
| 655 | + else |
|
| 656 | + { |
|
| 542 | 657 | $ok = $conn->Connect($host, $user, $password, $database); |
| 543 | 658 | } |
| 544 | 659 | |
| 545 | - if ($ok) $GLOBALS['ADODB_SESS_CONN'] =& $conn; |
|
| 546 | - else |
|
| 547 | - ADOConnection::outp('<p>Session: connection failed</p>', false); |
|
| 660 | + if ($ok) |
|
| 661 | + { |
|
| 662 | + $GLOBALS['ADODB_SESS_CONN'] =& $conn; |
|
| 663 | + } |
|
| 664 | + else { |
|
| 665 | + ADOConnection::outp('<p>Session: connection failed</p>', false); |
|
| 666 | + } |
|
| 548 | 667 | |
| 549 | 668 | |
| 550 | 669 | return $ok; |
@@ -553,7 +672,8 @@ discard block |
||
| 553 | 672 | /*! |
| 554 | 673 | Close the connection |
| 555 | 674 | */ |
| 556 | - function close() { |
|
| 675 | + function close() |
|
| 676 | + { |
|
| 557 | 677 | /* |
| 558 | 678 | $conn =& ADODB_Session::_conn(); |
| 559 | 679 | if ($conn) $conn->Close(); |
@@ -564,13 +684,15 @@ discard block |
||
| 564 | 684 | /* |
| 565 | 685 | Slurp in the session variables and return the serialized string |
| 566 | 686 | */ |
| 567 | - function read($key) { |
|
| 687 | + function read($key) |
|
| 688 | + { |
|
| 568 | 689 | $conn =& ADODB_Session::_conn(); |
| 569 | 690 | $data = ADODB_Session::dataFieldName(); |
| 570 | 691 | $filter = ADODB_Session::filter(); |
| 571 | 692 | $table = ADODB_Session::table(); |
| 572 | 693 | |
| 573 | - if (!$conn) { |
|
| 694 | + if (!$conn) |
|
| 695 | + { |
|
| 574 | 696 | return ''; |
| 575 | 697 | } |
| 576 | 698 | |
@@ -589,14 +711,20 @@ discard block |
||
| 589 | 711 | |
| 590 | 712 | $rs =& $conn->Execute($sql); |
| 591 | 713 | //ADODB_Session::_dumprs($rs); |
| 592 | - if ($rs) { |
|
| 593 | - if ($rs->EOF) { |
|
| 714 | + if ($rs) |
|
| 715 | + { |
|
| 716 | + if ($rs->EOF) |
|
| 717 | + { |
|
| 594 | 718 | $v = ''; |
| 595 | - } else { |
|
| 719 | + } |
|
| 720 | + else |
|
| 721 | + { |
|
| 596 | 722 | $v = reset($rs->fields); |
| 597 | 723 | $filter = array_reverse($filter); |
| 598 | - foreach ($filter as $f) { |
|
| 599 | - if (is_object($f)) { |
|
| 724 | + foreach ($filter as $f) |
|
| 725 | + { |
|
| 726 | + if (is_object($f)) |
|
| 727 | + { |
|
| 600 | 728 | $v = $f->read($v, ADODB_Session::_sessionKey()); |
| 601 | 729 | } |
| 602 | 730 | } |
@@ -617,7 +745,8 @@ discard block |
||
| 617 | 745 | |
| 618 | 746 | If the data has not been modified since the last read(), we do not write. |
| 619 | 747 | */ |
| 620 | - function write($key, $val) { |
|
| 748 | + function write($key, $val) |
|
| 749 | + { |
|
| 621 | 750 | $clob = ADODB_Session::clob(); |
| 622 | 751 | $conn =& ADODB_Session::_conn(); |
| 623 | 752 | $crc = ADODB_Session::_crc(); |
@@ -629,7 +758,8 @@ discard block |
||
| 629 | 758 | $lifetime = ADODB_Session::lifetime(); |
| 630 | 759 | $table = ADODB_Session::table(); |
| 631 | 760 | |
| 632 | - if (!$conn) { |
|
| 761 | + if (!$conn) |
|
| 762 | + { |
|
| 633 | 763 | return false; |
| 634 | 764 | } |
| 635 | 765 | $qkey = $conn->qstr($key); |
@@ -642,41 +772,53 @@ discard block |
||
| 642 | 772 | |
| 643 | 773 | // crc32 optimization since adodb 2.1 |
| 644 | 774 | // now we only update expiry date, thx to sebastian thom in adodb 2.32 |
| 645 | - if ($crc !== false && $crc == (strlen($val) . crc32($val))) { |
|
| 646 | - if ($debug) { |
|
| 775 | + if ($crc !== false && $crc == (strlen($val) . crc32($val))) |
|
| 776 | + { |
|
| 777 | + if ($debug) |
|
| 778 | + { |
|
| 647 | 779 | echo '<p>Session: Only updating date - crc32 not changed</p>'; |
| 648 | 780 | } |
| 649 | 781 | $sql = "UPDATE $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2'); |
| 650 | 782 | $rs =& $conn->Execute($sql,array($expiry,$key,time())); |
| 651 | 783 | ADODB_Session::_dumprs($rs); |
| 652 | - if ($rs) { |
|
| 784 | + if ($rs) |
|
| 785 | + { |
|
| 653 | 786 | $rs->Close(); |
| 654 | 787 | } |
| 655 | 788 | return true; |
| 656 | 789 | } |
| 657 | 790 | $val = rawurlencode($val); |
| 658 | - foreach ($filter as $f) { |
|
| 659 | - if (is_object($f)) { |
|
| 791 | + foreach ($filter as $f) |
|
| 792 | + { |
|
| 793 | + if (is_object($f)) |
|
| 794 | + { |
|
| 660 | 795 | $val = $f->write($val, ADODB_Session::_sessionKey()); |
| 661 | 796 | } |
| 662 | 797 | } |
| 663 | 798 | |
| 664 | 799 | $arr = array('sesskey' => $key, 'expiry' => $expiry, $data => $val, 'expireref' => ''); |
| 665 | - if ($expire_notify) { |
|
| 800 | + if ($expire_notify) |
|
| 801 | + { |
|
| 666 | 802 | $var = reset($expire_notify); |
| 667 | 803 | global $$var; |
| 668 | - if (isset($$var)) { |
|
| 804 | + if (isset($$var)) |
|
| 805 | + { |
|
| 669 | 806 | $arr['expireref'] = $$var; |
| 670 | 807 | } |
| 671 | 808 | } |
| 672 | 809 | |
| 673 | - if (!$clob) { // no lobs, simply use replace() |
|
| 810 | + if (!$clob) |
|
| 811 | + { |
|
| 812 | +// no lobs, simply use replace() |
|
| 674 | 813 | $arr[$data] = $conn->qstr($val); |
| 675 | 814 | $rs = $conn->Replace($table, $arr, 'sesskey', $autoQuote = true); |
| 676 | 815 | ADODB_Session::_dumprs($rs); |
| 677 | - } else { |
|
| 816 | + } |
|
| 817 | + else |
|
| 818 | + { |
|
| 678 | 819 | // what value shall we insert/update for lob row? |
| 679 | - switch ($driver) { |
|
| 820 | + switch ($driver) |
|
| 821 | + { |
|
| 680 | 822 | // empty_clob or empty_lob for oracle dbs |
| 681 | 823 | case 'oracle': |
| 682 | 824 | case 'oci8': |
@@ -694,46 +836,59 @@ discard block |
||
| 694 | 836 | // do we insert or update? => as for sesskey |
| 695 | 837 | $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey"); |
| 696 | 838 | ADODB_Session::_dumprs($rs); |
| 697 | - if ($rs && reset($rs->fields) > 0) { |
|
| 839 | + if ($rs && reset($rs->fields) > 0) |
|
| 840 | + { |
|
| 698 | 841 | $sql = "UPDATE $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey"; |
| 699 | - } else { |
|
| 842 | + } |
|
| 843 | + else |
|
| 844 | + { |
|
| 700 | 845 | $sql = "INSERT INTO $table (expiry, $data, sesskey) VALUES ($expiry, $lob_value, $qkey)"; |
| 701 | 846 | } |
| 702 | - if ($rs) { |
|
| 847 | + if ($rs) |
|
| 848 | + { |
|
| 703 | 849 | $rs->Close(); |
| 704 | 850 | } |
| 705 | 851 | |
| 706 | 852 | $err = ''; |
| 707 | 853 | $rs1 =& $conn->Execute($sql); |
| 708 | 854 | ADODB_Session::_dumprs($rs1); |
| 709 | - if (!$rs1) { |
|
| 855 | + if (!$rs1) |
|
| 856 | + { |
|
| 710 | 857 | $err = $conn->ErrorMsg()."\n"; |
| 711 | 858 | } |
| 712 | 859 | $rs2 =& $conn->UpdateBlob($table, $data, $val, " sesskey=$qkey", strtoupper($clob)); |
| 713 | 860 | ADODB_Session::_dumprs($rs2); |
| 714 | - if (!$rs2) { |
|
| 861 | + if (!$rs2) |
|
| 862 | + { |
|
| 715 | 863 | $err .= $conn->ErrorMsg()."\n"; |
| 716 | 864 | } |
| 717 | 865 | $rs = ($rs && $rs2) ? true : false; |
| 718 | - if ($rs1) { |
|
| 866 | + if ($rs1) |
|
| 867 | + { |
|
| 719 | 868 | $rs1->Close(); |
| 720 | 869 | } |
| 721 | - if (is_object($rs2)) { |
|
| 870 | + if (is_object($rs2)) |
|
| 871 | + { |
|
| 722 | 872 | $rs2->Close(); |
| 723 | 873 | } |
| 724 | 874 | } |
| 725 | 875 | |
| 726 | - if (!$rs) { |
|
| 876 | + if (!$rs) |
|
| 877 | + { |
|
| 727 | 878 | ADOConnection::outp('<p>Session Replace: ' . $conn->ErrorMsg() . '</p>', false); |
| 728 | 879 | return false; |
| 729 | - } else { |
|
| 880 | + } |
|
| 881 | + else |
|
| 882 | + { |
|
| 730 | 883 | // bug in access driver (could be odbc?) means that info is not committed |
| 731 | 884 | // properly unless select statement executed in Win2000 |
| 732 | - if ($conn->databaseType == 'access') { |
|
| 885 | + if ($conn->databaseType == 'access') |
|
| 886 | + { |
|
| 733 | 887 | $sql = "SELECT sesskey FROM $table WHERE $binary sesskey = $qkey"; |
| 734 | 888 | $rs =& $conn->Execute($sql); |
| 735 | 889 | ADODB_Session::_dumprs($rs); |
| 736 | - if ($rs) { |
|
| 890 | + if ($rs) |
|
| 891 | + { |
|
| 737 | 892 | $rs->Close(); |
| 738 | 893 | } |
| 739 | 894 | } |
@@ -746,12 +901,14 @@ discard block |
||
| 746 | 901 | |
| 747 | 902 | /*! |
| 748 | 903 | */ |
| 749 | - function destroy($key) { |
|
| 904 | + function destroy($key) |
|
| 905 | + { |
|
| 750 | 906 | $conn =& ADODB_Session::_conn(); |
| 751 | 907 | $table = ADODB_Session::table(); |
| 752 | 908 | $expire_notify = ADODB_Session::expireNotify(); |
| 753 | 909 | |
| 754 | - if (!$conn) { |
|
| 910 | + if (!$conn) |
|
| 911 | + { |
|
| 755 | 912 | return false; |
| 756 | 913 | } |
| 757 | 914 | |
@@ -760,7 +917,8 @@ discard block |
||
| 760 | 917 | $qkey = $conn->quote($key); |
| 761 | 918 | $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; |
| 762 | 919 | |
| 763 | - if ($expire_notify) { |
|
| 920 | + if ($expire_notify) |
|
| 921 | + { |
|
| 764 | 922 | reset($expire_notify); |
| 765 | 923 | $fn = next($expire_notify); |
| 766 | 924 | $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); |
@@ -768,10 +926,12 @@ discard block |
||
| 768 | 926 | $rs =& $conn->Execute($sql); |
| 769 | 927 | ADODB_Session::_dumprs($rs); |
| 770 | 928 | $conn->SetFetchMode($savem); |
| 771 | - if (!$rs) { |
|
| 929 | + if (!$rs) |
|
| 930 | + { |
|
| 772 | 931 | return false; |
| 773 | 932 | } |
| 774 | - if (!$rs->EOF) { |
|
| 933 | + if (!$rs->EOF) |
|
| 934 | + { |
|
| 775 | 935 | $ref = $rs->fields[0]; |
| 776 | 936 | $key = $rs->fields[1]; |
| 777 | 937 | //assert('$ref'); |
@@ -784,7 +944,8 @@ discard block |
||
| 784 | 944 | $sql = "DELETE FROM $table WHERE $binary sesskey = $qkey"; |
| 785 | 945 | $rs =& $conn->Execute($sql); |
| 786 | 946 | ADODB_Session::_dumprs($rs); |
| 787 | - if ($rs) { |
|
| 947 | + if ($rs) |
|
| 948 | + { |
|
| 788 | 949 | $rs->Close(); |
| 789 | 950 | } |
| 790 | 951 | |
@@ -793,7 +954,8 @@ discard block |
||
| 793 | 954 | |
| 794 | 955 | /*! |
| 795 | 956 | */ |
| 796 | - function gc($maxlifetime) { |
|
| 957 | + function gc($maxlifetime) |
|
| 958 | + { |
|
| 797 | 959 | $conn =& ADODB_Session::_conn(); |
| 798 | 960 | $debug = ADODB_Session::debug(); |
| 799 | 961 | $expire_notify = ADODB_Session::expireNotify(); |
@@ -801,7 +963,8 @@ discard block |
||
| 801 | 963 | $sync_seconds = ADODB_Session::syncSeconds(); |
| 802 | 964 | $table = ADODB_Session::table(); |
| 803 | 965 | |
| 804 | - if (!$conn) { |
|
| 966 | + if (!$conn) |
|
| 967 | + { |
|
| 805 | 968 | return false; |
| 806 | 969 | } |
| 807 | 970 | |
@@ -811,7 +974,8 @@ discard block |
||
| 811 | 974 | |
| 812 | 975 | $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; |
| 813 | 976 | |
| 814 | - if ($expire_notify) { |
|
| 977 | + if ($expire_notify) |
|
| 978 | + { |
|
| 815 | 979 | reset($expire_notify); |
| 816 | 980 | $fn = next($expire_notify); |
| 817 | 981 | $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); |
@@ -819,10 +983,12 @@ discard block |
||
| 819 | 983 | $rs =& $conn->Execute($sql); |
| 820 | 984 | ADODB_Session::_dumprs($rs); |
| 821 | 985 | $conn->SetFetchMode($savem); |
| 822 | - if ($rs) { |
|
| 986 | + if ($rs) |
|
| 987 | + { |
|
| 823 | 988 | $conn->BeginTrans(); |
| 824 | 989 | $keys = array(); |
| 825 | - while (!$rs->EOF) { |
|
| 990 | + while (!$rs->EOF) |
|
| 991 | + { |
|
| 826 | 992 | $ref = $rs->fields[0]; |
| 827 | 993 | $key = $rs->fields[1]; |
| 828 | 994 | $fn($ref, $key); |
@@ -833,55 +999,70 @@ discard block |
||
| 833 | 999 | |
| 834 | 1000 | $conn->CommitTrans(); |
| 835 | 1001 | } |
| 836 | - } else { |
|
| 1002 | + } |
|
| 1003 | + else |
|
| 1004 | + { |
|
| 837 | 1005 | $sql = "DELETE FROM $table WHERE expiry < $time"; |
| 838 | 1006 | $rs =& $conn->Execute($sql); |
| 839 | 1007 | ADODB_Session::_dumprs($rs); |
| 840 | - if ($rs) { |
|
| 1008 | + if ($rs) |
|
| 1009 | + { |
|
| 841 | 1010 | $rs->Close(); |
| 842 | 1011 | } |
| 843 | - if ($debug) { |
|
| 1012 | + if ($debug) |
|
| 1013 | + { |
|
| 844 | 1014 | ADOConnection::outp("<p><b>Garbage Collection</b>: $sql</p>"); |
| 845 | 1015 | } |
| 846 | 1016 | } |
| 847 | 1017 | |
| 848 | 1018 | // suggested by Cameron, "GaM3R" <[email protected]> |
| 849 | - if ($optimize) { |
|
| 1019 | + if ($optimize) |
|
| 1020 | + { |
|
| 850 | 1021 | $driver = ADODB_Session::driver(); |
| 851 | 1022 | |
| 852 | - if (preg_match('/mysql/i', $driver)) { |
|
| 1023 | + if (preg_match('/mysql/i', $driver)) |
|
| 1024 | + { |
|
| 853 | 1025 | $sql = "OPTIMIZE TABLE $table"; |
| 854 | 1026 | } |
| 855 | - if (preg_match('/postgres/i', $driver)) { |
|
| 1027 | + if (preg_match('/postgres/i', $driver)) |
|
| 1028 | + { |
|
| 856 | 1029 | $sql = "VACUUM $table"; |
| 857 | 1030 | } |
| 858 | - if (!empty($sql)) { |
|
| 1031 | + if (!empty($sql)) |
|
| 1032 | + { |
|
| 859 | 1033 | $conn->Execute($sql); |
| 860 | 1034 | } |
| 861 | 1035 | } |
| 862 | 1036 | |
| 863 | - if ($sync_seconds) { |
|
| 1037 | + if ($sync_seconds) |
|
| 1038 | + { |
|
| 864 | 1039 | $sql = 'SELECT '; |
| 865 | - if ($conn->dataProvider === 'oci8') { |
|
| 1040 | + if ($conn->dataProvider === 'oci8') |
|
| 1041 | + { |
|
| 866 | 1042 | $sql .= "TO_CHAR({$conn->sysTimeStamp}, 'RRRR-MM-DD HH24:MI:SS')"; |
| 867 | - } else { |
|
| 1043 | + } |
|
| 1044 | + else |
|
| 1045 | + { |
|
| 868 | 1046 | $sql .= $conn->sysTimeStamp; |
| 869 | 1047 | } |
| 870 | 1048 | $sql .= " FROM $table"; |
| 871 | 1049 | |
| 872 | 1050 | $rs =& $conn->SelectLimit($sql, 1); |
| 873 | - if ($rs && !$rs->EOF) { |
|
| 1051 | + if ($rs && !$rs->EOF) |
|
| 1052 | + { |
|
| 874 | 1053 | $dbts = reset($rs->fields); |
| 875 | 1054 | $rs->Close(); |
| 876 | 1055 | $dbt = $conn->UnixTimeStamp($dbts); |
| 877 | 1056 | $t = time(); |
| 878 | 1057 | |
| 879 | - if (abs($dbt - $t) >= $sync_seconds) { |
|
| 1058 | + if (abs($dbt - $t) >= $sync_seconds) |
|
| 1059 | + { |
|
| 880 | 1060 | $msg = __FILE__ . |
| 881 | 1061 | ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: " . |
| 882 | 1062 | " database=$dbt ($dbts), webserver=$t (diff=". (abs($dbt - $t) / 60) . ' minutes)'; |
| 883 | 1063 | error_log($msg); |
| 884 | - if ($debug) { |
|
| 1064 | + if ($debug) |
|
| 1065 | + { |
|
| 885 | 1066 | ADOConnection::outp("<p>$msg</p>"); |
| 886 | 1067 | } |
| 887 | 1068 | } |
@@ -896,13 +1077,14 @@ discard block |
||
| 896 | 1077 | |
| 897 | 1078 | |
| 898 | 1079 | // for backwards compatability only |
| 899 | -function adodb_sess_open($save_path, $session_name, $persist = true) { |
|
| 1080 | +function adodb_sess_open($save_path, $session_name, $persist = true) |
|
| 1081 | +{ |
|
| 900 | 1082 | return ADODB_Session::open($save_path, $session_name, $persist); |
| 901 | 1083 | } |
| 902 | 1084 | |
| 903 | 1085 | // for backwards compatability only |
| 904 | 1086 | function adodb_sess_gc($t) |
| 905 | -{ |
|
| 1087 | +{ |
|
| 906 | 1088 | return ADODB_Session::gc($t); |
| 907 | 1089 | } |
| 908 | 1090 | |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | $qkey = $conn->quote($key); |
| 580 | 580 | $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; |
| 581 | 581 | |
| 582 | - $sql = "SELECT $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= " . time(); |
|
| 582 | + $sql = "select $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= " . time(); |
|
| 583 | 583 | /* Lock code does not work as it needs to hold transaction within whole page, and we don't know if |
| 584 | 584 | developer has commited elsewhere... :( |
| 585 | 585 | */ |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | if ($debug) { |
| 647 | 647 | echo '<p>Session: Only updating date - crc32 not changed</p>'; |
| 648 | 648 | } |
| 649 | - $sql = "UPDATE $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2'); |
|
| 649 | + $sql = "update $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2'); |
|
| 650 | 650 | $rs =& $conn->Execute($sql,array($expiry,$key,time())); |
| 651 | 651 | ADODB_Session::_dumprs($rs); |
| 652 | 652 | if ($rs) { |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey"); |
| 696 | 696 | ADODB_Session::_dumprs($rs); |
| 697 | 697 | if ($rs && reset($rs->fields) > 0) { |
| 698 | - $sql = "UPDATE $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey"; |
|
| 698 | + $sql = "update $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey"; |
|
| 699 | 699 | } else { |
| 700 | 700 | $sql = "INSERT INTO $table (expiry, $data, sesskey) VALUES ($expiry, $lob_value, $qkey)"; |
| 701 | 701 | } |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | $sql = "OPTIMIZE TABLE $table"; |
| 854 | 854 | } |
| 855 | 855 | if (preg_match('/postgres/i', $driver)) { |
| 856 | - $sql = "VACUUM $table"; |
|
| 856 | + $sql = "vacuum $table"; |
|
| 857 | 857 | } |
| 858 | 858 | if (!empty($sql)) { |
| 859 | 859 | $conn->Execute($sql); |
@@ -1,6 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // Session Encryption by Ari Kuorikoski <[email protected]> |
| 3 | 3 | class MD5Crypt{ |
| 4 | + |
|
| 5 | + /** |
|
| 6 | + * @param string $txt |
|
| 7 | + */ |
|
| 4 | 8 | function keyED($txt,$encrypt_key) |
| 5 | 9 | { |
| 6 | 10 | $encrypt_key = md5($encrypt_key); |
@@ -1,43 +1,43 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Session Encryption by Ari Kuorikoski <[email protected]> |
| 3 | -class MD5Crypt{ |
|
| 4 | - function keyED($txt,$encrypt_key) |
|
| 3 | +class MD5Crypt { |
|
| 4 | + function keyED($txt, $encrypt_key) |
|
| 5 | 5 | { |
| 6 | 6 | $encrypt_key = md5($encrypt_key); |
| 7 | - $ctr=0; |
|
| 7 | + $ctr = 0; |
|
| 8 | 8 | $tmp = ""; |
| 9 | - for ($i=0;$i<strlen($txt);$i++){ |
|
| 10 | - if ($ctr==strlen($encrypt_key)) $ctr=0; |
|
| 11 | - $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); |
|
| 9 | + for ($i = 0; $i < strlen($txt); $i++) { |
|
| 10 | + if ($ctr == strlen($encrypt_key)) $ctr = 0; |
|
| 11 | + $tmp .= substr($txt, $i, 1)^substr($encrypt_key, $ctr, 1); |
|
| 12 | 12 | $ctr++; |
| 13 | 13 | } |
| 14 | 14 | return $tmp; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - function Encrypt($txt,$key) |
|
| 17 | + function Encrypt($txt, $key) |
|
| 18 | 18 | { |
| 19 | - srand((double)microtime()*1000000); |
|
| 20 | - $encrypt_key = md5(rand(0,32000)); |
|
| 21 | - $ctr=0; |
|
| 19 | + srand((double)microtime() * 1000000); |
|
| 20 | + $encrypt_key = md5(rand(0, 32000)); |
|
| 21 | + $ctr = 0; |
|
| 22 | 22 | $tmp = ""; |
| 23 | - for ($i=0;$i<strlen($txt);$i++) |
|
| 23 | + for ($i = 0; $i < strlen($txt); $i++) |
|
| 24 | 24 | { |
| 25 | - if ($ctr==strlen($encrypt_key)) $ctr=0; |
|
| 26 | - $tmp.= substr($encrypt_key,$ctr,1) . |
|
| 27 | - (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); |
|
| 25 | + if ($ctr == strlen($encrypt_key)) $ctr = 0; |
|
| 26 | + $tmp .= substr($encrypt_key, $ctr, 1). |
|
| 27 | + (substr($txt, $i, 1)^substr($encrypt_key, $ctr, 1)); |
|
| 28 | 28 | $ctr++; |
| 29 | 29 | } |
| 30 | - return base64_encode($this->keyED($tmp,$key)); |
|
| 30 | + return base64_encode($this->keyED($tmp, $key)); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - function Decrypt($txt,$key) |
|
| 33 | + function Decrypt($txt, $key) |
|
| 34 | 34 | { |
| 35 | - $txt = $this->keyED(base64_decode($txt),$key); |
|
| 35 | + $txt = $this->keyED(base64_decode($txt), $key); |
|
| 36 | 36 | $tmp = ""; |
| 37 | - for ($i=0;$i<strlen($txt);$i++){ |
|
| 38 | - $md5 = substr($txt,$i,1); |
|
| 37 | + for ($i = 0; $i < strlen($txt); $i++) { |
|
| 38 | + $md5 = substr($txt, $i, 1); |
|
| 39 | 39 | $i++; |
| 40 | - $tmp.= (substr($txt,$i,1) ^ $md5); |
|
| 40 | + $tmp .= (substr($txt, $i, 1)^$md5); |
|
| 41 | 41 | } |
| 42 | 42 | return $tmp; |
| 43 | 43 | } |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | function RandPass() |
| 46 | 46 | { |
| 47 | 47 | $randomPassword = ""; |
| 48 | - srand((double)microtime()*1000000); |
|
| 49 | - for($i=0;$i<8;$i++) |
|
| 48 | + srand((double)microtime() * 1000000); |
|
| 49 | + for ($i = 0; $i < 8; $i++) |
|
| 50 | 50 | { |
| 51 | - $randnumber = rand(48,120); |
|
| 51 | + $randnumber = rand(48, 120); |
|
| 52 | 52 | |
| 53 | 53 | while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96)) |
| 54 | 54 | { |
| 55 | - $randnumber = rand(48,120); |
|
| 55 | + $randnumber = rand(48, 120); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $randomPassword .= chr($randnumber); |
@@ -1,13 +1,18 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Session Encryption by Ari Kuorikoski <[email protected]> |
| 3 | -class MD5Crypt{ |
|
| 3 | +class MD5Crypt |
|
| 4 | +{ |
|
| 4 | 5 | function keyED($txt,$encrypt_key) |
| 5 | 6 | { |
| 6 | 7 | $encrypt_key = md5($encrypt_key); |
| 7 | 8 | $ctr=0; |
| 8 | 9 | $tmp = ""; |
| 9 | - for ($i=0;$i<strlen($txt);$i++){ |
|
| 10 | - if ($ctr==strlen($encrypt_key)) $ctr=0; |
|
| 10 | + for ($i=0;$i<strlen($txt);$i++) |
|
| 11 | + { |
|
| 12 | + if ($ctr==strlen($encrypt_key)) |
|
| 13 | + { |
|
| 14 | + $ctr=0; |
|
| 15 | + } |
|
| 11 | 16 | $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); |
| 12 | 17 | $ctr++; |
| 13 | 18 | } |
@@ -22,7 +27,10 @@ discard block |
||
| 22 | 27 | $tmp = ""; |
| 23 | 28 | for ($i=0;$i<strlen($txt);$i++) |
| 24 | 29 | { |
| 25 | - if ($ctr==strlen($encrypt_key)) $ctr=0; |
|
| 30 | + if ($ctr==strlen($encrypt_key)) |
|
| 31 | + { |
|
| 32 | + $ctr=0; |
|
| 33 | + } |
|
| 26 | 34 | $tmp.= substr($encrypt_key,$ctr,1) . |
| 27 | 35 | (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); |
| 28 | 36 | $ctr++; |
@@ -34,7 +42,8 @@ discard block |
||
| 34 | 42 | { |
| 35 | 43 | $txt = $this->keyED(base64_decode($txt),$key); |
| 36 | 44 | $tmp = ""; |
| 37 | - for ($i=0;$i<strlen($txt);$i++){ |
|
| 45 | + for ($i=0;$i<strlen($txt);$i++) |
|
| 46 | + { |
|
| 38 | 47 | $md5 = substr($txt,$i,1); |
| 39 | 48 | $i++; |
| 40 | 49 | $tmp.= (substr($txt,$i,1) ^ $md5); |
@@ -60,6 +60,10 @@ |
||
| 60 | 60 | if ($fp) fclose($fp); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | +/** |
|
| 64 | + * @param string $sep |
|
| 65 | + * @param string $sepreplace |
|
| 66 | + */ |
|
| 63 | 67 | function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ') |
| 64 | 68 | { |
| 65 | 69 | if (!$rs) return ''; |
@@ -22,45 +22,45 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | // returns a recordset as a csv string |
| 25 | -function rs2csv(&$rs,$addtitles=true) |
|
| 25 | +function rs2csv(&$rs, $addtitles = true) |
|
| 26 | 26 | { |
| 27 | - return _adodb_export($rs,',',',',false,$addtitles); |
|
| 27 | + return _adodb_export($rs, ',', ',', false, $addtitles); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // writes recordset to csv file |
| 31 | -function rs2csvfile(&$rs,$fp,$addtitles=true) |
|
| 31 | +function rs2csvfile(&$rs, $fp, $addtitles = true) |
|
| 32 | 32 | { |
| 33 | - _adodb_export($rs,',',',',$fp,$addtitles); |
|
| 33 | + _adodb_export($rs, ',', ',', $fp, $addtitles); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | // write recordset as csv string to stdout |
| 37 | -function rs2csvout(&$rs,$addtitles=true) |
|
| 37 | +function rs2csvout(&$rs, $addtitles = true) |
|
| 38 | 38 | { |
| 39 | - $fp = fopen('php://stdout','wb'); |
|
| 40 | - _adodb_export($rs,',',',',true,$addtitles); |
|
| 39 | + $fp = fopen('php://stdout', 'wb'); |
|
| 40 | + _adodb_export($rs, ',', ',', true, $addtitles); |
|
| 41 | 41 | fclose($fp); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | -function rs2tab(&$rs,$addtitles=true) |
|
| 44 | +function rs2tab(&$rs, $addtitles = true) |
|
| 45 | 45 | { |
| 46 | - return _adodb_export($rs,"\t",',',false,$addtitles); |
|
| 46 | + return _adodb_export($rs, "\t", ',', false, $addtitles); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | // to file pointer |
| 50 | -function rs2tabfile(&$rs,$fp,$addtitles=true) |
|
| 50 | +function rs2tabfile(&$rs, $fp, $addtitles = true) |
|
| 51 | 51 | { |
| 52 | - _adodb_export($rs,"\t",',',$fp,$addtitles); |
|
| 52 | + _adodb_export($rs, "\t", ',', $fp, $addtitles); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // to stdout |
| 56 | -function rs2tabout(&$rs,$addtitles=true) |
|
| 56 | +function rs2tabout(&$rs, $addtitles = true) |
|
| 57 | 57 | { |
| 58 | - $fp = fopen('php://stdout','wb'); |
|
| 59 | - _adodb_export($rs,"\t",' ',true,$addtitles); |
|
| 58 | + $fp = fopen('php://stdout', 'wb'); |
|
| 59 | + _adodb_export($rs, "\t", ' ', true, $addtitles); |
|
| 60 | 60 | if ($fp) fclose($fp); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | -function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ') |
|
| 63 | +function _adodb_export(&$rs, $sep, $sepreplace, $fp = false, $addtitles = true, $quote = '"', $escquote = '"', $replaceNewLine = ' ') |
|
| 64 | 64 | { |
| 65 | 65 | if (!$rs) return ''; |
| 66 | 66 | //---------- |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | if ($addtitles) { |
| 74 | 74 | $fieldTypes = $rs->FieldTypesArray(); |
| 75 | 75 | reset($fieldTypes); |
| 76 | - while(list(,$o) = each($fieldTypes)) { |
|
| 76 | + while (list(,$o) = each($fieldTypes)) { |
|
| 77 | 77 | |
| 78 | 78 | $v = $o->name; |
| 79 | - if ($escquote) $v = str_replace($quote,$escquotequote,$v); |
|
| 80 | - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
|
| 79 | + if ($escquote) $v = str_replace($quote, $escquotequote, $v); |
|
| 80 | + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n", $replaceNewLine, str_replace($sep, $sepreplace, $v)))); |
|
| 81 | 81 | $elements[] = $v; |
| 82 | 82 | |
| 83 | 83 | } |
@@ -93,22 +93,22 @@ discard block |
||
| 93 | 93 | $i = 0; |
| 94 | 94 | |
| 95 | 95 | if ($hasNumIndex) { |
| 96 | - for ($j=0; $j < $max; $j++) { |
|
| 96 | + for ($j = 0; $j < $max; $j++) { |
|
| 97 | 97 | $v = $rs->fields[$j]; |
| 98 | 98 | if (!is_object($v)) $v = trim($v); |
| 99 | 99 | else $v = 'Object'; |
| 100 | - if ($escquote) $v = str_replace($quote,$escquotequote,$v); |
|
| 101 | - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
|
| 100 | + if ($escquote) $v = str_replace($quote, $escquotequote, $v); |
|
| 101 | + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n", $replaceNewLine, str_replace($sep, $sepreplace, $v)))); |
|
| 102 | 102 | |
| 103 | - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; |
|
| 103 | + if (strpos($v, $sep) !== false || strpos($v, $quote) !== false) $elements[] = "$quote$v$quote"; |
|
| 104 | 104 | else $elements[] = $v; |
| 105 | 105 | } |
| 106 | 106 | } else { // ASSOCIATIVE ARRAY |
| 107 | - foreach($rs->fields as $v) { |
|
| 108 | - if ($escquote) $v = str_replace($quote,$escquotequote,trim($v)); |
|
| 109 | - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
|
| 107 | + foreach ($rs->fields as $v) { |
|
| 108 | + if ($escquote) $v = str_replace($quote, $escquotequote, trim($v)); |
|
| 109 | + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n", $replaceNewLine, str_replace($sep, $sepreplace, $v)))); |
|
| 110 | 110 | |
| 111 | - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; |
|
| 111 | + if (strpos($v, $sep) !== false || strpos($v, $quote) !== false) $elements[] = "$quote$v$quote"; |
|
| 112 | 112 | else $elements[] = $v; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | $line += 1; |
| 118 | 118 | if ($fp && ($line % $BUFLINES) == 0) { |
| 119 | 119 | if ($fp === true) echo $s; |
| 120 | - else fwrite($fp,$s); |
|
| 120 | + else fwrite($fp, $s); |
|
| 121 | 121 | $s = ''; |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if ($fp) { |
| 126 | 126 | if ($fp === true) echo $s; |
| 127 | - else fwrite($fp,$s); |
|
| 127 | + else fwrite($fp, $s); |
|
| 128 | 128 | $s = ''; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -57,12 +57,18 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | $fp = fopen('php://stdout','wb'); |
| 59 | 59 | _adodb_export($rs,"\t",' ',true,$addtitles); |
| 60 | - if ($fp) fclose($fp); |
|
| 61 | -} |
|
| 60 | + if ($fp) |
|
| 61 | + { |
|
| 62 | + fclose($fp); |
|
| 63 | + } |
|
| 64 | + } |
|
| 62 | 65 | |
| 63 | 66 | function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ') |
| 64 | 67 | { |
| 65 | - if (!$rs) return ''; |
|
| 68 | + if (!$rs) |
|
| 69 | + { |
|
| 70 | + return ''; |
|
| 71 | + } |
|
| 66 | 72 | //---------- |
| 67 | 73 | // CONSTANTS |
| 68 | 74 | $NEWLINE = "\r\n"; |
@@ -70,13 +76,18 @@ discard block |
||
| 70 | 76 | $escquotequote = $escquote.$quote; |
| 71 | 77 | $s = ''; |
| 72 | 78 | |
| 73 | - if ($addtitles) { |
|
| 79 | + if ($addtitles) |
|
| 80 | + { |
|
| 74 | 81 | $fieldTypes = $rs->FieldTypesArray(); |
| 75 | 82 | reset($fieldTypes); |
| 76 | - while(list(,$o) = each($fieldTypes)) { |
|
| 83 | + while(list(,$o) = each($fieldTypes)) |
|
| 84 | + { |
|
| 77 | 85 | |
| 78 | 86 | $v = $o->name; |
| 79 | - if ($escquote) $v = str_replace($quote,$escquotequote,$v); |
|
| 87 | + if ($escquote) |
|
| 88 | + { |
|
| 89 | + $v = str_replace($quote,$escquotequote,$v); |
|
| 90 | + } |
|
| 80 | 91 | $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
| 81 | 92 | $elements[] = $v; |
| 82 | 93 | |
@@ -88,43 +99,83 @@ discard block |
||
| 88 | 99 | $line = 0; |
| 89 | 100 | $max = $rs->FieldCount(); |
| 90 | 101 | |
| 91 | - while (!$rs->EOF) { |
|
| 102 | + while (!$rs->EOF) |
|
| 103 | + { |
|
| 92 | 104 | $elements = array(); |
| 93 | 105 | $i = 0; |
| 94 | 106 | |
| 95 | - if ($hasNumIndex) { |
|
| 96 | - for ($j=0; $j < $max; $j++) { |
|
| 107 | + if ($hasNumIndex) |
|
| 108 | + { |
|
| 109 | + for ($j=0; $j < $max; $j++) |
|
| 110 | + { |
|
| 97 | 111 | $v = $rs->fields[$j]; |
| 98 | - if (!is_object($v)) $v = trim($v); |
|
| 99 | - else $v = 'Object'; |
|
| 100 | - if ($escquote) $v = str_replace($quote,$escquotequote,$v); |
|
| 112 | + if (!is_object($v)) |
|
| 113 | + { |
|
| 114 | + $v = trim($v); |
|
| 115 | + } |
|
| 116 | + else { |
|
| 117 | + $v = 'Object'; |
|
| 118 | + } |
|
| 119 | + if ($escquote) |
|
| 120 | + { |
|
| 121 | + $v = str_replace($quote,$escquotequote,$v); |
|
| 122 | + } |
|
| 101 | 123 | $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
| 102 | 124 | |
| 103 | - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; |
|
| 104 | - else $elements[] = $v; |
|
| 125 | + if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) |
|
| 126 | + { |
|
| 127 | + $elements[] = "$quote$v$quote"; |
|
| 128 | + } |
|
| 129 | + else { |
|
| 130 | + $elements[] = $v; |
|
| 131 | + } |
|
| 105 | 132 | } |
| 106 | - } else { // ASSOCIATIVE ARRAY |
|
| 107 | - foreach($rs->fields as $v) { |
|
| 108 | - if ($escquote) $v = str_replace($quote,$escquotequote,trim($v)); |
|
| 133 | + } |
|
| 134 | + else |
|
| 135 | + { |
|
| 136 | +// ASSOCIATIVE ARRAY |
|
| 137 | + foreach($rs->fields as $v) |
|
| 138 | + { |
|
| 139 | + if ($escquote) |
|
| 140 | + { |
|
| 141 | + $v = str_replace($quote,$escquotequote,trim($v)); |
|
| 142 | + } |
|
| 109 | 143 | $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); |
| 110 | 144 | |
| 111 | - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; |
|
| 112 | - else $elements[] = $v; |
|
| 145 | + if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) |
|
| 146 | + { |
|
| 147 | + $elements[] = "$quote$v$quote"; |
|
| 148 | + } |
|
| 149 | + else { |
|
| 150 | + $elements[] = $v; |
|
| 151 | + } |
|
| 113 | 152 | } |
| 114 | 153 | } |
| 115 | 154 | $s .= implode($sep, $elements).$NEWLINE; |
| 116 | 155 | $rs->MoveNext(); |
| 117 | 156 | $line += 1; |
| 118 | - if ($fp && ($line % $BUFLINES) == 0) { |
|
| 119 | - if ($fp === true) echo $s; |
|
| 120 | - else fwrite($fp,$s); |
|
| 157 | + if ($fp && ($line % $BUFLINES) == 0) |
|
| 158 | + { |
|
| 159 | + if ($fp === true) |
|
| 160 | + { |
|
| 161 | + echo $s; |
|
| 162 | + } |
|
| 163 | + else { |
|
| 164 | + fwrite($fp,$s); |
|
| 165 | + } |
|
| 121 | 166 | $s = ''; |
| 122 | 167 | } |
| 123 | 168 | } |
| 124 | 169 | |
| 125 | - if ($fp) { |
|
| 126 | - if ($fp === true) echo $s; |
|
| 127 | - else fwrite($fp,$s); |
|
| 170 | + if ($fp) |
|
| 171 | + { |
|
| 172 | + if ($fp === true) |
|
| 173 | + { |
|
| 174 | + echo $s; |
|
| 175 | + } |
|
| 176 | + else { |
|
| 177 | + fwrite($fp,$s); |
|
| 178 | + } |
|
| 128 | 179 | $s = ''; |
| 129 | 180 | } |
| 130 | 181 | |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | * All key of the returned array use the 'account_' prefix. |
| 361 | 361 | * For backward compatibility some values are additionaly availible without the prefix, using them is depricated! |
| 362 | 362 | * |
| 363 | - * @param int|string $id numeric account_id or string with account_lid (use of default value of 0 is depricated!!!) |
|
| 363 | + * @param integer $id numeric account_id or string with account_lid (use of default value of 0 is depricated!!!) |
|
| 364 | 364 | * @param boolean $set_depricated_names =false set _additionaly_ the depricated keys without 'account_' prefix |
| 365 | 365 | * @return array/boolean array with account data (keys: account_id, account_lid, ...) or false if account not found |
| 366 | 366 | */ |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | * - 'account_firstname','account_lastname','account_email','account_fullname','account_phone' |
| 401 | 401 | * |
| 402 | 402 | * @param int|string $id |
| 403 | - * @return string|boolean json or false if not found |
|
| 403 | + * @return string json or false if not found |
|
| 404 | 404 | */ |
| 405 | 405 | function json($id) |
| 406 | 406 | { |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | * Not all existing accounts are visible because off account_selection preference: 'none' or 'groupmembers' |
| 792 | 792 | * |
| 793 | 793 | * @param int|string $account_id nummeric account_id or account_lid |
| 794 | - * @return boolean true = account is visible, false = account not visible, null = account does not exist |
|
| 794 | + * @return null|boolean true = account is visible, false = account not visible, null = account does not exist |
|
| 795 | 795 | */ |
| 796 | 796 | function visible($account_id) |
| 797 | 797 | { |
@@ -986,7 +986,6 @@ discard block |
||
| 986 | 986 | * |
| 987 | 987 | * @param string $account_lid |
| 988 | 988 | * @param string $passwd |
| 989 | - * @param array $GLOBALS['auto_create_acct'] values for 'firstname', 'lastname', 'email' and 'primary_group' |
|
| 990 | 989 | * @return int|boolean account_id or false on error |
| 991 | 990 | */ |
| 992 | 991 | function auto_add($account_lid, $passwd) |
@@ -1106,7 +1105,7 @@ discard block |
||
| 1106 | 1105 | * |
| 1107 | 1106 | * We use now an instance-wide read-cache storing account-data and members(hips). |
| 1108 | 1107 | * |
| 1109 | - * @param int|array $account_ids user- or group-id(s) for which cache should be invalidated, default 0 = only search/name2id cache |
|
| 1108 | + * @param integer $account_ids user- or group-id(s) for which cache should be invalidated, default 0 = only search/name2id cache |
|
| 1110 | 1109 | */ |
| 1111 | 1110 | static function cache_invalidate($account_ids=0) |
| 1112 | 1111 | { |
@@ -225,13 +225,13 @@ |
||
| 225 | 225 | * @param int $accountId |
| 226 | 226 | * @deprecated |
| 227 | 227 | */ |
| 228 | - function setAccountId($accountId) |
|
| 229 | - { |
|
| 230 | - if($accountId && is_numeric($accountId)) |
|
| 231 | - { |
|
| 232 | - $this->account_id = (int)$accountId; |
|
| 233 | - } |
|
| 234 | - } |
|
| 228 | + function setAccountId($accountId) |
|
| 229 | + { |
|
| 230 | + if($accountId && is_numeric($accountId)) |
|
| 231 | + { |
|
| 232 | + $this->account_id = (int)$accountId; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | 237 | * Searches / lists accounts: users and/or groups |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @var array |
| 90 | 90 | */ |
| 91 | - var $depricated_names = array('firstname','lastname','fullname','email','type', |
|
| 92 | - 'status','expires','lastlogin','lastloginfrom','lastpasswd_change'); |
|
| 91 | + var $depricated_names = array('firstname', 'lastname', 'fullname', 'email', 'type', |
|
| 92 | + 'status', 'expires', 'lastlogin', 'lastloginfrom', 'lastpasswd_change'); |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * List of all config vars accounts depend on and therefore should be passed in when calling contructor with array syntax |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | * @var array |
| 98 | 98 | */ |
| 99 | 99 | static public $config_vars = array( |
| 100 | - 'account_repository', 'auth_type', // auth_type if fallback if account_repository is not set |
|
| 101 | - 'install_id', // instance-specific caching |
|
| 102 | - 'auto_create_expire', 'default_group_lid', // auto-creation of accounts |
|
| 103 | - 'ldap_host','ldap_root_dn','ldap_root_pw','ldap_context','ldap_group_context','ldap_search_filter', // ldap backend |
|
| 104 | - 'ads_domain', 'ads_host', 'ads_admin_user', 'ads_admin_passwd', 'ads_connection', 'ads_context', // ads backend |
|
| 100 | + 'account_repository', 'auth_type', // auth_type if fallback if account_repository is not set |
|
| 101 | + 'install_id', // instance-specific caching |
|
| 102 | + 'auto_create_expire', 'default_group_lid', // auto-creation of accounts |
|
| 103 | + 'ldap_host', 'ldap_root_dn', 'ldap_root_pw', 'ldap_context', 'ldap_group_context', 'ldap_search_filter', // ldap backend |
|
| 104 | + 'ads_domain', 'ads_host', 'ads_admin_user', 'ads_admin_passwd', 'ads_connection', 'ads_context', // ads backend |
|
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -166,23 +166,23 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @param string|array $backend =null string with backend 'sql'|'ldap', or whole config array, default read from global egw_info |
| 168 | 168 | */ |
| 169 | - public function __construct($backend=null) |
|
| 169 | + public function __construct($backend = null) |
|
| 170 | 170 | { |
| 171 | 171 | if (is_numeric($backend)) // depricated use with account_id |
| 172 | 172 | { |
| 173 | - if ((int)$backend) $this->account_id = (int) $backend; |
|
| 173 | + if ((int)$backend) $this->account_id = (int)$backend; |
|
| 174 | 174 | $backend = null; |
| 175 | 175 | } |
| 176 | 176 | if (is_array($backend)) |
| 177 | 177 | { |
| 178 | 178 | $this->config = $backend; |
| 179 | 179 | $backend = null; |
| 180 | - self::$_instance = $this; // also set instance returned by singleton |
|
| 181 | - self::$cache = array(); // and empty our internal (session) cache |
|
| 180 | + self::$_instance = $this; // also set instance returned by singleton |
|
| 181 | + self::$cache = array(); // and empty our internal (session) cache |
|
| 182 | 182 | } |
| 183 | 183 | else |
| 184 | 184 | { |
| 185 | - $this->config =& $GLOBALS['egw_info']['server']; |
|
| 185 | + $this->config = & $GLOBALS['egw_info']['server']; |
|
| 186 | 186 | |
| 187 | 187 | if (!isset(self::$_instance)) self::$_instance = $this; |
| 188 | 188 | } |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | * @param int $account_id =0 depricated param to instanciate for the given account_id |
| 213 | 213 | * @deprecated use __construct |
| 214 | 214 | */ |
| 215 | - function accounts($account_id=0) |
|
| 215 | + function accounts($account_id = 0) |
|
| 216 | 216 | { |
| 217 | - $this->account_id = (int) $account_id; |
|
| 217 | + $this->account_id = (int)$account_id; |
|
| 218 | 218 | |
| 219 | 219 | $this->__construct(); |
| 220 | 220 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | */ |
| 228 | 228 | function setAccountId($accountId) |
| 229 | 229 | { |
| 230 | - if($accountId && is_numeric($accountId)) |
|
| 230 | + if ($accountId && is_numeric($accountId)) |
|
| 231 | 231 | { |
| 232 | 232 | $this->account_id = (int)$accountId; |
| 233 | 233 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | function search($param) |
| 259 | 259 | { |
| 260 | 260 | //error_log(__METHOD__.'('.array2string($param).') '.function_backtrace()); |
| 261 | - if (!isset($param['active'])) $param['active'] = true; // default is true = only return active accounts |
|
| 261 | + if (!isset($param['active'])) $param['active'] = true; // default is true = only return active accounts |
|
| 262 | 262 | |
| 263 | 263 | self::setup_cache(); |
| 264 | 264 | $account_search = &self::$cache['account_search']; |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | } |
| 271 | 271 | // no backend understands $param['app'], only sql understands type owngroups or groupmemember[+memberships] |
| 272 | 272 | // --> do an full search first and then filter and limit that search |
| 273 | - elseif($param['app'] || $this->config['account_repository'] != 'sql' && |
|
| 274 | - in_array($param['type'], array('owngroups','groupmembers','groupmembers+memberships'))) |
|
| 273 | + elseif ($param['app'] || $this->config['account_repository'] != 'sql' && |
|
| 274 | + in_array($param['type'], array('owngroups', 'groupmembers', 'groupmembers+memberships'))) |
|
| 275 | 275 | { |
| 276 | 276 | $app = $param['app']; |
| 277 | 277 | unset($param['app']); |
@@ -283,15 +283,15 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | if ($param['type'] == 'owngroups') |
| 285 | 285 | { |
| 286 | - $members = $this->memberships($GLOBALS['egw_info']['user']['account_id'],true); |
|
| 286 | + $members = $this->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
|
| 287 | 287 | $param['type'] = 'groups'; |
| 288 | 288 | } |
| 289 | - elseif(in_array($param['type'],array('groupmembers','groupmembers+memberships'))) |
|
| 289 | + elseif (in_array($param['type'], array('groupmembers', 'groupmembers+memberships'))) |
|
| 290 | 290 | { |
| 291 | 291 | $members = array(); |
| 292 | - foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp) |
|
| 292 | + foreach ((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $grp) |
|
| 293 | 293 | { |
| 294 | - $members = array_unique(array_merge($members, (array)$this->members($grp,true,$param['active']))); |
|
| 294 | + $members = array_unique(array_merge($members, (array)$this->members($grp, true, $param['active']))); |
|
| 295 | 295 | if ($param['type'] == 'groupmembers+memberships') $members[] = $grp; |
| 296 | 296 | } |
| 297 | 297 | $param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts'; |
@@ -304,20 +304,20 @@ discard block |
||
| 304 | 304 | if ($app) |
| 305 | 305 | { |
| 306 | 306 | // we want the result merged, whatever it takes, as we only care for the ids |
| 307 | - $valid = $this->split_accounts($app,!in_array($param['type'],array('accounts','groups')) ? 'merge' : $param['type'],$param['active']); |
|
| 307 | + $valid = $this->split_accounts($app, !in_array($param['type'], array('accounts', 'groups')) ? 'merge' : $param['type'], $param['active']); |
|
| 308 | 308 | } |
| 309 | 309 | if (isset($members)) |
| 310 | 310 | { |
| 311 | 311 | //error_log(__METHOD__.'() members='.array2string($members)); |
| 312 | 312 | if (!$members) $members = array(); |
| 313 | - $valid = !$app ? $members : array_intersect($valid,$members); // use the intersection |
|
| 313 | + $valid = !$app ? $members : array_intersect($valid, $members); // use the intersection |
|
| 314 | 314 | } |
| 315 | 315 | //error_log(__METHOD__."() limiting result to app='$app' and/or group=$group valid-ids=".array2string($valid)); |
| 316 | 316 | $n = 0; |
| 317 | 317 | $account_search[$serial]['data'] = array(); |
| 318 | 318 | foreach ($full_search as $id => $data) |
| 319 | 319 | { |
| 320 | - if (!in_array($id,$valid)) |
|
| 320 | + if (!in_array($id, $valid)) |
|
| 321 | 321 | { |
| 322 | 322 | $this->total--; |
| 323 | 323 | continue; |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | $account_search[$serial]['data'] = $this->backend->search($param); |
| 338 | 338 | if ($param['type'] !== 'accounts') |
| 339 | 339 | { |
| 340 | - foreach($account_search[$serial]['data'] as &$account) |
|
| 340 | + foreach ($account_search[$serial]['data'] as &$account) |
|
| 341 | 341 | { |
| 342 | 342 | // add default description for Admins and Default group |
| 343 | 343 | if ($account['account_type'] === 'g' && empty($account['account_description'])) |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | { |
| 369 | 369 | $options['filter'] = (array)$options['filter']; |
| 370 | 370 | } |
| 371 | - switch($GLOBALS['egw_info']['user']['preferences']['common']['account_display']) |
|
| 371 | + switch ($GLOBALS['egw_info']['user']['preferences']['common']['account_display']) |
|
| 372 | 372 | { |
| 373 | 373 | case 'firstname': |
| 374 | 374 | case 'firstall': |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | } |
| 385 | 385 | $only_own = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] === 'groupmembers' && |
| 386 | 386 | !isset($GLOBALS['egw_info']['user']['apps']['admin']); |
| 387 | - switch($options['account_type']) |
|
| 387 | + switch ($options['account_type']) |
|
| 388 | 388 | { |
| 389 | 389 | case 'accounts': |
| 390 | 390 | $type = $only_own ? 'groupmembers' : 'accounts'; |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | break; |
| 404 | 404 | } |
| 405 | 405 | $accounts = array(); |
| 406 | - foreach(self::getInstance()->search(array( |
|
| 406 | + foreach (self::getInstance()->search(array( |
|
| 407 | 407 | 'type' => $options['filter']['group'] < 0 ? $options['filter']['group'] : $type, |
| 408 | 408 | 'query' => $pattern, |
| 409 | 409 | 'query_type' => 'all', |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | )) as $account) |
| 412 | 412 | { |
| 413 | 413 | $accounts[$account['account_id']] = common::display_fullname($account['account_lid'], |
| 414 | - $account['account_firstname'],$account['account_lastname'],$account['account_id']); |
|
| 414 | + $account['account_firstname'], $account['account_lastname'], $account['account_id']); |
|
| 415 | 415 | } |
| 416 | 416 | return $accounts; |
| 417 | 417 | } |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | * @param boolean $set_depricated_names =false set _additionaly_ the depricated keys without 'account_' prefix |
| 428 | 428 | * @return array/boolean array with account data (keys: account_id, account_lid, ...) or false if account not found |
| 429 | 429 | */ |
| 430 | - function read($id=0,$set_depricated_names=false) |
|
| 430 | + function read($id = 0, $set_depricated_names = false) |
|
| 431 | 431 | { |
| 432 | 432 | if (!$id) // deprecated use!!! |
| 433 | 433 | { |
@@ -449,9 +449,9 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | if ($set_depricated_names && $data) |
| 451 | 451 | { |
| 452 | - foreach($this->depricated_names as $name) |
|
| 452 | + foreach ($this->depricated_names as $name) |
|
| 453 | 453 | { |
| 454 | - $data[$name] =& $data['account_'.$name]; |
|
| 454 | + $data[$name] = & $data['account_'.$name]; |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | return $data; |
@@ -468,8 +468,8 @@ discard block |
||
| 468 | 468 | function json($id) |
| 469 | 469 | { |
| 470 | 470 | static $keys = array( |
| 471 | - 'account_id','account_lid','person_id','account_status', |
|
| 472 | - 'account_firstname','account_lastname','account_email','account_fullname','account_phone', |
|
| 471 | + 'account_id', 'account_lid', 'person_id', 'account_status', |
|
| 472 | + 'account_firstname', 'account_lastname', 'account_email', 'account_fullname', 'account_phone', |
|
| 473 | 473 | ); |
| 474 | 474 | if (($account = $this->read($id))) |
| 475 | 475 | { |
@@ -478,9 +478,9 @@ discard block |
||
| 478 | 478 | // for current user, add the apps available to him |
| 479 | 479 | if ($id == $GLOBALS['egw_info']['user']['account_id']) |
| 480 | 480 | { |
| 481 | - foreach((array)$GLOBALS['egw_info']['user']['apps'] as $app => $data) |
|
| 481 | + foreach ((array)$GLOBALS['egw_info']['user']['apps'] as $app => $data) |
|
| 482 | 482 | { |
| 483 | - unset($data['table_defs']); // no need for that on the client |
|
| 483 | + unset($data['table_defs']); // no need for that on the client |
|
| 484 | 484 | $account['apps'][$app] = $data; |
| 485 | 485 | } |
| 486 | 486 | } |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | */ |
| 495 | 495 | protected static function add_default_group_description(array &$data) |
| 496 | 496 | { |
| 497 | - switch($data['account_lid']) |
|
| 497 | + switch ($data['account_lid']) |
|
| 498 | 498 | { |
| 499 | 499 | case 'Default': |
| 500 | 500 | $data['account_description'] = lang('EGroupware all users group, do NOT delete'); |
@@ -517,15 +517,15 @@ discard block |
||
| 517 | 517 | * @param boolean $check_depricated_names =false check _additionaly_ the depricated keys without 'account_' prefix |
| 518 | 518 | * @return int|boolean the account_id or false on error |
| 519 | 519 | */ |
| 520 | - function save(&$data,$check_depricated_names=false) |
|
| 520 | + function save(&$data, $check_depricated_names = false) |
|
| 521 | 521 | { |
| 522 | 522 | if ($check_depricated_names) |
| 523 | 523 | { |
| 524 | - foreach($this->depricated_names as $name) |
|
| 524 | + foreach ($this->depricated_names as $name) |
|
| 525 | 525 | { |
| 526 | 526 | if (isset($data[$name]) && !isset($data['account_'.$name])) |
| 527 | 527 | { |
| 528 | - $data['account_'.$name] =& $data[$name]; |
|
| 528 | + $data['account_'.$name] = & $data[$name]; |
|
| 529 | 529 | } |
| 530 | 530 | } |
| 531 | 531 | } |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | { |
| 539 | 539 | // if we are not on a pure LDAP system, we have to write the account-date via the contacts class now |
| 540 | 540 | if (($this->config['account_repository'] == 'sql' || $this->config['contact_repository'] == 'sql-ldap') && |
| 541 | - (!($old = $this->read($data['account_id'])) || // only for new account or changed contact-data |
|
| 541 | + (!($old = $this->read($data['account_id'])) || // only for new account or changed contact-data |
|
| 542 | 542 | $old['account_firstname'] != $data['account_firstname'] || |
| 543 | 543 | $old['account_lastname'] != $data['account_lastname'] || |
| 544 | 544 | $old['account_email'] != $data['account_email'])) |
@@ -553,14 +553,14 @@ discard block |
||
| 553 | 553 | 'id' => $data['person_id'], |
| 554 | 554 | 'owner' => 0, |
| 555 | 555 | ); |
| 556 | - $GLOBALS['egw']->contacts->save($contact,true); // true = ignore addressbook acl |
|
| 556 | + $GLOBALS['egw']->contacts->save($contact, true); // true = ignore addressbook acl |
|
| 557 | 557 | } |
| 558 | 558 | // save primary group if necessary |
| 559 | - if ($data['account_primary_group'] && (!($memberships = $this->memberships($id,true)) || |
|
| 560 | - !in_array($data['account_primary_group'],$memberships))) |
|
| 559 | + if ($data['account_primary_group'] && (!($memberships = $this->memberships($id, true)) || |
|
| 560 | + !in_array($data['account_primary_group'], $memberships))) |
|
| 561 | 561 | { |
| 562 | 562 | $memberships[] = $data['account_primary_group']; |
| 563 | - $this->set_memberships($memberships, $id); // invalidates cache for account_id and primary group |
|
| 563 | + $this->set_memberships($memberships, $id); // invalidates cache for account_id and primary group |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | // as some backends set (group-)members in save, we need to invalidate their members too! |
@@ -616,9 +616,9 @@ discard block |
||
| 616 | 616 | * @param array $data =null array with account data, not specifying the account is depricated!!! |
| 617 | 617 | * @return boolean true=expired (no more login possible), false otherwise |
| 618 | 618 | */ |
| 619 | - function is_expired($data=null) |
|
| 619 | + function is_expired($data = null) |
|
| 620 | 620 | { |
| 621 | - if (is_null($data)) $data = $this->data; // depricated use |
|
| 621 | + if (is_null($data)) $data = $this->data; // depricated use |
|
| 622 | 622 | |
| 623 | 623 | $expires = isset($data['account_expires']) ? $data['account_expires'] : $data['expires']; |
| 624 | 624 | |
@@ -652,10 +652,10 @@ discard block |
||
| 652 | 652 | * @param string $account_type =null u = user or g = group, or default null = try both |
| 653 | 653 | * @return int|false numeric account_id or false on error ($name not found) |
| 654 | 654 | */ |
| 655 | - function name2id($name,$which='account_lid',$account_type=null) |
|
| 655 | + function name2id($name, $which = 'account_lid', $account_type = null) |
|
| 656 | 656 | { |
| 657 | 657 | // Don't bother searching for empty or non-scalar account_lid |
| 658 | - if(empty($name) || !is_scalar($name)) |
|
| 658 | + if (empty($name) || !is_scalar($name)) |
|
| 659 | 659 | { |
| 660 | 660 | return False; |
| 661 | 661 | } |
@@ -663,12 +663,12 @@ discard block |
||
| 663 | 663 | self::setup_cache(); |
| 664 | 664 | $name_list = &self::$cache['name_list']; |
| 665 | 665 | |
| 666 | - if(@isset($name_list[$which][$name]) && $name_list[$which][$name]) |
|
| 666 | + if (@isset($name_list[$which][$name]) && $name_list[$which][$name]) |
|
| 667 | 667 | { |
| 668 | 668 | return $name_list[$which][$name]; |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - return $name_list[$which][$name] = $this->backend->name2id($name,$which,$account_type); |
|
| 671 | + return $name_list[$which][$name] = $this->backend->name2id($name, $which, $account_type); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
| 681 | 681 | * @return string|boolean converted value or false on error ($account_id not found) |
| 682 | 682 | */ |
| 683 | - static function id2name($account_id, $which='account_lid') |
|
| 683 | + static function id2name($account_id, $which = 'account_lid') |
|
| 684 | 684 | { |
| 685 | 685 | if (!is_numeric($account_id) && !($account_id = self::getInstance()->name2id($account_id))) |
| 686 | 686 | { |
@@ -753,13 +753,13 @@ discard block |
||
| 753 | 753 | $account_lid != $GLOBALS['egw_info']['user']['account_lid'] || |
| 754 | 754 | // only allow group-members for account-selection is groupmembers |
| 755 | 755 | $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && |
| 756 | - !array_intersect((array)$this->memberships($account_id,true), |
|
| 757 | - (array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true)))) |
|
| 756 | + !array_intersect((array)$this->memberships($account_id, true), |
|
| 757 | + (array)$this->memberships($GLOBALS['egw_info']['user']['account_id'], true)))) |
|
| 758 | 758 | { |
| 759 | 759 | //error_log(__METHOD__."($account_id='$account_lid') returning FALSE"); |
| 760 | - return false; // user is not allowed to see given account |
|
| 760 | + return false; // user is not allowed to see given account |
|
| 761 | 761 | } |
| 762 | - return true; // user allowed to see given account |
|
| 762 | + return true; // user allowed to see given account |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -769,11 +769,11 @@ discard block |
||
| 769 | 769 | * @param boolean $just_id =false return just account_id's or account_id => account_lid pairs |
| 770 | 770 | * @return array with account_id's ($just_id) or account_id => account_lid pairs (!$just_id) |
| 771 | 771 | */ |
| 772 | - function memberships($account_id, $just_id=false) |
|
| 772 | + function memberships($account_id, $just_id = false) |
|
| 773 | 773 | { |
| 774 | 774 | if (!is_int($account_id) && !is_numeric($account_id)) |
| 775 | 775 | { |
| 776 | - $account_id = $this->name2id($account_id,'account_lid','u'); |
|
| 776 | + $account_id = $this->name2id($account_id, 'account_lid', 'u'); |
|
| 777 | 777 | } |
| 778 | 778 | if ($account_id && ($data = self::cache_read($account_id))) |
| 779 | 779 | { |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | * @param array $groups array with gidnumbers |
| 790 | 790 | * @param int $account_id uidnumber |
| 791 | 791 | */ |
| 792 | - function set_memberships($groups,$account_id) |
|
| 792 | + function set_memberships($groups, $account_id) |
|
| 793 | 793 | { |
| 794 | 794 | //echo "<p>accounts::set_memberships(".print_r($groups,true).",$account_id)</p>\n"; |
| 795 | 795 | if (!is_int($account_id) && !is_numeric($account_id)) |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | * @param boolean $active =false true: return only active (not expired or deactived) members, false: return all accounts |
| 819 | 819 | * @return array with account_id ($just_id) or account_id => account_lid pairs (!$just_id) |
| 820 | 820 | */ |
| 821 | - function members($account_id, $just_id=false, $active=true) |
|
| 821 | + function members($account_id, $just_id = false, $active = true) |
|
| 822 | 822 | { |
| 823 | 823 | if (!is_int($account_id) && !is_numeric($account_id)) |
| 824 | 824 | { |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | * @param array $members array with uidnumber or uid's |
| 840 | 840 | * @param int $gid gidnumber of group to set |
| 841 | 841 | */ |
| 842 | - function set_members($members,$gid) |
|
| 842 | + function set_members($members, $gid) |
|
| 843 | 843 | { |
| 844 | 844 | //echo "<p>accounts::set_members(".print_r($members,true).",$gid)</p>\n"; |
| 845 | 845 | if (($old_members = $this->members($gid, true, false)) != $members) |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | * @param boolean $active =false true: return only active (not expired or deactived) members, false: return all accounts |
| 865 | 865 | * @return array/boolean see $use, false on error (wront $use) |
| 866 | 866 | */ |
| 867 | - function split_accounts($app_users,$use='both',$active=true) |
|
| 867 | + function split_accounts($app_users, $use = 'both', $active = true) |
|
| 868 | 868 | { |
| 869 | 869 | if (!is_array($app_users)) |
| 870 | 870 | { |
@@ -875,21 +875,21 @@ discard block |
||
| 875 | 875 | { |
| 876 | 876 | return $cache; |
| 877 | 877 | } |
| 878 | - $app_users = $GLOBALS['egw']->acl->get_ids_for_location('run',1,$app_users); |
|
| 878 | + $app_users = $GLOBALS['egw']->acl->get_ids_for_location('run', 1, $app_users); |
|
| 879 | 879 | } |
| 880 | 880 | $accounts = array( |
| 881 | 881 | 'accounts' => array(), |
| 882 | 882 | 'groups' => array(), |
| 883 | 883 | ); |
| 884 | - foreach($app_users as $id) |
|
| 884 | + foreach ($app_users as $id) |
|
| 885 | 885 | { |
| 886 | 886 | $type = $this->get_type($id); |
| 887 | - if($type == 'g') |
|
| 887 | + if ($type == 'g') |
|
| 888 | 888 | { |
| 889 | 889 | $accounts['groups'][$id] = $id; |
| 890 | 890 | if ($use != 'groups') |
| 891 | 891 | { |
| 892 | - foreach((array)$this->members($id, true, $active) as $id) |
|
| 892 | + foreach ((array)$this->members($id, true, $active) as $id) |
|
| 893 | 893 | { |
| 894 | 894 | $accounts['accounts'][$id] = $id; |
| 895 | 895 | } |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | } |
| 912 | 912 | //echo "<p>accounts::split_accounts(".print_r($app_users,True).",'$use') = <pre>".print_r($accounts,True)."</pre>\n"; |
| 913 | 913 | |
| 914 | - switch($use) |
|
| 914 | + switch ($use) |
|
| 915 | 915 | { |
| 916 | 916 | case 'both': |
| 917 | 917 | return $accounts; |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | case 'accounts': |
| 921 | 921 | return $accounts['accounts']; |
| 922 | 922 | case 'merge': |
| 923 | - return array_merge($accounts['accounts'],$accounts['groups']); |
|
| 923 | + return array_merge($accounts['accounts'], $accounts['groups']); |
|
| 924 | 924 | } |
| 925 | 925 | return False; |
| 926 | 926 | } |
@@ -938,21 +938,20 @@ discard block |
||
| 938 | 938 | function auto_add($account_lid, $passwd) |
| 939 | 939 | { |
| 940 | 940 | $expires = !isset($this->config['auto_create_expire']) || |
| 941 | - $this->config['auto_create_expire'] == 'never' ? -1 : |
|
| 942 | - time() + $this->config['auto_create_expire'] + 2; |
|
| 941 | + $this->config['auto_create_expire'] == 'never' ? -1 : time() + $this->config['auto_create_expire'] + 2; |
|
| 943 | 942 | |
| 944 | 943 | $memberships = array(); |
| 945 | 944 | $default_group_id = null; |
| 946 | 945 | // check if we have a comma or semicolon delimited list of groups --> add first as primary and rest as memberships |
| 947 | - foreach(preg_split('/[,;] */',$this->config['default_group_lid']) as $group_lid) |
|
| 946 | + foreach (preg_split('/[,;] */', $this->config['default_group_lid']) as $group_lid) |
|
| 948 | 947 | { |
| 949 | - if (($group_id = $this->name2id($group_lid,'account_lid','g'))) |
|
| 948 | + if (($group_id = $this->name2id($group_lid, 'account_lid', 'g'))) |
|
| 950 | 949 | { |
| 951 | 950 | if (!$default_group_id) $default_group_id = $group_id; |
| 952 | 951 | $memberships[] = $group_id; |
| 953 | 952 | } |
| 954 | 953 | } |
| 955 | - if (!$default_group_id && ($default_group_id = $this->name2id('Default','account_lid','g'))) |
|
| 954 | + if (!$default_group_id && ($default_group_id = $this->name2id('Default', 'account_lid', 'g'))) |
|
| 956 | 955 | { |
| 957 | 956 | $memberships[] = $default_group_id; |
| 958 | 957 | } |
@@ -989,25 +988,25 @@ discard block |
||
| 989 | 988 | // set memberships if given |
| 990 | 989 | if ($memberships) |
| 991 | 990 | { |
| 992 | - $this->set_memberships($memberships,$data['account_id']); |
|
| 991 | + $this->set_memberships($memberships, $data['account_id']); |
|
| 993 | 992 | } |
| 994 | 993 | // set the appropriate value for the can change password flag (assume users can, if the admin requires users to change their password) |
| 995 | 994 | $data['changepassword'] = (bool)$GLOBALS['egw_info']['server']['change_pwd_every_x_days']; |
| 996 | - if(!$data['changepassword']) |
|
| 995 | + if (!$data['changepassword']) |
|
| 997 | 996 | { |
| 998 | - $GLOBALS['egw']->acl->add_repository('preferences','nopasswordchange',$data['account_id'],1); |
|
| 997 | + $GLOBALS['egw']->acl->add_repository('preferences', 'nopasswordchange', $data['account_id'], 1); |
|
| 999 | 998 | } |
| 1000 | 999 | else |
| 1001 | 1000 | { |
| 1002 | - $GLOBALS['egw']->acl->delete_repository('preferences','nopasswordchange',$data['account_id']); |
|
| 1001 | + $GLOBALS['egw']->acl->delete_repository('preferences', 'nopasswordchange', $data['account_id']); |
|
| 1003 | 1002 | } |
| 1004 | 1003 | // call hook to notify interested apps about the new account |
| 1005 | 1004 | $GLOBALS['hook_values'] = $data; |
| 1006 | - $GLOBALS['egw']->hooks->process($data+array( |
|
| 1005 | + $GLOBALS['egw']->hooks->process($data + array( |
|
| 1007 | 1006 | 'location' => 'addaccount', |
| 1008 | 1007 | // at login-time only the hooks from the following apps will be called |
| 1009 | - 'order' => array('felamimail','fudforum'), |
|
| 1010 | - ),False,True); // called for every app now, not only enabled ones |
|
| 1008 | + 'order' => array('felamimail', 'fudforum'), |
|
| 1009 | + ), False, True); // called for every app now, not only enabled ones |
|
| 1011 | 1010 | unset($data['changepassword']); |
| 1012 | 1011 | |
| 1013 | 1012 | return $data['account_id']; |
@@ -1054,14 +1053,14 @@ discard block |
||
| 1054 | 1053 | * |
| 1055 | 1054 | * @param int|array $account_ids user- or group-id(s) for which cache should be invalidated, default 0 = only search/name2id cache |
| 1056 | 1055 | */ |
| 1057 | - static function cache_invalidate($account_ids=0) |
|
| 1056 | + static function cache_invalidate($account_ids = 0) |
|
| 1058 | 1057 | { |
| 1059 | 1058 | //error_log(__METHOD__.'('.array2string($account_ids).')'); |
| 1060 | 1059 | |
| 1061 | 1060 | // instance-wide cache |
| 1062 | 1061 | if ($account_ids) |
| 1063 | 1062 | { |
| 1064 | - foreach((array)$account_ids as $account_id) |
|
| 1063 | + foreach ((array)$account_ids as $account_id) |
|
| 1065 | 1064 | { |
| 1066 | 1065 | $instance = self::getInstance(); |
| 1067 | 1066 | |
@@ -1073,11 +1072,11 @@ discard block |
||
| 1073 | 1072 | |
| 1074 | 1073 | // session-cache |
| 1075 | 1074 | if (self::$cache) self::$cache = array(); |
| 1076 | - egw_cache::unsetSession('accounts_cache','phpgwapi'); |
|
| 1075 | + egw_cache::unsetSession('accounts_cache', 'phpgwapi'); |
|
| 1077 | 1076 | |
| 1078 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 1077 | + if (method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 1079 | 1078 | { |
| 1080 | - egw::invalidate_session_cache(); // invalidates whole egw-enviroment if stored in the session |
|
| 1079 | + egw::invalidate_session_cache(); // invalidates whole egw-enviroment if stored in the session |
|
| 1081 | 1080 | } |
| 1082 | 1081 | } |
| 1083 | 1082 | |
@@ -1101,11 +1100,11 @@ discard block |
||
| 1101 | 1100 | * @return array |
| 1102 | 1101 | * @throws egw_exception_wrong_parameter if no integer was passed as $account_id |
| 1103 | 1102 | */ |
| 1104 | - static function cache_read($account_id, $need_active=false) |
|
| 1103 | + static function cache_read($account_id, $need_active = false) |
|
| 1105 | 1104 | { |
| 1106 | 1105 | if (!is_numeric($account_id)) throw new egw_exception_wrong_parameter('Not an integer!'); |
| 1107 | 1106 | |
| 1108 | - $account =& self::$request_cache[$account_id]; |
|
| 1107 | + $account = & self::$request_cache[$account_id]; |
|
| 1109 | 1108 | |
| 1110 | 1109 | if (!isset($account)) // not in request cache --> try instance cache |
| 1111 | 1110 | { |
@@ -1136,7 +1135,7 @@ discard block |
||
| 1136 | 1135 | { |
| 1137 | 1136 | $instance = self::getInstance(); |
| 1138 | 1137 | $account['members-active'] = array(); |
| 1139 | - foreach((array)$account['members'] as $id => $lid) |
|
| 1138 | + foreach ((array)$account['members'] as $id => $lid) |
|
| 1140 | 1139 | { |
| 1141 | 1140 | if ($instance->is_active($id)) $account['members-active'][$id] = $lid; |
| 1142 | 1141 | } |
@@ -1162,11 +1161,11 @@ discard block |
||
| 1162 | 1161 | */ |
| 1163 | 1162 | private static function setup_cache() |
| 1164 | 1163 | { |
| 1165 | - if (is_array(self::$cache)) return; // cache is already setup |
|
| 1164 | + if (is_array(self::$cache)) return; // cache is already setup |
|
| 1166 | 1165 | |
| 1167 | 1166 | if (self::$use_session_cache && is_object($GLOBALS['egw']->session)) |
| 1168 | 1167 | { |
| 1169 | - self::$cache =& egw_cache::getSession('accounts_cache','phpgwapi'); |
|
| 1168 | + self::$cache = & egw_cache::getSession('accounts_cache', 'phpgwapi'); |
|
| 1170 | 1169 | //echo "<p>restoring cache from session, ".count(call_user_func_array('array_merge',(array)self::$cache))." items</p>\n"; |
| 1171 | 1170 | } |
| 1172 | 1171 | //error_log(__METHOD__."() use_session_cache=".array2string(self::$use_session_cache).", is_array(self::\$cache)=".array2string(is_array(self::$cache))); |
@@ -1200,7 +1199,7 @@ discard block |
||
| 1200 | 1199 | */ |
| 1201 | 1200 | function read_repository() |
| 1202 | 1201 | { |
| 1203 | - return $this->data = $this->account_id ? $this->read($this->account_id,true) : array(); |
|
| 1202 | + return $this->data = $this->account_id ? $this->read($this->account_id, true) : array(); |
|
| 1204 | 1203 | } |
| 1205 | 1204 | |
| 1206 | 1205 | /** |
@@ -1210,7 +1209,7 @@ discard block |
||
| 1210 | 1209 | */ |
| 1211 | 1210 | function save_repository() |
| 1212 | 1211 | { |
| 1213 | - $this->save($this->data,true); |
|
| 1212 | + $this->save($this->data, true); |
|
| 1214 | 1213 | } |
| 1215 | 1214 | |
| 1216 | 1215 | /** |
@@ -1218,7 +1217,7 @@ discard block |
||
| 1218 | 1217 | * |
| 1219 | 1218 | * @deprecated use search |
| 1220 | 1219 | */ |
| 1221 | - function get_list($_type='both',$start = null,$sort = '', $order = '', $query = '', $offset = null,$query_type='') |
|
| 1220 | + function get_list($_type = 'both', $start = null, $sort = '', $order = '', $query = '', $offset = null, $query_type = '') |
|
| 1222 | 1221 | { |
| 1223 | 1222 | if (is_array($_type)) // XML-RPC |
| 1224 | 1223 | { |
@@ -1231,7 +1230,7 @@ discard block |
||
| 1231 | 1230 | 'sort' => $sort, |
| 1232 | 1231 | 'query' => $query, |
| 1233 | 1232 | 'offset' => $offset, |
| 1234 | - 'query_type' => $query_type , |
|
| 1233 | + 'query_type' => $query_type, |
|
| 1235 | 1234 | ))); |
| 1236 | 1235 | } |
| 1237 | 1236 | |
@@ -1243,9 +1242,9 @@ discard block |
||
| 1243 | 1242 | * @param booelan $default_prefs =true has no meaning any more, as we use "real" default prefs since 1.0 |
| 1244 | 1243 | * @return int new nummeric account-id |
| 1245 | 1244 | */ |
| 1246 | - function create($account_info,$default_prefs=True) |
|
| 1245 | + function create($account_info, $default_prefs = True) |
|
| 1247 | 1246 | { |
| 1248 | - unset($default_prefs); // not used, but required by function signature |
|
| 1247 | + unset($default_prefs); // not used, but required by function signature |
|
| 1249 | 1248 | return $this->save($account_info); |
| 1250 | 1249 | } |
| 1251 | 1250 | |
@@ -1278,7 +1277,7 @@ discard block |
||
| 1278 | 1277 | return $memberships; |
| 1279 | 1278 | } |
| 1280 | 1279 | $old = array(); |
| 1281 | - foreach($memberships as $id => $lid) |
|
| 1280 | + foreach ($memberships as $id => $lid) |
|
| 1282 | 1281 | { |
| 1283 | 1282 | $old[] = array('account_id' => $id, 'account_name' => $lid); |
| 1284 | 1283 | } |
@@ -1301,7 +1300,7 @@ discard block |
||
| 1301 | 1300 | return $members; |
| 1302 | 1301 | } |
| 1303 | 1302 | $old = array(); |
| 1304 | - foreach($members as $uid => $lid) |
|
| 1303 | + foreach ($members as $uid => $lid) |
|
| 1305 | 1304 | { |
| 1306 | 1305 | $old[] = array('account_id' => $uid, 'account_name' => $lid); |
| 1307 | 1306 | } |
@@ -1335,7 +1334,7 @@ discard block |
||
| 1335 | 1334 | * @param string &$lname on return: last name |
| 1336 | 1335 | * @return boolean true if $accountid was found, false otherwise |
| 1337 | 1336 | */ |
| 1338 | - function get_account_name($accountid,&$lid,&$fname,&$lname) |
|
| 1337 | + function get_account_name($accountid, &$lid, &$fname, &$lname) |
|
| 1339 | 1338 | { |
| 1340 | 1339 | if (!($data = $this->read($accountid))) return false; |
| 1341 | 1340 | |
@@ -168,9 +168,12 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | public function __construct($backend=null) |
| 170 | 170 | { |
| 171 | - if (is_numeric($backend)) // depricated use with account_id |
|
| 171 | + if (is_numeric($backend)) |
|
| 172 | + { |
|
| 173 | + // depricated use with account_id |
|
| 172 | 174 | { |
| 173 | 175 | if ((int)$backend) $this->account_id = (int) $backend; |
| 176 | + } |
|
| 174 | 177 | $backend = null; |
| 175 | 178 | } |
| 176 | 179 | if (is_array($backend)) |
@@ -184,7 +187,10 @@ discard block |
||
| 184 | 187 | { |
| 185 | 188 | $this->config =& $GLOBALS['egw_info']['server']; |
| 186 | 189 | |
| 187 | - if (!isset(self::$_instance)) self::$_instance = $this; |
|
| 190 | + if (!isset(self::$_instance)) |
|
| 191 | + { |
|
| 192 | + self::$_instance = $this; |
|
| 193 | + } |
|
| 188 | 194 | } |
| 189 | 195 | if (is_null($backend)) |
| 190 | 196 | { |
@@ -258,7 +264,11 @@ discard block |
||
| 258 | 264 | function search($param) |
| 259 | 265 | { |
| 260 | 266 | //error_log(__METHOD__.'('.array2string($param).') '.function_backtrace()); |
| 261 | - if (!isset($param['active'])) $param['active'] = true; // default is true = only return active accounts |
|
| 267 | + if (!isset($param['active'])) |
|
| 268 | + { |
|
| 269 | + $param['active'] = true; |
|
| 270 | + } |
|
| 271 | + // default is true = only return active accounts |
|
| 262 | 272 | |
| 263 | 273 | self::setup_cache(); |
| 264 | 274 | $account_search = &self::$cache['account_search']; |
@@ -292,7 +302,10 @@ discard block |
||
| 292 | 302 | foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp) |
| 293 | 303 | { |
| 294 | 304 | $members = array_unique(array_merge($members, (array)$this->members($grp,true,$param['active']))); |
| 295 | - if ($param['type'] == 'groupmembers+memberships') $members[] = $grp; |
|
| 305 | + if ($param['type'] == 'groupmembers+memberships') |
|
| 306 | + { |
|
| 307 | + $members[] = $grp; |
|
| 308 | + } |
|
| 296 | 309 | } |
| 297 | 310 | $param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts'; |
| 298 | 311 | } |
@@ -309,7 +322,10 @@ discard block |
||
| 309 | 322 | if (isset($members)) |
| 310 | 323 | { |
| 311 | 324 | //error_log(__METHOD__.'() members='.array2string($members)); |
| 312 | - if (!$members) $members = array(); |
|
| 325 | + if (!$members) |
|
| 326 | + { |
|
| 327 | + $members = array(); |
|
| 328 | + } |
|
| 313 | 329 | $valid = !$app ? $members : array_intersect($valid,$members); // use the intersection |
| 314 | 330 | } |
| 315 | 331 | //error_log(__METHOD__."() limiting result to app='$app' and/or group=$group valid-ids=".array2string($valid)); |
@@ -429,15 +445,21 @@ discard block |
||
| 429 | 445 | */ |
| 430 | 446 | function read($id=0,$set_depricated_names=false) |
| 431 | 447 | { |
| 432 | - if (!$id) // deprecated use!!! |
|
| 448 | + if (!$id) |
|
| 449 | + { |
|
| 450 | + // deprecated use!!! |
|
| 433 | 451 | { |
| 434 | 452 | return $this->data ? $this->data : $this->read_repository(); |
| 435 | 453 | } |
| 454 | + } |
|
| 436 | 455 | if (!is_int($id) && !is_numeric($id)) |
| 437 | 456 | { |
| 438 | 457 | $id = $this->name2id($id); |
| 439 | 458 | } |
| 440 | - if (!$id) return false; |
|
| 459 | + if (!$id) |
|
| 460 | + { |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 441 | 463 | |
| 442 | 464 | $data = self::cache_read($id); |
| 443 | 465 | |
@@ -543,7 +565,10 @@ discard block |
||
| 543 | 565 | $old['account_lastname'] != $data['account_lastname'] || |
| 544 | 566 | $old['account_email'] != $data['account_email'])) |
| 545 | 567 | { |
| 546 | - if (!$data['person_id']) $data['person_id'] = $old['person_id']; |
|
| 568 | + if (!$data['person_id']) |
|
| 569 | + { |
|
| 570 | + $data['person_id'] = $old['person_id']; |
|
| 571 | + } |
|
| 547 | 572 | |
| 548 | 573 | $contact = array( |
| 549 | 574 | 'n_given' => $data['account_firstname'], |
@@ -583,7 +608,10 @@ discard block |
||
| 583 | 608 | { |
| 584 | 609 | $id = $this->name2id($id); |
| 585 | 610 | } |
| 586 | - if (!$id) return false; |
|
| 611 | + if (!$id) |
|
| 612 | + { |
|
| 613 | + return false; |
|
| 614 | + } |
|
| 587 | 615 | |
| 588 | 616 | if ($this->get_type($id) == 'u') |
| 589 | 617 | { |
@@ -618,7 +646,11 @@ discard block |
||
| 618 | 646 | */ |
| 619 | 647 | function is_expired($data=null) |
| 620 | 648 | { |
| 621 | - if (is_null($data)) $data = $this->data; // depricated use |
|
| 649 | + if (is_null($data)) |
|
| 650 | + { |
|
| 651 | + $data = $this->data; |
|
| 652 | + } |
|
| 653 | + // depricated use |
|
| 622 | 654 | |
| 623 | 655 | $expires = isset($data['account_expires']) ? $data['account_expires'] : $data['expires']; |
| 624 | 656 | |
@@ -635,7 +667,10 @@ discard block |
||
| 635 | 667 | */ |
| 636 | 668 | function is_active($data) |
| 637 | 669 | { |
| 638 | - if (!is_array($data)) $data = $this->read($data); |
|
| 670 | + if (!is_array($data)) |
|
| 671 | + { |
|
| 672 | + $data = $this->read($data); |
|
| 673 | + } |
|
| 639 | 674 | |
| 640 | 675 | return $data && !(self::is_expired($data) || $data['account_status'] != 'A'); |
| 641 | 676 | } |
@@ -687,7 +722,10 @@ discard block |
||
| 687 | 722 | return false; |
| 688 | 723 | } |
| 689 | 724 | try { |
| 690 | - if (!($data = self::cache_read($account_id))) return false; |
|
| 725 | + if (!($data = self::cache_read($account_id))) |
|
| 726 | + { |
|
| 727 | + return false; |
|
| 728 | + } |
|
| 691 | 729 | } |
| 692 | 730 | catch (Exception $e) { |
| 693 | 731 | unset($e); |
@@ -738,14 +776,23 @@ discard block |
||
| 738 | 776 | */ |
| 739 | 777 | function visible($account_id) |
| 740 | 778 | { |
| 741 | - if (!is_numeric($account_id)) // account_lid given |
|
| 779 | + if (!is_numeric($account_id)) |
|
| 780 | + { |
|
| 781 | + // account_lid given |
|
| 742 | 782 | { |
| 743 | 783 | $account_lid = $account_id; |
| 744 | - if (!($account_id = $this->name2id($account_lid))) return null; |
|
| 784 | + } |
|
| 785 | + if (!($account_id = $this->name2id($account_lid))) |
|
| 786 | + { |
|
| 787 | + return null; |
|
| 788 | + } |
|
| 745 | 789 | } |
| 746 | 790 | else |
| 747 | 791 | { |
| 748 | - if (!($account_lid = $this->id2name($account_id))) return null; |
|
| 792 | + if (!($account_lid = $this->id2name($account_id))) |
|
| 793 | + { |
|
| 794 | + return null; |
|
| 795 | + } |
|
| 749 | 796 | } |
| 750 | 797 | if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) && |
| 751 | 798 | // do NOT allow other user, if account-selection is none |
@@ -800,7 +847,10 @@ discard block |
||
| 800 | 847 | { |
| 801 | 848 | $this->backend->set_memberships($groups, $account_id); |
| 802 | 849 | |
| 803 | - if (!$old_memberships) $old_memberships = array(); |
|
| 850 | + if (!$old_memberships) |
|
| 851 | + { |
|
| 852 | + $old_memberships = array(); |
|
| 853 | + } |
|
| 804 | 854 | self::cache_invalidate(array_unique(array_merge( |
| 805 | 855 | array($account_id), |
| 806 | 856 | array_diff($old_memberships, $groups), |
@@ -948,7 +998,10 @@ discard block |
||
| 948 | 998 | { |
| 949 | 999 | if (($group_id = $this->name2id($group_lid,'account_lid','g'))) |
| 950 | 1000 | { |
| 951 | - if (!$default_group_id) $default_group_id = $group_id; |
|
| 1001 | + if (!$default_group_id) |
|
| 1002 | + { |
|
| 1003 | + $default_group_id = $group_id; |
|
| 1004 | + } |
|
| 952 | 1005 | $memberships[] = $group_id; |
| 953 | 1006 | } |
| 954 | 1007 | } |
@@ -1033,7 +1086,10 @@ discard block |
||
| 1033 | 1086 | function change_account_lid_allowed() |
| 1034 | 1087 | { |
| 1035 | 1088 | $change_account_lid = constant(get_class($this->backend).'::CHANGE_ACCOUNT_LID'); |
| 1036 | - if (!isset($change_account_lid)) $change_account_lid = true; |
|
| 1089 | + if (!isset($change_account_lid)) |
|
| 1090 | + { |
|
| 1091 | + $change_account_lid = true; |
|
| 1092 | + } |
|
| 1037 | 1093 | return $change_account_lid; |
| 1038 | 1094 | } |
| 1039 | 1095 | |
@@ -1072,12 +1128,19 @@ discard block |
||
| 1072 | 1128 | } |
| 1073 | 1129 | |
| 1074 | 1130 | // session-cache |
| 1075 | - if (self::$cache) self::$cache = array(); |
|
| 1131 | + if (self::$cache) |
|
| 1132 | + { |
|
| 1133 | + self::$cache = array(); |
|
| 1134 | + } |
|
| 1076 | 1135 | egw_cache::unsetSession('accounts_cache','phpgwapi'); |
| 1077 | 1136 | |
| 1078 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 1137 | + if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 1079 | 1138 | { |
| 1080 | - egw::invalidate_session_cache(); // invalidates whole egw-enviroment if stored in the session |
|
| 1139 | + // egw object in setup is limited |
|
| 1140 | + { |
|
| 1141 | + egw::invalidate_session_cache(); |
|
| 1142 | + } |
|
| 1143 | + // invalidates whole egw-enviroment if stored in the session |
|
| 1081 | 1144 | } |
| 1082 | 1145 | } |
| 1083 | 1146 | |
@@ -1103,27 +1166,39 @@ discard block |
||
| 1103 | 1166 | */ |
| 1104 | 1167 | static function cache_read($account_id, $need_active=false) |
| 1105 | 1168 | { |
| 1106 | - if (!is_numeric($account_id)) throw new egw_exception_wrong_parameter('Not an integer!'); |
|
| 1169 | + if (!is_numeric($account_id)) |
|
| 1170 | + { |
|
| 1171 | + throw new egw_exception_wrong_parameter('Not an integer!'); |
|
| 1172 | + } |
|
| 1107 | 1173 | |
| 1108 | 1174 | $account =& self::$request_cache[$account_id]; |
| 1109 | 1175 | |
| 1110 | - if (!isset($account)) // not in request cache --> try instance cache |
|
| 1176 | + if (!isset($account)) |
|
| 1177 | + { |
|
| 1178 | + // not in request cache --> try instance cache |
|
| 1111 | 1179 | { |
| 1112 | 1180 | $instance = self::getInstance(); |
| 1181 | + } |
|
| 1113 | 1182 | |
| 1114 | 1183 | $account = egw_cache::getCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id); |
| 1115 | 1184 | |
| 1116 | - if (!isset($account)) // not in instance cache --> read from backend |
|
| 1185 | + if (!isset($account)) |
|
| 1186 | + { |
|
| 1187 | + // not in instance cache --> read from backend |
|
| 1117 | 1188 | { |
| 1118 | 1189 | if (($account = $instance->backend->read($account_id))) |
| 1119 | 1190 | { |
| 1120 | 1191 | if ($instance->get_type($account_id) == 'u') |
| 1121 | 1192 | { |
| 1122 | 1193 | if (!isset($account['memberships'])) $account['memberships'] = $instance->backend->memberships($account_id); |
| 1194 | + } |
|
| 1123 | 1195 | } |
| 1124 | 1196 | else |
| 1125 | 1197 | { |
| 1126 | - if (!isset($account['members'])) $account['members'] = $instance->backend->members($account_id); |
|
| 1198 | + if (!isset($account['members'])) |
|
| 1199 | + { |
|
| 1200 | + $account['members'] = $instance->backend->members($account_id); |
|
| 1201 | + } |
|
| 1127 | 1202 | } |
| 1128 | 1203 | egw_cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT); |
| 1129 | 1204 | } |
@@ -1138,7 +1213,10 @@ discard block |
||
| 1138 | 1213 | $account['members-active'] = array(); |
| 1139 | 1214 | foreach((array)$account['members'] as $id => $lid) |
| 1140 | 1215 | { |
| 1141 | - if ($instance->is_active($id)) $account['members-active'][$id] = $lid; |
|
| 1216 | + if ($instance->is_active($id)) |
|
| 1217 | + { |
|
| 1218 | + $account['members-active'][$id] = $lid; |
|
| 1219 | + } |
|
| 1142 | 1220 | } |
| 1143 | 1221 | egw_cache::setCache($instance->config['install_id'], __CLASS__, 'account-'.$account_id, $account, self::READ_CACHE_TIMEOUT); |
| 1144 | 1222 | } |
@@ -1162,7 +1240,11 @@ discard block |
||
| 1162 | 1240 | */ |
| 1163 | 1241 | private static function setup_cache() |
| 1164 | 1242 | { |
| 1165 | - if (is_array(self::$cache)) return; // cache is already setup |
|
| 1243 | + if (is_array(self::$cache)) |
|
| 1244 | + { |
|
| 1245 | + return; |
|
| 1246 | + } |
|
| 1247 | + // cache is already setup |
|
| 1166 | 1248 | |
| 1167 | 1249 | if (self::$use_session_cache && is_object($GLOBALS['egw']->session)) |
| 1168 | 1250 | { |
@@ -1220,10 +1302,13 @@ discard block |
||
| 1220 | 1302 | */ |
| 1221 | 1303 | function get_list($_type='both',$start = null,$sort = '', $order = '', $query = '', $offset = null,$query_type='') |
| 1222 | 1304 | { |
| 1223 | - if (is_array($_type)) // XML-RPC |
|
| 1305 | + if (is_array($_type)) |
|
| 1306 | + { |
|
| 1307 | + // XML-RPC |
|
| 1224 | 1308 | { |
| 1225 | 1309 | return array_values($this->search($_type)); |
| 1226 | 1310 | } |
| 1311 | + } |
|
| 1227 | 1312 | return array_values($this->search(array( |
| 1228 | 1313 | 'type' => $_type, |
| 1229 | 1314 | 'start' => $start, |
@@ -1337,14 +1422,23 @@ discard block |
||
| 1337 | 1422 | */ |
| 1338 | 1423 | function get_account_name($accountid,&$lid,&$fname,&$lname) |
| 1339 | 1424 | { |
| 1340 | - if (!($data = $this->read($accountid))) return false; |
|
| 1425 | + if (!($data = $this->read($accountid))) |
|
| 1426 | + { |
|
| 1427 | + return false; |
|
| 1428 | + } |
|
| 1341 | 1429 | |
| 1342 | 1430 | $lid = $data['account_lid']; |
| 1343 | 1431 | $fname = $data['account_firstname']; |
| 1344 | 1432 | $lname = $data['account_lastname']; |
| 1345 | 1433 | |
| 1346 | - if (empty($fname)) $fname = $lid; |
|
| 1347 | - if (empty($lname)) $lname = $this->get_type($accountid) == 'g' ? lang('Group') : lang('user'); |
|
| 1434 | + if (empty($fname)) |
|
| 1435 | + { |
|
| 1436 | + $fname = $lid; |
|
| 1437 | + } |
|
| 1438 | + if (empty($lname)) |
|
| 1439 | + { |
|
| 1440 | + $lname = $this->get_type($accountid) == 'g' ? lang('Group') : lang('user'); |
|
| 1441 | + } |
|
| 1348 | 1442 | |
| 1349 | 1443 | return true; |
| 1350 | 1444 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | /** |
| 130 | 130 | * Factory method and singelton to get adLDAP object for given configuration or default server config |
| 131 | 131 | * |
| 132 | - * @param array $config=null values for keys 'ads_domain', 'ads_host' (required) and optional 'ads_admin_user', 'ads_admin_passwd', 'ads_connection' |
|
| 132 | + * @param array $config values for keys 'ads_domain', 'ads_host' (required) and optional 'ads_admin_user', 'ads_admin_passwd', 'ads_connection' |
|
| 133 | 133 | * @return adLDAP |
| 134 | 134 | * @throws adLDAPException |
| 135 | 135 | */ |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | * |
| 1139 | 1139 | * @param int $_account_id |
| 1140 | 1140 | * @param string $ip |
| 1141 | - * @return int lastlogin time |
|
| 1141 | + * @return boolean lastlogin time |
|
| 1142 | 1142 | */ |
| 1143 | 1143 | function update_lastlogin($_account_id, $ip) |
| 1144 | 1144 | { |
@@ -1335,7 +1335,7 @@ discard block |
||
| 1335 | 1335 | * - activate user |
| 1336 | 1336 | * |
| 1337 | 1337 | * @param array $attributes The attributes to set to the user account |
| 1338 | - * @return bool |
|
| 1338 | + * @return string|boolean |
|
| 1339 | 1339 | */ |
| 1340 | 1340 | public function create($attributes) |
| 1341 | 1341 | { |
@@ -1525,7 +1525,7 @@ discard block |
||
| 1525 | 1525 | * @param string $username The username to query |
| 1526 | 1526 | * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
| 1527 | 1527 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 1528 | - * @return bool |
|
| 1528 | + * @return string|boolean |
|
| 1529 | 1529 | */ |
| 1530 | 1530 | public function modify($username, $attributes, $isGUID = false) |
| 1531 | 1531 | { |
@@ -1590,7 +1590,7 @@ discard block |
||
| 1590 | 1590 | * Extended to allow to specify $attribute["container"] as string, because array hardcodes "OU=", while Samba4 and win2008r2 uses "CN=Users" |
| 1591 | 1591 | * |
| 1592 | 1592 | * @param array $attributes Default attributes of the group |
| 1593 | - * @return bool |
|
| 1593 | + * @return string|boolean |
|
| 1594 | 1594 | */ |
| 1595 | 1595 | public function create($attributes) |
| 1596 | 1596 | { |
@@ -803,11 +803,11 @@ discard block |
||
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | /** |
| 806 | - * Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000 |
|
| 807 | - * |
|
| 808 | - * @param long $unixTime |
|
| 809 | - * @return long windowsTime |
|
| 810 | - */ |
|
| 806 | + * Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000 |
|
| 807 | + * |
|
| 808 | + * @param long $unixTime |
|
| 809 | + * @return long windowsTime |
|
| 810 | + */ |
|
| 811 | 811 | public static function convertUnixTimeToWindowsTime($unixTime) |
| 812 | 812 | { |
| 813 | 813 | return ($unixTime + 11644477200) * 10000000; |
@@ -1260,10 +1260,10 @@ discard block |
||
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | /** |
| 1263 | - * Convert 8bit characters e.g. accented characters to UTF8 encoded characters |
|
| 1264 | - * |
|
| 1265 | - * Extended to use mbstring to convert from arbitrary charset to utf-8 |
|
| 1266 | - */ |
|
| 1263 | + * Convert 8bit characters e.g. accented characters to UTF8 encoded characters |
|
| 1264 | + * |
|
| 1265 | + * Extended to use mbstring to convert from arbitrary charset to utf-8 |
|
| 1266 | + */ |
|
| 1267 | 1267 | protected function encode8Bit(&$item, $key) |
| 1268 | 1268 | { |
| 1269 | 1269 | if ($this->charset != 'utf-8' && $key != 'password') |
@@ -1291,29 +1291,29 @@ discard block |
||
| 1291 | 1291 | return $this->userClass; |
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | - /** |
|
| 1295 | - * Get the group class interface |
|
| 1296 | - * |
|
| 1297 | - * @return adLDAPGroups |
|
| 1298 | - */ |
|
| 1299 | - public function group() { |
|
| 1300 | - if (!$this->groupClass) { |
|
| 1301 | - $this->groupClass = new adLDAPGroups_egw($this); |
|
| 1302 | - } |
|
| 1303 | - return $this->groupClass; |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * Get the utils class interface |
|
| 1308 | - * |
|
| 1309 | - * @return adLDAPUtils |
|
| 1310 | - */ |
|
| 1311 | - public function utilities() { |
|
| 1312 | - if (!$this->utilClass) { |
|
| 1313 | - $this->utilClass = new adLDAPUtils_egw($this); |
|
| 1314 | - } |
|
| 1315 | - return $this->utilClass; |
|
| 1316 | - } |
|
| 1294 | + /** |
|
| 1295 | + * Get the group class interface |
|
| 1296 | + * |
|
| 1297 | + * @return adLDAPGroups |
|
| 1298 | + */ |
|
| 1299 | + public function group() { |
|
| 1300 | + if (!$this->groupClass) { |
|
| 1301 | + $this->groupClass = new adLDAPGroups_egw($this); |
|
| 1302 | + } |
|
| 1303 | + return $this->groupClass; |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * Get the utils class interface |
|
| 1308 | + * |
|
| 1309 | + * @return adLDAPUtils |
|
| 1310 | + */ |
|
| 1311 | + public function utilities() { |
|
| 1312 | + if (!$this->utilClass) { |
|
| 1313 | + $this->utilClass = new adLDAPUtils_egw($this); |
|
| 1314 | + } |
|
| 1315 | + return $this->utilClass; |
|
| 1316 | + } |
|
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | 1319 | /** |
@@ -1402,45 +1402,45 @@ discard block |
||
| 1402 | 1402 | return true; |
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | - /** |
|
| 1406 | - * Encode a password for transmission over LDAP |
|
| 1407 | - * |
|
| 1408 | - * Extended to use mbstring to convert from arbitrary charset to UTF-16LE |
|
| 1409 | - * |
|
| 1410 | - * @param string $password The password to encode |
|
| 1411 | - * @return string |
|
| 1412 | - */ |
|
| 1413 | - public function encodePassword($password) |
|
| 1414 | - { |
|
| 1415 | - $password="\"".$password."\""; |
|
| 1416 | - if (function_exists('mb_convert_encoding')) |
|
| 1417 | - { |
|
| 1418 | - return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
|
| 1419 | - } |
|
| 1420 | - $encoded=""; |
|
| 1421 | - for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
| 1422 | - return $encoded; |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - /** |
|
| 1426 | - * Set a password |
|
| 1427 | - * |
|
| 1428 | - * Requires "Reset password" priviledges from bind user! |
|
| 1429 | - * |
|
| 1405 | + /** |
|
| 1406 | + * Encode a password for transmission over LDAP |
|
| 1407 | + * |
|
| 1408 | + * Extended to use mbstring to convert from arbitrary charset to UTF-16LE |
|
| 1409 | + * |
|
| 1410 | + * @param string $password The password to encode |
|
| 1411 | + * @return string |
|
| 1412 | + */ |
|
| 1413 | + public function encodePassword($password) |
|
| 1414 | + { |
|
| 1415 | + $password="\"".$password."\""; |
|
| 1416 | + if (function_exists('mb_convert_encoding')) |
|
| 1417 | + { |
|
| 1418 | + return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
|
| 1419 | + } |
|
| 1420 | + $encoded=""; |
|
| 1421 | + for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
| 1422 | + return $encoded; |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + /** |
|
| 1426 | + * Set a password |
|
| 1427 | + * |
|
| 1428 | + * Requires "Reset password" priviledges from bind user! |
|
| 1429 | + * |
|
| 1430 | 1430 | * We can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2! |
| 1431 | 1431 | * |
| 1432 | - * @param string $dn |
|
| 1433 | - * @param string $password |
|
| 1434 | - * @return boolean |
|
| 1435 | - */ |
|
| 1436 | - public function setPassword($dn, $password) |
|
| 1437 | - { |
|
| 1438 | - $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
|
| 1439 | - 'unicodePwd' => $this->encodePassword($password), |
|
| 1440 | - )); |
|
| 1441 | - if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
|
| 1442 | - return $result; |
|
| 1443 | - } |
|
| 1432 | + * @param string $dn |
|
| 1433 | + * @param string $password |
|
| 1434 | + * @return boolean |
|
| 1435 | + */ |
|
| 1436 | + public function setPassword($dn, $password) |
|
| 1437 | + { |
|
| 1438 | + $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
|
| 1439 | + 'unicodePwd' => $this->encodePassword($password), |
|
| 1440 | + )); |
|
| 1441 | + if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
|
| 1442 | + return $result; |
|
| 1443 | + } |
|
| 1444 | 1444 | |
| 1445 | 1445 | /** |
| 1446 | 1446 | * Check if we can to a real password change, not just a password reset |
@@ -1454,30 +1454,30 @@ discard block |
||
| 1454 | 1454 | return function_exists('ldap_modify_batch'); |
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | - /** |
|
| 1458 | - * Set the password of a user - This must be performed over SSL |
|
| 1459 | - * |
|
| 1460 | - * @param string $username The username to modify |
|
| 1461 | - * @param string $password The new password |
|
| 1462 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 1463 | - * @param string $old_password old password for password change, if supported |
|
| 1464 | - * @return bool |
|
| 1465 | - */ |
|
| 1466 | - public function password($username, $password, $isGUID = false, $old_password=null) |
|
| 1467 | - { |
|
| 1468 | - if ($username === NULL) { return false; } |
|
| 1469 | - if ($password === NULL) { return false; } |
|
| 1470 | - if (!$this->adldap->getLdapBind()) { return false; } |
|
| 1471 | - if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
| 1472 | - throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
|
| 1473 | - } |
|
| 1474 | - |
|
| 1475 | - $userDn = $this->dn($username, $isGUID); |
|
| 1476 | - if ($userDn === false) { |
|
| 1477 | - return false; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - $add=array(); |
|
| 1457 | + /** |
|
| 1458 | + * Set the password of a user - This must be performed over SSL |
|
| 1459 | + * |
|
| 1460 | + * @param string $username The username to modify |
|
| 1461 | + * @param string $password The new password |
|
| 1462 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 1463 | + * @param string $old_password old password for password change, if supported |
|
| 1464 | + * @return bool |
|
| 1465 | + */ |
|
| 1466 | + public function password($username, $password, $isGUID = false, $old_password=null) |
|
| 1467 | + { |
|
| 1468 | + if ($username === NULL) { return false; } |
|
| 1469 | + if ($password === NULL) { return false; } |
|
| 1470 | + if (!$this->adldap->getLdapBind()) { return false; } |
|
| 1471 | + if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
| 1472 | + throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
|
| 1473 | + } |
|
| 1474 | + |
|
| 1475 | + $userDn = $this->dn($username, $isGUID); |
|
| 1476 | + if ($userDn === false) { |
|
| 1477 | + return false; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + $add=array(); |
|
| 1481 | 1481 | |
| 1482 | 1482 | if (empty($old_password) || !function_exists('ldap_modify_batch')) { |
| 1483 | 1483 | $add["unicodePwd"][0] = $this->encodePassword($password); |
@@ -1499,76 +1499,76 @@ discard block |
||
| 1499 | 1499 | ); |
| 1500 | 1500 | $result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods); |
| 1501 | 1501 | } |
| 1502 | - if ($result === false){ |
|
| 1503 | - $err = ldap_errno($this->adldap->getLdapConnection()); |
|
| 1504 | - if ($err) { |
|
| 1505 | - $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
|
| 1506 | - if($err == 53) { |
|
| 1507 | - $msg .= ' Your password might not match the password policy.'; |
|
| 1508 | - } |
|
| 1509 | - throw new adLDAPException($msg); |
|
| 1510 | - } |
|
| 1511 | - else { |
|
| 1512 | - return false; |
|
| 1513 | - } |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - return true; |
|
| 1517 | - } |
|
| 1518 | - |
|
| 1519 | - /** |
|
| 1520 | - * Modify a user |
|
| 1521 | - * |
|
| 1522 | - * @param string $username The username to query |
|
| 1523 | - * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
| 1524 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 1525 | - * @return bool |
|
| 1526 | - */ |
|
| 1527 | - public function modify($username, $attributes, $isGUID = false) |
|
| 1528 | - { |
|
| 1529 | - if ($username === NULL) { return "Missing compulsory field [username]"; } |
|
| 1530 | - if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
| 1531 | - throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.'); |
|
| 1532 | - } |
|
| 1533 | - |
|
| 1534 | - // Find the dn of the user |
|
| 1535 | - $userDn = $this->dn($username, $isGUID); |
|
| 1536 | - if ($userDn === false) { |
|
| 1537 | - return false; |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - // Translate the update to the LDAP schema |
|
| 1541 | - $mod = $this->adldap->adldap_schema($attributes); |
|
| 1542 | - |
|
| 1543 | - // Check to see if this is an enabled status update |
|
| 1544 | - if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
| 1545 | - return false; |
|
| 1546 | - } |
|
| 1547 | - |
|
| 1548 | - // Set the account control attribute (only if specified) |
|
| 1549 | - if (array_key_exists("enabled", $attributes)){ |
|
| 1550 | - if ($attributes["enabled"]){ |
|
| 1551 | - $controlOptions = array("NORMAL_ACCOUNT"); |
|
| 1552 | - } |
|
| 1553 | - else { |
|
| 1554 | - $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE"); |
|
| 1555 | - } |
|
| 1556 | - $mod["userAccountControl"][0] = $this->accountControl($controlOptions); |
|
| 1557 | - } |
|
| 1502 | + if ($result === false){ |
|
| 1503 | + $err = ldap_errno($this->adldap->getLdapConnection()); |
|
| 1504 | + if ($err) { |
|
| 1505 | + $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
|
| 1506 | + if($err == 53) { |
|
| 1507 | + $msg .= ' Your password might not match the password policy.'; |
|
| 1508 | + } |
|
| 1509 | + throw new adLDAPException($msg); |
|
| 1510 | + } |
|
| 1511 | + else { |
|
| 1512 | + return false; |
|
| 1513 | + } |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + return true; |
|
| 1517 | + } |
|
| 1518 | + |
|
| 1519 | + /** |
|
| 1520 | + * Modify a user |
|
| 1521 | + * |
|
| 1522 | + * @param string $username The username to query |
|
| 1523 | + * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
| 1524 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 1525 | + * @return bool |
|
| 1526 | + */ |
|
| 1527 | + public function modify($username, $attributes, $isGUID = false) |
|
| 1528 | + { |
|
| 1529 | + if ($username === NULL) { return "Missing compulsory field [username]"; } |
|
| 1530 | + if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
| 1531 | + throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.'); |
|
| 1532 | + } |
|
| 1533 | + |
|
| 1534 | + // Find the dn of the user |
|
| 1535 | + $userDn = $this->dn($username, $isGUID); |
|
| 1536 | + if ($userDn === false) { |
|
| 1537 | + return false; |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + // Translate the update to the LDAP schema |
|
| 1541 | + $mod = $this->adldap->adldap_schema($attributes); |
|
| 1542 | + |
|
| 1543 | + // Check to see if this is an enabled status update |
|
| 1544 | + if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
| 1545 | + return false; |
|
| 1546 | + } |
|
| 1547 | + |
|
| 1548 | + // Set the account control attribute (only if specified) |
|
| 1549 | + if (array_key_exists("enabled", $attributes)){ |
|
| 1550 | + if ($attributes["enabled"]){ |
|
| 1551 | + $controlOptions = array("NORMAL_ACCOUNT"); |
|
| 1552 | + } |
|
| 1553 | + else { |
|
| 1554 | + $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE"); |
|
| 1555 | + } |
|
| 1556 | + $mod["userAccountControl"][0] = $this->accountControl($controlOptions); |
|
| 1557 | + } |
|
| 1558 | 1558 | // we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2 |
| 1559 | 1559 | unset($mod['unicodePwd']); |
| 1560 | 1560 | |
| 1561 | 1561 | if ($mod) |
| 1562 | 1562 | { |
| 1563 | - // Do the update |
|
| 1564 | - $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
|
| 1565 | - if ($result == false) { |
|
| 1563 | + // Do the update |
|
| 1564 | + $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
|
| 1565 | + if ($result == false) { |
|
| 1566 | 1566 | if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***'; |
| 1567 | 1567 | error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
| 1568 | - return false; |
|
| 1569 | - } |
|
| 1568 | + return false; |
|
| 1569 | + } |
|
| 1570 | 1570 | } |
| 1571 | - if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
| 1571 | + if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
| 1572 | 1572 | { |
| 1573 | 1573 | return false; |
| 1574 | 1574 | } |
@@ -1633,23 +1633,23 @@ discard block |
||
| 1633 | 1633 | return $this->adldap->encode8bit($item, $key); |
| 1634 | 1634 | } |
| 1635 | 1635 | |
| 1636 | - /** |
|
| 1637 | - * Escape strings for the use in LDAP filters |
|
| 1638 | - * |
|
| 1639 | - * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT |
|
| 1640 | - * Ported from Perl's Net::LDAP::Util escape_filter_value |
|
| 1641 | - * |
|
| 1642 | - * @param string $str The string the parse |
|
| 1643 | - * @author Port by Andreas Gohr <[email protected]> |
|
| 1644 | - * @return string |
|
| 1645 | - */ |
|
| 1646 | - public function ldapSlashes($str){ |
|
| 1647 | - return preg_replace_callback( |
|
| 1648 | - '/([\x00-\x1F\*\(\)\\\\])/', |
|
| 1649 | - function ($matches) { |
|
| 1650 | - return "\\".join("", unpack("H2", $matches[1])); |
|
| 1651 | - }, |
|
| 1652 | - $str |
|
| 1653 | - ); |
|
| 1654 | - } |
|
| 1636 | + /** |
|
| 1637 | + * Escape strings for the use in LDAP filters |
|
| 1638 | + * |
|
| 1639 | + * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT |
|
| 1640 | + * Ported from Perl's Net::LDAP::Util escape_filter_value |
|
| 1641 | + * |
|
| 1642 | + * @param string $str The string the parse |
|
| 1643 | + * @author Port by Andreas Gohr <[email protected]> |
|
| 1644 | + * @return string |
|
| 1645 | + */ |
|
| 1646 | + public function ldapSlashes($str){ |
|
| 1647 | + return preg_replace_callback( |
|
| 1648 | + '/([\x00-\x1F\*\(\)\\\\])/', |
|
| 1649 | + function ($matches) { |
|
| 1650 | + return "\\".join("", unpack("H2", $matches[1])); |
|
| 1651 | + }, |
|
| 1652 | + $str |
|
| 1653 | + ); |
|
| 1654 | + } |
|
| 1655 | 1655 | } |
@@ -129,10 +129,10 @@ discard block |
||
| 129 | 129 | * @return adLDAP |
| 130 | 130 | * @throws adLDAPException |
| 131 | 131 | */ |
| 132 | - public static function get_adldap(array &$config=null) |
|
| 132 | + public static function get_adldap(array &$config = null) |
|
| 133 | 133 | { |
| 134 | 134 | static $adldap = array(); |
| 135 | - if (!$config) $config =& $GLOBALS['egw_info']['server']; |
|
| 135 | + if (!$config) $config = & $GLOBALS['egw_info']['server']; |
|
| 136 | 136 | |
| 137 | 137 | if (!isset($adldap[$config['ads_domain']])) |
| 138 | 138 | { |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | if (empty($config['ads_domain'])) throw new Exception("Required ADS domain missing!"); |
| 141 | 141 | |
| 142 | 142 | $base_dn_parts = array(); |
| 143 | - foreach(explode('.', $config['ads_domain']) as $dc) |
|
| 143 | + foreach (explode('.', $config['ads_domain']) as $dc) |
|
| 144 | 144 | { |
| 145 | 145 | $base_dn_parts[] = 'DC='.$dc; |
| 146 | 146 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @param int $account_id |
| 169 | 169 | * @return string|NULL |
| 170 | 170 | */ |
| 171 | - protected function get_sid($account_id=null) |
|
| 171 | + protected function get_sid($account_id = null) |
|
| 172 | 172 | { |
| 173 | 173 | static $domain_sid = null; |
| 174 | 174 | if (!isset($domain_sid)) |
@@ -203,14 +203,14 @@ discard block |
||
| 203 | 203 | * @param boolean $set_if_empty =false true set from DN of "Domain Users" group # |
| 204 | 204 | * @return string |
| 205 | 205 | */ |
| 206 | - public function ads_context($set_if_empty=false) |
|
| 206 | + public function ads_context($set_if_empty = false) |
|
| 207 | 207 | { |
| 208 | 208 | if (empty($this->frontend->config[self::ADS_CONTEXT])) |
| 209 | 209 | { |
| 210 | 210 | if ($set_if_empty && ($dn = $this->id2name(-self::DOMAIN_USERS_GROUP, 'account_dn'))) |
| 211 | 211 | { |
| 212 | 212 | $dn = preg_replace('/^CN=.*?,(CN|OU)=/i', '$1=', $dn); |
| 213 | - config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT]=$dn, 'phpgwapi'); |
|
| 213 | + config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT] = $dn, 'phpgwapi'); |
|
| 214 | 214 | } |
| 215 | 215 | else |
| 216 | 216 | { |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * @param boolean $reconnect =false true: reconnect even if already connected |
| 248 | 248 | * @return resource |
| 249 | 249 | */ |
| 250 | - public function ldap_connection($reconnect=false) |
|
| 250 | + public function ldap_connection($reconnect = false) |
|
| 251 | 251 | { |
| 252 | 252 | if (($reconnect || !($ds = $this->adldap->getLdapConnection())) && |
| 253 | 253 | // call connect, thought I dont know how it can be not connected ... |
@@ -411,8 +411,7 @@ discard block |
||
| 411 | 411 | $data = translation::convert($_data, 'utf-8'); |
| 412 | 412 | |
| 413 | 413 | // no need to calculate sid, if already calculated |
| 414 | - $sid = is_string($data['objectsid']) ? $data['objectsid'] : |
|
| 415 | - $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
| 414 | + $sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
| 416 | 415 | $account_id = -self::sid2account_id($sid); |
| 417 | 416 | |
| 418 | 417 | $group = array( |
@@ -426,10 +425,8 @@ discard block |
||
| 426 | 425 | 'account_lastname' => lang('Group'), |
| 427 | 426 | 'account_fullname' => lang('Group').' '.$data['samaccountname'][0], |
| 428 | 427 | 'account_email' => $data['mail'][0], |
| 429 | - 'account_created' => !isset($data['whencreated'][0]) ? null : |
|
| 430 | - self::_when2ts($data['whencreated'][0]), |
|
| 431 | - 'account_modified' => !isset($data['whenchanged'][0]) ? null : |
|
| 432 | - self::_when2ts($data['whenchanged'][0]), |
|
| 428 | + 'account_created' => !isset($data['whencreated'][0]) ? null : self::_when2ts($data['whencreated'][0]), |
|
| 429 | + 'account_modified' => !isset($data['whenchanged'][0]) ? null : self::_when2ts($data['whenchanged'][0]), |
|
| 433 | 430 | 'account_description' => $data['description'][0], |
| 434 | 431 | 'mailAllowed' => true, |
| 435 | 432 | ); |
@@ -449,7 +446,7 @@ discard block |
||
| 449 | 446 | { |
| 450 | 447 | if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'g', self::$group_attributes))) |
| 451 | 448 | { |
| 452 | - return false; // group not found |
|
| 449 | + return false; // group not found |
|
| 453 | 450 | } |
| 454 | 451 | $group = $this->_ldap2group(array_shift($data)); |
| 455 | 452 | |
@@ -472,8 +469,7 @@ discard block |
||
| 472 | 469 | $data = translation::convert($_data, 'utf-8'); |
| 473 | 470 | |
| 474 | 471 | // no need to calculate sid, if already calculated |
| 475 | - $sid = is_string($data['objectsid']) ? $data['objectsid'] : |
|
| 476 | - $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
| 472 | + $sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]); |
|
| 477 | 473 | $account_id = self::sid2account_id($sid); |
| 478 | 474 | |
| 479 | 475 | $user = array( |
@@ -489,22 +485,18 @@ discard block |
||
| 489 | 485 | 'account_email' => $data['mail'][0], |
| 490 | 486 | 'account_fullname' => $data['displayname'][0], |
| 491 | 487 | 'account_phone' => $data['telephonenumber'][0], |
| 492 | - 'account_status' => $data['useraccountcontrol'][0] & 2 ? false : 'A', |
|
| 493 | - 'account_expires' => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : |
|
| 494 | - $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]), |
|
| 495 | - 'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : |
|
| 496 | - $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])), |
|
| 497 | - 'account_created' => !isset($data['whencreated'][0]) ? null : |
|
| 498 | - self::_when2ts($data['whencreated'][0]), |
|
| 499 | - 'account_modified' => !isset($data['whenchanged'][0]) ? null : |
|
| 500 | - self::_when2ts($data['whenchanged'][0]), |
|
| 488 | + 'account_status' => $data['useraccountcontrol'][0]&2 ? false : 'A', |
|
| 489 | + 'account_expires' => !isset($data['accountexpires']) || $data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]), |
|
| 490 | + 'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])), |
|
| 491 | + 'account_created' => !isset($data['whencreated'][0]) ? null : self::_when2ts($data['whencreated'][0]), |
|
| 492 | + 'account_modified' => !isset($data['whenchanged'][0]) ? null : self::_when2ts($data['whenchanged'][0]), |
|
| 501 | 493 | ); |
| 502 | 494 | // expired accounts are NOT active |
| 503 | 495 | if ($user['account_expires'] !== -1 && $user['account_expires'] < time()) |
| 504 | 496 | { |
| 505 | 497 | $user['account_status'] = false; |
| 506 | 498 | } |
| 507 | - $user['person_id'] = $user['account_guid']; // id of contact |
|
| 499 | + $user['person_id'] = $user['account_guid']; // id of contact |
|
| 508 | 500 | //error_log(__METHOD__."(".array2string($data).") returning ".array2string($user)); |
| 509 | 501 | return $user; |
| 510 | 502 | } |
@@ -534,7 +526,7 @@ discard block |
||
| 534 | 526 | { |
| 535 | 527 | if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'u', self::$user_attributes))) |
| 536 | 528 | { |
| 537 | - return false; // user not found |
|
| 529 | + return false; // user not found |
|
| 538 | 530 | } |
| 539 | 531 | $user = $this->_ldap2user(array_shift($data)); |
| 540 | 532 | |
@@ -557,10 +549,10 @@ discard block |
||
| 557 | 549 | */ |
| 558 | 550 | protected static function _when2ts($_when) |
| 559 | 551 | { |
| 560 | - static $utc=null; |
|
| 552 | + static $utc = null; |
|
| 561 | 553 | if (!isset($utc)) $utc = new DateTimeZone('UTC'); |
| 562 | 554 | |
| 563 | - list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat |
|
| 555 | + list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat |
|
| 564 | 556 | $datetime = egw_time::createFromFormat(self::WHEN_FORMAT, $when, $utc); |
| 565 | 557 | if (egw_time::$server_timezone) $datetime->setTimezone(egw_time::$server_timezone); |
| 566 | 558 | |
@@ -575,7 +567,7 @@ discard block |
||
| 575 | 567 | * @param array $old =null current data |
| 576 | 568 | * @return int|false account_id or false on error |
| 577 | 569 | */ |
| 578 | - protected function _save_group(array &$data, array $old=null) |
|
| 570 | + protected function _save_group(array &$data, array $old = null) |
|
| 579 | 571 | { |
| 580 | 572 | //error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')'); |
| 581 | 573 | |
@@ -586,7 +578,7 @@ discard block |
||
| 586 | 578 | 'account_description' => 'description', |
| 587 | 579 | ); |
| 588 | 580 | $attributes = array(); |
| 589 | - foreach($new2adldap as $egw => $adldap) |
|
| 581 | + foreach ($new2adldap as $egw => $adldap) |
|
| 590 | 582 | { |
| 591 | 583 | $attributes[$adldap] = (string)$data[$egw]; |
| 592 | 584 | } |
@@ -623,11 +615,11 @@ discard block |
||
| 623 | 615 | 'account_description' => 'description', |
| 624 | 616 | ); |
| 625 | 617 | $ldap = array(); |
| 626 | - foreach($egw2adldap as $egw => $adldap) |
|
| 618 | + foreach ($egw2adldap as $egw => $adldap) |
|
| 627 | 619 | { |
| 628 | 620 | if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw]) |
| 629 | 621 | { |
| 630 | - switch($egw) |
|
| 622 | + switch ($egw) |
|
| 631 | 623 | { |
| 632 | 624 | case 'account_description': |
| 633 | 625 | $ldap[$adldap] = !empty($data[$egw]) ? $data[$egw] : array(); |
@@ -640,7 +632,7 @@ discard block |
||
| 640 | 632 | } |
| 641 | 633 | } |
| 642 | 634 | // attributes not (yet) suppored by adldap |
| 643 | - if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap))) |
|
| 635 | + if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap))) |
|
| 644 | 636 | { |
| 645 | 637 | error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret)); |
| 646 | 638 | return false; |
@@ -656,7 +648,7 @@ discard block |
||
| 656 | 648 | * @param array $old =null current data |
| 657 | 649 | * @return int|false account_id or false on error |
| 658 | 650 | */ |
| 659 | - protected function _save_user(array &$data, array $old=null) |
|
| 651 | + protected function _save_user(array &$data, array $old = null) |
|
| 660 | 652 | { |
| 661 | 653 | //error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')'); |
| 662 | 654 | if (!isset($data['account_fullname']) && !empty($data['account_firstname']) && !empty($data['account_lastname'])) |
@@ -676,12 +668,12 @@ discard block |
||
| 676 | 668 | 'account_status' => 'enabled', |
| 677 | 669 | ); |
| 678 | 670 | $attributes = array(); |
| 679 | - foreach($new2adldap as $egw => $adldap) |
|
| 671 | + foreach ($new2adldap as $egw => $adldap) |
|
| 680 | 672 | { |
| 681 | 673 | if ($egw == 'account_passwd' && (empty($data[$egw]) || |
| 682 | 674 | !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) |
| 683 | 675 | { |
| 684 | - continue; // do not try to set password, if no SSL or TLS, whole user creation will fail |
|
| 676 | + continue; // do not try to set password, if no SSL or TLS, whole user creation will fail |
|
| 685 | 677 | } |
| 686 | 678 | if (isset($data[$egw])) $attributes[$adldap] = $data[$egw]; |
| 687 | 679 | } |
@@ -718,7 +710,7 @@ discard block |
||
| 718 | 710 | 'account_firstname' => 'firstname', |
| 719 | 711 | 'account_lastname' => 'surname', |
| 720 | 712 | 'account_email' => 'email', |
| 721 | - 'account_fullname' => 'display_name', // handeled currently in rename above, as not supported by adLDAP |
|
| 713 | + 'account_fullname' => 'display_name', // handeled currently in rename above, as not supported by adLDAP |
|
| 722 | 714 | 'account_passwd' => 'password', |
| 723 | 715 | 'account_status' => 'enabled', |
| 724 | 716 | 'account_primary_group' => 'primarygroupid', |
@@ -731,7 +723,7 @@ discard block |
||
| 731 | 723 | // for a new entry set certain values (eg. profilePath) to in setup configured value |
| 732 | 724 | if ($new_entry) |
| 733 | 725 | { |
| 734 | - foreach($this->frontend->config as $name => $value) |
|
| 726 | + foreach ($this->frontend->config as $name => $value) |
|
| 735 | 727 | { |
| 736 | 728 | if (substr($name, 0, 8) == 'ads_new_') |
| 737 | 729 | { |
@@ -739,22 +731,22 @@ discard block |
||
| 739 | 731 | } |
| 740 | 732 | } |
| 741 | 733 | } |
| 742 | - foreach($egw2adldap as $egw => $adldap) |
|
| 734 | + foreach ($egw2adldap as $egw => $adldap) |
|
| 743 | 735 | { |
| 744 | 736 | if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw]) |
| 745 | 737 | { |
| 746 | - switch($egw) |
|
| 738 | + switch ($egw) |
|
| 747 | 739 | { |
| 748 | 740 | case 'account_passwd': |
| 749 | 741 | if (!empty($data[$egw]) && ($this->adldap->getUseSSL() || $this->adldap->getUseTLS())) |
| 750 | 742 | { |
| 751 | - $attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS |
|
| 743 | + $attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS |
|
| 752 | 744 | } |
| 753 | 745 | break; |
| 754 | 746 | case 'account_primary_group': |
| 755 | 747 | // setting a primary group seems to fail, if user is no member of that group |
| 756 | 748 | if (isset($old['memberships'][$data[$egw]]) || |
| 757 | - $this->adldap->group()->addUser($group=$this->id2name($data[$egw]), $data['account_id'])) |
|
| 749 | + $this->adldap->group()->addUser($group = $this->id2name($data[$egw]), $data['account_id'])) |
|
| 758 | 750 | { |
| 759 | 751 | $old['memberships'][$data[$egw]] = $group; |
| 760 | 752 | $ldap[$adldap] = abs($data[$egw]); |
@@ -765,11 +757,10 @@ discard block |
||
| 765 | 757 | $ldap['userPrincipalName'] = $data[$egw].'@'.$this->frontend->config['ads_domain']; |
| 766 | 758 | break; |
| 767 | 759 | case 'account_expires': |
| 768 | - $attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : |
|
| 769 | - self::convertUnixTimeToWindowsTime($data[$egw]); |
|
| 760 | + $attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : self::convertUnixTimeToWindowsTime($data[$egw]); |
|
| 770 | 761 | break; |
| 771 | 762 | case 'account_status': |
| 772 | - if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd! |
|
| 763 | + if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd! |
|
| 773 | 764 | $attributes[$adldap] = $data[$egw] == 'A'; |
| 774 | 765 | break; |
| 775 | 766 | case 'account_lastpwd_change': |
@@ -791,7 +782,7 @@ discard block |
||
| 791 | 782 | } |
| 792 | 783 | //elseif ($attributes) error_log(__METHOD__."(".array2string($data).") adldap->user()->modify('$data[account_lid]', ".array2string($attributes).') returned '.array2string($ret).' '.function_backtrace()); |
| 793 | 784 | // attributes not (yet) suppored by adldap |
| 794 | - if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap))) |
|
| 785 | + if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap))) |
|
| 795 | 786 | { |
| 796 | 787 | error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret).' ('.ldap_error($ds).') '.function_backtrace()); |
| 797 | 788 | return false; |
@@ -864,11 +855,11 @@ discard block |
||
| 864 | 855 | $query = ldap::quote(strtolower($param['query'])); |
| 865 | 856 | |
| 866 | 857 | $accounts = array(); |
| 867 | - if($param['type'] !== 'groups') |
|
| 858 | + if ($param['type'] !== 'groups') |
|
| 868 | 859 | { |
| 869 | 860 | if (!empty($query) && $query != '*') |
| 870 | 861 | { |
| 871 | - switch($param['query_type']) |
|
| 862 | + switch ($param['query_type']) |
|
| 872 | 863 | { |
| 873 | 864 | case 'all': |
| 874 | 865 | default: |
@@ -899,14 +890,14 @@ discard block |
||
| 899 | 890 | $membership_filter = '(|(memberOf='.$this->id2name((int)$param['type'], 'account_dn').')(PrimaryGroupId='.abs($param['type']).'))'; |
| 900 | 891 | $filter = $filter ? "(&$membership_filter$filter)" : $membership_filter; |
| 901 | 892 | } |
| 902 | - foreach($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data) |
|
| 893 | + foreach ($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data) |
|
| 903 | 894 | { |
| 904 | 895 | $account = $this->_ldap2user($data); |
| 905 | 896 | if ($param['active'] && !$this->frontend->is_active($account)) |
| 906 | 897 | { |
| 907 | 898 | continue; |
| 908 | 899 | } |
| 909 | - $account['account_fullname'] = common::display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$account['account_id']); |
|
| 900 | + $account['account_fullname'] = common::display_fullname($account['account_lid'], $account['account_firstname'], $account['account_lastname'], $account['account_id']); |
|
| 910 | 901 | $accounts[$account_id] = $account; |
| 911 | 902 | } |
| 912 | 903 | } |
@@ -915,9 +906,9 @@ discard block |
||
| 915 | 906 | $query = ldap::quote(strtolower($param['query'])); |
| 916 | 907 | |
| 917 | 908 | $filter = null; |
| 918 | - if(!empty($query) && $query != '*') |
|
| 909 | + if (!empty($query) && $query != '*') |
|
| 919 | 910 | { |
| 920 | - switch($param['query_type']) |
|
| 911 | + switch ($param['query_type']) |
|
| 921 | 912 | { |
| 922 | 913 | case 'all': |
| 923 | 914 | default: |
@@ -931,16 +922,16 @@ discard block |
||
| 931 | 922 | } |
| 932 | 923 | $filter = "(|(cn=$query)(description=$query))"; |
| 933 | 924 | } |
| 934 | - foreach($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data) |
|
| 925 | + foreach ($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data) |
|
| 935 | 926 | { |
| 936 | 927 | $accounts[$account_id] = $this->_ldap2group($data); |
| 937 | 928 | } |
| 938 | 929 | } |
| 939 | 930 | // sort the array |
| 940 | 931 | $this->_callback_sort = strtoupper($param['sort']); |
| 941 | - $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']); |
|
| 932 | + $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']); |
|
| 942 | 933 | $sortedAccounts = $accounts; |
| 943 | - uasort($sortedAccounts,array($this,'_sort_callback')); |
|
| 934 | + uasort($sortedAccounts, array($this, '_sort_callback')); |
|
| 944 | 935 | $account_search[$unl_serial]['data'] = $sortedAccounts; |
| 945 | 936 | |
| 946 | 937 | $account_search[$unl_serial]['total'] = $this->total = count($accounts); |
@@ -948,7 +939,7 @@ discard block |
||
| 948 | 939 | //echo "<p>accounts_ldap::search() found $this->total: ".microtime()."</p>\n"; |
| 949 | 940 | // return only the wanted accounts |
| 950 | 941 | reset($sortedAccounts); |
| 951 | - if(is_numeric($start) && is_numeric($offset)) |
|
| 942 | + if (is_numeric($start) && is_numeric($offset)) |
|
| 952 | 943 | { |
| 953 | 944 | $account_search[$serial]['data'] = array_slice($sortedAccounts, $start, $offset); |
| 954 | 945 | $account_search[$serial]['total'] = $this->total; |
@@ -979,19 +970,19 @@ discard block |
||
| 979 | 970 | * @param array $b |
| 980 | 971 | * @return int |
| 981 | 972 | */ |
| 982 | - protected function _sort_callback($a,$b) |
|
| 973 | + protected function _sort_callback($a, $b) |
|
| 983 | 974 | { |
| 984 | - foreach($this->_callback_order as $col ) |
|
| 975 | + foreach ($this->_callback_order as $col) |
|
| 985 | 976 | { |
| 986 | - if($this->_callback_sort != 'DESC') |
|
| 977 | + if ($this->_callback_sort != 'DESC') |
|
| 987 | 978 | { |
| 988 | - $cmp = strcasecmp( $a[$col], $b[$col] ); |
|
| 979 | + $cmp = strcasecmp($a[$col], $b[$col]); |
|
| 989 | 980 | } |
| 990 | 981 | else |
| 991 | 982 | { |
| 992 | - $cmp = strcasecmp( $b[$col], $a[$col] ); |
|
| 983 | + $cmp = strcasecmp($b[$col], $a[$col]); |
|
| 993 | 984 | } |
| 994 | - if ( $cmp != 0 ) |
|
| 985 | + if ($cmp != 0) |
|
| 995 | 986 | { |
| 996 | 987 | return $cmp; |
| 997 | 988 | } |
@@ -1010,9 +1001,9 @@ discard block |
||
| 1010 | 1001 | * @param array $accounts =array() array to add filtered accounts too, default empty array |
| 1011 | 1002 | * @return array account_id => account_lid or values for $attrs pairs |
| 1012 | 1003 | */ |
| 1013 | - protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array()) |
|
| 1004 | + protected function filter($attr_filter, $account_type = null, array $attrs = null, array $accounts = array()) |
|
| 1014 | 1005 | { |
| 1015 | - switch($account_type) |
|
| 1006 | + switch ($account_type) |
|
| 1016 | 1007 | { |
| 1017 | 1008 | case 'u': |
| 1018 | 1009 | $type_filter = '(samaccounttype='.adLDAP::ADLDAP_NORMAL_ACCOUNT.')'; |
@@ -1037,25 +1028,25 @@ discard block |
||
| 1037 | 1028 | } |
| 1038 | 1029 | else |
| 1039 | 1030 | { |
| 1040 | - foreach($attr_filter as $attr => $value) |
|
| 1031 | + foreach ($attr_filter as $attr => $value) |
|
| 1041 | 1032 | { |
| 1042 | 1033 | $filter .= '('.$attr.'='.$this->adldap->utilities()->ldapSlashes($value).')'; |
| 1043 | 1034 | } |
| 1044 | 1035 | } |
| 1045 | 1036 | $filter .= $type_filter.')'; |
| 1046 | 1037 | } |
| 1047 | - $sri = ldap_search($ds=$this->ldap_connection(), $context=$this->ads_context(), $filter, |
|
| 1038 | + $sri = ldap_search($ds = $this->ldap_connection(), $context = $this->ads_context(), $filter, |
|
| 1048 | 1039 | $attrs ? $attrs : self::$default_attributes); |
| 1049 | 1040 | if (!$sri) |
| 1050 | 1041 | { |
| 1051 | 1042 | if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...'); |
| 1052 | - $sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter, |
|
| 1043 | + $sri = ldap_search($ds = $this->ldap_connection(true), $context = $this->ads_context(), $filter, |
|
| 1053 | 1044 | $attrs ? $attrs : self::$default_attributes); |
| 1054 | 1045 | } |
| 1055 | 1046 | |
| 1056 | 1047 | if ($sri && ($allValues = ldap_get_entries($ds, $sri))) |
| 1057 | 1048 | { |
| 1058 | - foreach($allValues as $key => $data) |
|
| 1049 | + foreach ($allValues as $key => $data) |
|
| 1059 | 1050 | { |
| 1060 | 1051 | if ($key === 'count') continue; |
| 1061 | 1052 | |
@@ -1069,7 +1060,7 @@ discard block |
||
| 1069 | 1060 | |
| 1070 | 1061 | if ($data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT && $rid < self::MIN_ACCOUNT_ID) |
| 1071 | 1062 | { |
| 1072 | - continue; // ignore system accounts incl. "Administrator" |
|
| 1063 | + continue; // ignore system accounts incl. "Administrator" |
|
| 1073 | 1064 | } |
| 1074 | 1065 | $accounts[($data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP ? '-' : '').$rid] = |
| 1075 | 1066 | $attrs ? $data : translation::convert($data['samaccountname'][0], 'utf-8'); |
@@ -1093,7 +1084,7 @@ discard block |
||
| 1093 | 1084 | * @param string $account_type u = user, g = group, default null = try both |
| 1094 | 1085 | * @return int|false numeric account_id or false on error ($name not found) |
| 1095 | 1086 | */ |
| 1096 | - public function name2id($name, $which='account_lid', $account_type=null) |
|
| 1087 | + public function name2id($name, $which = 'account_lid', $account_type = null) |
|
| 1097 | 1088 | { |
| 1098 | 1089 | static $to_ldap = array( |
| 1099 | 1090 | 'account_lid' => 'samaccountname', |
@@ -1105,7 +1096,7 @@ discard block |
||
| 1105 | 1096 | $ret = false; |
| 1106 | 1097 | if (isset($to_ldap[$which])) |
| 1107 | 1098 | { |
| 1108 | - foreach($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid) |
|
| 1099 | + foreach ($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid) |
|
| 1109 | 1100 | { |
| 1110 | 1101 | unset($account_lid); |
| 1111 | 1102 | $ret = $account_id; |
@@ -1125,9 +1116,9 @@ discard block |
||
| 1125 | 1116 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
| 1126 | 1117 | * @return string/false converted value or false on error ($account_id not found) |
| 1127 | 1118 | */ |
| 1128 | - public function id2name($account_id, $which='account_lid') |
|
| 1119 | + public function id2name($account_id, $which = 'account_lid') |
|
| 1129 | 1120 | { |
| 1130 | - return $this->frontend->id2name($account_id,$which); |
|
| 1121 | + return $this->frontend->id2name($account_id, $which); |
|
| 1131 | 1122 | } |
| 1132 | 1123 | |
| 1133 | 1124 | /** |
@@ -1139,9 +1130,9 @@ discard block |
||
| 1139 | 1130 | */ |
| 1140 | 1131 | function update_lastlogin($_account_id, $ip) |
| 1141 | 1132 | { |
| 1142 | - unset($_account_id, $ip); // not used, but required by function signature |
|
| 1133 | + unset($_account_id, $ip); // not used, but required by function signature |
|
| 1143 | 1134 | |
| 1144 | - return false; // not longer supported |
|
| 1135 | + return false; // not longer supported |
|
| 1145 | 1136 | } |
| 1146 | 1137 | |
| 1147 | 1138 | /** |
@@ -1181,21 +1172,21 @@ discard block |
||
| 1181 | 1172 | * @param int $account_id uidnumber |
| 1182 | 1173 | * @return int number of added or removed memberships |
| 1183 | 1174 | */ |
| 1184 | - function set_memberships($groups,$account_id) |
|
| 1175 | + function set_memberships($groups, $account_id) |
|
| 1185 | 1176 | { |
| 1186 | 1177 | if (!($account = $this->id2name($account_id))) return; |
| 1187 | 1178 | $current = array_keys($this->memberships($account_id)); |
| 1188 | 1179 | |
| 1189 | 1180 | $changed = 0; |
| 1190 | - foreach(array( |
|
| 1191 | - 'add' => array_diff($groups, $current), // add account to all groups he is currently not in |
|
| 1192 | - 'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in |
|
| 1181 | + foreach (array( |
|
| 1182 | + 'add' => array_diff($groups, $current), // add account to all groups he is currently not in |
|
| 1183 | + 'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in |
|
| 1193 | 1184 | ) as $op => $memberships) |
| 1194 | 1185 | { |
| 1195 | 1186 | $func = $op.($account_id > 0 ? 'User' : 'Group'); |
| 1196 | - foreach($memberships as $gid) |
|
| 1187 | + foreach ($memberships as $gid) |
|
| 1197 | 1188 | { |
| 1198 | - $ok = $this->adldap->group()->$func($group=$this->id2name($gid), $account); |
|
| 1189 | + $ok = $this->adldap->group()->$func($group = $this->id2name($gid), $account); |
|
| 1199 | 1190 | //error_log(__METHOD__.'('.array2string($groups).", $account_id) $func('$group', '$account') returned ".array2string($ok)); |
| 1200 | 1191 | $changed += (int)$ok; |
| 1201 | 1192 | } |
@@ -1217,15 +1208,15 @@ discard block |
||
| 1217 | 1208 | $current = array_keys($this->members($gid)); |
| 1218 | 1209 | |
| 1219 | 1210 | $changed = 0; |
| 1220 | - foreach(array( |
|
| 1221 | - 'add' => array_diff($users, $current), // add members currently not in |
|
| 1222 | - 'remove' => array_diff($current, $users), // remove members only currently in |
|
| 1211 | + foreach (array( |
|
| 1212 | + 'add' => array_diff($users, $current), // add members currently not in |
|
| 1213 | + 'remove' => array_diff($current, $users), // remove members only currently in |
|
| 1223 | 1214 | ) as $op => $members) |
| 1224 | 1215 | { |
| 1225 | - foreach($members as $account_id) |
|
| 1216 | + foreach ($members as $account_id) |
|
| 1226 | 1217 | { |
| 1227 | 1218 | $func = $op.($account_id > 0 ? 'User' : 'Group'); |
| 1228 | - $ok = $this->adldap->group()->$func($group, $account=$this->id2name($account_id)); |
|
| 1219 | + $ok = $this->adldap->group()->$func($group, $account = $this->id2name($account_id)); |
|
| 1229 | 1220 | //error_log(__METHOD__.'('.array2string($users).", $account_id) $func('$group', '$account') returned ".array2string($ok)); |
| 1230 | 1221 | $changed += (int)$ok; |
| 1231 | 1222 | } |
@@ -1250,7 +1241,7 @@ discard block |
||
| 1250 | 1241 | */ |
| 1251 | 1242 | public $charset = 'iso-8859-1'; |
| 1252 | 1243 | |
| 1253 | - function __construct(array $options=array()) |
|
| 1244 | + function __construct(array $options = array()) |
|
| 1254 | 1245 | { |
| 1255 | 1246 | if (isset($options['charset'])) |
| 1256 | 1247 | { |
@@ -1337,19 +1328,19 @@ discard block |
||
| 1337 | 1328 | public function create($attributes) |
| 1338 | 1329 | { |
| 1339 | 1330 | // Check for compulsory fields |
| 1340 | - if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; } |
|
| 1341 | - if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; } |
|
| 1342 | - if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; } |
|
| 1343 | - if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; } |
|
| 1344 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
| 1345 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
| 1346 | - |
|
| 1347 | - if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){ |
|
| 1331 | + if (!array_key_exists("username", $attributes)) { return "Missing compulsory field [username]"; } |
|
| 1332 | + if (!array_key_exists("firstname", $attributes)) { return "Missing compulsory field [firstname]"; } |
|
| 1333 | + if (!array_key_exists("surname", $attributes)) { return "Missing compulsory field [surname]"; } |
|
| 1334 | + if (!array_key_exists("email", $attributes)) { return "Missing compulsory field [email]"; } |
|
| 1335 | + if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; } |
|
| 1336 | + if (empty($attributes["container"])) { return "Container attribute must be an array or string."; } |
|
| 1337 | + |
|
| 1338 | + if (array_key_exists("password", $attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) { |
|
| 1348 | 1339 | throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
| 1349 | 1340 | } |
| 1350 | 1341 | |
| 1351 | 1342 | if (!array_key_exists("display_name", $attributes)) { |
| 1352 | - $attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"]; |
|
| 1343 | + $attributes["display_name"] = $attributes["firstname"]." ".$attributes["surname"]; |
|
| 1353 | 1344 | } |
| 1354 | 1345 | |
| 1355 | 1346 | // Translate the schema |
@@ -1372,20 +1363,20 @@ discard block |
||
| 1372 | 1363 | // Determine the container |
| 1373 | 1364 | if (is_array($attributes['container'])) { |
| 1374 | 1365 | $attributes["container"] = array_reverse($attributes["container"]); |
| 1375 | - $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
|
| 1366 | + $attributes["container"] = "OU=".implode(",OU=", $attributes["container"]); |
|
| 1376 | 1367 | } |
| 1377 | 1368 | // we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2 |
| 1378 | 1369 | unset($add['unicodePwd']); |
| 1379 | 1370 | |
| 1380 | 1371 | // Add the entry |
| 1381 | - $result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
|
| 1372 | + $result = ldap_add($ds = $this->adldap->getLdapConnection(), $dn = "CN=".$add["cn"][0].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add); |
|
| 1382 | 1373 | if ($result != true) { |
| 1383 | 1374 | error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
| 1384 | 1375 | return false; |
| 1385 | 1376 | } |
| 1386 | 1377 | |
| 1387 | 1378 | // now password can be added to still disabled account |
| 1388 | - if (array_key_exists("password",$attributes)) |
|
| 1379 | + if (array_key_exists("password", $attributes)) |
|
| 1389 | 1380 | { |
| 1390 | 1381 | if (!$this->setPassword($dn, $attributes['password'])) return false; |
| 1391 | 1382 | |
@@ -1412,13 +1403,13 @@ discard block |
||
| 1412 | 1403 | */ |
| 1413 | 1404 | public function encodePassword($password) |
| 1414 | 1405 | { |
| 1415 | - $password="\"".$password."\""; |
|
| 1406 | + $password = "\"".$password."\""; |
|
| 1416 | 1407 | if (function_exists('mb_convert_encoding')) |
| 1417 | 1408 | { |
| 1418 | 1409 | return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
| 1419 | 1410 | } |
| 1420 | - $encoded=""; |
|
| 1421 | - for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
| 1411 | + $encoded = ""; |
|
| 1412 | + for ($i = 0; $i < strlen($password); $i++) { $encoded .= "{$password{$i}}\000"; } |
|
| 1422 | 1413 | return $encoded; |
| 1423 | 1414 | } |
| 1424 | 1415 | |
@@ -1435,7 +1426,7 @@ discard block |
||
| 1435 | 1426 | */ |
| 1436 | 1427 | public function setPassword($dn, $password) |
| 1437 | 1428 | { |
| 1438 | - $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
|
| 1429 | + $result = ldap_mod_replace($ds = $this->adldap->getLdapConnection(), $dn, array( |
|
| 1439 | 1430 | 'unicodePwd' => $this->encodePassword($password), |
| 1440 | 1431 | )); |
| 1441 | 1432 | if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
@@ -1463,7 +1454,7 @@ discard block |
||
| 1463 | 1454 | * @param string $old_password old password for password change, if supported |
| 1464 | 1455 | * @return bool |
| 1465 | 1456 | */ |
| 1466 | - public function password($username, $password, $isGUID = false, $old_password=null) |
|
| 1457 | + public function password($username, $password, $isGUID = false, $old_password = null) |
|
| 1467 | 1458 | { |
| 1468 | 1459 | if ($username === NULL) { return false; } |
| 1469 | 1460 | if ($password === NULL) { return false; } |
@@ -1477,7 +1468,7 @@ discard block |
||
| 1477 | 1468 | return false; |
| 1478 | 1469 | } |
| 1479 | 1470 | |
| 1480 | - $add=array(); |
|
| 1471 | + $add = array(); |
|
| 1481 | 1472 | |
| 1482 | 1473 | if (empty($old_password) || !function_exists('ldap_modify_batch')) { |
| 1483 | 1474 | $add["unicodePwd"][0] = $this->encodePassword($password); |
@@ -1499,11 +1490,11 @@ discard block |
||
| 1499 | 1490 | ); |
| 1500 | 1491 | $result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods); |
| 1501 | 1492 | } |
| 1502 | - if ($result === false){ |
|
| 1493 | + if ($result === false) { |
|
| 1503 | 1494 | $err = ldap_errno($this->adldap->getLdapConnection()); |
| 1504 | 1495 | if ($err) { |
| 1505 | - $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
|
| 1506 | - if($err == 53) { |
|
| 1496 | + $msg = 'Error '.$err.': '.ldap_err2str($err).'.'; |
|
| 1497 | + if ($err == 53) { |
|
| 1507 | 1498 | $msg .= ' Your password might not match the password policy.'; |
| 1508 | 1499 | } |
| 1509 | 1500 | throw new adLDAPException($msg); |
@@ -1541,13 +1532,13 @@ discard block |
||
| 1541 | 1532 | $mod = $this->adldap->adldap_schema($attributes); |
| 1542 | 1533 | |
| 1543 | 1534 | // Check to see if this is an enabled status update |
| 1544 | - if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
| 1535 | + if (!$mod && !array_key_exists("enabled", $attributes)) { |
|
| 1545 | 1536 | return false; |
| 1546 | 1537 | } |
| 1547 | 1538 | |
| 1548 | 1539 | // Set the account control attribute (only if specified) |
| 1549 | - if (array_key_exists("enabled", $attributes)){ |
|
| 1550 | - if ($attributes["enabled"]){ |
|
| 1540 | + if (array_key_exists("enabled", $attributes)) { |
|
| 1541 | + if ($attributes["enabled"]) { |
|
| 1551 | 1542 | $controlOptions = array("NORMAL_ACCOUNT"); |
| 1552 | 1543 | } |
| 1553 | 1544 | else { |
@@ -1561,14 +1552,14 @@ discard block |
||
| 1561 | 1552 | if ($mod) |
| 1562 | 1553 | { |
| 1563 | 1554 | // Do the update |
| 1564 | - $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
|
| 1555 | + $result = @ldap_modify($ds = $this->adldap->getLdapConnection(), $userDn, $mod); |
|
| 1565 | 1556 | if ($result == false) { |
| 1566 | 1557 | if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***'; |
| 1567 | 1558 | error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
| 1568 | 1559 | return false; |
| 1569 | 1560 | } |
| 1570 | 1561 | } |
| 1571 | - if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
| 1562 | + if (array_key_exists("password", $attributes) && !$this->setPassword($userDn, $attributes['password'])) |
|
| 1572 | 1563 | { |
| 1573 | 1564 | return false; |
| 1574 | 1565 | } |
@@ -1591,10 +1582,10 @@ discard block |
||
| 1591 | 1582 | */ |
| 1592 | 1583 | public function create($attributes) |
| 1593 | 1584 | { |
| 1594 | - if (!is_array($attributes)){ return "Attributes must be an array"; } |
|
| 1595 | - if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; } |
|
| 1596 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
| 1597 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
| 1585 | + if (!is_array($attributes)) { return "Attributes must be an array"; } |
|
| 1586 | + if (!array_key_exists("group_name", $attributes)) { return "Missing compulsory field [group_name]"; } |
|
| 1587 | + if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; } |
|
| 1588 | + if (empty($attributes["container"])) { return "Container attribute must be an array or string."; } |
|
| 1598 | 1589 | |
| 1599 | 1590 | //$member_array = array(); |
| 1600 | 1591 | //$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com"; |
@@ -1610,9 +1601,9 @@ discard block |
||
| 1610 | 1601 | // Determine the container |
| 1611 | 1602 | if (is_array($attributes['container'])) { |
| 1612 | 1603 | $attributes["container"] = array_reverse($attributes["container"]); |
| 1613 | - $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
|
| 1604 | + $attributes["container"] = "OU=".implode(",OU=", $attributes["container"]); |
|
| 1614 | 1605 | } |
| 1615 | - $result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
|
| 1606 | + $result = ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add); |
|
| 1616 | 1607 | if ($result != true) { |
| 1617 | 1608 | return false; |
| 1618 | 1609 | } |
@@ -1643,10 +1634,10 @@ discard block |
||
| 1643 | 1634 | * @author Port by Andreas Gohr <[email protected]> |
| 1644 | 1635 | * @return string |
| 1645 | 1636 | */ |
| 1646 | - public function ldapSlashes($str){ |
|
| 1637 | + public function ldapSlashes($str) { |
|
| 1647 | 1638 | return preg_replace_callback( |
| 1648 | 1639 | '/([\x00-\x1F\*\(\)\\\\])/', |
| 1649 | - function ($matches) { |
|
| 1640 | + function($matches) { |
|
| 1650 | 1641 | return "\\".join("", unpack("H2", $matches[1])); |
| 1651 | 1642 | }, |
| 1652 | 1643 | $str |
@@ -132,12 +132,21 @@ discard block |
||
| 132 | 132 | public static function get_adldap(array &$config=null) |
| 133 | 133 | { |
| 134 | 134 | static $adldap = array(); |
| 135 | - if (!$config) $config =& $GLOBALS['egw_info']['server']; |
|
| 135 | + if (!$config) |
|
| 136 | + { |
|
| 137 | + $config =& $GLOBALS['egw_info']['server']; |
|
| 138 | + } |
|
| 136 | 139 | |
| 137 | 140 | if (!isset($adldap[$config['ads_domain']])) |
| 138 | 141 | { |
| 139 | - if (empty($config['ads_host'])) throw new Exception("Required ADS host name(s) missing!"); |
|
| 140 | - if (empty($config['ads_domain'])) throw new Exception("Required ADS domain missing!"); |
|
| 142 | + if (empty($config['ads_host'])) |
|
| 143 | + { |
|
| 144 | + throw new Exception("Required ADS host name(s) missing!"); |
|
| 145 | + } |
|
| 146 | + if (empty($config['ads_domain'])) |
|
| 147 | + { |
|
| 148 | + throw new Exception("Required ADS domain missing!"); |
|
| 149 | + } |
|
| 141 | 150 | |
| 142 | 151 | $base_dn_parts = array(); |
| 143 | 152 | foreach(explode('.', $config['ads_domain']) as $dc) |
@@ -156,7 +165,10 @@ discard block |
||
| 156 | 165 | 'charset' => translation::charset(), |
| 157 | 166 | ); |
| 158 | 167 | $adldap[$config['ads_domain']] = new adLDAP_egw($options); |
| 159 | - if (self::$debug) error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace()); |
|
| 168 | + if (self::$debug) |
|
| 169 | + { |
|
| 170 | + error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace()); |
|
| 171 | + } |
|
| 160 | 172 | } |
| 161 | 173 | //else error_log(__METHOD__."() returning cached adLDAP ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace()); |
| 162 | 174 | return $adldap[$config['ads_domain']]; |
@@ -237,7 +249,10 @@ discard block |
||
| 237 | 249 | throw new egw_exception_wrong_userinput("Wrong or not configured ADS context '$context' (baseDN='$base')!"); |
| 238 | 250 | } |
| 239 | 251 | $container = $matches[1]; |
| 240 | - if (self::$debug) error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container)); |
|
| 252 | + if (self::$debug) |
|
| 253 | + { |
|
| 254 | + error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container)); |
|
| 255 | + } |
|
| 241 | 256 | return $container; |
| 242 | 257 | } |
| 243 | 258 | |
@@ -330,10 +345,16 @@ discard block |
||
| 330 | 345 | */ |
| 331 | 346 | public function read($account_id) |
| 332 | 347 | { |
| 333 | - if (!(int)$account_id) return false; |
|
| 348 | + if (!(int)$account_id) |
|
| 349 | + { |
|
| 350 | + return false; |
|
| 351 | + } |
|
| 334 | 352 | |
| 335 | 353 | $ret = $account_id < 0 ? $this->_read_group($account_id) : $this->_read_user($account_id); |
| 336 | - if (self::$debug) error_log(__METHOD__."($account_id) returning ".array2string($ret)); |
|
| 354 | + if (self::$debug) |
|
| 355 | + { |
|
| 356 | + error_log(__METHOD__."($account_id) returning ".array2string($ret)); |
|
| 357 | + } |
|
| 337 | 358 | return $ret; |
| 338 | 359 | } |
| 339 | 360 | |
@@ -366,7 +387,10 @@ discard block |
||
| 366 | 387 | } |
| 367 | 388 | $ret = $is_group ? $this->_save_group($data, $old) : $this->_save_user($data, $old); |
| 368 | 389 | |
| 369 | - if (self::$debug) error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret)); |
|
| 390 | + if (self::$debug) |
|
| 391 | + { |
|
| 392 | + error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret)); |
|
| 393 | + } |
|
| 370 | 394 | return $ret; |
| 371 | 395 | } |
| 372 | 396 | |
@@ -396,7 +420,10 @@ discard block |
||
| 396 | 420 | { |
| 397 | 421 | $ret = $this->adldap->user()->delete($account_lid); |
| 398 | 422 | } |
| 399 | - if (self::$debug) error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret)); |
|
| 423 | + if (self::$debug) |
|
| 424 | + { |
|
| 425 | + error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret)); |
|
| 426 | + } |
|
| 400 | 427 | return $ret; |
| 401 | 428 | } |
| 402 | 429 | |
@@ -558,11 +585,17 @@ discard block |
||
| 558 | 585 | protected static function _when2ts($_when) |
| 559 | 586 | { |
| 560 | 587 | static $utc=null; |
| 561 | - if (!isset($utc)) $utc = new DateTimeZone('UTC'); |
|
| 588 | + if (!isset($utc)) |
|
| 589 | + { |
|
| 590 | + $utc = new DateTimeZone('UTC'); |
|
| 591 | + } |
|
| 562 | 592 | |
| 563 | 593 | list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat |
| 564 | 594 | $datetime = egw_time::createFromFormat(self::WHEN_FORMAT, $when, $utc); |
| 565 | - if (egw_time::$server_timezone) $datetime->setTimezone(egw_time::$server_timezone); |
|
| 595 | + if (egw_time::$server_timezone) |
|
| 596 | + { |
|
| 597 | + $datetime->setTimezone(egw_time::$server_timezone); |
|
| 598 | + } |
|
| 566 | 599 | |
| 567 | 600 | return $datetime->getTimestamp(); |
| 568 | 601 | } |
@@ -579,12 +612,15 @@ discard block |
||
| 579 | 612 | { |
| 580 | 613 | //error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')'); |
| 581 | 614 | |
| 582 | - if (!$old) // new entry |
|
| 615 | + if (!$old) |
|
| 616 | + { |
|
| 617 | + // new entry |
|
| 583 | 618 | { |
| 584 | 619 | static $new2adldap = array( |
| 585 | 620 | 'account_lid' => 'group_name', |
| 586 | 621 | 'account_description' => 'description', |
| 587 | 622 | ); |
| 623 | + } |
|
| 588 | 624 | $attributes = array(); |
| 589 | 625 | foreach($new2adldap as $egw => $adldap) |
| 590 | 626 | { |
@@ -664,7 +700,9 @@ discard block |
||
| 664 | 700 | $data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname']; |
| 665 | 701 | } |
| 666 | 702 | |
| 667 | - if (($new_entry = !$old)) // new entry |
|
| 703 | + if (($new_entry = !$old)) |
|
| 704 | + { |
|
| 705 | + // new entry |
|
| 668 | 706 | { |
| 669 | 707 | static $new2adldap = array( |
| 670 | 708 | 'account_lid' => 'username', |
@@ -675,6 +713,7 @@ discard block |
||
| 675 | 713 | 'account_passwd' => 'password', |
| 676 | 714 | 'account_status' => 'enabled', |
| 677 | 715 | ); |
| 716 | + } |
|
| 678 | 717 | $attributes = array(); |
| 679 | 718 | foreach($new2adldap as $egw => $adldap) |
| 680 | 719 | { |
@@ -683,7 +722,10 @@ discard block |
||
| 683 | 722 | { |
| 684 | 723 | continue; // do not try to set password, if no SSL or TLS, whole user creation will fail |
| 685 | 724 | } |
| 686 | - if (isset($data[$egw])) $attributes[$adldap] = $data[$egw]; |
|
| 725 | + if (isset($data[$egw])) |
|
| 726 | + { |
|
| 727 | + $attributes[$adldap] = $data[$egw]; |
|
| 728 | + } |
|
| 687 | 729 | } |
| 688 | 730 | $attributes['enabled'] = !isset($data['account_status']) || $data['account_status'] === 'A'; |
| 689 | 731 | $attributes['container'] = $this->_get_container(); |
@@ -769,7 +811,11 @@ discard block |
||
| 769 | 811 | self::convertUnixTimeToWindowsTime($data[$egw]); |
| 770 | 812 | break; |
| 771 | 813 | case 'account_status': |
| 772 | - if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd! |
|
| 814 | + if ($new_entry && empty($data['account_passwd'])) |
|
| 815 | + { |
|
| 816 | + continue; |
|
| 817 | + } |
|
| 818 | + // cant active new account without passwd! |
|
| 773 | 819 | $attributes[$adldap] = $data[$egw] == 'A'; |
| 774 | 820 | break; |
| 775 | 821 | case 'account_lastpwd_change': |
@@ -849,8 +895,14 @@ discard block |
||
| 849 | 895 | } |
| 850 | 896 | // if it's a limited query, check if the unlimited query is cached |
| 851 | 897 | $start = $param['start']; |
| 852 | - if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15; |
|
| 853 | - if (!($offset = $param['offset'])) $offset = $maxmatchs; |
|
| 898 | + if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) |
|
| 899 | + { |
|
| 900 | + $maxmatchs = 15; |
|
| 901 | + } |
|
| 902 | + if (!($offset = $param['offset'])) |
|
| 903 | + { |
|
| 904 | + $offset = $maxmatchs; |
|
| 905 | + } |
|
| 854 | 906 | unset($param['start']); |
| 855 | 907 | unset($param['offset']); |
| 856 | 908 | $unl_serial = serialize($param); |
@@ -1048,7 +1100,10 @@ discard block |
||
| 1048 | 1100 | $attrs ? $attrs : self::$default_attributes); |
| 1049 | 1101 | if (!$sri) |
| 1050 | 1102 | { |
| 1051 | - if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...'); |
|
| 1103 | + if (self::$debug) |
|
| 1104 | + { |
|
| 1105 | + error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...'); |
|
| 1106 | + } |
|
| 1052 | 1107 | $sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter, |
| 1053 | 1108 | $attrs ? $attrs : self::$default_attributes); |
| 1054 | 1109 | } |
@@ -1057,7 +1112,10 @@ discard block |
||
| 1057 | 1112 | { |
| 1058 | 1113 | foreach($allValues as $key => $data) |
| 1059 | 1114 | { |
| 1060 | - if ($key === 'count') continue; |
|
| 1115 | + if ($key === 'count') |
|
| 1116 | + { |
|
| 1117 | + continue; |
|
| 1118 | + } |
|
| 1061 | 1119 | |
| 1062 | 1120 | if ($account_type && !($account_type == 'u' && $data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT || |
| 1063 | 1121 | $account_type == 'g' && $data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP)) |
@@ -1075,7 +1133,10 @@ discard block |
||
| 1075 | 1133 | $attrs ? $data : translation::convert($data['samaccountname'][0], 'utf-8'); |
| 1076 | 1134 | } |
| 1077 | 1135 | } |
| 1078 | - else if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues)); |
|
| 1136 | + else if (self::$debug) |
|
| 1137 | + { |
|
| 1138 | + error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues)); |
|
| 1139 | + } |
|
| 1079 | 1140 | |
| 1080 | 1141 | //error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returning ".array2string($accounts).' '.function_backtrace()); |
| 1081 | 1142 | return $accounts; |
@@ -1112,7 +1173,10 @@ discard block |
||
| 1112 | 1173 | break; |
| 1113 | 1174 | } |
| 1114 | 1175 | } |
| 1115 | - if (self::$debug) error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret)); |
|
| 1176 | + if (self::$debug) |
|
| 1177 | + { |
|
| 1178 | + error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret)); |
|
| 1179 | + } |
|
| 1116 | 1180 | return $ret; |
| 1117 | 1181 | } |
| 1118 | 1182 | |
@@ -1154,7 +1218,10 @@ discard block |
||
| 1154 | 1218 | */ |
| 1155 | 1219 | function memberships($account_id) |
| 1156 | 1220 | { |
| 1157 | - if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0) return false; |
|
| 1221 | + if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0) |
|
| 1222 | + { |
|
| 1223 | + return false; |
|
| 1224 | + } |
|
| 1158 | 1225 | |
| 1159 | 1226 | return $data['memberships']; |
| 1160 | 1227 | } |
@@ -1169,7 +1236,10 @@ discard block |
||
| 1169 | 1236 | */ |
| 1170 | 1237 | function members($gid) |
| 1171 | 1238 | { |
| 1172 | - if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0) return false; |
|
| 1239 | + if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0) |
|
| 1240 | + { |
|
| 1241 | + return false; |
|
| 1242 | + } |
|
| 1173 | 1243 | |
| 1174 | 1244 | return $data['members']; |
| 1175 | 1245 | } |
@@ -1183,7 +1253,10 @@ discard block |
||
| 1183 | 1253 | */ |
| 1184 | 1254 | function set_memberships($groups,$account_id) |
| 1185 | 1255 | { |
| 1186 | - if (!($account = $this->id2name($account_id))) return; |
|
| 1256 | + if (!($account = $this->id2name($account_id))) |
|
| 1257 | + { |
|
| 1258 | + return; |
|
| 1259 | + } |
|
| 1187 | 1260 | $current = array_keys($this->memberships($account_id)); |
| 1188 | 1261 | |
| 1189 | 1262 | $changed = 0; |
@@ -1200,7 +1273,10 @@ discard block |
||
| 1200 | 1273 | $changed += (int)$ok; |
| 1201 | 1274 | } |
| 1202 | 1275 | } |
| 1203 | - if (self::$debug) error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed"); |
|
| 1276 | + if (self::$debug) |
|
| 1277 | + { |
|
| 1278 | + error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed"); |
|
| 1279 | + } |
|
| 1204 | 1280 | return $changed; |
| 1205 | 1281 | } |
| 1206 | 1282 | |
@@ -1213,7 +1289,10 @@ discard block |
||
| 1213 | 1289 | */ |
| 1214 | 1290 | function set_members($users, $gid) |
| 1215 | 1291 | { |
| 1216 | - if (!($group = $this->id2name($gid))) return; |
|
| 1292 | + if (!($group = $this->id2name($gid))) |
|
| 1293 | + { |
|
| 1294 | + return; |
|
| 1295 | + } |
|
| 1217 | 1296 | $current = array_keys($this->members($gid)); |
| 1218 | 1297 | |
| 1219 | 1298 | $changed = 0; |
@@ -1230,7 +1309,10 @@ discard block |
||
| 1230 | 1309 | $changed += (int)$ok; |
| 1231 | 1310 | } |
| 1232 | 1311 | } |
| 1233 | - if (self::$debug) error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed"); |
|
| 1312 | + if (self::$debug) |
|
| 1313 | + { |
|
| 1314 | + error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed"); |
|
| 1315 | + } |
|
| 1234 | 1316 | return $changed; |
| 1235 | 1317 | } |
| 1236 | 1318 | } |
@@ -1284,8 +1366,10 @@ discard block |
||
| 1284 | 1366 | * |
| 1285 | 1367 | * @return adLDAPUsers |
| 1286 | 1368 | */ |
| 1287 | - public function user() { |
|
| 1288 | - if (!$this->userClass) { |
|
| 1369 | + public function user() |
|
| 1370 | + { |
|
| 1371 | + if (!$this->userClass) |
|
| 1372 | + { |
|
| 1289 | 1373 | $this->userClass = new adLDAPUsers_egw($this); |
| 1290 | 1374 | } |
| 1291 | 1375 | return $this->userClass; |
@@ -1296,8 +1380,10 @@ discard block |
||
| 1296 | 1380 | * |
| 1297 | 1381 | * @return adLDAPGroups |
| 1298 | 1382 | */ |
| 1299 | - public function group() { |
|
| 1300 | - if (!$this->groupClass) { |
|
| 1383 | + public function group() |
|
| 1384 | + { |
|
| 1385 | + if (!$this->groupClass) |
|
| 1386 | + { |
|
| 1301 | 1387 | $this->groupClass = new adLDAPGroups_egw($this); |
| 1302 | 1388 | } |
| 1303 | 1389 | return $this->groupClass; |
@@ -1308,8 +1394,10 @@ discard block |
||
| 1308 | 1394 | * |
| 1309 | 1395 | * @return adLDAPUtils |
| 1310 | 1396 | */ |
| 1311 | - public function utilities() { |
|
| 1312 | - if (!$this->utilClass) { |
|
| 1397 | + public function utilities() |
|
| 1398 | + { |
|
| 1399 | + if (!$this->utilClass) |
|
| 1400 | + { |
|
| 1313 | 1401 | $this->utilClass = new adLDAPUtils_egw($this); |
| 1314 | 1402 | } |
| 1315 | 1403 | return $this->utilClass; |
@@ -1337,18 +1425,32 @@ discard block |
||
| 1337 | 1425 | public function create($attributes) |
| 1338 | 1426 | { |
| 1339 | 1427 | // Check for compulsory fields |
| 1340 | - if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; } |
|
| 1341 | - if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; } |
|
| 1342 | - if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; } |
|
| 1343 | - if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; } |
|
| 1344 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
| 1345 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
| 1346 | - |
|
| 1347 | - if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){ |
|
| 1428 | + if (!array_key_exists("username", $attributes)) |
|
| 1429 | + { |
|
| 1430 | +return "Missing compulsory field [username]"; } |
|
| 1431 | + if (!array_key_exists("firstname", $attributes)) |
|
| 1432 | + { |
|
| 1433 | +return "Missing compulsory field [firstname]"; } |
|
| 1434 | + if (!array_key_exists("surname", $attributes)) |
|
| 1435 | + { |
|
| 1436 | +return "Missing compulsory field [surname]"; } |
|
| 1437 | + if (!array_key_exists("email", $attributes)) |
|
| 1438 | + { |
|
| 1439 | +return "Missing compulsory field [email]"; } |
|
| 1440 | + if (!array_key_exists("container", $attributes)) |
|
| 1441 | + { |
|
| 1442 | +return "Missing compulsory field [container]"; } |
|
| 1443 | + if (empty($attributes["container"])) |
|
| 1444 | + { |
|
| 1445 | +return "Container attribute must be an array or string."; } |
|
| 1446 | + |
|
| 1447 | + if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) |
|
| 1448 | + { |
|
| 1348 | 1449 | throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
| 1349 | 1450 | } |
| 1350 | 1451 | |
| 1351 | - if (!array_key_exists("display_name", $attributes)) { |
|
| 1452 | + if (!array_key_exists("display_name", $attributes)) |
|
| 1453 | + { |
|
| 1352 | 1454 | $attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"]; |
| 1353 | 1455 | } |
| 1354 | 1456 | |
@@ -1370,7 +1472,8 @@ discard block |
||
| 1370 | 1472 | $add["userAccountControl"][0] = $this->accountControl($control_options); |
| 1371 | 1473 | |
| 1372 | 1474 | // Determine the container |
| 1373 | - if (is_array($attributes['container'])) { |
|
| 1475 | + if (is_array($attributes['container'])) |
|
| 1476 | + { |
|
| 1374 | 1477 | $attributes["container"] = array_reverse($attributes["container"]); |
| 1375 | 1478 | $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
| 1376 | 1479 | } |
@@ -1379,7 +1482,8 @@ discard block |
||
| 1379 | 1482 | |
| 1380 | 1483 | // Add the entry |
| 1381 | 1484 | $result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
| 1382 | - if ($result != true) { |
|
| 1485 | + if ($result != true) |
|
| 1486 | + { |
|
| 1383 | 1487 | error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
| 1384 | 1488 | return false; |
| 1385 | 1489 | } |
@@ -1387,7 +1491,10 @@ discard block |
||
| 1387 | 1491 | // now password can be added to still disabled account |
| 1388 | 1492 | if (array_key_exists("password",$attributes)) |
| 1389 | 1493 | { |
| 1390 | - if (!$this->setPassword($dn, $attributes['password'])) return false; |
|
| 1494 | + if (!$this->setPassword($dn, $attributes['password'])) |
|
| 1495 | + { |
|
| 1496 | + return false; |
|
| 1497 | + } |
|
| 1391 | 1498 | |
| 1392 | 1499 | // now account can be enabled |
| 1393 | 1500 | if ($attributes["enabled"]) |
@@ -1395,7 +1502,10 @@ discard block |
||
| 1395 | 1502 | $control_options = array("NORMAL_ACCOUNT"); |
| 1396 | 1503 | $mod = array("userAccountControl" => $this->accountControl($control_options)); |
| 1397 | 1504 | $result = ldap_modify($ds, $dn, $mod); |
| 1398 | - if (!$result) error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
|
| 1505 | + if (!$result) |
|
| 1506 | + { |
|
| 1507 | + error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
|
| 1508 | + } |
|
| 1399 | 1509 | } |
| 1400 | 1510 | } |
| 1401 | 1511 | |
@@ -1418,7 +1528,9 @@ discard block |
||
| 1418 | 1528 | return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); |
| 1419 | 1529 | } |
| 1420 | 1530 | $encoded=""; |
| 1421 | - for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } |
|
| 1531 | + for ($i=0; $i <strlen($password); $i++) |
|
| 1532 | + { |
|
| 1533 | +$encoded.="{$password{$i}}\000"; } |
|
| 1422 | 1534 | return $encoded; |
| 1423 | 1535 | } |
| 1424 | 1536 | |
@@ -1438,7 +1550,10 @@ discard block |
||
| 1438 | 1550 | $result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array( |
| 1439 | 1551 | 'unicodePwd' => $this->encodePassword($password), |
| 1440 | 1552 | )); |
| 1441 | - if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
|
| 1553 | + if (!$result) |
|
| 1554 | + { |
|
| 1555 | + error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds)); |
|
| 1556 | + } |
|
| 1442 | 1557 | return $result; |
| 1443 | 1558 | } |
| 1444 | 1559 | |
@@ -1465,26 +1580,36 @@ discard block |
||
| 1465 | 1580 | */ |
| 1466 | 1581 | public function password($username, $password, $isGUID = false, $old_password=null) |
| 1467 | 1582 | { |
| 1468 | - if ($username === NULL) { return false; } |
|
| 1469 | - if ($password === NULL) { return false; } |
|
| 1470 | - if (!$this->adldap->getLdapBind()) { return false; } |
|
| 1471 | - if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
| 1583 | + if ($username === NULL) |
|
| 1584 | + { |
|
| 1585 | +return false; } |
|
| 1586 | + if ($password === NULL) |
|
| 1587 | + { |
|
| 1588 | +return false; } |
|
| 1589 | + if (!$this->adldap->getLdapBind()) |
|
| 1590 | + { |
|
| 1591 | +return false; } |
|
| 1592 | + if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) |
|
| 1593 | + { |
|
| 1472 | 1594 | throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
| 1473 | 1595 | } |
| 1474 | 1596 | |
| 1475 | 1597 | $userDn = $this->dn($username, $isGUID); |
| 1476 | - if ($userDn === false) { |
|
| 1598 | + if ($userDn === false) |
|
| 1599 | + { |
|
| 1477 | 1600 | return false; |
| 1478 | 1601 | } |
| 1479 | 1602 | |
| 1480 | 1603 | $add=array(); |
| 1481 | 1604 | |
| 1482 | - if (empty($old_password) || !function_exists('ldap_modify_batch')) { |
|
| 1605 | + if (empty($old_password) || !function_exists('ldap_modify_batch')) |
|
| 1606 | + { |
|
| 1483 | 1607 | $add["unicodePwd"][0] = $this->encodePassword($password); |
| 1484 | 1608 | |
| 1485 | 1609 | $result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $add); |
| 1486 | 1610 | } |
| 1487 | - else { |
|
| 1611 | + else |
|
| 1612 | + { |
|
| 1488 | 1613 | $mods = array( |
| 1489 | 1614 | array( |
| 1490 | 1615 | "attrib" => "unicodePwd", |
@@ -1499,16 +1624,20 @@ discard block |
||
| 1499 | 1624 | ); |
| 1500 | 1625 | $result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods); |
| 1501 | 1626 | } |
| 1502 | - if ($result === false){ |
|
| 1627 | + if ($result === false) |
|
| 1628 | + { |
|
| 1503 | 1629 | $err = ldap_errno($this->adldap->getLdapConnection()); |
| 1504 | - if ($err) { |
|
| 1630 | + if ($err) |
|
| 1631 | + { |
|
| 1505 | 1632 | $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
| 1506 | - if($err == 53) { |
|
| 1633 | + if($err == 53) |
|
| 1634 | + { |
|
| 1507 | 1635 | $msg .= ' Your password might not match the password policy.'; |
| 1508 | 1636 | } |
| 1509 | 1637 | throw new adLDAPException($msg); |
| 1510 | 1638 | } |
| 1511 | - else { |
|
| 1639 | + else |
|
| 1640 | + { |
|
| 1512 | 1641 | return false; |
| 1513 | 1642 | } |
| 1514 | 1643 | } |
@@ -1526,14 +1655,18 @@ discard block |
||
| 1526 | 1655 | */ |
| 1527 | 1656 | public function modify($username, $attributes, $isGUID = false) |
| 1528 | 1657 | { |
| 1529 | - if ($username === NULL) { return "Missing compulsory field [username]"; } |
|
| 1530 | - if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
|
| 1658 | + if ($username === NULL) |
|
| 1659 | + { |
|
| 1660 | +return "Missing compulsory field [username]"; } |
|
| 1661 | + if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) |
|
| 1662 | + { |
|
| 1531 | 1663 | throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.'); |
| 1532 | 1664 | } |
| 1533 | 1665 | |
| 1534 | 1666 | // Find the dn of the user |
| 1535 | 1667 | $userDn = $this->dn($username, $isGUID); |
| 1536 | - if ($userDn === false) { |
|
| 1668 | + if ($userDn === false) |
|
| 1669 | + { |
|
| 1537 | 1670 | return false; |
| 1538 | 1671 | } |
| 1539 | 1672 | |
@@ -1541,16 +1674,20 @@ discard block |
||
| 1541 | 1674 | $mod = $this->adldap->adldap_schema($attributes); |
| 1542 | 1675 | |
| 1543 | 1676 | // Check to see if this is an enabled status update |
| 1544 | - if (!$mod && !array_key_exists("enabled", $attributes)){ |
|
| 1677 | + if (!$mod && !array_key_exists("enabled", $attributes)) |
|
| 1678 | + { |
|
| 1545 | 1679 | return false; |
| 1546 | 1680 | } |
| 1547 | 1681 | |
| 1548 | 1682 | // Set the account control attribute (only if specified) |
| 1549 | - if (array_key_exists("enabled", $attributes)){ |
|
| 1550 | - if ($attributes["enabled"]){ |
|
| 1683 | + if (array_key_exists("enabled", $attributes)) |
|
| 1684 | + { |
|
| 1685 | + if ($attributes["enabled"]) |
|
| 1686 | + { |
|
| 1551 | 1687 | $controlOptions = array("NORMAL_ACCOUNT"); |
| 1552 | 1688 | } |
| 1553 | - else { |
|
| 1689 | + else |
|
| 1690 | + { |
|
| 1554 | 1691 | $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE"); |
| 1555 | 1692 | } |
| 1556 | 1693 | $mod["userAccountControl"][0] = $this->accountControl($controlOptions); |
@@ -1562,14 +1699,18 @@ discard block |
||
| 1562 | 1699 | { |
| 1563 | 1700 | // Do the update |
| 1564 | 1701 | $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod); |
| 1565 | - if ($result == false) { |
|
| 1566 | - if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***'; |
|
| 1702 | + if ($result == false) |
|
| 1703 | + { |
|
| 1704 | + if (isset($mod['unicodePwd'])) |
|
| 1705 | + { |
|
| 1706 | + $mod['unicodePwd'] = '***'; |
|
| 1707 | + } |
|
| 1567 | 1708 | error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds)); |
| 1568 | 1709 | return false; |
| 1569 | 1710 | } |
| 1570 | 1711 | } |
| 1571 | 1712 | if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password'])) |
| 1572 | - { |
|
| 1713 | + { |
|
| 1573 | 1714 | return false; |
| 1574 | 1715 | } |
| 1575 | 1716 | return true; |
@@ -1591,10 +1732,18 @@ discard block |
||
| 1591 | 1732 | */ |
| 1592 | 1733 | public function create($attributes) |
| 1593 | 1734 | { |
| 1594 | - if (!is_array($attributes)){ return "Attributes must be an array"; } |
|
| 1595 | - if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; } |
|
| 1596 | - if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; } |
|
| 1597 | - if (empty($attributes["container"])){ return "Container attribute must be an array or string."; } |
|
| 1735 | + if (!is_array($attributes)) |
|
| 1736 | + { |
|
| 1737 | +return "Attributes must be an array"; } |
|
| 1738 | + if (!array_key_exists("group_name", $attributes)) |
|
| 1739 | + { |
|
| 1740 | +return "Missing compulsory field [group_name]"; } |
|
| 1741 | + if (!array_key_exists("container", $attributes)) |
|
| 1742 | + { |
|
| 1743 | +return "Missing compulsory field [container]"; } |
|
| 1744 | + if (empty($attributes["container"])) |
|
| 1745 | + { |
|
| 1746 | +return "Container attribute must be an array or string."; } |
|
| 1598 | 1747 | |
| 1599 | 1748 | //$member_array = array(); |
| 1600 | 1749 | //$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com"; |
@@ -1604,16 +1753,21 @@ discard block |
||
| 1604 | 1753 | $add["cn"] = $attributes["group_name"]; |
| 1605 | 1754 | $add["samaccountname"] = $attributes["group_name"]; |
| 1606 | 1755 | $add["objectClass"] = "Group"; |
| 1607 | - if (!empty($attributes["description"])) $add["description"] = $attributes["description"]; |
|
| 1756 | + if (!empty($attributes["description"])) |
|
| 1757 | + { |
|
| 1758 | + $add["description"] = $attributes["description"]; |
|
| 1759 | + } |
|
| 1608 | 1760 | //$add["member"] = $member_array; UNTESTED |
| 1609 | 1761 | |
| 1610 | 1762 | // Determine the container |
| 1611 | - if (is_array($attributes['container'])) { |
|
| 1763 | + if (is_array($attributes['container'])) |
|
| 1764 | + { |
|
| 1612 | 1765 | $attributes["container"] = array_reverse($attributes["container"]); |
| 1613 | 1766 | $attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]); |
| 1614 | 1767 | } |
| 1615 | 1768 | $result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add); |
| 1616 | - if ($result != true) { |
|
| 1769 | + if ($result != true) |
|
| 1770 | + { |
|
| 1617 | 1771 | return false; |
| 1618 | 1772 | } |
| 1619 | 1773 | return true; |
@@ -1643,10 +1797,12 @@ discard block |
||
| 1643 | 1797 | * @author Port by Andreas Gohr <[email protected]> |
| 1644 | 1798 | * @return string |
| 1645 | 1799 | */ |
| 1646 | - public function ldapSlashes($str){ |
|
| 1800 | + public function ldapSlashes($str) |
|
| 1801 | + { |
|
| 1647 | 1802 | return preg_replace_callback( |
| 1648 | 1803 | '/([\x00-\x1F\*\(\)\\\\])/', |
| 1649 | - function ($matches) { |
|
| 1804 | + function ($matches) |
|
| 1805 | + { |
|
| 1650 | 1806 | return "\\".join("", unpack("H2", $matches[1])); |
| 1651 | 1807 | }, |
| 1652 | 1808 | $str |