function upgrade_211_212()
{
    global $conf;
    $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";", $conf['nbc_UserAdvManager']) : array();
    if (!isset($conf_UAM[14]) and !isset($conf_UAM[15]) and !isset($conf_UAM[16]) and !isset($conf_UAM[17])) {
        $upgrade_UAM = $conf_UAM[0] . ';' . $conf_UAM[1] . ';' . $conf_UAM[2] . ';' . $conf_UAM[3] . ';' . $conf_UAM[4] . ';' . $conf_UAM[5] . ';' . $conf_UAM[6] . ';' . $conf_UAM[7] . ';' . $conf_UAM[8] . ';' . $conf_UAM[9] . ';' . $conf_UAM[10] . ';' . $conf_UAM[11] . ';' . $conf_UAM[12] . ';' . $conf_UAM[13] . ';false;100;false;false;10;Hello.
	
This is a reminder because a very long time passed since your last visit on our gallery. If you do not want anymore to use your access account, please let us know by replying to this email. Your account will be deleted.

On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.

Best regards,

The admin of the gallery.';
        conf_update_param('nbc_UserAdvManager', pwg_db_real_escape_string($upgrade_UAM));
    }
    $q = "\nCREATE TABLE IF NOT EXISTS " . USER_LASTVISIT_TABLE . " (\n  user_id SMALLINT(5) NOT NULL DEFAULT '0',\n  lastvisit DATETIME NULL DEFAULT NULL,\n  reminder ENUM('true','false') NULL,\nPRIMARY KEY (`user_id`)\n  )\n;";
    pwg_query($q);
    upgrade_212_213();
}
function plugin_activate($id, $version, &$errors)
{
    global $conf;
    /* Cleaning obsolete files */
    /* *********************** */
    clean_obsolete_files();
    include_once UAM_PATH . 'include/upgradedb.inc.php';
    /* Check if old version is < 2.15 */
    /* ****************************** */
    $query = '
SELECT param
  FROM ' . CONFIG_TABLE . '
WHERE param = "nbc_UserAdvManager"
;';
    $count1 = pwg_db_num_rows(pwg_query($query));
    $query = '
SELECT *
  FROM ' . CONFIG_TABLE . '
WHERE param = "nbc_UserAdvManager_ConfirmMail"
;';
    $count2 = pwg_db_num_rows(pwg_query($query));
    /* If old params exist an upgrade is needed */
    /* **************************************** */
    if ($count1 == 1) {
        /* Check for upgrade from 2.10 to 2.11 */
        /* *********************************** */
        if ($count1 == 1 and $count2 == 0) {
            /* upgrade from branch 2.10 to 2.11 */
            /* ******************************** */
            upgrade_210_211();
        }
        /* Check for upgrade from 2.11 to 2.12 */
        /* *********************************** */
        if (!table_exist(USER_LASTVISIT_TABLE)) {
            /* upgrade from branch 2.11 to 2.12 */
            /* ******************************** */
            upgrade_211_212();
        }
        /* Check for upgrade from 2.12 to 2.13 */
        /* *********************************** */
        $fields = pwg_query('SHOW COLUMNS FROM ' . USER_CONFIRM_MAIL_TABLE . ';');
        $nb_fields = pwg_db_num_rows($fields);
        if ($nb_fields < 6) {
            /* upgrade from branch 2.12 to 2.13 */
            /* ******************************** */
            upgrade_212_213();
        }
        /* Serializing conf parameters - Available since 2.14.0 */
        /* **************************************************** */
        if (unserialize($conf['nbc_UserAdvManager']) === false) {
            /* upgrade from branch 2.13 to 2.14 */
            /* ******************************** */
            upgrade_213_214();
        }
        /* upgrade from branch 2.14 to 2.15 */
        /* ******************************** */
        upgrade_214_215();
    }
    /* Old version is > 2.15 */
    /* ********************* */
    $query = '
SELECT param
  FROM ' . CONFIG_TABLE . '
WHERE param = "UserAdvManager_Redir"
;';
    $count = pwg_db_num_rows(pwg_query($query));
    if ($count == 0) {
        upgrade_2153_2154();
    }
    /* Check for upgrade from 2.15 to 2.16 */
    /* *********************************** */
    $query = '
SELECT param
  FROM ' . CONFIG_TABLE . '
WHERE param = "UserAdvManager_Version"
;';
    $count = pwg_db_num_rows(pwg_query($query));
    if ($count == 0) {
        /* upgrade from branch 2.15 to 2.16 */
        /* ******************************** */
        upgrade_215_2160();
    }
    /* Check database upgrade since version 2.16.0 */
    /* ******************************************* */
    if (isset($conf['UserAdvManager_Version'])) {
        if (version_compare($conf['UserAdvManager_Version'], '2.20.0') < 0) {
            /* upgrade from branch 2.16 to 2.20 */
            /* ******************************** */
            upgrade_216_220();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.20.4') < 0) {
            /* upgrade from version 2.20.3 to 2.20.4 */
            /* ************************************* */
            upgrade_2203_2204();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.20.7') < 0) {
            /* upgrade from version 2.20.4 to 2.20.7 */
            /* ************************************* */
            upgrade_2204_2207();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.20.8') < 0) {
            /* upgrade from version 2.20.7 to 2.20.8 */
            /* ************************************* */
            upgrade_2207_2208();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.30.0') < 0) {
            /* upgrade from version 2.20.8 to 2.30.0 */
            /* ************************************* */
            upgrade_2208_2300();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.30.2') < 0) {
            /* upgrade from version 2.30.x to 2.30.2 */
            /* ************************************* */
            upgrade_2300_2302();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.40.0') < 0) {
            /* upgrade from version 2.30.x to 2.40.0 */
            /* ************************************* */
            upgrade_2300_2400();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.41.0') < 0) {
            /* upgrade from version 2.40.x to 2.41.0 */
            /* ************************************* */
            upgrade_2400_2410();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.50.0') < 0) {
            /* upgrade from version 2.41.x to 2.50.0 */
            /* ************************************* */
            upgrade_2410_2500();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.50.11') < 0) {
            /* upgrade from version 2.50.x to 2.50.11 */
            /* ************************************** */
            upgrade_2500_25011();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.51.0') < 0) {
            /* upgrade from version 2.50.x to 2.51.0 */
            /* ************************************* */
            upgrade_2500_2510();
        }
        if (version_compare($conf['UserAdvManager_Version'], '2.70.3') < 0) {
            /* upgrade from version 2.51.0 to 2.70.3 */
            /* ************************************* */
            upgrade_2510_2703();
        }
    }
    // Update plugin version number in #_config table and check consistency of #_plugins table
    // ---------------------------------------------------------------------------------------
    UAM_version_update();
    load_conf_from_db('param like \'UserAdvManager\\_%\'');
}