From 5c411dc42e920f9dd1dc7272f6cbea2ffbb24cc3 Mon Sep 17 00:00:00 2001 From: victoralagwu Date: Fri, 15 Jun 2018 23:08:25 +0100 Subject: [PATCH] ACHECKER-4 --- check/index.php | 11 +++----- include/classes/DAO/ChecksDAO.class.php | 19 +++++++++++++- include/classes/DAO/LanguageTextDAO.class.php | 13 ++++++++++ .../classes/Language/LanguageEditor.class.php | 2 +- include/lib/output.inc.php | 26 ++++++++++--------- 5 files changed, 50 insertions(+), 21 deletions(-) diff --git a/check/index.php b/check/index.php index d99d13b5..af062905 100644 --- a/check/index.php +++ b/check/index.php @@ -195,10 +195,10 @@ } if ($condition == '') $condition = '1'; +$checksDAO = new ChecksDAO(); -$sql = "SELECT COUNT(check_id) AS cnt FROM ".TABLE_PREFIX."checks WHERE $condition"; +$rows = $checksDAO->getChecksByID($condition); -$rows = $dao->execute($sql); $num_results = $rows[0]['cnt']; $num_pages = max(ceil($num_results / $results_per_page), 1); @@ -214,12 +214,9 @@ $results_per_page = 999999; } -$checksDAO = new ChecksDAO(); -$sql = "SELECT * - FROM ".TABLE_PREFIX."checks - WHERE $condition ORDER BY $col $order LIMIT $offset, $results_per_page"; -$check_rows = $dao->execute($sql); + +$check_rows = $checksDAO->getChecks($condition, $col, $order, $offset, $results_per_page); // if prerequisite or next checks are inserted into db successfully, diff --git a/include/classes/DAO/ChecksDAO.class.php b/include/classes/DAO/ChecksDAO.class.php index 821a1d1b..eb5718ba 100644 --- a/include/classes/DAO/ChecksDAO.class.php +++ b/include/classes/DAO/ChecksDAO.class.php @@ -822,5 +822,22 @@ private function deleteLang($checkID, $term, $fieldName) return true; } + + public function getChecks($condition, $col, $order, $offset, $results_per_page) + { + $sql = "SELECT * FROM ".TABLE_PREFIX. + "checks WHERE $condition + ORDER BY $col $order + LIMIT $offset, $results_per_page"; + + return $this->execute($sql); + } + + public function getChecksByID($condition) + { + $sql = "SELECT COUNT(check_id) AS + cnt FROM ".TABLE_PREFIX."checks WHERE $condition"; + + } } -?> \ No newline at end of file +?> diff --git a/include/classes/DAO/LanguageTextDAO.class.php b/include/classes/DAO/LanguageTextDAO.class.php index b17982cc..302d6281 100644 --- a/include/classes/DAO/LanguageTextDAO.class.php +++ b/include/classes/DAO/LanguageTextDAO.class.php @@ -243,5 +243,18 @@ function getMsgByVar($variable) return $this->execute($sql); } + + function getMsgByVarAndLang ($variable, $lang, $parent) + { + $variable = $this->addSlashes($variable); + + $sql = "SELECT * FROM ".TABLE_PREFIX." + language_text WHERE variable=".$variable." + AND (language_code=".$lang." + OR language_code=".$parent.")"; + + return $this->execute($sql); + } + } ?> diff --git a/include/classes/Language/LanguageEditor.class.php b/include/classes/Language/LanguageEditor.class.php index 76fb2efe..7213340b 100644 --- a/include/classes/Language/LanguageEditor.class.php +++ b/include/classes/Language/LanguageEditor.class.php @@ -275,4 +275,4 @@ function export($filename = '') { } } -?> \ No newline at end of file +?> diff --git a/include/lib/output.inc.php b/include/lib/output.inc.php index 0e3183bd..6777b8fb 100644 --- a/include/lib/output.inc.php +++ b/include/lib/output.inc.php @@ -820,17 +820,19 @@ function getTranslatedCodeStr($codes) { $parent = Language::getParentCode($_SESSION['lang']); /* get $_msgs_new from the DB */ - $sql = 'SELECT * FROM '.TABLE_PREFIX.'language_text WHERE variable="_msgs" AND (language_code="'.$_SESSION['lang'].'" OR language_code="'.$parent.'")'; - $result = mysqli_query($languagesDAO->db, $sql); - $i = 1; - while ($row = mysqli_fetch_assoc($result)) { + $rows = $languagesDAO->getMsgByVarAndLang('_msgs', $_SESSION['lang'], $parent); + + + if (is_array($rows)) + { + $row = $rows[0]; // do not cache key as a digit (no contstant(), use string) $_cache_msgs_new[$row['term']] = str_replace('SITE_URL/', $_base_path, $row['text']); if (AC_DEVEL) { $_cache_msgs_new[$row['term']] .= ' ('.$row['term'].')'; } } - + cache_variable('_cache_msgs_new'); endcache(true, false); } @@ -853,14 +855,14 @@ function getTranslatedCodeStr($codes) { if ($message == '') { /* the language for this msg is missing: */ - //$rows = $languagesDAO->getMsgByVar('_msgs'); - $sql = 'SELECT * FROM '.TABLE_PREFIX.'language_text WHERE variable="_msgs"'; - $result = mysqli_query($languagesDAO->db, $sql); - $i = 1; - while ($row = mysqli_fetch_assoc($result)) { - if (($row['term']) === $codes) { + $rows = $languagesDAO->getMsgByVar('_msgs'); + if (is_array($rows)) + { + $row = $rows[0]; + + if (($row['term']) === $codes) + { $message = '['.$row['term'].']'; - break; } } }