1 | <?php |
---|
2 | |
---|
3 | class env |
---|
4 | { |
---|
5 | public $config_file; |
---|
6 | public $PATHES; |
---|
7 | public $PARAMS; |
---|
8 | public $CONFIG; |
---|
9 | public $prefix; |
---|
10 | public $base_url; |
---|
11 | public $bdd; |
---|
12 | public $acces; |
---|
13 | public $DEFAULT_ALLOW; |
---|
14 | |
---|
15 | function __construct($config_file) |
---|
16 | { $this->config_file = $config_file; |
---|
17 | if(file_exists($config_file)) |
---|
18 | { $config = simplexml_load_file($config_file); |
---|
19 | foreach($config->pathes[0] as $path_name => $path_value) |
---|
20 | { $this->PATHES[$path_name] = utf8_decode($path_value); |
---|
21 | } |
---|
22 | $this->PARAMS = array(); |
---|
23 | foreach($config->params[0] as $code_param => $get_param) |
---|
24 | { $this->PARAMS[$code_param] = utf8_decode($get_param); |
---|
25 | } |
---|
26 | $this->CONFIG = array(); |
---|
27 | foreach($config->config[0] as $config_param => $config_value) |
---|
28 | { $this->CONFIG[$config_param] = utf8_decode($config_value); |
---|
29 | } |
---|
30 | $this->init_base_url(); |
---|
31 | $this->acces = array(); |
---|
32 | $this->prefix = utf8_decode($config->prefix); |
---|
33 | $this->DEFAULT_ALLOW = false; |
---|
34 | } |
---|
35 | else |
---|
36 | { echo "[erreur] config : impossible de trouver le fichier de configuration pour l'installation"; |
---|
37 | exit(); |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | function set_config($config) |
---|
42 | { if(is_array($config)) |
---|
43 | { foreach($config as $key => $value) $this->CONFIG[$key] = $value; |
---|
44 | return true; |
---|
45 | } |
---|
46 | return false; |
---|
47 | } |
---|
48 | |
---|
49 | function init_base_url() |
---|
50 | { $_params = $_SERVER["QUERY_STRING"]; |
---|
51 | $v_params = explode("&", $_params); |
---|
52 | $this->base_url = $_SERVER["SCRIPT_NAME"]."?"; |
---|
53 | $FIRST = true; |
---|
54 | foreach($v_params as $param) |
---|
55 | { $key = strpos($param, "=") === false ? $param : substr($param, 0, strpos($param, "=")); |
---|
56 | if(!$this->is_a_param($key)) |
---|
57 | { if(!$FIRST) $this->base_url .= "&"; |
---|
58 | else $FIRST = false; |
---|
59 | $this->base_url .= $param; |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | function is_a_param($key) |
---|
65 | { foreach($this->PARAMS as $_key => $_value) if(strcmp($key, $_value) == 0) return true; |
---|
66 | return false; |
---|
67 | } |
---|
68 | |
---|
69 | function path($name) { return $this->PATHES[$name]; } |
---|
70 | function param($name) { return $this->PARAMS[$name]; } |
---|
71 | function config($name) { return $this->CONFIG[$name]; } |
---|
72 | |
---|
73 | function url($_params) |
---|
74 | { $url = $this->base_url; |
---|
75 | foreach($_params as $key => $value) |
---|
76 | { $url .= strcmp(substr($url, -1, 1), "?") == 0 ? "" : "&"; |
---|
77 | $url .= $this->param($key)."=".$value; |
---|
78 | } |
---|
79 | return $url; |
---|
80 | } |
---|
81 | |
---|
82 | function action_ok($action) |
---|
83 | { return |
---|
84 | ( isset($this->acces["actions"][$action]) ? |
---|
85 | $this->acces["actions"][$action][$this->user["statut"]] |
---|
86 | :($this->DEFAULT_ALLOW ? true : false) |
---|
87 | ); |
---|
88 | } |
---|
89 | |
---|
90 | function interface_ok($interface) |
---|
91 | { return |
---|
92 | ( isset($this->acces["interfaces"][$interface]) ? |
---|
93 | $this->acces["interfaces"][$interface][$this->user["statut"]] |
---|
94 | :($this->DEFAULT_ALLOW ? true : false) |
---|
95 | ); |
---|
96 | } |
---|
97 | |
---|
98 | function out_file_exists($file) { return file_exists("out/".$file); } |
---|
99 | function out_file($file) { return "out/".$file; } |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | ?> |
---|