// 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/chkfunc.inc.php"; require_once "monica/commtext.inc.php"; require_once "monica/getlang.inc.php"; require_once "monica/htmlchar.inc.php"; require_once "monica/lninfo.inc.php"; require_once "monica/sql.inc.php"; require_once "monica/usrconst.inc.php"; // username: Obtain a user name function username($sn) { // Cache the result static $cache = array(); // Bounce if there is any problem with $sn if (is_null($sn)) { return t_notset(); } // Return the cache if (array_key_exists($sn, $cache)) { return $cache[$sn]; } // Check the serial number first if (!check_sn($sn)) { $cache[$sn] = t_na(); return $cache[$sn]; } // Query $select = "SELECT name FROM users WHERE sn=$sn;\n"; $result = sql_query($select); // Not found if (sql_num_rows($result) != 1) { $cache[$sn] = t_na(); return $cache[$sn]; } // Found $row = sql_fetch_assoc($result); $cache[$sn] = $row["name"]; return $cache[$sn]; } // userid: Obtain a user ID function userid($sn) { // Cache the result static $cache = array(); // Bounce if there is any problem with $sn if (is_null($sn)) { return t_notset(); } // Return the cache if (array_key_exists($sn, $cache)) { return $cache[$sn]; } // Check the serial number first if (!check_sn($sn)) { $cache[$sn] = t_na(); return $cache[$sn]; } // Query $select = "SELECT id FROM users WHERE sn=$sn;\n"; $result = sql_query($select); // Not found if (sql_num_rows($result) != 1) { $cache[$sn] = t_na(); return $cache[$sn]; } // Found $row = sql_fetch_assoc($result); $cache[$sn] = $row["id"]; return $cache[$sn]; } // usersn: Obtain a user S/N // Return null if not available function usersn($id) { // Cache the result static $cache = array(); // Bounce if there is any problem with $id if (is_null($id)) { return null; } // Return the cache if (array_key_exists($id, $cache)) { return $cache[$id]; } // Query $select = "SELECT sn FROM users" . " WHERE id='" . sql_esctext($id) . "';\n"; $result = sql_query($select); // Not found if (sql_num_rows($result) != 1) { $cache[$id] = null; return $cache[$id]; } // Found $row = sql_fetch_assoc($result); $cache[$id] = $row["sn"]; return $cache[$id]; } // groupid: Obtain a group ID function groupid($sn) { // Cache the result static $cache = array(); // Bounce if there is any problem with $sn if (is_null($sn)) { return t_notset(); } // Return the cache if (array_key_exists($sn, $cache)) { return $cache[$sn]; } // Check the serial number first if (!check_sn($sn)) { $cache[$sn] = t_na(); return $cache[$sn]; } // Query $select = "SELECT id FROM groups WHERE sn=$sn;\n"; $result = sql_query($select); // Not found if (sql_num_rows($result) != 1) { $cache[$sn] = t_na(); return $cache[$sn]; } // Found $row = sql_fetch_assoc($result); $cache[$sn] = $row["id"]; return $cache[$sn]; } // groupdsc: Obtain a group description function groupdsc($sn) { // Cache the result static $cache = array(); // Bounce if there is any problem with $sn if (is_null($sn)) { return t_notset(); } // Return the cache if (array_key_exists($sn, $cache)) { return $cache[$sn]; } // Check the serial number first if (!check_sn($sn)) { $cache[$sn] = t_na(); return $cache[$sn]; } // Query // Unilingual if (count($GLOBALS["ALL_LINGUAS"]) == 1) { $col = "dsc AS dsc"; // Multilingual } else { // Default language if (getlang() == DEFAULT_LANG) { $col = "dsc_" . getlang(LN_DATABASE) . " AS dsc"; // Fall back to the default language } else { $thiscol = "dsc_" . getlang(LN_DATABASE); $defcol = "dsc_" . ln(DEFAULT_LANG, LN_DATABASE); $col = "COALESCE($thiscol, $defcol) AS dsc"; } } $select = "SELECT $col FROM groups WHERE sn=$sn;\n"; $result = sql_query($select); // Not found if (sql_num_rows($result) != 1) { $cache[$sn] = t_na(); return $cache[$sn]; } // Found $row = sql_fetch_assoc($result); $cache[$sn] = $row["dsc"]; return $cache[$sn]; } // groupsn: Obtain a group S/N // Return null if not available function groupsn($id) { // Cache the result static $cache = array(); // Bounce if there is any problem with $id if (is_null($id)) { return null; } // Return the cache if (array_key_exists($id, $cache)) { return $cache[$id]; } // Query $select = "SELECT sn FROM groups" . " WHERE id='" . sql_esctext($id) . "';\n"; $result = sql_query($select); // Not found if (sql_num_rows($result) != 1) { $cache[$id] = null; return $cache[$id]; } // Found $row = sql_fetch_assoc($result); $cache[$id] = $row["sn"]; return $cache[$id]; } // user_opt_label: Obtain a user option label // Return null when not found function user_opt_label($sn, $for = null) { // Check the validity of the serial number first if (!check_sn($sn)) { return null; } $select = "SELECT id, name FROM users" . " WHERE sn=$sn;\n"; $result = sql_query($select); if (sql_num_rows($result) != 1) { return null; } $row = sql_fetch_assoc($result); if (!is_null($for)) { return sprintf("", h($for), h($row["id"]), h($row["name"])); } else { return sprintf("%s (%s)", h($row["id"]), h($row["name"])); } } // group_opt_label: Obtain a group option label function group_opt_label($sn, $for = null) { // Check the validity of the serial number first if (!check_sn($sn)) { return t_na(); } if (count($GLOBALS["ALL_LINGUAS"]) > 1) { $lndb = getlang(LN_DATABASE); if (getlang() == DEFAULT_LANG) { $dsc = "dsc_$lndb AS dsc"; } else { $lndbdef = ln(DEFAULT_LANG, LN_DATABASE); $dsc = "COALESCE(dsc_$lndb, dsc_$lndbdef) AS dsc"; } } else { $dsc = "dsc AS dsc"; } $select = "SELECT id, $dsc FROM groups" . " WHERE sn=$sn;\n"; $result = sql_query($select); if (sql_num_rows($result) != 1) { return t_na(); } $row = sql_fetch_assoc($result); if (!is_null($for)) { return sprintf("", h($for), h($row["id"]), h($row["dsc"])); } else { return sprintf("%s (%s)", h($row["id"]), h($row["dsc"])); } } // su_group_id: Return the ID. of the super user group function su_group_id() { return SU_GROUP; } // su_group_sn: Return the S/N of the super user group function su_group_sn() { // Cache the result static $cache; // Return the cache if (isset($cache)) { return $cache; } // Query $select = "SELECT * FROM groups" . " WHERE id='" . sql_esctext(SU_GROUP) . "';\n"; $result = sql_query($select); // Found if (sql_num_rows($result) == 1) { $row = sql_fetch_assoc($result); $cache = $row["sn"]; // Not found } else { $cache = null; } return $cache; } ?>