s_host = $host; $this->i_port = $port; $this->f_timeout = $timeout; $this->s_encryption_key = $key; } public function connect() { $this->o_sock = new Socket_Client($this->s_host,$this->i_port,TRUE,$this->f_timeout); $this->o_sock->setEncryptionKey($this->s_encryption_key); if($this->o_sock->connected()){ $this->is_connected = TRUE; }else{ $this->is_connected = FALSE; } } public function disconnect() { $this->o_sock->close(); $this->is_connected = FALSE; } public function __reload() { echo "Reload"; $this->entries = array(); $this->pointer = 0; $xml_msg = "
gosa_query_jobdb
*
"; $this->connect(); if($this->is_connected){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); $entries = $this->xml_to_array($str); if(!isset($entries['XML'])){ print_a($entries); echo htmlentities($str); $this->set_error("Couldn't parse xml."); $this->disconnect(); return(FALSE); }else{ $ret = array_values($entries['XML']); } $this->entries = $ret; $this->disconnect(); return(TRUE); } $this->set_error("Could not establish socket connection."); return(FALSE); } function xml_to_array($xml) { $params = array(); $level = array(); $parser = xml_parser_create_ns(); xml_parse_into_struct($parser, $xml, $vals, $index); $err_id = xml_get_error_code($parser); if($err_id){ $this->set_error(xml_error_string(xml_get_error_code($parser))); xml_parser_free($parser); }else{ xml_parser_free($parser); foreach ($vals as $xml_elem) { if ($xml_elem['type'] == 'open') { if (array_key_exists('attributes',$xml_elem)) { list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']); } else { $level[$xml_elem['level']] = $xml_elem['tag']; } } if ($xml_elem['type'] == 'complete') { $start_level = 1; $php_stmt = '$params'; while($start_level < $xml_elem['level']) { $php_stmt .= '[$level['.$start_level.']]'; $start_level++; } $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];'; eval($php_stmt); } } } return($params); } public function load() { return($this->__reload()); } public function fetch() { if(isset($this->entries[$this->pointer])){ $p = $this->entries[$this->pointer]; $this->pointer ++; return($p); } return(FALSE); } private function set_error($str) { $this->b_error = TRUE; $this->s_error = $str; } public function is_error() { return($this->b_error); } public function get_error() { return($this->s_error); } public function decrease_entry_priority($id) { echo $id; } public function increase_entry_priority($id) { echo $id; } public function max_entry_priority($id) { echo $id; } public function min_entry_priority($id) { echo $id; } public function id_exists($id) { return(TRUE); } public function get_entry($id) { foreach($this->entries as $entry){ if($entry['ID'] == $id){ return($entry); } } } public function update_entry($id,$entry) { $xml_msg = ""; if($this->is_connected){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); $entries = $this->xml_to_array($str); $this->disconnect(); return(TRUE); } $this->set_error("Could not establish socket connection."); return(FALSE); } public function add_multiple($multiple) { } public function remove_entry($id) { } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>