Beispiel #1
0
 public static function getPresetMailingList(array $params = null)
 {
     $resultList = array();
     $event = new \Bitrix\Main\Event('sender', 'OnPresetMailingList');
     $event->send();
     foreach ($event->getResults() as $eventResult) {
         if ($eventResult->getType() == \Bitrix\Main\EventResult::ERROR) {
             continue;
         }
         $eventResultParameters = $eventResult->getParameters();
         if (!empty($eventResultParameters)) {
             if (!empty($params['CODE'])) {
                 $eventResultParametersTmp = array();
                 foreach ($eventResultParameters as $preset) {
                     if ($params['CODE'] == $preset['CODE']) {
                         $eventResultParametersTmp[] = $preset;
                         break;
                     }
                 }
                 $eventResultParameters = $eventResultParametersTmp;
             }
             $resultList = array_merge($resultList, $eventResultParameters);
         }
     }
     $resultListTmp = array();
     foreach ($resultList as $result) {
         if (empty($result['TRIGGER']['START']['ENDPOINT']['CODE'])) {
             continue;
         }
         $trigger = TriggerManager::getOnce($result['TRIGGER']['START']['ENDPOINT']);
         if (!$trigger) {
             continue;
         }
         $result['TRIGGER']['START']['ENDPOINT']['NAME'] = $trigger->getName();
         if (!empty($result['TRIGGER']['START']['ENDPOINT']['CODE'])) {
             $trigger = TriggerManager::getOnce($result['TRIGGER']['END']['ENDPOINT']);
             if (!$trigger) {
                 $result['TRIGGER']['END']['ENDPOINT']['NAME'] = $trigger->getName();
             }
         }
         $resultListTmp[] = $result;
     }
     return $resultListTmp;
 }
Beispiel #2
0
 /**
  * Instantiates an function object by function name.
  *
  * @param string $functionName Name of the function in the lower case.
  * @param mixed $data Additional data for function instance
  * @return FunctionBase
  */
 public static function createInstance($functionName, $data = null)
 {
     if ($functionName === "upper") {
         return new FunctionUpper($data);
     } elseif ($functionName === "lower") {
         return new FunctionLower($data);
     } elseif ($functionName === "translit") {
         return new FunctionTranslit($data);
     } elseif ($functionName === "concat") {
         return new FunctionConcat($data);
     } elseif ($functionName === "limit") {
         return new FunctionLimit($data);
     } elseif ($functionName === "contrast") {
         return new FunctionContrast($data);
     } elseif ($functionName === "min") {
         return new FunctionMin($data);
     } elseif ($functionName === "max") {
         return new FunctionMax($data);
     } elseif ($functionName === "distinct") {
         return new FunctionDistinct($data);
     } elseif (isset(self::$functionMap[$functionName])) {
         $functionClass = self::$functionMap[$functionName];
         return new $functionClass($data);
     } else {
         $event = new \Bitrix\Main\Event("iblock", "OnTemplateGetFunctionClass", array($functionName));
         $event->send();
         if ($event->getResults()) {
             foreach ($event->getResults() as $evenResult) {
                 if ($evenResult->getResultType() == \Bitrix\Main\EventResult::SUCCESS) {
                     $functionClass = $evenResult->getParameters();
                     if (is_string($functionClass) && class_exists($functionClass)) {
                         self::$functionMap[$functionName] = $functionClass;
                     }
                     break;
                 }
             }
         }
         if (isset(self::$functionMap[$functionName])) {
             $functionClass = self::$functionMap[$functionName];
             return new $functionClass($data);
         }
     }
     return new FunctionBase($data);
 }
