/** * return current session id * * @param boolean $generateUid * @return mixed|null */ public static function getSessionId($generateUid = true) { if (!self::isRegistered(self::SESSIONID)) { $sessionId = null; // TODO allow to access Tinebase/Core methods with Setup session and remove this workaround if (Tinebase_Session::isStarted() && !Tinebase_Session::isSetupSession()) { $sessionId = Tinebase_Session::getId(); } if (empty($sessionId)) { $sessionId = 'NOSESSION'; if ($generateUid) { $sessionId .= Tinebase_Record_Abstract::generateUID(31); } } self::set(self::SESSIONID, $sessionId); } return self::get(self::SESSIONID); }
/** * create the search results dialogue * * @param string $mac the mac address of the phone * @param string $query the string to search the contacts for */ public function searchContacts($mac, $query) { $baseUrl = $this->_getBaseUrl(); // do nothing if search string is empty if (empty($query)) { $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?> <SnomIPPhoneText> <Title>Nothing found!</Title> <Text>Nothing found!</Text> <fetch mil="1000">' . $baseUrl . '?method=Phone.directory&TINE20SESSID=' . Tinebase_Session::getId() . '&mac=' . $mac . '</fetch> </SnomIPPhoneText> '); header('Content-Type: text/xml'); echo $xml->asXML(); return; } $this->_authenticate(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' phone ' . $mac . ' search for ' . $query); } $phone = Voipmanager_Controller_Snom_Phone::getInstance()->getByMacAddress($mac); $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL); $tbContainer = Tinebase_Container::getInstance(); $readAbleContainer = array(); foreach ($phone->rights as $right) { if ($right->account_type == Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) { $containers = $tbContainer->getContainerByACL($right->account_id, 'Addressbook', Tinebase_Model_Grants::GRANT_READ); $readAbleContainer = array_merge($readAbleContainer, $containers->getArrayOfIds()); } } $readAbleContainer = array_unique($readAbleContainer); $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'query', 'operator' => 'contains', 'value' => $query), array('field' => 'container', 'operator' => 'in', 'value' => $readAbleContainer))); $contacts = $contactsBackend->search($filter, new Tinebase_Model_Pagination()); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' found ' . count($contacts) . ' contacts'); } if (count($contacts) == 0) { $baseUrl = $this->_getBaseUrl(); $xml = '<SnomIPPhoneText> <Title>Nothing found!</Title> <Text>Nothing found!</Text> <fetch mil="1000">' . $baseUrl . '?method=Phone.directory&TINE20SESSID=' . Tinebase_Session::getId() . '&mac=' . $mac . '</fetch> </SnomIPPhoneText> '; } else { $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?> <SnomIPPhoneDirectory> <Title>Directory</Title> <Prompt>Dial</Prompt> </SnomIPPhoneDirectory> '); foreach ($contacts as $contact) { if (!empty($contact->tel_work)) { $directoryEntry = $xml->addChild('DirectoryEntry'); $directoryEntry->addChild('Name', $contact->n_fileas . ' Work'); $directoryEntry->addChild('Telephone', $contact->tel_work); } if (!empty($contact->tel_cell)) { $directoryEntry = $xml->addChild('DirectoryEntry'); $directoryEntry->addChild('Name', $contact->n_fileas . ' Cell'); $directoryEntry->addChild('Telephone', $contact->tel_cell); } if (!empty($contact->tel_home)) { $directoryEntry = $xml->addChild('DirectoryEntry'); $directoryEntry->addChild('Name', $contact->n_fileas . ' Home'); $directoryEntry->addChild('Telephone', $contact->tel_home); } if (!empty($contact->tel_cell_private)) { $directoryEntry = $xml->addChild('DirectoryEntry'); $directoryEntry->addChild('Name', $contact->n_fileas . ' CellP'); $directoryEntry->addChild('Telephone', $contact->tel_cell_private); } } $xml = $xml->asXML(); } header('Content-Type: text/xml'); echo $xml; }