Esempio n. 1
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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 /**
  * Returns the column descriptions for a table.
  *
  * The return value is an associative array keyed by the column name,
  * as returned by the RDBMS.
  *
  * The value of each array element is an associative array
  * with the following keys:
  *
  * SCHEMA_NAME      => string; name of schema
  * TABLE_NAME       => string;
  * COLUMN_NAME      => string; column name
  * COLUMN_POSITION  => number; ordinal position of column in table
  * DATA_TYPE        => string; SQL datatype name of column
  * DEFAULT          => string; default expression of column, null if none
  * NULLABLE         => boolean; true if column can have nulls
  * LENGTH           => number; length of CHAR/VARCHAR
  * SCALE            => number; scale of NUMERIC/DECIMAL
  * PRECISION        => number; precision of NUMERIC/DECIMAL
  * UNSIGNED         => boolean; unsigned property of an integer type
  * PRIMARY          => boolean; true if column is part of the primary key
  * PRIMARY_POSITION => integer; position of column in primary key
  * IDENTITY         => integer; true if column is auto-generated with unique values
  *
  * @todo Discover integer unsigned property.
  *
  * @param string $tableName
  * @param string $schemaName OPTIONAL
  * @return array
  */
 public function describeTable($tableName, $schemaName = null)
 {
     // MOD FILIP cache mod
     $cache = Tinebase_Core::get('cache');
     $cacheId = convertCacheId('describeTable' . $tableName);
     $desc = $cache->load($cacheId);
     if (!$desc) {
         $desc = array();
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' CacheTable ' . $tableName);
         $version = $this->getServerVersion();
         if ($version === null || version_compare($version, '9.0.0', '>=')) {
             $sql = "SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,\n\t                    TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH,\n\t                    TC.DATA_SCALE, TC.DATA_PRECISION, C.CONSTRAINT_TYPE, CC.POSITION, TC.CHAR_LENGTH\n\t                FROM ALL_TAB_COLUMNS TC\n\t                LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C\n\t                    ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND C.CONSTRAINT_TYPE = 'P'))\n\t                  ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME\n\t                WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)";
             $bind[':TBNAME'] = $tableName;
             if ($schemaName) {
                 $sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
                 $bind[':SCNAME'] = $schemaName;
             }
             $sql .= ' ORDER BY TC.COLUMN_ID';
         } else {
             $subSql = "SELECT AC.OWNER, AC.TABLE_NAME, ACC.COLUMN_NAME, AC.CONSTRAINT_TYPE, ACC.POSITION\n\t                from ALL_CONSTRAINTS AC, ALL_CONS_COLUMNS ACC\n\t                  WHERE ACC.CONSTRAINT_NAME = AC.CONSTRAINT_NAME\n\t                    AND ACC.TABLE_NAME = AC.TABLE_NAME\n\t                    AND ACC.OWNER = AC.OWNER\n\t                    AND AC.CONSTRAINT_TYPE = 'P'\n\t                    AND UPPER(AC.TABLE_NAME) = UPPER(:TBNAME)";
             $bind[':TBNAME'] = $tableName;
             if ($schemaName) {
                 $subSql .= ' AND UPPER(ACC.OWNER) = UPPER(:SCNAME)';
                 $bind[':SCNAME'] = $schemaName;
             }
             $sql = "SELECT TC.TABLE_NAME, TC.OWNER, TC.COLUMN_NAME, TC.DATA_TYPE,\n\t                    TC.DATA_DEFAULT, TC.NULLABLE, TC.COLUMN_ID, TC.DATA_LENGTH, \n\t                    TC.DATA_SCALE, TC.DATA_PRECISION, CC.CONSTRAINT_TYPE, CC.POSITION, TC.CHAR_LENGTH\n\t                FROM ALL_TAB_COLUMNS TC, ({$subSql}) CC\n\t                WHERE UPPER(TC.TABLE_NAME) = UPPER(:TBNAME)\n\t                  AND TC.OWNER = CC.OWNER(+) AND TC.TABLE_NAME = CC.TABLE_NAME(+) AND TC.COLUMN_NAME = CC.COLUMN_NAME(+)";
             if ($schemaName) {
                 $sql .= ' AND UPPER(TC.OWNER) = UPPER(:SCNAME)';
             }
             $sql .= ' ORDER BY TC.COLUMN_ID';
         }
         $stmt = $this->query($sql, $bind);
         /**
          * Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
          */
         $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
         $table_name = 0;
         $owner = 1;
         $column_name = 2;
         $data_type = 3;
         $data_default = 4;
         $nullable = 5;
         $column_id = 6;
         $data_length = 7;
         $data_scale = 8;
         $data_precision = 9;
         $constraint_type = 10;
         $position = 11;
         $char_length = 12;
         $desc = array();
         foreach ($result as $key => $row) {
             list($primary, $primaryPosition, $identity) = array(false, null, false);
             if ($row[$constraint_type] == 'P') {
                 $primary = true;
                 $primaryPosition = $row[$position];
                 /**
                  * Oracle does not support auto-increment keys.
                  */
                 $identity = false;
             }
             $desc[$this->foldCase($row[$column_name])] = array('SCHEMA_NAME' => $this->foldCase($row[$owner]), 'TABLE_NAME' => $this->foldCase($row[$table_name]), 'COLUMN_NAME' => $this->foldCase($row[$column_name]), 'COLUMN_POSITION' => $row[$column_id], 'DATA_TYPE' => $row[$data_type], 'DEFAULT' => $row[$data_default], 'NULLABLE' => (bool) ($row[$nullable] == 'Y'), 'LENGTH' => $row[$char_length], 'SCALE' => $row[$data_scale], 'PRECISION' => $row[$data_precision], 'UNSIGNED' => null, 'PRIMARY' => $primary, 'PRIMARY_POSITION' => $primaryPosition, 'IDENTITY' => $identity);
         }
         // Save to cache
         $cache->save($desc, $cacheId, array('describetableoracle'));
     }
     return $desc;
 }
