public function testCachedResults()
 {
     $this->_uit->setCache(Tinebase_Core::get('cache'));
     $this->testGetListOfTimezonesForOffsets();
     $this->testGetListOfTimezonesForPackedStrings();
     $this->_uit->setCache(null);
 }
コード例 #2
0
 public function printDocs()
 {
     // print payments which are debit returns and have flag print inquiry
     $resultData = array();
     $filters = array(array('field' => 'is_return_debit', 'operator' => 'equals', 'value' => '1'), array('field' => 'print_inquiry', 'operator' => 'equals', 'value' => '1'), array('field' => 'inquiry_print_date', 'operator' => 'isnull', 'value' => ''));
     $objFilter = new Billing_Model_PaymentFilter($filters, 'AND');
     $paymentIds = Billing_Controller_Payment::getInstance()->search($objFilter, null, null, true);
     foreach ($paymentIds as $paymentId) {
         $payment = Billing_Controller_Payment::getInstance()->get($paymentId);
         // get base payment
         $basePayment = $payment->getForeignRecordBreakNull('return_debit_base_payment_id', Billing_Controller_Payment::getInstance());
         if ($basePayment) {
             $batchJobDta = $basePayment->getForeignRecordBreakNull('batch_job_dta_id', Billing_Controller_BatchJobDta::getInstance());
             if ($batchJobDta) {
                 $bankAccount = Billing_Api_BankAccount::getFromBatchJobDta($batchJobDta);
                 $debitor = $payment->getForeignRecord('debitor_id', Billing_Controller_Debitor::getInstance());
                 $contact = $debitor->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance());
                 $data = array();
                 $dummyTextBlocks = null;
                 $data = array_merge($data, Addressbook_Custom_Template::getContactData(array('contact' => $contact, 'user' => Tinebase_Core::get(Tinebase_Core::USER), 'userContact' => Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::get(Tinebase_Core::USER)->getId())), $dummyTextBlocks));
                 $data = array_merge($data, array('bank_name' => $bankAccount->getBank(), 'account_name' => $bankAccount->getName(), 'account_nr' => $bankAccount->getNumber(), 'bank_code' => $bankAccount->getBankCode()));
                 $resultData[$contact->__get('n_fileas')] = $data;
                 $payment->__set('inquiry_print_date', new Zend_Date());
                 Billing_Controller_Payment::getInstance()->update($payment);
             }
         }
     }
     $outputFileName = 'Ruecklastschrift-Nachforschung-' . strftime('%d-%m-%Y %H-%M-%S') . '.pdf';
     $templateId = Tinebase_Core::getPreference('Billing')->getValue(Billing_Preference::TEMPLATE_DEBIT_RETURN_INQUIRY);
     ksort($resultData);
     Billing_Controller_PrintJobRecordData::getInstance()->export($resultData, $templateId, $outputFileName);
 }
コード例 #3
0
 /**
  * upload image
  *
  * @param  string  $base64
  */
 public function uploadImage($base64 = 'no')
 {
     $tmpFile = tempnam(Tinebase_Core::getTempDir(), '');
     $file = new Zend_Form_Element_File('file');
     $maxsize = $file->getMaxFileSize();
     $sessionId = Tinebase_Core::get(Tinebase_Session::SESSIONID);
     if (move_uploaded_file($_FILES['upload']['tmp_name'], $tmpFile)) {
         $image_id = str_replace(Tinebase_Core::getTempDir() . '/', '', $tmpFile);
         $image_size = filesize($tmpFile);
         if ($base64 === 'yes') {
             // converts image to base64
             try {
                 $image = file_get_contents($tmpFile);
                 $encoded_data = base64_encode($image);
                 echo '{"success":true , "id":"' . $image_id . '", "session_id":"' . $sessionId . '", "size":"' . $image_size . '", "path":"' . $tmpFile . '", "base64":"' . $encoded_data . '"}';
             } catch (Exception $e) {
                 echo '{"success":false, "error":' . $e . description . '}';
             }
         } else {
             echo '{"success":true , "id":"' . $image_id . '", "session_id":"' . $sessionId . '", "size":"' . $image_size . '", "path":"' . $tmpFile . '"}';
         }
     } else {
         echo '{"success":false, "method":"uploadImage", "maxsize":"' . $maxsize . '"}';
     }
 }
 /**
  * factory function to return a selected account/imap backend class
  *
  * @param   string|Expressomail_Model_Account $_accountId
  * @return  Expressomail_Backend_ImapProxy
  * @throws  Expressomail_Exception_IMAPInvalidCredentials
  */
 public static function factory($_accountId, $_readOnly = FALSE)
 {
     $accountId = $_accountId instanceof Expressomail_Model_Account ? $_accountId->getId() : $_accountId;
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Getting IMAP backend for account id ' . $accountId);
     }
     if (!isset(self::$_backends[$accountId])) {
         // get imap config from account
         $account = $_accountId instanceof Expressomail_Model_Account ? $_accountId : Expressomail_Controller_Account::getInstance()->get($_accountId);
         $imapConfig = $account->getImapConfig();
         // we need to instantiate a new imap backend
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Connecting to server ' . $imapConfig['host'] . ':' . $imapConfig['port'] . ' (' . (array_key_exists('ssl', $imapConfig) ? $imapConfig['ssl'] : 'none') . ')' . ' with username ' . $imapConfig['user']);
         }
         try {
             self::$_backends[$accountId] = new Expressomail_Backend_ImapProxy($imapConfig, $_readOnly);
             if (Tinebase_Core::get(Tinebase_Core::SERVER_CLASS_NAME) !== 'ActiveSync_Server_Http') {
                 Expressomail_Controller_Account::getInstance()->updateCapabilities($account, self::$_backends[$accountId]);
             }
         } catch (Expressomail_Exception_IMAPInvalidCredentials $feiic) {
             // add account and username to Expressomail_Exception_IMAPInvalidCredentials
             $feiic->setAccount($account)->setUsername($imapConfig['user']);
             throw $feiic;
         }
     }
     return self::$_backends[$accountId];
 }
