maj syntaxe accolades, maj jQuery, correction layout contact
[mtweb] / web / app / data / modules / sql / mw_data_config.php
1 <?php
2
3   class mw_data_config extends mw_data{
4
5     function config($key = null){
6       $sgbd = $this->sgbd();
7       $value = false;
8       if(isset($key)){
9         $sql =
10          "SELECT `value` FROM #--config"
11         ." WHERE `key`=".$this->eq($key);
12         $rst = $sgbd->query($sql);
13         if(!isset($rst)) return false;
14         if($v_rst = $sgbd->fetch_assoc($rst)) $value = $v_rst["value"];
15         else $value = "";
16         $sgbd->free_result($rst);
17       }
18       else{
19         $value = array();
20         $sql =
21          "SELECT * FROM #--config";
22         $rst = $sgbd->query($sql);
23         if(!isset($rst)) return false;
24         while($v_rst = $sgbd->fetch_assoc($rst)) $value[$v_rst["key"]] = $v_rst["value"];
25         $sgbd->free_result($rst);
26       }
27       return $value;
28     }
29
30     function config_exists($key){
31       $sgbd = $this->sgbd();
32       $exists = false;
33       $sql = "SELECT count(*) as n FROM #--config"
34       ." WHERE `key`=".$this->eq($key);
35       $rst = $sgbd->query($sql);
36       if(!isset($rst)) return false;
37       if($v_rst = $sgbd->fetch_assoc($rst)) $exists = $v_rst["n"];
38       $sgbd->free_result($rst);
39       return $exists;
40     }
41
42     function set_config($key, $value){
43       $sgbd = $this->sgbd();
44       if($this->config_exists($key)) $sql =
45        "UPDATE #--config"
46       ." SET `value`=".$this->eq($value)
47       ." WHERE `key`=".$this->eq($key);
48       else $sql =
49        "INSERT INTO #--config"
50       ." VALUES(NULL, ".$this->eq($key).", ".$this->eq($value).")";
51       $rst = $sgbd->query($sql);
52       if(!isset($rst)) return false;
53       return true;
54     }
55
56     function del_config($key){
57       $sgbd = $this->sgbd();
58       return $sgbd->query("DELETE FROM #--config WHERE `key`=".$this->eq($key)) ? true : false;
59     }
60
61   }
62
63 ?>