public static function set($moduleId, $name, $value = "", $siteId = false) { if (static::$cacheTtl === null) { static::$cacheTtl = self::getCacheTtl(); } if (static::$cacheTtl !== false) { $cache = Main\Application::getInstance()->getManagedCache(); $cache->clean("b_option"); } if ($siteId === false) { $context = Main\Application::getInstance()->getContext(); if ($context != null) { $siteId = $context->getSite(); } } $con = Main\Application::getConnection(); $sqlHelper = $con->getSqlHelper(); $strSqlWhere = sprintf("SITE_ID %s AND MODULE_ID = '%s' AND NAME = '%s'", $siteId == "" ? "IS NULL" : "= '" . $sqlHelper->forSql($siteId, 2) . "'", $sqlHelper->forSql($moduleId), $sqlHelper->forSql($name)); $res = $con->queryScalar("SELECT 'x' " . "FROM b_option " . "WHERE " . $strSqlWhere); if ($res != null) { $con->queryExecute("UPDATE b_option SET " . "\tVALUE = '" . $sqlHelper->forSql($value, 2000) . "' " . "WHERE " . $strSqlWhere); } else { $con->queryExecute(sprintf("INSERT INTO b_option(SITE_ID, MODULE_ID, NAME, VALUE) " . "VALUES(%s, '%s', '%s', '%s') ", $siteId == "" ? "NULL" : "'" . $sqlHelper->forSql($siteId, 2) . "'", $sqlHelper->forSql($moduleId, 50), $sqlHelper->forSql($name, 50), $sqlHelper->forSql($value, 2000))); } if ($siteId == "") { $siteId = '-'; } self::$options[$siteId][$moduleId][$name] = $value; self::loadTriggers($moduleId); $event = new Main\Event("main", "OnAfterSetOption_" . $name, array("value" => $value)); $event->send(); return; }
public function send($sender = null) { static $events = array(DataManager::EVENT_ON_BEFORE_ADD => true, DataManager::EVENT_ON_ADD => true, DataManager::EVENT_ON_AFTER_ADD => true, DataManager::EVENT_ON_BEFORE_UPDATE => true, DataManager::EVENT_ON_UPDATE => true, DataManager::EVENT_ON_AFTER_UPDATE => true, DataManager::EVENT_ON_BEFORE_DELETE => true, DataManager::EVENT_ON_DELETE => true, DataManager::EVENT_ON_AFTER_DELETE => true); if (isset($events[$this->entityEventType])) { //The event handler function name magically equals to the event type (e.g. "OnBeforeAdd"). //There are emtpy handlers in the DataManager class. $result = call_user_func_array(array($this->entity->getDataClass(), $this->entityEventType), array($this)); if ($result !== null && !$result instanceof EventResult) { $result = new EventResult(); } if ($result !== null) { $this->addResult($result); } } parent::send($sender); }
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()); } }