protected function checkUserPermissionsForRecord() { if ($this->currentUser['adminRole'] < $this->adminRoles['adminRoleSuperadmin'] && $this->currentUser['id'] != $this->record['id']) { CoreServices2::getDB()->transactionCommit(); CoreUtils::redirect($this->getListPageAddress()); } }
public function prepareData() { parent::prepareData(); if (CoreServices2::getRequest()->getFromGet('_sm')) { $this->successMessage = 1; return; } $this->dao = new UserDAO(); $this->initRecord(); $this->initForm(); $this->createFormFields(); if (empty($this->record['id'])) { // @TODO: własciwie w tym wypadku powinno sie przejść z powrotem do pierwszego // formularza i rozpocząć całą procedurę od nowa $this->errorMessageContainer = new CoreFormValidationMessageContainer(); $this->errorMessageContainer->addMessage('errorInvalidCode'); return; } if ($this->form->isSubmitted()) { $this->addFormValidators(); $this->form->setFieldValuesFromRequest(); $this->handleRequest(); } else { $this->setFormFieldValuesFromRecord(); } if (!empty($this->redirectAddress)) { CoreUtils::redirect($this->redirectAddress); } }
/** * Processes a preference item's new value * * @param string $key * * @return mixed */ static function process($key) { $value = isset($_POST['value']) ? CoreUtils::trim($_POST['value']) : null; switch ($key) { case "cg_itemsperpage": $thing = 'Color Guide items per page'; if (!is_numeric($value)) { throw new \Exception("{$thing} must be a number"); } $value = intval($value, 10); if ($value < 7 || $value > 20) { throw new \Exception("{$thing} must be between 7 and 20"); } break; case "p_vectorapp": if (!empty($value) && !isset(CoreUtils::$VECTOR_APPS[$value])) { throw new \Exception("The specified app is invalid"); } break; case "p_hidediscord": case "p_disable_ga": case "cg_hidesynon": case "cg_hideclrinfo": $value = $value ? 1 : 0; break; case "discord_token": Response::fail("You cannot change the {$key} setting"); } return $value; }
protected function initRecord() { parent::initRecord(); if (empty($this->record['id']) || $this->record['subpageModule'] != 'Subpage' || $this->record['subpageMode'] != 'Website') { CoreUtils::redirect($this->getListPageAddress()); } }
public static function getDateTime() { if (!self::$datetime) { self::$datetime = date('Y-m-d H:i:s'); } return self::$datetime; }
/** * Ta funkcja zwraca na razie liczbę dni, godzin, minut, sekund * pozostających do momentu podanego w parametrze. Podanie ilości * miesięcy i lat to trochę gorsza sprawa (szczególnie z miesiącami * jest problem koncepcyjny). * @param string * @return array */ public function getTimeRemaining($time) { $timeSeconds = strtotime($time) - strtotime(CoreUtils::getDateTime()); if ($timeSeconds <= 0) { return null; } return array('timeSeconds' => $timeSeconds, 's' => $timeSeconds % 60, 'm' => floor($timeSeconds / 60) % 60, 'h' => floor($timeSeconds / (60 * 60)) % 24, 'D' => floor($timeSeconds / (60 * 60 * 24))); }
public function eventFinish($category, $eventName) { $eventId = $this->getIdByName($eventName); if (empty($this->info[$category]['events'][$eventId]['eventName'])) { $this->info[$category]['events'][$eventId]['eventName'] = $eventName; } $this->info[$category]['events'][$eventId]['finishTime'] = CoreUtils::getTimeMicroseconds() - $this->startTime; }
protected function initParams(&$params) { CoreUtils::checkConstraint(is_null($params) || is_array($params)); if (!empty($params)) { $this->params = $params; } else { $this->params = array(); } }
public function validate($messageManager) { $field = $this->form->getField($this->fieldName); $fieldValue = $field->getValue(); if (!is_null($fieldValue)) { if (date('Y-m-d', strtotime($fieldValue)) < CoreUtils::getDate()) { $messageManager->addMessage('dateInThePast', array($this->fieldName => $field->getCaption())); } } }
protected function logAction($action) { $logRecord = $this->logDAO->getRecordTemplate(); $logRecord['adminId'] = CoreServices2::getAccess()->getCurrentUserId(); $logRecord['recordType'] = $this->recordType; $logRecord['recordId'] = CoreServices2::getAccess()->getCurrentUserId(); $logRecord['logTime'] = CoreUtils::getDateTime(); $logRecord['logIP'] = CoreServices2::getRequest()->getRealIP(); $logRecord['logOperation'] = $action; $this->logDAO->save($logRecord); }
/** * Teoretycznie jest to odporne na thickboxy. */ protected function checkHTTPS() { $httpsOn = CoreServices2::getUrl()->isHTTPSOn(); $httpsRequired = CoreConfig::get('Environment', 'httpsForWebsite'); if ($httpsRequired && !$httpsOn) { CoreUtils::redirect(CoreServices2::getUrl()->getCurrentExactAddress('https')); } if (!$httpsRequired && $httpsOn) { CoreUtils::redirect(CoreServices2::getUrl()->getCurrentExactAddress('http')); } }
protected function redirectToPage($url, $layoutType) { switch ($layoutType) { case 'standard': CoreUtils::redirect(CoreServices2::getUrl()->createAddress('_m', 'Helper', '_o', 'WebsiteThickboxParentRedirect', 'url', $url)); case 'thickbox': CoreUtils::redirect($url); default: throw new CoreException('Invalid layout type ' . $layoutType); } }
protected function handleRequest() { $this->errorMessageContainer = $this->form->getValidationResults(); if (!$this->errorMessageContainer->isAnyErrorMessage()) { $this->setRecordValuesFromForm(); $this->record['userEraseRequestTime'] = CoreUtils::getDateTime(); $this->record['userState'] = 'forDeletion'; $this->dao->save($this->record); CoreServices2::getAccess()->logout(); $this->redirectToStep2(); } }
public static function add($pointName = '') { if (self::$index == 0) { self::$timePoints = array(); } self::$timePoints[self::$index] = array(); $currentTime = CoreUtils::getTimeMicroseconds(); self::$timePoints[self::$index]['diff'] = self::$index != 0 ? $currentTime - self::$timePoints[self::$index - 1]['time'] : 0; self::$timePoints[self::$index]['time'] = $currentTime; self::$timePoints[self::$index]['name'] = $pointName; self::$index++; }
public function getChildrenCount(&$record) { CoreUtils::checkConstraint(!empty($record['id'])); $db = CoreServices2::getDB(); $sql = ' SELECT COUNT(*) AS num FROM subpage WHERE subpageParentId = ' . $db->prepareInputValue($record['id']); $row = $db->getRow($sql); return $row['num']; }
public function prepareData() { if (!$this->isCLI()) { CoreUtils::redirect(CoreServices::get('url')->createAddress()); } $this->garbageCollector = new TmpRecordGarbageCollector(); try { $this->garbageCollector->clean(); } catch (Exception $e) { $this->reportError($e->getMessage()); } }
public function prepareData() { $this->checkHTTPS(); $this->adminRoles = array_flip(CoreConfig::get('Data', 'adminRoles')); $this->currentUser = CoreServices::get('access')->getCurrentUserData(); if (!$this->isControllerUsagePermitted()) { CoreUtils::redirect($this->getNoPermissionsAddress()); } $this->initDAO(); $this->initLayout(); $this->initCompany(); $this->initProject(); }
/** * Returns boolean value, not null. */ public function isValidToken($token) { if (empty($token)) { return False; } $sessionId = CoreServices::get('request')->getSessionId(); $timeMiliseconds = CoreUtils::getTimeMiliseconds(); $db = CoreServices::get('db'); $db->change($this->deleteOldTokensSQL($timeMiliseconds)); $db->change($this->insertTokenSQL($token, $sessionId, $timeMiliseconds)); $row = $db->getRow($this->checkTokenSQL($token, $sessionId)); return $row['num'] == '1'; }
/** * Processes a configuration item's new value * * @param string $key * * @return mixed */ static function process($key) { $value = CoreUtils::trim($_POST['value']); if ($value === '') { return null; } switch ($key) { case "reservation_rules": case "about_reservations": $value = CoreUtils::sanitizeHtml($value, $key === 'reservation_rules' ? array('li', 'ol') : array('p')); break; } return $value; }
public function prepareData() { parent::prepareData(); $this->initDAO(); $this->initSearchForm(); if ($this->searchForm->isSubmitted()) { $this->searchForm->setFieldValuesFromRequest(); } $this->initRecordList(); $this->initDeletionForm(); if ($this->deletionForm->isSubmitted()) { $this->deletionForm->setFieldValuesFromRequest(); $this->handleDeleteRequest(); CoreUtils::redirect(CoreServices::get('url')->getCurrentPageUrl('_sm', 'MassDelete')); } }
protected function addDynamicImageInfo(&$imageData) { if (count($imageData) < 4 || count($imageData) > 7) { throw new CoreException('Invalid number of arguments supplied for image from database in email template!'); } $image = $fileDAO->getRecordById($imageData[1]); CoreUtils::checkConstraint(!empty($image['id'])); $fullName = $image['fileBaseName'] . '.' . $image['fileExtension']; $options = $this->getDynamicImageOptions($imageData); $resizedImagePath = $files->getResizedImageDiskPath($image['fileBaseName'], $image['fileExtension'], $options); if (!file_exists($resizedImagePath)) { $imagePath = $files->getDiskPath($image['fileBaseName'], $image['fileExtension']); $files->resizeImage($resizedImagePath, $image['fileBaseName'], $image['fileExtension'], $options); } $this->attachments[] = array('cid' => $cid, 'fileName' => $fullName, 'filePath' => $resizedImagePath, 'mimeType' => $image['fileMimeType']); }
protected function updateLoginHistory($loginHistoryDAO, $type, $userId, $loginSuccessful) { $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; $host = isset($_SERVER['REMOTE_HOST']) ? gethostbyaddr($_SERVER['REMOTE_HOST']) : ($ip ? gethostbyaddr($ip) : null); $record = $loginHistoryDAO->getRecordTemplate(); $record['loginHistorySuccess'] = $loginSuccessful ? 1 : null; $record['loginHistoryTime'] = CoreUtils::getDateTime(); $record['loginHistoryMicrotime'] = CoreUtils::getTimeMicroseconds(); $record['loginHistoryIP'] = $ip; if ($host != $ip) { $record['loginHistoryHost'] = $host; } $record['loginHistoryPHPSessionId'] = CoreServices::get('request')->getSessionId(); $record[$type . 'Id'] = $userId; $loginHistoryDAO->save($record); }
/** * Usuwa te rekordy z tabeli _tmpRecord, dla których sesja już na pewno wygasła. * Usuwa też przypisane do tych rekordów pliki. */ public function clean() { $calendar = new Calendar(); $time = $calendar->addSeconds(CoreUtils::getDateTime(), -CoreConfig::get('Cron', 'tmpRecordOldAgeSeconds')); $tmpRecordDAO = new TmpRecordDAO(); $oldRecords = $tmpRecordDAO->getOldRecords($time, CoreConfig::get('Cron', 'tmpRecordsToDeletePerExecution')); $fileDAO = new FileDAO(); foreach ($oldRecords as $record) { if ($this->isForDeletion($record)) { $files = $fileDAO->getListByRecord('_tmpRecord', $record['id']); foreach ($files as $file) { $fileDAO->delete($file); } $tmpRecordDAO->delete($record); } } }
protected function initRecord() { $id = CoreServices::get('request')->getFromRequest('id'); if (!empty($id)) { $this->record = $this->dao->getRecordById($id); if (!$this->record['id']) { CoreServices::get('db')->transactionCommit(); CoreUtils::redirect($this->getListPageAddress()); } } else { CoreUtils::redirect(CoreServices2::getUrl()->createAddress('_m', 'Settings', '_o', 'CMSList')); } $this->initMultiselectRelations(); $this->recordOldValues = $this->record; // clone! $this->checkUserPermissionsForRecord(); }
protected function decodePHPUploadError($errorCode) { CoreUtils::checkConstraint($errorCode != UPLOAD_ERR_OK); switch ($errorCode) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: return 'fileTooBig'; case UPLOAD_ERR_PARTIAL: return 'fileUploadedPartially'; case UPLOAD_ERR_NO_FILE: return 'fileNotUploaded'; case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_EXTENSION: default: return 'fileUploadUnknownError'; } }
protected function checkHTTPS() { $httpsOn = CoreServices2::getUrl()->isHTTPSOn(); if ($this->getSessionName() == 'CMSSession') { $httpsRequired = CoreConfig::get('Environment', 'httpsForCMS'); } elseif ($this->getSessionName() == 'WebsiteSession') { $httpsRequired = CoreConfig::get('Environment', 'httpsForWebsite'); } else { $httpsRequired = False; // i tak nie ma sesji! } if ($httpsRequired && !$httpsOn) { CoreUtils::redirect(CoreServices::get('url')->getCurrentExactAddress('https')); } if (!$httpsRequired && $httpsOn) { CoreUtils::redirect(CoreServices::get('url')->getCurrentExactAddress('http')); } }
public static function getInitialChar($string, $lang = null) { if (is_null($lang)) { $lang = 'universal'; } if (!array_key_exists($lang, CoreConfigDisplay::$paginationChars)) { throw new CoreException('Invalid language \'' . $lang . '\' for first character pagination!'); } if (empty($string)) { return CoreConfigDisplay::paginationDummy; } $firstChar = mb_strtoupper(CoreUtils::substr($string, 0, 1), CoreConfigDisplay::globalCharset); foreach (CoreConfigDisplay::$paginationChars[$lang] as $shownChar => $initials) { if (in_array($firstChar, $initials)) { return $shownChar; } } return CoreConfigDisplay::paginationDummy; }
public function prepareData() { parent::prepareData(); $this->dao = new UserDAO(); if (CoreServices::get('request')->getFromGet('_sm')) { $this->successMessage = 1; return; } $this->initForm(); $this->createFormFields(); if ($this->form->isSubmitted()) { $this->addFormValidators(); $this->form->setFieldValuesFromRequest(); $this->handleRequest(); } if (!is_null($this->redirectAddress)) { CoreUtils::redirect($this->redirectAddress); } }
public function Notify(AbstractPaymentModule $PaymentModule, $status) { Log::Log("UIPaymentObserver: received notify", E_USER_NOTICE); if ($status == PAYMENT_STATUS::SUCCESS) { $GLOBALS["okmsg"] = _("Thank you for your payment!"); if (!$_SESSION["success_payment_redirect_url"]) CoreUtils::Redirect("inv_view.php"); else CoreUtils::Redirect($_SESSION["success_payment_redirect_url"]); } elseif ($status == PAYMENT_STATUS::FAILURE) { $PaymentForm = $PaymentModule->GetPaymentForm(); $smarty = Core::GetSmartyInstance("SmartyExt"); $fields = $PaymentForm->ListFields(); $smarty_fields = array(); foreach($fields as $field) { $smarty_fields[$field->Title] = array("name" => $field->Name, "required" => $field->IsRequired, "type" => $field->FieldType, "values" => $field->Options); if ($_REQUEST[$field->Name]) $attr[$field->Title] = $_REQUEST[$field->Name]; } $display["errmsg"] = "The following errors occured"; $display["err"] = explode("\n", $PaymentModule->GetFailureReason()); $display["gate"] = $PaymentModule->GetModuleName(); $display["orderid"] = $PaymentModule->GetOrderID(false); $display["fields"] = $smarty_fields; $display["post"] = $attr; $template_name = "client/paymentdata.tpl"; $smarty->assign($GLOBALS["display"]); $smarty->assign($display); $smarty->display($template_name); } else throw new Exception(sprintf(_("Undefined PaymentStatus received from %s payment module."), $PaymentModule->GetModuleName()), E_USER_ERROR); }
public function prepareData() { parent::prepareData(); $this->initDAO(); $this->form = new CoreForm('post'); if ($this->form->isSubmitted()) { CoreServices::get('db')->transactionStart(); $this->initRecordList(); $this->initActions(); $this->createFormFields(); $this->addFormValidators(); $this->form->setFieldValuesFromRequest(); $this->handleRequest(); CoreServices::get('db')->transactionCommit(); } else { $this->initRecordList(); $this->initActions(); $this->createFormFields(); } if (!is_null($this->redirectAddress)) { CoreUtils::redirect($this->redirectAddress); } }