Beispiel #3
0
 /**
  * @param $arMailParams
  * @return bool
  */
 public static function send($arMailParams)
 {
     $result = false;
     $event = new \Bitrix\Main\Event("main", "OnBeforeMailSend", array($arMailParams));
     $event->send();
     foreach ($event->getResults() as $eventResult) {
         if ($eventResult->getType() == \Bitrix\Main\EventResult::ERROR) {
             return false;
         }
         $arMailParams = array_merge($arMailParams, $eventResult->getParameters());
     }
     if (defined("ONLY_EMAIL") && $arMailParams['TO'] != ONLY_EMAIL) {
         $result = true;
     } else {
         $mail = static::createInstance($arMailParams);
         $mailResult = bxmail($mail->getTo(), $mail->getSubject(), $mail->getBody(), $mail->getHeaders(), $mail->getAdditionalParameters());
         if ($mailResult) {
             $result = true;
         }
     }
     return $result;
 }
 public static function execOldEventWithNewParams(Bitrix\Main\Event $params)
 {
     /** @var \Bitrix\Sale\Shipment $shipment*/
     if (!($shipment = $params->getParameter("SHIPMENT"))) {
         return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale');
     }
     /** @var \Bitrix\Sale\Delivery\Services\Base $deliverySrv */
     if (!($deliverySrv = $shipment->getDelivery())) {
         return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale');
     }
     if (get_class($deliverySrv) != 'Bitrix\\Sale\\Delivery\\Services\\AutomaticProfile') {
         return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale');
     }
     if (!($code = $deliverySrv->getCode())) {
         return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale');
     }
     $sidAndProfile = \CSaleDeliveryHelper::getDeliverySIDAndProfile($code);
     /** @var \Bitrix\Sale\Delivery\CalculationResult $result*/
     if (!($result = $params->getParameter("RESULT"))) {
         throw new \Bitrix\Main\ArgumentNullException("params[RESULT]");
     }
     if (!($collection = $shipment->getCollection())) {
         return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale');
     }
     /** @var \Bitrix\Sale\Order $order */
     if (!($order = $collection->getOrder())) {
         return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, null, 'sale');
     }
     $oldOrder = \Bitrix\Sale\Compatible\OrderCompatibility::convertOrderToArray($order);
     $oldResult = array("VALUE" => $result->getPrice(), "TRANSIT" => $result->getPeriodDescription(), "TEXT" => $result->isSuccess() ? $result->getDescription() : implode("<br>\n", $result->getErrorMessages()), "RESULT" => $result->isSuccess() ? "OK" : "ERROR");
     if ($result->isNextStep()) {
         $oldResult["RESULT"] = "NEXT_STEP";
     }
     if ($result->isSuccess() && strlen($result->getDescription()) > 0) {
         $oldResult["RESULT"] = "NOTE";
     }
     if (intval($result->getPacksCount()) > 0) {
         $oldResult["PACKS_COUNT"] = $result->getPacksCount();
     }
     if ($result->isNextStep() && strlen($result->getTmpData()) > 0) {
         $oldResult["TEMP"] = CUtil::JSEscape($result->getTmpData());
     }
     $oldResult = self::__executeCalculateEvents($sidAndProfile["SID"], $sidAndProfile["PROFILE"], $oldOrder, $oldResult);
     $result->setDeliveryPrice($oldResult["VALUE"]);
     if ($oldResult["RESULT"] == "ERROR") {
         $result->addError(new \Bitrix\Main\Entity\EntityError($oldResult["TEXT"]));
     } elseif ($oldResult["RESULT"] == "NEXT_STEP") {
         $result->setAsNextStep();
     }
     if (isset($oldResult["TRANSIT"])) {
         $result->setPeriodDescription($oldResult["TRANSIT"]);
     }
     if (isset($oldResult["TEXT"])) {
         $result->setDescription($oldResult["TEXT"]);
     }
     if (isset($oldResult["PACKS_COUNT"])) {
         $result->setPacksCount($oldResult["PACKS_COUNT"]);
     }
     if (isset($oldResult["TEMP"])) {
         $result->setTmpData($oldResult["TEMP"]);
     }
     return $result;
 }
Beispiel #5
0
 function SetLastActivityDateByArray($arUsers)
 {
     global $DB;
     if (!is_array($arUsers) || count($arUsers) <= 0) {
         return false;
     }
     $strSqlPrefix = "UPDATE b_user SET " . "TIMESTAMP_X = " . (strtoupper($DB->type) == "ORACLE" ? "NULL" : "TIMESTAMP_X") . ", " . "LAST_ACTIVITY_DATE = " . $DB->CurrentTimeFunction() . " WHERE ID IN (";
     $strSqlPostfix = ")";
     $maxValuesLen = 2048;
     $strSqlValues = "";
     $arUsers = array_map("intval", $arUsers);
     foreach ($arUsers as $userId) {
         $strSqlValues .= ",{$userId}";
         if (strlen($strSqlValues) > $maxValuesLen) {
             $DB->Query($strSqlPrefix . substr($strSqlValues, 1) . $strSqlPostfix, false, "", array("ignore_dml" => true));
             $strSqlValues = "";
         }
     }
     if (strlen($strSqlValues) > 0) {
         $DB->Query($strSqlPrefix . substr($strSqlValues, 1) . $strSqlPostfix, false, "", array("ignore_dml" => true));
     }
     $event = new \Bitrix\Main\Event("main", "OnUserSetLastActivityDate", array($arUsers));
     $event->send();
     return true;
 }
