function get_installed_version($postinstall = false) { global $database_upgrade_matrix, $PROGRAM_VERSION, $settings, $show_all_errors; // Set this as the default value. $_SESSION['application_name'] = 'Title'; $_SESSION['blank_database'] = ''; // We will append the db_type to come up te proper filename. $_SESSION['install_file'] = 'tables'; $_SESSION['old_program_version'] = $postinstall ? $PROGRAM_VERSION : 'new_install'; // Suppress errors based on $show_all_errors. if (!$show_all_errors) { show_errors(false); } // This data is read from file upgrade_matrix.php. for ($i = 0, $dbCntStr = count($database_upgrade_matrix); $i < $dbCntStr; $i++) { $sql = $database_upgrade_matrix[$i][0]; if ($sql != '') { $res = dbi_execute($sql, array(), false, $show_all_errors); } if ($res) { $_SESSION['old_program_version'] = $database_upgrade_matrix[$i + 1][2]; $_SESSION['install_file'] = $database_upgrade_matrix[$i + 1][3]; $res = ''; $sql = $database_upgrade_matrix[$i][1]; if ($sql != '') { dbi_execute($sql, array(), false, $show_all_errors); } } } $response_msg = $_SESSION['old_program_version'] == 'pre-v0.9.07' ? translate('Perl script required') : translate('previous version requires updating several tables'); // v1.1 and after will have an entry in webcal_config to make this easier // $res = dbi_execute ( 'SELECT cal_value FROM webcal_config // WHERE cal_setting = \'WEBCAL_PROGRAM_VERSION\'', array (), false, false ); // if ( $res ) { // $row = dbi_fetch_row ( $res ); // if ( ! empty ( $row[0] ) ) { // $_SESSION['old_program_version'] = $row[0]; // $_SESSION['install_file'] = 'upgrade_' . $row[0]; // } // dbi_free_result ( $res ); // } // We need to determine if this is a blank database. // This may be due to a manual table setup. $res = dbi_execute('SELECT COUNT( cal_value ) FROM webcal_config', array(), false, $show_all_errors); if ($res) { $row = dbi_fetch_row($res); if (isset($row[0]) && $row[0] == 0) { $_SESSION['blank_database'] = true; } else { // Make sure all existing values in config and pref tables are UPPERCASE. make_uppercase(); // Clear db_cache. This will prevent looping when launching WebCalendar // if upgrading and WEBCAL_PROGRAM_VERSION is cached. if (!empty($settings['db_cachedir'])) { dbi_init_cache($settings['db_cachedir']); } else { if (!empty($settings['cachedir'])) { dbi_init_cache($settings['cachedir']); } } // Delete existing WEBCAL_PROGRAM_VERSION number. dbi_execute('DELETE FROM webcal_config WHERE cal_setting = \'WEBCAL_PROGRAM_VERSION\''); } dbi_free_result($res); // Insert webcal_config values only if blank. db_load_config(); // Check if an Admin account exists. $_SESSION['admin_exists'] = db_check_admin(); } // Determine if old data has been converted to GMT. // This seems lke a good place to put this. $res = dbi_execute('SELECT cal_value FROM webcal_config WHERE cal_setting = \'WEBCAL_TZ_CONVERSION\'', array(), false, $show_all_errors); if ($res) { $row = dbi_fetch_row($res); dbi_free_result($res); // If not 'Y', prompt user to do conversion from server time to GMT time. if (!empty($row[0])) { $_SESSION['tz_conversion'] = $row[0]; } else { // We'll test if any events even exist. $res = dbi_execute('SELECT COUNT( cal_id ) FROM webcal_entry ', array(), false, $show_all_errors); if ($res) { $row = dbi_fetch_row($res); dbi_free_result($res); } $_SESSION['tz_conversion'] = $row[0] > 0 ? 'NEEDED' : 'Y'; } dbi_free_result($res); } // Don't show TZ conversion if blank database. if ($_SESSION['blank_database'] == true) { $_SESSION['tz_conversion'] = 'Y'; } // Get existing server URL. // We could use the self-discvery value, but this may be a custom value. $res = dbi_execute('SELECT cal_value FROM webcal_config WHERE cal_setting = \'SERVER_URL\'', array(), false, $show_all_errors); if ($res) { $row = dbi_fetch_row($res); if (!empty($row[0]) && strlen($row[0])) { $_SESSION['server_url'] = $row[0]; } dbi_free_result($res); } // Get existing application name. $res = dbi_execute('SELECT cal_value FROM webcal_config WHERE cal_setting = \'APPLICATION_NAME\'', array(), false, $show_all_errors); if ($res) { $row = dbi_fetch_row($res); if (!empty($row[0])) { $_SESSION['application_name'] = $row[0]; } dbi_free_result($res); } // Enable warnings. show_errors(true); }
if ($c) { if (isset($_SESSION['application_name'])) { dbi_execute("DELETE FROM webcal_config WHERE cal_setting = 'APPLICATION_NAME'"); dbi_execute("INSERT INTO webcal_config ( cal_setting, cal_value ) " . "VALUES ('APPLICATION_NAME', ?)", array($_SESSION['application_name'])); } if (isset($_SESSION['server_url'])) { dbi_execute("DELETE FROM webcal_config WHERE cal_setting = 'SERVER_URL'"); dbi_execute("INSERT INTO webcal_config ( cal_setting, cal_value ) " . "VALUES ('SERVER_URL', ?)", array($_SESSION['server_url'])); } } $do_load_admin = getPostValue('load_admin'); if (!empty($do_load_admin)) { //add default admin user if not exists db_load_admin(); //check if an Admin account exists $_SESSION['admin_exists'] = db_check_admin(); } $setup_complete = true; } // Save settings to file now. if (!empty($x) || !empty($y)) { if ($doLogin) { // Hack attempt :-) echo "Bugger off.<br>"; exit; } $fd = @fopen($file, 'w+b', false); if (empty($fd)) { if (@file_exists($file)) { $onloadDetailStr = translate('Please change the file permissions of this file', true); } else {