File: 1.19.3a/server/base/nats.cfg.inc.php (View as Code)

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008 PurplePixie Systems 6: 7: FreeNATS is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeNATS is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeNATS. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freenats 21: -------------------------------------------------------------- */ 22: 23: class TNATS_Cfg 24: { 25: var $loaded=false; 26: var $data=array(); 27: var $default=""; 28: 29: function Load($nats_db) 30: { 31: $q="SELECT * FROM fnconfig"; 32: $r=$nats_db->Query($q); 33: while ($row=$nats_db->Fetch_Array($r)) 34: { 35: $this->data[$row['fnc_var']]=$row['fnc_val']; 36: //echo $row['fnc_var']."=".$row['fnc_val']."\n
";
37: } 38: $nats_db->Free($r); 39: } 40: 41: function Get($var,$def="") 42: { 43: if (isset($this->data[$var])) return $this->data[$var]; 44: return $def; 45: } 46: 47: function DumpToScreen() 48: { 49: $keys=array_keys($this->data); 50: foreach($keys as $key) 51: { 52: echo $key."=".$this->data[$key]."
\n";
53: } 54: } 55: function Set($var,$val,$perm=true) 56: { 57: global $NATS; 58: $this->data[$var]=$val; 59: if ($perm) 60: { 61: global $NATS; 62: $q="UPDATE fnconfig SET fnc_val=\"".ss($val)."\" WHERE fnc_var=\"".ss($var)."\""; 63: $NATS->DB->Query($q); 64: if ($NATS->DB->Affected_Rows()<=0) // not already existing 65: { 66: $q="INSERT INTO fnconfig(fnc_var,fnc_val) VALUES(\"".ss($var)."\",\"".ss($val)."\")"; 67: $NATS->DB->Query($q); 68: } 69: } 70: } 71: }