Mercurial > hg > fapweb
diff msitegen.inc.php @ 198:96ab189e5c03
Add some new helper functions and use them.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 16 Nov 2013 06:13:17 +0200 |
parents | 1b30c2107e5b |
children | 8985d2bdb29b |
line wrap: on
line diff
--- a/msitegen.inc.php Fri Nov 15 19:16:12 2013 +0200 +++ b/msitegen.inc.php Sat Nov 16 06:13:17 2013 +0200 @@ -51,23 +51,39 @@ } +function stGetSQLSettingData($item) +{ + switch ($item["vtype"]) + { + case VT_INT: return intval($item["vint"]); + case VT_BOOL: return intval($item["vint"]) ? true : false; + case VT_STR: return $item["vstr"]; + case VT_TEXT: return $item["vtext"]; + } +} + + +function stGetSettingSQL($item, $val) +{ + global $db; + switch ($item["vtype"]) + { + case VT_INT: return "vint=".intval($val); break; + case VT_BOOL: return "vint=".($val ? "1" : "0"); break; + case VT_STR: return "vstr=".$db->quote($val); break; + case VT_TEXT: return "vtext=".$db->quote($val); break; + default: return FALSE; + } +} + function stReloadSettings() { global $siteSettings; - $res = stExecSQL("SELECT * FROM settings"); - if ($res !== FALSE) + + if (($res = stExecSQL("SELECT * FROM settings")) !== FALSE) { - foreach ($res as $row) - { - switch ($row["vtype"]) - { - case VT_INT: $val = intval($row["vint"]); break; - case VT_BOOL: $val = intval($row["vint"]) ? true : false; break; - case VT_STR: $val = $row["vstr"]; break; - case VT_TEXT: $val = $row["vtext"]; break; - } - $siteSettings[$row["key"]] = $val; - } + foreach ($res as $item) + $siteSettings[$item["key"]] = stGetSQLSettingData($item); } else die("Error fetching site settings.");