Esempio n. 5
0
 /**
  * Returns settings for SimpleFAQ app
  * - result is cached
  *
  * @param boolean $_resolve if some values should be resolved (here yet unused)
  * @return  SimpleFAQ_Model_Config
  *
  */
 public function getConfigSettings($_resolve = FALSE)
 {
     $cache = Tinebase_Core::get('cache');
     $cacheId = convertCacheId('getSimpleFAQSettings');
     $result = $cache->load($cacheId);
     if (!$result) {
         $translate = Tinebase_Translation::getTranslation('SimpleFAQ');
         $result = new SimpleFAQ_Model_Config(array('defaults' => parent::getConfigSettings()));
         $others = array(SimpleFAQ_Model_Config::FAQSTATUSES => array(array('id' => 1, 'faqstatus' => $translate->_('Draft')), array('id' => 2, 'faqstatus' => $translate->_('released')), array('id' => 3, 'faqstatus' => $translate->_('obsolete'))), SimpleFAQ_Model_Config::FAQTYPES => array(array('id' => 1, 'faqtype' => $translate->_('Internal')), array('id' => 2, 'faqtype' => $translate->_('Public'))));
         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;
 }
 /**
  * returns all grants of a given timeaccount
  * - this function caches its result (with cache tag 'container')
  *
  * @param  Timetracker_Model_Timeaccount $_timeaccount
  * @param  boolean $_ignoreACL
  * @return Tinebase_Record_RecordSet
  */
 public static function getTimeaccountGrants($_timeaccount, $_ignoreACL = FALSE)
 {
     if (!$_ignoreACL) {
         if (!Timetracker_Controller_Timeaccount::getInstance()->checkRight(Timetracker_Acl_Rights::MANAGE_TIMEACCOUNTS, FALSE)) {
             if (!self::hasGrant($_timeaccount, Tinebase_Model_Grants::GRANT_ADMIN)) {
                 throw new Tinebase_Exception_AccessDenied("You nor have the RIGHT either the GRANT to get see all grants for this timeaccount");
             }
         }
     }
     $cache = Tinebase_Core::getCache();
     $cacheId = convertCacheId('getTimeaccountGrants' . Tinebase_Core::getUser()->getId() . $_timeaccount->getId() . $_ignoreACL);
     $result = $cache->load($cacheId);
     if ($result === FALSE) {
         $allContainerGrants = Tinebase_Container::getInstance()->getGrantsOfContainer($_timeaccount->container_id, true, 'Timetracker_Model_TimeaccountGrants');
         $allTimeaccountGrants = new Tinebase_Record_RecordSet('Timetracker_Model_TimeaccountGrants');
         foreach ($allContainerGrants as $index => $containerGrants) {
             $timeaccountGrants = new Timetracker_Model_TimeaccountGrants($containerGrants->toArray());
             $allTimeaccountGrants->addRecord($timeaccountGrants);
         }
         $result = $allTimeaccountGrants;
         $cache->save($result, $cacheId, array('container'));
     }
     return $result;
 }
Esempio n. 7
0
 /**
  * remove one groupmember from the group
  *
  * @param  mixed  $_groupId
  * @param  mixed  $_accountId
  */
 public function removeGroupMemberFromSqlBackend($_groupId, $_accountId)
 {
     $groupId = Tinebase_Model_Group::convertGroupIdToInt($_groupId);
     $accountId = Tinebase_Model_User::convertUserIdToInt($_accountId);
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('group_id') . '= ?', $groupId), $this->_db->quoteInto($this->_db->quoteIdentifier('account_id') . '= ?', $accountId));
     $this->groupMembersTable->delete($where);
     // invalidate cache
     $cacheId = convertCacheId('groupMembers' . $groupId);
     Tinebase_Core::getCache()->remove($cacheId);
     $cacheId = convertCacheId('groupMemberships' . $accountId);
     Tinebase_Core::getCache()->remove($cacheId);
 }
