$currentUpdateStep = 0; if (!$gDb->query('SELECT 1 FROM ' . TBL_COMPONENTS, false)) { // in Admidio version 2 the database version was stored in preferences table if (isset($gPreferences['db_version'])) { $installedDbVersion = $gPreferences['db_version']; $installedDbBetaVersion = $gPreferences['db_version_beta']; } } else { // read system component $componentUpdateHandle = new ComponentUpdate($gDb); $componentUpdateHandle->readDataByColumns(array('com_type' => 'SYSTEM', 'com_name_intern' => 'CORE')); if ($componentUpdateHandle->getValue('com_id') > 0) { $installedDbVersion = $componentUpdateHandle->getValue('com_version'); $installedDbBetaVersion = $componentUpdateHandle->getValue('com_beta'); $currentUpdateStep = $componentUpdateHandle->getValue('com_update_step'); $maxUpdateStep = $componentUpdateHandle->getMaxUpdateStep(); } } // if a beta was installed then create the version string with Beta version if ($installedDbBetaVersion > 0) { $installedDbVersion = $installedDbVersion . ' Beta ' . $installedDbBetaVersion; } // if database version is not set then show notice if ($installedDbVersion === '') { $message = ' <div class="alert alert-danger alert-small" role="alert"> <span class="glyphicon glyphicon-exclamation-sign"></span> <strong>' . $gL10n->get('INS_UPDATE_NOT_POSSIBLE') . '</strong> </div> <p>' . $gL10n->get('INS_NO_INSTALLED_VERSION_FOUND', ADMIDIO_VERSION_TEXT) . '</p>'; showNotice($message, $g_root_path . '/adm_program/index.php', $gL10n->get('SYS_OVERVIEW'), 'layout/application_view_list.png', true);
foreach ($sql_arr as $sql) { if (trim($sql) !== '') { // Prefix fuer die Tabellen einsetzen und SQL-Statement ausfuehren $sql = str_replace('%PREFIX%', $g_tbl_praefix, $sql); $db->query($sql); } } // create default data // add system component to database $component = new ComponentUpdate($db); $component->setValue('com_type', 'SYSTEM'); $component->setValue('com_name', 'Admidio Core'); $component->setValue('com_name_intern', 'CORE'); $component->setValue('com_version', ADMIDIO_VERSION); $component->setValue('com_beta', (string) ADMIDIO_VERSION_BETA); $component->setValue('com_update_step', $component->getMaxUpdateStep()); $component->save(); // create a hidden system user for internal use // all recordsets created by installation will get the create id of the system user $gCurrentUser = new TableUsers($db); $gCurrentUser->setValue('usr_login_name', $gL10n->get('SYS_SYSTEM')); $gCurrentUser->setValue('usr_valid', '0'); $gCurrentUser->setValue('usr_timestamp_create', DATETIME_NOW); $gCurrentUser->save(false); // no registered user -> UserIdCreate couldn't be filled $systemUserId = $gCurrentUser->getValue('usr_id'); // create all modules components $sql = 'INSERT INTO ' . TBL_COMPONENTS . ' (com_type, com_name, com_name_intern, com_version, com_beta) VALUES (\'MODULE\', \'ANN_ANNOUNCEMENTS\', \'ANNOUCEMENTS\', \'' . ADMIDIO_VERSION . '\', ' . ADMIDIO_VERSION_BETA . ') , (\'MODULE\', \'BAC_DATABASE_BACKUP\', \'BACKUP\', \'' . ADMIDIO_VERSION . '\', ' . ADMIDIO_VERSION_BETA . ') , (\'MODULE\', \'SYS_CATEGORIES\', \'CATEGORIES\', \'' . ADMIDIO_VERSION . '\', ' . ADMIDIO_VERSION_BETA . ')