Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. <?php
  2. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
  3. if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
  4.  
  5. global $contactId;
  6. global $USER;
  7.  
  8. $result = [];
  9.  
  10. function error($msg) {
  11. $result['isError'] = true;
  12. $result['msg'] = $msg;
  13. }
  14.  
  15. $isIncludeModules = \Bitrix\Main\Loader::includeModule('sender') &&
  16. \Bitrix\Main\Loader::includeModule('subscribe');
  17.  
  18. if (!$isIncludeModules) {
  19. error('Не установлены неопходимые модули');
  20. return;
  21. }
  22.  
  23. $email = $USER->GetEmail();
  24. $idUser = $USER->GetID();
  25.  
  26. // Получение email и пользователя если email указан в запросе
  27. if (!is_null($_REQUEST["email_subs"])) {
  28. $email = $_REQUEST["email_subs"];
  29. $filter = ["=EMAIL" => $email];
  30. $res = CUser::GetList(($by = "id"), ($order = "desc"), $filter);
  31. if ($res->NavNext(true, "f_")) {
  32. $idUser = $f_ID;
  33. }
  34. }
  35.  
  36. $subscription = CSubscription::GetUserSubscription();
  37. $subscriptionDb = new CSubscription;
  38.  
  39. $contactId = $subscription["ID"];
  40.  
  41. if ($subscription["ID"] == 0 || $subscription["CONFIRMED"] == 'N') {
  42. $contactId = null;
  43. }
  44.  
  45. // Подписка
  46. if ($_REQUEST["SUBSCRIBE"] == "Y") {
  47.  
  48. $arFilter = [
  49. "ACTIVE" => "Y",
  50. "LID" => "s1",
  51. "VISIBLE" => "Y",
  52. ];
  53.  
  54. $rsRubrics = CRubric::GetList([], $arFilter);
  55. $arRubrics = [];
  56. while ($arRubric = $rsRubrics->GetNext()) {
  57. $arRubrics[] = $arRubric["ID"];
  58. }
  59.  
  60. $subscribeFields = [
  61. "AJAX_MODE" => "Y",
  62. "USER_ID" => $idUser,
  63. "FORMAT" => "html",
  64. "EMAIL" => $email,
  65. "ACTIVE" => "Y",
  66. "SEND_CONFIRM" => "",
  67. "RUB_ID" => $arRubrics,
  68. "CONFIRMED" => "N"
  69. ];
  70.  
  71. $ID = $subscriptionDb->Add($subscribeFields);
  72. if ($ID > 0) {
  73. CSubscription::Authorize($ID);
  74. $result['isSuccess'] = true;
  75. $result['id'] = $ID;
  76. $contactId = $ID;
  77. }
  78. }
  79.  
  80. // Подтверждение подписки
  81. if ($_REQUEST["ID"] > 0 && !is_null($_REQUEST["CONFIRM_CODE"])) {
  82. if ($subscriptionDb->Update($_REQUEST["ID"], ["CONFIRM_CODE" => $_REQUEST["CONFIRM_CODE"]])) {
  83. $contactId = $_REQUEST["ID"];
  84. $result['isSuccess'] = true;
  85. }
  86. }
  87.  
  88. // Отписка
  89. if ($_REQUEST['UNSUBSCRIBE'] == 'Y') {
  90. $user = CSubscription::GetByEmail($USER->GetEmail());
  91. $user = $user->Fetch();
  92. CSubscription::Delete($user["ID"]);
  93. $contactId = null;
  94. $result['isSuccess'] = true;
  95. }
  96.  
  97. return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement