Merge branch 'MDL-52455' of git://github.com/timhunt/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 21 Dec 2015 12:43:01 +0000 (12:43 +0000)
committerDan Poltawski <dan@moodle.com>
Mon, 21 Dec 2015 12:43:01 +0000 (12:43 +0000)
321 files changed:
.travis.yml
admin/environment.xml
admin/tool/uploaduser/index.php
admin/tool/uploaduser/tests/behat/upload_users.feature [moved from admin/tests/behat/upload_users.feature with 58% similarity]
auth/cas/auth.php
auth/db/tests/db_test.php
auth/email/auth.php
auth/fc/auth.php
auth/fc/fcFPP.php
auth/imap/auth.php
auth/ldap/auth.php
auth/manual/auth.php
auth/mnet/auth.php
auth/nntp/auth.php
auth/nologin/auth.php
auth/none/auth.php
auth/pam/auth.php
auth/pop3/auth.php
auth/radius/auth.php
auth/shibboleth/auth.php
auth/webservice/auth.php
backup/cc/cc_lib/gral_lib/cssparser.php
backup/util/plan/backup_structure_step.class.php
backup/util/plan/restore_structure_step.class.php
backup/util/settings/tests/settings_test.php
blocks/edit_form.php
blocks/rss_client/editfeed.php
blocks/rss_client/tests/cron_test.php
course/moodleform_mod.php
filter/local_settings_form.php
filter/tex/latex.php
grade/export/lib.php
grade/grading/form/guide/guideeditor.php
grade/grading/form/rubric/rubriceditor.php
grade/lib.php
install/lang/ro/moodle.php
lib/adminlib.php
lib/adodb/adodb-active-record.inc.php
lib/adodb/adodb-active-recordx.inc.php
lib/adodb/adodb-csvlib.inc.php
lib/adodb/adodb-datadict.inc.php
lib/adodb/adodb-error.inc.php
lib/adodb/adodb-errorhandler.inc.php
lib/adodb/adodb-errorpear.inc.php
lib/adodb/adodb-exceptions.inc.php
lib/adodb/adodb-iterator.inc.php
lib/adodb/adodb-lib.inc.php
lib/adodb/adodb-memcache.lib.inc.php
lib/adodb/adodb-pager.inc.php
lib/adodb/adodb-pear.inc.php
lib/adodb/adodb-perf.inc.php
lib/adodb/adodb-php4.inc.php
lib/adodb/adodb-time.inc.php
lib/adodb/adodb-xmlschema.inc.php
lib/adodb/adodb-xmlschema03.inc.php
lib/adodb/adodb.inc.php
lib/adodb/datadict/datadict-access.inc.php
lib/adodb/datadict/datadict-db2.inc.php
lib/adodb/datadict/datadict-firebird.inc.php
lib/adodb/datadict/datadict-generic.inc.php
lib/adodb/datadict/datadict-ibase.inc.php
lib/adodb/datadict/datadict-informix.inc.php
lib/adodb/datadict/datadict-mssql.inc.php
lib/adodb/datadict/datadict-mssqlnative.inc.php
lib/adodb/datadict/datadict-mysql.inc.php
lib/adodb/datadict/datadict-oci8.inc.php
lib/adodb/datadict/datadict-postgres.inc.php
lib/adodb/datadict/datadict-sapdb.inc.php
lib/adodb/datadict/datadict-sqlite.inc.php
lib/adodb/datadict/datadict-sybase.inc.php
lib/adodb/drivers/adodb-access.inc.php
lib/adodb/drivers/adodb-ado.inc.php
lib/adodb/drivers/adodb-ado5.inc.php
lib/adodb/drivers/adodb-ado_access.inc.php
lib/adodb/drivers/adodb-ado_mssql.inc.php
lib/adodb/drivers/adodb-ads.inc.php
lib/adodb/drivers/adodb-borland_ibase.inc.php
lib/adodb/drivers/adodb-csv.inc.php
lib/adodb/drivers/adodb-db2.inc.php
lib/adodb/drivers/adodb-db2oci.inc.php
lib/adodb/drivers/adodb-db2ora.inc.php
lib/adodb/drivers/adodb-fbsql.inc.php
lib/adodb/drivers/adodb-firebird.inc.php
lib/adodb/drivers/adodb-ibase.inc.php
lib/adodb/drivers/adodb-informix.inc.php
lib/adodb/drivers/adodb-informix72.inc.php
lib/adodb/drivers/adodb-ldap.inc.php
lib/adodb/drivers/adodb-mssql.inc.php
lib/adodb/drivers/adodb-mssql_n.inc.php
lib/adodb/drivers/adodb-mssqlnative.inc.php
lib/adodb/drivers/adodb-mssqlpo.inc.php
lib/adodb/drivers/adodb-mysql.inc.php
lib/adodb/drivers/adodb-mysqli.inc.php
lib/adodb/drivers/adodb-mysqlpo.inc.php
lib/adodb/drivers/adodb-mysqlt.inc.php
lib/adodb/drivers/adodb-netezza.inc.php
lib/adodb/drivers/adodb-oci8.inc.php
lib/adodb/drivers/adodb-oci805.inc.php
lib/adodb/drivers/adodb-oci8po.inc.php
lib/adodb/drivers/adodb-oci8quercus.inc.php
lib/adodb/drivers/adodb-odbc.inc.php
lib/adodb/drivers/adodb-odbc_db2.inc.php
lib/adodb/drivers/adodb-odbc_mssql.inc.php
lib/adodb/drivers/adodb-odbc_oracle.inc.php
lib/adodb/drivers/adodb-odbtp.inc.php
lib/adodb/drivers/adodb-odbtp_unicode.inc.php
lib/adodb/drivers/adodb-oracle.inc.php
lib/adodb/drivers/adodb-pdo.inc.php
lib/adodb/drivers/adodb-pdo_mssql.inc.php
lib/adodb/drivers/adodb-pdo_mysql.inc.php
lib/adodb/drivers/adodb-pdo_oci.inc.php
lib/adodb/drivers/adodb-pdo_pgsql.inc.php
lib/adodb/drivers/adodb-pdo_sqlite.inc.php
lib/adodb/drivers/adodb-pdo_sqlsrv.inc.php [new file with mode: 0644]
lib/adodb/drivers/adodb-postgres.inc.php
lib/adodb/drivers/adodb-postgres64.inc.php
lib/adodb/drivers/adodb-postgres7.inc.php
lib/adodb/drivers/adodb-postgres8.inc.php
lib/adodb/drivers/adodb-postgres9.inc.php
lib/adodb/drivers/adodb-proxy.inc.php
lib/adodb/drivers/adodb-sapdb.inc.php
lib/adodb/drivers/adodb-sqlanywhere.inc.php
lib/adodb/drivers/adodb-sqlite.inc.php
lib/adodb/drivers/adodb-sqlite3.inc.php
lib/adodb/drivers/adodb-sqlitepo.inc.php
lib/adodb/drivers/adodb-sybase.inc.php
lib/adodb/drivers/adodb-sybase_ase.inc.php
lib/adodb/drivers/adodb-text.inc.php [new file with mode: 0644]
lib/adodb/drivers/adodb-vfp.inc.php
lib/adodb/license.txt
lib/adodb/perf/perf-db2.inc.php
lib/adodb/perf/perf-informix.inc.php
lib/adodb/perf/perf-mssql.inc.php
lib/adodb/perf/perf-mssqlnative.inc.php
lib/adodb/perf/perf-mysql.inc.php
lib/adodb/perf/perf-oci8.inc.php
lib/adodb/perf/perf-postgres.inc.php
lib/adodb/pivottable.inc.php
lib/adodb/readme_moodle.txt
lib/adodb/rsfilter.inc.php
lib/adodb/toexport.inc.php
lib/adodb/tohtml.inc.php
lib/classes/shutdown_manager.php
lib/completionlib.php
lib/componentlib.class.php
lib/dml/moodle_database.php
lib/dml/moodle_transaction.php
lib/editor/tinymce/plugins/spellchecker/classes/SpellChecker.php
lib/editor/tinymce/plugins/spellchecker/classes/utils/JSON.php
lib/editor/tinymce/plugins/spellchecker/classes/utils/Logger.php
lib/editor/tinymce/plugins/spellchecker/readme_moodle.txt
lib/environmentlib.php
lib/evalmath/evalmath.class.php
lib/evalmath/readme_moodle.txt
lib/form/advcheckbox.php
lib/form/autocomplete.php
lib/form/button.php
lib/form/cancel.php
lib/form/checkbox.php
lib/form/dateselector.php
lib/form/datetimeselector.php
lib/form/duration.php
lib/form/editor.php
lib/form/filemanager.php
lib/form/filepicker.php
lib/form/grading.php
lib/form/group.php
lib/form/header.php
lib/form/hidden.php
lib/form/htmleditor.php
lib/form/listing.php
lib/form/modgrade.php
lib/form/modvisible.php
lib/form/password.php
lib/form/passwordunmask.php
lib/form/questioncategory.php
lib/form/radio.php
lib/form/recaptcha.php
lib/form/searchableselector.php
lib/form/select.php
lib/form/selectgroups.php
lib/form/selectwithlink.php
lib/form/selectyesno.php
lib/form/static.php
lib/form/submit.php
lib/form/submitlink.php
lib/form/tags.php
lib/form/text.php
lib/form/textarea.php
lib/form/url.php
lib/form/warning.php
lib/formslib.php
lib/graphlib.php
lib/horde/framework/Horde/Imap/Client/Socket.php
lib/horde/readme_moodle.txt
lib/jabber/XMPP/XMLStream.php
lib/jabber/readme_moodle.txt
lib/lexer.php
lib/mathslib.php
lib/pear/Crypt/CHAP.php
lib/pear/HTML/Common.php
lib/pear/HTML/QuickForm.php
lib/pear/HTML/QuickForm/Renderer.php
lib/pear/HTML/QuickForm/Renderer/Array.php
lib/pear/HTML/QuickForm/Renderer/Default.php
lib/pear/HTML/QuickForm/Renderer/Object.php
lib/pear/HTML/QuickForm/Renderer/Tableless.php
lib/pear/HTML/QuickForm/advcheckbox.php
lib/pear/HTML/QuickForm/autocomplete.php
lib/pear/HTML/QuickForm/button.php
lib/pear/HTML/QuickForm/checkbox.php
lib/pear/HTML/QuickForm/date.php
lib/pear/HTML/QuickForm/element.php
lib/pear/HTML/QuickForm/file.php
lib/pear/HTML/QuickForm/group.php
lib/pear/HTML/QuickForm/header.php
lib/pear/HTML/QuickForm/hidden.php
lib/pear/HTML/QuickForm/hiddenselect.php
lib/pear/HTML/QuickForm/hierselect.php
lib/pear/HTML/QuickForm/html.php
lib/pear/HTML/QuickForm/image.php
lib/pear/HTML/QuickForm/input.php
lib/pear/HTML/QuickForm/link.php
lib/pear/HTML/QuickForm/password.php
lib/pear/HTML/QuickForm/radio.php
lib/pear/HTML/QuickForm/reset.php
lib/pear/HTML/QuickForm/select.php
lib/pear/HTML/QuickForm/static.php
lib/pear/HTML/QuickForm/submit.php
lib/pear/HTML/QuickForm/text.php
lib/pear/HTML/QuickForm/textarea.php
lib/pear/HTML/QuickForm/xbutton.php
lib/pear/PEAR.php
lib/pear/README_MOODLE.txt
lib/phpexcel/PHPExcel/Shared/PCLZip/pclzip.lib.php
lib/phpexcel/PHPExcel/Worksheet/AutoFilter/Column.php
lib/phpexcel/readme_moodle.txt
lib/phpunit/classes/advanced_testcase.php
lib/phpunit/classes/basic_testcase.php
lib/phpunit/classes/database_driver_testcase.php
lib/searchlib.php
lib/setup.php
lib/setuplib.php
lib/tablelib.php
lib/tests/behat/largeforms.feature [new file with mode: 0644]
lib/tests/completionlib_test.php
lib/tests/fixtures/max_input_vars.php [new file with mode: 0644]
lib/tests/fixtures/upload_users_profile.csv [new file with mode: 0644]
lib/tests/rsslib_test.php
lib/tests/setuplib_test.php
lib/thirdpartylibs.xml
lib/upgrade.txt
lib/upgradelib.php
message/tests/behat/message_participants.feature
mnet/environment.php
mnet/peer.php
mnet/xmlrpc/client.php
mnet/xmlrpc/xmlparser.php
mod/assign/feedback/editpdf/fpdi/ASL20.txt [deleted file]
mod/assign/feedback/editpdf/fpdi/LICENSE [new file with mode: 0644]
mod/assign/feedback/editpdf/fpdi/filters/FilterASCII85.php
mod/assign/feedback/editpdf/fpdi/filters/FilterASCII85_FPDI.php [deleted file]
mod/assign/feedback/editpdf/fpdi/filters/FilterASCIIHexDecode.php
mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php
mod/assign/feedback/editpdf/fpdi/filters/FilterLZW_FPDI.php [deleted file]
mod/assign/feedback/editpdf/fpdi/fpdf_tpl.php
mod/assign/feedback/editpdf/fpdi/fpdi.php
mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php
mod/assign/feedback/editpdf/fpdi/fpdi_pdf_parser.php
mod/assign/feedback/editpdf/fpdi/pdf_context.php
mod/assign/feedback/editpdf/fpdi/pdf_parser.php
mod/assign/feedback/editpdf/fpdi/readme_moodle.txt
mod/assign/feedback/editpdf/thirdpartylibs.xml
mod/data/export_form.php
mod/data/field/textarea/field.class.php
mod/lesson/mod_form.php
mod/lti/locallib.php
mod/lti/tests/locallib_test.php
mod/quiz/attemptlib.php
mod/quiz/locallib.php
mod/quiz/renderer.php
mod/quiz/upgrade.txt
mod/scorm/classes/external.php
mod/scorm/datamodels/scorm_12.php
mod/scorm/datamodels/scorm_13.php
mod/scorm/locallib.php
mod/scorm/report/interactions/classes/report.php
mod/scorm/report/interactions/lang/en/scormreport_interactions.php
mod/scorm/report/interactions/responsessettings_form.php
mod/scorm/report/interactions/version.php
mod/scorm/tests/externallib_test.php
mod/wiki/diff/diff_nwiki.php
mod/wiki/diff/difflib.php
mod/wiki/editors/wikieditor.php
mod/wiki/editors/wikifiletable.php
question/category_class.php
question/type/calculated/db/upgradelib.php
question/type/calculated/question.php
question/type/calculated/tests/variablesubstituter_test.php
question/type/calculatedmulti/db/upgradelib.php
question/type/ddimageortext/tests/behat/preview.feature
question/type/ddmarker/tests/behat/preview.feature
question/type/ddwtos/tests/behat/preview.feature
question/type/multianswer/db/upgrade.php
question/type/multianswer/edit_multianswer_form.php
user/filters/cohort.php
user/filters/courserole.php
user/filters/date.php
user/filters/globalrole.php
user/filters/lib.php
user/filters/profilefield.php
user/filters/select.php
user/filters/simpleselect.php
user/filters/text.php
user/filters/yesno.php
user/message.html
user/messageselect.php
user/profile/field/checkbox/field.class.php
user/profile/field/menu/field.class.php
user/profile/lib.php
version.php

index c462b85..08d8338 100644 (file)
@@ -12,21 +12,12 @@ notifications:
 language: php
 
 php:
-    # Moodle supports versions 5.4, 5.5, and 5.6 of PHP.
-    # Order by fastest to slowest.
-    # We currently only run the highest and lowest versions to reduce the load on travis-ci.org.
-    - 5.6
+    # We only run the highest and lowest supported versions to reduce the load on travis-ci.org.
+    - 7.0
+    # - 5.6
     # - 5.5
     - 5.4
 
-    # We hope to offer PHP 7 support in the near future.
-    - nightly
-
-services:
-    # Ensure that memcached and mongodb are running for testing of those MUC stores.
-    - memcached
-    - mongodb
-
 env:
     # Although we want to run these jobs and see failures as quickly as possible, we also want to get the slowest job to
     # start first so that the total run time is not too high.
@@ -50,29 +41,18 @@ matrix:
     # It will not stop the jobs from running.
     fast_finish: true
 
-    # Always allow failure on nightly.
-    # It's a nightly build and failures can happen.
-    allow_failures:
-        - php: nightly
-
     exclude:
-        # PHP 7 is not yet supported for actual runs.
-        # Exclude it by default - we include it for CITEST only later.
-        - php: nightly
-
         # MySQL - it's just too slow.
