/bitrix/modules/sale/general/auxiliary.php

https://gitlab.com/Rad1calDreamer/honey · PHP · 160 lines · 127 code · 26 blank · 7 comment · 33 complexity · 50c1fad289bf1881898bf7c1c234764b MD5 · raw file

  1. <?
  2. IncludeModuleLangFile(__FILE__);
  3. /***********************************************************************/
  4. /*********** CSaleAuxiliary ******************************************/
  5. /***********************************************************************/
  6. class CAllSaleAuxiliary
  7. {
  8. function PrepareItemMD54Where($val, $key, $operation, $negative, $field, &$arField, &$arFilter)
  9. {
  10. $val1 = md5($val);
  11. return "(".($negative=="Y"?" A.ITEM_MD5 IS NULL OR NOT ":"")."(A.ITEM_MD5 ".$operation." '".$GLOBALS["DB"]->ForSql($val1)."' )".")";
  12. }
  13. //********** CHECK **************//
  14. function CheckAccess($userID, $itemMD5, $periodLength, $periodType)
  15. {
  16. global $DB;
  17. $userID = IntVal($userID);
  18. if ($userID <= 0)
  19. return false;
  20. $itemMD5 = Trim($itemMD5);
  21. if (strlen($itemMD5) <= 0)
  22. return false;
  23. $periodLength = IntVal($periodLength);
  24. if ($periodLength <= 0)
  25. return False;
  26. $periodType = Trim($periodType);
  27. $periodType = ToUpper($periodType);
  28. if (strlen($periodType) <= 0)
  29. return False;
  30. $checkVal = 0;
  31. if ($periodType == "I")
  32. $checkVal = mktime(date("H"), date("i") - $periodLength, date("s"), date("m"), date("d"), date("Y"));
  33. elseif ($periodType == "H")
  34. $checkVal = mktime(date("H") - $periodLength, date("i"), date("s"), date("m"), date("d"), date("Y"));
  35. elseif ($periodType == "D")
  36. $checkVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $periodLength, date("Y"));
  37. elseif ($periodType == "W")
  38. $checkVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") - 7 * $periodLength, date("Y"));
  39. elseif ($periodType == "M")
  40. $checkVal = mktime(date("H"), date("i"), date("s"), date("m") - $periodLength, date("d"), date("Y"));
  41. elseif ($periodType == "Q")
  42. $checkVal = mktime(date("H"), date("i"), date("s"), date("m") - 3 * $periodLength, date("d"), date("Y"));
  43. elseif ($periodType == "S")
  44. $checkVal = mktime(date("H"), date("i"), date("s"), date("m") - 6 * $periodLength, date("d"), date("Y"));
  45. elseif ($periodType == "Y")
  46. $checkVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") - $periodLength);
  47. if ($checkVal <= 0)
  48. return False;
  49. $dbAuxiliary = CSaleAuxiliary::GetList(
  50. array(),
  51. array(
  52. "USER_ID" => $userID,
  53. "ITEM_MD5" => $itemMD5,
  54. ">=DATE_INSERT" => Date($GLOBALS["DB"]->DateFormatToPHP(CSite::GetDateFormat("FULL", SITE_ID)), $checkVal)
  55. ),
  56. false,
  57. false,
  58. array("*")
  59. );
  60. if ($arAuxiliary = $dbAuxiliary->Fetch())
  61. return $arAuxiliary;
  62. return false;
  63. }
  64. //********** ADD, UPDATE, DELETE **************//
  65. function CheckFields($ACTION, &$arFields, $ID = 0)
  66. {
  67. if ((is_set($arFields, "USER_ID") || $ACTION=="ADD") && IntVal($arFields["USER_ID"]) <= 0)
  68. {
  69. $GLOBALS["APPLICATION"]->ThrowException("Empty user field", "EMPTY_USER_ID");
  70. return false;
  71. }
  72. if ((is_set($arFields, "ITEM") || $ACTION=="ADD") && strlen($arFields["ITEM"]) <= 0)
  73. {
  74. $GLOBALS["APPLICATION"]->ThrowException("Empty item field", "EMPTY_ITEM");
  75. return false;
  76. }
  77. if ((is_set($arFields, "ITEM_MD5") || $ACTION=="ADD") && strlen($arFields["ITEM_MD5"]) <= 0)
  78. {
  79. $GLOBALS["APPLICATION"]->ThrowException("Empty item md5 field", "EMPTY_ITEM_MD5");
  80. return false;
  81. }
  82. if ((is_set($arFields, "DATE_INSERT") || $ACTION=="ADD") && strlen($arFields["DATE_INSERT"]) <= 0)
  83. {
  84. $GLOBALS["APPLICATION"]->ThrowException("Empty date insert field", "EMPTY_DATE_INSERT");
  85. return false;
  86. }
  87. if (is_set($arFields, "ITEM_MD5"))
  88. $arFields["ITEM_MD5"] = md5($arFields["ITEM_MD5"]);
  89. if (is_set($arFields, "USER_ID"))
  90. {
  91. $dbUser = CUser::GetByID($arFields["USER_ID"]);
  92. if (!$dbUser->Fetch())
  93. {
  94. $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["USER_ID"], GetMessage("SGMA_NO_USER")), "ERROR_NO_USER_ID");
  95. return false;
  96. }
  97. }
  98. return True;
  99. }
  100. function Delete($ID)
  101. {
  102. global $DB;
  103. $ID = IntVal($ID);
  104. if ($ID <= 0)
  105. return False;
  106. return $DB->Query("DELETE FROM b_sale_auxiliary WHERE ID = ".$ID." ", true);
  107. }
  108. function DeleteByUserID($userID)
  109. {
  110. global $DB;
  111. $userID = IntVal($userID);
  112. if ($userID <= 0)
  113. return False;
  114. return $DB->Query("DELETE FROM b_sale_auxiliary WHERE USER_ID = ".$userID." ", true);
  115. }
  116. //********** EVENTS **************//
  117. function OnUserDelete($userID)
  118. {
  119. $userID = IntVal($userID);
  120. $bSuccess = True;
  121. if (!CSaleAuxiliary::DeleteByUserID($userID))
  122. $bSuccess = False;
  123. return $bSuccess;
  124. }
  125. //********** AGENTS **************//
  126. function DeleteOldAgent($periodLength, $periodType)
  127. {
  128. CSaleAuxiliary::DeleteByTime($periodLength, $periodType);
  129. global $pPERIOD;
  130. $pPERIOD = 12*60*60;
  131. return 'CSaleAuxiliary::DeleteOldAgent('.$periodLength.', "'.$periodType.'");';
  132. }
  133. }
  134. ?>