Esempio n. 8
0
 /**
  * get grants assigned to one account of one container
  *
  * @param   string|Tinebase_Model_User          $_accountId
  * @param   int|Tinebase_Model_Container        $_containerId
  * @param   string                              $_grantModel
  * @return Tinebase_Model_Grants
  */
 public function getGrantsOfAccount($_accountId, $_containerId, $_grantModel = 'Tinebase_Model_Grants')
 {
     $accountId = Tinebase_Model_User::convertUserIdToInt($_accountId);
     $containerId = Tinebase_Model_Container::convertContainerIdToInt($_containerId);
     $cacheKey = convertCacheId('getGrantsOfAccount' . $containerId . $accountId);
     $cache = Tinebase_Core::getCache();
     $grants = $cache->load($cacheKey);
     if ($grants === FALSE) {
         $select = $this->_getSelect(array('container.id', 'container.name'), TRUE)->where("{$this->_db->quoteIdentifier('container.id')} = ?", $containerId)->join(array('container_acl' => SQL_TABLE_PREFIX . 'container_acl'), "{$this->_db->quoteIdentifier('container_acl.container_id')} = {$this->_db->quoteIdentifier('container.id')}", array('account_grant', 'account_grants' => Tinebase_Backend_Sql_Command::getAggregateFunction($this->_db, $this->_db->quoteIdentifier('container_acl.account_grant'))))->group(array('container.id', 'container.name', 'container_acl.account_grant'));
         $this->addGrantsSql($select, $accountId, '*');
         $stmt = $this->_db->query($select);
         $rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
         $grants = $this->_getGrantsFromArray($rows, $accountId, $_grantModel);
         $cache->save($grants, $cacheKey, array('container'));
     }
     return $grants;
 }
Esempio n. 9
0
 /**
  * get custom fields for an application
  * - results are cached in class cache $_cfByApplicationCache
  * - results are cached if caching is active (with cache tag 'customfields')
  *
  * @param string|Tinebase_Model_Application $_applicationId
  * @param string                            $_modelName
  * @param string                            $_requiredGrant (read grant by default)
  * @return Tinebase_Record_RecordSet of Tinebase_Model_CustomField_Config records
  */
 public function getCustomFieldsForApplication($_applicationId, $_modelName = NULL, $_requiredGrant = Tinebase_Model_CustomField_Grant::GRANT_READ)
 {
     $applicationId = Tinebase_Model_Application::convertApplicationIdToInt($_applicationId);
     $cfIndex = $applicationId . ($_modelName !== NULL ? $_modelName : '') . $_requiredGrant;
     if (isset($this->_cfByApplicationCache[$cfIndex])) {
         return $this->_cfByApplicationCache[$cfIndex];
     }
     $cache = Tinebase_Core::getCache();
     $cacheId = convertCacheId('getCustomFieldsForApplication' . $cfIndex);
     $result = $cache->load($cacheId);
     //Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' seconds  MEMORY: ' . memory_get_usage(true)/1024/1024 . ' MBytes');
     if (!$result) {
         $filterValues = array(array('field' => 'application_id', 'operator' => 'equals', 'value' => $applicationId));
         if ($_modelName !== NULL) {
             $filterValues[] = array('field' => 'model', 'operator' => 'equals', 'value' => $_modelName);
         }
         $filter = new Tinebase_Model_CustomField_ConfigFilter($filterValues);
         $filter->setRequiredGrants((array) $_requiredGrant);
         $result = $this->_backendConfig->search($filter);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got ' . count($result) . ' uncached custom fields for app id ' . $applicationId . ' (cacheid: ' . $cacheId . ')');
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE) && count($result) > 0) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . print_r($result->toArray(), TRUE));
         }
         $cache->save($result, $cacheId, array('customfields'));
     }
     $this->_cfByApplicationCache[$cfIndex] = $result;
     //Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' seconds  MEMORY: ' . memory_get_usage(true)/1024/1024 . ' MBytes');
     return $result;
 }
Esempio n. 10
0
 /**
  * testCleanupCache
  */
 public function testCleanupCache()
 {
     $this->_instance->cleanupCache(Zend_Cache::CLEANING_MODE_ALL);
     $cache = Tinebase_Core::getCache();
     $oldLifetime = $cache->getOption('lifetime');
     $cache->setLifetime(1);
     $cacheId = convertCacheId('testCleanupCache');
     $cache->save('value', $cacheId);
     sleep(3);
     // cleanup with CLEANING_MODE_OLD
     $this->_instance->cleanupCache();
     $cache->setLifetime($oldLifetime);
     $this->assertFalse($cache->load($cacheId));
     // check for cache files
     $config = Tinebase_Core::getConfig();
     if ($config->caching && $config->caching->backend == 'File' && $config->caching->path) {
         $cacheFile = $this->_lookForCacheFile($config->caching->path);
         $this->assertEquals(NULL, $cacheFile, 'found cache file: ' . $cacheFile);
     }
 }