コード例 #5
0
 /**
  *
  * @return type
  */
 public function getFilterImap()
 {
     $format = "d-M-Y";
     // prepare value
     $value = (array) $this->_getDateValues($this->_operator, $this->_value);
     $timezone = Tinebase_Helper::array_value('timezone', $this->_options);
     $timezone = $timezone ? $timezone : Tinebase_Core::get('userTimeZone');
     foreach ($value as &$date) {
         $date = new Tinebase_DateTime($date);
         // should be in user timezone
         $date->setTimezone(new DateTimeZone($timezone));
     }
     switch ($this->_operator) {
         case 'within':
         case 'inweek':
             $value[1]->add(new DateInterval('P1D'));
             // before is not inclusive, so we have to add a day
             $return = "SINCE {$value[0]->format($format)} BEFORE {$value[1]->format($format)}";
             break;
         case 'before':
             $return = "BEFORE {$value[0]->format($format)}";
             break;
         case 'after':
             $return = "SINCE {$value[0]->format($format)}";
             break;
         case 'equals':
             $return = "ON {$value[0]->format($format)}";
     }
     return $return;
 }
コード例 #6
0
 /**
  * return all groups an account is member of
  * - this function caches its result (with cache tag 'ldap')
  *
  * @param mixed $_accountId the account as integer or Tinebase_Model_User
  * @return array
  */
 public function getGroupMemberships($_accountId)
 {
     $cache = Tinebase_Core::get(Tinebase_Core::CACHE);
     $cacheId = convertCacheId('getLdapGroupMemberships' . ($_accountId instanceof Tinebase_Model_FullUser ? $_accountId->getId() : $_accountId));
     $result = $cache->load($cacheId);
     if (!$result) {
         if ($_accountId instanceof Tinebase_Model_FullUser) {
             $memberuid = $_accountId->accountLoginName;
         } else {
             $account = Tinebase_User::getInstance()->getFullUserById($_accountId);
             $memberuid = $account->accountLoginName;
         }
         $filter = "(&(objectclass=user)(sAMAccountName={$memberuid}))";
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' search filter: ' . $filter);
         }
         $groupMemberships = $this->_ldap->fetchAll($this->_options['userDn'], $filter, array('memberOf'));
         $memberships = array();
         foreach ($groupMemberships as $groupMembership) {
             $group = $this->_ldap->fetch($groupMembership['memberOf'][0], 'objectClass=group', array('objectGUID'));
             $memberships[] = $group['objectGUID'][0];
         }
         $result = $memberships;
         $cache->save($result, $cacheId, array('ldap'), 240);
     }
     return $result;
 }
コード例 #7
0
ファイル: Task.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * add one record
  *
  * @param   Tinebase_Record_Interface $_record
  * @return  Tinebase_Record_Interface
  * @throws  Tinebase_Exception_AccessDenied
  * @throws  Tinebase_Exception_Record_Validation
  */
 public function create(Tinebase_Record_Interface $_task)
 {
     $this->_handleCompleted($_task);
     $_task->originator_tz = $_task->originator_tz ? $_task->originator_tz : Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
     $task = parent::create($_task);
     $this->_addAutomaticAlarms($task);
     return $task;
 }
コード例 #8
0
ファイル: Json.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * Search for calls matching given arguments
  *
  * @param  array $filter
  * @param  array $paging
  * @return array
  */
 public function searchCalls($filter, $paging)
 {
     $filter = new Phone_Model_CallFilter($filter);
     $pagination = new Tinebase_Model_Pagination($paging);
     $calls = Phone_Controller::getInstance()->searchCalls($filter, $pagination);
     // set timezone
     $calls->setTimezone(Tinebase_Core::get('userTimeZone'));
     return array('results' => $calls->toArray(), 'totalcount' => Phone_Controller::getInstance()->searchCallsCount($filter));
 }
 /**
  * set new password & credentials
  * 
  * @param string $_username
  * @param string $_password
  */
 protected function _setCredentials($_username, $_password)
 {
     Tinebase_User::getInstance()->setPassword(Tinebase_Core::getUser(), $_password, true, false);
     $oldCredentialCache = Tinebase_Core::get(Tinebase_Core::USERCREDENTIALCACHE);
     // update credential cache
     $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($_username, $_password);
     Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache);
     $event = new Tinebase_Event_User_ChangeCredentialCache($oldCredentialCache);
     Tinebase_Event::fireEvent($event);
 }
