public static function getList($userId, $taskId, array $parameters = array()) { $data = array(); $task = static::getTask($userId, $taskId); if ($task !== null && $task->checkCanRead()) { $res = \CTaskLog::GetList(array('CREATED_DATE' => 'DESC'), array('TASK_ID' => $taskId)); $tzDisabled = !\CTimeZone::enabled(); if ($tzDisabled) { \CTimeZone::enable(); } $tzOffset = \CTimeZone::getOffset(); if ($tzDisabled) { \CTimeZone::disable(); } while (true) { if ($parameters['ESCAPE_DATA']) { $item = $res->GetNext(); } else { $item = $res->fetch(); } if (!$item) { break; } // Adjust unix timestamps to "bitrix timestamps" if (isset(\CTaskLog::$arComparedFields[$item['FIELD']]) && \CTaskLog::$arComparedFields[$item['FIELD']] === 'date') { $item['TO_VALUE'] = $item['TO_VALUE'] + $tzOffset; $item['FROM_VALUE'] = $item['FROM_VALUE'] + $tzOffset; } $data[] = $item; } } return array('DATA' => $data, 'CAN' => array()); }
private function getGridData($gridId) { $grid = array('ID' => $gridId); $securityContext = $this->storage->getCurrentUserSecurityContext(); $parameters = array('with' => array('FILE', 'CREATE_USER'), 'filter' => array('IS_EXPIRED' => false, 'OBJECT.STORAGE_ID' => $this->storage->getId(), 'CREATED_BY' => $this->getUser()->getId())); $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('OBJECT_ID', 'OBJECT.CREATED_BY')); $items = ExternalLink::getModelList($parameters); Collection::sortByColumn($items, array('CREATE_TIME' => array(SORT_NUMERIC, SORT_ASC))); $urlManager = Driver::getInstance()->getUrlManager(); $rows = array(); foreach ($items as $externalLink) { /** @var ExternalLink $externalLink */ $exportData = $externalLink->toArray(); $nameSpecialChars = htmlspecialcharsbx($externalLink->getFile()->getName()); $createDateText = htmlspecialcharsbx((string) $externalLink->getCreateTime()); $columnName = "\n\t\t\t\t<table class=\"bx-disk-object-name\"><tr>\n\t\t\t\t\t\t<td style=\"width: 45px;\"><div data-object-id=\"{$externalLink->getId()}\" class=\"draggable bx-file-icon-container-small bx-disk-file-icon\"></div></td>\n\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$externalLink->getId()}\" href=\"\" data-bx-dateModify=\"{$createDateText}\">{$nameSpecialChars}</a></td>\n\t\t\t\t</tr></table>\n\t\t\t"; $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $externalLink->getCreatedBy())); $rows[] = array('data' => $exportData, 'columns' => array('CREATE_TIME' => formatDate('x', $externalLink->getCreateTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'UPDATE_TIME' => formatDate('x', $externalLink->getCreateTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'NAME' => $columnName, 'FORMATTED_SIZE' => CFile::formatSize($externalLink->getFile()->getSize()), 'CREATE_USER' => "\n\t\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($externalLink->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t\t"), 'actions' => array(array("PSEUDO_NAME" => "download", "DEFAULT" => true, "ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_ACT_DOWNLOAD'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadFile($externalLink->getFile()) . "')"), array("PSEUDO_NAME" => "disable_external_link", "ICONCLASS" => "disable_external_link", "TEXT" => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_ACT_DISABLE_EXTERNAL_LINK'), "SHORT_TEXT" => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_ACT_DISABLE_EXTERNAL_LINK_SHORT'), "ONCLICK" => "BX.Disk['ExternalLinkListClass_{$this->getComponentId()}'].disableExternalLink({$externalLink->getId()}, {$externalLink->getObjectId()})"))); } unset($externalLink); $grid['MODE'] = 'list'; $grid['HEADERS'] = array(array('id' => 'ID', 'name' => 'ID', 'default' => false, 'show_checkbox' => true), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_COLUMN_NAME'), 'default' => true), array('id' => 'CREATE_TIME', 'name' => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_COLUMN_CREATE_TIME'), 'default' => true), array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_COLUMN_CREATE_USER'), 'default' => false), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_COLUMN_FORMATTED_SIZE'), 'default' => true)); $grid['ROWS'] = $rows; $grid['ROWS_COUNT'] = count($rows); $grid['FOOTER'] = array(); return $grid; }
/** * @param $userId * @return bool */ public function canRead($userId) { if ($this->canRead !== null) { return $this->canRead; } if (!Loader::includeModule('socialnetwork')) { return false; } $cacheTtl = 2592000; $cacheId = 'blog_post_socnet_general_' . $this->entityId . '_' . LANGUAGE_ID; $timezoneOffset = \CTimeZone::getOffset(); if ($timezoneOffset != 0) { $cacheId .= "_" . $timezoneOffset; } $cacheDir = '/blog/socnet_post/gen/' . intval($this->entityId / 100) . '/' . $this->entityId; $cache = new \CPHPCache(); if ($cache->initCache($cacheTtl, $cacheId, $cacheDir)) { $post = $cache->getVars(); } else { $cache->startDataCache(); $queryPost = \CBlogPost::getList(array(), array("ID" => $this->entityId), false, false, array("ID", "BLOG_ID", "PUBLISH_STATUS", "TITLE", "AUTHOR_ID", "ENABLE_COMMENTS", "NUM_COMMENTS", "VIEWS", "CODE", "MICRO", "DETAIL_TEXT", "DATE_PUBLISH", "CATEGORY_ID", "HAS_SOCNET_ALL", "HAS_TAGS", "HAS_IMAGES", "HAS_PROPS", "HAS_COMMENT_IMAGES")); $post = $queryPost->fetch(); $cache->endDataCache($post); } if (!$post) { $this->canRead = false; return false; } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $this->canRead = \CBlogPost::getSocNetPostPerms($this->entityId, true, $userId, $post["AUTHOR_ID"]) >= BLOG_PERMS_READ; return $this->canRead; }
public function appendIBlockEntry($url, $modifiedDate, $priority = 0) { if ($this->isExists()) { $this->appendEntry(array('XML_LOC' => $this->settings['PROTOCOL'] . '://' . \CBXPunycode::toASCII($this->settings['DOMAIN'], $e = null) . $url, 'XML_LASTMOD' => date('c', $modifiedDate - \CTimeZone::getOffset()), 'XML_PRIORITY' => $priority ? $priority : self::DEFAULT_PRIORITY)); } else { $this->addHeader(); $this->addIBlockEntry($url, $modifiedDate, $priority); $this->addFooter(); } }
function tasksFormatDate($in_date) { $date = $in_date; $strDate = false; if (!is_int($in_date)) { $date = MakeTimeStamp($in_date); } if ($date === false || $date === -1 || $date === 0) { $date = MakeTimeStamp($in_date); } // It can be other date on server (relative to client), ... $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } $ts = time() + CTimeZone::getOffset(); // ... so shift cur timestamp to compensate it. if ($bTzWasDisabled) { CTimeZone::disable(); } $curDateStrAtClient = date('d.m.Y', $ts); $yesterdayDateStrAtClient = date('d.m.Y', strtotime('-1 day', $ts)); if ($curDateStrAtClient === date('d.m.Y', $date)) { $strDate = FormatDate("today", $date); } elseif ($yesterdayDateStrAtClient === date('d.m.Y', $date)) { $strDate = FormatDate("yesterday", $date); } else { if (defined('FORMAT_DATE')) { $strDate = FormatDate(CDatabase::DateFormatToPHP(FORMAT_DATE), $date); } else { $strDate = FormatDate("d.m.Y", $date); } } return $strDate; }
/** * Function returns an cache identifier based on component parameters and environment. * * @param mixed $additionalCacheID * @return string */ public function getCacheID($additionalCacheID = false) { if (!$this->getSiteId()) { $SITE_ID = SITE_ID; } else { $SITE_ID = $this->getSiteId(); } if (!$this->getLanguageId()) { $LANGUAGE_ID = LANGUAGE_ID; } else { $LANGUAGE_ID = $this->getLanguageId(); } if (!$this->getSiteTemplateId()) { $SITE_TEMPLATE_ID = defined("SITE_TEMPLATE_ID") ? SITE_TEMPLATE_ID : ""; } else { $SITE_TEMPLATE_ID = $this->getSiteTemplateId(); } $cacheID = $SITE_ID . "|" . $LANGUAGE_ID . ($SITE_TEMPLATE_ID != "" ? "|" . $SITE_TEMPLATE_ID : "") . "|" . $this->__name . "|" . $this->getTemplateName() . "|"; foreach ($this->arParams as $k => $v) { if (strncmp("~", $k, 1)) { $cacheID .= "," . $k . "=" . serialize($v); } } if (($offset = CTimeZone::getOffset()) != 0) { $cacheID .= "|" . $offset; } if ($additionalCacheID !== false) { $cacheID .= "|" . serialize($additionalCacheID); } return $cacheID; }
private function getGridData($gridId) { $grid = array('ID' => $gridId); $filter = array(); $securityContext = $this->storage->getCurrentUserSecurityContext(); //shown trash can root if ($this->arParams['RELATIVE_PATH'] == '/') { $filter['DELETED_TYPE'] = ObjectTable::DELETED_TYPE_ROOT; $items = $this->folder->getDescendants($securityContext, array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => $filter)); } else { $filter['DELETED_TYPE'] = ObjectTable::DELETED_TYPE_CHILD; $items = $this->folder->getChildren($securityContext, array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => $filter)); } if (count($items)) { $this->folder->preloadOperationsForChildren($securityContext); } $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager(); $rows = array(); foreach ($items as $object) { /** @var File|Folder $object */ $exportData = $object->toArray(); $relativePath = trim($this->arParams['RELATIVE_PATH'], '/'); $detailPageFile = CComponentEngine::MakePathFromTemplate($this->arParams['PATH_TO_TRASHCAN_FILE_VIEW'], array('FILE_ID' => $object->getId(), 'TRASH_FILE_PATH' => ltrim($relativePath . '/' . $object->getOriginalName(), '/'))); $listingPage = rtrim(CComponentEngine::MakePathFromTemplate($this->arParams['PATH_TO_TRASHCAN_LIST'], array('TRASH_PATH' => $relativePath)), '/'); $isFolder = $object instanceof Folder; $actions = array(); $exportData['OPEN_URL'] = $urlManager->encodeUrn($isFolder ? $listingPage . '/' . $object->getOriginalName() : $detailPageFile); $actions[] = array("PSEUDO_NAME" => "open", "ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_OPEN'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "')"); if (!$isFolder) { $actions[] = array("PSEUDO_NAME" => "download", "ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_DOWNLOAD'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadFile($object) . "')"); } if ($object->isDeleted() && $object->canRestore($securityContext)) { $actions[] = array("ICONCLASS" => "restore", "PSEUDO_NAME" => "restore", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_RESTORE'), "ONCLICK" => "BX.Disk['TrashCanClass_{$this->getComponentId()}'].openConfirmRestore({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$object->getId()},\n\t\t\t\t\t\t\t\tname: '{$object->getName()}',\n\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t})"); } if ($object->canDelete($securityContext)) { $actions[] = array("ICONCLASS" => "destroy", "PSEUDO_NAME" => "destroy", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_DESTROY'), "ONCLICK" => "BX.Disk['TrashCanClass_{$this->getComponentId()}'].openConfirmDelete({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$object->getId()},\n\t\t\t\t\t\t\t\tname: '{$object->getName()}',\n\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t})"); } if ($isFolder) { $uri = $urlManager->encodeUrn($listingPage . '/' . $object->getOriginalName()); } else { $uri = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->encodeUrn($detailPageFile); } $iconClass = \Bitrix\Disk\Ui\Icon::getIconClassByObject($object); $name = htmlspecialcharsbx($object->getName()); $updateDateTime = $object->getUpdateTime(); $columnName = "\n\t\t\t\t<table class=\"bx-disk-object-name\"><tr>\n\t\t\t\t\t\t<td style=\"width: 45px;\"><div data-object-id=\"{$object->getId()}\" class=\"bx-file-icon-container-small {$iconClass}\"></div></td>\n\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$object->getId()}\" href=\"{$uri}\" data-bx-dateModify=\"" . htmlspecialcharsbx($updateDateTime) . "\">{$name}</a></td>\n\t\t\t\t</tr></table>\n\t\t\t"; $deletedTime = $object->getDeleteTime(); $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getCreatedBy())); $deletedByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getDeletedBy())); $columns = array('CREATE_TIME' => formatDate('x', $object->getCreateTime()->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'UPDATE_TIME' => formatDate('x', $updateDateTime->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'DELETE_TIME' => formatDate('x', $deletedTime->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'NAME' => $columnName, 'FORMATTED_SIZE' => $isFolder ? '' : CFile::formatSize($object->getSize()), 'CREATE_USER' => "\n\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($object->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t", 'DELETE_USER' => "\n\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$deletedByLink}\" id=\"\">" . htmlspecialcharsbx($object->getDeleteUser()->getFormattedName()) . "</a></div>\n\t\t\t\t"); $exportData['ICON_CLASS'] = $iconClass; $exportData['IS_SHARED'] = false; $exportData['IS_LINK'] = false; $tildaExportData = array(); foreach ($exportData as $exportName => $exportValue) { $tildaExportData['~' . $exportName] = $exportValue; } unset($exportRow); $rows[] = array('data' => array_merge($exportData, $tildaExportData), 'columns' => $columns, 'actions' => $actions, 'DELETE_TIME' => $deletedTime->getTimestamp()); } unset($object); Collection::sortByColumn($rows, array('DELETE_TIME' => SORT_DESC)); $grid['HEADERS'] = array(array('id' => 'ID', 'name' => 'ID', 'default' => false), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_NAME'), 'default' => true), array('id' => 'DELETE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_DELETE_TIME'), 'default' => true), array('id' => 'CREATE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_CREATE_TIME'), 'default' => false), array('id' => 'UPDATE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_UPDATE_TIME'), 'default' => false), array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_CREATE_USER'), 'default' => false), array('id' => 'DELETE_USER', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_DELETE_USER'), 'default' => false), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_FORMATTED_SIZE'), 'default' => true)); $grid['ROWS'] = $rows; $grid['ROWS_COUNT'] = count($rows); $grid['FOOTER'] = array(); return $grid; }
/** * Shows information about WAF stats in Admin's informer popup * @return bool|void */ public static function OnAdminInformerInsertItems() { /** @global CMain $APPLICATION */ global $APPLICATION; if ($APPLICATION->GetGroupRight("security") < "W") return false; $setupLink = '/bitrix/admin/security_filter.php?lang='.LANGUAGE_ID; $WAFAIParams = array( "TITLE" => getMessage("SECURITY_FILTER_INFORM_TITLE"), "COLOR" => "blue", "FOOTER" => '<a href="'.$setupLink.'">'.getMessage("SECURITY_FILTER_INFORM_LINK_TO_SETUP_ON").'</a>' ); try { if (self::IsActive()) { $days = COption::getOptionInt("main", "event_log_cleanup_days", 7); if($days > 7) $days = 7; $timestampX = ConvertTimeStamp(time()-$days*24*3600+CTimeZone::getOffset()); $eventLink = '/bitrix/admin/event_log.php?set_filter=Y&find_type=audit_type_id&find_audit_type[]=SECURITY_FILTER_SQL&find_audit_type[]=SECURITY_FILTER_XSS&find_audit_type[]=SECURITY_FILTER_XSS2&find_audit_type[]=SECURITY_FILTER_PHP&mod=security&find_timestamp_x_1='.$timestampX.'&lang='.LANGUAGE_ID; $eventCount = self::getEventsCount($timestampX); if($eventCount > 999) $eventCount = round($eventCount/1000,1).'K'; if($eventCount > 0) $descriptionText = getMessage("SECURITY_FILTER_INFORM_EVENT_COUNT").'<a href="'.$eventLink.'">'.$eventCount.'</a>'; else $descriptionText = getMessage("SECURITY_FILTER_INFORM_EVENT_COUNT_EMPTY"); $WAFAIParams["FOOTER"] = '<a href="'.$setupLink.'">'.getMessage("SECURITY_FILTER_INFORM_LINK_TO_SETUP").'</a>'; $WAFAIParams["ALERT"] = false; $WAFAIParams["HTML"] = ' <div class="adm-informer-item-section"> <span class="adm-informer-item-l"> <span class="adm-informer-strong-text">'.getMessage("SECURITY_FILTER_INFORM_FILTER_ON").'</span> <span>'.$descriptionText.'</span> </span> </div> '; } else { $WAFAIParams["ALERT"] = true; $WAFAIParams["HTML"] = ' <div class="adm-informer-item-section"> <span class="adm-informer-item-l"> <span class="adm-informer-strong-text">'.getMessage("SECURITY_FILTER_INFORM_FILTER_OFF").'</span> <span>'.getMessage("SECURITY_FILTER_INFORM_FILTER_ON_RECOMMENDATION", array("#LINK#" => $setupLink)).'</span> </span> </div> '; } } catch (Exception $e) { $WAFAIParams["TITLE"] .= " - ".getMessage("top_panel_ai_title_err"); $WAFAIParams["ALERT"] = true; $WAFAIParams["HTML"] = $e->getMessage(); } CAdminInformer::AddItem($WAFAIParams); return true; }
public static function getCurrentActivity($departmentId = 0, $section = null) { $data = array(); $fieldName = $section === null ? 'TOTAL' : $section; $currentHour = ConvertTimeStamp(mktime(date('G'), 0, 0), 'FULL'); $previousHour = ConvertTimeStamp(mktime(date('G') - 1, 0, 0), 'FULL'); $currentHourClient = ConvertTimeStamp(mktime(date('G'), 0, 0) + \CTimeZone::getOffset(), 'FULL'); $previousHourClient = ConvertTimeStamp(mktime(date('G') - 1, 0, 0) + \CTimeZone::getOffset(), 'FULL'); $result = DepartmentHourTable::getList(array('select' => array('HOUR', $fieldName), 'filter' => array('=DEPT_ID' => $departmentId, '=HOUR' => array($currentHourClient, $previousHourClient)))); while ($row = $result->fetch()) { $data[ConvertTimeStamp($row['HOUR']->getTimestamp(), 'FULL')] = $row[$fieldName]; } $currentActivity = isset($data[$currentHour]) ? (int) $data[$currentHour] : 0; if (isset($data[$previousHour])) { // emulation of [60 - CURRENT_MINUTES] of previous hour $currentActivity += round($data[$previousHour] * (1 - date('i') / 60)); } return $currentActivity; }
public static function setAuthentication(CurrentUser $user, $isPersistent = false) { /** @var $context \Freetrix\Main\HttpContext */ $context = \Freetrix\Main\Application::getInstance()->getContext(); $context->setUser($user); static::copyToSession($user); /** @var $response \Freetrix\Main\HttpResponse */ $response = $context->getResponse(); if (!$user->isAuthenticated()) { $cookie = new \Freetrix\Main\Web\Cookie("UIDH", "", time() - 3600); $response->addCookie($cookie); return; } $connection = \Freetrix\Main\Application::getDbConnection(); $sqlHelper = $connection->getSqlHelper(); $connection->queryExecute("UPDATE b_user SET " . " STORED_HASH = NULL, " . " LAST_LOGIN = "******", " . " TIMESTAMP_X = TIMESTAMP_X, " . " LOGIN_ATTEMPTS = 0, " . " TIME_ZONE_OFFSET = " . \CTimeZone::getOffset() . " " . "WHERE ID = " . $user->getUserId() . " "); $cookie = new \Freetrix\Main\Web\Cookie("LOGIN", $user->getLogin(), time() + 60 * 60 * 24 * 30 * 60); $cookie->setSpread(\Freetrix\Main\Config\Option::get("main", "auth_multisite", "N") == "Y" ? \Freetrix\Main\Web\Cookie::SPREAD_SITES : \Freetrix\Main\Web\Cookie::SPREAD_DOMAIN); $response->addCookie($cookie); if ($isPersistent || \Freetrix\Main\Config\Option::get("main", "auth_multisite", "N") == "Y") { $hash = $user->getSessionHash(); /** @var $request \Freetrix\Main\HttpRequest */ $request = $context->getRequest(); if ($isPersistent) { $cookie = new \Freetrix\Main\Web\Cookie("UIDH", $hash, time() + 60 * 60 * 24 * 30 * 60); } else { $cookie = new \Freetrix\Main\Web\Cookie("UIDH", $hash, 0); } $cookie->setSecure(\Freetrix\Main\Config\Option::get("main", "use_secure_password_cookies", "N") == "Y" && $request->isHttps()); $response->addCookie($cookie); $storedId = static::getStoredHashId($user, $hash); if ($storedId) { $connection->queryExecute("UPDATE b_user_stored_auth SET " . "\tLAST_AUTH = " . $sqlHelper->getCurrentDateTimeFunction() . ", " . "\t" . ($user->getAuthType() === static::AUTHENTICATED_BY_HASH ? "" : "TEMP_HASH='" . ($isPersistent ? "N" : "Y") . "', ") . " " . "\tIP_ADDR = '" . sprintf("%u", ip2long($request->getRemoteAddress())) . "' " . "WHERE ID = " . intval($storedId)); } else { $sqlTmp1 = ""; $sqlTmp2 = ""; if ($connection->getType() === "oracle") { $storedId = $connection->getIdentity("sq_b_user_stored_auth"); $sqlTmp1 = "ID, "; $sqlTmp2 = intval($storedId) . ", "; } $sql = "INSERT INTO b_user_stored_auth (" . $sqlTmp1 . "USER_ID, DATE_REG, LAST_AUTH, TEMP_HASH, " . " IP_ADDR, STORED_HASH) " . "VALUES (" . $sqlTmp2 . intval($user->getUserId()) . ", " . $sqlHelper->getCurrentDateTimeFunction() . ", " . " " . $sqlHelper->getCurrentDateTimeFunction() . ", '" . ($isPersistent ? "N" : "Y") . "', " . " '" . $sqlHelper->forSql(sprintf("%u", ip2long($request->getRemoteAddress()))) . "', " . " '" . $sqlHelper->forSql($hash) . "')"; $connection->queryExecute($sql); if ($connection->getType() !== "oracle") { $storedId = $connection->getIdentity(); } } $user->setStoredAuthId($storedId); } $event = new Main\Event("main", "OnUserLogin", array("USER" => $user)); $event->send(); if (\Freetrix\Main\Config\Option::get("main", "event_log_login_success", "N") === "Y") { \CEventLog::log("SECURITY", "USER_AUTHORIZE", "main", $user->getUserId()); } }
/** * Return datetime template for old api emulation. * * @return string */ public static function getDatetimeExpressionTemplate() { if (self::$datetimeTemplate === null) { $helper = Application::getConnection()->getSqlHelper(); $format = Context::getCurrent()->getCulture()->getDateTimeFormat(); $datetimeFieldName = '#FIELD#'; $datetimeField = $datetimeFieldName; if (\CTimeZone::enabled()) { $diff = \CTimeZone::getOffset(); if ($diff != 0) { $datetimeField = $helper->addSecondsToDateTime($diff, $datetimeField); } unset($diff); } self::$datetimeTemplate = str_replace(array('%', $datetimeFieldName), array('%%', '%1$s'), $helper->formatDate($format, $datetimeField)); unset($datetimeField, $datetimeFieldName, $format, $helper); } return self::$datetimeTemplate; }
public static function UnifyFields(&$value, $key) { if (array_key_exists($key, self::$arComparedFields)) { switch (self::$arComparedFields[$key]) { case "integer": $value = intval($value); break; case "string": $value = trim($value); break; case "array": if (!is_array($value)) { $value = explode(",", $value); } $value = array_unique(array_filter(array_map("trim", $value))); sort($value); break; case "date": $value = MakeTimeStamp($value); if (!$value) { $value = strtotime($value); // There is correct Unix timestamp in return value // CTimeZone::getOffset() substraction here??? } else { // It can be other date on server (relative to client), ... $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } $value -= CTimeZone::getOffset(); // get correct UnixTimestamp if ($bTzWasDisabled) { CTimeZone::disable(); } // We mustn't store result of MakeTimestamp() in DB, // because it is shifted for time zone offset already, // which can't be restored. } break; case "bool": if ($value != "Y") { $value = "N"; } break; } } }
private static function getSqlForTimestamps($key, $val, $userID, $sAliasPrefix, $bGetZombie) { static $ts = null; // some fixed timestamp of "now" (for consistency) if ($ts === null) { $ts = CTasksPerHitOption::getHitTimestamp(); } $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } // Adjust UNIX TS to "Bitrix timestamp" $tzOffset = CTimeZone::getOffset(); $val += $tzOffset; $ts += $tzOffset; if ($bTzWasDisabled) { CTimeZone::disable(); } $arSqlSearch = array(); $arFilter = array('::LOGIC' => 'AND'); $key = ltrim($key); $res = CTasks::MkOperationFilter($key); $fieldName = substr($res["FIELD"], 5, -3); // Cutoff prefix "META:" and suffix "_TS" $cOperationType = $res["OPERATION"]; $operationSymbol = substr($key, 0, -1 * strlen($res["FIELD"])); if (substr($cOperationType, 0, 1) !== '#') { switch ($operationSymbol) { case '<': $operationCode = CTaskFilterCtrl::OP_STRICTLY_LESS; break; case '>': $operationCode = CTaskFilterCtrl::OP_STRICTLY_GREATER; break; case '<=': $operationCode = CTaskFilterCtrl::OP_LESS_OR_EQUAL; break; case '>=': $operationCode = CTaskFilterCtrl::OP_GREATER_OR_EQUAL; break; case '!=': $operationCode = CTaskFilterCtrl::OP_NOT_EQUAL; break; case '': case '=': $operationCode = CTaskFilterCtrl::OP_EQUAL; break; default: CTaskAssert::log('Unknown operation code: ' . $operationSymbol . '; $key = ' . $key . '; it will be silently ignored, incorrect results expected', CTaskAssert::ELL_ERROR); return $arSqlSearch; break; } } else { $operationCode = (int) substr($cOperationType, 1); } $date1 = $date2 = $cOperationType1 = $cOperationType2 = null; // Convert cOperationType to format accepted by self::FilterCreate switch ($operationCode) { case CTaskFilterCtrl::OP_EQUAL: case CTaskFilterCtrl::OP_DATE_TODAY: case CTaskFilterCtrl::OP_DATE_YESTERDAY: case CTaskFilterCtrl::OP_DATE_TOMORROW: case CTaskFilterCtrl::OP_DATE_CUR_WEEK: case CTaskFilterCtrl::OP_DATE_PREV_WEEK: case CTaskFilterCtrl::OP_DATE_NEXT_WEEK: case CTaskFilterCtrl::OP_DATE_CUR_MONTH: case CTaskFilterCtrl::OP_DATE_PREV_MONTH: case CTaskFilterCtrl::OP_DATE_NEXT_MONTH: case CTaskFilterCtrl::OP_DATE_NEXT_DAYS: case CTaskFilterCtrl::OP_DATE_LAST_DAYS: $cOperationType1 = '>='; $cOperationType2 = '<='; break; case CTaskFilterCtrl::OP_LESS_OR_EQUAL: $cOperationType1 = '<='; break; case CTaskFilterCtrl::OP_GREATER_OR_EQUAL: $cOperationType1 = '>='; break; case CTaskFilterCtrl::OP_NOT_EQUAL: $cOperationType1 = '<'; $cOperationType2 = '>'; break; case CTaskFilterCtrl::OP_STRICTLY_LESS: $cOperationType1 = '<'; break; case CTaskFilterCtrl::OP_STRICTLY_GREATER: $cOperationType1 = '>'; break; default: CTaskAssert::log('Unknown operation code: ' . $operationCode . '; $key = ' . $key . '; it will be silently ignored, incorrect results expected', CTaskAssert::ELL_ERROR); return $arSqlSearch; break; } // Convert/generate dates $ts1 = $ts2 = null; switch ($operationCode) { case CTaskFilterCtrl::OP_DATE_TODAY: $ts1 = $ts2 = $ts; break; case CTaskFilterCtrl::OP_DATE_YESTERDAY: $ts1 = $ts2 = $ts - 86400; break; case CTaskFilterCtrl::OP_DATE_TOMORROW: $ts1 = $ts2 = $ts + 86400; break; case CTaskFilterCtrl::OP_DATE_CUR_WEEK: $weekDay = date('N'); // numeric representation of the day of the week (1 to 7) $ts1 = $ts - ($weekDay - 1) * 86400; $ts2 = $ts + (7 - $weekDay) * 86400; break; case CTaskFilterCtrl::OP_DATE_PREV_WEEK: $weekDay = date('N'); // numeric representation of the day of the week (1 to 7) $ts1 = $ts - ($weekDay - 1 + 7) * 86400; $ts2 = $ts - $weekDay * 86400; break; case CTaskFilterCtrl::OP_DATE_NEXT_WEEK: $weekDay = date('N'); // numeric representation of the day of the week (1 to 7) $ts1 = $ts + (7 - $weekDay + 1) * 86400; $ts2 = $ts + (7 - $weekDay + 7) * 86400; break; case CTaskFilterCtrl::OP_DATE_CUR_MONTH: $ts1 = mktime(0, 0, 0, date('n', $ts), 1, date('Y', $ts)); $ts2 = mktime(23, 59, 59, date('n', $ts) + 1, 0, date('Y', $ts)); break; case CTaskFilterCtrl::OP_DATE_PREV_MONTH: $ts1 = mktime(0, 0, 0, date('n', $ts) - 1, 1, date('Y', $ts)); $ts2 = mktime(23, 59, 59, date('n', $ts), 0, date('Y', $ts)); break; case CTaskFilterCtrl::OP_DATE_NEXT_MONTH: $ts1 = mktime(0, 0, 0, date('n', $ts) + 1, 1, date('Y', $ts)); $ts2 = mktime(23, 59, 59, date('n', $ts) + 2, 0, date('Y', $ts)); break; case CTaskFilterCtrl::OP_DATE_LAST_DAYS: $ts1 = $ts - (int) $val * 86400; $ts2 = $ts; break; case CTaskFilterCtrl::OP_DATE_NEXT_DAYS: $ts1 = $ts; $ts2 = $ts + (int) $val * 86400; break; case CTaskFilterCtrl::OP_GREATER_OR_EQUAL: case CTaskFilterCtrl::OP_LESS_OR_EQUAL: case CTaskFilterCtrl::OP_STRICTLY_LESS: case CTaskFilterCtrl::OP_STRICTLY_GREATER: $ts1 = $val; break; case CTaskFilterCtrl::OP_EQUAL: $ts1 = mktime(0, 0, 0, date('n', $val), date('j', $val), date('Y', $val)); $ts2 = mktime(23, 59, 59, date('n', $val), date('j', $val), date('Y', $val)); break; case CTaskFilterCtrl::OP_NOT_EQUAL: $ts1 = mktime(0, 0, 0, date('n', $val), date('j', $val), date('Y', $val)); $ts2 = mktime(23, 59, 59, date('n', $val), date('j', $val), date('Y', $val)); break; default: CTaskAssert::log('Unknown operation code: ' . $operationCode . '; $key = ' . $key . '; it will be silently ignored, incorrect results expected', CTaskAssert::ELL_ERROR); return $arSqlSearch; break; } if ($ts1) { $date1 = ConvertTimeStamp(mktime(0, 0, 0, date('n', $ts1), date('j', $ts1), date('Y', $ts1)), 'FULL'); } if ($ts2) { $date2 = ConvertTimeStamp(mktime(23, 59, 59, date('n', $ts2), date('j', $ts2), date('Y', $ts2)), 'FULL'); } if ($cOperationType1 !== null && $date1 !== null) { $arrayKey = $cOperationType1 . $fieldName; while (isset($arFilter[$arrayKey])) { $arrayKey = ' ' . $arrayKey; } $arFilter[$arrayKey] = $date1; } if ($cOperationType2 !== null && $date2 !== null) { $arrayKey = $cOperationType2 . $fieldName; while (isset($arFilter[$arrayKey])) { $arrayKey = ' ' . $arrayKey; } $arFilter[$arrayKey] = $date2; } $arSqlSearch[] = self::GetSqlByFilter($arFilter, $userID, $sAliasPrefix, $bGetZombie); return $arSqlSearch; }
function AddMessage($mailbox_id, $message, $charset) { global $DB; list($obHeader, $message_body_html, $message_body, $arMessageParts) = CMailMessage::parseMessage($message, $charset); $arFields = array("MAILBOX_ID" => $mailbox_id, "HEADER" => $obHeader->strHeader, "FIELD_DATE_ORIGINAL" => $obHeader->GetHeader("DATE"), "NEW_MESSAGE" => "Y", "FIELD_FROM" => $obHeader->GetHeader("FROM"), "FIELD_REPLY_TO" => $obHeader->GetHeader("REPLY-TO"), "FIELD_TO" => $obHeader->GetHeader("TO"), "FIELD_CC" => $obHeader->GetHeader("CC"), "FIELD_BCC" => ($obHeader->GetHeader('X-Original-Rcpt-to') != '' ? $obHeader->GetHeader('X-Original-Rcpt-to') . ($obHeader->GetHeader("BCC") != '' ? ', ' : '') : '') . $obHeader->GetHeader("BCC"), "MSG_ID" => trim($obHeader->GetHeader("MESSAGE-ID"), " <>"), "IN_REPLY_TO" => trim($obHeader->GetHeader("IN-REPLY-TO"), " <>"), "FIELD_PRIORITY" => IntVal($obHeader->GetHeader("X-PRIORITY")), "MESSAGE_SIZE" => strlen($message), "SUBJECT" => $obHeader->GetHeader("SUBJECT"), "BODY" => rtrim($message_body)); if (COption::GetOptionString("mail", "save_src", B_MAIL_SAVE_SRC) == "Y") { $arFields["FULL_TEXT"] = $message; } if ($message_body_html !== false) { $arFields["FOR_SPAM_TEST"] = $obHeader->strHeader . " " . $message_body_html; } else { $arFields["FOR_SPAM_TEST"] = $obHeader->strHeader . " " . $message_body; } $arFields["SPAM"] = "?"; if (COption::GetOptionString("mail", "spam_check", B_MAIL_CHECK_SPAM) == "Y") { $arSpam = CMailFilter::GetSpamRating($arFields["FOR_SPAM_TEST"]); $arFields["SPAM_RATING"] = $arSpam["RATING"]; $arFields["SPAM_WORDS"] = $arSpam["WORDS"]; $arFields["SPAM_LAST_RESULT"] = "Y"; } if (CMailUtil::IsSizeAllowed(strlen(implode(",", $arFields)))) { $MESSAGE_ID = CMailMessage::Add($arFields); CMailLog::AddMessage(array("MAILBOX_ID" => $mailbox_id, "MESSAGE_ID" => $MESSAGE_ID, "STATUS_GOOD" => "Y", "LOG_TYPE" => "NEW_MESSAGE", "MESSAGE" => $arFields["SUBJECT"] . " (" . $arFields["MESSAGE_SIZE"] . ") " . (COption::GetOptionString("mail", "spam_check", B_MAIL_CHECK_SPAM) == "Y" ? "[" . Round($arFields["SPAM_RATING"], 3) . "]" : ""))); $atchCnt = 0; if (COption::GetOptionString("mail", "save_attachments", B_MAIL_SAVE_ATTACHMENTS) == "Y") { foreach ($arMessageParts as $part) { $arField = array("MESSAGE_ID" => $MESSAGE_ID, "FILE_NAME" => $part["FILENAME"], "CONTENT_TYPE" => $part["CONTENT-TYPE"], "FILE_DATA" => $part["BODY"], "CONTENT_ID" => $part["CONTENT-ID"]); if (CMailMessage::AddAttachment($arField)) { $atchCnt++; } } // foreach($arMessageParts as $part) } $arFields['ID'] = $MESSAGE_ID; $arFields['ATTACHMENTS'] = $atchCnt; if (is_set($arFields, 'FIELD_DATE_ORIGINAL') && !is_set($arFields, 'FIELD_DATE')) { $arFields['FIELD_DATE'] = $DB->formatDate(date('d.m.Y H:i:s', strtotime($arFields['FIELD_DATE_ORIGINAL']) + CTimeZone::getOffset()), 'DD.MM.YYYY HH:MI:SS', CLang::GetDateFormat('FULL')); } CMailFilter::Filter($arFields, "R"); return $MESSAGE_ID; } else { CMailLog::AddMessage(array("MAILBOX_ID" => $mailbox_id, "STATUS_GOOD" => "N", "LOG_TYPE" => "NEW_MESSAGE", "MESSAGE" => "Big message size, check mysql max_allow_packet.")); } }
/** * Not part of public API, for internal use only. * @deprecated * @access private */ public static function getTimeZoneOffset($userId = false) { $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } if ($userId === false) { $tzOffset = CTimeZone::getOffset(); } else { $tzOffset = CTimeZone::getOffset($userId); } if ($bTzWasDisabled) { CTimeZone::disable(); } return $tzOffset; }
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule("learning")) { ShowError(GetMessage("LEARNING_MODULE_NOT_FOUND")); return; } global $USER; $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } if ($userId === false) { $tzOffset = CTimeZone::getOffset(); } else { $tzOffset = CTimeZone::getOffset($userId); } if ($bTzWasDisabled) { CTimeZone::disable(); } $nowDateStr = ConvertTimeStamp(time() + $tzOffset, 'FULL'); $rs = CLearningGroup::getList(array(), array('MEMBER_ID' => $USER->getId(), 'ACTIVE' => 'Y', '<ACTIVE_FROM' => $nowDateStr, '>ACTIVE_TO' => $nowDateStr)); while ($ar = $rs->fetch()) { CLearnParsePermissionsFromFilter::registerAvailableCourse($ar['COURSE_LESSON_ID']); } $arParams["SORBY"] = isset($arParams["~SORBY"]) ? trim($arParams["~SORBY"]) : "SORT"; $arParams["SORORDER"] = isset($arParams["~SORORDER"]) ? trim($arParams["~SORORDER"]) : "ASC"; $arParams["CHECK_PERMISSIONS"] = isset($arParams["CHECK_PERMISSIONS"]) && $arParams["CHECK_PERMISSIONS"] == "N" ? "N" : "Y"; $arParams["COURSE_DETAIL_TEMPLATE"] = isset($arParams["COURSE_DETAIL_TEMPLATE"]) ? htmlspecialcharsbx($arParams["COURSE_DETAIL_TEMPLATE"]) : "course/index.php?COURSE_ID=#COURSE_ID#"; $arParams["COURSES_PER_PAGE"] = intval($arParams["COURSES_PER_PAGE"]) > 0 ? intval($arParams["COURSES_PER_PAGE"]) : 20; //Set Title
private static function convertDateStringToTimestamp($operation, $value) { switch ($operation) { case self::OP_DATE_TODAY: case self::OP_DATE_YESTERDAY: case self::OP_DATE_TOMORROW: case self::OP_DATE_CUR_WEEK: case self::OP_DATE_PREV_WEEK: case self::OP_DATE_NEXT_WEEK: case self::OP_DATE_CUR_MONTH: case self::OP_DATE_PREV_MONTH: case self::OP_DATE_NEXT_MONTH: $value = ''; break; case self::OP_DATE_LAST_DAYS: case self::OP_DATE_NEXT_DAYS: $value = (int) $value; break; default: case self::OP_EQUAL: case self::OP_NOT_EQUAL: case self::OP_STRICTLY_LESS: case self::OP_STRICTLY_GREATER: case self::OP_LESS_OR_EQUAL: case self::OP_GREATER_OR_EQUAL: $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } // get correct UnixTimestamp $value = (int) MakeTimeStamp($value) - CTimeZone::getOffset(); if ($bTzWasDisabled) { CTimeZone::disable(); } break; } return $value; }
$activeFromMap = CLearnAccessMacroses::getActiveLearningChaptersPeriod($courseLessonId, $USER->getId()); if ($activeFromMap !== false) { $arResult['LEARNING_GROUP_CHAPTERS_ACTIVE_FROM'] = $activeFromMap; } $oPath = new CLearnPath(); $oPath->ImportUrlencoded($arParams['LESSON_PATH']); $arPath = $oPath->GetPathAsArray(); if (count($arPath) >= 2) { $secondLevelLesson = $arPath[1]; if (isset($arResult['LEARNING_GROUP_CHAPTERS_ACTIVE_FROM'][$secondLevelLesson])) { $activeFrom = $arResult['LEARNING_GROUP_CHAPTERS_ACTIVE_FROM'][$secondLevelLesson]; $bTzWasDisabled = !CTimeZone::enabled(); if ($bTzWasDisabled) { CTimeZone::enable(); } $tzOffset = CTimeZone::getOffset(); if ($bTzWasDisabled) { CTimeZone::disable(); } // Adjust unix timestamp to bitrix-timestamp for correct comparision below $nowTimestamp = time() + $tzOffset; if ($nowTimestamp < MakeTimeStamp($activeFrom)) { $delayed = $activeFrom; } } } } } $lastDirtyCacheTS = COption::GetOptionString('learning', CLearnCacheOfLessonTreeComponent::OPTION_TS, time()); // was: if($this->StartResultCache(false, $USER->GetGroups())) $additionalCacheID = CLearnAccess::GetAccessSymbolsHashForSiteUser() . '|' . $ratingTransistor . '|' . $lastDirtyCacheTS . '|' . ($delayed === false ? 'ND' : 'D');
/** * Return WAF events count for Admin's informer popup and Admin's gadget * @param string $pTimestamp - from date * @return integer */ public function getEventsCount($pTimestamp = '') { if (!$this->isDBEngineActive) { return 0; } /** * @global CCacheManager $CACHE_MANAGER * @global CDataBase $DB */ global $DB, $CACHE_MANAGER; $ttl = 3600; $cacheId = 'sec_events_count'; $cacheDir = '/security/events'; if ($CACHE_MANAGER->read($ttl, $cacheId, $cacheDir)) { $result = $CACHE_MANAGER->get($cacheId); } else { if (strlen($pTimestamp) <= 0) { $days = COption::getOptionInt("main", "event_log_cleanup_days", 7); if ($days > 7) { $days = 7; } $pTimestamp = convertTimeStamp(time() - $days * 24 * 3600 + CTimeZone::getOffset()); } $arAudits = array("SECURITY_FILTER_SQL", "SECURITY_FILTER_XSS", "SECURITY_FILTER_XSS2", "SECURITY_FILTER_PHP"); $strAuditsSql = implode("', '", $arAudits); $strSql = "\n\t\t\t\tSELECT COUNT(ID) AS COUNT\n\t\t\t\tFROM\n\t\t\t\t\tb_event_log\n\t\t\t\tWHERE\n\t\t\t\t\tAUDIT_TYPE_ID in ('" . $strAuditsSql . "')\n\t\t\t\tAND\n\t\t\t\t\t(MODULE_ID = 'security' and MODULE_ID is not null)\n\t\t\t\tAND\n\t\t\t\t\tTIMESTAMP_X >= " . $DB->charToDateFunction($DB->forSQL($pTimestamp)) . "\n\t\t\t"; $res = $DB->query($strSql, false, "FILE: " . __FILE__ . "<br>LINE: " . __LINE__); if ($arRes = $res->fetch()) { $result = $arRes["COUNT"]; } else { $result = 0; } $CACHE_MANAGER->set($cacheId, $result); } return $result; }
private function getGridData($gridId, $showDeleted = false) { $grid = array('ID' => $gridId); $gridOptions = new CGridOptions($grid['ID']); $gridSort = $gridOptions->getSorting(array('sort' => array('NAME' => 'ASC'), 'vars' => array('by' => 'by', 'order' => 'order'))); $filter = array(); $grid['SORT'] = $gridSort['sort']; $grid['SORT_VARS'] = $gridSort['vars']; $grid['MODE'] = $this->getViewMode(); $possibleColumnForSorting = array('UPDATE_TIME' => array('ALIAS' => 'UPDATE_TIME', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_UPDATE_TIME')), 'NAME' => array('ALIAS' => 'NAME', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_NAME')), 'FORMATTED_SIZE' => array('ALIAS' => 'SIZE', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_FORMATTED_SIZE'))); $byColumn = key($grid['SORT']); if (!isset($possibleColumnForSorting[$byColumn]) || strtolower($grid['SORT'][$byColumn]) !== 'desc' && strtolower($grid['SORT'][$byColumn]) !== 'asc') { $grid['SORT'] = array(); } $order = $grid['SORT']; $byColumn = key($order); $sortingColumns = array('TYPE' => array(SORT_NUMERIC, SORT_ASC), $possibleColumnForSorting[$byColumn]['ALIAS'] => strtolower($order[$byColumn]) === 'asc' ? SORT_ASC : SORT_DESC); if ($byColumn !== 'NAME') { $sortingColumns[$possibleColumnForSorting['NAME']['ALIAS']] = SORT_ASC; } $securityContext = $this->storage->getCurrentUserSecurityContext(); $proxyType = $this->storage->getProxyType(); $isStorageCurrentUser = $proxyType instanceof ProxyType\User && $proxyType->getTitleForCurrentUser() != $proxyType->getTitle(); $parameters = array('with' => array('CREATE_USER'), 'filter' => array('PARENT_ID' => $this->folder->getRealObjectId(), 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE)); $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY')); $needPagination = $this->needPagination(); $pageNumber = (int) $this->request->getQuery('pageNumber'); if ($pageNumber <= 0) { $pageNumber = 1; } if ($needPagination) { $parameters['order'] = array(); foreach ($sortingColumns as $columnName => $columnData) { if (is_array($columnData)) { $parameters['order'][$columnName] = in_array(SORT_DESC, $columnData, true) ? 'DESC' : 'ASC'; } else { $parameters['order'][$columnName] = SORT_DESC === $columnData ? 'DESC' : 'ASC'; } } unset($columnName, $columnData); $parameters['limit'] = self::COUNT_ON_PAGE + 1; // +1 because we want to know about existence next page $parameters['offset'] = self::COUNT_ON_PAGE * ($pageNumber - 1); } $this->folder->preloadOperationsForChildren($securityContext); $sharedObjectIds = $this->getUserShareObjectIds(); $isDesktopDiskInstall = \Bitrix\Disk\Desktop::isDesktopDiskInstall(); $nowTime = time() + CTimeZone::getOffset(); $fullFormatWithoutSec = preg_replace('/:s$/', '', CAllDatabase::dateFormatToPHP(CSite::GetDateFormat("FULL"))); $urlManager = Driver::getInstance()->getUrlManager(); $rows = array(); $storageTitle = $proxyType->getTitle(); $isEnabledShowExtendedRights = $this->storage->isEnabledShowExtendedRights(); $result = $this->folder->getList($parameters); $countObjectsOnPage = 0; $needShowNextPagePagination = false; while ($row = $result->fetch()) { $countObjectsOnPage++; if ($needPagination && $countObjectsOnPage > self::COUNT_ON_PAGE) { $needShowNextPagePagination = true; break; } $object = BaseObject::buildFromArray($row); /** @var File|Folder $object */ $name = $object->getName(); $objectId = $object->getId(); $exportData = array('TYPE' => $object->getType(), 'NAME' => $name, 'ID' => $objectId); $relativePath = trim($this->arParams['RELATIVE_PATH'], '/'); $detailPageFile = CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_FILE_VIEW'], array('FILE_ID' => $objectId, 'FILE_PATH' => ltrim($relativePath . '/' . $name, '/'))); $listingPage = rtrim(CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_FOLDER_LIST'], array('PATH' => $relativePath)), '/'); $isFolder = $object instanceof Folder; $actions = $tileActions = $columns = array(); if ($object->canRead($securityContext)) { $exportData['OPEN_URL'] = $urlManager->encodeUrn($isFolder ? $listingPage . '/' . $name . '/' : $detailPageFile); $actions[] = array("PSEUDO_NAME" => "open", "DEFAULT" => true, "ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_OPEN'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "')"); if (!$object->canChangeRights($securityContext) && !$object->canShare($securityContext)) { $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk.showSharingDetailWithoutEdit({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } elseif ($object->canChangeRights($securityContext)) { $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showSharingDetailWithChangeRights({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } elseif ($object->canShare($securityContext)) { $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showSharingDetailWithSharing({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } if ($isEnabledShowExtendedRights && !$object->isLink() && $object->canChangeRights($securityContext)) { $actions[] = array("PSEUDO_NAME" => "rights", "ICONCLASS" => "rights", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_RIGHTS_SETTINGS'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showRightsOnObjectDetail({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } if (!$isFolder) { $actions[] = array("PSEUDO_NAME" => "download", "ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_DOWNLOAD'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadFile($object) . "')"); } $actions[] = array("PSEUDO_NAME" => "copy", "ICONCLASS" => "copy", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_COPY'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openCopyModalWindow({\n\t\t\t\t\t\tid: {$this->storage->getRootObjectId()},\n\t\t\t\t\t\tname: '" . CUtil::JSEscape($storageTitle) . "'\n\t\t\t\t\t}, {\n\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "'\n\t\t\t\t\t});"); if ($object->canDelete($securityContext)) { $actions[] = array("PSEUDO_NAME" => "move", "ICONCLASS" => "move", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_MOVE'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openMoveModalWindow({\n\t\t\t\t\t\t\tid: {$this->storage->getRootObjectId()},\n\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($storageTitle) . "'\n\t\t\t\t\t\t}, {\n\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "'\n\t\t\t\t\t\t});"); } if (!$isStorageCurrentUser && (!isset($sharedObjectIds[$object->getRealObjectId()]) || $sharedObjectIds[$object->getRealObjectId()]['TO_ENTITY'] != Sharing::CODE_USER . $this->getUser()->getId())) { $actions[] = array("PSEUDO_NAME" => "connect", "ICONCLASS" => "connect", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_CONNECT'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].connectObjectToDisk({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "',\n\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});"); } if (!$isFolder) { $actions[] = array("ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_GET_EXT_LINK'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].getExternalLink({$objectId});"); $downloadLink = $urlManager->getUrlForShowFile($object, array(), true); $actions[] = array("ICONCLASS" => "show", 'PSEUDO_NAME' => 'internal_link', 'PSEUDO_VALUE' => $downloadLink, "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_COPY_INTERNAL_LINK'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].getInternalLink('{$downloadLink}');"); $actions[] = array("ICONCLASS" => "history", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_HISTORY'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "#tab-history')"); } } if ($object->canRename($securityContext)) { $actions[] = array("TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_RENAME'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].renameInline({$objectId})"); } if ((!empty($sharedObjectIds[$objectId]) || $object->isLink()) && $object->canRead($securityContext)) { $tileActions['SHARE_INFO'] = array("ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_DETAIL_SHARE_INFO'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showShareInfoSmallView({\n\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t }\n\t\t\t\t\t})"); } $columnsBizProc = array('BIZPROC' => ''); $bizprocIcon = array('BIZPROC' => ''); if ($this->arParams['STATUS_BIZPROC'] && !$isFolder) { list($actions, $columnsBizProc, $bizprocIcon) = $this->getBizProcData($object, $securityContext, $actions, $columnsBizProc, $bizprocIcon, $exportData); } if ($object->canDelete($securityContext)) { if ($object->isLink()) { $actions[] = array("PSEUDO_NAME" => "detach", "ICONCLASS" => "detach", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_DETACH_BUTTON'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openConfirmDetach({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } elseif ($object->getCode() !== Folder::CODE_FOR_UPLOADED_FILES) { $actions[] = array("PSEUDO_NAME" => "delete", "ICONCLASS" => "delete", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_MARK_DELETED'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openConfirmDelete({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t },\n\t\t\t\t\t\t\t\tcanDelete: {$object->canDelete($securityContext)}\n\t\t\t\t\t\t\t})"); } } $iconClass = Ui\Icon::getIconClassByObject($object, !empty($sharedObjectIds[$objectId])); $dataAttributesForViewer = ''; if ($isFolder) { $dataAttributesForViewer = Ui\Viewer::getAttributesByObject($object); if ($grid['MODE'] === 'tile') { $exportData['VIEWER_ATTRS'] = $dataAttributesForViewer; $dataAttributesForViewer = ''; } $nameSpecialChars = htmlspecialcharsbx($name); $columnName = "\n\t\t\t\t\t<table class=\"bx-disk-object-name\"><tr>\n\t\t\t\t\t\t\t<td style=\"width: 45px;\"><div data-object-id=\"{$objectId}\" class=\"draggable bx-file-icon-container-small {$iconClass}\"></div></td>\n\t\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$objectId}\" href=\"{$exportData['OPEN_URL']}\" {$dataAttributesForViewer}>{$nameSpecialChars}</a></td>\n\t\t\t\t\t</tr></table>\n\t\t\t\t"; } else { $externalId = ''; if ($isDesktopDiskInstall && $isStorageCurrentUser) { $externalId = "st{$this->storage->getId()}|{$this->storage->getRootObjectId()}|f{$objectId}"; } $dataAttributesForViewer = Ui\Viewer::getAttributesByObject($object, array('canUpdate' => $object->canUpdate($securityContext), 'relativePath' => $relativePath . '/' . $name, 'externalId' => $externalId)); if ($grid['MODE'] === 'tile') { $exportData['VIEWER_ATTRS'] = $dataAttributesForViewer; $dataAttributesForViewer = ''; } $nameSpecialChars = htmlspecialcharsbx($name); $columnName = "\n\t\t\t\t\t<table class=\"bx-disk-object-name\"><tr>\n\t\t\t\t\t\t<td style=\"width: 45px;\"><div data-object-id=\"{$objectId}\" class=\"draggable bx-file-icon-container-small {$iconClass}\"></div></td>\n\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$objectId}\" href=\"{$exportData['OPEN_URL']}\" {$dataAttributesForViewer}>{$nameSpecialChars}</a></td>\n\t\t\t\t\t\t<td>{$bizprocIcon['BIZPROC']}</td>\n\t\t\t\t\t</tr></table>\n\t\t\t\t"; } $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getCreatedBy())); $timestampCreate = $object->getCreateTime()->toUserTime()->getTimestamp(); $timestampUpdate = $object->getUpdateTime()->toUserTime()->getTimestamp(); $columns = array('CREATE_TIME' => $nowTime - $timestampCreate > 158400 ? formatDate($fullFormatWithoutSec, $timestampCreate, $nowTime) : formatDate('x', $timestampCreate, $nowTime), 'UPDATE_TIME' => $nowTime - $timestampCreate > 158400 ? formatDate($fullFormatWithoutSec, $timestampUpdate, $nowTime) : formatDate('x', $timestampUpdate, $nowTime), 'NAME' => $columnName, 'FORMATTED_SIZE' => $isFolder ? '' : CFile::formatSize($object->getSize()), 'CREATE_USER' => "\n\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($object->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t"); if ($this->arParams['STATUS_BIZPROC']) { $columns['BIZPROC'] = $columnsBizProc["BIZPROC"]; } $exportData['ICON_CLASS'] = $iconClass; if ($grid['MODE'] === 'tile') { $exportData['IS_IMAGE'] = $isFolder ? false : \Bitrix\Disk\TypeFile::isImage($object); if ($exportData['IS_IMAGE']) { $exportData['SRC_IMAGE'] = $urlManager->getUrlForShowFile($object, array('exact' => 'Y', 'width' => 64, 'height' => 64)); } $exportData['UPDATE_TIME'] = $columns['UPDATE_TIME']; } $exportData['IS_SHARED'] = !empty($sharedObjectIds[$objectId]); $exportData['IS_LINK'] = $object->isLink(); $tildaExportData = array(); foreach ($exportData as $exportName => $exportValue) { $tildaExportData['~' . $exportName] = $exportValue; } unset($exportRow); $rows[] = array('data' => array_merge($exportData, $tildaExportData), 'columns' => $columns, 'actions' => $actions, 'tileActions' => $tileActions, 'TYPE' => $exportData['TYPE'], 'NAME' => $exportData['NAME'], 'UPDATE_TIME' => $object->getUpdateTime()->getTimestamp(), 'SIZE' => $isFolder ? 0 : $object->getSize()); } unset($object); if (!$needPagination) { Collection::sortByColumn($rows, $sortingColumns); } $grid['HEADERS'] = array(array('id' => 'ID', 'name' => 'ID', 'sort' => isset($possibleColumnForSorting['ID']) ? 'ID' : false, 'default' => false), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_NAME'), 'sort' => isset($possibleColumnForSorting['NAME']) ? 'NAME' : false, 'default' => true, 'editable' => array('size' => 45)), array('id' => 'CREATE_TIME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_CREATE_TIME'), 'sort' => isset($possibleColumnForSorting['CREATE_TIME']) ? 'CREATE_TIME' : false, 'default' => false), array('id' => 'UPDATE_TIME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_UPDATE_TIME'), 'sort' => isset($possibleColumnForSorting['UPDATE_TIME']) ? 'UPDATE_TIME' : false, 'default' => true), array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_CREATE_USER'), 'sort' => isset($possibleColumnForSorting['CREATE_USER']) ? 'CREATE_USER' : false, 'default' => false), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_FORMATTED_SIZE'), 'sort' => isset($possibleColumnForSorting['FORMATTED_SIZE']) ? 'FORMATTED_SIZE' : false, 'default' => true)); if ($this->arParams['STATUS_BIZPROC']) { $grid['HEADERS'][] = array('id' => 'BIZPROC', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_BIZPROC'), 'default' => false); } $grid['DATA_FOR_PAGINATION'] = array('ENABLED' => $needPagination); if ($needPagination) { $grid['DATA_FOR_PAGINATION']['SHOW_NEXT_PAGE'] = $needShowNextPagePagination; $grid['DATA_FOR_PAGINATION']['CURRENT_PAGE'] = $pageNumber; } $grid['COLUMN_FOR_SORTING'] = $possibleColumnForSorting; $grid['ROWS'] = $rows; $grid['ROWS_COUNT'] = count($rows); $grid['FOOTER'] = array(); if (isModuleInstalled('bitrix24')) { list($freeSpace, $diskSize) = $this->getDiskSpace(); $freeSpace = CFile::formatSize($freeSpace); $diskSize = CFile::formatSize($diskSize); $grid['FOOTER'] = array(array('custom_html' => ' <td class="tar" style="width: 100%;">' . Loc::getMessage('DISK_FOLDER_LIST_B24_LABEL_DISK_SPACE', array('#FREE_SPACE#' => '<span>' . $freeSpace, '#DISK_SIZE#' => $diskSize . '</span>')) . '</span></td> '), array('custom_html' => ' <td class="tar"><a class="bx-disk-mp-link-addhdd" href="' . Loc::getMessage('DISK_FOLDER_LIST_B24_URL_DISK_SPACE') . '" target="_blank">+ <span>' . Loc::getMessage('DISK_FOLDER_LIST_B24_APPEND_DISK_SPACE') . '</span></a></td> ')); } return $grid; }
/** * Function returns an cache identifier based on component parameters and environment. * * @return string * */ public function getCacheID($additionalCacheID = false) { $cacheID = SITE_ID."|".LANGUAGE_ID.(defined("SITE_TEMPLATE_ID")? "|".SITE_TEMPLATE_ID:"")."|".$this->__name."|".$this->getTemplateName()."|"; foreach($this->arParams as $k=>$v) if(strncmp("~", $k, 1)) $cacheID .= ",".$k."=".serialize($v); if(($offset = CTimeZone::getOffset()) <> 0) $cacheID .= "|".$offset; if ($additionalCacheID !== false) $cacheID .= "|".serialize($additionalCacheID); return $cacheID; }
function Update($ID, $arFields) { global $DB; $ID = Intval($ID); if (is_set($arFields, "FIELD_DATE_ORIGINAL") && !is_set($arFields, "FIELD_DATE")) { $date = preg_replace('/(?<=[\\s\\d])UT$/i', '+0000', $arFields['FIELD_DATE_ORIGINAL']); $arFields['FIELD_DATE'] = $DB->formatDate(date('d.m.Y H:i:s', strtotime($date) + CTimeZone::getOffset()), 'DD.MM.YYYY HH:MI:SS', CLang::getDateFormat('FULL')); } if (array_key_exists('SUBJECT', $arFields)) { $arFields['SUBJECT'] = strval(substr($arFields['SUBJECT'], 0, 255)); } $strUpdate = $DB->PrepareUpdate("b_mail_message", $arFields); $strSql = "UPDATE b_mail_message SET " . $strUpdate . " WHERE ID=" . $ID; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); return true; }