Esempio n. 1
0
 /**
  * the singleton pattern
  *
  * @return Voipmanager_Controller_Snom_Template
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Voipmanager_Controller_Snom_Template();
     }
     return self::$_instance;
 }
 /**
  * public function to access the directory
  * 
  * @param string $mac
  */
 public function directory($mac)
 {
     $this->_authenticate();
     # get the phone
     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' phone ' . $mac);
     $phone = Voipmanager_Controller_Snom_Phone::getInstance()->getByMacAddress($mac);
     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' phone ' . $phone->template_id);
     $template = Voipmanager_Controller_Snom_Template::getInstance()->get($phone->template_id);
     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' phone ' . $template->setting_id);
     $settings = Voipmanager_Controller_Snom_Setting::getInstance()->get($template->setting_id);
     $language = $settings->language ? $settings->language : 'en';
     $translate = Tinebase_Translation::getTranslation($this->_applicationName, new Zend_Locale('de'));
     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' phone ' . $language);
     $baseUrl = $this->_getBaseUrl();
     $xml = '<?xml version="1.0" encoding="UTF-8"?>
         <SnomIPPhoneInput>
             <Prompt>Prompt</Prompt>
             <URL>' . $baseUrl . '</URL>
             <InputItem>
                 <DisplayName>' . $translate->_('Enter search') . ':</DisplayName>
                 <QueryStringParam>method=Phone.searchContacts&TINE20SESSID=' . Tinebase_Session::getId() . '&mac=' . $mac . '&query</QueryStringParam>
                 <DefaultValue/>
                 <InputFlags>a</InputFlags>
             </InputItem>
         </SnomIPPhoneInput>
     ';
     header('Content-Type: text/xml');
     echo $xml;
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->_backends['Asterisk_Context'] = Voipmanager_Controller_Asterisk_Context::getInstance();
     $this->_backends['Asterisk_Meetme'] = Voipmanager_Controller_Asterisk_Meetme::getInstance();
     $this->_backends['Asterisk_SipPeer'] = Voipmanager_Controller_Asterisk_SipPeer::getInstance();
     $this->_backends['Asterisk_Voicemail'] = Voipmanager_Controller_Asterisk_Voicemail::getInstance();
     $this->_backends['Snom_Line'] = Voipmanager_Controller_Snom_Line::getInstance();
     $this->_backends['Snom_Location'] = Voipmanager_Controller_Snom_Location::getInstance();
     $this->_backends['Snom_Phone'] = Voipmanager_Controller_Snom_Phone::getInstance();
     $this->_backends['Snom_Setting'] = Voipmanager_Controller_Snom_Setting::getInstance();
     $this->_backends['Snom_Software'] = Voipmanager_Controller_Snom_Software::getInstance();
     $this->_backends['Snom_Template'] = Voipmanager_Controller_Snom_Template::getInstance();
 }
 /**
  * create edit MyPhone dialog
  *
  * @param int $phoneId
  * 
  * @todo remove that when new myphone edit dialog is working
  * @deprecated
  */
 public function editMyPhone($phoneId = NULL)
 {
     $currentAccount = Tinebase_Core::getUser()->toArray();
     if (!empty($phoneId)) {
         $snomPhone = Phone_Controller_MyPhone::getInstance()->get($phoneId);
         //unset($phone->lines);
         $_phoneData = $snomPhone->toArray();
         $_phoneSettingsData = Voipmanager_Controller_Snom_PhoneSettings::getInstance()->get($_phoneData['id'])->toArray();
         $_templateData = Voipmanager_Controller_Snom_Template::getInstance()->get($_phoneData['template_id'])->toArray();
         $_settingsData = Voipmanager_Controller_Snom_Setting::getInstance()->get($_templateData['setting_id'])->toArray();
         $_writableFields = array('web_language', 'language', 'display_method', 'mwi_notification', 'mwi_dialtone', 'headset_device', 'message_led_other', 'global_missed_counter', 'scroll_outgoing', 'show_local_line', 'show_call_status', 'call_waiting');
         foreach ($_writableFields as $wField) {
             $_fieldRW = $wField . '_writable';
             if ($_settingsData[$_fieldRW] == '0') {
                 $_phoneSettingsData[$wField] = $_settingsData[$wField];
                 $_notWritable[$wField] = 'true';
             } else {
                 if ($_phoneSettingsData[$wField] === NULL) {
                     $_phoneSettingsData[$wField] = $_settingsData[$wField];
                 }
                 $_notWritable[$wField] = '';
             }
         }
         $encodedWritable = Zend_Json::encode($_notWritable);
         $_phoneData = array_merge($_phoneSettingsData, $_phoneData);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_phoneData, true));
         }
         // encode the data arrays
         $encodedSnomPhone = Zend_Json::encode($_phoneData);
     } else {
         //$phone = new Voipmanager_Model_Snom_Phone();
         //$lines = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_Line');
         $encodedWritable = '{}';
         $encodedSnomPhone = '{}';
         //$encodedSettings = '{}';
     }
     $view = new Zend_View();
     $view->setScriptPath('Tinebase/views');
     $view->title = "edit myPhone data";
     $view->jsExecute = 'Tine.Voipmanager.MyPhones.EditDialog.display(' . $encodedSnomPhone . ', ' . $encodedWritable . ');';
     header('Content-Type: text/html; charset=utf-8');
     echo $view->render('jsclient.php');
 }
 /**
  * update one phone
  *
  * @param Voipmanager_Model_Snom_Phone $_phone
  * @return Voipmanager_Model_Snom_Phone
  * @throws Voipmanager_Exception_Validation
  * 
  * @todo do not overwrite update() -> use inspectBefore/After functions
  */
 public function update(Tinebase_Record_Interface $_phone)
 {
     // check first if mac address is already used
     if ($_phone->has('macaddress')) {
         try {
             $phoneWithMac = $this->getByMacAddress($_phone->macaddress);
             if ($phoneWithMac->getId() !== $_phone->getId()) {
                 throw new Voipmanager_Exception_Validation('A phone with this mac address already exists.');
             }
         } catch (Voipmanager_Exception_NotFound $venf) {
             // everything ok
         }
     }
     try {
         $db = $this->_backend->getAdapter();
         $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($db);
         $phone = $this->_backend->update($_phone);
         $_phoneSettings = $_phone->settings;
         if ($_phoneSettings instanceof Voipmanager_Model_Snom_PhoneSettings) {
             // force the right phone_id
             $_phoneSettings->setId($phone->getId());
             // set all settings which are equal to the default settings to NULL
             $template = Voipmanager_Controller_Snom_Template::getInstance()->get($phone->template_id);
             $settingDefaults = Voipmanager_Controller_Snom_Setting::getInstance()->get($template->setting_id);
             foreach ($_phoneSettings->toArray() as $key => $value) {
                 if ($key == 'phone_id') {
                     continue;
                 }
                 if ($settingDefaults->{$key} == $value) {
                     $_phoneSettings->{$key} = NULL;
                 }
             }
             if (Voipmanager_Controller_Snom_PhoneSettings::getInstance()->get($phone->getId())) {
                 $phoneSettings = Voipmanager_Controller_Snom_PhoneSettings::getInstance()->update($_phoneSettings);
             } else {
                 $phoneSettings = Voipmanager_Controller_Snom_PhoneSettings::getInstance()->create($_phoneSettings);
             }
         }
         Voipmanager_Controller_Snom_Line::getInstance()->deletePhoneLines($phone->getId());
         $this->_createLines($phone, $_phone->lines);
         // save phone rights
         if (isset($_phone->rights)) {
             $this->_backend->setPhoneRights($_phone);
         }
         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     } catch (Exception $e) {
         $this->_handleRecordCreateOrUpdateException($e);
     }
     return $this->get($phone->getId());
 }
 /**
  * create a phone with a line for the current user
  */
 protected function _createSnomPhone()
 {
     $testLocation = $this->_getSnomLocation();
     $returnedLocation = Voipmanager_Controller_Snom_Location::getInstance()->create($testLocation);
     $testTemplate = $this->_getSnomTemplate();
     $returnedTemplate = Voipmanager_Controller_Snom_Template::getInstance()->create($testTemplate);
     $rights = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_PhoneRight', array(array('account_id' => Tinebase_Core::getUser()->getId(), 'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER, 'read_right' => TRUE, 'write_right' => TRUE, 'dial_right' => TRUE)));
     $sipPeer = Voipmanager_Controller_Asterisk_SipPeer::getInstance()->create($this->_getAsteriskSipPeer());
     $lines = new Tinebase_Record_RecordSet('Voipmanager_Model_Snom_Line', array(array('asteriskline_id' => $sipPeer->getId(), 'linenumber' => 1, 'lineactive' => 1, 'idletext' => 'idle')));
     $settings = new Voipmanager_Model_Snom_PhoneSettings(array('web_language' => 'English'));
     $this->_phone = Voipmanager_Controller_Snom_Phone::getInstance()->create(new Voipmanager_Model_Snom_Phone(array('description' => 'Created by Tine 2.0 DEMO DATA', 'macaddress' => substr(Tinebase_Record_Abstract::generateUID(), 0, 12), 'location_id' => $returnedLocation['id'], 'template_id' => $returnedTemplate['id'], 'current_model' => 'snom300', 'redirect_event' => 'none', 'http_client_info_sent' => '1', 'http_client_user' => Tinebase_Record_Abstract::generateUID(), 'http_client_pass' => Tinebase_Record_Abstract::generateUID(), 'rights' => $rights, 'lines' => $lines, 'settings' => $settings)));
 }