コード例 #10
0
 public function setUp()
 {
     // invalidate all caches
     $cache = Tinebase_Core::get(Tinebase_Core::CACHE);
     if (!$cache || !$cache->getOption('caching')) {
         return;
     }
     $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     Tinebase_Core::getDb()->query("RESET QUERY CACHE;");
     $this->_json = new Calendar_Frontend_Json();
 }
コード例 #11
0
 /**
  * converts Tinebase_Record_RecordSet to external format
  * 
  * @param  Tinebase_Record_RecordSet  $_records
  * @param  array $_resolveUserFields
  * @return mixed
  */
 public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records, $_resolveUserFields = array())
 {
     if (count($_records) == 0) {
         return array();
     }
     Tinebase_Frontend_Json_Abstract::resolveContainerTagsUsers($_records, $_resolveUserFields);
     $_records->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
     $_records->convertDates = true;
     $result = $_records->toArray();
     return $result;
 }
コード例 #12
0
 /**
  * testTimezoneConversion
  */
 public function testTimezoneConversion()
 {
     $exampleFilterData = self::getPersistentFilterData();
     $savedFilterData = $this->testSaveFilter($exampleFilterData);
     $testUserTimezone = Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
     Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, $testUserTimezone !== 'US/Pacific' ? 'US/Pacific' : 'UTC');
     $originalDueDateFilter = $this->_getFilter('due', $exampleFilterData);
     $convertedDueDataFilter = $this->_getFilter('due', $this->_uit->getPersistentFilter($savedFilterData['id']));
     Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, $testUserTimezone);
     $this->assertNotEquals($originalDueDateFilter['value'], $convertedDueDataFilter['value']);
 }
コード例 #13
0
 /**
  * @TODO: egw can have groups as owner 
  * -> map this to shared folder
  * -> find appropriate creator / current_user for this
  * -> support maps for group => creator and owner => folder?
  */
 protected function _migrateEgwRecordPage($recordPage)
 {
     foreach ($recordPage as $egwContactData) {
         try {
             $this->_importResult['totalcount']++;
             $currentUser = Tinebase_Core::get(Tinebase_Core::USER);
             $owner = $egwContactData['contact_owner'] ? Tinebase_User::getInstance()->getFullUserById($this->mapAccountIdEgw2Tine($egwContactData['contact_owner'])) : $currentUser;
             Tinebase_Core::set(Tinebase_Core::USER, $owner);
             $contactData = array_merge($egwContactData, array('id' => $egwContactData['contact_id'], 'creation_time' => $this->convertDate($egwContactData['contact_created']), 'created_by' => $this->mapAccountIdEgw2Tine($egwContactData['contact_creator'], FALSE), 'last_modified_time' => $egwContactData['contact_modified'] ? $this->convertDate($egwContactData['contact_modified']) : NULL, 'last_modified_by' => $egwContactData['contact_modifier'] ? $this->mapAccountIdEgw2Tine($contact['contact_modifier'], FALSE) : NULL));
             $contactData['created_by'] = $contactData['created_by'] ?: $owner;
             $contactData['$egwContactData'] = $contactData['last_modified_time'] && !$contactData['last_modified_by'] ?: $owner;
             // fix mandentory fields
             if (!($egwContactData['org_name'] || $egwContactData['n_family'])) {
                 $contactData['org_name'] = 'N/A';
             }
             // add 'http://' if missing
             foreach (array('contact_url', 'contact_url_home') as $urlProperty) {
                 if (!preg_match("/^http/i", $egwContactData[$urlProperty]) && !empty($egwContactData[$urlProperty])) {
                     $contactData[$urlProperty] = "http://" . $egwContactData[$urlProperty];
                 }
             }
             // normalize countynames
             $contactData['adr_one_countryname'] = $this->convertCountryname2Iso($egwContactData['adr_one_countryname']);
             $contactData['adr_two_countryname'] = $this->convertCountryname2Iso($egwContactData['adr_two_countryname']);
             // handle bday
             if ((isset($egwContactData['contact_bday']) || array_key_exists('contact_bday', $egwContactData)) && $egwContactData['contact_bday']) {
                 // @TODO evaluate contact_tz
                 $contactData['bday'] = new Tinebase_DateTime($egwContactData['contact_bday'], $this->_config->birthdayDefaultTimezone);
             } else {
                 if ((isset($egwContactData['bday']) || array_key_exists('bday', $egwContactData)) && $egwContactData['bday']) {
                     // egw <= 1.4
                     $contactData['bday'] = $this->convertDate($egwContactData['bday']);
                 }
             }
             // handle tags
             $contactData['tags'] = $this->convertCategories($egwContactData['cat_id']);
             // @TODO handle photo
             // handle container
             if ($egwContactData['contact_owner'] && !$egwContactData['account_id']) {
                 $contactData['container_id'] = $egwContactData['contact_private'] && $this->_config->setPersonalContainerGrants ? $this->getPrivateContainer($this->mapAccountIdEgw2Tine($egwContactData['contact_owner']))->getId() : $this->getPersonalContainer($this->mapAccountIdEgw2Tine($egwContactData['contact_owner']))->getId();
             }
             // finally create the record
             $tineContact = new Addressbook_Model_Contact($contactData);
             $this->saveTineRecord($tineContact);
         } catch (Exception $e) {
             $this->_importResult['failcount']++;
             Tinebase_Core::set(Tinebase_Core::USER, $currentUser);
             $this->_log->ERR(__METHOD__ . '::' . __LINE__ . ' could not migrate contact "' . $egwContactData['contact_id'] . '" cause: ' . $e->getMessage());
             $this->_log->DEBUG(__METHOD__ . '::' . __LINE__ . ' ' . $e);
         }
     }
 }
