Пример #1
0
 function install($aParams)
 {
     $bInclude = @(include $this->sFilePath);
     if (!$bInclude || empty($LANG) || empty($LANG_INFO) || !$this->_addLanguage($LANG, $LANG_INFO)) {
         return array('operation_title' => _t('_adm_txt_modules_operation_install', $this->_aConfig['title']), 'message' => 'Language file parse error or such language already exists: ' . $this->sFileName, 'result' => false);
     }
     $iLangId = getLangIdByName($LANG_INFO['Name']);
     $this->_recompileLanguageForAllModules($iLangId);
     compileLanguage($iLangId);
     return parent::install($aParams);
 }
 function assureCompiled($language)
 {
     if (file_exists(langFile($language))) {
         return true;
     } else {
         $language = get_magic_quotes_gpc() ? $language : addslashes($language);
         $langID = mysql_query("SELECT `ID` FROM `LocalizationLanguages` WHERE `Name` = '{$language}'");
         if (mysql_num_rows($langID) <= 0) {
             return false;
         }
         $langID = mysql_fetch_row($langID);
         $langID = $langID[0];
         return compileLanguage($langID);
     }
 }
Пример #3
0
 function actionUpdateLanguages($bInstall = true)
 {
     global $MySQL;
     $aLanguages = $MySQL->getAll("SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title` FROM `sys_localization_languages`");
     //--- Process languages' key=>value pears ---//
     $sModuleConfig = $this->_sHomePath . 'install/config.php';
     if (!file_exists($sModuleConfig)) {
         return array('code' => BX_DOL_INSTALLER_FAILED, 'content' => '_adm_txt_modules_module_config_not_found');
     }
     include $sModuleConfig;
     $iCategoryId = (int) $MySQL->getOne("SELECT `ID` FROM `sys_localization_categories` WHERE `Name`='" . $aConfig['language_category'] . "' LIMIT 1");
     foreach ($aLanguages as $aLanguage) {
         $this->_updateLanguage($bInstall, $aLanguage, $iCategoryId);
     }
     //--- Recompile all language files ---//
     $aResult = array();
     foreach ($aLanguages as $aLanguage) {
         $bResult = compileLanguage($aLanguage['id']);
         if (!$bResult) {
             $aResult[] = $aLanguage['title'];
         }
     }
     return empty($aResult) ? BX_DOL_INSTALLER_SUCCESS : array('code' => BX_DOL_INSTALLER_FAILED, 'content' => $aResult);
 }
Пример #4
0
 function updateLangString($sKey, $sString)
 {
     if ($sKey == '') {
         return false;
     }
     $sKey_db = addslashes($sKey);
     $sString_db = addslashes($sString);
     $sQuery = "SELECT `ID` FROM `sys_localization_keys` WHERE `Key` = '{$sKey_db}'";
     $iKeyID = (int) db_value($sQuery);
     if (!$iKeyID) {
         //create key
         $sQuery = "INSERT INTO `sys_localization_keys` (`IDCategory`,`Key`) VALUES (32,'{$sKey_db}')";
         db_res($sQuery);
         $iKeyID = db_last_id();
     }
     $sQuery = "\n            SELECT COUNT( * ) FROM `sys_localization_strings`\n            WHERE `IDKey` = {$iKeyID} AND `IDLanguage` = {$this->sLangID}";
     $iCount = (int) db_value($sQuery);
     if ($iCount) {
         $sQuery = "\n                UPDATE `sys_localization_strings`\n                SET `String` = '{$sString_db}'\n                WHERE `IDKey` = {$iKeyID} AND `IDLanguage` = {$this->sLangID}";
         db_res($sQuery);
     } else {
         $sQuery = "INSERT INTO `sys_localization_strings` VALUES ( {$iKeyID}, {$this->sLangID}, '{$sString_db}' )";
         db_res($sQuery);
     }
     compileLanguage($this->sLangID);
 }