Beispiel #6
0
 /**
  * @param $mailingChainId
  * @return string
  */
 public static function chainSend($mailingChainId)
 {
     static::$error = null;
     $mailingChainPrimary = array('ID' => $mailingChainId);
     $mailingChainDb = MailingChainTable::getById($mailingChainPrimary);
     $mailingChain = $mailingChainDb->fetch();
     if ($mailingChain && $mailingChain['STATUS'] == MailingChainTable::STATUS_SEND) {
         if (\COption::GetOptionString("sender", "auto_method") === 'cron') {
             $maxMailCount = 0;
             $timeout = 0;
         } else {
             $maxMailCount = \COption::GetOptionInt("sender", "max_emails_per_hit");
             $timeout = \COption::GetOptionInt("sender", "interval");
         }
         $postingSendStatus = '';
         if (!empty($mailingChain['POSTING_ID'])) {
             try {
                 $postingSendStatus = PostingManager::send($mailingChain['POSTING_ID'], $timeout, $maxMailCount);
             } catch (Exception $e) {
                 static::$error = $e;
                 $postingSendStatus = PostingManager::SEND_RESULT_ERROR;
             }
         }
         if (empty(static::$error) && $postingSendStatus !== PostingManager::SEND_RESULT_CONTINUE) {
             if ($mailingChain['REITERATE'] == 'Y') {
                 $mailingChainFields = array('STATUS' => MailingChainTable::STATUS_WAIT, 'AUTO_SEND_TIME' => null, 'POSTING_ID' => null);
                 if ($mailingChain['IS_TRIGGER'] == 'Y') {
                     $postingDb = PostingTable::getList(array('select' => array('ID', 'DATE_CREATE'), 'filter' => array('STATUS' => PostingTable::STATUS_NEW, 'MAILING_CHAIN_ID' => $mailingChain['ID']), 'order' => array('DATE_CREATE' => 'ASC'), 'limit' => 1));
                     if ($posting = $postingDb->fetch()) {
                         $mailingChainFields['AUTO_SEND_TIME'] = $posting['DATE_CREATE']->add($mailingChain['TIME_SHIFT'] . ' minutes');
                         $mailingChainFields['STATUS'] = MailingChainTable::STATUS_SEND;
                         $mailingChainFields['POSTING_ID'] = $posting['ID'];
                     }
                 }
                 MailingChainTable::update($mailingChainPrimary, $mailingChainFields);
                 $eventData = array('MAILING_CHAIN' => $mailingChain);
                 $event = new \Bitrix\Main\Event('sender', 'OnAfterMailingChainSend', array($eventData));
                 $event->send();
             } else {
                 MailingChainTable::update($mailingChainPrimary, array('STATUS' => MailingChainTable::STATUS_END));
             }
         } else {
             return static::getAgentName($mailingChainId);
         }
     }
     return "";
 }
