0);
}
/**
* Get the real user name for an account name
* @param $strAct (string) Account name of the user to look up
* @return (string) The real name of the user. If the function fails, it returns null.
* Call getLastError() to get more information about the error.
*/
function getRealUserName($strAct) {
$hQuery = db_query("SELECT firstname, lastname FROM users WHERE act = $1;", $strAct);
if(!is_resource($hQuery)) {
// TODO throw exception
setLastError(RS_ERROR_SQL);
return null;
}
if(pg_num_rows($hQuery) == 0) {
return $strAct; // User not found in database, return account name
}
$arResult = pg_fetch_array($hQuery);
return user_join_name($arResult);
}
/**
* Determine if a specified group exists
* @param $strAct (string) Account name of the group
* @return (bool / null) If the function fails, it returns null. Call getLastError() to
* get more information about the error.
*/
function isGroup($strAct) {
$hQuery = db_query("SELECT * FROM groups WHERE act = $1;", $strAct);
if(!is_resource($hQuery)) {
// TODO throw exception
setLastError(RS_ERROR_SQL);
return null;
}
return (pg_num_rows($hQuery) > 0);
}
/**
* Look up the name of a group
* @param $strAct (string) Account name of the group
* @return (string) The name of the group. If the function fails, it returns null.
* Call getLastError() to get more information about the error.
*/
function getGroupName($strAct) {
$hQuery = db_query("SELECT * FROM groups WHERE act = $1;", $strAct);
if(!is_resource($hQuery)) {
// TODO throw exception
setLastError(RS_ERROR_SQL);
return null;
}
if(pg_num_rows($hQuery) == 0) {
return $strAct; // Group not found in database, return account name
}
$arResult = pg_fetch_array($hQuery);
return $arResult["name"];
}
/**
* Create a link to write a mail to the specified account name.
* This function returns a link if the specified account exists, otherwise it returns the
* account name.
* @param $strAct (string) Account name
* @param $strColor (string) Background color for icon()
* @param $strParams (string) additional URL parameters
* @return string
*/
function mailToUserLink($strAct, $strColor = "bl", $strParams = "") {
if(!isAct($strAct)) {
return $strAct;
}
return popup(relroot("msg/write/?to=".user_mail_addr($strAct).$strParams),
600, 400, nobr(icon("mail-reply-usr", array("size" => 16, "bg" =>
$strColor)) . getRealUserName($strAct)));
}
/**
* Determine if a specified string is a valid mail address
* @param $strAddr string
* @return string
*/
function isMailAddress($strAddr) {
return ((preg_match("/([a-zA-Z0-9_\-\.]*(@[a-zA-Z0-9\-\.]*)?(\s*,\s*)?)+/", $strAddr) > 0)
and (preg_match("/(\s*,\s*)$/", $strAddr) == 0));
}
/**
* Module-specific logging function.
* Prefixes the log message with a module-specific string and writes it to the logs.
* @param $strLog (string) Log message
* @return void
*/
function rrInsertLog($strLog) {
log_insert($strLog, null, "Room Reservation Schedule");
}
/**
* Get the SQL day number from a given timestamp.
* @param $ts (timestamp)
* @return (int) 0-6 for Sunday to Monday
*/
function rrDateToSQLDayNumber($ts) {
$aDays = array("Sun" => 0, "Mon" => 1, "Tue" => 2,
"Wed" => 3, "Thu" => 4, "Fri" => 5, "Sat" => 6);
return $aDays[date("D", $ts)];
}
/**
* Convert a UNIX timestamp to an SQL date string
* @param $ts (timestamp)
* @return string
*/
function dateToSql($ts) { return date("Y\-m\-d", intval($ts)); }
/**
* Calculate the timestamp of the monday in the current week
* @param $ts (timestamp) Calculate the value relative to this date
* @return timestamp
*/
function rrGetMonday($ts = null) {
if($ts === null) {
$ts = time();
}
if(date("D", $ts) == "Mon") {
// Today is monday
return strtotime("00:00", $ts);
} else {
return strtotime("last monday", $ts);
}
}
/** (array of strings) Additional CSS rules */
$rsLocalCss = array();
/**
* Add CSS rules to the page
* @param $s (string)
* @return void
*/
function rrAddCss($s) {
rrDebug("rsAddCss: add \"$s\"");
$GLOBALS["rsLocalCss"][] = $s;
}
/**
* Get CSS rules that have been added with rmAddCss()
* @return string
*/
function rrGetCSS() {
rrDebug("rsGetCss: Local CSS is ".var_export($GLOBALS["rsLocalCss"], true));
return implode("\n", $GLOBALS["rsLocalCss"]);
}
function rrDebug($s, $bReturn = false) {
if(isset($_GET["debug"])) {
if(!$bReturn) {
echo "\n";
} else {
return $s;
}
}
}
/**
* sprintf with support for ordinal numbers.
* This version of sprintf replaces all substrings of the type /\\d+#/
* (i.e. a decimal number with a hash sign appended) in the input string with
* the corresponding english ordinal number prefices (st, nd, rd, th).
* @param $str (string) Input string
* @param $args (mixed) Additional parameters to be passed to sprintf()
* @return (string)
*/
function _sprintf_ord($str, $args /*leave this parameters for doxygen*/) {
$args = func_get_args();
if(preg_match_all("/%[bcdufosxX]/", $args[0], $temp) != func_num_args()-1) {
trigger_error("Too few arguments", E_USER_ERROR);
return false;
}
$str = call_user_func_array("sprintf", $args);
while(preg_match("/(.*)(\d+)#(.*)/", $str, $m))
$str = $m[1]._(append_ord_suffix($m[2])).$m[3];
return $str;
}
?>