コード例 #14
0
 public function testUpdateEvent()
 {
     $persistentEvent = $this->testCreateEvent();
     $currentTz = Tinebase_Core::get(Tinebase_Core::USERTIMEZONE);
     Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, 'farfaraway');
     $persistentEvent->summary = 'Lunchtime';
     $updatedEvent = $this->_controller->update($persistentEvent);
     $this->assertEquals($persistentEvent->summary, $updatedEvent->summary);
     $this->assertEquals($currentTz, $updatedEvent->originator_tz, 'originator_tz must not be touchet if dtsart is not updatet!');
     $updatedEvent->dtstart->addHour(1);
     $updatedEvent->dtend->addHour(1);
     $secondUpdatedEvent = $this->_controller->update($updatedEvent);
     $this->assertEquals(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE), $secondUpdatedEvent->originator_tz, 'originator_tz must be adopted if dtsart is updatet!');
     Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, $currentTz);
 }
コード例 #15
0
 /**
  * check available queues
  * 
  * @return array of queueNames
  */
 public function getQueues()
 {
     $cache = Tinebase_Core::get(Tinebase_Core::CACHE);
     $cacheId = 'RequestTrackerGetQueues' . Tinebase_Core::getUser()->getId();
     $availableQueues = $cache->load($cacheId);
     if (!$availableQueues) {
         $availableQueues = array();
         foreach ($this->_config->rest->queues as $queueName) {
             if ($this->_checkQueue($queueName)) {
                 $availableQueues[] = $queueName;
             }
         }
         $cache->save($availableQueues, $cacheId, array('rt'));
     }
     return $availableQueues;
 }
コード例 #16
0
 /**
  * handler for command line scripts
  * 
  * @return boolean
  */
 public function handle()
 {
     $opts = Tinebase_Core::get('opts');
     if (!in_array($opts->method, array('Tinebase.monitoringCheckDB', 'Tinebase.monitoringCheckConfig'))) {
         $this->_initFramework();
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Is cli request. method: ' . (isset($opts->method) ? $opts->method : 'EMPTY'));
         }
     }
     $tinebaseServer = new Tinebase_Frontend_Cli();
     if (!in_array($opts->method, array('Tinebase.triggerAsyncEvents', 'Tinebase.processQueue', 'Tinebase.monitoringCheckDB', 'Tinebase.monitoringCheckConfig', 'Tinebase.monitoringCheckCron', 'Tinebase.monitoringLoginNumber'))) {
         $tinebaseServer->authenticate($opts->username, $opts->password);
     }
     $result = $tinebaseServer->handle($opts);
     //@todo remove cli session path
     return $result;
 }