-        # Exclude it on all versions except for 5.6.
+        # Exclude it on all versions except for 7.0
+        # - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
+        #   php: 5.6
+        #
         # - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
         #   php: 5.5
 
         - env: DB=mysqli   PHPUNIT=true    INSTALL=false   CITEST=false
           php: 5.4
 
-    include:
-        # Attempt to run the CITEST set on PHP 7.
-        - php: nightly
-          env: DB=none     PHPUNIT=false   INSTALL=false   CITEST=true
-
 cache:
     directories:
       - $HOME/.composer/cache
@@ -86,10 +66,6 @@ install:
     # Typically it should be able to use the Composer cache if any other job has already completed before we started here.
     - travis_retry composer install --prefer-dist --no-interaction
 
-    - echo "extension = memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
-    - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
-    - echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
-
 before_script:
     - >
       if [ "$INSTALL" = 'true' -o "$PHPUNIT" = 'true' ];
@@ -144,9 +120,6 @@ before_script:
           sed -i \
             -e "/require_once/i \\\$CFG->phpunit_dataroot = '\/home\/travis\/roots\/phpunit';" \
             -e "/require_once/i \\\$CFG->phpunit_prefix = 'p_';" \
-            -e "/require_once/i define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', '127.0.0.1:11211');" \
-            -e "/require_once/i define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11211');" \
-            -e "/require_once/i define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://localhost:27017');" \
             config.php ;
 
           # Initialise PHPUnit for Moodle.
index 6847483..4bf5798 100644 (file)
       <VENDOR name="oracle" version="10.2" />
     </DATABASE>
     <PHP version="5.4.4" level="required">
-      <RESTRICT function="restrict_php_version_7" message="unsupportedphpversion7" />
     </PHP>
     <PCREUNICODE level="optional">
       <FEEDBACK>
