2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 * DAO for "config" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
24 class LanguagesDAO extends DAO {
27 * Insert table languages
29 * @param $langCode, $charset, $regExp, $nativeName, $englishName, $status
30 * @return true / false
33 function Create($langCode, $charset, $regExp, $nativeName, $englishName, $status)
35 global $languageManager, $msg;
37 // check if the required fields are filled
38 if (!$this->ValidateFields($langCode, $charset, $nativeName, $englishName)) return false;
40 // check if the language already exists
41 if ($languageManager->exists($langCode)) $msg->addError('LANG_EXISTS');
43 if (!$msg->containsErrors())
45 $sql = "INSERT INTO ".TABLE_PREFIX."languages (language_code, charset, reg_exp, native_name, english_name, status)
46 VALUES ('".$langCode."', '".$charset."', '".$regExp."', '".$nativeName."', '".$englishName."', ".$status.")";
47 return $this->execute($sql);
54 * @param $langCode: required
56 * @return true / false
59 function Update($langCode, $charset, $regExp, $nativeName, $englishName, $status)
61 // check if the required fields are filled
62 if (!$this->ValidateFields($langCode, $charset, $nativeName, $englishName)) return false;
64 $sql = "UPDATE ".TABLE_PREFIX."languages
65 SET reg_exp='".$regExp."',
66 native_name = '".$nativeName."',
67 english_name = '".$englishName."',
69 WHERE language_code = '".$langCode."'
70 AND charset = '".$charset."'";
71 return $this->execute($sql);
75 * Update the given field with the given value by language_code and charset
80 * @return true / false
83 function UpdateField($langCode, $fieldName, $fieldValue)
87 // check if the required fields are filled
88 if ($fieldValue == '') return false;
90 $sql = "UPDATE ".TABLE_PREFIX."languages
91 SET ".$addslashes($fieldName)."='".$addslashes($fieldValue)."'
92 WHERE language_code = '".$addslashes($langCode)."'";
93 return $this->execute($sql);
101 * @return true / false
102 * @author Cindy Qi Li
104 function Delete($langCode)
106 $sql = "DELETE FROM ".TABLE_PREFIX."languages
107 WHERE language_code = '".$langCode."'";
108 if (!$this->execute($sql)) return false;
110 $sql = "DELETE FROM ".TABLE_PREFIX."language_text
111 WHERE language_code = '".$langCode."'";
113 return $this->execute($sql);
117 * Return all languages
121 * @author Cindy Qi Li
125 $sql = "SELECT * FROM ".TABLE_PREFIX."languages l
126 ORDER BY l.native_name";
127 return $this->execute($sql);
131 * Return all enabled languages
135 * @author Cindy Qi Li
137 function getAllEnabled()
139 $sql = "SELECT * FROM ".TABLE_PREFIX."languages l
140 WHERE status = ".TR_STATUS_ENABLED."
141 ORDER BY l.native_name";
142 return $this->execute($sql);
146 * Return language with given language code
151 * @author Cindy Qi Li
153 function getByLangCodeAndCharset($langCode, $charset)
155 $sql = "SELECT * FROM ".TABLE_PREFIX."languages l
156 WHERE l.language_code = '".$langCode."'
157 AND l.charset='".$charset."'
158 ORDER BY l.native_name";
160 if ($rows = $this->execute($sql))
167 * Return all languages except the ones with language code in the given string
169 * @param $langCode : one language codes, for example: en
171 * @author Cindy Qi Li
173 function getAllExceptLangCode($langCode)
175 if (trim($langCode) == '')
176 return $this->getAll();
179 $sql = "SELECT * FROM ".TABLE_PREFIX."languages
180 WHERE language_code <> '".$langCode."'
181 ORDER BY native_name";
182 return $this->execute($sql);
187 * Return all languages except the ones with language code in the given string
189 * @param $langCode : one language codes, for example: en
191 * @author Cindy Qi Li
193 function ValidateFields($langCode, $charset, $nativeName, $englishName)
197 $missing_fields = array();
199 if ($langCode == '') {
200 $missing_fields[] = _AT('lang_code');
202 if ($charset == '') {
203 $missing_fields[] = _AT('charset');
205 if ($nativeName == '') {
206 $missing_fields[] = _AT('name_in_language');
208 if ($englishName == '') {
209 $missing_fields[] = _AT('name_in_english');
212 if ($missing_fields) {
213 $missing_fields = implode(', ', $missing_fields);
214 $msg->addError(array('EMPTY_FIELDS', $missing_fields));