From 3236f2cbb784c5d17caa1da29c850dc3a269a9fe Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 24 Sep 2005 18:33:31 +0000 Subject: [PATCH] r435: - added build_language_cache() to cache the XML data for languages - delete/kill implementations now work in admin/language --- admin/language.php | 44 +++++++++++++++++++++++++++++++------------ includes/language.php | 15 +++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/admin/language.php b/admin/language.php index ba373e9..8f9464b 100644 --- a/admin/language.php +++ b/admin/language.php @@ -11,6 +11,7 @@ \*=====================================================================*/ require_once('./global.php'); +require_once('./includes/functions_datastore.php'); if (!can_perform('canadmintools')) { @@ -28,21 +29,48 @@ if (empty($_REQUEST['do'])) if ($_REQUEST['do'] == 'kill') { - // run code to remove item in database + $count = $db->query_first("SELECT COUNT(*) AS count FROM language"); + if ($count['count'] < 2) + { + $admin->error($lang->string('At least one language needs to be present. Deleting this language would violate that.')); + } + + $language = $db->query_first("SELECT * FROM language WHERE languageid = " . intval($bugsys->in['languageid'])); + if ($language['default']) + { + $admin->error($lang->string('You cannot delete the default language. Please select another language to be the default language and then delete this one.')); + } + + $db->query("DELETE FROM language WHERE languageid = " . intval($bugsys->in['languageid'])); + $db->query("DELETE FROM localization WHERE languageid = " . intval($bugsys->in['languageid'])); + build_languages(); + $admin->redirect('language.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'delete') { - // display delete confirmation message + $admin->page_confirm($lang->string('Are you sure you want to delete this language?'), 'language.php?do=kill&languageid=' . intval($bugsys->in['languageid'])); } // ################################################################### if ($_POST['do'] == 'insert') { - // run code to insert new item into database + $languageid = $db->query(" + INSERT INTO language + (title, charset, direction, userselect, debug, filename) + VALUES + ('" . $bugsys->in['title'] . "', '" . $bugsys->in['charset'] . "', + '" . $bugsys->in['direction'] . "', " . intval($bugsys->in['userselect']) . ", + " . intval($bugsys->in['debug']) . ", '" . $bugsys->in['filename'] . "' + )" + ); + + build_languages(); + + build_language_cache($languageid); } // ################################################################### @@ -135,15 +163,7 @@ if ($_REQUEST['do'] == 'reload') $admin->error($lang->getlex('error_invalid_id')); } - $db->query("DELETE FROM localization WHERE languageid = $language[languageid]"); - - require_once('./includes/language.php'); - - $localizations = fetch_phrases($language['languageid'], true); - foreach ($localizations AS $key => $value) - { - $db->query("INSERT INTO localization (localkey, localtext, languageid) VALUES ('" . $bugsys->escape($key) . "', '" . $bugsys->escape($value) . "', $language[languageid])"); - } + build_language_cache($language['languageid']); $admin->redirect('language.php?do=modify'); } diff --git a/includes/language.php b/includes/language.php index 8584b31..07d8034 100644 --- a/includes/language.php +++ b/includes/language.php @@ -15,6 +15,21 @@ $lang->setlex('error_invalid_id', $lang->string('That is an invalid ID.')); +// ################################################################### +// updates the localization cache +function build_language_cache($languageid) +{ + global $bugsys; + + $bugsys->db->query("DELETE FROM localization WHERE languageid = $languageid"); + + $localizations = fetch_phrases($language['languageid'], true); + foreach ($localizations AS $key => $value) + { + $bugsys->db->query("INSERT INTO localization (localkey, localtext, languageid) VALUES ('" . $bugsys->escape($key) . "', '" . $bugsys->escape($value) . "', $languageid)"); + } +} + // ################################################################### // fetches phrases from the system function fetch_phrases($languageid, $forcexml = false) -- 2.22.5