コード例 #17
0
 /**
  * calculates the date filter values
  *
  * @param string $_operator
  * @param string $_value
  * @param string $_dateFormat
  * @return array|string date value
  */
 protected function _getDateValues($_operator, $_value)
 {
     if ($_operator === 'within' || $_operator === 'inweek') {
         // get beginning / end date and add 00:00:00 / 23:59:59
         date_default_timezone_set(array_key_exists('timezone', $this->_options) && !empty($this->_options['timezone']) ? $this->_options['timezone'] : Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
         $value = parent::_getDateValues($_operator, $_value);
         $value[0] .= ' 00:00:00';
         $value[1] .= ' 23:59:59';
         date_default_timezone_set('UTC');
         // convert to utc
         $value[0] = $this->_convertStringToUTC($value[0]);
         $value[1] = $this->_convertStringToUTC($value[1]);
     } else {
         $value = $_value instanceof DateTime ? $_value->toString(Tinebase_Record_Abstract::ISO8601LONG) : $_value;
     }
     return $value;
 }
コード例 #18
0
 /**
  * get sieve vacation object
  * 
  * @return Expressomail_Sieve_Vacation
  */
 public function getFSV()
 {
     $fsv = new Expressomail_Sieve_Vacation();
     $fsv->setEnabled($this->enabled)->setDays(is_int($this->days) && $this->days > 0 ? $this->days : 7)->setSubject($this->subject)->setFrom($this->from)->setMime($this->mime)->setReason($this->reason)->setDateEnabled($this->date_enabled);
     $this->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
     if ($this->start_date instanceof Tinebase_DateTime) {
         $fsv->setStartdate($this->start_date->format('Y-m-d'));
     }
     if ($this->end_date instanceof Tinebase_DateTime) {
         $fsv->setEnddate($this->end_date->format('Y-m-d'));
     }
     $this->setTimezone('UTC');
     if (is_array($this->addresses)) {
         foreach ($this->addresses as $address) {
             $fsv->addAddress($address);
         }
     }
     return $fsv;
 }
コード例 #19
0
 /**
  * create lead pdf
  *
  * @param    Crm_Model_Lead $_lead lead data
  * 
  * @return    string    the pdf
  */
 public function generate(Crm_Model_Lead $_lead, $_pageNumber = 0)
 {
     $locale = Tinebase_Core::get('locale');
     $translate = Tinebase_Translation::getTranslation('Crm');
     // set user timezone
     $_lead->setTimezone(Tinebase_Core::getUserTimezone());
     /*********************** build data array ***************************/
     $record = $this->getRecord($_lead, $locale, $translate);
     /******************* build title / subtitle / description ***********/
     $title = $_lead->lead_name;
     $subtitle = "";
     $description = $_lead->description;
     $titleIcon = "/images/oxygen/32x32/actions/datashowchart.png";
     /*********************** add linked objects *************************/
     $linkedObjects = $this->getLinkedObjects($_lead, $locale, $translate);
     $tags = $_lead->tags instanceof Tinebase_Record_RecordSet ? $_lead->tags->toArray() : array();
     /***************************** generate pdf now! ********************/
     parent::generatePdf($record, $title, $subtitle, $tags, $description, $titleIcon, NULL, $linkedObjects, FALSE);
 }
コード例 #20
0
 /**
  * (non-PHPdoc)
  * @see Tinebase_Server_Interface::handle()
  */
 public function handle(\Zend\Http\Request $request = null, $body = null)
 {
     $this->_request = $request instanceof \Zend\Http\Request ? $request : Tinebase_Core::get(Tinebase_Core::REQUEST);
     $this->_body = $body !== null ? $body : fopen('php://input', 'r');
     Tinebase_Core::initFramework();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' is Asterisk curl request: ' . print_r($_REQUEST, true));
     }
     if (Tinebase_Controller::getInstance()->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $this->_request, self::REQUEST_TYPE) === true) {
         $server = new Tinebase_Http_Server();
         $server->setClass('Voipmanager_Frontend_Asterisk_SipPeers', 'Voipmanager_SipPeers');
         $server->setClass('Voipmanager_Frontend_Asterisk_SipRegs', 'Voipmanager_SipRegs');
         $server->setClass('Voipmanager_Frontend_Asterisk_CallForward', 'Voipmanager_CallForward');
         $server->setClass('Voipmanager_Frontend_Asterisk_MeetMe', 'Voipmanager_MeetMe');
         $_REQUEST['method'] = $this->getRequestMethod();
         $server->handle($_REQUEST);
         Tinebase_Controller::getInstance()->logout($_SERVER['REMOTE_ADDR']);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' auth failed ');
         }
     }
 }
コード例 #21
0
 /**
  * generic check admin rights function
  * rules: 
  * - ADMIN right includes all other rights
  * - MANAGE_* right includes VIEW_* right 
  * - results are cached if caching is active (with cache tag 'rights')
  * 
  * @param   string  $_right to check
  * @param   boolean $_throwException [optional]
  * @param   boolean $_includeTinebaseAdmin [optional]
  * @return  boolean
  * @throws  Tinebase_Exception_UnexpectedValue
  * @throws  Tinebase_Exception_AccessDenied
  * 
  * @todo move that to *_Acl_Rights
  */
 public function checkRight($_right, $_throwException = TRUE, $_includeTinebaseAdmin = TRUE)
 {
     if (empty($this->_applicationName)) {
         throw new Tinebase_Exception_UnexpectedValue('No application name defined!');
     }
     $right = strtoupper($_right);
     $cache = Tinebase_Core::get(Tinebase_Core::CACHE);
     $cacheId = convertCacheId('checkRight' . Tinebase_Core::getUser()->getId() . $_right . $this->_applicationName);
     $result = $cache->load($cacheId);
     if (!$result) {
         $applicationRightsClass = $this->_applicationName . '_Acl_Rights';
         // array with the rights that should be checked, ADMIN is in it per default
         $rightsToCheck = $_includeTinebaseAdmin ? array(Tinebase_Acl_Rights::ADMIN) : array();
         if (preg_match("/MANAGE_/", $right)) {
             $rightsToCheck[] = constant($applicationRightsClass . '::' . $right);
         }
         if (preg_match("/VIEW_([A-Z_]*)/", $right, $matches)) {
             $rightsToCheck[] = constant($applicationRightsClass . '::' . $right);
             // manage right includes view right
             $rightsToCheck[] = constant($applicationRightsClass . '::MANAGE_' . $matches[1]);
         }
         $result = FALSE;
         foreach ($rightsToCheck as $rightToCheck) {
             //echo "check right: " . $rightToCheck;
             if (Tinebase_Acl_Roles::getInstance()->hasRight($this->_applicationName, Tinebase_Core::getUser()->getId(), $rightToCheck)) {
                 $result = TRUE;
                 break;
             }
         }
         $cache->save($result, $cacheId, array('rights'), 120);
     }
     if (!$result && $_throwException) {
         throw new Tinebase_Exception_AccessDenied("You are not allowed to {$right} in application {$this->_applicationName} !");
     }
     return $result;
 }
