Files
selima-perl/lib/php/monica/country.inc.php
2026-03-10 21:31:43 +08:00

79 lines
2.2 KiB
PHP

<?php
// File name: country.inc.php
// Description: PHP subroutine to obtain a country name
// Date: 2002-11-08
// Author: imacat <imacat@pristine.com.tw>
// Copyright: Copyright (C) 2002-2007 Pristine Communications
// Set the include path
if (!defined("INCPATH_SET")) {
require_once dirname(__FILE__) . "/incpath.inc.php";
}
// Referenced subroutines
require_once "monica/commtext.inc.php";
require_once "monica/echoform.inc.php";
require_once "monica/getlang.inc.php";
require_once "monica/lninfo.inc.php";
require_once "monica/sql.inc.php";
// ctname: Obtain a country name
function ctname($id)
{
// Cache the result
static $cache = array();
// Bounce if there is any problem with $id
if (is_null($id)) {
return t_notset();
}
// Return the cache
if (array_key_exists($id, $cache)) {
return $cache[$id];
}
// Query
// Default language
if (getlang() == DEFAULT_LANG) {
$col = "name_" . getlang(LN_DATABASE) . " AS name";
// Fall back to the default language
} else {
$thiscol = "name_" . getlang(LN_DATABASE);
$defcol = "name_" . ln(DEFAULT_LANG, LN_DATABASE);
$col = "COALESCE($thiscol, $defcol) AS name";
}
$select = "SELECT $col FROM country"
. " WHERE id='" . sql_esctext($id) . "';\n";
$result = sql_query($select);
// Not found
if (sql_num_rows($result) != 1) {
$cache[$id] = t_na();
return $cache[$id];
}
// Found
$row = sql_fetch_assoc($result);
$cache[$id] = $row["name"];
return $cache[$id];
}
// country_options: Obtain a country options list
function country_options($value)
{
// Default language
if (getlang() == DEFAULT_LANG) {
$content = "name_" . getlang(LN_DATABASE) . " AS content";
// Fall back to the default language
} else {
$col = "name_" . getlang(LN_DATABASE);
$defcol = "name_" . ln(DEFAULT_LANG, LN_DATABASE);
$content = "COALESCE($col, $defcol) AS content";
}
$select = "SELECT id AS value, $content FROM country"
. " WHERE " . sql_is_false("special")
. " ORDER BY content;\n";
return opt_list($select, $value);
}
?>