Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/main/classes/general/ |
Upload File : |
<?php use Bitrix\Main\Localization\CultureTable; use Bitrix\Main\Localization; IncludeModuleLangFile(__FILE__); class CAllLanguage { var $LAST_ERROR; public static function GetList($by = "sort", $order = "asc", $arFilter = []) { global $DB; $arSqlSearch = []; if (is_array($arFilter)) { foreach ($arFilter as $key => $val) { if ((string)$val <> '') { switch (strtoupper($key)) { case "ACTIVE": if ($val == "Y" || $val == "N") { $arSqlSearch[] = "L.ACTIVE='" . $DB->ForSql($val) . "'"; } break; case "NAME": $arSqlSearch[] = "UPPER(L.NAME) LIKE UPPER('" . $DB->ForSql($val) . "')"; break; case "ID": case "LID": $arSqlSearch[] = "L.LID='" . $DB->ForSql($val) . "'"; break; case "CODE": $arSqlSearch[] = "L.CODE='" . $DB->ForSql($val) . "'"; break; } } } } $strSqlSearch = ""; foreach ($arSqlSearch as $condition) { $strSqlSearch .= " AND (" . $condition . ") "; } $strSql = "SELECT L.*, L.LID as ID, L.LID as LANGUAGE_ID, " . " C.FORMAT_DATE, C.FORMAT_DATETIME, C.FORMAT_NAME, C.WEEK_START, C.CHARSET, C.DIRECTION " . "FROM b_language L, b_culture C " . "WHERE C.ID = L.CULTURE_ID " . $strSqlSearch; if ($by == "lid" || $by == "id") { $strSqlOrder = " ORDER BY L.LID "; } elseif ($by == "active") { $strSqlOrder = " ORDER BY L.ACTIVE "; } elseif ($by == "name") { $strSqlOrder = " ORDER BY L.NAME "; } elseif ($by == "code") { $strSqlOrder = " ORDER BY L.CODE "; } elseif ($by == "def") { $strSqlOrder = " ORDER BY L.DEF "; } else { $strSqlOrder = " ORDER BY L.SORT "; } if ($order == "desc") { $strSqlOrder .= " desc "; } $strSql .= $strSqlOrder; $res = $DB->Query($strSql); return $res; } public static function GetByID($ID) { return CLanguage::GetList('', '', ["LID" => $ID]); } public function CheckFields($arFields, $ID = false) { global $APPLICATION, $DB; $this->LAST_ERROR = ""; $arMsg = []; if (($ID === false || isset($arFields["LID"])) && mb_strlen($arFields["LID"]) <> 2) { $this->LAST_ERROR .= GetMessage("BAD_LANG_LID") . " "; $arMsg[] = ["id" => "LID", "text" => GetMessage("BAD_LANG_LID")]; } if ($ID === false && !isset($arFields["CULTURE_ID"])) { $this->LAST_ERROR .= GetMessage("lang_check_culture_not_set") . " "; $arMsg[] = ["id" => "CULTURE_ID", "text" => GetMessage("lang_check_culture_not_set")]; } if (isset($arFields["CULTURE_ID"])) { if (CultureTable::getRowById($arFields["CULTURE_ID"]) === null) { $this->LAST_ERROR .= GetMessage("lang_check_culture_incorrect") . " "; $arMsg[] = ["id" => "CULTURE_ID", "text" => GetMessage("lang_check_culture_incorrect")]; } } if (isset($arFields["NAME"]) && mb_strlen($arFields["NAME"]) < 2) { $this->LAST_ERROR .= GetMessage("BAD_LANG_NAME") . " "; $arMsg[] = ["id" => "NAME", "text" => GetMessage("BAD_LANG_NAME")]; } if (isset($arFields["SORT"]) && intval($arFields["SORT"]) <= 0) { $this->LAST_ERROR .= GetMessage("BAD_LANG_SORT") . " "; $arMsg[] = ["id" => "SORT", "text" => GetMessage("BAD_LANG_SORT")]; } if (!empty($arMsg)) { $e = new CAdminException($arMsg); $APPLICATION->ThrowException($e); } if ($this->LAST_ERROR <> "") { return false; } if ($ID === false) { $r = $DB->Query("SELECT 'x' FROM b_language WHERE LID='" . $DB->ForSQL($arFields["LID"], 2) . "'"); if ($r->Fetch()) { $this->LAST_ERROR .= GetMessage("BAD_LANG_DUP") . " "; $e = new CAdminException([["id" => "LID", "text" => GetMessage("BAD_LANG_DUP")]]); $APPLICATION->ThrowException($e); return false; } } return true; } public function Add($arFields) { global $DB; if (!$this->CheckFields($arFields)) { return false; } if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") { $arFields["ACTIVE"] = "N"; } $arInsert = $DB->PrepareInsert("b_language", $arFields); if (is_set($arFields, "DEF")) { if ($arFields["DEF"] == "Y") { $DB->Query("UPDATE b_language SET DEF='N' WHERE DEF='Y'"); } else { $arFields["DEF"] = "N"; } } $strSql = "INSERT INTO b_language(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")"; $DB->Query($strSql); Localization\LanguageTable::cleanCache(); foreach (GetModuleEvents('main', 'OnAfterLanguageAdd', true) as $arEvent) { ExecuteModuleEventEx($arEvent, [$arFields]); } return $arFields["LID"]; } public function Update($ID, $arFields) { global $DB; unset(CSite::$MAIN_LANGS_CACHE[$ID]); unset(CSite::$MAIN_LANGS_ADMIN_CACHE[$ID]); if (!$this->CheckFields($arFields, $ID)) { return false; } if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") { $arFields["ACTIVE"] = "N"; } if (is_set($arFields, "DEF")) { if ($arFields["DEF"] == "Y") { $DB->Query("UPDATE b_language SET DEF='N' WHERE DEF='Y'"); } else { $arFields["DEF"] = "N"; } } $strUpdate = $DB->PrepareUpdate("b_language", $arFields); $strSql = "UPDATE b_language SET " . $strUpdate . " WHERE LID='" . $DB->ForSql($ID, 2) . "'"; $DB->Query($strSql); Localization\LanguageTable::cleanCache(); return true; } public static function Delete($ID) { global $APPLICATION, $DB; $db_res = CLang::GetList('', '', ["LANGUAGE_ID" => $ID]); if ($db_res->Fetch()) { return false; } foreach (GetModuleEvents("main", "OnBeforeLanguageDelete", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, [$ID]) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR1") . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); return false; } } foreach (GetModuleEvents("main", "OnLanguageDelete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, [$ID]); } CFavorites::OnLanguageDelete($ID); $res = $DB->Query("DELETE FROM b_language WHERE LID='" . $DB->ForSQL($ID, 2) . "'", true); Localization\LanguageTable::cleanCache(); return $res; } public static function SelectBox($sFieldName, $sValue, $sDefaultValue = "", $sFuncName = "", $field = "class=\"typeselect\"") { $l = CLanguage::GetList(); $s = '<select name="' . $sFieldName . '" ' . $field; $s1 = ''; if ($sFuncName <> '') { $s .= ' OnChange="' . $sFuncName . '"'; } $s .= '>' . "\n"; $found = false; while (($l_arr = $l->Fetch())) { $found = ($l_arr["LID"] == $sValue); $s1 .= '<option value="' . $l_arr["LID"] . '"' . ($found ? ' selected' : '') . '>[' . htmlspecialcharsex($l_arr["LID"]) . '] ' . htmlspecialcharsex($l_arr["NAME"]) . '</option>' . "\n"; } if ($sDefaultValue <> '') { $s .= "<option value='' " . ($found ? "" : "selected") . ">" . htmlspecialcharsex($sDefaultValue) . "</option>"; } return $s . $s1 . '</select>'; } public static function GetLangSwitcherArray() { global $APPLICATION; $result = []; $db_res = Localization\LanguageTable::getList([ 'filter' => ['=ACTIVE' => 'Y'], 'order' => ['SORT' => 'ASC'], 'cache' => ['ttl' => 86400], ]); while ($ar = $db_res->fetch()) { $ar["NAME"] = htmlspecialcharsbx($ar["NAME"]); $ar["SELECTED"] = ($ar["LID"] == LANG); $p = rtrim(str_replace("&#", "#", preg_replace("/lang=[^&#]*&*/", "", $_SERVER["QUERY_STRING"])), "&"); $ar["PATH"] = $APPLICATION->GetCurPage() . "?lang=" . $ar["LID"] . ($p <> '' ? '&' . htmlspecialcharsbx($p) : ''); $result[] = $ar; } return $result; } } class CLanguage extends CAllLanguage { } class CLangAdmin extends CLanguage { }