function manageLanguagesBlock()
{
    global $site;
    function copyLanguage()
    {
        $newLangName = get_magic_quotes_gpc() ? $_POST['CopyLanguage_Name'] : addslashes($_POST['CopyLanguage_Name']);
        $sFlag = htmlspecialchars_adv($_POST['Flag']);
        $sourceLangID = (int) $_POST['CopyLanguage_SourceLangID'];
        if (strlen($newLangName) <= 0) {
            return '<font color="red">Error: please specify a name for the new language.</font>';
        }
        mysql_query("\r\n\t\t\tINSERT INTO `LocalizationLanguages`\r\n\t\t\t(`Name`, `Flag`) VALUES\r\n\t\t\t('{$newLangName}', '{$sFlag}')\r\n\t\t");
        if (mysql_affected_rows() <= 0) {
            return '<font color="red">Error: could not add a new language to the database.</font>';
        }
        $newLangID = mysql_insert_id();
        $resSourceLangStrings = mysql_query("\r\n\t\t\tSELECT\t`IDKey`, `String`\r\n\t\t\tFROM\t`LocalizationStrings`\r\n\t\t\tWHERE\t`IDLanguage` = {$sourceLangID}\r\n\t\t");
        while ($arr = mysql_fetch_assoc($resSourceLangStrings)) {
            $arr['String'] = addslashes($arr['String']);
            mysql_query("\r\n\t\t\t\tINSERT INTO `LocalizationStrings`\r\n\t\t\t\t(`IDKey`, `IDLanguage`, `String`) VALUES\r\n\t\t\t\t('{$arr['IDKey']}', {$newLangID}, '{$arr['String']}')\r\n\t\t\t\t");
            if (mysql_affected_rows() <= 0) {
                return '<font color="red">Error: could not add a language string to the database.</font>';
            }
        }
        return '<font color="green"><b>' . htmlspecialchars(stripslashes($newLangName)) . '</b> language has been successfully created.</font>';
    }
    function getLangName($langID)
    {
        $langName = mysql_query('SELECT `Name` FROM `LocalizationLanguages` WHERE `ID` = ' . (int) $langID);
        $langName = mysql_fetch_row($langName);
        return $langName[0];
    }
    if ($_POST['CopyLanguage']) {
        $resultMsg = copyLanguage();
    } else {
        if (isset($_POST['CompileLanguage'])) {
            $langName = getLangName($_POST['CompileLanguage']);
            if (compileLanguage((int) $_POST['CompileLanguage'])) {
                $resultMsg = '<font color="green"><b>' . htmlspecialchars($langName) . '</b> language has been successfully compiled.</font>';
            } else {
                $resultMsg = '<font color="red>Error: could not compile a language.</font>';
            }
        } else {
            if (isset($_POST['DeleteLanguage'])) {
                $langName = getLangName($_POST['DeleteLanguage']);
                if ($langName == getParam('lang_default')) {
                    $resultMsg = '<font color="red">Cannot delete the default language. You have to set another default language for the site in <b>global settings -> Change language settings</b> to be able to delete this one.</font>';
                } else {
                    if (deleteLanguage((int) $_POST['DeleteLanguage'])) {
                        $resultMsg = '<font color="green"><b>' . htmlspecialchars($langName) . '</b> language has been successfully removed.</font>';
                    } else {
                        $resultMsg = '<font color="red">Error: could not delete a language.</font>';
                    }
                }
            }
        }
    }
    ob_start();
    $arrLangs = getLocalizationLanguages();
    displayLanguageSettings();
    $contents = ob_get_contents();
    ob_end_clean();
    $sCon1 = panelSection('Language', $contents);
    ob_start();
    ?>
<form action="<?php 
    echo $_SERVER['PHP_SELF'];
    ?>
" method="post" style="margin:0px">
New language:
<input type="text" name="CopyLanguage_Name" style="width: 80px" />
Copy from:
<select name="CopyLanguage_SourceLangID" style="width: 80px">
<?php 
    foreach ($arrLangs as $langID => $langName) {
        ?>
	<option value="<?php 
        echo $langID;
        ?>
"><?php 
        echo htmlspecialchars($langName);
        ?>
</option>
<?php 
    }
    ?>
</select>
Flag: 
<?php 
    echo showLangIcons();
    ?>
<br />
<br />
<center>
<input type="submit" name="CopyLanguage" value="Create" />
</center>
</form>
<br />
<?php 
    if (strlen($resultMsg) > 0) {
        echo $resultMsg . '<br /><br />';
    }
    ?>
<table class="LanguagesStrings" cellpadding="0" cellspacing="0">
	<tr class="HeaderRow">
		<td width="85%" align="left">Language</td>
		<td width="15%" align="left">Flag</td>
		<td colspan="3">&nbsp;</td>
	</tr>
<?php 
    $resLangs = mysql_query('
		SELECT `ID`, `Name`, `Flag`
		FROM `LocalizationLanguages`
		ORDER BY `Name`
	');
    $defaultLangName = getParam('lang_default');
    while ($arrLang = mysql_fetch_assoc($resLangs)) {
        ?>
	<tr>
		<td class="Left"><?php 
        echo htmlspecialchars($arrLang['Name']) . ($arrLang['Name'] == $defaultLangName ? '<font color="red"> (default)</font>' : '');
        ?>
</td>
		<td><img src="<?php 
        echo $site['flags'] . $arrLang['Flag'] . '.gif';
        ?>
"></td>
		<td><a href="javascript:void(0)" onclick="popupForm('<?php 
        echo $_SERVER['PHP_SELF'];
        ?>
?view=editLanguage&editLanguageID=<?php 
        echo $arrLang['ID'];
        ?>
', 500, 300, 300, 200, 'no'); return false;">Edit</a></td>
		<td>
			<form id="CompileForm_<?php 
        echo $arrLang['ID'];
        ?>
" action="<?php 
        echo $_SERVER['PHP_SELF'];
        ?>
" method="post" style="padding: 0px; margin: 0px">
				<input type="hidden" name="CompileLanguage" value="<?php 
        echo $arrLang['ID'];
        ?>
" />
			</form>
			<a href="javascript:void(0)" onclick="document.getElementById('CompileForm_<?php 
        echo $arrLang['ID'];
        ?>
').submit(); return false;">Compile</a>
		</td>
		<td>
			<form id="DeleteForm_<?php 
        echo $arrLang['ID'];
        ?>
" action="<?php 
        echo $_SERVER['PHP_SELF'];
        ?>
" method="post" style="padding: 0px; margin: 0px">
				<input type="hidden" name="DeleteLanguage" value="<?php 
        echo $arrLang['ID'];
        ?>
" />
			</form>
			<a href="javascript:void(0)" onclick="document.getElementById('DeleteForm_<?php 
        echo $arrLang['ID'];
        ?>
').submit(); return false;"><font color="red">Delete</font></a>
		</td>
	</tr>
<?php 
    }
    ?>
</table>
<?php 
    $contents = ob_get_contents();
    ob_end_clean();
    $sCon2 = panelSection('Language Files', $contents);
    return $sCon1 . $sCon2;
}
Пример #6
0
function updateLangFile($key, $string)
{
    // clear from special chars ;
    $key = preg_replace('|\\{([^\\}]+)\\}|', '', $key);
    $langName = getParam('lang_default');
    $langID = db_value("SELECT `ID` FROM `sys_localization_languages` WHERE `Name` = '" . addslashes($langName) . "'");
    $keyID = db_value("SELECT `ID` FROM `sys_localization_keys` WHERE `Key` = '" . process_db_input($key) . "'");
    if ($keyID) {
        db_res("UPDATE `sys_localization_strings` SET `String` = '" . process_db_input($string) . "' WHERE `IDKey`={$keyID} AND `IDLanguage`={$langID}");
    } else {
        db_res("INSERT INTO `sys_localization_keys` SET `IDCategory` = 2, `Key` = '" . process_db_input($key) . "'");
        db_res("INSERT INTO `sys_localization_strings` SET `IDKey` = " . db_last_id() . ", `IDLanguage` = {$langID}, `String` = '" . process_db_input($string) . "'");
    }
    compileLanguage($langID);
}
Пример #7
0
 function actionUpdateLanguages($bInstall = true)
 {
     $aLanguages = array();
     $rLanguages = db_res("SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title` FROM `sys_localization_languages`");
     while ($aLanguage = mysql_fetch_assoc($rLanguages)) {
         $aLanguages[] = $aLanguage;
     }
     //--- Process Language Category ---//
     $iCategoryId = 100;
     $sCategoryName = isset($this->_aConfig['language_category']) ? $this->_aConfig['language_category'] : '';
     if ($bInstall && !empty($sCategoryName)) {
         db_res("INSERT IGNORE INTO `sys_localization_categories` SET `Name`='" . $sCategoryName . "'");
         if (db_affected_rows() <= 0) {
             $iCategoryId = (int) db_value("SELECT `ID` FROM `sys_localization_categories` WHERE `Name`='" . $sCategoryName . "' LIMIT 1");
         } else {
             $iCategoryId = db_last_id();
         }
     } else {
         if (!$bInstall && !empty($sCategoryName)) {
             db_res("DELETE FROM `sys_localization_categories` WHERE `Name`='" . $sCategoryName . "'");
         }
     }
     //--- Process languages' key=>value pears ---//
     foreach ($aLanguages as $aLanguage) {
         $this->_updateLanguage($bInstall, $aLanguage, $iCategoryId);
     }
     //--- Recompile all language files ---//
     $aResult = array();
     foreach ($aLanguages as $aLanguage) {
         $bResult = compileLanguage($aLanguage['id']);
         if (!$bResult) {
             $aResult[] = $aLanguage['title'];
         }
     }
     return empty($aResult) ? BX_DOL_INSTALLER_SUCCESS : array('code' => BX_DOL_INSTALLER_FAILED, 'content' => $aResult);
 }
function updateLangFile($key, $string)
{
    global $sTableName;
    $langName = getParam('lang_default');
    $langID = db_value("SELECT `ID` FROM `LocalizationLanguages` WHERE `Name` = '" . addslashes($langName) . "'");
    $keyID = db_value("SELECT `ID` FROM `LocalizationKeys` WHERE `Key` = '" . process_db_input($key) . "'");
    if ($keyID) {
        db_res("UPDATE `LocalizationStrings` SET `String` = '" . process_db_input($string) . "' WHERE `IDKey`={$keyID} AND `IDLanguage`={$langID}");
    } else {
        db_res("INSERT INTO `LocalizationKeys` SET `IDCategory` = 2, `Key` = '" . process_db_input($key) . "'");
        db_res("INSERT INTO `LocalizationStrings` SET `IDKey` = " . mysql_insert_id() . ", `IDLanguage` = {$langID}, `String` = '" . process_db_input($string) . "'");
    }
    compileLanguage($langID);
}
Пример #9
0
function performInstallLanguages()
{
    db_res("TRUNCATE TABLE `sys_localization_languages`");
    db_res("TRUNCATE TABLE `sys_localization_keys`");
    db_res("TRUNCATE TABLE `sys_localization_strings`");
    if (!($sLangsDir = opendir(BX_DIRECTORY_PATH_ROOT . 'install/langs/'))) {
        return;
    }
    while (false !== ($sFilename = readdir($sLangsDir))) {
        if (substr($sFilename, -3) == 'php') {
            unset($LANG);
            unset($LANG_INFO);
            require_once BX_DIRECTORY_PATH_ROOT . 'install/langs/' . $sFilename;
            walkThroughLanguage($LANG, $LANG_INFO);
        }
    }
    closedir($sLangsDir);
    compileLanguage();
}
Пример #10
0
function updateLangFile($key, $string)
{
    $langName = getParam('lang_default');
    $langID = db_value("SELECT `ID` FROM `sys_localization_languages` WHERE `Name` = '" . addslashes($langName) . "'");
    $keyID = db_value("SELECT `ID` FROM `sys_localization_keys` WHERE `Key` = '" . process_db_input($key) . "'");
    if ($keyID) {
        db_res("UPDATE `sys_localization_strings` SET `String` = '" . process_db_input($string) . "' WHERE `IDKey`='{$keyID}' AND `IDLanguage`='{$langID}'");
    } else {
        db_res("INSERT INTO `sys_localization_keys` SET `IDCategory` = 2, `Key` = '" . process_db_input($key) . "'");
        db_res("INSERT INTO `sys_localization_strings` SET `IDKey` = " . db_last_id() . ", `IDLanguage` = '{$langID}', `String` = '" . process_db_input($string) . "'");
    }
    compileLanguage($langID);
}
Пример #11
0
function importLanguage(&$aData, &$aFiles)
{
    global $MySQL;
    $sTmpPath = $GLOBALS['dir']['tmp'] . mktime() . ".php";
    if (!file_exists($aFiles['ImportLanguage_File']['tmp_name']) || !move_uploaded_file($aFiles['ImportLanguage_File']['tmp_name'], $sTmpPath)) {
        return '_adm_txt_langs_cannot_upload_file';
    }
    require_once $sTmpPath;
    $aLangInfo = isset($aLangInfo) ? $aLangInfo : $LANG_INFO;
    $aLangContent = isset($aLangContent) ? $aLangContent : $LANG;
    if (empty($aLangInfo) || empty($aLangContent)) {
        return '_adm_txt_langs_cannot_create';
    }
    if (_checkLangUnique($aLangInfo['Name']) === true) {
        return '_adm_txt_langs_cannot_create';
    }
    $mixedResult = $MySQL->query("INSERT INTO `sys_localization_languages` (`Name`, `Flag`, `Title`, `Direction`, `LanguageCountry`) \n                                  VALUES (?, ?, ?, ?, ?)", [$aLangInfo['Name'], $aLangInfo['Flag'], $aLangInfo['Title'], $aLangInfo['Direction'], $aLangInfo['LanguageCountry']]);
    if ($mixedResult === false) {
        @unlink($sTmpPath);
        return '_adm_txt_langs_cannot_create';
    }
    $iId = (int) $MySQL->lastId();
    $MySQL->cleanCache('sys_localization_languages');
    $aKeys = $MySQL->getAllWithKey("SELECT `ID` AS `id`, `Key` AS `key` FROM `sys_localization_keys`", "key");
    foreach ($aLangContent as $sKey => $sString) {
        if (!isset($aKeys[$sKey])) {
            continue;
        }
        $MySQL->query("INSERT INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES ('" . $aKeys[$sKey]['id'] . "', " . $iId . ", '" . addslashes($sString) . "')");
    }
    compileLanguage($iId);
    @unlink($sTmpPath);
    return '_adm_txt_langs_success_import';
}
Пример #12
0
function addStringToLanguage($langKey, $langString, $langID = -1, $categoryID = BX_DOL_LANGUAGE_CATEGORY_SYSTEM)
{
    // input validation
    $langID = (int) $langID;
    $categoryID = (int) $categoryID;
    if ($langID == -1) {
        $resLangs = db_res('SELECT `ID`, `Name` FROM `sys_localization_languages`');
    } else {
        $resLangs = db_res('
            SELECT	`ID`, `Name`
            FROM	`sys_localization_languages`
            WHERE	`ID` = ' . $langID);
    }
    $langKey = process_db_input($langKey, BX_TAGS_STRIP);
    $langString = process_db_input($langString, BX_TAGS_VALIDATE);
    $resInsertKey = db_res("\n        INSERT INTO\t`sys_localization_keys`\n        SET\t\t\t`IDCategory` = {$categoryID},\n                    `Key` = '{$langKey}'", false);
    if (!$resInsertKey || db_affected_rows() <= 0) {
        return false;
    }
    $keyID = db_last_id();
    while ($arrLanguage = mysql_fetch_assoc($resLangs)) {
        $resInsertString = db_res("\n            INSERT INTO\t`sys_localization_strings`\n            SET\t\t\t`IDKey` = {$keyID},\n                        `IDLanguage` = {$arrLanguage['ID']},\n                        `String` = '{$langString}'", false);
        if (!$resInsertString || db_affected_rows() <= 0) {
            return false;
        }
        compileLanguage($arrLanguage['ID']);
    }
    return true;
}
/**
 * Perform edit ar add field database actions
 * @param
 */
function edit_or_add_field()
{
    // Get field type.
    $field_type = $_POST['field_type'];
    // Select old field values
    if ('add' != $_GET['action']) {
        $q_str = "SELECT * FROM `ProfilesDesc` WHERE `ID` = {$_GET['ID']}";
        $field = db_arr($q_str);
    }
    // Get new field order.
    if ('add' == $_GET['action']) {
        $order = get_field_order($_POST['insert_after']);
    }
    // Get field name.
    $name = process_pass_data($_POST['field_name']);
    $name = str_replace(' ', '_', $name);
    $name = str_replace("'", '_', $name);
    // Get caption and determ if it was changed
    if ('add' == $_GET['action']) {
        $namedisp = '_' . $name . '_caption';
        $namedisp_changed = true;
    } else {
        if ($_POST['caption'] == _t($field['namedisp'])) {
            $namedisp = $field['namedisp'];
            $namedisp_changed = false;
        } else {
            $namedisp = '_' . $name . '_caption';
            $namedisp_changed = true;
        }
    }
    // Get field description.
    if ('add' == $_GET['action']) {
        $namenote = $_POST['desc'] ? '_' . $name . '_desc' : '';
        $namenote_changed = true;
    } else {
        if ($_POST['desc'] == _t($field['namenote'])) {
            $namenote = $field['namedisp'];
            $namenote_changed = false;
        } else {
            $namenote = $_POST['desc'] ? '_' . $name . '_desc' : '';
            $namenote_changed = true;
        }
    }
    // Get user visibility.
    $visible = '';
    if ('on' == $_POST['visible_to_visitor']) {
        $visible .= 'user';
    }
    if ('on' == $_POST['visible_to_member']) {
        $visible = cat_string($visible, 'memb');
    }
    if ('on' == $_POST['visible_to_admin']) {
        $visible = cat_string($visible, 'adm');
    }
    // Get user edit possibility.
    $editable = '';
    if ('on' == $_POST['editable_for_member']) {
        $editable .= 'memb';
    }
    if ('on' == $_POST['editable_for_admin']) {
        $editable = cat_string($editable, 'adm');
    }
    // Get page visibility.
    $show_on_page = '';
    if ('on' == $_POST['show_on_all']) {
        $show_on_page = '0';
    }
    if ('on' == $_POST['show_on_join']) {
        $show_on_page = cat_string($show_on_page, '3');
    }
    if ('on' == $_POST['show_on_view_profile']) {
        $show_on_page = cat_string($show_on_page, '7');
    }
    if ('on' == $_POST['show_on_edit_profile']) {
        $show_on_page = cat_string($show_on_page, '25');
    }
    // Generate extra field content.
    $extra = '';
    switch ($field_type) {
        case 'p':
        case 'c':
            $extra = (int) $_POST['edit_box_length'];
            break;
        case 'date':
            $extra = process_db_input($_POST['edit_box_length']);
            break;
        case 'e':
        case 'rb':
        case 'set':
            $temp = explode("\r\n", $_POST['choices']);
            $extra = '';
            foreach ($temp as $value) {
                $value = process_pass_data($value);
                $value = str_replace("'", '`', $value);
                $replace_arr = array(' ', '.', ',', "\\");
                $value = str_replace($replace_arr, '_', $value);
                $extra = cat_string($extra, "\\'{$value}\\'");
            }
            $result = db_arr("SHOW COLUMNS FROM `Profiles` LIKE '{$name}'");
            $extratmp = str_replace("\\", "", $extra);
            // Alter existing field
            if ($result['Default']) {
                $alter_field_type = $field_type == 'set' ? "SET({$extratmp})" : "ENUM({$extratmp})";
                if (strstr($extratmp, "'" . $result['Default'] . "'")) {
                    db_res("ALTER TABLE `Profiles` MODIFY `{$name}` {$alter_field_type} NOT NULL DEFAULT '{$result['Default']}'");
                } else {
                    $defval = substr($extratmp, 0, strpos($extratmp, ","));
                    db_res("ALTER TABLE `Profiles` MODIFY `{$name}` {$alter_field_type} NOT NULL DEFAULT {$defval}");
                }
            }
            break;
        case 'a':
            $extra = (int) $_POST['memo_rows'] . "x" . (int) $_POST['memo_cols'];
            break;
    }
    // Generate check script.
    if ('Email' != $name && 'Email,Email1' != $name && 'NickName' != $name && 'Password,Password1' != $name) {
        if ($_POST['min_value'] && $_POST['max_value']) {
            $check = 'return (strlen($arg0) >= ' . $_POST['min_value'] . ' && strlen($arg0) <= ' . $_POST['max_value'] . ' ) ? true : false;';
        } else {
            if ($_POST['min_value']) {
                $check = 'return (strlen($arg0) >= ' . $_POST['min_value'] . ') ? true : false;';
            } else {
                if ($_POST['max_value']) {
                    $check = 'return (strlen($arg0) <= ' . $_POST['max_value'] . ') ? true : false;';
                } else {
                    if ('on' == $_POST['mandatory']) {
                        $check = 'return strlen($arg0) > 0 ? true : false;';
                    }
                }
            }
        }
    } else {
        $length_check = $_POST['min_value'] ? 'strlen($arg0) >= ' . $_POST['min_value'] . ' && ' : "";
        $length_check .= $_POST['max_value'] ? ' strlen($arg0) <= ' . $_POST['max_value'] . ' && ' : "";
        if ('Email' == $name) {
            $check = 'return (' . $length_check . 'strstr($arg0,"@") && strstr($arg0,".")  && conf_email($arg0,$_COOKIE[memberID]))  ? true : false;';
        } else {
            if ('NickName' == $name) {
                $check = 'return (' . $length_check . 'conf_nick($arg0,$_COOKIE[memberID]) && preg_match("/^[0-9A-Za-z]+$/",$arg0)) ? true : false;';
            } else {
                if ('Password,Password1' == $name) {
                    $check = 'return (' . $length_check . '!strcmp($arg0,$_POST[Password2])) ? true : false;';
                } else {
                    if ('Email,Email1' == $name) {
                        $check = 'return (eregi("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,4}$", $arg0) && !strcmp($arg0,$_POST[Email2]) && conf_email($arg0,$_COOKIE[memberID])) ? true : false;';
                    } else {
                        $check = '';
                    }
                }
            }
        }
    }
    // Generate error message.
    if ('add' == $_GET['action']) {
        $err_msg = '_' . $name . '_err_msg';
        $err_msg_changed = true;
    } else {
        if ($_POST['err_msg'] == _t($field['because'])) {
            $err_msg = $field['because'];
            $err_msg_changed = false;
        } else {
            $err_msg = '_' . $name . '_err_msg';
            $err_msg_changed = true;
        }
    }
    // Generate search type.
    $search_type = $_POST['search_t'] ? $_POST['search_t'] : 'none';
    // Generate 'search_hide' value.
    $search_hide = 0;
    if ('on' == $_POST['search_hidden']) {
        $search_hide = 1;
    }
    // Generate 'search_cols' value.
    $search_cols = $_POST['search_cols'] ? (int) $_POST['search_cols'] : 0;
    // Generate 'search_order' value.
    $q_str = 'SELECT `search_order` FROM `ProfilesDesc` ORDER BY `search_order` DESC LIMIT 1';
    $row = db_arr($q_str);
    $search_order = $row['search_order'] + 1;
    // Generate match type
    $match_type = $_POST['match_t'] ? $_POST['match_t'] : 'none';
    // Generate match field
    $match_field = $_POST['match_f'] && $_POST['match_f'] != 'none' ? $_POST['match_f'] : '';
    // Generate match extra
    $match_extra = $_POST['match_perc'] ? $_POST['match_perc'] : '';
    $min_length = process_db_input($_POST['min_value']);
    $max_length = process_db_input($_POST['max_value']);
    if ('add' == $_GET['action']) {
        // Generate query to add record to ProfilesDesc.
        $q_str = "INSERT INTO `ProfilesDesc` (`name`, `namedisp`, `namenote`, `extra`, `type`, `order`, `visible`, `editable`, `show_on_page`, `check`, `because`, `min_length`, `max_length`, `search_type`, `search_hide`, `search_cols`, `search_order`, `match_type`, `match_field`, `match_extra`)";
        $q_str .= "VALUES ('{$name}', '{$namedisp}', '{$namenote}', '{$extra}', '{$field_type}', '{$order}', '{$visible}', '{$editable}', '{$show_on_page}', '{$check}', '{$err_msg}', '{$min_length}', '{$max_length}', '{$search_type}', '{$search_hide}', '{$search_cols}', '{$search_order}', '{$match_type}', '{$match_field}', '{$match_extra}')";
    } elseif ('edit' == $_GET['action']) {
        $namedisp_sql = $namedisp_changed ? "`namedisp` = '{$namedisp}'," : "";
        $namenote_sql = $namenote_changed ? "`namenote` = '{$namenote}'," : "";
        $err_msg_sql = $err_msg_changed ? "`because` = '{$err_msg}'," : "";
        $q_str = "UPDATE `ProfilesDesc` SET {$namedisp_sql} {$namenote_sql} `extra` = '{$extra}', `visible` = '{$visible}', `editable` = '{$editable}', `show_on_page` = '{$show_on_page}', `check` = '{$check}', {$err_msg_sql} `min_length` = '{$min_length}', `max_length` = '{$max_length}', `search_type` = '{$search_type}', `search_hide` = '{$search_hide}', `search_cols` = '{$search_cols}', `match_type` = '{$match_type}', `match_field` = '{$match_field}', `match_extra` = '{$match_extra}' WHERE ID = {$_GET['ID']}";
    }
    // Execute query.
    db_res($q_str);
    $type = '';
    // Generate field type for Profiles table.
    switch ($field_type) {
        case 'c':
            $type = 'VARCHAR(255)';
            break;
        case 'e':
        case 'rb':
            $arr = explode("\r\n", $_POST['choices']);
            $type = '';
            foreach ($arr as $value) {
                $value = process_pass_data($value);
                $value = str_replace("'", '`', $value);
                $replace_arr = array(' ', '.', ',', "\\");
                $value = str_replace($replace_arr, '_', $value);
                $type = cat_string($type, "'{$value}'");
            }
            $type = "ENUM ({$type})";
            break;
        case 'a':
            $type = 'MEDIUMTEXT';
            break;
        case 'set':
            $arr = explode("\r\n", $_POST['choices']);
            $type = '';
            foreach ($arr as $value) {
                $value = process_pass_data($value);
                $value = str_replace("'", '`', $value);
                $replace_arr = array(' ', '.', ',', "\\");
                $value = str_replace($replace_arr, '_', $value);
                $type = cat_string($type, "'{$value}'");
            }
            $type = "SET ({$type})";
            break;
    }
    if ($field_type != '0' && 'add' == $_GET['action']) {
        // Generate query to add new field to Profiles.
        $vals = split(",", $name);
        $db_name = $vals[0];
        $q_str = "ALTER TABLE `Profiles` ADD `{$db_name}` {$type} NOT NULL";
        db_res($q_str);
    }
    // Generate language file content.
    $lang_file = '';
    $langFailFields = '';
    if ($namedisp_changed) {
        $lang_file .= "'{$_POST['caption']}';<br />";
        if (!addStringToLanguage($namedisp, $_POST['caption']) && !updateStringInLanguage($namedisp, $_POST['caption'])) {
            $langFailFields .= "'{$namedisp}';<br />";
        }
    }
    if ($namenote_changed && $namenote) {
        $lang_file .= "'{$_POST['desc']}';<br />";
        if (!addStringToLanguage($namenote, $_POST['desc']) && !updateStringInLanguage($namenote, $_POST['desc'])) {
            $langFailFields .= "'{$namenote}';<br />";
        }
    }
    // Error message.
    if ($err_msg_changed) {
        $lang_file .= "'{$_POST['err_msg']}';<br />";
        if (!addStringToLanguage($err_msg, $_POST['err_msg']) && !updateStringInLanguage($err_msg, $_POST['err_msg'])) {
            $langFailFields .= "'{$err_msg}';<br />";
        }
    }
    // Drop-down box options.
    if ($_POST['choices']) {
        $arr = explode("\r\n", $_POST['choices']);
        foreach ($arr as $value) {
            $value = process_pass_data($value);
            $entered_value = $value;
            $value = str_replace("'", '`', $value);
            $replace_arr = array(' ', '.', ',', "\\");
            $value = str_replace($replace_arr, '_', $value);
            $lang_file .= "'{$entered_value}';<br />";
            if (!addStringToLanguage("_{$value}", $entered_value) && !updateStringInLanguage("_{$value}", $entered_value)) {
                $langFailFields .= "'{$entered_value}';<br />";
            }
        }
    }
    // Compile language files if needed
    if (strlen($lang_file)) {
        compileLanguage();
    }
    if ('add' == $_GET['action']) {
        echo "<p><span style=\"color:#ff6666;font-weight:bold\">New field has been added.</span></p>";
    } else {
        if ('edit' == $_GET['action']) {
            echo "<p><span style=\"color:#ff6666;font-weight:bold\">Field has been updated.</span></p>";
        }
    }
    if (strlen($lang_file)) {
        echo "Following strings were added or updated in your language files:<br />";
        echo "<pre>{$lang_file}</pre>";
        if (strlen($langFailFields)) {
            echo "Fail to insert or update following strings:<br />";
            echo "<pre>{$langFailFields}</pre>";
        }
    }
    echo "<p><a href=\"profile_fields.php\">Continue</a></p>";
}
function checkLangExists($sLang)
{
    global $dir;
    if (file_exists("{$dir['root']}langs/lang-{$sLang}.php")) {
        return true;
    }
    $sQuery = "SELECT `ID` FROM `LocalizationLanguages` WHERE `Name` = '{$sLang}'";
    $iLangID = (int) db_value($sQuery);
    if (!$iLangID) {
        return false;
    }
    if (compileLanguage($iLangID)) {
        return true;
    }
    return false;
}