From 1f188888976ee8302265e2e9b093a13f47d69eb8 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 18 Aug 2006 00:26:16 +0000 Subject: [PATCH] r1051: Finalizing the LanguageAPI and implementing it --- admin/language.php | 81 ++++++++++++++++----------------------- docs/changes.txt | 1 + includes/api_language.php | 21 ++++++++++ 3 files changed, 54 insertions(+), 49 deletions(-) diff --git a/admin/language.php b/admin/language.php index 10de8a0..2f8e02b 100644 --- a/admin/language.php +++ b/admin/language.php @@ -19,10 +19,11 @@ || ################################################################### \*=====================================================================*/ -// #*# create API for language.php - require_once('./global.php'); -require_once('./includes/functions_datastore.php'); +require_once('./includes/api_language.php'); + +require_once('./includes/class_api_error.php'); +APIError(array(new API_Error_Handler($admin), 'admin_error')); NavLinks::optionsPages(); $navigator->set_focus('tab', 'options', null); @@ -43,21 +44,11 @@ if (empty($_REQUEST['do'])) if ($_REQUEST['do'] == 'kill') { - $bugsys->input_clean('languageid', TYPE_UINT); - $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "language"); - if ($count['count'] < 2) - { - $admin->error(_('At least one language needs to be present. Deleting this language would violate that.')); - } + $language = new LanguageAPI($bugsys); + $language->set('languageid', $bugsys->in['languageid']); + $language->set_condition(); + $language->insert(); - if ($bugsys->options['defaultlanguage'] == $bugsys->in['languageid']) - { - $admin->error(_('You cannot delete the default language. Please select another language to be the default language and then delete this one.')); - } - - $db->query("DELETE FROM " . TABLE_PREFIX . "language WHERE languageid = " . $bugsys->in['languageid']); - $db->query("DELETE FROM " . TABLE_PREFIX . "localization WHERE languageid = " . $bugsys->in['languageid']); - build_languages(); $admin->redirect('language.php?do=modify'); } @@ -72,19 +63,14 @@ if ($_REQUEST['do'] == 'delete') if ($_POST['do'] == 'insert') { - $languageid = $db->query(" - INSERT INTO " . TABLE_PREFIX . "language - (title, charset, direction, userselect, debug, filename) - VALUES - ('" . $bugsys->in['title'] . "', '" . $bugsys->in['charset'] . "', - '" . $bugsys->in['direction'] . "', " . $bugsys->input_clean('userselect', TYPE_UINT) . ", - " . $bugsys->input_clean('debug', TYPE_UINT) . ", '" . $bugsys->in['filename'] . "' - )" - ); - - build_languages(); - - build_language_cache($db->insert_id()); + $language = new LanguageAPI($bugsys); + $language->set('title', $bugsys->in['title']); + $language->set('charset', $bugsys->in['charset']); + $language->set('direction', $bugsys->in['direction']); + $language->set('userselect', $bugsys->in['userselect']); + $language->set('debug', $bugsys->in['debug']); + $language->set('filename', $bugsys->in['filename']); + $language->insert(); $admin->redirect('language.php?do=modify'); } @@ -122,18 +108,16 @@ if ($_REQUEST['do'] == 'add') if ($_POST['do'] == 'update') { - $db->query(" - UPDATE " . TABLE_PREFIX . "language - SET title = '" . $bugsys->in['title'] . "', - charset = '" . $bugsys->in['charset'] . "', - direction = '" . $bugsys->in['direction'] . "', - userselect = " . $bugsys->input_clean('userselect', TYPE_UINT) . ", - debug = " . $bugsys->input_clean('langdebug', TYPE_UINT) . ", - filename = '" . $bugsys->in['filename'] . "' - WHERE languageid = " . $bugsys->input_clean('languageid', TYPE_UINT) - ); - - build_languages(); + $language = new LanguageAPI($bugsys); + $language->set('languageid', $bugsys->in['languageid']); + $language->set_condition(); + $language->set('title', $bugsys->in['title']); + $language->set('charset', $bugsys->in['charset']); + $language->set('direction', $bugsys->in['direction']); + $language->set('userselect', $bugsys->in['userselect']); + $language->set('debug', $bugsys->in['debug']); + $language->set('filename', $bugsys->in['filename']); + $language->update(); $admin->redirect('language.php?do=modify'); } @@ -142,16 +126,15 @@ if ($_POST['do'] == 'update') if ($_REQUEST['do'] == 'edit') { - $bugsys->input_clean('languageid', TYPE_UINT); - NavLinks::languagesEdit($bugsys->in['languageid']); $navigator->set_focus('link', 'options-languages-edit', 'options-languages'); - $language = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "language WHERE languageid = " . $bugsys->in['languageid']); - if (!$language) - { - $admin->error($lang->getlex('error_invalid_id')); - } + $languageapi = new LanguageAPI($bugsys); + $languageapi->set('languageid', $bugsys->in['languageid']); + $languageapi->set_condition(); + $languageapi->fetch(); + + $language =& $languageapi->objdata; $admin->page_start(_('Edit Language')); diff --git a/docs/changes.txt b/docs/changes.txt index 1b7ca8e..4c726bd 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -6,6 +6,7 @@ - Changed the access key for "Save Report and Add Another" button to E - Removed potential warnings when there are no products [includes/functions.php#417] (http://bugs.bluestatic.org/showreport.php?bugid=26) - Removed potential warnings if there is no page navigator [class_pagination.php#243] (http://bugs.bluestatic.org/showreport.php?bugid=26) +- Created a Language API 1.1.0 Beta 1 ================== diff --git a/includes/api_language.php b/includes/api_language.php index 61612ca..d6d1319 100644 --- a/includes/api_language.php +++ b/includes/api_language.php @@ -42,6 +42,8 @@ class LanguageAPI extends API var $fields = array( 'languageid' => array(TYPE_UINT, REQ_AUTO, 'verify_nozero'), 'title' => array(TYPE_STR, REQ_YES, 'verify_noempty'), + 'charset' => array(TYPE_STR, REQ_YES), + 'debug' => array(TYPE_BOOL, REQ_NO), 'direction' => array(TYPE_STR, REQ_NO, ':self'), 'userselect' => array(TYPE_BOOL, REQ_NO), 'filename' => array(TYPE_STR, REQ_YES) @@ -84,6 +86,24 @@ class LanguageAPI extends API build_languages(); } + // ################################################################### + /** + * Pre-delete + */ + function pre_delete() + { + $count = $this->registry->db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "language"); + if ($count['count'] < 2) + { + $this->error(_('At least one language needs to be present. Deleting this language would violate that.')); + } + + if ($this->registry->options['defaultlanguage'] == $this->values['languageid']) + { + $this->error(_('You cannot delete the default language. Please select another language to be the default language and then delete this one.')); + } + } + // ################################################################### /** * Post-delete @@ -93,6 +113,7 @@ class LanguageAPI extends API function post_delete() { build_languages(); + $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "localization WHERE languageid = " . $this->values['languageid']); } // ################################################################### -- 2.43.5