0) { foreach ($content as $value_content) { $path_file = $dir.'/'.$value_content; unlink($path_file); } return @rmdir($dir); } else { return @rmdir($dir); } } /** * check if language exist by id. * * @param int $language_id * * @return bool */ public static function check_if_exist_language_by_id($language_id) { $table = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql = 'SELECT count(*) as count FROM '.$table.' WHERE id="'.intval($language_id).'"'; $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { if (Database::result($rs, 0, 'count') == 1) { return true; } else { return false; } } else { return false; } } /** * Get name of language by id. * * @param int $language_id The language id * * @return string The original name of language */ public static function get_name_of_language_by_id($language_id) { $table = Database::get_main_table(TABLE_MAIN_LANGUAGE); $language_id = intval($language_id); $sql = "SELECT original_name FROM $table WHERE id = $language_id"; $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { return Database::result($rs, 0, 'original_name'); } else { return ''; } } /** * Verified if language is sub-language. * * @param int $language_id * * @return bool */ public static function check_if_language_is_sub_language($language_id) { $table = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql = 'SELECT count(*) AS count FROM '.$table.' WHERE id = '.intval($language_id).' AND NOT ISNULL(parent_id)'; $rs = Database::query($sql); if (Database::num_rows($rs) > 0 && Database::result($rs, '0', 'count') == 1) { return true; } else { return false; } } /** * @param int $language_id * * @return bool */ public static function check_if_language_is_used($language_id) { $language_info = self::get_all_information_of_language($language_id); $table = Database::get_main_table(TABLE_MAIN_USER); $sql = 'SELECT count(*) AS count FROM '.$table.' WHERE language ="'.Database::escape_string($language_info['english_name']).'"'; $rs = Database::query($sql); if (Database::num_rows($rs) > 0 && Database::result($rs, '0', 'count') >= 1) { return true; } else { return false; } } /** * Verified if language is father of an sub-language. * * @param int $language_id The language id * * @return bool */ public static function check_if_language_is_father($language_id) { $table = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql = 'SELECT count(*) AS count FROM '.$table.' WHERE parent_id= '.intval($language_id).' AND NOT ISNULL(parent_id);'; $rs = Database::query($sql); if (Database::num_rows($rs) > 0 && Database::result($rs, '0', 'count') == 1) { return true; } else { return false; } } /** * Make unavailable the language. * * @param int $language_id The language id * * @return bool */ public static function make_unavailable_language($language_id) { $tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id = ".intval($language_id).""; $result = Database::query($sql); return $result !== false; //only return false on sql error } /** * Make available the language. * * @param int $language_id language id * * @return bool */ public static function make_available_language($language_id) { $tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id = ".intval($language_id).""; $result = Database::query($sql); return $result !== false; //only return false on sql error } /** * Set platform language. * * @param int $language_id The language id * * @return bool */ public static function set_platform_language($language_id) { if (empty($language_id) || (intval($language_id) != $language_id)) { return false; } $language_id = intval($language_id); $tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE); $tbl_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $sql = "SELECT * FROM $tbl_admin_languages WHERE id = $language_id"; $result = Database::query($sql); $lang = Database::fetch_array($result); $sql_update_2 = "UPDATE $tbl_settings_current SET selected_value = '".$lang['isocode']."' WHERE variable = 'platform_language'"; $result_2 = Database::query($sql_update_2); Event::addEvent( LOG_PLATFORM_LANGUAGE_CHANGE, LOG_PLATFORM_LANGUAGE, $lang['english_name'] ); return $result_2 !== false; } /** * Get platform language ID. * * @return int The platform language ID */ public static function get_platform_language_id() { $name = api_get_setting('platformLanguage'); $tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql = "SELECT id FROM $tbl_admin_languages WHERE english_name ='$name'"; $res = Database::query($sql); if (Database::num_rows($res) < 1) { return false; } $row = Database::fetch_array($res); return (int) $row['id']; } /** * Get parent language path (or null if no parent). * * @param string $language_path Children language path * * @return string Parent language path or null */ public static function get_parent_language_path($language_path) { $tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql = "SELECT dokeos_folder FROM ".$tbl_admin_languages." WHERE id = ( SELECT parent_id FROM ".$tbl_admin_languages." WHERE dokeos_folder = '".Database::escape_string($language_path)."' ) "; $result = Database::query($sql); if (Database::num_rows($result) == 0) { return null; } $row = Database::fetch_array($result); return $row['dokeos_folder']; } /** * Get language matching isocode. * * @param string $isocode The language isocode (en, es, fr, zh-TW, etc) * * @return mixed English name of the matching language, or false if no active language could be found */ public static function getLanguageFromIsocode($isocode) { $isocode = Database::escape_string($isocode); $adminLanguagesTable = Database::get_main_table(TABLE_MAIN_LANGUAGE); // select language - if case several languages match, get the last (more recent) one $sql = "SELECT english_name FROM ".$adminLanguagesTable." WHERE isocode ='$isocode' AND available = 1 ORDER BY id DESC LIMIT 1"; $res = Database::query($sql); if (Database::num_rows($res) < 1) { return false; } $row = Database::fetch_assoc($res); return $row['english_name']; } /** * Get best language in browser preferences. * * @param string $preferences The browser-configured language preferences (e.g. "en,es;q=0.7;en-us;q=0.3", etc) * * @return mixed English name of the matching language, or false if no active language could be found */ public static function getLanguageFromBrowserPreference($preferences) { if (empty($preferences)) { return false; } $preferencesArray = explode(',', $preferences); if (count($preferencesArray) > 0) { foreach ($preferencesArray as $pref) { $s = strpos($pref, ';'); if ($s >= 2) { $code = substr($pref, 0, $s); } else { $code = $pref; } $name = self::getLanguageFromIsocode($code); if ($name !== false) { return $name; } } } return false; } }