コード例 #22
0
 /**
  * (non-PHPdoc)
  * @see Tinebase_Server_Interface::handle()
  */
 public function handle(\Zend\Http\Request $request = null, $body = null)
 {
     $this->_request = $request instanceof \Zend\Http\Request ? $request : Tinebase_Core::get(Tinebase_Core::REQUEST);
     $this->_body = $this->_getBody($body);
     try {
         list($loginName, $password) = $this->_getAuthData($this->_request);
     } catch (Tinebase_Exception_NotFound $tenf) {
         header('WWW-Authenticate: Basic realm="ActiveSync for Tine 2.0"');
         header('HTTP/1.1 401 Unauthorized');
         return;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' is ActiveSync request.');
     }
     Tinebase_Core::initFramework();
     try {
         $authResult = $this->_authenticate($loginName, $password, $this->_request);
     } catch (Exception $e) {
         Tinebase_Exception::log($e);
         $authResult = false;
     }
     if ($authResult !== true) {
         header('WWW-Authenticate: Basic realm="ActiveSync for Tine 2.0"');
         header('HTTP/1.1 401 Unauthorized');
         return;
     }
     if (!$this->_checkUserPermissions($loginName)) {
         return;
     }
     $this->_initializeRegistry();
     $request = new Zend_Controller_Request_Http();
     $request->setRequestUri($this->_request->getRequestUri());
     $syncFrontend = new Syncroton_Server(Tinebase_Core::getUser()->accountId, $request, $this->_body);
     $syncFrontend->handle();
     Tinebase_Controller::getInstance()->logout();
 }
コード例 #23
0
 /**
  * update user profile
  *
  * @param  array $profileData
  * @return array
  */
 public function updateUserProfile($profileData)
 {
     $contact = new Addressbook_Model_Contact(array(), TRUE);
     $contact->setFromJsonInUsersTimezone($profileData);
     // NOTE: $userProfile is a contact where non readable fields are clearad out!
     $userProfile = Tinebase_UserProfile::getInstance()->update($contact);
     // NOTE: This hurts! We don't have methods to call in our frontends yet which convert
     //       a record to the json representaion :( Thus image link will be broken!
     $userProfile->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
     return $userProfile->toArray();
 }
コード例 #24
0
 /**
  * authenticate user but don't log in
  *
  * @param   string $loginName
  * @param   string $password
  * @param   array  $remoteInfo
  * @param   string $clientIdString
  * @return  bool
  */
 public function authenticate($loginName, $password, $remoteInfo, $clientIdString = NULL)
 {
     $result = $this->login($loginName, $password, Tinebase_Core::get(Tinebase_Core::REQUEST), $clientIdString);
     /**
      * we unset the Zend_Auth session variable. This way we keep the session,
      * but the user is not logged into Tine 2.0
      * we use this to validate passwords for OpenId for example
      */
     $coreSession = Tinebase_Session::getSessionNamespace();
     unset($coreSession->Zend_Auth);
     unset($coreSession->currentAccount);
     return $result;
 }
コード例 #25
0
 /**
  * get user registry
  * 
  * @return array
  */
 protected function _getUserRegistryData()
 {
     $user = Tinebase_Core::getUser();
     $userContactArray = array();
     if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
         try {
             $userContactArray = Addressbook_Controller_Contact::getInstance()->getContactByUserId($user->getId(), TRUE)->toArray();
         } catch (Addressbook_Exception_NotFound $aenf) {
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 /** @noinspection PhpUndefinedMethodInspection */
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' User not found in Addressbook: ' . $user->accountDisplayName);
             }
         }
     }
     try {
         $persistentFilters = Tinebase_Frontend_Json_PersistentFilter::getAllPersistentFilters();
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Failed to fetch persistent filters. Exception: \n" . $tenf);
         }
         $persistentFilters = array();
     } catch (Exception $e) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Failed to fetch persistent filters. Exception: \n" . $e);
         }
         $persistentFilters = array();
     }
     $userRegistryData = array('timeZone' => Tinebase_Core::getUserTimezone(), 'currentAccount' => $user->toArray(), 'userContact' => $userContactArray, 'accountBackend' => Tinebase_User::getConfiguredBackend(), 'jsonKey' => Tinebase_Core::get('jsonKey'), 'userApplications' => $user->getApplications()->toArray(), 'NoteTypes' => $this->getNoteTypes(), 'stateInfo' => Tinebase_State::getInstance()->loadStateInfo(), 'mustchangepw' => $user->mustChangePassword(), 'confirmLogout' => Tinebase_Core::getPreference()->getValue(Tinebase_Preference::CONFIRM_LOGOUT, 1), 'advancedSearch' => Tinebase_Core::getPreference()->getValue(Tinebase_Preference::ADVANCED_SEARCH, 0), 'persistentFilters' => $persistentFilters, 'userAccountChanged' => Tinebase_Controller::getInstance()->userAccountChanged());
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' User registry: ' . print_r($userRegistryData, TRUE));
     }
     return $userRegistryData;
 }
