forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.inc.php
98 lines (87 loc) · 3.21 KB
/
config.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
class Config{
var $ParameterArray;
var $defaults;
function Config ($db=null){
//Get parameter value pairs from fac_Config
$sql='select Parameter, Value, DefaultVal from fac_Config';
$result=mysql_query($sql);
while ($row=@mysql_fetch_array($result)){
if ($row['Parameter']== 'ClassList'){
$List = explode(', ', $row['Value']);
$this->ParameterArray[$row['Parameter']]=$List;
$this->defaults[$row['Parameter']]=$row['DefaultVal'];
}else{
$this->ParameterArray[$row['Parameter']]=$row['Value'];
$this->defaults[$row['Parameter']]=$row['DefaultVal'];
}
}
return;
}
function UpdateConfig($db){
foreach($this->ParameterArray as $key=>$value){
if ($key=='ClassList'){
$numItems=count($value);
$i=0;
$valueStr='';
foreach($value as $item){
$valueStr .= $item;
if($i+1 != $numItems){
$valueStr.=', ';
}
$i++;
}
$sql='update fac_Config set Value=\''.addslashes($valueStr).'\' where Parameter=\''.$key.'\'';
$result=mysql_query($sql,$db);
}else{
$sql='update fac_Config set Value=\''.addslashes($value).'\' where Parameter=\''.$key.'\'';
$result=mysql_query($sql,$db);
}
}
return;
}
static function RevertToDefault($db, $parameter){
if ($parameter=='none'){
$sql='update fac_Config set Value=DefaultVal';
}
else{
$sql='update fac_Config set Value=DefaultVal where Parameter = \''.$parameter.'\'';
}
$result=mysql_query($sql,$db);
return;
}
function Rebuild ($db){
/* Rebuild: This function should only be needed after something like the version erasing glitch from 1.1 and 1.2.
At this time it is possible to get unwanted duplicate configuration parameters and this will clean
them.
I am not sanitizing input here because it should have no user interaction. Read from the db, flush
db, write unique values back to the db.
*/
$sql='select * from fac_Config';
$result=mysql_query($sql,$db);
$uniqueconfig=array();
// Build array of unique config parameters
while ($row=mysql_fetch_array($result)){
if(isset($uniqueconfig[$row['Parameter']]['Value'])){
// if value in the array is equal to the default value AND the current value is different from the value in the array update the value in the array
if($uniqueconfig[$row['Parameter']]['Value']==$row['DefaultVal'] && $uniqueconfig[$row['Parameter']]['Value']!=$row['Value']){
$uniqueconfig[$row['Parameter']]['Value']=$row['Value'];
}
}else{
// value wasn't set in the array so we'll take whatever we're given even if it is the default value
$uniqueconfig[$row['Parameter']]['Value']=$row['Value'];
}
// the following aren't user configurable so no need to check for differences
$uniqueconfig[$row['Parameter']]['UnitOfMeasure']=$row['UnitOfMeasure'];
$uniqueconfig[$row['Parameter']]['ValType']=$row['ValType'];
$uniqueconfig[$row['Parameter']]['DefaultVal']=$row['DefaultVal'];
}
// Empty config table
mysql_query('TRUNCATE TABLE fac_Config;',$db);
// Rebuild config table from cleaned array
foreach($uniqueconfig as $key => $row){
mysql_query("INSERT INTO fac_Config VALUES ('$key','{$row['Value']}','{$row['UnitOfMeasure']}','{$row['ValType']}','{$row['DefaultVal']}');",$db);
}
}
}
?>