r1202 + all options have moved into the database
[racktables] / inc / config.php
CommitLineData
e673ee24
DO
1<?
2/*
9c0b0016
DO
3 *
4 * This file used to hold a collection of constants, variables and arrays,
5 * which drived the way misc RackTables functions performed. Now most of
6 * then have gone into the database, and there is perhaps a user interface
7 * for changing them. This file now provides a couple of functions to
8 * access the new config storage.
9 *
8d07e3e0
DO
10 */
11
8d07e3e0 12
9c0b0016
DO
13// Current code version is subject to change with each new release.
14define ('CODE_VERSION', '0.14.6');
e673ee24 15
9c0b0016
DO
16// The name of hash used to store account password hashes
17// in the database. I think, we are happy with this one forever.
18define ('PASSWORD_HASH', 'sha1');
75d3818d 19
9c0b0016
DO
20function getConfigVar ($varname = '')
21{
22 global $configCache;
23 // We assume the only point of cache init, and it is init.php. If it
24 // has failed, we don't retry loading.
25 if (!isset ($configCache))
26 {
27 showError ("Configuration cache is unavailable in getConfigVar()");
28 die;
29 }
30 if ($varname == '')
31 {
32 showError ("Missing argument to getConfigVar()");
33 die;
34 }
35 if (isset ($configCache[$varname]))
36 {
37 // Try casting to int, if possible.
38 if ($configCache[$varname]['vartype'] == 'unit')
39 return 0 + $configCache[$varname]['varvalue'];
40 else
41 return $configCache[$varname]['varvalue'];
42 }
43 return NULL;
44}
45
46function setConfigVar ($varname = '', $varvalue = '')
47{
48 global $configCache;
49 if (!isset ($configCache))
50 {
51 showError ('Configuration cache is unavailable in setConfigVar()');
52 die;
53 }
54 if (empty ($varname))
55 {
56 showError ("Empty argument to setConfigVar()");
57 die;
58 }
59 // We don't operate on unknown data.
60 if (!isset ($configCache[$varname]))
61 {
62 showError ("setConfigVar() doesn't know how to handle '${varname}'");
63 die;
64 }
65 if (empty ($varvalue) && $configCache[$varname]['emptyok'] != 'yes')
66 {
67 showError ("'${varname}' is configured to take non-empty value. Perhaps there was a reason to do so.");
68 die;
69 }
70 // Update cache only if the changes went into DB.
71 if (storeConfigVar ($varname, $varvalue))
72 $configCache[$varname]['varvalue'] = $varvalue;
73}
8d07e3e0 74
e673ee24 75?>