Beispiel #1
0
 protected function executeImpl(ArrayAdapter $params)
 {
     $url = $params->str('url');
     $text = $params->str('text');
     $note = $params->str('note');
     if (!$url || !$text) {
         return 'Не передан url или текст';
     }
     /*
      * Если пользователь не просматривал эту страницу и это не администратор - игнорируем.
      */
     /*
      $wasOpened = PageOpenWatcher::isPageOpenedByUser($url, PsUser::instOrNull());
      if (!$wasOpened && !AuthManager::isAuthorizedAsAdmin()) {
      return 'Пользователь не открывал страницу'; //---
      }
     */
     $text = UserInputTools::safeShortText($text);
     $note = $note ? UserInputTools::safeLongText($note) : $note;
     $saved = UtilsBean::inst()->saveMisprint($url, $text, $note, AuthManager::getUserIdOrNull());
     if (!$saved) {
         return 'Запись не была сохранена';
         //---
     }
     return new AjaxSuccess();
 }
Beispiel #2
0
 public function buildContent()
 {
     $PARAMS['uts_php'] = time();
     $PARAMS['uts_db'] = UtilsBean::inst()->getDbUnixTimeStamp();
     $posts = array();
     /* @var $pp PostsProcessor */
     foreach (Handlers::getInstance()->getPostsProcessors() as $pp) {
         $posts[$pp->postsTitle()] = AdminPostsBean::inst()->getAllPosts($pp->dbBean());
     }
     $PARAMS['data'] = $posts;
     echo $this->getFoldedEntity()->fetchTpl($PARAMS);
 }
Beispiel #3
0
 protected function executeImpl(ArrayAdapter $params)
 {
     UtilsBean::inst()->removeMissprint($params->int('id'));
     return new AjaxSuccess();
 }
Beispiel #4
0
 public function buildContent()
 {
     $PARAMS['mp'] = UtilsBean::inst()->getMissprints();
     echo $this->getFoldedEntity()->fetchTpl($PARAMS);
 }
Beispiel #5
0
 /**
  * Метод проверяет, была ли страница просмотрена пользователем.
  * Если пользователь не авторизован, то проверяет без привязки к пользователю.
  */
 public static function isPageOpenedByUser($url, PsUser $user = null)
 {
     return UtilsBean::inst()->isPageWasOpened($url, $user ? $user->getId() : null);
 }
Beispiel #6
0
 /**
  * Удаление настройки из базы
  */
 public function reset()
 {
     UtilsBean::inst()->delDbProp($this->name());
 }
Beispiel #7
0
 /**
  * Установка нового значения настройки
  */
 public function set(DbProp $prop, $val)
 {
     UtilsBean::inst()->setDbProp($this->colName, $prop->name(), $this->php2db($val));
     return $val;
 }
Beispiel #8
0
 protected function doAudit($action, $userId = null, $data = null, $saveToSession = false, $parentAction = null, $auditIfNoParent = true, $clearParent = true)
 {
     try {
         $action = $this->validateAction($action);
         $parentAction = $this->validateAction($parentAction, true);
         $actionSessionKey = $this->sessionCode($action);
         $parentActionSessionKey = $parentAction ? $this->sessionCode($parentAction) : null;
         $parentId = $parentActionSessionKey ? SessionArrayHelper::getInt($parentActionSessionKey) : null;
         $hasParentIdInSession = is_integer($parentId);
         $userId = AuthManager::validateUserIdOrNull($userId);
         $userIdAuthed = AuthManager::getUserIdOrNull();
         if ($this->LOGGER->isEnabled()) {
             $this->LOGGER->info();
             $this->LOGGER->info("<Запись #{}>", ++$this->NUM);
             $this->LOGGER->info('Действие: {}', $this->decodeAction($action));
             $this->LOGGER->info('Пользователь: {}', is_inumeric($userId) ? $userId : 'НЕТ');
             $this->LOGGER->info('Авторизованный пользователь: {}', is_inumeric($userIdAuthed) ? $userIdAuthed : 'НЕТ');
             $this->LOGGER->info('Данные: {}', $data === null ? 'НЕТ' : print_r($data, true));
             $this->LOGGER->info('Сохранять в сессию: {}', $saveToSession ? 'ДА' : 'НЕТ');
             $this->LOGGER->info('Родительское действие: {}', $this->decodeAction($parentAction));
             if ($parentAction) {
                 $this->LOGGER->info('Родительское действие есть в сессии: {}', $hasParentIdInSession ? "ДА ({$parentActionSessionKey}={$parentId})" : 'НЕТ');
                 if ($hasParentIdInSession) {
                     $this->LOGGER->info('Очищать родительское действие в сессии: {}', $clearParent ? 'ДА' : 'НЕТ');
                 } else {
                     $this->LOGGER->info('Производить аудит при отсутствии родит. действия: {}', $auditIfNoParent ? 'ДА' : 'НЕТ');
                 }
             }
         }
         if (!$hasParentIdInSession && !$auditIfNoParent) {
             $this->LOGGER->info('АУДИТ НЕ ПРОИЗВЕДЁН!');
             return;
             //--- Нужен предок, но его нет
         }
         $encoded = 0;
         if (is_array($data)) {
             if (count($data) == 0) {
                 $data = null;
             } else {
                 $data = self::encodeData($data);
                 $encoded = 1;
             }
         }
         check_condition($data === null || is_string($data) || is_numeric($data), 'Illegal audit data type: ' . gettype($data) . ' for ' . $this);
         $recId = UtilsBean::inst()->saveAudit($parentId, $userId, $userIdAuthed, $this->PROCESS_CODE, $action, $data, $encoded);
         if ($this->LOGGER->isEnabled()) {
             if ($data !== null) {
                 $this->LOGGER->info('Данные кодированы: {}', $encoded ? "ДА ({$data})" : 'НЕТ');
             }
             $this->LOGGER->info('Информация сохранена в базу, id={}', $recId);
         }
         if ($saveToSession) {
             SessionArrayHelper::setInt($actionSessionKey, $recId);
             $this->LOGGER->info("Данные о действии сохранены в сессию ({$actionSessionKey}={$recId})");
         }
         if ($hasParentIdInSession && $clearParent) {
             SessionArrayHelper::reset($parentActionSessionKey);
             $this->LOGGER->info('Данные о родительском действии удалены из сессии');
         }
         $this->LOGGER->info('АУДИТ ПРОИЗВЕДЁН.');
     } catch (Exception $ex) {
         //Не удалось записть аудит, но работа должна быть продолжена!
         ExceptionHandler::dumpError($ex);
     }
 }