コード例 #26
0
 /**
  * Send the reading confirmation in a message who has the correct header and is not seen yet
  *
  * @return void
  */
 public function sendReadingConfirmation()
 {
     if (!is_array($this->headers)) {
         $this->headers = Expressomail_Controller_Message::getInstance()->getMessageHeaders($this->getId(), NULL, TRUE);
     }
     if (array_key_exists('disposition-notification-to', $this->headers) && $this->headers['disposition-notification-to'] && !$this->hasSeenFlag() && !$this->hasReadFlag() && !$this->hasDraftFlag()) {
         $translate = Tinebase_Translation::getTranslation($this->_application);
         $from = Expressomail_Controller_Account::getInstance()->get($this->account_id);
         $arrRet = array();
         preg_match(Tinebase_Mail::EMAIL_ADDRESS_REGEXP, $this->headers['disposition-notification-to'], $arrRet);
         $to = $arrRet[0];
         if ($from->email === $to) {
             return;
         }
         // calculate timezone in "GMT-HH:MM" format
         $dtz = new DateTimeZone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
         $time = new DateTime('now', $dtz);
         $offset = $dtz->getOffset($time);
         $sign = $offset < 0 ? "-" : "+";
         $offset = abs($offset);
         $hours = floor($offset / 3600);
         $hours = $hours < 10 ? '0' . $hours : $hours;
         $minutes = offset % 60;
         $minutes = $minutes < 10 ? '0' . $minutes : $minutes;
         $gmt = '(GMT' . $sign . $hours . ":" . $minutes . ')';
         $subject = $translate->_('Reading Confirmation:') . ' ' . $this->subject;
         $readTime = date('Y-m-d H:i:s');
         $tzReadTime = Tinebase_Translation::dateToStringInTzAndLocaleFormat(Expressomail_Message::convertDate($readTime));
         $tzReceived = Tinebase_Translation::dateToStringInTzAndLocaleFormat(Expressomail_Message::convertDate($this->received));
         $messageBody = $translate->_('Your message:') . ' ' . $this->subject . "\n" . $translate->_('Received on') . ' ' . $tzReceived . ' ' . $gmt . "\n" . $translate->_('Was read by:') . ' ' . $from->from . ' <' . $from->email . '> ' . $translate->_('on') . ' ' . $tzReadTime . ' ' . $gmt;
         //$messageBody         = Expressomail_Message::convertFromTextToHTML($messageBody);
         $readconf = array('to' => $to, 'subject' => $this->subject, 'received' => $this->received, 'from_name' => $from->from, 'from_email' => $from->email, 'read_time' => $readTime);
         $mailPart = new Zend_Mime_Part(serialize($readconf));
         $mailPart->charset = 'UTF-8';
         $mailPart->type = 'text/readconf;';
         $mailPart->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE;
         $contact = new Addressbook_Model_Contact(array('email' => $to, 'n_fn' => $from->from), true);
         $result = Tinebase_Notification::getInstance()->send(Tinebase_Core::getUser(), array($contact), $subject, $messageBody, $mailPart, NULL);
         Expressomail_Controller_Message_Flags::getInstance()->addFlags($this->getId(), (array) 'Read');
     }
 }
コード例 #27
0
 public function getConfigSettings($_resolve = FALSE)
 {
     $cache = Tinebase_Core::get('cache');
     $cacheId = convertCacheId('getCrmSettings');
     $result = $cache->load($cacheId);
     if (!$result) {
         $translate = Tinebase_Translation::getTranslation('Crm');
         $result = new Crm_Model_Config(array('defaults' => parent::getConfigSettings()));
         $others = array(Crm_Model_Config::LEADTYPES => array(array('id' => 1, 'leadtype' => $translate->_('Customer')), array('id' => 2, 'leadtype' => $translate->_('Partner')), array('id' => 3, 'leadtype' => $translate->_('Reseller'))), Crm_Model_Config::LEADSTATES => array(array('id' => 1, 'leadstate' => $translate->_('open'), 'probability' => 0, 'endslead' => 0), array('id' => 2, 'leadstate' => $translate->_('contacted'), 'probability' => 10, 'endslead' => 0), array('id' => 3, 'leadstate' => $translate->_('waiting for feedback'), 'probability' => 30, 'endslead' => 0), array('id' => 4, 'leadstate' => $translate->_('quote sent'), 'probability' => 50, 'endslead' => 0), array('id' => 5, 'leadstate' => $translate->_('accepted'), 'probability' => 100, 'endslead' => 1), array('id' => 6, 'leadstate' => $translate->_('lost'), 'probability' => 0, 'endslead' => 1)), Crm_Model_Config::LEADSOURCES => array(array('id' => 1, 'leadsource' => $translate->_('Market')), array('id' => 2, 'leadsource' => $translate->_('Email')), array('id' => 3, 'leadsource' => $translate->_('Telephone')), array('id' => 4, 'leadsource' => $translate->_('Website'))));
         foreach ($others as $setting => $defaults) {
             $result->{$setting} = Tinebase_Config::getInstance()->getConfigAsArray($setting, $this->_applicationName, $defaults);
         }
         // save result and tag it with 'settings'
         $cache->save($result, $cacheId, array('settings'));
     }
     return $result;
 }