Beispiel #7
0
 public static function getUserByPassword($login, $password, $passwordIsOriginal = true)
 {
     if (empty($login)) {
         throw new Main\ArgumentNullException("login");
     }
     $event = new Main\Event("main", "OnBeforeUserLogin", array(array("LOGIN" => $login, "PASSWORD" => $password, "PASSWORD_ORIGINAL" => $passwordIsOriginal)));
     $event->send();
     if (($eventResults = $event->getResults()) !== null) {
         foreach ($eventResults as $eventResult) {
             if ($eventResult->getResultType() === Main\EventResult::ERROR) {
                 static::$lastError = $eventResult->getParameters();
                 return null;
             } elseif ($eventResult->getResultType() === Main\EventResult::SUCCESS) {
                 if (($resultParams = $eventResult->getParameters()) && is_array($resultParams)) {
                     if (isset($resultParams["LOGIN"])) {
                         $login = $resultParams["LOGIN"];
                     }
                     if (isset($resultParams["PASSWORD"])) {
                         $password = $resultParams["PASSWORD"];
                     }
                     if (isset($resultParams["PASSWORD_ORIGINAL"])) {
                         $passwordIsOriginal = $resultParams["PASSWORD_ORIGINAL"];
                     }
                 }
             }
         }
     }
     $user = null;
     $event = new Main\Event("main", "OnUserLoginExternal", array(array("LOGIN" => $login, "PASSWORD" => $password, "PASSWORD_ORIGINAL" => $passwordIsOriginal)));
     $event->send();
     if (($eventResults = $event->getResults()) !== null) {
         foreach ($eventResults as $eventResult) {
             if ($eventResult->getResultType() === Main\EventResult::SUCCESS) {
                 $userId = $eventResult->getParameters();
                 if (!Main\Type\Int::isInteger($userId)) {
                     throw new SecurityException();
                 }
                 $user = new CurrentUser($userId);
                 break;
             }
         }
     }
     $connection = Main\Application::getDbConnection();
     $sqlHelper = $connection->getSqlHelper();
     if (is_null($user)) {
         $sql = "SELECT U.ID, U.PASSWORD, U.LOGIN_ATTEMPTS " . "FROM b_user U  " . "WHERE U.LOGIN = '******' " . "\tAND (U.EXTERNAL_AUTH_ID IS NULL OR U.EXTERNAL_AUTH_ID = '') " . "   AND U.ACTIVE = 'Y' ";
         $userRecordset = $connection->query($sql);
         if ($userRecord = $userRecordset->fetch()) {
             $userTmp = new CurrentUser($userRecord["ID"]);
             $salt = substr($userRecord["PASSWORD"], 0, -32);
             $passwordFromDb = substr($userRecord["PASSWORD"], -32);
             if ($passwordIsOriginal) {
                 $passwordFromUser = md5($salt . $password);
             } else {
                 $passwordFromUser = strlen($password) > 32 ? substr($password, -32) : $password;
             }
             $policy = $userTmp->getPolicy();
             $policyLoginAttempts = intval($policy["LOGIN_ATTEMPTS"]);
             $userLoginAttempts = intval($userRecord["LOGIN_ATTEMPTS"]) + 1;
             if ($policyLoginAttempts > 0 && $userLoginAttempts > $policyLoginAttempts) {
                 //					$_SESSION["BX_LOGIN_NEED_CAPTCHA"] = true;
                 //					if (!$APPLICATION->captchaCheckCode($_REQUEST["captcha_word"], $_REQUEST["captcha_sid"]))
                 //					{
                 //						$passwordUser = false;
                 //					}
             }
             if ($passwordFromDb === $passwordFromUser) {
                 $user = $userTmp;
                 //update digest hash for http digest authorization
                 if ($passwordIsOriginal && Main\Config\Option::get('main', 'use_digest_auth', 'N') == 'Y') {
                     static::updateDigest($user->getUserId(), $password);
                 }
             } else {
                 $connection->query("UPDATE b_user SET " . "   LOGIN_ATTEMPTS = " . $userLoginAttempts . " " . "WHERE ID = " . intval($userRecord["ID"]));
             }
         }
     }
     if (is_null($user)) {
         if (Main\Config\Option::get("main", "event_log_login_fail", "N") === "Y") {
             \CEventLog::log("SECURITY", "USER_LOGIN", "main", $login, "LOGIN_FAILED");
         }
         return null;
     }
     if ($user->getUserId() !== 1) {
         $limitUsersCount = intval(Main\Config\Option::get("main", "PARAM_MAX_USERS", 0));
         if ($limitUsersCount > 0) {
             $usersCount = Main\UserTable::getActiveUsersCount();
             if ($usersCount > $limitUsersCount) {
                 $sql = "SELECT 'x' " . "FROM b_user " . "WHERE ACTIVE = 'Y' " . "   AND ID = " . intval($user->getUserId()) . " " . "   AND LAST_LOGIN IS NULL ";
                 $recordset = $connection->query($sql);
                 if ($recordset->fetch()) {
                     $user = null;
                     static::$lastError = array("CODE" => "LIMIT_USERS_COUNT", "MESSAGE" => Main\Localization\Loc::getMessage("LIMIT_USERS_COUNT"));
                 }
             }
         }
     }
     if (is_null($user)) {
         if (Main\Config\Option::get("main", "event_log_login_fail", "N") === "Y") {
             \CEventLog::log("SECURITY", "USER_LOGIN", "main", $login, "LIMIT_USERS_COUNT");
         }
         return null;
     }
     $user->setAuthType(static::AUTHENTICATED_BY_PASSWORD);
     $event = new \Bitrix\Main\Event("main", "OnAfterUserLogin", array(array("LOGIN" => $login, "PASSWORD" => $password, "PASSWORD_ORIGINAL" => $passwordIsOriginal, "USER_ID" => $user->getUserId())));
     $event->send();
     return $user;
 }
