PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/sale.affiliate.register/component.php

https://gitlab.com/alexprowars/bitrix
PHP | 250 lines | 210 code | 37 blank | 3 comment | 81 complexity | c1110cd3bf745c61a7041add8ff480f5 MD5 | raw file
  1. <?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?><?
  2. if(!CBXFeatures::IsFeatureEnabled('SaleAffiliate'))
  3. return;
  4. $arParas["REDIRECT_PAGE"] = trim($arParams["REDIRECT_PAGE"]);
  5. if ($arParams["SET_TITLE"] == '') $arParams["SET_TITLE"] = "Y";
  6. if (
  7. $arParams["REDIRECT_PAGE"] == ''
  8. || preg_match('/^([a-z0-9]+):\\/\\//', $arParams["REDIRECT_PAGE"])
  9. )
  10. $arParams["REDIRECT_PAGE"] = "index.php";
  11. if (CModule::IncludeModule("sale"))
  12. {
  13. CSaleAffiliate::GetAffiliate();
  14. $errorMessage = "";
  15. $arResult = array();
  16. if (!$GLOBALS["USER"]->IsAuthorized())
  17. {
  18. if($_SERVER["REQUEST_METHOD"] == "POST" && check_bitrix_sessid())
  19. {
  20. if ($_REQUEST["do_authorize"] == "Y")
  21. {
  22. $USER_LOGIN = $_REQUEST["USER_LOGIN"];
  23. if ($USER_LOGIN == '')
  24. $errorMessage .= GetMessage("SPCR1_ON_LOGIN").".<br />";
  25. $USER_PASSWORD = $_REQUEST["USER_PASSWORD"];
  26. if ($errorMessage == '')
  27. {
  28. $arAuthResult = $GLOBALS["USER"]->Login($USER_LOGIN, $USER_PASSWORD, "N");
  29. if ($arAuthResult != False && $arAuthResult["TYPE"] == "ERROR")
  30. $errorMessage .= GetMessage("SPCR1_ERR_REG").(($arAuthResult["MESSAGE"] <> '') ? ": ".$arAuthResult["MESSAGE"] : ".<br />" );
  31. }
  32. }
  33. elseif ($_REQUEST["do_register"] == "Y")
  34. {
  35. $NEW_NAME = $_REQUEST["NEW_NAME"];
  36. if ($NEW_NAME == '')
  37. $errorMessage .= GetMessage("SPCR1_NO_NAME").".<br />";
  38. $NEW_LAST_NAME = $_REQUEST["NEW_LAST_NAME"];
  39. if ($NEW_LAST_NAME == '')
  40. $errorMessage .= GetMessage("SPCR1_NO_LASTNAME").".<br />";
  41. $NEW_EMAIL = $_REQUEST["NEW_EMAIL"];
  42. if ($NEW_EMAIL == '')
  43. $errorMessage .= GetMessage("SPCR1_NO_EMAIL").".<br />";
  44. elseif (!check_email($NEW_EMAIL))
  45. $errorMessage .= GetMessage("SPCR1_BAD_EMAIL").".<br />";
  46. $NEW_LOGIN = $_REQUEST["NEW_LOGIN"];
  47. if ($NEW_LOGIN == '')
  48. $errorMessage .= GetMessage("SPCR1_NO_LOGIN").".<br />";
  49. $NEW_PASSWORD = $_REQUEST["NEW_PASSWORD"];
  50. if ($NEW_PASSWORD == '')
  51. $errorMessage .= GetMessage("SPCR1_NO_PASSWORD").".<br />";
  52. $NEW_PASSWORD_CONFIRM = $_REQUEST["NEW_PASSWORD_CONFIRM"];
  53. if ($NEW_PASSWORD_CONFIRM == '')
  54. $errorMessage .= GetMessage("SPCR1_NO_PASSWORD_CONF").".<br />";
  55. if ($NEW_PASSWORD <> '' && $NEW_PASSWORD_CONFIRM <> '' && $NEW_PASSWORD != $NEW_PASSWORD_CONFIRM)
  56. $errorMessage .= GetMessage("SPCR1_NO_CONF").".<br />";
  57. if ($errorMessage == '')
  58. {
  59. $arAuthResult = $GLOBALS["USER"]->Register($NEW_LOGIN, $NEW_NAME, $NEW_LAST_NAME, $NEW_PASSWORD, $NEW_PASSWORD_CONFIRM, $NEW_EMAIL, LANG, $_REQUEST["captcha_word"], $_REQUEST["captcha_sid"]);
  60. if ($arAuthResult != False && $arAuthResult["TYPE"] == "ERROR")
  61. $errorMessage .= GetMessage("SPCR1_ERR_REGISTER").(($arAuthResult["MESSAGE"] <> '') ? ": ".$arAuthResult["MESSAGE"] : ".<br />" );
  62. else
  63. if ($GLOBALS["USER"]->IsAuthorized())
  64. CUser::SendUserInfo($GLOBALS["USER"]->GetID(), SITE_ID, GetMessage("INFO_REQ"), true);
  65. }
  66. $arResult["NEW_LOGIN"] = htmlspecialcharsbx($NEW_LOGIN);
  67. $arResult["NEW_NAME"] = htmlspecialcharsbx($NEW_NAME);
  68. $arResult["NEW_LAST_NAME"] = htmlspecialcharsbx($NEW_LAST_NAME);
  69. $arResult["NEW_PASSWORD"] = htmlspecialcharsbx($NEW_PASSWORD);
  70. $arResult["NEW_PASSWORD_CONFIRM"] = htmlspecialcharsbx($NEW_PASSWORD_CONFIRM);
  71. $arResult["NEW_EMAIL"] = htmlspecialcharsbx($NEW_EMAIL);
  72. }
  73. }
  74. }
  75. $arResult["AFFILIATE"] = "N";
  76. $arResult["UNACTIVE_AFFILIATE"] = "N";
  77. if ($GLOBALS["USER"]->IsAuthorized())
  78. {
  79. $dbAffiliate = CSaleAffiliate::GetList(
  80. array("TRANSACT_DATE" => "ASC"),
  81. array(
  82. "USER_ID" => intval($GLOBALS["USER"]->GetID()),
  83. "SITE_ID" => SITE_ID
  84. ),
  85. false,
  86. false,
  87. array("ID", "ACTIVE")
  88. );
  89. if ($arAffiliate = $dbAffiliate->Fetch())
  90. {
  91. $arResult["AFFILIATE"] = "Y";
  92. if ($arAffiliate["ACTIVE"] == "Y")
  93. {
  94. LocalRedirect($arParams["REDIRECT_PAGE"]);
  95. die();
  96. }
  97. else
  98. {
  99. $arResult["UNACTIVE_AFFILIATE"] = "Y";
  100. }
  101. }
  102. }
  103. if ($arResult["AFFILIATE"] == "N")
  104. {
  105. if ($arParams["SET_TITLE"] == "Y")
  106. $APPLICATION->SetTitle(GetMessage("SPCR1_REGISTER_AFF"));
  107. /****************************************************************/
  108. /********* ACTIONS ***************************************/
  109. /****************************************************************/
  110. if($_SERVER["REQUEST_METHOD"] == "POST" && check_bitrix_sessid())
  111. {
  112. if ($_REQUEST["do_agree"] == "Y")
  113. {
  114. if ($_REQUEST["is_agree_agreement"] == "Y")
  115. {
  116. if ($_REQUEST["agree_agreement"] != "Y")
  117. $errorMessage .= GetMessage("SPCR1_NO_AGREE").".<br />";
  118. }
  119. $arResult["agree_agreement"] = $_REQUEST["agree_agreement"] == "Y" ? "Y" : "N";
  120. $AFF_SITE = Trim($_REQUEST["AFF_SITE"]);
  121. if ($AFF_SITE == '')
  122. $errorMessage .= GetMessage("SPCR1_NO_SITE").".<br />";
  123. $arResult["AFF_SITE"] = htmlspecialcharsbx($AFF_SITE);
  124. $AFF_DESCRIPTION = Trim($_REQUEST["AFF_DESCRIPTION"]);
  125. if ($AFF_DESCRIPTION == '')
  126. $errorMessage .= GetMessage("SPCR1_NO_DESCR").".<br />";
  127. $arResult["AFF_DESCRIPTION"] = htmlspecialcharsbx($AFF_DESCRIPTION);
  128. if ($errorMessage == '')
  129. {
  130. $dbPlan = CSaleAffiliatePlan::GetList(
  131. array("MIN_PLAN_VALUE" => "ASC"),
  132. array(
  133. "SITE_ID" => SITE_ID,
  134. "ACTIVE" => "Y",
  135. ),
  136. false,
  137. false,
  138. array("ID", "MIN_PLAN_VALUE")
  139. );
  140. $arPlan = $dbPlan->Fetch();
  141. if (!$arPlan)
  142. $errorMessage .= GetMessage("SPCR1_NO_PLANS").".<br />";
  143. }
  144. if ($errorMessage == '')
  145. {
  146. $arFields = array(
  147. "SITE_ID" => SITE_ID,
  148. "USER_ID" => intval($GLOBALS["USER"]->GetID()),
  149. "PLAN_ID" => $arPlan["ID"],
  150. "ACTIVE" => ((DoubleVal($arPlan["MIN_PLAN_VALUE"]) > 0) ? "N" : "Y"),
  151. "DATE_CREATE" => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time()+CTimeZone::GetOffset()),
  152. "PAID_SUM" => 0,
  153. "PENDING_SUM" => 0,
  154. "LAST_CALCULATE" => false,
  155. "FIX_PLAN" => "N",
  156. "AFF_SITE" => $AFF_SITE,
  157. "AFF_DESCRIPTION" => $AFF_DESCRIPTION
  158. );
  159. $affiliateID = CSaleAffiliate::GetAffiliate();
  160. if ($affiliateID > 0)
  161. $arFields["AFFILIATE_ID"] = $affiliateID;
  162. else
  163. $arFields["AFFILIATE_ID"] = false;
  164. if (!CSaleAffiliate::Add($arFields))
  165. {
  166. if ($ex = $GLOBALS["APPLICATION"]->GetException())
  167. $errorMessage .= $ex->GetString().".<br />";
  168. else
  169. $errorMessage .= GetMessage("SPCR1_ERR_AFF").".<br />";
  170. }
  171. else
  172. {
  173. LocalRedirect($arParams["REDIRECT_PAGE"]);
  174. die();
  175. }
  176. }
  177. }
  178. }
  179. $arResult["ERROR_MESSAGE"] = $errorMessage;
  180. $arResult["CURRENT_PAGE"] = $APPLICATION->GetCurPage();
  181. if (!$GLOBALS["USER"]->IsAuthorized())
  182. {
  183. $arResult["USER_AUTHORIZED"] = "N";
  184. $arResult["DEFAULT_USER_LOGIN"] = ${COption::GetOptionString("main", "cookie_name", "BITRIX_SM")."_LOGIN"};
  185. $arResult["CAPTCHA_CODE"] = False;
  186. if (COption::GetOptionString("main", "captcha_registration", "N") == "Y")
  187. $arResult["CAPTCHA_CODE"] = htmlspecialcharsbx($GLOBALS["APPLICATION"]->CaptchaGetCode());
  188. }
  189. else
  190. {
  191. $arResult["USER_AUTHORIZED"] = "Y";
  192. $arResult["AGREEMENT_TEXT_FILE"] = $arParams["AGREEMENT_TEXT_FILE"];
  193. if (empty($arResult["AGREEMENT_TEXT_FILE"]) || !file_exists($_SERVER["DOCUMENT_ROOT"].$arResult["AGREEMENT_TEXT_FILE"]))
  194. {
  195. $arResult["AGREEMENT_TEXT_FILE"] = false;
  196. }
  197. $arResult['USER_CONSENT_PROPERTY_DATA'] = [
  198. GetMessage("SPCR1_SITE_URL_CONSENT"),
  199. GetMessage("SPCR1_SITE_DESCR_CONSENT")
  200. ];
  201. }
  202. }
  203. $arResult["REDIRECT_PAGE"] = htmlspecialcharsbx($arParams["REDIRECT_PAGE"]);
  204. $arResult["DEFAULT_USER_LOGIN"] = ($_REQUEST["USER_LOGIN"] <> '') ? htmlspecialcharsbx($_REQUEST["USER_LOGIN"]) : htmlspecialcharsbx($arResult["DEFAULT_USER_LOGIN"]);
  205. $this->IncludeComponentTemplate();
  206. }
  207. else
  208. {
  209. ?>
  210. <b><?=ShowError(GetMessage("SPCR1_NO_SHOP"))?></b>
  211. <?
  212. }
  213. ?>