コード例 #28
0
 /**
  * check if js or css files have changed and return all js/css as one big file or return "HTTP/1.0 304 Not Modified" if files don't have changed
  * 
  * @param string $_fileType
  * @param array $filesToWatch
  */
 protected function _deliverChangedFiles($_fileType, $filesToWatch = null)
 {
     // close session to allow other requests
     Tinebase_Session::writeClose(true);
     $config = Tinebase_Config::getInstance();
     $cacheId = null;
     $clientETag = null;
     $ifModifiedSince = null;
     if (isset($_SERVER['If_None_Match'])) {
         $clientETag = trim($_SERVER['If_None_Match'], '"');
         $ifModifiedSince = trim($_SERVER['If_Modified_Since'], '"');
     } elseif (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
         $clientETag = trim($_SERVER['HTTP_IF_NONE_MATCH'], '"');
         $ifModifiedSince = trim($_SERVER['HTTP_IF_MODIFIED_SINCE'], '"');
     }
     $filesToWatch = $filesToWatch ? $filesToWatch : $this->_getFilesToWatch($_fileType);
     if ($_fileType == 'js' && TINE20_BUILDTYPE != 'DEVELOPMENT') {
         $customJSFiles = Tinebase_Config::getInstance()->get(Tinebase_Config::FAT_CLIENT_CUSTOM_JS);
         if (!empty($customJSFiles)) {
             $filesToWatch = array_merge($filesToWatch, (array) $customJSFiles);
         }
     }
     $lastModified = $this->_getLastModified($filesToWatch);
     // use last modified time also
     $serverETag = hash('sha1', implode('', $filesToWatch) . $lastModified);
     $cache = new Zend_Cache_Frontend_File(array('master_files' => $filesToWatch));
     $cache->setBackend(Tinebase_Core::get(Tinebase_Core::CACHE)->getBackend());
     if ($clientETag && $ifModifiedSince) {
         $cacheId = __CLASS__ . "_" . __FUNCTION__ . hash('sha1', $clientETag . $ifModifiedSince);
     }
     // cache for 60 seconds
     $maxAge = 60;
     header('Cache-Control: private, max-age=' . $maxAge);
     header("Expires: " . gmdate('D, d M Y H:i:s', Tinebase_DateTime::now()->addSecond($maxAge)->getTimestamp()) . " GMT");
     // overwrite Pragma header from session
     header("Pragma: cache");
     // if the cache id is still valid, the files don't have changed on disk
     if ($clientETag == $serverETag && $cache->test($cacheId)) {
         header("Last-Modified: " . $ifModifiedSince);
         header("HTTP/1.0 304 Not Modified");
         header('Content-Length: 0');
     } else {
         // get new cacheId
         $cacheId = __CLASS__ . "_" . __FUNCTION__ . hash('sha1', $serverETag . $lastModified);
         // do we need to update the cache? maybe the client did not send an etag
         if (!$cache->test($cacheId)) {
             $cache->save(TINE20_BUILDTYPE, $cacheId, array(), null);
         }
         header("Last-Modified: " . $lastModified);
         header('Content-Type: ' . ($_fileType == 'css' ? 'text/css' : 'application/javascript'));
         header('Etag: "' . $serverETag . '"');
         flush();
         // send files to client
         foreach ($filesToWatch as $file) {
             readfile($file);
         }
     }
 }
コード例 #29
0
 /**
  * get formatted gmt date and time
  *
  * @return String
  */
 private function getFormattedGmtDateTime()
 {
     // calculate timezone in "GMT-HH:MM" format
     $dtz = new DateTimeZone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
     $time = new DateTime('now', $dtz);
     $offset = $dtz->getOffset($time);
     $sign = $offset < 0 ? "-" : "+";
     $offset = abs($offset);
     $hours = floor($offset / 3600);
     $hours = $hours < 10 ? '0' . $hours : $hours;
     $minutes = offset % 60;
     $minutes = $minutes < 10 ? '0' . $minutes : $minutes;
     $gmt = '(GMT' . $sign . $hours . ":" . $minutes . ')';
     $dateTime = date('Y-m-d H:i:s');
     $formattedDateTime = Tinebase_Translation::dateToStringInTzAndLocaleFormat(Expressomail_Message::convertDate($dateTime));
     return $formattedDateTime . ' ' . $gmt;
 }
コード例 #30
0
 /**
  * test record translation
  */
 public function testTranslate()
 {
     $oldLocale = Tinebase_Core::get(Tinebase_Core::LOCALE);
     Tinebase_Core::set(Tinebase_Core::LOCALE, new Zend_Locale('de'));
     $record = new Tinebase_Record_DummyRecord(array('string' => 'test', 'leadstate' => 'waiting for feedback'), true);
     $record->translate();
     $this->assertEquals('Wartet auf Feedback', $record->leadstate);
     Tinebase_Core::set(Tinebase_Core::LOCALE, $oldLocale);
 }