Beispiel #8
0
	/**
	 * @param $data
	 * @return bool
	 * @throws \Bitrix\Main\ArgumentException
	 */
	public static function unsubscribe($data)
	{
		$result = false;

		if(isset($data['TEST']) && $data['TEST'] == 'Y')
			return true;

		$posting = null;
		if($data['RECIPIENT_ID'])
		{
			$postingDb = PostingRecipientTable::getList(array(
				'select' => array('POSTING_ID', 'POSTING_MAILING_ID' => 'POSTING.MAILING_ID'),
				'filter' => array('ID' => $data['RECIPIENT_ID'], 'EMAIL' => $data['EMAIL'])
			));
			$posting = $postingDb->fetch();
		}

		$mailingDb = MailingTable::getList(array(
			'select' => array('ID'),
			'filter' => array(
				'ID' => $data['UNSUBSCRIBE_LIST'],
			)
		));
		while($mailing = $mailingDb->fetch())
		{
			$unsub = null;

			if($posting && $posting['POSTING_MAILING_ID'] == $mailing['ID'])
			{
				$unsub = array(
					'POSTING_ID' => $posting['POSTING_ID'],
					'RECIPIENT_ID' => $data['RECIPIENT_ID'],
				);
			}
			else
			{
				$mailingPostingDb = PostingRecipientTable::getList(array(
					'select' => array('RECIPIENT_ID' => 'ID', 'POSTING_ID'),
					'filter' => array('=POSTING.MAILING_ID' => $mailing['ID'], 'EMAIL' => $data['EMAIL'])
				));
				if($mailingPosting = $mailingPostingDb->fetch())
				{
					$unsub = $mailingPosting;
				}
			}

			if(!empty($unsub))
			{
				$unsubExists = PostingUnsubTable::getRowById($unsub);
				if(!$unsubExists)
				{
					$unsubResult = PostingUnsubTable::add($unsub);
					if($unsubResult->isSuccess())
					{
						$eventData = array(
							'MAILING_ID' => $mailing['ID'],
							'RECIPIENT_ID' => $unsub['RECIPIENT_ID'],
							'EMAIL' => $data['EMAIL'],
						);
						$event = new \Bitrix\Main\Event('sender', 'OnAfterRecipientUnsub', array($eventData));
						$event->send();
					}
				}

				$result = true;
			}

			$contactDb = ContactTable::getList(array(
				'select' => array('ID'),
				'filter' => array('=EMAIL' => $data['EMAIL'])
			));
			while($contact = $contactDb->fetch())
			{
				MailingSubscriptionTable::delete(array('MAILING_ID' => $mailing['ID'], 'CONTACT_ID' => $contact['ID']));
				$result = true;
			}
		}

		return $result;
	}
 public static function DeleteRecent($entityId, $isChat = false, $userId = false)
 {
     if (is_array($entityId)) {
         foreach ($entityId as $key => $value) {
             $entityId[$key] = intval($value);
         }
         $entityId = array_slice($entityId, 0, 1000);
         $sqlEntityId = 'ITEM_ID IN (' . implode(',', $entityId) . ')';
     } else {
         if (intval($entityId) > 0) {
             $sqlEntityId = 'ITEM_ID = ' . intval($entityId);
         } else {
             return false;
         }
     }
     if (intval($userId) <= 0) {
         $userId = $GLOBALS['USER']->GetID();
     }
     global $DB;
     if ($isChat) {
         $itemType = "ITEM_TYPE != '" . IM_MESSAGE_PRIVATE . "'";
     } else {
         $itemType = "ITEM_TYPE = '" . IM_MESSAGE_PRIVATE . "'";
     }
     $strSQL = "DELETE FROM b_im_recent WHERE USER_ID = " . $userId . " AND " . $itemType . " AND " . $sqlEntityId;
     $DB->Query($strSQL, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     $obCache = new CPHPCache();
     $obCache->CleanDir('/bx/imc/recent' . CIMMessenger::GetCachePath($userId));
     $strSQL = $DB->TopSql("SELECT 1 FROM b_im_recent WHERE USER_ID = " . $userId, 1);
     $rs = $DB->Query($strSQL, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     if (!$rs->Fetch()) {
         $event = new \Bitrix\Main\Event("im", "OnAfterRecentDelete", array("user_id" => $userId));
         $event->send();
     }
     return true;
 }