Search data:   First name Last name

command != 'SEARCH') die("ConnectorSearchResult: Packet is not a search result"); foreach($packet->fields as $f) { $field = substr($f, 0, 3); $data = substr($f, 4); switch($field) { case FLD_SEARCH_COUNT: $this->parseSearchCount($data); break; case FLD_SHOWFLD: $this->parseShowFld($data); break; case FLD_FIELDS: $this->parseFields($data); break; case FLD_FIELDSWIDTH: $this->parseFieldsWidth($data); break; case FLD_HEADERS: $this->parseHeaders($data); break; case FLD_SEARCHREC: $this->parseSearchRec($data); break; case FLD_SEARCHHV: $this->parseSearchHv($data); break; case FLD_HV_GROUP: $this->parseHvGroup($data); break; default: echo "$field = " . mangle($data) . "\r\n"; break; } } } // Protected methods protected function updateFieldCount($len) { while (count($this->fields) < $len) $this->fields[] = array(); } protected function parseSearchCount($data) { $this->searchCount = (int)$data; } protected function parseShowFld($data) { $x = explode(CONNECTOR_SUB, $data); $this->updateFieldCount(count($x)); for($i=0; $ifields[$i]['visible'] = $x[$i]; } protected function parseFields($data) { $x = explode(CONNECTOR_SUB, $data); $this->updateFieldCount(count($x)); for($i=0; $ifields[$i]['field'] = $x[$i]; } protected function parseFieldsWidth($data) { $x = explode(CONNECTOR_SUB, $data); $this->updateFieldCount(count($x)); for($i=0; $ifields[$i]['width'] = $x[$i]; } protected function parseHeaders($data) { $x = explode(CONNECTOR_SUB, $data); $this->updateFieldCount(count($x)); for($i=0; $ifields[$i]['header'] = $x[$i]; } protected function parseSearchRec($data) { $this->records[] = explode(CONNECTOR_SUB, $data); } protected function parseSearchHv($data) { $last = count($this->records) - 1; if ($last < 0) return; $x = explode(CONNECTOR_SUB, $data); $this->records[$last]['hv'][] = array( 'start' => $x[0], 'stop' => $x[1], 'tel' => $x[2], 'text' => $x[3], 'orsid' => $x[4], 'orstext' => $x[5], 'status' => $x[6], 'hvnr' => $x[7], 'tillg' => $x[8], 'vem' => $x[10], 'tel_text' => $x[11] ); } protected function parseHvGroup($data) { $last = count($this->records) - 1; if ($last < 0) return; $this->records[$last]['hvGroup'] = $data; } // Public methods public static function dumpDate($date) { // Reformat 20081231090000 -> 2008-12-31 09:00 return substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2) . ' ' . substr($date, 8, 2) . ':' . substr($date, 10, 2); } public function dumpToTable() { $visibleFields = array(); $visibleCount = 0; // Check which fields should be displayed or not for($i=0; $ifields); $i++) if ($this->fields[$i]['visible'] == 'J') $visibleFields[] = $i; $visibleCount = count($visibleFields); echo ""; // Dump table header echo ""; foreach($visibleFields as $i) echo ""; echo ""; foreach($this->records as $rec) { echo ""; foreach($visibleFields as $i) echo ""; echo ""; if (array_key_exists('hv', $rec)) foreach($rec['hv'] as $hv) { echo ""; } if (array_key_exists('hvGroup', $rec)) { $hv_return = self::dumpDate($rec['hvGroup']); echo ""; } } echo "
" . $this->fields[$i]['header'] . "
" . $rec[$i] . "
"; $hv_from = self::dumpDate($hv['start']); $hv_to = self::dumpDate($hv['stop']); $hv_ors = $hv['orstext']; echo "$hv_ors ($hv_from - $hv_to)"; echo "
Returns on $hv_return
"; } } command = $command; if ($fields != null) { foreach($fields as $k => $v) $this->fields[] = "$k=$v"; } } public static function decode($packet) { if ($packet == "" || $packet[0] != CONNECTOR_STX || $packet[strlen($packet)-1] != CONNECTOR_ETX) return null; $packet = substr($packet, 1, strlen($packet) - 2); $x = explode(CONNECTOR_SEP, $packet); $result = new ConnectorPacket(); $result->command = array_shift($x); $result->fields = $x; if ($result->command == "ERR") { $result->errno = $result->fields[0]; $result->errtext = $result->fields[1]; } return $result; } public function success() { return $this->errno == 0; } public function failed() { return $this->errno != 0; } public function get($code) { $code = $code . "="; $len = strlen($code); foreach($this->fields as $field) if (substr($field, 0, $len) == $code) return substr($field, $len); return ""; } public function add($code, $data) { $this->fields[] = $code . "=" . $data; } public function packet() { if ($this->command == "") return ""; return CONNECTOR_STX . $this->command . (count($this->fields) > 0 ? CONNECTOR_SEP . implode(CONNECTOR_SEP, $this->fields) : "") . CONNECTOR_ETX; } } connected()) die('Trying to use Connector communication while disconnected. This is not possible.'); } public function __construct() { $this->ip = new IP(); $this->ip->timeout = 8; } public function __destruct() { $this->ip->disconnect(); } public function connect($host) { return $this->ip->connect($host, 2089); } public function disconnect() { $this->ip->disconnect(); } public function send(ConnectorPacket $packet) { $this->assertConnected(); $this->ip->send($packet->packet()); } public function read() { $data = $this->ip->readeol(CONNECTOR_ETX); if ($data == "") return null; return ConnectorPacket::decode($data); } public function connected() { return $this->ip->connected(); } public function sessionized() { return $this->ip->connected() && $this->session != ""; } public function authorized() { return $this->ip->connected() && $this->sessionized() && $this->authorized; } public function stat() { $this->send(new ConnectorPacket('STAT')); if (($packet = $this->read()) == null) die("Connector: STAT did not receive a reply"); return $packet; } public function req_s() { $this->send(new ConnectorPacket('REQ-S')); if (($packet = $this->read()) == null) die("Connector: REQ-S did not receive a reply"); if ($packet->errno == 0) $this->session = $packet->get('000'); return $packet; } public function end() { $this->send(new ConnectorPacket('END', array( FLD_SESSION => $this->session ))); if (($packet = $this->read()) == null) die("Connector: END did not receive a reply"); $this->session = ""; return $packet; } public function auth($anknr, $password) { $this->send(new ConnectorPacket('AUTH', array( FLD_SESSION => $this->session, FLD_ANKNR => $anknr, FLD_PASSWORD => $password ))); if (($packet = $this->read()) == null) die("Connector: AUTH did not receive a reply"); $this->authorized = $packet->success(); return $packet; } public function signon($value) { $this->send(new ConnectorPacket('AUTH', array( FLD_SESSION => $this->session, FLD_SIGNON => $value ))); if (($packet = $this->read()) == null) die("Connector: AUTH did not receive a reply"); $this->authorized = $packet->success(); return $packet; } public function info($id = "") { $packet = new ConnectorPacket('INFO', array( FLD_SESSION => $this->session )); if ($id != "") $packet->add(FLD_ID, $id); $this->send($packet); if (($packet = $this->read()) == null) die("Connector: INFO did not receive a reply"); return $packet; } public function info_data($id = "") { $packet = new ConnectorPacket('INFO-DATA', array( FLD_SESSION => $this->session )); if ($id != "") $packet->add(FLD_ID, $id); $this->send($packet); if (($packet = $this->read()) == null) die("Connector: INFO-DATA did not receive a reply"); return $packet; } public function int_call($number) { $this->send(new ConnectorPacket('INT-CALL', array( FLD_SESSION => $this->session, FLD_INT_TARGET => $number ))); if (($packet = $this->read()) == null) die("Connector: INT-CALL did not receive a reply"); return $packet; } }