protected function parseUserValue($value) { global $smwgHistoricTypeNamespace; if ($this->m_caption === false) { $this->m_caption = $value; } $valueParts = explode(':', $value, 2); $contentLanguage = $this->getOptionBy(self::OPT_CONTENT_LANGUAGE); if ($smwgHistoricTypeNamespace && count($valueParts) > 1) { $namespace = smwfNormalTitleText($valueParts[0]); $value = $valueParts[1]; $typeNamespace = Localizer::getInstance()->getLanguage($contentLanguage)->getNsText(SMW_NS_TYPE); if ($namespace != $typeNamespace) { $this->addErrorMsg(array('smw_wrong_namespace', $typeNamespace)); } } if ($value !== '' && $value[0] === '_') { $this->m_typeId = $value; } else { $this->m_givenLabel = smwfNormalTitleText($value); $this->m_typeId = DataTypeRegistry::getInstance()->findTypeIdByLanguage($this->m_givenLabel, $contentLanguage); } if ($this->m_typeId === '') { $this->addErrorMsg(array('smw_unknowntype', $this->m_givenLabel)); $this->m_realLabel = $this->m_givenLabel; } else { $this->m_realLabel = DataTypeRegistry::getInstance()->findTypeLabel($this->m_typeId); } $this->m_isAlias = $this->m_realLabel === $this->m_givenLabel ? false : true; try { $this->m_dataitem = self::getTypeUriFromTypeId($this->m_typeId); } catch (SMWDataItemException $e) { $this->m_dataitem = self::getTypeUriFromTypeId('notype'); $this->addErrorMsg(array('smw-datavalue-type-invalid-typeuri', $this->m_typeId)); } }
public function __construct($locale = false) { $this->locale = $locale ? $locale : Localizer::getInstance(); }
/** * @since 2.5 * * @param string $id * @param string|null $languageCode * * @return string */ public function findPreferredPropertyLabelById($id, $languageCode = '') { if ($languageCode === false || $languageCode === '') { $languageCode = Localizer::getInstance()->getUserLanguage()->getCode(); } return $this->propertyLabelFinder->findPreferredPropertyLabelByLanguageCode($id, $languageCode); }
/** * Updates a property * * @param int $id The property ID * @param array $data * @return int The property ID */ public function do_update($id, $data = null) { $user = $this->requireUser(); if (!$user->isAdmin()) { throw new Exception('Only administrators are allowed to edit properties.'); } // Validate input data $validator = new KickstartValidator(); $locale = Localizer::getInstance(); $warnings = $validator->filterErrors($data, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { return array('result' => false, 'warnings' => $warnings); } $query = PropertyQuery::create()->filterByAccount($user->getAccount()); if ($id !== null) { $query->filterById($id, Criteria::NOT_EQUAL); $property = PropertyQuery::create()->filterByAccount($user->getAccount())->findOneById($id); if (!$property) { throw new Exception('Property not found; ID: ' . $id); } } else { $property = new Property(); } // Check for duplicates if (isset($data['Name']) and $query->findOneByName($data['Name'])) { throw new Exception($locale->insert('error.taken', array('value' => '"' . $data['Name'] . '"'))); } unset($data['Id']); $property->fromArray($data); $property->setAccount($user->getAccount()); $property->save(); return $property->getId(); }
/** * Updates a user * * @param int $intId The user ID * @param array $arrData The data array * @throws Exception * @return int The user ID */ public function do_update($intId = null, $arrData) { $user = null; $con = Propel::getConnection(); if (!$con->beginTransaction()) { throw new Exception('Could not start transaction.'); } try { $authUser = $this->requireUser(); $accountId = $authUser->getAccountId(); $validator = new KickstartValidator(); $locale = Localizer::getInstance(); if ($intId and (!isset($arrData['Password']) or $arrData['Password'] == '')) { unset($this->filter_basic['Password']); unset($arrData['Password']); unset($arrData['Password2']); } $warnings = $validator->filterErrors($arrData, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { return array('result' => false, 'warnings' => $warnings); } if ($intId) { $user = $authUser->getSubordinate($intId); } else { $user = new User(); $user->setAccountId($accountId)->setDomainId($authUser->getDomainId()); } if (isset($arrData['Password'])) { $user->setPassword($arrData['Password']); } $allowedFields = array('Name' => true, 'Firstname' => true, 'Lastname' => true, 'Phone' => true, 'Email' => true, 'Number' => true); if ($authUser->getIsAdmin()) { $allowedFields += array('DomainId' => true, 'ManagerOf' => true, 'IsAdmin' => true); } $user->fromArray(array_intersect_key($arrData, $allowedFields)); // Fail if domain does not belong to authenticated account $domain = $user->getDomain($con); if ($domain === null or $domain->getAccountId() !== $accountId) { throw new Exception('Invalid domain ID #' . $user->getDomainId()); } $user->save($con); if (!empty($arrData['Properties'])) { $user->setProperties($arrData['Properties'], $con); } } catch (Exception $e) { $con->rollBack(); throw $e; } if (!$con->commit()) { throw new Exception('Could not commit transaction.'); } return $user->getId(); }
/** * Initializes localization for the filter array * * @param array $arrFilter * @param Localizer $locale * @return array */ public function initFilter($arrFilter, $locale = false) { if (!$locale) { $locale = Localizer::getInstance(); } foreach ($arrFilter as &$F) { if (isset($F['field'])) { $F['field'] = $locale->get($F['field']); } } return $arrFilter; }
public function callback($matches) { $replacement = $matches[2]; switch ($replacement) { case 'D': $replacement = Localizer::getInstance()->get('date.abbr_day_names.' . date('w', $this->timestamp)); break; case 'l': $replacement = Localizer::getInstance()->get('date.day_names.' . date('w', $this->timestamp)); break; case 'F': $replacement = Localizer::getInstance()->get('date.month_names.' . date('n', $this->timestamp)); break; case 'M': $replacement = Localizer::getInstance()->get('date.abbr_month_names.' . date('n', $this->timestamp)); break; case '\\': default: return $matches[0]; } $result = array(); $length = strlen($replacement); for ($i = 0; $i < $length; $i++) { $result[] = $replacement[$i]; } return '\\' . implode('\\', $result); }
/** * Updates a domain * * @param int $intId * @param array $arrData * @return int The domain ID */ public function do_update($intId, $arrData) { $domain = null; $con = Propel::getConnection(); if (!$con->beginTransaction()) { throw new Exception('Could not start transaction.'); } try { $user = $this->requireUser(); $account = $user->getAccount($con); // Validate input data $validator = new KickstartValidator(); $locale = Localizer::getInstance(); $warnings = $validator->filterErrors($arrData, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { $con->rollBack(); return array('result' => false, 'warnings' => $warnings); } $query = DomainQuery::create()->filterByAccount($account); if ($intId !== null) { $domain = DomainQuery::create()->filterByAccount($account)->findOneById($intId, $con); if ($domain === null) { throw new Exception('Domain not found; ID: ' . $intId); } $query->filterById($intId, Criteria::NOT_EQUAL); } else { $domain = new Domain(); $domain->setAccount($account); } // Check for duplicates if ($query->findOneByName($arrData['Name'], $con)) { throw new Exception($locale->insert('error.taken', array('value' => '"' . $arrData['Name'] . '"'))); } $domain->fromArray(array_intersect_key($arrData, array('AddressId' => true, 'Name' => true, 'Description' => true, 'Number' => true))); $domain->save($con); if (!empty($arrData['Properties'])) { $domain->setProperties($arrData['Properties'], $con); } } catch (Exception $e) { $con->rollBack(); throw $e; } if (!$con->commit()) { throw new Exception('Could not commit transaction.'); } return $domain->getId(); }
<?php session_start() or die("Error initializing session."); $template_page = array(); $errormessage = ""; $islogin = isset($_SESSION['username']) ? true : false; define('IN_ANNOUNCE', true); define("ROOT_PATH", dirname(__FILE__) . '/'); require_once ROOT_PATH . 'include/functions.php'; spl_autoload_register(function ($class) { include ROOT_PATH . 'include/classes/' . $class . '.class.php'; }); require_once ROOT_PATH . 'include/config.php'; $htmltemplate = new HtmlTemplate(); $localize = Localizer::getInstance(); $localize->setLanguage($lang); $page = isset($_GET['page']) ? $_GET['page'] : "login"; if (is_file(ROOT_PATH . "pages/" . $page . ".php")) { require_once ROOT_PATH . "pages/" . $page . ".php"; } if (is_file(ROOT_PATH . "template/{$page}.tpl")) { $template_page = file(ROOT_PATH . "template/{$page}.tpl"); } $template_page = implode("", $template_page); $template_main = implode("", file(ROOT_PATH . "template/main.tpl")); $htmltemplate->assign("pagetitle", $page); $htmltemplate->assign("errormessage", $errormessage); $htmltemplate->assign("main", $template_page); header('Content-type: text/html; charset=utf-8'); $htmltemplate->display($template_main, $localize);
/** * Updates a plugin * * @param int $id The vacation ID * @param array $data * @return int The vacation ID */ public function do_update($id, $data) { $user = $this->requireUser(); if (!$user->isAdmin()) { throw new Exception('Non-administrative user "' . $user->getFQN() . '" cannot modify plugins.'); } // Validate input data $validator = new KickstartValidator(); $locale = Localizer::getInstance(); $warnings = $validator->filterErrors($data, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { return array('result' => false, 'warnings' => $warnings); } $query = PluginQuery::create()->filterByAccount($user->getAccount()); if ($id) { $query->filterById($id, Criteria::NOT_EQUAL); $plugin = PluginQuery::create()->filterByAccount($user->getAccount())->findOneById($id); if (!$plugin) { throw new Exception('Plugin not found; ID: ' . $id); } } else { $plugin = new Plugin(); } // Check for duplicates if ($query->findOneByIdentifier($data['Name'])) { throw new Exception($locale->insert('error.taken', array('value' => '"' . $data['Name'] . '"'))); } if (isset($data['Start'])) { $plugin->setStart(strtotime($data['Start'] . 'Z', 0)); unset($data['Start']); } $plugin->fromArray($data); $plugin->setAccount($user->getAccount()); $plugin->save(); return $plugin->getId(); }
/** * Updates an account. * * @param int $id * @param array $data * @return int The account ID */ public function do_update($id, $data) { $account = null; $con = Propel::getConnection(); if (!$con->beginTransaction()) { throw new Exception('Could not start transaction.'); } try { $user = $this->requireUser(); // Validate input data $validator = new KickstartValidator(); $locale = Localizer::getInstance(); $warnings = $validator->filterErrors($data, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { $con->rollBack(); return array('result' => false, 'warnings' => $warnings); } if ($id === null) { $account = new Account(); } else { $account = AccountQuery::create()->findOneById($id, $con); if ($account === null or $account !== $user->getAccount($con) or !$user->getIsAdmin()) { throw new Exception('Account #' . $id . ' not found or no permission to update it.'); } // Check for duplicates if (isset($data['Name'])) { $otherAccount = AccountQuery::create()->filterById($account->getId(), Criteria::NOT_EQUAL)->findOneByName($data['Name'], $con); if ($otherAccount !== null) { throw new Exception($locale->insert('error.taken', array('value' => '"' . $data['Name'] . '"'))); } } } $account->fromArray(array_intersect_key($data, array('Name' => true))); $account->save($con); if (!empty($data['Address'])) { $address = $account->getAddress($con); if ($address === null) { $address = new Address(); $address->setAccount($account); } $address->fromArray(array_intersect_key($data['Address'], array('Company' => true, 'Firstname' => true, 'Lastname' => true, 'Address' => true, 'Zipcode' => true, 'City' => true, 'State' => true, 'Province' => true, 'Country' => true, 'Phone' => true, 'Fax' => true, 'Website' => true, 'Email' => true, 'Vatid' => true))); $address->save($con); } if (!empty($data['Properties'])) { $account->setProperties($data['Properties'], $con); } } catch (Exception $e) { $con->rollBack(); throw $e; } if (!$con->commit()) { throw new Exception('Could not commit transaction.'); } return $account->getId(); }
/** * Updates a holiday * * @param int $intId The holiday ID * @param array $arrData * @return int The holiday ID */ public function do_update($intId, $arrData) { $user = $this->requireUser(); // Validate input data $validator = new KickstartValidator(); $locale = Localizer::getInstance(); $warnings = $validator->filterErrors($arrData, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { return array('result' => false, 'warnings' => $warnings); } if ($intId) { if (!($holiday = HolidayQuery::create()->findOneById($intId))) { throw new Exception('Holiday with ID ' . $intId . ' not found!'); } } else { $holiday = new Holiday(); } $con = Propel::getConnection(HolidayPeer::DATABASE_NAME); $con->beginTransaction(); try { $holiday->setName($arrData['Name'])->setDate($arrData['Date'])->setAccount($user->getAccount())->save($con); // Assign the domains if (!(isset($arrData['Domains']) && is_array($arrData['Domains']))) { $arrData['Domains'] = array(); } $sub = array(); foreach (HolidayDomainQuery::create()->filterByHoliday($holiday)->find() as $link) { if (in_array($link->getDomainId(), $arrData['Domains'])) { $sub[] = $link->getDomainId(); } else { $link->delete($con); } } $diff = array_diff($arrData['Domains'], $sub); if (sizeof($diff) > 0) { // Get the account's domains $domainFilter = DomainQuery::create()->filterByAccount($user->getAccount())->add(DomainPeer::ID, $arrData['Domains'], Criteria::IN)->find(); if (sizeof($domainFilter) != sizeof($arrData['Domains'])) { // Obviously there are some domains the user does not belong to } foreach (array_diff($arrData['Domains'], $sub) as $domainId) { $link = new HolidayDomain(); $link->setHoliday($holiday)->setDomainId($domainId)->save($con); } } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } return array('result' => $holiday->getId(), 'test' => $diff); // return $holiday->getId(); }
/** * Creates or updates a clocking. * * @param int $id * @param array $data * @return int The clocking ID */ public function do_update($id, $data) { $con = Propel::getConnection(); if (!$con->beginTransaction()) { throw new Exception('Could not start transaction.'); } $clocking = null; try { $authUser = $this->requireUser(); // Validate input data $validator = new KickstartValidator(); $locale = Localizer::getInstance(); // Cut off seconds to get time in full minutes if (isset($data['Start']) and is_numeric($data['Start'])) { $data['Start'] -= date('s', $data['Start']); } if (isset($data['End']) and is_numeric($data['End'])) { $data['End'] -= date('s', $data['End']); } $warnings = $validator->filterErrors($data, $this->initFilter($this->filter_basic, $locale)); if ($warnings) { return array('result' => false, 'warnings' => $warnings); } if ((string) $id === '') { $event = 'create'; $clocking = new Clocking(); } else { $event = 'update'; $clocking = $this->getClockingById($id, $con); if ($clocking->getBooked() or $clocking->getFrozen()) { throw new Exception('Cannot change clocking entry #' . $id . ' because it already has bookings or is locked for booking.'); } } $isAdmin = $authUser->getIsAdmin(); $allowedColumns = array('TypeId' => true, 'Start' => true, 'End' => true, 'Breaktime' => true, 'Comment' => true); if ($isAdmin) { $allowedColumns['ApprovalStatus'] = true; } $clocking->fromArray(array_intersect_key($data, array('UserId' => true) + $allowedColumns)); $clockingUser = $clocking->getUserRelatedByUserId($con); $clockingUserId = $clocking->getUserId(); $authUserAccountId = $authUser->getAccountId(); // Check if authenticated user may access clocking's user if ($clockingUser === null or (string) $clockingUser->getAccountId() !== (string) $authUserAccountId or !$isAdmin and $clockingUser !== $authUser) { throw new Exception('Invalid user #' . $clockingUserId . ' specified for clocking or no permission to access that user\'s data.'); } $type = $clocking->getClockingType($con); if ($type === null) { throw new Exception('Clocking #' . $id . ' has no clocking type assigned.'); } $account = $authUser->getAccount($con); if ($account === null) { throw new Exception('Could not load account of user #' . $authUser->getId() . ' "' . $authUser->getFQN($con) . '".'); } // Check hard time limit for non-admin users if (!$isAdmin) { $this->validateTimeLimits($account, $authUser, $clocking, $con); } $isNew = $clocking->isNew(); // Save first to obtain an ID which may be referenced by a plugin $clocking->save($con); $clockingData = EntityArray::from($clocking, $con) + array('IsNew' => $isNew, 'Type' => EntityArray::from($type, $con)); if (!$isAdmin and ($type->getApprovalRequired() or $this->pastGraceTimeExceeded($type, min((int) $clocking->getStart('U'), (int) $clocking->getEnd('U'))))) { $clocking->setApprovalStatus(ClockingPeer::APPROVAL_STATUS_REQUIRED); } $clocking->fromArray(array_intersect_key(PluginPeer::fireEvent($clockingUser, 'clocking', $event, $clockingData, $con), $allowedColumns)); $type = $clocking->getClockingType($con); // Plugins may have changed this if ($type === null or (string) $type->getAccountId() !== (string) $authUserAccountId) { throw new Exception('Clocking #' . $id . ' has an invalid or unknown clocking type #' . $clocking->getTypeId() . ' assigned.'); } $start = (int) $clocking->getStart('U'); $end = (int) $clocking->getEnd('U'); if ($start > $end) { throw new APIException(self::ERROR_INTERVAL, 'Start time (' . $clocking->getStart('Y-m-d H:i:s') . ') must be before end time (' . $clocking->getEnd('Y-m-d H:i:s') . ').', array('start' => $start, 'end' => $end)); } elseif ($type->getWholeDay()) { // Set time of day for start and end to 00:00:00 $clocking->setStart(strtotime(date('Y-m-d 00:00:00', $start))); $clocking->setEnd(strtotime(date('Y-m-d 00:00:00', $end))); // Set break time to 0 $clocking->setBreaktime(0); } elseif ($start === $end) { // Create an open clocking entry (i.e. sign on for work). // Fail if there are other open entries. if (($openClocking = $this->getOpenClocking($authUser, $clockingUser, $clocking, $con)) !== null) { $openComment = $openClocking->getComment(); throw new APIException(self::ERROR_OPEN, 'Clocking #' . $openClocking->getId() . ((string) $openComment === '' ? '' : ' "' . $openComment . '"') . ' from ' . $openClocking->getStart('r') . ' to ' . $openClocking->getEnd('r') . ' is already open. Please close that entry first.' . $openClocking->getId() . ' ' . $clocking->getId(), $openClocking); } } elseif ($clocking->getTime() < $clocking->getBreaktime()) { throw new APIException(self::ERROR_BREAK, 'Break (' . $clocking->getBreaktime() / 60 . ' minutes) must be less than the specified work time (' . $clocking->getTime() . ' = ' . $clocking->getStart('Y-m-d H:i:s') . ' - ' . $clocking->getEnd('Y-m-d H:i:s') . ').'); } $futureGraceTime = $type->getFutureGraceTime(); if ($futureGraceTime !== null and $end > time() + $futureGraceTime) { throw new APIException(self::ERROR_FUTURE, 'Clocking type "' . $type->getIdentifier() . '" #' . $type->getId() . ' does not allow entries in the future (' . $clocking->getStart('Y-m-d H:i:s') . ' - ' . $clocking->getEnd('Y-m-d H:i:s') . ').'); } $clocking->save($con); $clocking->reload(false, $con); if ($clocking->getFrozen()) { throw new APIException(self::ERROR_LOCKED, 'The clocking #' . $clocking->getId() . ' is currently locked for booking.'); } // Check for other non-whole-day clockings with overlapping time if (!$type->getWholeDay()) { $firstConflict = self::createClockingQuery($authUser, $con)->filterById($clocking->getId(), Criteria::NOT_EQUAL)->filterByUserId($clockingUserId)->add(ClockingTypePeer::WHOLE_DAY, 0, Criteria::EQUAL)->filterByStart($end, Criteria::LESS_THAN)->filterByEnd($start, Criteria::GREATER_THAN)->filterByDeleted(0, Criteria::EQUAL)->findOne($con); if ($firstConflict !== null) { throw new APIException(self::ERROR_OVERLAP, $clocking->__toString() . ' overlaps with ' . $firstConflict->__toString() . '.', $firstConflict); } } SystemLogPeer::add('clocking.' . $event, $clocking, SystemLogPeer::CODE_SUCCESSFUL, null, $authUser, array('clocking' => $clocking->toArray()), $con); } catch (Exception $e) { $con->rollBack(); SystemLogPeer::add('clocking.' . $event, $clocking, SystemLogPeer::CODE_FAILED, $e->getMessage(), $authUser, array('exception' => $e->__toString(), 'clocking' => $clocking->toArray()), $con); throw $e; } if (!$con->commit()) { throw new Exception('Could not commit transaction.'); } return $clocking->getId(); }
require LIB_DIR . '/kickstart/kickstart.controller.php'; require LIB_DIR . '/kickstart/kickstart.localizer.php'; require LIB_DIR . '/kickstart/kickstart.validator.php'; require LIB_DIR . '/kickstart/utils.excel.php'; require LIB_DIR . '/kickstart/compatibility.php'; require LIB_DIR . '/kickstart/form.php'; require LIB_DIR . '/kickstart/html.php'; require LIB_DIR . '/kickstart/http.php'; require LIB_DIR . '/kickstart/keyreplace.php'; require LIB_DIR . '/kickstart/ldap.php'; require LIB_DIR . '/kickstart/recentlist.php'; require LIB_DIR . '/kickstart/session.php'; require LIB_DIR . '/kickstart/util.php'; require LIB_DIR . '/cryptastic/cryptastic.class.php'; require LIB_DIR . '/spyc/spyc.php'; require LIB_DIR . '/tymio/controller.class.php'; require LIB_DIR . '/tymio/localizer.class.php'; require LIB_DIR . '/tymio/api.class.php'; require LIB_DIR . '/tymio/util.inc.php'; require LIB_DIR . '/tymio/ixml.inc.php'; require LIB_DIR . '/tymio/entityarray.php'; require LIB_DIR . '/tymio/search.php'; require APP_DIR . '/api/account.php'; require APP_DIR . '/api/clocking.php'; require APP_DIR . '/api/domain.php'; require APP_DIR . '/api/holiday.php'; require APP_DIR . '/api/plugin.php'; require APP_DIR . '/api/transaction.php'; require APP_DIR . '/api/user.php'; $locale = Localizer::getInstance($langAccepted, $langDefault); $locale->load(APP_DIR . 'locales', \Xily\Config::get('app.cache', 'bool', false) ? CACHE_DIR . 'locales' : false);
/** * @since 2.5 * * @param string $text * @param string $languageCode * * @return DIProperty[]|[] */ public function findPropertyListFromLabelByLanguageCode($text, $languageCode = '') { if ($text === '') { return array(); } if ($languageCode === '') { $languageCode = Localizer::getInstance()->getContentLanguage()->getCode(); } $dataValue = DataValueFactory::getInstance()->newDataValueByProperty(new DIProperty('_PPLB')); $dataValue->setUserValue($dataValue->getTextWithLanguageTag($text, $languageCode)); $queryFactory = ApplicationFactory::getInstance()->getQueryFactory(); $descriptionFactory = $queryFactory->newDescriptionFactory(); $description = $descriptionFactory->newConjunction(array($descriptionFactory->newNamespaceDescription(SMW_NS_PROPERTY), $descriptionFactory->newFromDataValue($dataValue))); $propertyList = array(); $queryResult = $this->store->getQueryResult($queryFactory->newQuery($description)); if (!$queryResult instanceof \SMWQueryResult) { return $propertyList; } foreach ($queryResult->getResults() as $result) { $propertyList[] = DIProperty::newFromUserLabel($result->getDBKey()); } return $propertyList; }