Esempio n. 7
0
 /**
  * delete multiple template entries
  *
  * @param  array $ids list of templateId's to delete
  * @return array
  */
 public function deleteSnomTemplates($ids)
 {
     return $this->_delete($ids, Voipmanager_Controller_Snom_Template::getInstance());
 }
Esempio n. 8
0
 /**
  * update one phone
  *
  * @param Voipmanager_Model_Snom_Phone $_phone
  * @param Voipmanager_Model_Snom_PhoneSettings|optional $_phoneSettings
  * @return Voipmanager_Model_Snom_Phone
  * @throws Voipmanager_Exception_Validation
  */
 public function update(Tinebase_Record_Interface $_phone)
 {
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_phone->toArray(), true));
     // check first if mac address is already used
     if ($_phone->has('macaddress')) {
         try {
             $phoneWithMac = $this->getByMacAddress($_phone->macaddress);
             if ($phoneWithMac->getId() !== $_phone->getId()) {
                 throw new Voipmanager_Exception_Validation('A phone with this mac address already exists.');
             }
         } catch (Voipmanager_Exception_NotFound $venf) {
             // everything ok
         }
     }
     $phone = $this->_backend->update($_phone);
     $_phoneSettings = $_phone->settings;
     if ($_phoneSettings instanceof Voipmanager_Model_Snom_PhoneSettings) {
         // force the right phone_id
         $_phoneSettings->setId($phone->getId());
         // set all settings which are equal to the default settings to NULL
         $template = Voipmanager_Controller_Snom_Template::getInstance()->get($phone->template_id);
         $settingDefaults = Voipmanager_Controller_Snom_Setting::getInstance()->get($template->setting_id);
         foreach ($_phoneSettings->toArray() as $key => $value) {
             if ($key == 'phone_id') {
                 continue;
             }
             if ($settingDefaults->{$key} == $value) {
                 $_phoneSettings->{$key} = NULL;
             }
         }
         if (Voipmanager_Controller_Snom_PhoneSettings::getInstance()->get($phone->getId())) {
             //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_phoneSettings->toArray(), true));
             $phoneSettings = Voipmanager_Controller_Snom_PhoneSettings::getInstance()->update($_phoneSettings);
         } else {
             $phoneSettings = Voipmanager_Controller_Snom_PhoneSettings::getInstance()->create($_phoneSettings);
         }
     }
     Voipmanager_Controller_Snom_Line::getInstance()->deletePhoneLines($phone->getId());
     $this->_createLines($phone, $_phone->lines);
     // save phone rights
     if (isset($_phone->rights)) {
         $this->_backend->setPhoneRights($_phone);
     }
     return $this->get($phone->getId());
 }
 /**
  * create edit template dialog
  *
  * @param int $templateId
  * @todo catch permission denied exceptions only
  * @todo move stuff out of registry. Registry is reserved for Tinebase!!!
  * 
  */
 public function editSnomTemplate($templateId = NULL)
 {
     if (!empty($templateId)) {
         $template = Voipmanager_Controller_Snom_Template::getInstance()->get($templateId);
         // encode the template array
         $encodedTemplate = Zend_Json::encode($template->toArray());
     } else {
         $encodedTemplate = '{}';
     }
     // software data
     $software = Voipmanager_Controller_Snom_Software::getInstance()->search();
     $encodedSoftware = Zend_Json::encode($software->toArray());
     // keylayout data
     //      $keylayout = $controller->getKeylayout();
     $encodedKeylayout = Zend_Json::encode('[]');
     // settings data
     $settings = Voipmanager_Controller_Snom_Setting::getInstance()->search();
     $encodedSettings = Zend_Json::encode($settings->toArray());
     $view = new Zend_View();
     $view->setScriptPath('Tinebase/views');
     $view->title = "edit snom template data";
     $view->jsExecute = '
         Tine.Tinebase.registry.add("softwareVersions", ' . Voipmanager_Controller_Snom_Software::getInstance()->search()->toArray() . ' );
         Tine.Voipmanager.Snom.Templates.EditDialog.display(' . $encodedTemplate . ',' . $encodedSoftware . ',' . $encodedKeylayout . ',' . $encodedSettings . ');
     ';
     header('Content-Type: text/html; charset=utf-8');
     echo $view->render('jsclient.php');
 }