Code

Updated location list to remove addressbook for testing
[gosa.git] / gosa-core / include / class_gosaSupportDaemon.inc
1 <?php
3 class gosaSupportDaemon
4 {
5   private $o_sock       = NULL;
6   private $s_host       = "";
7   private $i_port       = 0;
8   private $f_timeout    = 0.2;
10   private $is_connected     = FALSE;
11   private $s_encryption_key = "";
13   private $entries  = array();
14   private $pointer  = 0;
16   private $s_error  = "";
17   private $b_error  = FALSE;
19   public function __construct($host,$port,$key="secret-gosa-password",$connect=TRUE,$timeout=0.2)
20   {
21     $this->s_host    = $host;
22     $this->i_port    = $port;
23     $this->f_timeout = $timeout;
24     $this->s_encryption_key = $key;
25   }
27   public function connect()
28   {
29     $this->o_sock = new Socket_Client($this->s_host,$this->i_port,TRUE,$this->f_timeout);
30     $this->o_sock->setEncryptionKey($this->s_encryption_key); 
31     if($this->o_sock->connected()){ 
32       $this->is_connected = TRUE;
33     }else{
34       $this->is_connected = FALSE;
35     }
36   }
38   public function disconnect()
39   {
40     $this->o_sock->close();
41     $this->is_connected = FALSE;
42   }
45   public function __reload()
46   {
47     echo "<b>Reload</b>";
48     $this->entries = array();
49     $this->pointer = 0;
50     $xml_msg = "<xml><header>gosa_query_jobdb</header><where><status>*</status></where></xml>";
51     $this->connect();
52     if($this->is_connected){
53       $this->o_sock->write($xml_msg);
54       $str = trim($this->o_sock->read());
55       $entries = $this->xml_to_array($str);
56       if(!isset($entries['XML'])){
57         print_a($entries);
58         echo htmlentities($str);
59         $this->set_error("Couldn't parse xml.");
60         $this->disconnect();
61         return(FALSE);
62       }else{
63         $ret = array_values($entries['XML']); 
64       }
65       $this->entries = $ret;
66       $this->disconnect();
67       return(TRUE);
68     }
69     $this->set_error("Could not establish socket connection.");
70     return(FALSE);
71   }
73   function xml_to_array($xml)
74   {
75     $params = array();
76     $level = array();
77     $parser  = xml_parser_create_ns();
78     xml_parse_into_struct($parser, $xml, $vals, $index);
80     $err_id = xml_get_error_code($parser);
81     if($err_id){
82       $this->set_error(xml_error_string(xml_get_error_code($parser)));
83       xml_parser_free($parser);
84     }else{
85       xml_parser_free($parser);
87       foreach ($vals as $xml_elem) {
88         if ($xml_elem['type'] == 'open') {
89           if (array_key_exists('attributes',$xml_elem)) {
90             list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
91           } else {
92             $level[$xml_elem['level']] = $xml_elem['tag'];
93           }
94         }
95         if ($xml_elem['type'] == 'complete') {
96           $start_level = 1;
97           $php_stmt = '$params';
98           while($start_level < $xml_elem['level']) {
99             $php_stmt .= '[$level['.$start_level.']]';
100             $start_level++;
101           }
102           $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
103           eval($php_stmt);
104         }
105       }
106     }
107     return($params); 
108   }
110   public function load()
111   {
112     return($this->__reload());
113   }
115   public function fetch()
116   {
117     if(isset($this->entries[$this->pointer])){
118       $p = $this->entries[$this->pointer];
119       $this->pointer ++;
120       return($p);
121     }
122     return(FALSE);
123   }
125   private function set_error($str)
126   {
127     $this->b_error = TRUE;
128     $this->s_error = $str;
129   }
131   public function is_error()
132   {
133     return($this->b_error);
134   }
136   public function get_error()
137   {
138     return($this->s_error);
139   }
141   public function decrease_entry_priority($id)
142   {
143     echo $id;
144   }
146   public function increase_entry_priority($id)
147   {
148     echo $id;
149   }
151   public function max_entry_priority($id)
152   {
153     echo $id;
154   }
156   public function min_entry_priority($id)
157   {
158     echo $id;
159   }
161   public function id_exists($id)
162   {
163     return(TRUE);
164   }
166   public function get_entry($id)
167   {
168     foreach($this->entries as $entry){
169       if($entry['ID'] == $id){
170         return($entry);
171       }
172     }
173   }
175   public function update_entry($id,$entry)
176   {
177     $xml_msg = "";
179     if($this->is_connected){
180       $this->o_sock->write($xml_msg);
181       $str = trim($this->o_sock->read());
182       $entries = $this->xml_to_array($str);
183       $this->disconnect();
184       return(TRUE);
185     }
186     $this->set_error("Could not establish socket connection.");
187     return(FALSE);
188   }
190   public function add_multiple($multiple)
191   {
192   }
194   public function remove_entry($id)
195   {
196   }
199 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
200 ?>