/** * returns weekstart in iCal day format * * @param string $locale * @return string */ public static function getWeekStart($locale = NULL) { $locale = $locale ?: Tinebase_Core::getLocale(); $weekInfo = Zend_Locale::getTranslationList('week', $locale); if (!isset($weekInfo['firstDay'])) { $weekInfo['firstDay'] = 'mon'; } return Tinebase_Helper::array_value($weekInfo['firstDay'], array_flip(self::$WEEKDAY_MAP)); }
/** * returns number of the first day of the week (0 = sunday or 1 = monday) depending on locale * * @return integer */ protected function _getFirstDayOfWeek() { $locale = Tinebase_Core::getLocale(); $weekInfo = Zend_Locale_Data::getList($locale, 'week'); if (!isset($weekInfo['firstDay'])) { $result = 1; } else { $result = $weekInfo['firstDay'] === 'sun' ? 0 : 1; } return $result; }
/** * Tine 2.0 main view * * @package Tinebase * @subpackage Views * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3 * @author Philipp Schuele <*****@*****.**> * @copyright Copyright (c) 2010 Metaways Infosystems GmbH (http://www.metaways.de) * * @todo check if build script puts the translation files in build dir $tineBuildPath */ echo "<!-- Tine 2.0 static files -->\n"; // this variable gets replaced by the buildscript $tineBuildPath = ''; $locale = Tinebase_Core::isRegistered(Tinebase_Core::LOCALE) ? Tinebase_Core::getLocale() : 'en'; switch (TINE20_BUILDTYPE) { case 'DEVELOPMENT': echo $this->jsb2tk->getHTML(); echo ' <script type="text/javascript" src="index.php?method=Tinebase.getJsTranslations&' . time() . '"></script>'; break; case 'DEBUG': case 'RELEASE': echo "\n <link rel='stylesheet' type='text/css' href='index.php?method=Tinebase.getCssFiles' />"; echo "\n <script type=\"text/javascript\" src=\"index.php?method=Tinebase.getJsFiles\"></script>"; echo "\n <script type=\"text/javascript\" src=\"index.php?method=Tinebase.getJsTranslations\"></script>"; break; } if (Tinebase_Core::getConfig()->customMainscreenHeaders) { echo "\n" . Tinebase_Core::getConfig()->customMainscreenHeaders; }
/** * @param string $_fileType * @return array */ protected function _getFilesToWatch($_fileType) { $requiredApplications = array('Tinebase', 'Admin', 'Addressbook'); $enabledApplications = Tinebase_Application::getInstance()->getApplicationsByState(Tinebase_Application::ENABLED)->name; $orderedApplications = array_merge($requiredApplications, array_diff($enabledApplications, $requiredApplications)); foreach ($orderedApplications as $application) { switch ($_fileType) { case 'css': $filesToWatch[] = "{$application}/css/{$application}-FAT.css.inc"; break; case 'js': $filesToWatch[] = "{$application}/js/{$application}-FAT" . (TINE20_BUILDTYPE == 'DEBUG' ? '-debug' : null) . '.js.inc'; break; case 'lang': $fileName = "{$application}/js/{$application}-lang-" . Tinebase_Core::getLocale() . (TINE20_BUILDTYPE == 'DEBUG' ? '-debug' : null) . '.js'; $lang = Tinebase_Core::getLocale(); $customPath = Tinebase_Config::getInstance()->translations; $basePath = is_readable("{$customPath}/{$lang}/{$fileName}") ? "{$customPath}/{$lang}" : '.'; $filesToWatch[] = "{$basePath}/{$application}/js/{$application}-lang-" . Tinebase_Core::getLocale() . (TINE20_BUILDTYPE == 'DEBUG' ? '-debug' : null) . '.js'; break; default: throw new Exception('no such fileType'); break; } } return $filesToWatch; }
/** * test get all registry data * * @return void * * @see 0007934: change pw button active even if it is not allowed * @see 0008310: apps should be sorted the other way round in menu * @see 0009130: Can't open login page on Ubuntu "due to a temporary overloading" * @see 0012188: add copyOmitFields to modelconfig */ public function testGetAllRegistryData() { $registryData = $this->_instance->getAllRegistryData(); $currentUser = Tinebase_Core::getUser(); $this->assertEquals($currentUser->toArray(), $registryData['Tinebase']['currentAccount']); $this->assertEquals(Addressbook_Controller_Contact::getInstance()->getContactByUserId($currentUser->getId())->toArray(), $registryData['Tinebase']['userContact']); $this->assertEquals(TRUE, $registryData['Tinebase']['config']['changepw']['value'], 'changepw should be TRUE'); Tinebase_Config::getInstance()->set('changepw', 0); $registryData = $this->_instance->getAllRegistryData(); $changepwValue = $registryData['Tinebase']['config']['changepw']['value']; $this->assertEquals(FALSE, $changepwValue, 'changepw should be (bool) false'); $this->assertTrue(is_bool($changepwValue), 'changepw should be (bool) false: ' . var_export($changepwValue, TRUE)); $userApps = $registryData['Tinebase']['userApplications']; $this->assertEquals('Admin', $userApps[0]['name'], 'first app should be Admin: ' . print_r($userApps, TRUE)); $locale = Tinebase_Core::getLocale(); $symbols = Zend_Locale::getTranslationList('symbols', $locale); $this->assertEquals($symbols['decimal'], $registryData['Tinebase']['decimalSeparator']); if (Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) { $configuredSalesModels = array_keys($registryData['Sales']['models']); $this->assertTrue(in_array('Invoice', $configuredSalesModels), 'Invoices is missing from configured models: ' . print_r($configuredSalesModels, true)); } $this->assertTrue(isset($registryData['Timetracker']['models']['Timeaccount']['copyOmitFields']), 'Timeaccount copyOmitFields empty/missing'); $this->assertEquals(array('billed_in', 'invoice_id', 'status', 'cleared_at'), $registryData['Timetracker']['models']['Timeaccount']['copyOmitFields']); }
/** * date filter test helper * * @param string $_type weekThis|inweek|monthLast */ protected function _dateFilterTest($_type = 'weekThis') { $oldLocale = Tinebase_Core::getLocale(); Tinebase_Core::set(Tinebase_Core::LOCALE, new Zend_Locale('en_US')); // date is last/this sunday (1. day of week in the US) $today = Tinebase_DateTime::now(); $dayOfWeek = $today->get('w'); $lastSunday = $today->subDay($dayOfWeek); $this->_createTsAndSearch($lastSunday, $_type); // change locale to de_DE -> timesheet should no longer be found because monday is the first day of the week Tinebase_Core::set(Tinebase_Core::LOCALE, new Zend_Locale('de_DE')); $search = $this->_json->searchTimesheets($this->_getTimesheetDateFilter($_type), $this->_getPaging()); // if today is sunday -> ts should be found in german locale! $this->assertEquals($dayOfWeek == 0 ? 1 : 0, $search['totalcount'], 'filter not working in german locale'); Tinebase_Core::set(Tinebase_Core::LOCALE, $oldLocale); }
/** * adds "start_date", "end_date" to contract and removes "status", "cleared", "cleared_in" */ protected function _updateContractsFields() { $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup(); $groupMembers = Tinebase_Group::getInstance()->getGroupMembers($adminGroup->getId()); if (count($groupMembers) > 0) { $user = Tinebase_User::getInstance()->getUserById($groupMembers[0]); Tinebase_Core::set(Tinebase_Core::USER, $user); // cleared, cleared_in, status gets deleted, if the update is not called on cli $controller = Sales_Controller_Contract::getInstance(); $table = new Zend_Db_Table(SQL_TABLE_PREFIX . 'sales_contracts', new Zend_Db_Table_Definition(array('id' => array('name' => 'id'), 'status' => array('name' => 'status'), 'cleared' => array('name' => 'cleared'), 'cleared_in' => array('name' => 'cleared_in'), 'description' => array('name' => 'description'), 'last_modified_time' => array('name' => 'last_modified_time')))); $count = 50; $offset = 0; $more = true; $updateDescription = $statusConfig = $clearedConfig = $setEndDate = array(); $appId = Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId(); $pref = Tinebase_Core::getPreference('Tinebase'); Tinebase_Core::setupUserLocale($pref->locale); $t = Tinebase_Translation::getTranslation('Sales', Tinebase_Core::getLocale()); $config = Sales_Config::getInstance()->get('contractStatus'); foreach ($config['records'] as $cfg) { $statusConfig[$cfg['id']] = $cfg['value']; } $config = Sales_Config::getInstance()->get('contractCleared'); foreach ($config['records'] as $cfg) { $clearedConfig[$cfg['id']] = $cfg['value']; } while ($more) { $results = $table->fetchAll(NULL, NULL, $count, $offset)->toArray(); foreach ($results as $row) { if ($row['status'] == 'CLOSED') { $setEndDate[$row['id']] = $row['last_modified_time']; } $desc = $row['description']; $desc .= PHP_EOL . '---' . PHP_EOL . PHP_EOL; $contents = FALSE; if (!empty($row['status'])) { $desc .= $t->_('Status') . ': '; $desc .= isset($statusConfig[$row['status']]) ? $t->_($statusConfig[$row['status']]) : $row['status']; $desc .= PHP_EOL; $contents = TRUE; } if (!empty($row['cleared'])) { $desc .= $t->_('Cleared') . ': '; $desc .= isset($clearedConfig[$row['cleared']]) ? $t->_($clearedConfig[$row['cleared']]) : $row['cleared']; $desc .= PHP_EOL; $contents = TRUE; } if (!empty($row['cleared_in'])) { $desc .= $t->_('Cleared In') . ': '; $desc .= $row['cleared_in']; $desc .= PHP_EOL; $contents = TRUE; } if ($contents) { $updateDescription[$row['id']] = $desc . PHP_EOL; } } if (count($updateDescription) > 50) { foreach ($controller->getMultiple(array_keys($updateDescription)) as $contr) { $contr->description = $updateDescription[$contr->getId()]; $controller->update($contr, FALSE); } $updateDescription = array(); } if (count($results) < $count) { $more = FALSE; } else { $offset = $offset + $count; } } try { foreach ($controller->getMultiple(array_keys($updateDescription)) as $contr) { $contr->description = $updateDescription[$contr->getId()]; $controller->update($contr, FALSE); } } catch (Tinebase_Exception_AccessDenied $tead) { // could not update contracts ... Tinebase_Exception::log($tead); } } // remove deprecated sales contract fields foreach (array('status', 'cleared_in', 'cleared') as $colToDrop) { try { $this->_backend->dropCol('sales_contracts', $colToDrop); } catch (Zend_Db_Statement_Exception $zdse) { Tinebase_Exception::log($zdse); } } // add new sales contract fields $fields = array('<field> <name>start_date</name> <type>datetime</type> </field>', ' <field> <name>end_date</name> <type>datetime</type> </field>'); foreach ($fields as $field) { try { $declaration = new Setup_Backend_Schema_Field_Xml($field); $this->_backend->addCol('sales_contracts', $declaration); } catch (Zend_Db_Statement_Exception $zdse) { Tinebase_Exception::log($zdse); } } $table = new Zend_Db_Table(SQL_TABLE_PREFIX . 'sales_contracts', new Zend_Db_Table_Definition(array('id' => array('name' => 'id'), 'last_modified_time' => array('name' => 'last_modified_time'), 'end_date' => array('name' => 'end_date'), 'start_date' => array('name' => 'start_date')))); $db = $table->getAdapter(); $values = array_keys($setEndDate); if (!empty($values)) { $sql = 'UPDATE ' . $db->quoteIdentifier(SQL_TABLE_PREFIX . 'sales_contracts') . ' SET ' . $db->quoteIdentifier('start_date') . ' = ' . $db->quoteIdentifier('last_modified_time') . ', ' . $db->quoteIdentifier('end_date') . ' = ' . $db->quoteIdentifier('last_modified_time') . ' WHERE ' . $db->quoteIdentifier('id') . $db->quoteInto(' IN (?)', $values); $db->query($sql); } if ($this->getTableVersion('sales_contracts') == 5) { $this->setTableVersion('sales_contracts', 6); } else { $this->setTableVersion('sales_contracts', 7); } }
protected function _updateContractsWithUser($user) { Tinebase_Core::set(Tinebase_Core::USER, $user); // cleared, cleared_in, status gets deleted, if the update is not called on cli $controller = Sales_Controller_Contract::getInstance(); $table = new Zend_Db_Table(SQL_TABLE_PREFIX . 'sales_contracts', new Zend_Db_Table_Definition(array('id' => array('name' => 'id'), 'status' => array('name' => 'status'), 'cleared' => array('name' => 'cleared'), 'cleared_in' => array('name' => 'cleared_in'), 'description' => array('name' => 'description'), 'last_modified_time' => array('name' => 'last_modified_time')))); $count = 50; $offset = 0; $more = true; $updateDescription = $statusConfig = $clearedConfig = $setEndDate = array(); $pref = Tinebase_Core::getPreference('Tinebase'); Tinebase_Core::setupUserLocale($pref->locale); $t = Tinebase_Translation::getTranslation('Sales', Tinebase_Core::getLocale()); $config = Sales_Config::getInstance()->get('contractStatus'); foreach ($config['records'] as $cfg) { $statusConfig[$cfg['id']] = $cfg['value']; } $config = Sales_Config::getInstance()->get('contractCleared'); foreach ($config['records'] as $cfg) { $clearedConfig[$cfg['id']] = $cfg['value']; } while ($more) { $results = $table->fetchAll(NULL, NULL, $count, $offset)->toArray(); foreach ($results as $row) { if ($row['status'] == 'CLOSED') { $setEndDate[$row['id']] = $row['last_modified_time']; } $desc = $row['description']; $desc .= PHP_EOL . '---' . PHP_EOL . PHP_EOL; $contents = FALSE; if (!empty($row['status'])) { $desc .= $t->_('Status') . ': '; $desc .= isset($statusConfig[$row['status']]) ? $t->_($statusConfig[$row['status']]) : $row['status']; $desc .= PHP_EOL; $contents = TRUE; } if (!empty($row['cleared'])) { $desc .= $t->_('Cleared') . ': '; $desc .= isset($clearedConfig[$row['cleared']]) ? $t->_($clearedConfig[$row['cleared']]) : $row['cleared']; $desc .= PHP_EOL; $contents = TRUE; } if (!empty($row['cleared_in'])) { $desc .= $t->_('Cleared In') . ': '; $desc .= $row['cleared_in']; $desc .= PHP_EOL; $contents = TRUE; } if ($contents) { $updateDescription[$row['id']] = $desc . PHP_EOL; } } if (count($updateDescription) > 50) { foreach ($controller->getMultiple(array_keys($updateDescription)) as $contr) { $contr->description = $updateDescription[$contr->getId()]; $controller->update($contr, FALSE); } $updateDescription = array(); } if (count($results) < $count) { $more = FALSE; } else { $offset = $offset + $count; } } try { foreach ($controller->getMultiple(array_keys($updateDescription)) as $contr) { $contr->description = $updateDescription[$contr->getId()]; $controller->update($contr, FALSE); } } catch (Tinebase_Exception_AccessDenied $tead) { // could not update contracts ... Tinebase_Exception::log($tead); } }