index ad36657..e687fe3 100644 (file)
@@ -232,8 +232,8 @@ if ($formdata = $mform2->is_cancelled()) {
                 if (isset($USER->$key) and is_array($USER->$key)) {
                     // this must be some hacky field that is abusing arrays to store content and format
                     $user->$key = array();
-                    $user->$key['text']   = $value;
-                    $user->$key['format'] = FORMAT_MOODLE;
+                    $user->{$key['text']}   = $value;
+                    $user->{$key['format']} = FORMAT_MOODLE;
                 } else {
                     $user->$key = trim($value);
                 }
@@ -1,4 +1,4 @@
-@core @core_admin @_file_upload
+@tool @tool_uploaduser @_file_upload
 Feature: Upload users
   In order to add users to the system
   As an admin
@@ -39,3 +39,25 @@ Feature: Upload users
     And I follow "Groups"
     And I set the field "groups" to "Section 1 (1)"
     And the "members" select box should contain "Tom Jones"
+
+  @javascript
+  Scenario: Upload users with custom profile fields
+    # Create user profile field.
+    Given I log in as "admin"
+    And I navigate to "User profile fields" node in "Site administration > Users > Accounts"
+    And I set the field "datatype" to "Text area"
+    And I set the following fields to these values:
+      | Short name | superfield  |
+      | Name       | Super field |
+    And I click on "Save changes" "button"
+    # Upload users.
+    When I navigate to "Upload users" node in "Site administration > Users > Accounts"
+    And I upload "lib/tests/fixtures/upload_users_profile.csv" file to "File" filemanager
+    And I press "Upload users"
+    And I press "Upload users"
+    # Check that users were created and the superfield is filled.
+    And I navigate to "Browse list of users" node in "Site administration > Users > Accounts"
+    And I follow "Tom Jones"
+    And I should see "Super field"
+    And I should see "The big guy"
+    And I log out
index afa87dd..4439bcb 100644 (file)
@@ -39,13 +39,23 @@ class auth_plugin_cas extends auth_plugin_ldap {
     /**
      * Constructor.
      */
-    function auth_plugin_cas() {
+    public function __construct() {
         $this->authtype = 'cas';
         $this->roleauth = 'auth_cas';
         $this->errorlogtag = '[AUTH CAS] ';
         $this->init_plugin($this->authtype);
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_cas() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     function prevent_local_passwords() {
         return true;
     }
index 7979bd8..03c186d 100644 (file)
@@ -381,4 +381,22 @@ class auth_db_testcase extends advanced_testcase {
 
         $this->cleanup_auth_database();
     }
+
+    /**
+     * Testing the function _colonscope() from ADOdb.
+     */
+    public function test_adodb_colonscope() {
+        global $CFG;
+        require_once($CFG->libdir.'/adodb/adodb.inc.php');
+        require_once($CFG->libdir.'/adodb/drivers/adodb-odbc.inc.php');
+        require_once($CFG->libdir.'/adodb/drivers/adodb-db2ora.inc.php');
+
+        $this->resetAfterTest(false);
+
+        $sql = "select * from table WHERE column=:1 AND anothercolumn > :0";
+        $arr = array('b', 1);
+        list($sqlout, $arrout) = _colonscope($sql,$arr);
+        $this->assertEquals("select * from table WHERE column=? AND anothercolumn > ?", $sqlout);
+        $this->assertEquals(array(1, 'b'), $arrout);
+    }
 }
index 0a0827d..ffa0e91 100644 (file)
@@ -34,11 +34,21 @@ class auth_plugin_email extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_email() {
+    public function __construct() {
         $this->authtype = 'email';
         $this->config = get_config('auth/email');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_email() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index 75c8bd0..b987992 100644 (file)
@@ -37,11 +37,21 @@ class auth_plugin_fc extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_fc() {
+    public function __construct() {
         $this->authtype = 'fc';
         $this->config = get_config('auth/fc');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_fc() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index c082202..2adc309 100644 (file)
@@ -30,7 +30,7 @@ class fcFPP
     var $_debug = FALSE;    // set to true to see some debug info
 
     // class constructor
-    function fcFPP($host="localhost", $port="3333")
+    public function __construct($host="localhost", $port="3333")
     {
     $this->_hostname = $host;
     $this->_port = $port;
@@ -38,6 +38,12 @@ class fcFPP
     $this->_pwd = "";
     }
 
+    function fcFPP($host="localhost", $port="3333")
+    {
+           debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+           self::__construct($host, $port);
+    }
+
     // open a connection to the FirstClass server
     function open()
     {
index b0d7f9f..3e3e2da 100644 (file)
@@ -35,11 +35,21 @@ class auth_plugin_imap extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_imap() {
+    public function __construct() {
         $this->authtype = 'imap';
         $this->config = get_config('auth/imap');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_imap() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index 96d9bba..9d3a4ad 100644 (file)
@@ -143,13 +143,23 @@ class auth_plugin_ldap extends auth_plugin_base {
     /**
      * Constructor with initialisation.
      */
-    function auth_plugin_ldap() {
+    public function __construct() {
         $this->authtype = 'ldap';
         $this->roleauth = 'auth_ldap';
         $this->errorlogtag = '[AUTH LDAP] ';
         $this->init_plugin($this->authtype);
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_ldap() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index 938aae8..c6df146 100644 (file)
@@ -46,13 +46,23 @@ class auth_plugin_manual extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_manual() {
+    public function __construct() {
         $this->authtype = 'manual';
         $config = get_config(self::COMPONENT_NAME);
         $legacyconfig = get_config(self::LEGACY_COMPONENT_NAME);
         $this->config = (object)array_merge((array)$legacyconfig, (array)$config);
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_manual() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist. (Non-mnet accounts only!)
index f061539..8bd7768 100644 (file)
@@ -35,12 +35,22 @@ class auth_plugin_mnet extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_mnet() {
+    public function __construct() {
         $this->authtype = 'mnet';
         $this->config = get_config('auth_mnet');
         $this->mnet = get_mnet_environment();
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_mnet() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * This function is normally used to determine if the username and password
      * are correct for local logins. Always returns false, as local users do not
index c2ad283..9e8b24c 100644 (file)
@@ -35,11 +35,21 @@ class auth_plugin_nntp extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_nntp() {
+    public function __construct() {
         $this->authtype = 'nntp';
         $this->config = get_config('auth/nntp');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_nntp() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index c3ed391..9a1ec28 100644 (file)
@@ -35,10 +35,20 @@ class auth_plugin_nologin extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_nologin() {
+    public function __construct() {
         $this->authtype = 'nologin';
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_nologin() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Do not allow any login.
      *
index fcfce4c..c002930 100644 (file)
@@ -34,11 +34,21 @@ class auth_plugin_none extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_none() {
+    public function __construct() {
         $this->authtype = 'none';
         $this->config = get_config('auth/none');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_none() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work or don't exist and false
      * if the user exists and the password is wrong.
index fd76a09..b1e2053 100644 (file)
@@ -53,12 +53,22 @@ class auth_plugin_pam extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_pam() {
+    public function __construct() {
         $this->authtype = 'pam';
         $this->config = get_config('auth/pam');
         $this->errormessage = '';
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_pam() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index 5e25aa9..4bfaa0b 100644 (file)
@@ -35,11 +35,21 @@ class auth_plugin_pop3 extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_pop3() {
+    public function __construct() {
         $this->authtype = 'pop3';
         $this->config = get_config('auth/pop3');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_pop3() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index a74369e..24ae5d3 100644 (file)
@@ -38,11 +38,21 @@ class auth_plugin_radius extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_radius() {
+    public function __construct() {
         $this->authtype = 'radius';
         $this->config = get_config('auth/radius');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_radius() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index a4cebd8..be7c25b 100644 (file)
@@ -38,11 +38,21 @@ class auth_plugin_shibboleth extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_shibboleth() {
+    public function __construct() {
         $this->authtype = 'shibboleth';
         $this->config = get_config('auth/shibboleth');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_shibboleth() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index 1fc5694..f027f1c 100644 (file)
@@ -35,11 +35,21 @@ class auth_plugin_webservice extends auth_plugin_base {
     /**
      * Constructor.
      */
-    function auth_plugin_webservice() {
+    public function __construct() {
         $this->authtype = 'webservice';
         $this->config = get_config('auth/webservice');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function auth_plugin_webservice() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Returns true if the username and password work and false if they are
      * wrong or don't exist.
index 3d5653f..fc2e304 100644 (file)
@@ -18,13 +18,23 @@ class cssparser {
   private $css;
   private $html;
 
-  function cssparser($html = true) {
+  public function __construct($html = true) {
     // Register "destructor"
     core_shutdown_manager::register_function(array(&$this, "finalize"));
     $this->html = ($html != false);
     $this->Clear();
   }
 
+  /**
+   * Old syntax of class constructor. Deprecated in PHP7.
+   *
+   * @deprecated since Moodle 3.1
+   */
+  public function cssparser($html = true) {
+      debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+      self::__construct($html);
+  }
+
   function finalize() {
     unset($this->css);
   }
@@ -258,4 +268,4 @@ class cssparser {
     }
     return $result;
   }
-}
\ No newline at end of file
+}
index 5d8cb55..e18ada4 100644 (file)
@@ -183,6 +183,10 @@ abstract class backup_structure_step extends backup_step {
      * @return void
      */
     protected function add_subplugin_structure($subplugintype, $element, $multiple, $plugintype = null, $pluginname = null) {
+        global $CFG;
+        // This global declaration is required, because where we do require_once($backupfile);
+        // That file may in turn try to do require_once($CFG->dirroot ...).
+        // That worked in the past, we should keep it working.
 
         // Verify if this is a BC call for an activity backup. See NOTE above for this special case.
         if ($plugintype === null and $pluginname === null) {
index de7b002..b59ac82 100644 (file)
@@ -313,6 +313,10 @@ abstract class restore_structure_step extends restore_step {
      * @return void
      */
     protected function add_subplugin_structure($subplugintype, $element, $plugintype = null, $pluginname = null) {
+        global $CFG;
+        // This global declaration is required, because where we do require_once($backupfile);
+        // That file may in turn try to do require_once($CFG->dirroot ...).
+        // That worked in the past, we should keep it working.
 
         // Verify if this is a BC call for an activity restore. See NOTE above for this special case.
         if ($plugintype === null and $pluginname === null) {
index 201d29e..45bc4ec 100644 (file)
@@ -126,6 +126,9 @@ class backp_settings_testcase extends basic_testcase {
         } catch (exception $e) {
             $this->assertTrue($e instanceof base_setting_exception);
             $this->assertEquals($e->errorcode, 'incorrect_object_passed');
+        } catch (TypeError $e) {
+            // On PHP7+ we get a TypeError raised, lets check we've the right error.
+            $this->assertRegexp('/must be an instance of backup_setting_ui/', $e->getMessage());
         }
         restore_error_handler();
 
@@ -140,6 +143,9 @@ class backp_settings_testcase extends basic_testcase {
         } catch (exception $e) {
             $this->assertTrue($e instanceof base_setting_exception);
             $this->assertEquals($e->errorcode, 'incorrect_object_passed');
+        } catch (TypeError $e) {
+            // On PHP7+ we get a TypeError raised, lets check we've the right error.
+            $this->assertRegexp('/must be an instance of backup_setting_ui/', $e->getMessage());
         }
         restore_error_handler();
 
@@ -302,6 +308,9 @@ class backp_settings_testcase extends basic_testcase {
         } catch (exception $e) {
             $this->assertTrue($e instanceof backup_setting_exception);
             $this->assertEquals($e->errorcode, 'incorrect_object_passed');
+        } catch (TypeError $e) {
+            // On PHP7+ we get a TypeError raised, lets check we've the right error.
+            $this->assertRegexp('/must be an instance of base_setting/', $e->getMessage());
         }
         restore_error_handler();
 
index ad32113..57c9de8 100644 (file)
@@ -54,7 +54,7 @@ class block_edit_form extends moodleform {
         global $CFG;
         $this->block = $block;
         $this->page = $page;
-        parent::moodleform($actionurl);
+        parent::__construct($actionurl);
     }
 
     function definition() {
index 77e3097..2b6d92a 100644 (file)
@@ -36,7 +36,7 @@ class feed_edit_form extends moodleform {
     function __construct($actionurl, $isadding, $caneditshared) {
         $this->isadding = $isadding;
         $this->caneditshared = $caneditshared;
-        parent::moodleform($actionurl);
+        parent::__construct($actionurl);
     }
 
     function definition() {
index 9069c28..e1299a5 100644 (file)
@@ -40,7 +40,7 @@ class block_rss_client_cron_testcase extends advanced_testcase {
      * than the current time the attempt is skipped.
      */
     public function test_skip() {
-        global $DB;
+        global $DB, $CFG;
         $this->resetAfterTest();
         // Create a RSS feed record with a skip until time set to the future.
         $record = (object) array(
@@ -57,8 +57,12 @@ class block_rss_client_cron_testcase extends advanced_testcase {
 
         $block = new block_rss_client();
         ob_start();
+
         // Silence SimplePie php notices.
-        @$block->cron();
+        $errorlevel = error_reporting($CFG->debug & ~E_USER_NOTICE);
+        $block->cron();
+        error_reporting($errorlevel);
+
         $cronoutput = ob_get_clean();
         $this->assertContains('skipping until ' . userdate($record->skipuntil), $cronoutput);
         $this->assertContains('0 feeds refreshed (took ', $cronoutput);
@@ -68,7 +72,7 @@ class block_rss_client_cron_testcase extends advanced_testcase {
      * Test that when a feed has an error the skip time is increaed correctly.
      */
     public function test_error() {
-        global $DB;
+        global $DB, $CFG;
         $this->resetAfterTest();
         $time = time();
         // A record that has failed before.
@@ -113,8 +117,12 @@ class block_rss_client_cron_testcase extends advanced_testcase {
         // Run the cron.
         $block = new block_rss_client();
         ob_start();
+
         // Silence SimplePie php notices.
-        @$block->cron();
+        $errorlevel = error_reporting($CFG->debug & ~E_USER_NOTICE);
+        $block->cron();
+        error_reporting($errorlevel);
+
         $cronoutput = ob_get_clean();
         $skiptime1 = $record->skiptime * 2;
         $message1 = 'http://example.com/rss Error: could not load/find the RSS feed - skipping for ' . $skiptime1 . ' seconds.';
index 4c8c25f..690dda8 100644 (file)
@@ -58,7 +58,7 @@ abstract class moodleform_mod extends moodleform {
     /** @var object The course format of the current course. */
     protected $courseformat;
 
-    function moodleform_mod($current, $section, $cm, $course) {
+    public function __construct($current, $section, $cm, $course) {
         global $CFG;
 
         $this->current   = $current;
@@ -83,7 +83,17 @@ abstract class moodleform_mod extends moodleform {
         }
         $this->_modname = $matches[1];
         $this->init_features();
-        parent::moodleform('modedit.php');
+        parent::__construct('modedit.php');
+    }
+
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function moodleform_mod($current, $section, $cm, $course) {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct($current, $section, $cm, $course);
     }
 
     protected function init_features() {
index 1721ffa..fce01a1 100644 (file)
@@ -33,7 +33,7 @@ abstract class filter_local_settings_form extends moodleform {
     public function __construct($submiturl, $filter, $context) {
         $this->filter = $filter;
         $this->context = $context;
-        parent::moodleform($submiturl);
+        parent::__construct($submiturl);
     }
 
     /**
index a1966da..7eb522e 100644 (file)
@@ -15,7 +15,7 @@
          * external 'helper' binaries.
          * Other platforms could/should be added
          */
-        function latex() {
+        public function __construct() {
             global $CFG;
 
             // construct directory structure
             make_temp_directory('latex');
         }
 
+        /**
+         * Old syntax of class constructor. Deprecated in PHP7.
+         *
+         * @deprecated since Moodle 3.1
+         */
+        public function latex() {
+            debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+            self::__construct();
+        }
+
         /**
          * Accessor function for support_platform field.
          * @return boolean value of supported_platform
index e817943..bf7b981 100644 (file)
@@ -625,11 +625,21 @@ class grade_export_update_buffer {
     /**
      * Constructor - creates the buffer and initialises the time stamp
      */
-    public function grade_export_update_buffer() {
+    public function __construct() {
         $this->update_list = array();
         $this->export_time = time();
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function grade_export_update_buffer() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     public function flush($buffersize) {
         global $CFG, $DB;
 
index 902834c..a6e43a1 100644 (file)
@@ -53,8 +53,18 @@ class moodlequickform_guideeditor extends HTML_QuickForm_input {
      * @param string $elementlabel
      * @param array $attributes
      */
+    public function __construct($elementname=null, $elementlabel=null, $attributes=null) {
+        parent::__construct($elementname, $elementlabel, $attributes);
+    }
+
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
     public function moodlequickform_guideeditor($elementname=null, $elementlabel=null, $attributes=null) {
-        parent::HTML_QuickForm_input($elementname, $elementlabel, $attributes);
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct($elementname, $elementlabel, $attributes);
     }
 
     /**
index b3cc5bf..d990126 100644 (file)
@@ -60,8 +60,18 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
      * @param string $elementLabel
      * @param array $attributes
      */
-    function MoodleQuickForm_rubriceditor($elementName=null, $elementLabel=null, $attributes=null) {
-        parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
+    public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
+        parent::__construct($elementName, $elementLabel, $attributes);
+    }
+
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function MoodleQuickForm_rubriceditor($elementName=null, $elementLabel=null, $attributes=null) {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct($elementName, $elementLabel, $attributes);
     }
 
     /**
index 3a04829..2696dca 100644 (file)
@@ -1085,7 +1085,7 @@ class grade_plugin_return {
      *
      * @param array $params - associative array with return parameters, if null parameter are taken from _GET or _POST
      */
-    public function grade_plugin_return($params = null) {
+    public function __construct($params = null) {
         if (empty($params)) {
             $this->type     = optional_param('gpr_type', null, PARAM_SAFEDIR);
             $this->plugin   = optional_param('gpr_plugin', null, PARAM_PLUGIN);
@@ -1102,6 +1102,16 @@ class grade_plugin_return {
         }
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function grade_plugin_return($params = null) {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct($params);
+    }
+
     /**
      * Returns return parameters as options array suitable for buttons.
      * @return array options
@@ -2033,7 +2043,7 @@ class grade_seq extends grade_structure {
      * @param bool $category_grade_last category grade item is the last child
      * @param bool $nooutcomes Whether or not outcomes should be included
      */
-    public function grade_seq($courseid, $category_grade_last=false, $nooutcomes=false) {
+    public function __construct($courseid, $category_grade_last=false, $nooutcomes=false) {
         global $USER, $CFG;
 
         $this->courseid   = $courseid;
@@ -2049,6 +2059,16 @@ class grade_seq extends grade_structure {
         }
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function grade_seq($courseid, $category_grade_last=false, $nooutcomes=false) {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct($courseid, $category_grade_last, $nooutcomes);
+    }
+
     /**
      * Static recursive helper - makes the grade_item for category the last children
      *
@@ -2185,7 +2205,7 @@ class grade_tree extends grade_structure {
      * @param array $collapsed array of collapsed categories
      * @param bool  $nooutcomes Whether or not outcomes should be included
      */
-    public function grade_tree($courseid, $fillers=true, $category_grade_last=false,
+    public function __construct($courseid, $fillers=true, $category_grade_last=false,
                                $collapsed=null, $nooutcomes=false) {
         global $USER, $CFG, $COURSE, $DB;
 
@@ -2229,6 +2249,17 @@ class grade_tree extends grade_structure {
 
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function grade_tree($courseid, $fillers=true, $category_grade_last=false,
+                               $collapsed=null, $nooutcomes=false) {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct($courseid, $fillers, $category_grade_last, $collapsed, $nooutcomes);
+    }
+
     /**
      * Static recursive helper - removes items from collapsed categories
      *
index be0a958..067f640 100644 (file)
@@ -31,6 +31,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 $string['language'] = 'Limba';
+$string['moodlelogo'] = 'Logo Moodle';
 $string['next'] = 'Următorul';
 $string['previous'] = 'Precedent';
 $string['reload'] = 'Reîncarcă';
index fc177f4..81c95d0 100644 (file)
@@ -4936,11 +4936,21 @@ class admin_setting_special_gradelimiting extends admin_setting_configcheckbox {
     /**
      * Calls parent::__construct with specific arguments
      */
-    function admin_setting_special_gradelimiting() {
+    public function __construct() {
         parent::__construct('unlimitedgrades', get_string('unlimitedgrades', 'grades'),
             get_string('unlimitedgrades_help', 'grades'), '0', '1', '0');
     }
 
+    /**
+     * Old syntax of class constructor. Deprecated in PHP7.
+     *
+     * @deprecated since Moodle 3.1
+     */
+    public function admin_setting_special_gradelimiting() {
+        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
+        self::__construct();
+    }
+
     /**
      * Force site regrading
      */
index 607fa94..ad9533c 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 /*
 
-@version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+@version   v5.20.1  06-Dec-2015
+@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+@copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Latest version is available at http://adodb.sourceforge.net
 
   Released under both BSD license and Lesser GPL library license.
@@ -52,10 +54,13 @@ function ADODB_SetDatabaseAdapter(&$db, $index=false)
 
                foreach($_ADODB_ACTIVE_DBS as $k => $d) {
                        if (PHP_VERSION >= 5) {
-                               if ($d->db === $db) return $k;
+                               if ($d->db === $db) {
+                                       return $k;
+                               }
                        } else {
-                               if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database)
+                               if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) {
                                        return $k;
+                               }
                        }
                }
 
@@ -63,8 +68,9 @@ function ADODB_SetDatabaseAdapter(&$db, $index=false)
                $obj->db = $db;
                $obj->tables = array();
 
-               if ($index == false) $index = sizeof($_ADODB_ACTIVE_DBS);
-
+               if ($index == false) {
+                       $index = sizeof($_ADODB_ACTIVE_DBS);
+               }
 
                $_ADODB_ACTIVE_DBS[$index] = $obj;
 
@@ -92,7 +98,9 @@ class ADODB_Active_Record {
        static function UseDefaultValues($bool=null)
        {
        global $ADODB_ACTIVE_DEFVALS;
-               if (isset($bool)) $ADODB_ACTIVE_DEFVALS = $bool;
+               if (isset($bool)) {
+                       $ADODB_ACTIVE_DEFVALS = $bool;
+               }
                return $ADODB_ACTIVE_DEFVALS;
        }
 
@@ -120,14 +128,21 @@ class ADODB_Active_Record {
                }
 
                if (!$table) {
-                       if (!empty($this->_table)) $table = $this->_table;
+                       if (!empty($this->_table)) {
+                               $table = $this->_table;
+                       }
                        else $table = $this->_pluralize(get_class($this));
                }
                $this->foreignName = strtolower(get_class($this)); // CFR: default foreign name
                if ($db) {
                        $this->_dbat = ADODB_Active_Record::SetDatabaseAdapter($db);
                } else if (!isset($this->_dbat)) {
-                       if (sizeof($_ADODB_ACTIVE_DBS) == 0) $this->Error("No database connection set; use ADOdb_Active_Record::SetDatabaseAdapter(\$db)",'ADODB_Active_Record::__constructor');
+                       if (sizeof($_ADODB_ACTIVE_DBS) == 0) {
+                               $this->Error(
+                                       "No database connection set; use ADOdb_Active_Record::SetDatabaseAdapter(\$db)",
+                                       'ADODB_Active_Record::__constructor'
+                               );
+                       }
                        end($_ADODB_ACTIVE_DBS);
                        $this->_dbat = key($_ADODB_ACTIVE_DBS);
                }
@@ -146,7 +161,9 @@ class ADODB_Active_Record {
 
        function _pluralize($table)
        {
-               if (!ADODB_Active_Record::$_changeNames) return $table;
+               if (!ADODB_Active_Record::$_changeNames) {
+                       return $table;
+               }
 
                $ut = strtoupper($table);
                $len = strlen($table);
@@ -160,8 +177,9 @@ class ADODB_Active_Record {
                case 'X':
                        return $table.'es';
                case 'H':
-                       if ($lastc2 == 'CH' || $lastc2 == 'SH')
+                       if ($lastc2 == 'CH' || $lastc2 == 'SH') {
                                return $table.'es';
+                       }
                default:
                        return $table.'s';
                }
@@ -172,24 +190,28 @@ class ADODB_Active_Record {
        function _singularize($tables)
        {
 
-               if (!ADODB_Active_Record::$_changeNames) return $table;
+               if (!ADODB_Active_Record::$_changeNames) {
+                       return $table;
+               }
 
                $ut = strtoupper($tables);
                $len = strlen($tables);
-               if($ut[$len-1] != 'S')
+               if($ut[$len-1] != 'S') {
                        return $tables; // I know...forget oxen
-               if($ut[$len-2] != 'E')
+               }
+               if($ut[$len-2] != 'E') {
                        return substr($tables, 0, $len-1);
-               switch($ut[$len-3])
-               {
+               }
+               switch($ut[$len-3]) {
                        case 'S':
                        case 'X':
                                return substr($tables, 0, $len-2);
                        case 'I':
                                return substr($tables, 0, $len-3) . 'y';
                        case 'H';
-                               if($ut[$len-4] == 'C' || $ut[$len-4] == 'S')
+                               if($ut[$len-4] == 'C' || $ut[$len-4] == 'S') {
                                        return substr($tables, 0, $len-2);
+                               }
                        default:
                                return substr($tables, 0, $len-1); // ?
                }
@@ -216,7 +238,9 @@ class ADODB_Active_Record {
        // use when you don't want ADOdb to auto-pluralize tablename
        static function TableKeyHasMany($table, $tablePKey, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
        {
-               if (!is_array($tablePKey)) $tablePKey = array($tablePKey);
+               if (!is_array($tablePKey)) {
+                       $tablePKey = array($tablePKey);
+               }
                $ar = new ADODB_Active_Record($table,$tablePKey);
                $ar->hasMany($foreignRef, $foreignKey, $foreignClass);
        }
@@ -260,7 +284,9 @@ class ADODB_Active_Record {
 
        static function TableKeyBelongsTo($table, $tablePKey, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
-               if (!is_array($tablePKey)) $tablePKey = array($tablePKey);
+               if (!is_array($tablePKey)) {
+                       $tablePKey = array($tablePKey);
+               }
                $ar = new ADOdb_Active_Record($table, $tablePKey);
                $ar->belongsTo($foreignRef, $foreignKey, $parentKey, $parentClass);
        }
@@ -289,24 +315,34 @@ class ADODB_Active_Record {
        {
                $extras = array();
                $table = $this->TableInfo();
-               if ($limit >= 0) $extras['limit'] = $limit;
-               if ($offset >= 0) $extras['offset'] = $offset;
+               if ($limit >= 0) {
+                       $extras['limit'] = $limit;
+               }
+               if ($offset >= 0) {
+                       $extras['offset'] = $offset;
+               }
 
-               if (strlen($whereOrderBy))
-                       if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy))
-                               if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy))
-                                       $whereOrderBy = 'AND '.$whereOrderBy;
+               if (strlen($whereOrderBy)) {
+                       if (!preg_match('/^[ \n\r]*AND/i', $whereOrderBy)) {
+                               if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i', $whereOrderBy)) {
+                                       $whereOrderBy = 'AND ' . $whereOrderBy;
+                               }
+                       }
+               }
 
-               if(!empty($table->_belongsTo[$name]))
-               {
+               if(!empty($table->_belongsTo[$name])) {
                        $obj = $table->_belongsTo[$name];
                        $columnName = $obj->foreignKey;
-                       if(empty($this->$columnName))
+                       if(empty($this->$columnName)) {
                                $this->$name = null;
-                       else
-                       {
-                               if ($obj->parentKey) $key = $obj->parentKey;
-                               else $key = reset($table->keys);
+                       }
+                       else {
+                               if ($obj->parentKey) {
+                                       $key = $obj->parentKey;
+                               }
+                               else {
+                                       $key = reset($table->keys);
+                               }
 
                                $arrayOfOne = $obj->Find($key.'='.$this->$columnName.' '.$whereOrderBy,false,false,$extras);
                                if ($arrayOfOne) {
@@ -315,8 +351,7 @@ class ADODB_Active_Record {
                                }
                        }
                }
-               if(!empty($table->_hasMany[$name]))
-               {
+               if(!empty($table->_hasMany[$name])) {
                        $obj = $table->_hasMany[$name];
                        $key = reset($table->keys);
                        $id = @$this->$key;
@@ -325,7 +360,9 @@ class ADODB_Active_Record {
                                $id = $db->qstr($id);
                        }
                        $objs = $obj->Find($obj->foreignKey.'='.$id. ' '.$whereOrderBy,false,false,$extras);
-                       if (!$objs) $objs = array();
+                       if (!$objs) {
+                               $objs = array();
+                       }
                        $this->$name = $objs;
                        return $objs;
                }
@@ -349,10 +386,12 @@ class ADODB_Active_Record {
 
                        $acttab = $tables[$tableat];
                        foreach($acttab->flds as $name => $fld) {
-                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
-                               $this->$name = $fld->default_value;
-                       else
-                               $this->$name = null;
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) {
+                                       $this->$name = $fld->default_value;
+                               }
+                               else {
+                                       $this->$name = null;
+                               }
                        }
                        return;
                }
@@ -368,10 +407,12 @@ class ADODB_Active_Record {
                                // ideally, you should cache at least 32 secs
 
                                foreach($acttab->flds as $name => $fld) {
-                                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
+                                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) {
                                                $this->$name = $fld->default_value;
-                                       else
+                                       }
+                                       else {
                                                $this->$name = null;
+                                       }
                                }
 
                                $activedb->tables[$table] = $acttab;
@@ -387,11 +428,15 @@ class ADODB_Active_Record {
 
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
-               if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
+               if ($db->fetchMode !== false) {
+                       $savem = $db->SetFetchMode(false);
+               }
 
                $cols = $db->MetaColumns($table);
 
-               if (isset($savem)) $db->SetFetchMode($savem);
+               if (isset($savem)) {
+                       $db->SetFetchMode($savem);
+               }
                $ADODB_FETCH_MODE = $save;
 
                if (!$cols) {
@@ -403,7 +448,9 @@ class ADODB_Active_Record {
                        if (isset($fld->primary_key)) {
                                $pkeys = array();
                                foreach($cols as $name => $fld) {
-                                       if (!empty($fld->primary_key)) $pkeys[] = $name;
+                                       if (!empty($fld->primary_key)) {
+                                               $pkeys[] = $name;
+                                       }
                                }
                        } else
                                $pkeys = $this->GetPrimaryKeys($db, $table);
@@ -420,10 +467,12 @@ class ADODB_Active_Record {
                case 0:
                        foreach($cols as $name => $fldobj) {
                                $name = strtolower($name);
-                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
-                    $this->$name = $fldobj->default_value;
-                else
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) {
+                                       $this->$name = $fldobj->default_value;
+                               }
+                               else {
                                        $this->$name = null;
+                               }
                                $attr[$name] = $fldobj;
                        }
                        foreach($pkeys as $k => $name) {
@@ -435,10 +484,12 @@ class ADODB_Active_Record {
                        foreach($cols as $name => $fldobj) {
                                $name = strtoupper($name);
 
-                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
-                    $this->$name = $fldobj->default_value;
-                else
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) {
+                                       $this->$name = $fldobj->default_value;
+                               }
+                               else {
                                        $this->$name = null;
+                               }
                                $attr[$name] = $fldobj;
                        }
 
@@ -450,10 +501,12 @@ class ADODB_Active_Record {
                        foreach($cols as $name => $fldobj) {
                                $name = ($fldobj->name);
 
-                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
-                    $this->$name = $fldobj->default_value;
-                else
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) {
+                                       $this->$name = $fldobj->default_value;
+                               }
+                               else {
                                        $this->$name = null;
+                               }
                                $attr[$name] = $fldobj;
                        }
                        foreach($pkeys as $k => $name) {
@@ -468,14 +521,18 @@ class ADODB_Active_Record {
                if ($ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR) {
                        $activetab->_created = time();
                        $s = serialize($activetab);
-                       if (!function_exists('adodb_write_file')) include(ADODB_DIR.'/adodb-csvlib.inc.php');
+                       if (!function_exists('adodb_write_file')) {
+                               include(ADODB_DIR.'/adodb-csvlib.inc.php');
+                       }
                        adodb_write_file($fname,$s);
                }
                if (isset($activedb->tables[$table])) {
                        $oldtab = $activedb->tables[$table];
 
-                       if ($oldtab) $activetab->_belongsTo = $oldtab->_belongsTo;
-                       if ($oldtab) $activetab->_hasMany = $oldtab->_hasMany;
+                       if ($oldtab) {
+                               $activetab->_belongsTo = $oldtab->_belongsTo;
+                               $activetab->_hasMany = $oldtab->_hasMany;
+                       }
                }
                $activedb->tables[$table] = $activetab;
        }
@@ -493,17 +550,26 @@ class ADODB_Active_Record {
                $fn = get_class($this).'::'.$fn;
                $this->_lasterr = $fn.': '.$err;
 
-               if ($this->_dbat < 0) $db = false;
+               if ($this->_dbat < 0) {
+                       $db = false;
+               }
                else {
                        $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
                        $db = $activedb->db;
                }
 
                if (function_exists('adodb_throw')) {
-                       if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
-                       else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
-               } else
-                       if (!$db || $db->debug) ADOConnection::outp($this->_lasterr);
+                       if (!$db) {
+                               adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
+                       }
+                       else {
+                               adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
+                       }
+               } else {
+                       if (!$db || $db->debug) {
+                               ADOConnection::outp($this->_lasterr);
+                       }
+               }
 
        }
 
@@ -511,18 +577,26 @@ class ADODB_Active_Record {
        function ErrorMsg()
        {
                if (!function_exists('adodb_throw')) {
-                       if ($this->_dbat < 0) $db = false;
-                       else $db = $this->DB();
+                       if ($this->_dbat < 0) {
+                               $db = false;
+                       }
+                       else {
+                               $db = $this->DB();
+                       }
 
                        // last error could be database error too
-                       if ($db && $db->ErrorMsg()) return $db->ErrorMsg();
+                       if ($db && $db->ErrorMsg()) {
+                               return $db->ErrorMsg();
+                       }
                }
                return $this->_lasterr;
        }
 
        function ErrorNo()
        {
-               if ($this->_dbat < 0) return -9999; // no database connection...
+               if ($this->_dbat < 0) {
+                       return -9999; // no database connection...
+               }
                $db = $this->DB();
 
                return (int) $db->ErrorNo();
@@ -558,8 +632,11 @@ class ADODB_Active_Record {
        // So, I find that for myTable, I want to reload an active record after saving it. -- Malcolm Cook
        function Reload()
        {
-               $db =& $this->DB(); if (!$db) return false;
-               $table =& $this->TableInfo();
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
+               $table = $this->TableInfo();
                $where = $this->GenWhere($db, $table);
                return($this->Load($where));
        }
@@ -581,44 +658,47 @@ class ADODB_Active_Record {
 
                $table = $this->TableInfo();
                if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) {
-            # <AP>
-            $bad_size = TRUE;
-            if (sizeof($row) == 2 * sizeof($table->flds)) {
-                // Only keep string keys
-                $keys = array_filter(array_keys($row), 'is_string');
-                if (sizeof($keys) == sizeof($table->flds))
-                    $bad_size = FALSE;
-            }
-            if ($bad_size) {
+                       # <AP>
+                       $bad_size = TRUE;
+                       if (sizeof($row) == 2 * sizeof($table->flds)) {
+                               // Only keep string keys
+                               $keys = array_filter(array_keys($row), 'is_string');
+                               if (sizeof($keys) == sizeof($table->flds)) {
+                                       $bad_size = FALSE;
+                               }
+                       }
+                       if ($bad_size) {
                        $this->Error("Table structure of $this->_table has changed","Load");
                        return false;
                }
-            # </AP>
+                       # </AP>
                }
-        else
+               else
                        $keys = array_keys($row);
 
-        # <AP>
-        reset($keys);
-        $this->_original = array();
+               # <AP>
+               reset($keys);
+               $this->_original = array();
                foreach($table->flds as $name=>$fld) {
-            $value = $row[current($keys)];
+                       $value = $row[current($keys)];
                        $this->$name = $value;
-            $this->_original[] = $value;
-            next($keys);
+                       $this->_original[] = $value;
+                       next($keys);
                }
 
-        # </AP>
+               # </AP>
                return true;
        }
 
        // get last inserted id for INSERT
        function LastInsertID(&$db,$fieldname)
        {
-               if ($db->hasInsertID)
+               if ($db->hasInsertID) {
                        $val = $db->Insert_ID($this->_table,$fieldname);
-               else
+               }
+               else {
                        $val = false;
+               }
 
                if (is_null($val) || $val === false) {
                        // this might not work reliably in multi-user environment
@@ -632,19 +712,25 @@ class ADODB_Active_Record {
        {
                switch($t) {
                case 'L':
-                       if (strpos($db->databaseType,'postgres') !== false) return $db->qstr($val);
+                       if (strpos($db->databaseType,'postgres') !== false) {
+                               return $db->qstr($val);
+                       }
                case 'D':
                case 'T':
-                       if (empty($val)) return 'null';
-
+                       if (empty($val)) {
+                               return 'null';
+                       }
                case 'B':
                case 'N':
                case 'C':
                case 'X':
-                       if (is_null($val)) return 'null';
+                       if (is_null($val)) {
+                               return 'null';
+                       }
 
                        if (strlen($val)>0 &&
-                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) {
+                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")
+                       ) {
                                return $db->qstr($val);
                                break;
                        }
@@ -672,8 +758,15 @@ class ADODB_Active_Record {
 
        function _QName($n,$db=false)
        {
-               if (!ADODB_Active_Record::$_quoteNames) return $n;
-               if (!$db) $db = $this->DB(); if (!$db) return false;
+               if (!ADODB_Active_Record::$_quoteNames) {
+                       return $n;
+               }
+               if (!$db) {
+                       $db = $this->DB();
+                       if (!$db) {
+                               return false;
+                       }
+               }
                return $db->nameQuote.$n.$db->nameQuote;
        }
 
@@ -683,23 +776,32 @@ class ADODB_Active_Record {
        {
        global $ADODB_FETCH_MODE;
 
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $this->_where = $where;
 
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-               if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
+               if ($db->fetchMode !== false) {
+                       $savem = $db->SetFetchMode(false);
+               }
 
                $qry = "select * from ".$this->_table;
 
                if($where) {
                        $qry .= ' WHERE '.$where;
                }
-               if ($lock) $qry .= $this->lockMode;
+               if ($lock) {
+                       $qry .= $this->lockMode;
+               }
 
                $row = $db->GetRow($qry,$bindarr);
 
-               if (isset($savem)) $db->SetFetchMode($savem);
+               if (isset($savem)) {
+                       $db->SetFetchMode($savem);
+               }
                $ADODB_FETCH_MODE = $save;
 
                return $this->Set($row);
@@ -714,25 +816,29 @@ class ADODB_Active_Record {
        # see http://phplens.com/lens/lensforum/msgs.php?id=17795
        function Reset()
        {
-        $this->_where=null;
-        $this->_saved = false;
-        $this->_lasterr = false;
-        $this->_original = false;
-        $vars=get_object_vars($this);
-        foreach($vars as $k=>$v){
-               if(substr($k,0,1)!=='_'){
-                       $this->{$k}=null;
-               }
-        }
-        $this->foreignName=strtolower(get_class($this));
-        return true;
-    }
+               $this->_where=null;
+               $this->_saved = false;
+               $this->_lasterr = false;
+               $this->_original = false;
+               $vars=get_object_vars($this);
+               foreach($vars as $k=>$v){
+                       if(substr($k,0,1)!=='_'){
+                               $this->{$k}=null;
+                       }
+               }
+               $this->foreignName=strtolower(get_class($this));
+               return true;
+       }
 
        // false on error
        function Save()
        {
-               if ($this->_saved) $ok = $this->Update();
-               else $ok = $this->Insert();
+               if ($this->_saved) {
+                       $ok = $this->Update();
+               }
+               else {
+                       $ok = $this->Insert();
+               }
 
                return $ok;
        }
@@ -741,7 +847,10 @@ class ADODB_Active_Record {
        // false on error
        function Insert()
        {
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $cnt = 0;
                $table = $this->TableInfo();
 
@@ -791,7 +900,10 @@ class ADODB_Active_Record {
 
        function Delete()
        {
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $table = $this->TableInfo();
 
                $where = $this->GenWhere($db,$table);
@@ -804,7 +916,10 @@ class ADODB_Active_Record {
        // returns an array of active record objects
        function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array())
        {
-               $db = $this->DB(); if (!$db || empty($this->_table)) return false;
+               $db = $this->DB();
+               if (!$db || empty($this->_table)) {
+                       return false;
+               }
                $arr = $db->GetActiveRecordsClass(get_class($this),$this->_table, $whereOrderBy,$bindarr,$pkeysArr,$extra);
                return $arr;
        }
@@ -814,7 +929,10 @@ class ADODB_Active_Record {
        {
        global $ADODB_ASSOC_CASE;
 
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $table = $this->TableInfo();
 
                $pkey = $table->keys;
@@ -824,7 +942,9 @@ class ADODB_Active_Record {
                        /*
                        if (is_null($val)) {
                                if (isset($fld->not_null) && $fld->not_null) {
-                                       if (isset($fld->default_value) && strlen($fld->default_value)) continue;
+                                       if (isset($fld->default_value) && strlen($fld->default_value)) {
+                                               continue;
+                                       }
                                        else {
                                                $this->Error("Cannot update null into $name","Replace");
                                                return false;
@@ -832,25 +952,31 @@ class ADODB_Active_Record {
                                }
                        }*/
                        if (is_null($val) && !empty($fld->auto_increment)) {
-               continue;
-            }
+                               continue;
+                       }
 
-                       if (is_array($val)) continue;
+                       if (is_array($val)) {
+                               continue;
+                       }
 
                        $t = $db->MetaType($fld->type);
                        $arr[$name] = $this->doquote($db,$val,$t);
                        $valarr[] = $val;
                }
 
-               if (!is_array($pkey)) $pkey = array($pkey);
-
+               if (!is_array($pkey)) {
+                       $pkey = array($pkey);
+               }
 
-               if ($ADODB_ASSOC_CASE == 0)
+               if ($ADODB_ASSOC_CASE == 0) {
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtolower($v);
-               elseif ($ADODB_ASSOC_CASE == 1)
-                       foreach($pkey as $k => $v)
+               }
+               elseif ($ADODB_ASSOC_CASE == 1) {
+                       foreach($pkey as $k => $v) {
                                $pkey[$k] = strtoupper($v);
+                       }
+               }
 
                $ok = $db->Replace($this->_table,$arr,$pkey);
                if ($ok) {
@@ -877,7 +1003,10 @@ class ADODB_Active_Record {
        // returns 0 on error, 1 on update, -1 if no change in data (no update)
        function Update()
        {
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $table = $this->TableInfo();
 
                $where = $this->GenWhere($db, $table);
@@ -896,12 +1025,15 @@ class ADODB_Active_Record {
                        $val = $this->$name;
                        $neworig[] = $val;
 
-                       if (isset($table->keys[$name]) || is_array($val))
+                       if (isset($table->keys[$name]) || is_array($val)) {
                                continue;
+                       }
 
                        if (is_null($val)) {
                                if (isset($fld->not_null) && $fld->not_null) {
-                                       if (isset($fld->default_value) && strlen($fld->default_value)) continue;
+                                       if (isset($fld->default_value) && strlen($fld->default_value)) {
+                                               continue;
+                                       }
                                        else {
                                                $this->Error("Cannot set field $name to NULL","Update");
                                                return false;
@@ -909,9 +1041,13 @@ class ADODB_Active_Record {
                                }
                        }
 
-                       if (isset($this->_original[$i]) && strcmp($val,$this->_original[$i]) == 0) continue;
+                       if (isset($this->_original[$i]) && strcmp($val,$this->_original[$i]) == 0) {
+                               continue;
+                       }
 
-                       if (is_null($this->_original[$i]) && is_null($val)) continue;
+                       if (is_null($this->_original[$i]) && is_null($val)) {
+                               continue;
+                       }
 
                        $valarr[] = $val;
                        $pairs[] = $this->_QName($name,$db).'='.$db->Param($cnt);
@@ -919,7 +1055,10 @@ class ADODB_Active_Record {
                }
 
 
-               if (!$cnt) return -1;
+               if (!$cnt) {
+                       return -1;
+               }
+
                $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where;
                $ok = $db->Execute($sql,$valarr);
                if ($ok) {
@@ -932,7 +1071,9 @@ class ADODB_Active_Record {
        function GetAttributeNames()
        {
                $table = $this->TableInfo();
-               if (!$table) return false;
+               if (!$table) {
+                       return false;
+               }
                return array_keys($table->flds);
        }
 
@@ -947,10 +1088,10 @@ global $_ADODB_ACTIVE_DBS;
        $save = $db->SetFetchMode(ADODB_FETCH_NUM);
        $qry = "select * from ".$table;
 
-       if (!empty($whereOrderBy))
+       if (!empty($whereOrderBy)) {
                $qry .= ' WHERE '.$whereOrderBy;
-       if(isset($extra['limit']))
-       {
+       }
+       if(isset($extra['limit'])) {
                $rows = false;
                if(isset($extra['offset'])) {
                        $rs = $db->SelectLimit($qry, $extra['limit'], $extra['offset'],$bindarr);
index e820144..771a086 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 /*
 
-@version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+@version   v5.20.1  06-Dec-2015
+@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+@copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Latest version is available at http://adodb.sourceforge.net
 
   Released under both BSD license and Lesser GPL library license.
@@ -66,10 +68,13 @@ function ADODB_SetDatabaseAdapter(&$db)
 
                foreach($_ADODB_ACTIVE_DBS as $k => $d) {
                        if (PHP_VERSION >= 5) {
-                               if ($d->db === $db) return $k;
+                               if ($d->db === $db) {
+                                       return $k;
+                               }
                        } else {
-                               if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database)
+                               if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) {
                                        return $k;
+                               }
                        }
                }
 
@@ -101,7 +106,9 @@ class ADODB_Active_Record {
        static function UseDefaultValues($bool=null)
        {
        global $ADODB_ACTIVE_DEFVALS;
-               if (isset($bool)) $ADODB_ACTIVE_DEFVALS = $bool;
+               if (isset($bool)) {
+                       $ADODB_ACTIVE_DEFVALS = $bool;
+               }
                return $ADODB_ACTIVE_DEFVALS;
        }
 
@@ -137,15 +144,13 @@ class ADODB_Active_Record {
                        $pkeyarr = false;
                }
 
-               if($table)
-               {
+               if($table) {
                        // table argument exists. It is expected to be
                        // already plural form.
                        $this->_pTable = $table;
                        $this->_sTable = $this->_singularize($this->_pTable);
                }
-               else
-               {
+               else {
                        // We will use current classname as table name.
                        // We need to pluralize it for the real table name.
                        $this->_sTable = strtolower(get_class($this));
@@ -161,7 +166,12 @@ class ADODB_Active_Record {
                        $this->_dbat = sizeof($_ADODB_ACTIVE_DBS)-1;
 
 
-               if ($this->_dbat < 0) $this->Error("No database connection set; use ADOdb_Active_Record::SetDatabaseAdapter(\$db)",'ADODB_Active_Record::__constructor');
+               if ($this->_dbat < 0) {
+                       $this->Error(
+                               "No database connection set; use ADOdb_Active_Record::SetDatabaseAdapter(\$db)",
+                               'ADODB_Active_Record::__constructor'
+                       );
+               }
 
                $this->_tableat = $this->_table; # reserved for setting the assoc value to a non-table name, eg. the sql string in future
 
@@ -169,8 +179,7 @@ class ADODB_Active_Record {
                // but there was no way to ask it to do that.
                $forceUpdate = (isset($options['refresh']) && true === $options['refresh']);
                $this->UpdateActiveTable($pkeyarr, $forceUpdate);
-               if(isset($options['new']) && true === $options['new'])
-               {
+               if(isset($options['new']) && true === $options['new']) {
                        $table =& $this->TableInfo();
                        unset($table->_hasMany);
                        unset($table->_belongsTo);
@@ -181,8 +190,8 @@ class ADODB_Active_Record {
 
        function __wakeup()
        {
-               $class = get_class($this);
-               new $class;
+               $class = get_class($this);
+               new $class;
        }
 
        // CFR: Constants found in Rails
@@ -215,32 +224,32 @@ class ADODB_Active_Record {
 
        function _pluralize($table)
        {
-               if (!ADODB_Active_Record::$_changeNames) return $table;
-
+               if (!ADODB_Active_Record::$_changeNames) {
+                       return $table;
+               }
                $ut = strtoupper($table);
-               if(isset(self::$WeIsI[$ut]))
-               {
+               if(isset(self::$WeIsI[$ut])) {
                        return $table;
                }
-               if(isset(self::$IrregularP[$ut]))
-               {
+               if(isset(self::$IrregularP[$ut])) {
                        return self::$IrregularP[$ut];
                }
                $len = strlen($table);
                $lastc = $ut[$len-1];
                $lastc2 = substr($ut,$len-2);
                switch ($lastc) {
-               case 'S':
-                       return $table.'es';
-               case 'Y':
-                       return substr($table,0,$len-1).'ies';
-               case 'X':
-                       return $table.'es';
-               case 'H':
-                       if ($lastc2 == 'CH' || $lastc2 == 'SH')
+                       case 'S':
                                return $table.'es';
-               default:
-                       return $table.'s';
+                       case 'Y':
+                               return substr($table,0,$len-1).'ies';
+                       case 'X':
+                               return $table.'es';
+                       case 'H':
+                               if ($lastc2 == 'CH' || $lastc2 == 'SH') {
+                                       return $table.'es';
+                               }
+                       default:
+                               return $table.'s';
                }
        }
 
@@ -249,32 +258,33 @@ class ADODB_Active_Record {
        function _singularize($table)
        {
 
-               if (!ADODB_Active_Record::$_changeNames) return $table;
-
+               if (!ADODB_Active_Record::$_changeNames) {
+               return $table;
+       }
                $ut = strtoupper($table);
-               if(isset(self::$WeIsI[$ut]))
-               {
+               if(isset(self::$WeIsI[$ut])) {
                        return $table;
                }
-               if(isset(self::$IrregularS[$ut]))
-               {
+               if(isset(self::$IrregularS[$ut])) {
                        return self::$IrregularS[$ut];
                }
                $len = strlen($table);
-               if($ut[$len-1] != 'S')
+               if($ut[$len-1] != 'S') {
                        return $table; // I know...forget oxen
-               if($ut[$len-2] != 'E')
+               }
+               if($ut[$len-2] != 'E') {
                        return substr($table, 0, $len-1);
-               switch($ut[$len-3])
-               {
+               }
+               switch($ut[$len-3]) {
                        case 'S':
                        case 'X':
                                return substr($table, 0, $len-2);
                        case 'I':
                                return substr($table, 0, $len-3) . 'y';
                        case 'H';
-                               if($ut[$len-4] == 'C' || $ut[$len-4] == 'S')
+                               if($ut[$len-4] == 'C' || $ut[$len-4] == 'S') {
                                        return substr($table, 0, $len-2);
+                               }
                        default:
                                return substr($table, 0, $len-1); // ?
                }
@@ -296,8 +306,7 @@ class ADODB_Active_Record {
                $ar->foreignKey = ($foreignKey) ? $foreignKey : strtolower(get_class($this)) . self::$_foreignSuffix;
 
                $table =& $this->TableInfo();
-               if(!isset($table->_hasMany[$foreignRef]))
-               {
+               if(!isset($table->_hasMany[$foreignRef])) {
                        $table->_hasMany[$foreignRef] = $ar;
                        $table->updateColsCount();
                }
@@ -322,8 +331,7 @@ class ADODB_Active_Record {
                $ar->foreignKey = ($foreignKey) ? $foreignKey : $ar->foreignName . self::$_foreignSuffix;
 
                $table =& $this->TableInfo();
-               if(!isset($table->_belongsTo[$foreignRef]))
-               {
+               if(!isset($table->_belongsTo[$foreignRef])) {
                        $table->_belongsTo[$foreignRef] = $ar;
                        $table->updateColsCount();
                }
@@ -345,27 +353,35 @@ class ADODB_Active_Record {
        function LoadRelations($name, $whereOrderBy, $offset=-1, $limit=-1)
        {
                $extras = array();
-               if($offset >= 0) $extras['offset'] = $offset;
-               if($limit >= 0) $extras['limit'] = $limit;
+               if($offset >= 0) {
+                       $extras['offset'] = $offset;
+               }
+               if($limit >= 0) {
+                       $extras['limit'] = $limit;
+               }
                $table =& $this->TableInfo();
 
-               if (strlen($whereOrderBy))
-                       if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy))
-                               if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy))
+               if (strlen($whereOrderBy)) {
+                       if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy)) {
+                               if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy)) {
                                        $whereOrderBy = 'AND '.$whereOrderBy;
+                               }
+                       }
+               }
 
-               if(!empty($table->_belongsTo[$name]))
-               {
+               if(!empty($table->_belongsTo[$name])) {
                        $obj = $table->_belongsTo[$name];
                        $columnName = $obj->foreignKey;
-                       if(empty($this->$columnName))
+                       if(empty($this->$columnName)) {
                                $this->$name = null;
-                       else
-                       {
-                               if(($k = reset($obj->TableInfo()->keys)))
+                       }
+                       else {
+                               if(($k = reset($obj->TableInfo()->keys))) {
                                        $belongsToId = $k;
-                               else
+                               }
+                               else {
                                        $belongsToId = 'id';
+                               }
 
                                $arrayOfOne =
                                        $obj->Find(
@@ -374,13 +390,14 @@ class ADODB_Active_Record {
                        }
                        return $this->$name;
                }
-               if(!empty($table->_hasMany[$name]))
-               {
+               if(!empty($table->_hasMany[$name])) {
                        $obj = $table->_hasMany[$name];
-                       if(($k = reset($table->keys)))
+                       if(($k = reset($table->keys))) {
                                $hasManyId   = $k;
-                       else
+                       }
+                       else {
                                $hasManyId   = 'id';
+                       }
 
                        $this->$name =
                                $obj->Find(
@@ -405,10 +422,12 @@ class ADODB_Active_Record {
 
                        $tobj = $tables[$tableat];
                        foreach($tobj->flds as $name => $fld) {
-                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
-                               $this->$name = $fld->default_value;
-                       else
-                               $this->$name = null;
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) {
+                                       $this->$name = $fld->default_value;
+                               }
+                               else {
+                                       $this->$name = null;
+                               }
                        }
                        return;
                }
@@ -426,7 +445,7 @@ class ADODB_Active_Record {
                                $activedb->tables[$table] = $acttab;
 
                                //if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname");
-                               return;
+                                       return;
                        } else if ($db->debug) {
                                ADOConnection::outp("Refreshing cached active record file: $fname");
                        }
@@ -436,11 +455,15 @@ class ADODB_Active_Record {
 
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
-               if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
+               if ($db->fetchMode !== false) {
+                       $savem = $db->SetFetchMode(false);
+               }
 
                $cols = $db->MetaColumns($table);
 
-               if (isset($savem)) $db->SetFetchMode($savem);
+               if (isset($savem)) {
+                       $db->SetFetchMode($savem);
+               }
                $ADODB_FETCH_MODE = $save;
 
                if (!$cols) {
@@ -452,10 +475,13 @@ class ADODB_Active_Record {
                        if (isset($fld->primary_key)) {
                                $pkeys = array();
                                foreach($cols as $name => $fld) {
-                                       if (!empty($fld->primary_key)) $pkeys[] = $name;
+                                       if (!empty($fld->primary_key)) {
+                                               $pkeys[] = $name;
+                                       }
                                }
-                       } else
+                       } else {
                                $pkeys = $this->GetPrimaryKeys($db, $table);
+                       }
                }
                if (empty($pkeys)) {
                        $this->Error("No primary key found for table $table",'UpdateActiveTable');
@@ -469,10 +495,12 @@ class ADODB_Active_Record {
                case 0:
                        foreach($cols as $name => $fldobj) {
                                $name = strtolower($name);
-                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
-                    $this->$name = $fldobj->default_value;
-                else
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) {
+                                       $this->$name = $fldobj->default_value;
+                               }
+                               else {
                                        $this->$name = null;
+                               }
                                $attr[$name] = $fldobj;
                        }
                        foreach($pkeys as $k => $name) {
@@ -484,10 +512,12 @@ class ADODB_Active_Record {
                        foreach($cols as $name => $fldobj) {
                                $name = strtoupper($name);
 
-                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
-                    $this->$name = $fldobj->default_value;
-                else
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) {
+                                       $this->$name = $fldobj->default_value;
+                               }
+                               else {
                                        $this->$name = null;
+                               }
                                $attr[$name] = $fldobj;
                        }
 
@@ -499,10 +529,12 @@ class ADODB_Active_Record {
                        foreach($cols as $name => $fldobj) {
                                $name = ($fldobj->name);
 
-                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
-                    $this->$name = $fldobj->default_value;
-                else
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) {
+                                       $this->$name = $fldobj->default_value;
+                               }
+                               else {
                                        $this->$name = null;
+                               }
                                $attr[$name] = $fldobj;
                        }
                        foreach($pkeys as $k => $name) {
@@ -518,14 +550,18 @@ class ADODB_Active_Record {
                if ($ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR) {
                        $activetab->_created = time();
                        $s = serialize($activetab);
-                       if (!function_exists('adodb_write_file')) include(ADODB_DIR.'/adodb-csvlib.inc.php');
+                       if (!function_exists('adodb_write_file')) {
+                               include(ADODB_DIR.'/adodb-csvlib.inc.php');
+                       }
                        adodb_write_file($fname,$s);
                }
                if (isset($activedb->tables[$table])) {
                        $oldtab = $activedb->tables[$table];
 
-                       if ($oldtab) $activetab->_belongsTo = $oldtab->_belongsTo;
-                       if ($oldtab) $activetab->_hasMany = $oldtab->_hasMany;
+                       if ($oldtab) {
+                               $activetab->_belongsTo = $oldtab->_belongsTo;
+                               $activetab->_hasMany = $oldtab->_hasMany;
+                       }
                }
                $activedb->tables[$table] = $activetab;
        }
@@ -543,17 +579,26 @@ class ADODB_Active_Record {
                $fn = get_class($this).'::'.$fn;
                $this->_lasterr = $fn.': '.$err;
 
-               if ($this->_dbat < 0) $db = false;
+               if ($this->_dbat < 0) {
+                       $db = false;
+               }
                else {
                        $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
                        $db = $activedb->db;
                }
 
                if (function_exists('adodb_throw')) {
-                       if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
-                       else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
-               } else
-                       if (!$db || $db->debug) ADOConnection::outp($this->_lasterr);
+                       if (!$db) {
+                               adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
+                       }
+                       else {
+                               adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
+                       }
+               } else {
+                       if (!$db || $db->debug) {
+                               ADOConnection::outp($this->_lasterr);
+                       }
+               }
 
        }
 
@@ -561,18 +606,26 @@ class ADODB_Active_Record {
        function ErrorMsg()
        {
                if (!function_exists('adodb_throw')) {
-                       if ($this->_dbat < 0) $db = false;
-                       else $db = $this->DB();
+                       if ($this->_dbat < 0) {
+                               $db = false;
+                       }
+                       else {
+                               $db = $this->DB();
+                       }
 
                        // last error could be database error too
-                       if ($db && $db->ErrorMsg()) return $db->ErrorMsg();
+                       if ($db && $db->ErrorMsg()) {
+                               return $db->ErrorMsg();
+                       }
                }
                return $this->_lasterr;
        }
 
        function ErrorNo()
        {
-               if ($this->_dbat < 0) return -9999; // no database connection...
+               if ($this->_dbat < 0) {
+                       return -9999; // no database connection...
+               }
                $db = $this->DB();
 
                return (int) $db->ErrorNo();
@@ -609,7 +662,10 @@ class ADODB_Active_Record {
        // So, I find that for myTable, I want to reload an active record after saving it. -- Malcolm Cook
        function Reload()
        {
-               $db =& $this->DB(); if (!$db) return false;
+               $db =& $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $table =& $this->TableInfo();
                $where = $this->GenWhere($db, $table);
                return($this->Load($where));
@@ -634,67 +690,74 @@ class ADODB_Active_Record {
                $sizeofFlds = sizeof($table->flds);
                $sizeofRow  = sizeof($row);
                if ($ACTIVE_RECORD_SAFETY && $table->_colsCount != $sizeofRow && $sizeofFlds != $sizeofRow) {
-            # <AP>
-            $bad_size = TRUE;
-       if($sizeofRow == 2 * $table->_colsCount || $sizeofRow == 2 * $sizeofFlds) {
-                // Only keep string keys
-                $keys = array_filter(array_keys($row), 'is_string');
-                if (sizeof($keys) == sizeof($table->flds))
-                    $bad_size = FALSE;
-            }
-            if ($bad_size) {
-                       $this->Error("Table structure of $this->_table has changed","Load");
-                       return false;
+                       # <AP>
+                       $bad_size = TRUE;
+                       if($sizeofRow == 2 * $table->_colsCount || $sizeofRow == 2 * $sizeofFlds) {
+                               // Only keep string keys
+                               $keys = array_filter(array_keys($row), 'is_string');
+                               if (sizeof($keys) == sizeof($table->flds)) {
+                                       $bad_size = FALSE;
+                               }
+                       }
+                       if ($bad_size) {
+                               $this->Error("Table structure of $this->_table has changed","Load");
+                               return false;
+                       }
+                       # </AP>
                }
-            # </AP>
+               else {
+                       $keys = array_keys($row);
                }
-        else
-               $keys = array_keys($row);
-        # <AP>
-        reset($keys);
-        $this->_original = array();
-               foreach($table->flds as $name=>$fld)
-               {
-            $value = $row[current($keys)];
+
+               # <AP>
+               reset($keys);
+               $this->_original = array();
+               foreach($table->flds as $name=>$fld) {
+                       $value = $row[current($keys)];
                        $this->$name = $value;
-            $this->_original[] = $value;
-            if(!next($keys)) break;
+                       $this->_original[] = $value;
+                       if(!next($keys)) {
+                               break;
+                       }
                }
                $table =& $this->TableInfo();
-               foreach($table->_belongsTo as $foreignTable)
-               {
+               foreach($table->_belongsTo as $foreignTable) {
                        $ft = $foreignTable->TableInfo();
                        $propertyName = $ft->name;
-                       foreach($ft->flds as $name=>$fld)
-                       {
+                       foreach($ft->flds as $name=>$fld) {
                                $value = $row[current($keys)];
                                $foreignTable->$name = $value;
                                $foreignTable->_original[] = $value;
-                               if(!next($keys)) break;
+                               if(!next($keys)) {
+                                       break;
+                               }
                        }
                }
-               foreach($table->_hasMany as $foreignTable)
-               {
+               foreach($table->_hasMany as $foreignTable) {
                        $ft = $foreignTable->TableInfo();
-                       foreach($ft->flds as $name=>$fld)
-                       {
+                       foreach($ft->flds as $name=>$fld) {
                                $value = $row[current($keys)];
                                $foreignTable->$name = $value;
                                $foreignTable->_original[] = $value;
-                               if(!next($keys)) break;
+                               if(!next($keys)) {
+                                       break;
+                               }
                        }
                }
-        # </AP>
+               # </AP>
+
                return true;
        }
 
        // get last inserted id for INSERT
        function LastInsertID(&$db,$fieldname)
        {
-               if ($db->hasInsertID)
+               if ($db->hasInsertID) {
                        $val = $db->Insert_ID($this->_table,$fieldname);
-               else
+               }
+               else {
                        $val = false;
+               }
 
                if (is_null($val) || $val === false) {
                        // this might not work reliably in multi-user environment
@@ -709,14 +772,17 @@ class ADODB_Active_Record {
                switch($t) {
                case 'D':
                case 'T':
-                       if (empty($val)) return 'null';
-
+                       if (empty($val)) {
+                               return 'null';
+                       }
                case 'C':
                case 'X':
-                       if (is_null($val)) return 'null';
-
+                       if (is_null($val)) {
+                               return 'null';
+                       }
                        if (strlen($val)>0 &&
-                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) {
+                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")
+                       ) {
                                return $db->qstr($val);
                                break;
                        }
@@ -746,26 +812,28 @@ class ADODB_Active_Record {
 
        function Load($where=null,$bindarr=false)
        {
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $this->_where = $where;
 
                $save = $db->SetFetchMode(ADODB_FETCH_NUM);
                $qry = "select * from ".$this->_table;
                $table =& $this->TableInfo();
 
-               if(($k = reset($table->keys)))
+               if(($k = reset($table->keys))) {
                        $hasManyId   = $k;
-               else
+               }
+               else {
                        $hasManyId   = 'id';
+               }
 
-               foreach($table->_belongsTo as $foreignTable)
-               {
-                       if(($k = reset($foreignTable->TableInfo()->keys)))
-                       {
+               foreach($table->_belongsTo as $foreignTable) {
+                       if(($k = reset($foreignTable->TableInfo()->keys))) {
                                $belongsToId = $k;
                        }
-                       else
-                       {
+                       else {
                                $belongsToId = 'id';
                        }
                        $qry .= ' LEFT JOIN '.$foreignTable->_table.' ON '.
@@ -778,96 +846,88 @@ class ADODB_Active_Record {
                                $this->_table.'.'.$hasManyId.'='.
                                $foreignTable->_table.'.'.$foreignTable->foreignKey;
                }
-               if($where)
+               if($where) {
                        $qry .= ' WHERE '.$where;
+               }
 
                // Simple case: no relations. Load row and return.
-               if((count($table->_hasMany) + count($table->_belongsTo)) < 1)
-               {
+               if((count($table->_hasMany) + count($table->_belongsTo)) < 1) {
                        $row = $db->GetRow($qry,$bindarr);
-                       if(!$row)
+                       if(!$row) {
                                return false;
+                       }
                        $db->SetFetchMode($save);
                        return $this->Set($row);
                }
 
                // More complex case when relations have to be collated
                $rows = $db->GetAll($qry,$bindarr);
-               if(!$rows)
+               if(!$rows) {
                        return false;
+               }
                $db->SetFetchMode($save);
-               if(count($rows) < 1)
+               if(count($rows) < 1) {
                        return false;
+               }
                $class = get_class($this);
                $isFirstRow = true;
 
-               if(($k = reset($this->TableInfo()->keys)))
+               if(($k = reset($this->TableInfo()->keys))) {
                        $myId   = $k;
-               else
+               }
+               else {
                        $myId   = 'id';
+               }
                $index = 0; $found = false;
                /** @todo Improve by storing once and for all in table metadata */
                /** @todo Also re-use info for hasManyId */
-               foreach($this->TableInfo()->flds as $fld)
-               {
-                       if($fld->name == $myId)
-                       {
+               foreach($this->TableInfo()->flds as $fld) {
+                       if($fld->name == $myId) {
                                $found = true;
                                break;
                        }
                        $index++;
                }
-               if(!$found)
+               if(!$found) {
                        $this->outp_throw("Unable to locate key $myId for $class in Load()",'Load');
+               }
 
-               foreach($rows as $row)
-               {
+               foreach($rows as $row) {
                        $rowId = intval($row[$index]);
-                       if($rowId > 0)
-                       {
-                               if($isFirstRow)
-                               {
+                       if($rowId > 0) {
+                               if($isFirstRow) {
                                        $isFirstRow = false;
-                                       if(!$this->Set($row))
+                                       if(!$this->Set($row)) {
                                                return false;
+                                       }
                                }
                                $obj = new $class($table,false,$db);
                                $obj->Set($row);
                                // TODO Copy/paste code below: bad!
-                               if(count($table->_hasMany) > 0)
-                               {
-                                       foreach($table->_hasMany as $foreignTable)
-                                       {
+                               if(count($table->_hasMany) > 0) {
+                                       foreach($table->_hasMany as $foreignTable) {
                                                $foreignName = $foreignTable->foreignName;
-                                               if(!empty($obj->$foreignName))
-                                               {
-                                                       if(!is_array($this->$foreignName))
-                                                       {
+                                               if(!empty($obj->$foreignName)) {
+                                                       if(!is_array($this->$foreignName)) {
                                                                $foreignObj = $this->$foreignName;
                                                                $this->$foreignName = array(clone($foreignObj));
                                                        }
-                                                       else
-                                                       {
+                                                       else {
                                                                $foreignObj = $obj->$foreignName;
                                                                array_push($this->$foreignName, clone($foreignObj));
                                                        }
                                                }
                                        }
                                }
-                               if(count($table->_belongsTo) > 0)
-                               {
-                                       foreach($table->_belongsTo as $foreignTable)
-                                       {
+                               if(count($table->_belongsTo) > 0) {
+                                       foreach($table->_belongsTo as $foreignTable) {
                                                $foreignName = $foreignTable->foreignName;
-                                               if(!empty($obj->$foreignName))
-                                               {
-                                                       if(!is_array($this->$foreignName))
-                                                       {
+                                               if(!empty($obj->$foreignName)) {
+                                                       if(!is_array($this->$foreignName)) {
                                                                $foreignObj = $this->$foreignName;
                                                                $this->$foreignName = array(clone($foreignObj));
                                                        }
-                                                       else
-                                                       {
+                                                       else {
                                                                $foreignObj = $obj->$foreignName;
                                                                array_push($this->$foreignName, clone($foreignObj));
                                                        }
@@ -882,8 +942,12 @@ class ADODB_Active_Record {
        // false on error
        function Save()
        {
-               if ($this->_saved) $ok = $this->Update();
-               else $ok = $this->Insert();
+               if ($this->_saved) {
+                       $ok = $this->Update();
+               }
+               else {
+                       $ok = $this->Insert();
+               }
 
                return $ok;
        }
@@ -898,7 +962,10 @@ class ADODB_Active_Record {
        // false on error
        function Insert()
        {
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $cnt = 0;
                $table = $this->TableInfo();
 
@@ -948,7 +1015,10 @@ class ADODB_Active_Record {
 
        function Delete()
        {
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $table = $this->TableInfo();
 
                $where = $this->GenWhere($db,$table);
@@ -961,7 +1031,10 @@ class ADODB_Active_Record {
        // returns an array of active record objects
        function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array())
        {
-               $db = $this->DB(); if (!$db || empty($this->_table)) return false;
+               $db = $this->DB();
+               if (!$db || empty($this->_table)) {
+                       return false;
+               }
                $table =& $this->TableInfo();
                $arr = $db->GetActiveRecordsClass(get_class($this),$this, $whereOrderBy,$bindarr,$pkeysArr,$extra,
                        array('foreignName'=>$this->foreignName, 'belongsTo'=>$table->_belongsTo, 'hasMany'=>$table->_hasMany));
@@ -974,7 +1047,10 @@ class ADODB_Active_Record {
        // Shockingly because I want to preserve PHP4 compatibility.
        function packageFind($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array())
        {
-               $db = $this->DB(); if (!$db || empty($this->_table)) return false;
+               $db = $this->DB();
+               if (!$db || empty($this->_table)) {
+                       return false;
+               }
                $table =& $this->TableInfo();
                $arr = $db->GetActiveRecordsClass(get_class($this),$this, $whereOrderBy,$bindarr,$pkeysArr,$extra,
                        array('foreignName'=>$this->foreignName, 'belongsTo'=>$table->_belongsTo, 'hasMany'=>$table->_hasMany));
@@ -986,7 +1062,10 @@ class ADODB_Active_Record {
        {
        global $ADODB_ASSOC_CASE;
 
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $table = $this->TableInfo();
 
                $pkey = $table->keys;
@@ -996,7 +1075,9 @@ class ADODB_Active_Record {
                        /*
                        if (is_null($val)) {
                                if (isset($fld->not_null) && $fld->not_null) {
-                                       if (isset($fld->default_value) && strlen($fld->default_value)) continue;
+                                       if (isset($fld->default_value) && strlen($fld->default_value)) {
+                                               continue;
+                                       }
                                        else {
                                                $this->Error("Cannot update null into $name","Replace");
                                                return false;
@@ -1004,22 +1085,30 @@ class ADODB_Active_Record {
                                }
                        }*/
                        if (is_null($val) && !empty($fld->auto_increment)) {
-               continue;
-            }
+                               continue;
+                       }
                        $t = $db->MetaType($fld->type);
                        $arr[$name] = $this->doquote($db,$val,$t);
                        $valarr[] = $val;
                }
 
-               if (!is_array($pkey)) $pkey = array($pkey);
+               if (!is_array($pkey)) {
+                       $pkey = array($pkey);
+               }
 
 
-               if ($ADODB_ASSOC_CASE == 0)
-                       foreach($pkey as $k => $v)
-                               $pkey[$k] = strtolower($v);
-               elseif ($ADODB_ASSOC_CASE == 1)
-                       foreach($pkey as $k => $v)
-                               $pkey[$k] = strtoupper($v);
+               switch ($ADODB_ASSOC_CASE == 0) {
+                       case ADODB_ASSOC_CASE_LOWER:
+                               foreach($pkey as $k => $v) {
+                                       $pkey[$k] = strtolower($v);
+                               }
+                               break;
+                       case ADODB_ASSOC_CASE_UPPER:
+                               foreach($pkey as $k => $v) {
+                                       $pkey[$k] = strtoupper($v);
+                               }
+                               break;
+               }
 
                $ok = $db->Replace($this->_table,$arr,$pkey);
                if ($ok) {
@@ -1046,7 +1135,10 @@ class ADODB_Active_Record {
        // returns 0 on error, 1 on update, -1 if no change in data (no update)
        function Update()
        {
-               $db = $this->DB(); if (!$db) return false;
+               $db = $this->DB();
+               if (!$db) {
+                       return false;
+               }
                $table = $this->TableInfo();
 
                $where = $this->GenWhere($db, $table);
@@ -1071,7 +1163,9 @@ class ADODB_Active_Record {
 
                        if (is_null($val)) {
                                if (isset($fld->not_null) && $fld->not_null) {
-                                       if (isset($fld->default_value) && strlen($fld->default_value)) continue;
+                                       if (isset($fld->default_value) && strlen($fld->default_value)) {
+                                               continue;
+                                       }
                                        else {
                                                $this->Error("Cannot set field $name to NULL","Update");
                                                return false;
@@ -1079,7 +1173,7 @@ class ADODB_Active_Record {
                                }
                        }
 
-                       if (isset($this->_original[$i]) && $val == $this->_original[$i]) {
+                       if (isset($this->_original[$i]) && $val === $this->_original[$i]) {
                                continue;
                        }
                        $valarr[] = $val;
@@ -1088,7 +1182,9 @@ class ADODB_Active_Record {
                }
 
 
-               if (!$cnt) return -1;
+               if (!$cnt) {
+                       return -1;
+               }
                $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where;
                $ok = $db->Execute($sql,$valarr);
                if ($ok) {
@@ -1101,7 +1197,9 @@ class ADODB_Active_Record {
        function GetAttributeNames()
        {
                $table = $this->TableInfo();
-               if (!$table) return false;
+               if (!$table) {
+                       return false;
+               }
                return array_keys($table->flds);
        }
 
@@ -1112,43 +1210,41 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
 {
        global $_ADODB_ACTIVE_DBS;
 
-               if (empty($extra['loading'])) $extra['loading'] = ADODB_LAZY_AR;
-
+               if (empty($extra['loading'])) {
+                       $extra['loading'] = ADODB_LAZY_AR;
+               }
                $save = $db->SetFetchMode(ADODB_FETCH_NUM);
                $table = &$tableObj->_table;
                $tableInfo =& $tableObj->TableInfo();
-               if(($k = reset($tableInfo->keys)))
-                       $myId   = $k;
-               else
-                       $myId   = 'id';
+               if(($k = reset($tableInfo->keys))) {
+                       $myId = $k;
+               }
+               else {
+                       $myId = 'id';
+               }
                $index = 0; $found = false;
                /** @todo Improve by storing once and for all in table metadata */
                /** @todo Also re-use info for hasManyId */
                foreach($tableInfo->flds as $fld)
                {
-                       if($fld->name == $myId)
-                       {
+                       if($fld->name == $myId) {
                                $found = true;
                                break;
                        }
                        $index++;
                }
-               if(!$found)
+               if(!$found) {
                        $db->outp_throw("Unable to locate key $myId for $class in GetActiveRecordsClass()",'GetActiveRecordsClass');
+               }
 
                $qry = "select * from ".$table;
-               if(ADODB_JOIN_AR == $extra['loading'])
-               {
-                       if(!empty($relations['belongsTo']))
-                       {
-                               foreach($relations['belongsTo'] as $foreignTable)
-                               {
-                                       if(($k = reset($foreignTable->TableInfo()->keys)))
-                                       {
+               if(ADODB_JOIN_AR == $extra['loading']) {
+                       if(!empty($relations['belongsTo'])) {
+                               foreach($relations['belongsTo'] as $foreignTable) {
+                                       if(($k = reset($foreignTable->TableInfo()->keys))) {
                                                $belongsToId = $k;
                                        }
-                                       else
-                                       {
+                                       else {
                                                $belongsToId = 'id';
                                        }
 
@@ -1157,27 +1253,28 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                                                $foreignTable->_table.'.'.$belongsToId;
                                }
                        }
-                       if(!empty($relations['hasMany']))
-                       {
-                               if(empty($relations['foreignName']))
+                       if(!empty($relations['hasMany'])) {
+                               if(empty($relations['foreignName'])) {
                                        $db->outp_throw("Missing foreignName is relation specification in GetActiveRecordsClass()",'GetActiveRecordsClass');
-                               if(($k = reset($tableInfo->keys)))
+                               }
+                               if(($k = reset($tableInfo->keys))) {
                                        $hasManyId   = $k;
-                               else
+                               }
+                               else {
                                        $hasManyId   = 'id';
+                               }
 
-                               foreach($relations['hasMany'] as $foreignTable)
-                               {
+                               foreach($relations['hasMany'] as $foreignTable) {
                                        $qry .= ' LEFT JOIN '.$foreignTable->_table.' ON '.
                                                $table.'.'.$hasManyId.'='.
                                                $foreignTable->_table.'.'.$foreignTable->foreignKey;
                                }
                        }
                }
-               if (!empty($whereOrderBy))
+               if (!empty($whereOrderBy)) {
                        $qry .= ' WHERE '.$whereOrderBy;
-               if(isset($extra['limit']))
-               {
+               }
+               if(isset($extra['limit'])) {
                        $rows = false;
                        if(isset($extra['offset'])) {
                                $rs = $db->SelectLimit($qry, $extra['limit'], $extra['offset']);
@@ -1237,59 +1334,55 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                        // Note: to-many relationships mess around with the 'limit' parameter
                        $rowId = intval($row[$index]);
 
-                       if(ADODB_WORK_AR == $extra['loading'])
-                       {
+                       if(ADODB_WORK_AR == $extra['loading']) {
                                $arrRef[$rowId] = $obj;
                                $arr[] = &$arrRef[$rowId];
-                               if(!isset($indices))
+                               if(!isset($indices)) {
                                        $indices = $rowId;
-                               else
+                               }
+                               else {
                                        $indices .= ','.$rowId;
-                               if(!empty($relations['belongsTo']))
-                               {
-                                       foreach($relations['belongsTo'] as $foreignTable)
-                                       {
+                               }
+                               if(!empty($relations['belongsTo'])) {
+                                       foreach($relations['belongsTo'] as $foreignTable) {
                                                $foreignTableRef = $foreignTable->foreignKey;
                                                // First array: list of foreign ids we are looking for
-                                               if(empty($bTos[$foreignTableRef]))
+                                               if(empty($bTos[$foreignTableRef])) {
                                                        $bTos[$foreignTableRef] = array();
+                                               }
                                                // Second array: list of ids found
-                                               if(empty($obj->$foreignTableRef))
+                                               if(empty($obj->$foreignTableRef)) {
                                                        continue;
-                                               if(empty($bTos[$foreignTableRef][$obj->$foreignTableRef]))
+                                               }
+                                               if(empty($bTos[$foreignTableRef][$obj->$foreignTableRef])) {
                                                        $bTos[$foreignTableRef][$obj->$foreignTableRef] = array();
+                                               }
                                                $bTos[$foreignTableRef][$obj->$foreignTableRef][] = $obj;
                                        }
                                }
                                continue;
                        }
 
-                       if($rowId>0)
-                       {
-                               if(ADODB_JOIN_AR == $extra['loading'])
-                               {
+                       if($rowId>0) {
+                               if(ADODB_JOIN_AR == $extra['loading']) {
                                        $isNewObj = !isset($uniqArr['_'.$row[0]]);
-                                       if($isNewObj)
+                                       if($isNewObj) {
                                                $uniqArr['_'.$row[0]] = $obj;
+                                       }
 
                                        // TODO Copy/paste code below: bad!
-                                       if(!empty($relations['hasMany']))
-                                       {
-                                               foreach($relations['hasMany'] as $foreignTable)
-                                               {
+                                       if(!empty($relations['hasMany'])) {
+                                               foreach($relations['hasMany'] as $foreignTable) {
                                                        $foreignName = $foreignTable->foreignName;
-                                                       if(!empty($obj->$foreignName))
-                                                       {
+                                                       if(!empty($obj->$foreignName)) {
                                                                $masterObj = &$uniqArr['_'.$row[0]];
                                                                // Assumption: this property exists in every object since they are instances of the same class
-                                                               if(!is_array($masterObj->$foreignName))
-                                                               {
+                                                               if(!is_array($masterObj->$foreignName)) {
                                                                        // Pluck!
                                                                        $foreignObj = $masterObj->$foreignName;
                                                                        $masterObj->$foreignName = array(clone($foreignObj));
                                                                }
-                                                               else
-                                                               {
+                                                               else {
                                                                        // Pluck pluck!
                                                                        $foreignObj = $obj->$foreignName;
                                                                        array_push($masterObj->$foreignName, clone($foreignObj));
@@ -1297,23 +1390,18 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                                                        }
                                                }
                                        }
-                                       if(!empty($relations['belongsTo']))
-                                       {
-                                               foreach($relations['belongsTo'] as $foreignTable)
-                                               {
+                                       if(!empty($relations['belongsTo'])) {
+                                               foreach($relations['belongsTo'] as $foreignTable) {
                                                        $foreignName = $foreignTable->foreignName;
-                                                       if(!empty($obj->$foreignName))
-                                                       {
+                                                       if(!empty($obj->$foreignName)) {
                                                                $masterObj = &$uniqArr['_'.$row[0]];
                                                                // Assumption: this property exists in every object since they are instances of the same class
-                                                               if(!is_array($masterObj->$foreignName))
-                                                               {
+                                                               if(!is_array($masterObj->$foreignName)) {
                                                                        // Pluck!
                                                                        $foreignObj = $masterObj->$foreignName;
                                                                        $masterObj->$foreignName = array(clone($foreignObj));
                                                                }
-                                                               else
-                                                               {
+                                                               else {
                                                                        // Pluck pluck!
                                                                        $foreignObj = $obj->$foreignName;
                                                                        array_push($masterObj->$foreignName, clone($foreignObj));
@@ -1321,34 +1409,28 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                                                        }
                                                }
                                        }
-                                       if(!$isNewObj)
+                                       if(!$isNewObj) {
                                                unset($obj); // We do not need this object itself anymore and do not want it re-added to the main array
+                                       }
                                }
-                               else if(ADODB_LAZY_AR == $extra['loading'])
-                               {
+                               else if(ADODB_LAZY_AR == $extra['loading']) {
                                        // Lazy loading: we need to give AdoDb a hint that we have not really loaded
                                        // anything, all the while keeping enough information on what we wish to load.
                                        // Let's do this by keeping the relevant info in our relationship arrays
                                        // but get rid of the actual properties.
                                        // We will then use PHP's __get to load these properties on-demand.
-                                       if(!empty($relations['hasMany']))
-                                       {
-                                               foreach($relations['hasMany'] as $foreignTable)
-                                               {
+                                       if(!empty($relations['hasMany'])) {
+                                               foreach($relations['hasMany'] as $foreignTable) {
                                                        $foreignName = $foreignTable->foreignName;
-                                                       if(!empty($obj->$foreignName))
-                                                       {
+                                                       if(!empty($obj->$foreignName)) {
                                                                unset($obj->$foreignName);
                                                        }
                                                }
                                        }
-                                       if(!empty($relations['belongsTo']))
-                                       {
-                                               foreach($relations['belongsTo'] as $foreignTable)
-                                               {
+                                       if(!empty($relations['belongsTo'])) {
+                                               foreach($relations['belongsTo'] as $foreignTable) {
                                                        $foreignName = $foreignTable->foreignName;
-                                                       if(!empty($obj->$foreignName))
-                                                       {
+                                                       if(!empty($obj->$foreignName)) {
                                                                unset($obj->$foreignName);
                                                        }
                                                }
@@ -1356,47 +1438,42 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                                }
                        }
 
-                       if(isset($obj))
+                       if(isset($obj)) {
                                $arr[] = $obj;
+                       }
                }
 
-               if(ADODB_WORK_AR == $extra['loading'])
-               {
+               if(ADODB_WORK_AR == $extra['loading']) {
                        // The best of both worlds?
                        // Here, the number of queries is constant: 1 + n*relationship.
                        // The second query will allow us to perform a good join
                        // while preserving LIMIT etc.
-                       if(!empty($relations['hasMany']))
-                       {
-                               foreach($relations['hasMany'] as $foreignTable)
-                               {
+                       if(!empty($relations['hasMany'])) {
+                               foreach($relations['hasMany'] as $foreignTable) {
                                        $foreignName = $foreignTable->foreignName;
                                        $className = ucfirst($foreignTable->_singularize($foreignName));
                                        $obj = new $className();
                                        $dbClassRef = $foreignTable->foreignKey;
                                        $objs = $obj->packageFind($dbClassRef.' IN ('.$indices.')');
-                                       foreach($objs as $obj)
-                                       {
-                                               if(!is_array($arrRef[$obj->$dbClassRef]->$foreignName))
+                                       foreach($objs as $obj) {
+                                               if(!is_array($arrRef[$obj->$dbClassRef]->$foreignName)) {
                                                        $arrRef[$obj->$dbClassRef]->$foreignName = array();
+                                               }
                                                array_push($arrRef[$obj->$dbClassRef]->$foreignName, $obj);
                                        }
                                }
 
                        }
-                       if(!empty($relations['belongsTo']))
-                       {
-                               foreach($relations['belongsTo'] as $foreignTable)
-                               {
+                       if(!empty($relations['belongsTo'])) {
+                               foreach($relations['belongsTo'] as $foreignTable) {
                                        $foreignTableRef = $foreignTable->foreignKey;
-                                       if(empty($bTos[$foreignTableRef]))
+                                       if(empty($bTos[$foreignTableRef])) {
                                                continue;
-                                       if(($k = reset($foreignTable->TableInfo()->keys)))
-                                       {
+                                       }
+                                       if(($k = reset($foreignTable->TableInfo()->keys))) {
                                                $belongsToId = $k;
                                        }
-                                       else
-                                       {
+                                       else {
                                                $belongsToId = 'id';
                                        }
                                        $origObjsArr = $bTos[$foreignTableRef];
index d70c16f..a379450 100644 (file)
@@ -8,7 +8,9 @@ $ADODB_INCLUDED_CSV = 1;
 
 /*
 
-  V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+  @version   v5.20.1  06-Dec-2015
+  @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+  @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence. See License.txt.
@@ -292,7 +294,7 @@ $ADODB_INCLUDED_CSV = 1;
                                // the tricky moment
                                @unlink($filename);
                                if (!@rename($tmpname,$filename)) {
-                                       unlink($tmpname);
+                                       @unlink($tmpname);
                                        $ok = 0;
                                }
                                if (!$ok) {
index b8b881e..7810bdb 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 
 /**
-  V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+  @version   v5.20.1  06-Dec-2015
+  @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+  @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
index 29c6a9c..b149092 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 /**
- * @version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version   v5.20.1  06-Dec-2015
+ * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+ * @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
  * Released under both BSD license and Lesser GPL library license.
  * Whenever there is any discrepancy between the two licenses,
  * the BSD license will take precedence.
index 680e76d..8bf0af4 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 /**
- * @version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version   v5.20.1  06-Dec-2015
+ * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+ * @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
  * Released under both BSD license and Lesser GPL library license.
  * Whenever there is any discrepancy between the two licenses,
  * the BSD license will take precedence.
index 10dbb97..dce7c73 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 /**
- * @version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version   v5.20.1  06-Dec-2015
+ * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+ * @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
  * Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
index 2300f11..eb14b78 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 
 /**
- * @version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version   v5.20.1  06-Dec-2015
+ * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+ * @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
  * Released under both BSD license and Lesser GPL library license.
  * Whenever there is any discrepancy between the two licenses,
  * the BSD license will take precedence.
@@ -29,9 +31,9 @@ var $database = '';
        {
                switch($fn) {
                case 'EXECUTE':
-                       $this->sql = $p1;
+                       $this->sql = is_array($p1) ? $p1[0] : $p1;
                        $this->params = $p2;
-                       $s = "$dbms error: [$errno: $errmsg] in $fn(\"$p1\")\n";
+                       $s = "$dbms error: [$errno: $errmsg] in $fn(\"$this->sql\")\n";
                        break;
 
                case 'PCONNECT':
index 2d26326..164dfb2 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 
 /*
-  V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+  @version   v5.20.1  06-Dec-2015
+  @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+  @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
index de35bc9..dc404b5 100644 (file)
@@ -6,7 +6,9 @@ global $ADODB_INCLUDED_LIB;
 $ADODB_INCLUDED_LIB = 1;
 
 /*
-  @version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+  @version   v5.20.1  06-Dec-2015
+  @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+  @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence. See License.txt.
@@ -17,7 +19,7 @@ $ADODB_INCLUDED_LIB = 1;
 
 function adodb_strip_order_by($sql)
 {
-       $rez = preg_match('/(\sORDER\s+BY\s(?:[^)](?!limit))*)(?:\sLIMIT\s+[0-9]+)?/is', $sql, $arr);
+       $rez = preg_match('/(\sORDER\s+BY\s(?:[^)](?!LIMIT))*)/is', $sql, $arr);
        if ($arr)
                if (strpos($arr[1], '(') !== false) {
                        $at = strpos($sql, $arr[1]);
@@ -38,7 +40,7 @@ function adodb_strip_order_by($sql)
                        $sql = str_replace($arr[1], '', $sql);
                }
        return $sql;
- }
+}
 
 if (false) {
        $sql = 'select * from (select a from b order by a(b),b(c) desc)';
@@ -421,8 +423,11 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
                }
        } else {
                // now replace SELECT ... FROM with SELECT COUNT(*) FROM
-               $rewritesql = preg_replace(
-                                       '/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);
+               if ( strpos($sql, '_ADODB_COUNT') !== FALSE ) {
+                       $rewritesql = preg_replace('/^\s*?SELECT\s+_ADODB_COUNT(.*)_ADODB_COUNT\s/is','SELECT COUNT(*) ',$sql);
+               } else {
+                       $rewritesql = preg_replace('/^\s*?SELECT\s.*?\s+(.*?)\s+FROM\s/is','SELECT COUNT(*) FROM ',$sql);
+               }
                // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails
                // with mssql, access and postgresql. Also a good speedup optimization - skips sorting!
                // also see http://phplens.com/lens/lensforum/msgs.php?id=12752
@@ -543,46 +548,86 @@ function _adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
        return $rsreturn;
 }
 
-// Iván Oliva version
+// Iván Oliva version
 function _adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0)
 {
 
        $atfirstpage = false;
        $atlastpage = false;
 
-       if (!isset($page) || $page <= 1) {      // If page number <= 1, then we are at the first page
+       if (!isset($page) || $page <= 1) {
+               // If page number <= 1, then we are at the first page
                $page = 1;
                $atfirstpage = true;
        }
-       if ($nrows <= 0) $nrows = 10;   // If an invalid nrows is supplied, we assume a default value of 10 rows per page
-
-       // ***** Here we check whether $page is the last page or whether we are trying to retrieve a page number greater than
-       // the last page number.
-       $pagecounter = $page + 1;
-       $pagecounteroffset = ($pagecounter * $nrows) - $nrows;
-       if ($secs2cache>0) $rstest = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
-       else $rstest = $zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
-       if ($rstest) {
-               while ($rstest && $rstest->EOF && $pagecounter>0) {
-                       $atlastpage = true;
-                       $pagecounter--;
-                       $pagecounteroffset = $nrows * ($pagecounter - 1);
-                       $rstest->Close();
-                       if ($secs2cache>0) $rstest = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
-                       else $rstest = $zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
-               }
-               if ($rstest) $rstest->Close();
+       if ($nrows <= 0) {
+               // If an invalid nrows is supplied, we assume a default value of 10 rows per page
+               $nrows = 10;
        }
-       if ($atlastpage) {      // If we are at the last page or beyond it, we are going to retrieve it
-               $page = $pagecounter;
-               if ($page == 1) $atfirstpage = true;    // We have to do this again in case the last page is the same as the first
-                       //... page, that is, the recordset has only 1 page.
+
+       $pagecounteroffset = ($page * $nrows) - $nrows;
+
+       // To find out if there are more pages of rows, simply increase the limit or
+       // nrows by 1 and see if that number of records was returned. If it was,
+       // then we know there is at least one more page left, otherwise we are on
+       // the last page. Therefore allow non-Count() paging with single queries
+       // rather than three queries as was done before.
+       $test_nrows = $nrows + 1;
+       if ($secs2cache > 0) {
+               $rsreturn = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
+       } else {
+               $rsreturn = $zthis->SelectLimit($sql, $test_nrows, $pagecounteroffset, $inputarr, $secs2cache);
        }
 
-       // We get the data we want
-       $offset = $nrows * ($page-1);
-       if ($secs2cache > 0) $rsreturn = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
-       else $rsreturn = $zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
+       // Now check to see if the number of rows returned was the higher value we asked for or not.
+       if ( $rsreturn->_numOfRows == $test_nrows ) {
+               // Still at least 1 more row, so we are not on last page yet...
+               // Remove the last row from the RS.
+               $rsreturn->_numOfRows = ( $rsreturn->_numOfRows - 1 );
+       } elseif ( $rsreturn->_numOfRows == 0 && $page > 1 ) {
+               // Likely requested a page that doesn't exist, so need to find the last
+               // page and return it. Revert to original method and loop through pages
+               // until we find some data...
+               $pagecounter = $page + 1;
+               $pagecounteroffset = ($pagecounter * $nrows) - $nrows;
+
+               $rstest = $rsreturn;
+               if ($rstest) {
+                       while ($rstest && $rstest->EOF && $pagecounter > 0) {
+                               $atlastpage = true;
+                               $pagecounter--;
+                               $pagecounteroffset = $nrows * ($pagecounter - 1);
+                               $rstest->Close();
+                               if ($secs2cache>0) {
+                                       $rstest = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
+                               }
+                               else {
+                                       $rstest = $zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
+                               }
+                       }
+                       if ($rstest) $rstest->Close();
+               }
+               if ($atlastpage) {
+                       // If we are at the last page or beyond it, we are going to retrieve it
+                       $page = $pagecounter;
+                       if ($page == 1) {
+                               // We have to do this again in case the last page is the same as
+                               // the first page, that is, the recordset has only 1 page.
+                               $atfirstpage = true;
+                       }
+               }
+               // We get the data we want
+               $offset = $nrows * ($page-1);
+               if ($secs2cache > 0) {
+                       $rsreturn = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
+               }
+               else {
+                       $rsreturn = $zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
+               }
+       } elseif ( $rsreturn->_numOfRows < $test_nrows ) {
+               // Rows is less than what we asked for, so must be at the last page.
+               $atlastpage = true;
+       }
 
        // Before returning the RecordSet, we set the pagination properties we need
        if ($rsreturn) {
index 6e0040d..25f0fe6 100644 (file)
@@ -7,11 +7,13 @@ global $ADODB_INCLUDED_MEMCACHE;
 $ADODB_INCLUDED_MEMCACHE = 1;
 
 global $ADODB_INCLUDED_CSV;
-if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');
+if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
 
 /*
 
-  V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+  @version   v5.20.1  06-Dec-2015
+  @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+  @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence. See License.txt.
@@ -48,7 +50,7 @@ $db->CacheExecute($sql);
                var $_connected = false;
                var $_memcache = false;
 
-               function ADODB_Cache_MemCache(&$obj)
+               function __construct(&$obj)
                {
                        $this->hosts = $obj->memCacheHost;
                        $this->port = $obj->memCachePort;
index a08ced4..bdb2ca3 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 
 /*
-       V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+       @version   v5.20.1  06-Dec-2015
+       @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+       @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
          Released under both BSD license and Lesser GPL library license.
          Whenever there is any discrepancy between the two licenses,
          the BSD license will take precedence.
@@ -55,7 +57,7 @@ class ADODB_Pager {
        //              if you have multiple on 1 page.
        //              $id should be only be [a-z0-9]*
        //
-       function ADODB_Pager(&$db,$sql,$id = 'adodb', $showPageLinks = false)
+       function __construct(&$db,$sql,$id = 'adodb', $showPageLinks = false)
        {
        global $PHP_SELF;
 
index 49ba936..edf1548 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 /**
- * @version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+ * @version   v5.20.1  06-Dec-2015
+ * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+ * @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
  * Released under both BSD license and Lesser GPL library license.
  * Whenever there is any discrepancy between the two licenses,
  * the BSD license will take precedence.
@@ -52,10 +54,6 @@ if (!defined('DB_OK')) {
 define("DB_OK",        1);
 define("DB_ERROR",-1);
 
-// autoExecute constants
-define('DB_AUTOQUERY_INSERT', 1);
-define('DB_AUTOQUERY_UPDATE', 2);
-
 /**
  * This is a special constant that tells DB the user hasn't specified
  * any particular get mode, so the default should be used.
index 8e6e6cc..6a98678 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 /*
-V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+@version   v5.20.1  06-Dec-2015
+@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+@copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence. See License.txt.
@@ -224,7 +226,7 @@ class adodb_perf {
        var $cliFormat = "%32s => %s \r\n";
        var $sql1 = 'sql1';  // used for casting sql1 to text for mssql
        var $explain = true;
-       var $helpurl = "<a href=http://phplens.com/adodb/reference.functions.fnexecute.and.fncacheexecute.properties.html#logsql>LogSQL help</a>";
+       var $helpurl = '<a href="http://adodb.sourceforge.net/docs-adodb.htm#logsql">LogSQL help</a>';
        var $createTableSQL = false;
        var $maxLength = 2000;
 
index e999983..ab47b2c 100644 (file)
@@ -1,7 +1,9 @@
 <?php
 
 /*
-  V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+  @version   v5.20.1  06-Dec-2015
+  @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+  @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
index c74778b..c8f4ae5 100644 (file)
@@ -1,7 +1,11 @@
 <?php
-/**
+/*
 ADOdb Date Library, part of the ADOdb abstraction library
-Download: http://phplens.com/phpeverywhere/
+Download: http://adodb.sourceforge.net/#download
+
+@version   v5.20.1  06-Dec-2015
+@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+@copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
 
 PHP native date functions use integer timestamps for computations.
 Because of this, dates are restricted to the years 1901-2038 on Unix
index 72a9f9b..0890155 100644 (file)
@@ -118,7 +118,7 @@ class dbObject {
        /**
        * NOP
        */
-       function dbObject( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
        }
 
@@ -248,7 +248,7 @@ class dbTable extends dbObject {
        * @param string $prefix DB Object prefix
        * @param array $attributes Array of table attributes.
        */
-       function dbTable( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
                $this->name = $this->prefix($attributes['NAME']);
        }
@@ -642,7 +642,7 @@ class dbIndex extends dbObject {
        *
        * @internal
        */
-       function dbIndex( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
 
                $this->name = $this->prefix ($attributes['NAME']);
@@ -786,7 +786,7 @@ class dbData extends dbObject {
        *
        * @internal
        */
-       function dbData( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
        }
 
@@ -985,7 +985,7 @@ class dbQuerySet extends dbObject {
        * @param object $parent Parent object
        * @param array $attributes Attributes
        */
-       function dbQuerySet( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
 
                // Overrides the manual prefix key
@@ -1301,7 +1301,7 @@ class adoSchema {
        *
        * @param object $db ADOdb database connection object.
        */
-       function adoSchema( $db ) {
+       function __construct( $db ) {
                // Initialize the environment
                $this->mgq = get_magic_quotes_runtime();
                ini_set("magic_quotes_runtime", 0);
index 3ed5aec..45a59bb 100644 (file)
@@ -136,7 +136,7 @@ class dbObject {
        /**
        * NOP
        */
-       function dbObject( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
        }
 
@@ -273,7 +273,7 @@ class dbTable extends dbObject {
        * @param string $prefix DB Object prefix
        * @param array $attributes Array of table attributes.
        */
-       function dbTable( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
                $this->name = $this->prefix($attributes['NAME']);
        }
@@ -683,7 +683,7 @@ class dbIndex extends dbObject {
        *
        * @internal
        */
-       function dbIndex( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
 
                $this->name = $this->prefix ($attributes['NAME']);
@@ -828,7 +828,7 @@ class dbData extends dbObject {
        *
        * @internal
        */
-       function dbData( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
        }
 
@@ -1084,7 +1084,7 @@ class dbQuerySet extends dbObject {
        * @param object $parent Parent object
        * @param array $attributes Attributes
        */
-       function dbQuerySet( &$parent, $attributes = NULL ) {
+       function __construct( &$parent, $attributes = NULL ) {
                $this->parent = $parent;
 
                // Overrides the manual prefix key
@@ -1405,7 +1405,7 @@ class adoSchema {
        *
        * @param object $db ADOdb database connection object.
        */
-       function adoSchema( $db ) {
+       function __construct( $db ) {
                // Initialize the environment
                $this->mgq = get_magic_quotes_runtime();
                #set_magic_quotes_runtime(0);
@@ -2104,11 +2104,12 @@ class adoSchema {
 
                $schema = '<?xml version="1.0"?>' . "\n"
                                . '<schema version="' . $this->schemaVersion . '">' . "\n";
-
-               if( is_array( $tables = $this->db->MetaTables( 'TABLES' , ($prefix) ? $prefix.'%' : '') ) ) {
+               if( is_array( $tables = $this->db->MetaTables( 'TABLES' ,false ,($prefix) ? str_replace('_','\_',$prefix).'%' : '') ) ) {
                        foreach( $tables as $table ) {
-                               if ($stripprefix) $table = str_replace(str_replace('\\_', '_', $pfx ), '', $table);
-                               $schema .= $indent . '<table name="' . htmlentities( $table ) . '">' . "\n";
+                               $schema .= $indent
+                                       . '<table name="'
+                                       . htmlentities( $stripprefix ? str_replace($prefix, '', $table) : $table )
+                                       . '">' . "\n";
 
                                // grab details from database
                                $rs = $this->db->Execute( 'SELECT * FROM ' . $table . ' WHERE -1' );
index a561772..82dcd02 100644 (file)
@@ -14,7 +14,9 @@
 /**
        \mainpage
 
-        @version V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
+       @version   v5.20.1  06-Dec-2015
+       @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
+       @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
 
        Released under both BSD license and Lesser GPL library license. You can choose which license
        you prefer.
@@ -44,21 +46,23 @@ if (!defined('_ADODB_LAYER')) {
         * Set ADODB_DIR to the directory where this file resides...
         * This constant was formerly called $ADODB_RootPath
         */
-       if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));
+       if (!defined('ADODB_DIR')) {
+               define('ADODB_DIR',dirname(__FILE__));
+       }
 
        //==============================================================================================
        // GLOBAL VARIABLES
        //==============================================================================================
 
        GLOBAL
-               $ADODB_vers,            // database version
+               $ADODB_vers,            // database version
                $ADODB_COUNTRECS,       // count number of records returned - slows down query
                $ADODB_CACHE_DIR,       // directory to cache recordsets
                $ADODB_CACHE,
                $ADODB_CACHE_CLASS,
                $ADODB_EXTENSION,   // ADODB extension installed
                $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF
-               $ADODB_FETCH_MODE,      // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
+               $ADODB_FETCH_MODE,      // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
                $ADODB_GETONE_EOF,
                $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql.
 
@@ -92,27 +96,59 @@ if (!defined('_ADODB_LAYER')) {
                define('ADODB_TABLE_REGEX','([]0-9a-z_\:\"\`\.\@\[-]*)');
 
        // prefetching used by oracle
-               if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);
+               if (!defined('ADODB_PREFETCH_ROWS')) {
+                       define('ADODB_PREFETCH_ROWS',10);
+               }
 
 
-       /*
-       Controls ADODB_FETCH_ASSOC field-name case. Default is 2, use native case-names.
-       This currently works only with mssql, odbc, oci8po and ibase derived drivers.
+       /**
+        * Fetch mode
+        *
+        * Set global variable $ADODB_FETCH_MODE to one of these constants or use
+        * the SetFetchMode() method to control how recordset fields are returned
+        * when fetching data.
+        *
+        *   - NUM:     array()
+        *   - ASSOC:   array('id' => 456, 'name' => 'john')
+        *   - BOTH:    array(0 => 456, 'id' => 456, 1 => 'john', 'name' => 'john')
+        *   - DEFAULT: driver-dependent
+        */
+               define('ADODB_FETCH_DEFAULT', 0);
+               define('ADODB_FETCH_NUM', 1);
+               define('ADODB_FETCH_ASSOC', 2);
+               define('ADODB_FETCH_BOTH', 3);
 
-               0 = assoc lowercase field names. $rs->fields['orderid']
-               1 = assoc uppercase field names. $rs->fields['ORDERID']
-               2 = use native-case field names. $rs->fields['OrderID']
-       */
+       /**
+        * Associative array case constants
+        *
+        * By defining the ADODB_ASSOC_CASE constant to one of these values, it is
+        * possible to control the case of field names (associative array's keys)
+        * when operating in ADODB_FETCH_ASSOC fetch mode.
+        *   - LOWER:  $rs->fields['orderid']
+        *   - UPPER:  $rs->fields['ORDERID']
+        *   - NATIVE: $rs->fields['OrderID'] (or whatever the RDBMS will return)
+        *
+        * The default is to use native case-names.
+        *
+        * NOTE: This functionality is not implemented everywhere, it currently
+        * works only with: mssql, odbc, oci8 and ibase derived drivers
+        */
                define('ADODB_ASSOC_CASE_LOWER', 0);
                define('ADODB_ASSOC_CASE_UPPER', 1);
                define('ADODB_ASSOC_CASE_NATIVE', 2);
 
-               define('ADODB_FETCH_DEFAULT',0);
-               define('ADODB_FETCH_NUM',1);
-               define('ADODB_FETCH_ASSOC',2);
-               define('ADODB_FETCH_BOTH',3);
 
-               if (!defined('TIMESTAMP_FIRST_YEAR')) define('TIMESTAMP_FIRST_YEAR',100);
+               if (!defined('TIMESTAMP_FIRST_YEAR')) {
+                       define('TIMESTAMP_FIRST_YEAR',100);
+               }
+
+               /**
+                * AutoExecute constants
+                * (moved from adodb-pear.inc.php since they are only used in here)
+                */
+               define('DB_AUTOQUERY_INSERT', 1);
+               define('DB_AUTOQUERY_UPDATE', 2);
+
 
                // PHP's version scheme makes converting to numbers difficult - workaround
                $_adodb_ver = (float) PHP_VERSION;
@@ -120,20 +156,20 @@ if (!defined('_ADODB_LAYER')) {
                        define('ADODB_PHPVER',0x5200);
                } else if ($_adodb_ver >= 5.0) {
                        define('ADODB_PHPVER',0x5000);
-               } else
+               } else {
                        die("PHP5 or later required. You are running ".PHP_VERSION);
+               }
+               unset($_adodb_ver);
        }
 
 
-       //if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);
-
-
        /**
-               Accepts $src and $dest arrays, replacing string $data
+               Accepts $src and $dest arrays, replacing string $data
        */
-       function ADODB_str_replace($src, $dest, $data)
-       {
-               if (ADODB_PHPVER >= 0x4050) return str_replace($src,$dest,$data);
+       function ADODB_str_replace($src, $dest, $data) {
+               if (ADODB_PHPVER >= 0x4050) {
+                       return str_replace($src,$dest,$data);
+               }
 
                $s = reset($src);
                $d = reset($dest);
@@ -145,20 +181,21 @@ if (!defined('_ADODB_LAYER')) {
                return $data;
        }
 
-       function ADODB_Setup()
-       {
+       function ADODB_Setup() {
        GLOBAL
-               $ADODB_vers,            // database version
+               $ADODB_vers,            // database version
                $ADODB_COUNTRECS,       // count number of records returned - slows down query
                $ADODB_CACHE_DIR,       // directory to cache recordsets
-               $ADODB_FETCH_MODE,
+               $ADODB_FETCH_MODE,
                $ADODB_CACHE,
                $ADODB_CACHE_CLASS,
                $ADODB_FORCE_TYPE,
                $ADODB_GETONE_EOF,
                $ADODB_QUOTE_FIELDNAMES;
 
-               if (empty($ADODB_CACHE_CLASS)) $ADODB_CACHE_CLASS =  'ADODB_Cache_File' ;
+               if (empty($ADODB_CACHE_CLASS)) {
+                       $ADODB_CACHE_CLASS =  'ADODB_Cache_File' ;
+               }
                $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;
                $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE;
                $ADODB_GETONE_EOF = null;
@@ -167,8 +204,9 @@ if (!defined('_ADODB_LAYER')) {
                        $ADODB_CACHE_DIR = '/tmp'; //(isset($_ENV['TMP'])) ? $_ENV['TMP'] : '/tmp';
                } else {
                        // do not accept url based paths, eg. http:/ or ftp:/
-                       if (strpos($ADODB_CACHE_DIR,'://') !== false)
+                       if (strpos($ADODB_CACHE_DIR,'://') !== false) {
                                die("Illegal path http:// or ftp://");
+                       }
                }
 
 
@@ -180,14 +218,16 @@ if (!defined('_ADODB_LAYER')) {
                /**
                 * ADODB version as a string.
                 */
-               $ADODB_vers = 'V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved. Released BSD & LGPL.';
+               $ADODB_vers = 'v5.20.1  06-Dec-2015';
 
                /**
                 * Determines whether recordset->RecordCount() is used.
                 * Set to false for highest performance -- RecordCount() will always return -1 then
                 * for databases that provide "virtual" recordcounts...
                 */
-               if (!isset($ADODB_COUNTRECS)) $ADODB_COUNTRECS = true;
+               if (!isset($ADODB_COUNTRECS)) {
+                       $ADODB_COUNTRECS = true;
+               }
        }
 
 
@@ -220,18 +260,19 @@ if (!defined('_ADODB_LAYER')) {
        }
 
 
-       function _adodb_safedate($s)
-       {
+       function _adodb_safedate($s) {
                return str_replace(array("'", '\\'), '', $s);
        }
 
        // parse date string to prevent injection attack
        // date string will have one quote at beginning e.g. '3434343'
-       function _adodb_safedateq($s)
-       {
+       function _adodb_safedateq($s) {
                $len = strlen($s);
-               if ($s[0] !== "'") $s2 = "'".$s[0];
-               else $s2 = "'";
+               if ($s[0] !== "'") {
+                       $s2 = "'".$s[0];
+               } else {
+                       $s2 = "'";
+               }
                for($i=1; $i<$len; $i++) {
                        $ch = $s[$i];
                        if ($ch === '\\') {
@@ -251,8 +292,7 @@ if (!defined('_ADODB_LAYER')) {
 
        // for transaction handling
 
-       function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)
-       {
+       function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) {
                //print "Errorno ($fn errno=$errno m=$errmsg) ";
                $thisConnection->_transOK = false;
                if ($thisConnection->_oldRaiseFn) {
@@ -267,63 +307,68 @@ if (!defined('_ADODB_LAYER')) {
 
                var $createdir = true; // requires creation of temp dirs
 
-               function ADODB_Cache_File()
-               {
-               global $ADODB_INCLUDED_CSV;
-                       if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
+               function __construct() {
+                       global $ADODB_INCLUDED_CSV;
+                       if (empty($ADODB_INCLUDED_CSV)) {
+                               include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
+                       }
                }
 
                // write serialised recordset to cache item/file
-               function writecache($filename, $contents,  $debug, $secs2cache)
-               {
+               function writecache($filename, $contents,  $debug, $secs2cache) {
                        return adodb_write_file($filename, $contents,$debug);
                }
 
                // load serialised recordset and unserialise it
-               function &readcache($filename, &$err, $secs2cache, $rsClass)
-               {
+               function &readcache($filename, &$err, $secs2cache, $rsClass) {
                        $rs = csv2rs($filename,$err,$secs2cache,$rsClass);
                        return $rs;
                }
 
                // flush all items in cache
-               function flushall($debug=false)
-               {
-               global $ADODB_CACHE_DIR;